1 | <?php declare(strict_types=1); |
||
2 | |||
3 | /* |
||
4 | You may not change or alter any portion of this comment or credits |
||
5 | of supporting developers from this source code or any supporting source code |
||
6 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
7 | |||
8 | This program is distributed in the hope that it will be useful, |
||
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
11 | */ |
||
12 | |||
13 | /** |
||
14 | * wgEvents module for xoops |
||
15 | * |
||
16 | * @copyright 2021 XOOPS Project (https://xoops.org) |
||
17 | * @license GPL 2.0 or later |
||
18 | * @package wgevents |
||
19 | * @author Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com |
||
20 | */ |
||
21 | |||
22 | use Xmf\Request; |
||
23 | use XoopsModules\Wgevents; |
||
24 | use XoopsModules\Wgevents\{ |
||
25 | Constants, |
||
26 | Common, |
||
27 | MailHandler, |
||
28 | Utility |
||
29 | }; |
||
30 | |||
31 | require __DIR__ . '/header.php'; |
||
32 | |||
33 | $op = Request::getCmd('op', 'list'); |
||
34 | if ('show' === $op) { |
||
35 | $GLOBALS['xoopsOption']['template_main'] = 'wgevents_registration_single.tpl'; |
||
36 | } else { |
||
37 | $GLOBALS['xoopsOption']['template_main'] = 'wgevents_registration.tpl'; |
||
38 | } |
||
39 | require_once \XOOPS_ROOT_PATH . '/header.php'; |
||
40 | |||
41 | $regId = Request::getInt('id'); |
||
42 | $regEvid = Request::getInt('evid'); |
||
43 | $start = Request::getInt('start'); |
||
44 | $limit = Request::getInt('limit', $helper->getConfig('userpager')); |
||
45 | $redir = Request::getString('redir', 'list'); |
||
46 | $showinfo = Request::getInt('showinfo'); |
||
47 | //$sortBy = Request::getString('sortby', 'datecreated'); |
||
48 | //$orderBy = Request::getString('orderby', 'asc'); |
||
49 | |||
50 | $GLOBALS['xoopsTpl']->assign('start', $start); |
||
51 | $GLOBALS['xoopsTpl']->assign('limit', $limit); |
||
52 | //$GLOBALS['xoopsTpl']->assign('sort_order', $sortBy . '_' . $orderBy); |
||
53 | $GLOBALS['xoopsTpl']->assign('evid', $regEvid); |
||
54 | if (1 === $showinfo) { |
||
55 | $GLOBALS['xoopsTpl']->assign('warning', \_MA_WGEVENTS_REGISTRATION_INFO_SPAM); |
||
56 | } |
||
57 | |||
58 | if (Request::hasVar('cancel')) { |
||
59 | $op = 'listeventmy'; |
||
60 | } |
||
61 | if (Request::hasVar('exec_contactall_test')) { |
||
62 | $op = 'exec_contactall_test'; |
||
63 | } |
||
64 | |||
65 | // Define Stylesheet |
||
66 | $GLOBALS['xoTheme']->addStylesheet($style, null); |
||
67 | // Paths |
||
68 | $GLOBALS['xoopsTpl']->assign('xoops_icons32_url', \XOOPS_ICONS32_URL); |
||
69 | $GLOBALS['xoopsTpl']->assign('wgevents_url', \WGEVENTS_URL); |
||
70 | $GLOBALS['xoopsTpl']->assign('wgevents_icons_url_16', \WGEVENTS_ICONS_URL_16); |
||
71 | // Keywords |
||
72 | $keywords = []; |
||
73 | // Breadcrumbs |
||
74 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_INDEX, 'link' => 'index.php']; |
||
75 | // Permission |
||
76 | $permView = $permissionsHandler->getPermRegistrationView(); |
||
77 | $GLOBALS['xoopsTpl']->assign('permView', $permView); |
||
78 | |||
79 | $uidCurrent = \is_object($GLOBALS['xoopsUser']) ? (int)$GLOBALS['xoopsUser']->uid() : 0; |
||
80 | |||
81 | switch ($op) { |
||
82 | case 'show': |
||
83 | $verifKey = Request::getString('verifkey'); |
||
84 | $verifKeyArray = explode('||', base64_decode($verifKey, true)); |
||
85 | // for testing purposes //$verifKeyArray = [5, 'http://localhost/wgevents/htdocs/modules/wgevents', 1, '[email protected]', 'z4NBI7sYn3']; |
||
86 | $regId = $verifKeyArray[0]; |
||
87 | $registrationObj = $registrationHandler->get($regId); |
||
88 | $eventName = $eventHandler->get($registrationObj->getVar('evid'))->getVar('name'); |
||
89 | if ($regId > 0 && \is_object($registrationObj) && \WGEVENTS_URL == (string)$verifKeyArray[1] && |
||
90 | (int)$registrationObj->getVar('evid') == (int)$verifKeyArray[2] && |
||
91 | (string)$registrationObj->getVar('email') == (string)$verifKeyArray[3] && |
||
92 | (string)$registrationObj->getVar('verifkey') == (string)$verifKeyArray[4]) { |
||
93 | $registration = []; |
||
94 | // get all detail of this registration |
||
95 | $registration = $registrationObj->getValuesRegistrations(); |
||
96 | // get event info |
||
97 | $evId = $registrationObj->getVar('evid'); |
||
98 | $eventObj = $eventHandler->get($evId); |
||
99 | $event = $eventObj->getValuesEvents(); |
||
100 | $questionsArr = $questionHandler->getQuestionsByEvent($evId); |
||
101 | $registration['questions'] = $questionsArr; |
||
102 | |||
103 | // get all answers for this event |
||
104 | $answers = $answerHandler->getAnswersDetailsByRegistration($regId, $questionsArr); |
||
105 | foreach ($questionsArr as $key => $value) { |
||
106 | $question_answer[$key]['caption'] = $value['caption']; |
||
107 | $question_answer[$key]['answer'] = $answers[$key]; |
||
108 | } |
||
109 | $registration['questions'] = \count($question_answer); |
||
110 | $registration['question_answer'] = $question_answer; |
||
111 | |||
112 | $GLOBALS['xoopsTpl']->assign('event', $event); |
||
113 | $GLOBALS['xoopsTpl']->assign('registration', $registration); |
||
114 | $GLOBALS['xoopsTpl']->assign('verifKey', $verifKey); |
||
115 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_eventlogos_url', \WGEVENTS_UPLOAD_EVENTLOGOS_URL); |
||
116 | } else { |
||
117 | $GLOBALS['xoopsTpl']->assign('error', \sprintf(\_MA_WGEVENTS_MAIL_REG_VERIF_ERROR, $eventName)); |
||
118 | } |
||
119 | case 'list': |
||
120 | default: |
||
121 | break; |
||
122 | case 'listmy': |
||
123 | // Check permissions |
||
124 | if (!$permissionsHandler->getPermRegistrationsSubmit()) { |
||
125 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
126 | } |
||
127 | $GLOBALS['xoopsTpl']->assign('redir', 'listmy'); |
||
128 | // Breadcrumbs |
||
129 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_REGISTRATIONS_MYLIST]; |
||
130 | $events = []; |
||
131 | $registrations = []; |
||
132 | $regIp = $_SERVER['REMOTE_ADDR']; |
||
133 | // get all events with my registrations |
||
134 | $sql = 'SELECT evid, name, ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . '.submitter as ev_submitter, ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . '.status as ev_status '; |
||
135 | $sql .= 'FROM ' . $GLOBALS['xoopsDB']->prefix('wgevents_registration') . ' '; |
||
136 | $sql .= 'INNER JOIN ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . ' ON ' . $GLOBALS['xoopsDB']->prefix('wgevents_registration') . '.evid = ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . '.id '; |
||
137 | $sql .= 'WHERE ('; |
||
138 | if ($uidCurrent > 0) { |
||
139 | $sql .= '(' . $GLOBALS['xoopsDB']->prefix('wgevents_registration') . '.submitter)=' . $uidCurrent; |
||
140 | } else { |
||
141 | $sql .= '(' . $GLOBALS['xoopsDB']->prefix('wgevents_registration') . '.ip)="' . $regIp . '"'; |
||
142 | } |
||
143 | $sql .= ') GROUP BY ' . $GLOBALS['xoopsDB']->prefix('wgevents_registration') . '.evid, ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . '.name '; |
||
144 | $sql .= 'ORDER BY ' . $GLOBALS['xoopsDB']->prefix('wgevents_event') . '.datefrom DESC;'; |
||
145 | $result = $GLOBALS['xoopsDB']->query($sql); |
||
146 | while (list($evId, $evName, $evSubmitter, $evStatus) = $GLOBALS['xoopsDB']->fetchRow($result)) { |
||
147 | $events[$evId] = [ |
||
148 | 'id' => $evId, |
||
149 | 'name' => $evName, |
||
150 | 'submitter' => $evSubmitter, |
||
151 | 'status' => $evStatus |
||
152 | ]; |
||
153 | } |
||
154 | foreach ($events as $evId => $event) { |
||
155 | // get all questions for this event |
||
156 | $questionsArr = $questionHandler->getQuestionsByEvent($evId); |
||
157 | $registrations[$evId]['questions'] = $questionsArr; |
||
158 | $registrations[$evId]['footerCols'] = \count($questionsArr) + 9; |
||
159 | //get list of existing registrations for current user/current IP |
||
160 | $registrations[$evId]['event_id'] = $event['id']; |
||
161 | $registrations[$evId]['event_name'] = $event['name']; |
||
162 | $permEdit = $permissionsHandler->getPermEventsEdit($event['submitter'], $event['status']) || $uidCurrent == $event['submitter']; |
||
163 | $registrations[$evId]['permEditEvent'] = $permEdit; |
||
164 | $registrations[$evId]['details'] = $registrationHandler->getRegistrationDetailsByEvent($evId, $questionsArr); |
||
165 | } |
||
166 | if (\count($registrations) > 0) { |
||
167 | $GLOBALS['xoopsTpl']->assign('registrations', $registrations); |
||
168 | unset($registrations); |
||
169 | } else { |
||
170 | $GLOBALS['xoopsTpl']->assign('warning', \_MA_WGEVENTS_REGISTRATIONS_THEREARENT); |
||
171 | } |
||
172 | break; |
||
173 | case 'listeventmy': // list all registrations of current user of given event |
||
174 | case 'listeventall': // list all registrations of all users of given event |
||
175 | // Check params |
||
176 | if (0 === $regEvid) { |
||
177 | \redirect_header('index.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
178 | } |
||
179 | // Check permissions |
||
180 | if (!$permissionsHandler->getPermRegistrationsSubmit()) { |
||
181 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
182 | } |
||
183 | |||
184 | $captionList = \_MA_WGEVENTS_REGISTRATIONS_MYLIST; |
||
185 | $currentUserOnly = true; |
||
186 | if ('listeventall' === $op) { |
||
187 | $captionList = \_MA_WGEVENTS_REGISTRATIONS_LIST; |
||
188 | $currentUserOnly = false; |
||
189 | $GLOBALS['xoopsTpl']->assign('showSubmitter', true); |
||
190 | } |
||
191 | $GLOBALS['xoopsTpl']->assign('captionList', $captionList); |
||
192 | $GLOBALS['xoopsTpl']->assign('redir', $op); |
||
193 | $GLOBALS['xoopsTpl']->assign('op', $op); |
||
194 | $GLOBALS['xoopsTpl']->assign('evid', $regEvid); |
||
195 | |||
196 | // Breadcrumbs |
||
197 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_REGISTRATION_ADD]; |
||
198 | // get all questions for this event |
||
199 | $questionsArr = $questionHandler->getQuestionsByEvent($regEvid); |
||
200 | |||
201 | //get list of existing registrations for current user/current IP |
||
202 | $eventObj = $eventHandler->get($regEvid); |
||
203 | $evSubmitter = (int)$eventObj->getVar('submitter'); |
||
204 | $permEdit = $permissionsHandler->getPermEventsEdit($evSubmitter, $eventObj->getVar('status')) || $uidCurrent == $evSubmitter; |
||
205 | // list all registrations of all users of given event |
||
206 | // user must have perm to edit event |
||
207 | if ('listeventall' === $op && $uidCurrent !== $evSubmitter && !$permEdit) { |
||
208 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
209 | } |
||
210 | $event_name = $eventObj->getVar('name'); |
||
211 | $registrations[$regEvid]['event_id'] = $regEvid; |
||
212 | $registrations[$regEvid]['event_name'] = $event_name; |
||
213 | $registrations[$regEvid]['permEditEvent'] = $permEdit; |
||
214 | $registrations[$regEvid]['event_fee'] = $eventObj->getVar('fee'); |
||
215 | |||
216 | $evFee = \json_decode($eventObj->getVar('fee'), true); |
||
217 | $evFeeArr = []; |
||
218 | foreach($evFee as $fee) { |
||
219 | $evFeeArr[] = ['text' => Utility::FloatToString((float)$fee[0]), 'value' => (float)$fee[0]]; |
||
220 | } |
||
221 | $registrations[$regEvid]['evfees'] = $evFeeArr; |
||
222 | $registrations[$regEvid]['evfees_count'] = \count($evFeeArr); |
||
223 | $registrations[$regEvid]['event_register_max'] = $eventObj->getVar('register_max'); |
||
224 | $registrations[$regEvid]['questions'] = $questionsArr; |
||
225 | $registrations[$regEvid]['footerCols'] = \count($questionsArr) + 9; |
||
226 | $registrations[$regEvid]['details'] = $registrationHandler->getRegistrationDetailsByEvent($regEvid, $questionsArr, $currentUserOnly); |
||
227 | if ($registrations) { |
||
228 | $GLOBALS['xoopsTpl']->assign('registrations', $registrations); |
||
229 | unset($registrations); |
||
230 | } |
||
231 | if ('listeventall' === $op) { |
||
232 | $GLOBALS['xoopsTpl']->assign('showHandleList', true); |
||
233 | } else { |
||
234 | //$permEdit = $permissionsHandler->getPermEventsEdit($evSubmitter, $eventObj->getVar('status')); |
||
235 | if ($permEdit || |
||
236 | (\time() >= $eventObj->getVar('register_from') && \time() <= $eventObj->getVar('register_to')) |
||
237 | ) { |
||
238 | // Form Create |
||
239 | $registrationObj = $registrationHandler->create(); |
||
240 | $registrationObj->setVar('evid', $regEvid); |
||
241 | $registrationObj->setRedir($redir); |
||
242 | $form = $registrationObj->getForm(); |
||
243 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
244 | } |
||
245 | if (!$permEdit && \time() < $eventObj->getVar('register_from')) { |
||
246 | $GLOBALS['xoopsTpl']->assign('warning', sprintf(\_MA_WGEVENTS_REGISTRATION_TOEARLY, \formatTimestamp($eventObj->getVar('register_from'), 'm'))); |
||
247 | } |
||
248 | if (!$permEdit && \time() > $eventObj->getVar('register_to')) { |
||
249 | $GLOBALS['xoopsTpl']->assign('warning', sprintf(\_MA_WGEVENTS_REGISTRATION_TOLATE, \formatTimestamp($eventObj->getVar('register_to'), 'm'))); |
||
250 | } |
||
251 | } |
||
252 | //assign language vars for js calls |
||
253 | $GLOBALS['xoopsTpl']->assign('js_lang_paid', \_MA_WGEVENTS_REGISTRATION_FINANCIAL_PAID); |
||
254 | $GLOBALS['xoopsTpl']->assign('js_lang_unpaid', \_MA_WGEVENTS_REGISTRATION_FINANCIAL_UNPAID); |
||
255 | if (1 === \count($evFeeArr)) { |
||
256 | $GLOBALS['xoopsTpl']->assign('js_feedefault_value', $evFeeArr[0]['value']); |
||
257 | $GLOBALS['xoopsTpl']->assign('js_feedefault_text', $evFeeArr[0]['text']); |
||
258 | |||
259 | } |
||
260 | $GLOBALS['xoopsTpl']->assign('js_feezero_text', Utility::FloatToString(0)); |
||
261 | $GLOBALS['xoopsTpl']->assign('js_lang_changed', \_MA_WGEVENTS_REGISTRATION_CHANGED); |
||
262 | $GLOBALS['xoopsTpl']->assign('js_lang_approved', \_MA_WGEVENTS_STATUS_APPROVED); |
||
263 | $GLOBALS['xoopsTpl']->assign('js_lang_error_save', \_MA_WGEVENTS_ERROR_SAVE); |
||
264 | |||
265 | // tablesorter |
||
266 | $GLOBALS['xoopsTpl']->assign('tablesorter', true); |
||
267 | $GLOBALS['xoopsTpl']->assign('mod_url', \WGEVENTS_URL); |
||
268 | $GLOBALS['xoopsTpl']->assign('tablesorter_allrows', \_AM_WGEVENTS_TABLESORTER_SHOW_ALL); |
||
269 | $GLOBALS['xoopsTpl']->assign('tablesorter_of', \_AM_WGEVENTS_TABLESORTER_OF); |
||
270 | $GLOBALS['xoopsTpl']->assign('tablesorter_total', \_AM_WGEVENTS_TABLESORTER_TOTALROWS); |
||
271 | $GLOBALS['xoopsTpl']->assign('tablesorter_pagesize', $helper->getConfig('userpager')); |
||
272 | if ('d.m.Y' === \_SHORTDATESTRING) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
273 | $dateformat = 'ddmmyyyy'; |
||
274 | } else { |
||
275 | $dateformat = 'mmddyyyy'; |
||
276 | } |
||
277 | $GLOBALS['xoopsTpl']->assign('tablesorter_dateformat', $dateformat); |
||
278 | |||
279 | $GLOBALS['xoTheme']->addStylesheet(\WGEVENTS_URL . '/assets/js/tablesorter/css/jquery.tablesorter.pager.min.css'); |
||
280 | $tablesorterTheme = $helper->getConfig('tablesorter_user'); |
||
281 | $GLOBALS['xoTheme']->addStylesheet(\WGEVENTS_URL . '/assets/js/tablesorter/css/theme.' . $tablesorterTheme . '.min.css'); |
||
282 | $GLOBALS['xoopsTpl']->assign('tablesorter_theme', $tablesorterTheme); |
||
283 | $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/tablesorter/js/jquery.tablesorter.js'); |
||
284 | $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/tablesorter/js/jquery.tablesorter.widgets.js'); |
||
285 | $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/tablesorter/js/extras/jquery.tablesorter.pager.min.js'); |
||
286 | $GLOBALS['xoTheme']->addScript(\WGEVENTS_URL . '/assets/js/tablesorter/js/widgets/widget-pager.min.js'); |
||
287 | break; |
||
288 | |||
289 | case 'save': |
||
290 | // Security Check |
||
291 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
292 | \redirect_header('registration.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
293 | } |
||
294 | // Check params |
||
295 | if (0 === $regEvid) { |
||
296 | \redirect_header('index.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
297 | } |
||
298 | $eventObj = $eventHandler->get($regEvid); |
||
299 | $evSubmitter = $eventObj->getVar('submitter'); |
||
300 | $evStatus = $eventObj->getVar('status'); |
||
301 | $registerForceVerif = (bool)$eventObj->getVar('register_forceverif'); |
||
302 | |||
303 | if ($regId > 0) { |
||
304 | // Check permissions |
||
305 | $registrationObj = $registrationHandler->get($regId); |
||
306 | $permEdit = $permissionsHandler->getPermRegistrationsEdit($registrationObj->getVar('ip'), $registrationObj->getVar('submitter'), $evSubmitter, $evStatus); |
||
307 | if (!$permEdit) { |
||
308 | // check for valid verifKey |
||
309 | $verifKeyEdit = Request::getString('verifkeyEdit'); |
||
310 | $verifKeyArray = explode('||', base64_decode($verifKeyEdit, true)); |
||
311 | if (\is_object($registrationObj) && \WGEVENTS_URL === (string)$verifKeyArray[1] && |
||
312 | (int)$registrationObj->getVar('evid') === (int)$verifKeyArray[2] && |
||
313 | (string)$registrationObj->getVar('email') === (string)$verifKeyArray[3] && |
||
314 | (string)$registrationObj->getVar('verifkey') === (string)$verifKeyArray[4]) { |
||
315 | $permEdit = true; |
||
316 | } |
||
317 | } |
||
318 | if (!$permEdit) { |
||
319 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
320 | } |
||
321 | $registrationObj = $registrationHandler->get($regId); |
||
322 | $registrationObjOld = $registrationHandler->get($regId); |
||
323 | } else { |
||
324 | // Check permissions |
||
325 | if (!$permissionsHandler->getPermRegistrationsSubmit()) { |
||
326 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
327 | } |
||
328 | $registrationObj = $registrationHandler->create(); |
||
329 | } |
||
330 | // create item in table registrations |
||
331 | $answersValueArr = []; |
||
332 | $answersIdArr = Request::getArray('ans_id'); |
||
333 | $answersTypeArr = Request::getArray('type'); |
||
334 | $registrationObj->setVar('evid', $regEvid); |
||
335 | $registrationObj->setVar('salutation', Request::getInt('salutation')); |
||
336 | $registrationObj->setVar('firstname', Request::getString('firstname')); |
||
337 | $registrationObj->setVar('lastname', Request::getString('lastname')); |
||
338 | $regEmail = Request::getString('email'); |
||
339 | $registrationObj->setVar('email', $regEmail); |
||
340 | $registrationObj->setVar('email_send', Request::getInt('email_send')); |
||
341 | $registrationObj->setVar('gdpr', Request::getInt('gdpr')); |
||
342 | $registrationObj->setVar('ip', Request::getString('ip')); |
||
343 | $regVerifkey = ('' === Request::getString('verifkey')) ? xoops_makepass() . xoops_makepass(): Request::getString('verifkey'); |
||
344 | $registrationObj->setVar('verifkey', $regVerifkey); |
||
345 | $regStatus = Request::getInt('status'); |
||
346 | $registrationObj->setVar('status', $regStatus); |
||
347 | $registrationObj->setVar('financial', Request::getInt('financial')); |
||
348 | $regPaidamount = Utility::StringToFloat(Request::getString('paidamount')); |
||
349 | $registrationObj->setVar('paidamount', $regPaidamount); |
||
350 | $regListwait = 0; |
||
351 | if ($regId > 0 || $permissionsHandler->getPermRegistrationsApprove($evSubmitter, $evStatus)) { |
||
352 | //existing registration or user has perm to approve => take value of form |
||
353 | $registrationObj->setVar('listwait', Request::getInt('listwait')); |
||
354 | } else { |
||
355 | //check number of registrations |
||
356 | $eventRegisterMax = (int)$eventObj->getVar('register_max'); |
||
357 | if ($eventRegisterMax > 0) { |
||
358 | $crRegCheck = new \CriteriaCompo(); |
||
359 | $crRegCheck->add(new \Criteria('evid', $regEvid)); |
||
360 | $numberRegCurr = $registrationHandler->getCount($crRegCheck); |
||
361 | if ($eventRegisterMax <= $numberRegCurr) { |
||
362 | $regListwait = 1; |
||
363 | } |
||
364 | } |
||
365 | $registrationObj->setVar('listwait', $regListwait); |
||
366 | } |
||
367 | if (Request::hasVar('datecreated_int')) { |
||
368 | $registrationObj->setVar('datecreated', Request::getInt('datecreated_int')); |
||
369 | } else { |
||
370 | $registrationDatecreatedObj = \DateTime::createFromFormat(\_SHORTDATESTRING, Request::getString('datecreated')); |
||
371 | $registrationObj->setVar('datecreated', $registrationDatecreatedObj->getTimestamp()); |
||
372 | } |
||
373 | $regSubmitter = Request::getInt('submitter'); |
||
374 | $registrationObj->setVar('submitter', $regSubmitter); |
||
375 | // Insert Data |
||
376 | if ($registrationHandler->insert($registrationObj)) { |
||
377 | $newRegId = $regId > 0 ? $regId : (int)$registrationObj->getNewInsertedId(); |
||
378 | if ($regId > 0) { |
||
379 | // create copy before deleting |
||
380 | // get all questions for this event |
||
381 | $questionsArr = $questionHandler->getQuestionsByEvent($regEvid); |
||
382 | // get old answers for this questions |
||
383 | $answersOld = $answerHandler->getAnswersDetailsByRegistration($newRegId, $questionsArr); |
||
384 | // delete all existing answers |
||
385 | $answerHandler->cleanupAnswers($regEvid, $regId); |
||
386 | } |
||
387 | // get all questions |
||
388 | if (\count($answersIdArr) > 0) { |
||
389 | foreach (\array_keys($answersIdArr) as $queId) { |
||
390 | $answer = ''; |
||
391 | if (Request::hasVar('ans_id_' . $queId) && '' !== Request::getString('ans_id_' . $queId)) { |
||
392 | switch ($answersTypeArr[$queId]) { |
||
393 | case Constants::FIELD_CHECKBOX: |
||
394 | case Constants::FIELD_COMBOBOX: |
||
395 | $answer = serialize(Request::getArray('ans_id_' . $queId)); |
||
396 | break; |
||
397 | case Constants::FIELD_SELECTBOX: //selectbox expect/gives single value, but stored as array |
||
398 | $answer = serialize(Request::getString('ans_id_' . $queId)); |
||
399 | break; |
||
400 | default: |
||
401 | $answer = Request::getString('ans_id_' . $queId); |
||
402 | break; |
||
403 | } |
||
404 | $answersValueArr[$queId] = $answer; |
||
405 | } |
||
406 | } |
||
407 | } |
||
408 | |||
409 | // create items in table answers |
||
410 | foreach ($answersValueArr as $key => $answer) { |
||
411 | if ('' !== (string)$answer) { |
||
412 | $answerObj = $answerHandler->create(); |
||
413 | $answerObj->setVar('regid', $newRegId); |
||
414 | $answerObj->setVar('queid', $key); |
||
415 | $answerObj->setVar('evid', $regEvid); |
||
416 | $answerObj->setVar('text', $answer); |
||
417 | $answerObj->setVar('datecreated', \time()); |
||
418 | $answerObj->setVar('submitter', $regSubmitter); |
||
419 | // Insert Data |
||
420 | $answerHandler->insert($answerObj); |
||
421 | } |
||
422 | } |
||
423 | // TODO: Handle notification |
||
424 | // send notifications/confirmation emails |
||
425 | $infotextReg = ''; // info text for registered person |
||
426 | $infotextOrg = ''; // infotext for organizer |
||
427 | $previousMail = ''; |
||
428 | $newRegistration = false; |
||
429 | // create code for verification and showing single registration |
||
430 | $codeArr = [ |
||
431 | $newRegId, |
||
432 | \WGEVENTS_URL, |
||
433 | $regEvid, |
||
434 | $regEmail, |
||
435 | $regVerifkey |
||
436 | ]; |
||
437 | $code = base64_encode(implode('||', $codeArr)); |
||
438 | if ($regId > 0) { |
||
439 | // find changes in table registrations |
||
440 | $infotextReg = $registrationHandler->getRegistrationsCompare($registrationObjOld, $registrationObj); |
||
441 | if ('' !== $infotextReg) { |
||
442 | // create history |
||
443 | if ($registrationObjOld->getVar('email') != $registrationObj->getVar('email')) { |
||
444 | $previousMail = $registrationObjOld->getVar('email'); |
||
445 | } |
||
446 | $registrationhistHandler->createHistory($registrationObjOld, 'update'); |
||
447 | } |
||
448 | // find changes in table answers |
||
449 | if (\is_array($answersOld)) { |
||
450 | // get new answers for this questions |
||
451 | $answersNew = $answerHandler->getAnswersDetailsByRegistration($newRegId, $questionsArr); |
||
452 | $result = $answerHandler->getAnswersCompare($answersOld, $answersNew); |
||
453 | if ('' !== $result) { |
||
454 | // create history |
||
455 | $answerhistHandler->createHistory($regEvid, $regId, 'update'); |
||
456 | } |
||
457 | $infotextReg .= $result; |
||
458 | } |
||
459 | $infotextOrg = $infotextReg; |
||
460 | $singleRegLink = \WGEVENTS_URL . '/registration.php?op=show&verifkey=' . $code; |
||
461 | $infotextReg .= PHP_EOL . \sprintf(\_MA_WGEVENTS_MAIL_REG_SINGLE, $singleRegLink) . PHP_EOL; |
||
462 | // other params |
||
463 | $typeNotify = Constants::MAIL_REG_NOTIFY_MODIFY; |
||
464 | $typeConfirm = Constants::MAIL_REG_CONFIRM_MODIFY; |
||
465 | } else { |
||
466 | $newRegistration = true; |
||
467 | if (1 === $regListwait) { |
||
468 | // registration was put on a waiting list |
||
469 | $infotextReg .= \_MA_WGEVENTS_MAIL_REG_IN_LISTWAIT . PHP_EOL; |
||
470 | } |
||
471 | if (Constants::STATUS_SUBMITTED == $regStatus) { |
||
472 | // user has no permission for autoverify |
||
473 | $verifLink = \WGEVENTS_URL . '/verification.php?verifkey=' . $code; |
||
474 | $infotextReg .= \sprintf(\_MA_WGEVENTS_MAIL_REG_IN_VERIF, $verifLink) . PHP_EOL; |
||
475 | } |
||
476 | if (1 === $regListwait || Constants::STATUS_SUBMITTED == $regStatus) { |
||
477 | // registration was put on a waiting list |
||
478 | $infotextReg .= \_MA_WGEVENTS_MAIL_REG_IN_FINAL . PHP_EOL; |
||
479 | } |
||
480 | $singleRegLink = \WGEVENTS_URL . '/registration.php?op=show&verifkey=' . $code; |
||
481 | $infotextReg .= PHP_EOL . \sprintf(\_MA_WGEVENTS_MAIL_REG_SINGLE, $singleRegLink) . PHP_EOL; |
||
482 | $typeNotify = Constants::MAIL_REG_NOTIFY_IN; |
||
483 | $typeConfirm = Constants::MAIL_REG_CONFIRM_IN; |
||
484 | } |
||
485 | $showinfo = 0; |
||
486 | if ($newRegistration || '' !== $infotextReg) { |
||
487 | $mailsHandler = new MailHandler(); |
||
488 | $mailParams = $mailsHandler->getMailParam($eventObj, $newRegId); |
||
489 | unset($mailsHandler); |
||
490 | $registerNotify = (string)$eventObj->getVar('register_notify', 'e'); |
||
491 | if ('' !== $registerNotify) { |
||
492 | $mailParams['infotext'] = $infotextOrg; |
||
493 | // send notifications to emails of register_notify |
||
494 | $notifyEmails = $eventHandler->getRecipientsNotify($registerNotify); |
||
495 | if (\count($notifyEmails) > 0) { |
||
496 | foreach ($notifyEmails as $recipient) { |
||
497 | $taskHandler->createTask($typeNotify, $recipient, json_encode($mailParams)); |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | if (('' !== $regEmail && Request::getInt('email_send') > 0) || ('' !== $previousMail)) { |
||
502 | $mailParams['infotext'] = $infotextReg; |
||
503 | $showinfo = 1; |
||
504 | // send confirmation, if radio is checked |
||
505 | // or inform old email in any case if email changed |
||
506 | $recipients = []; |
||
507 | $recipients[] = $regEmail; |
||
508 | if ('' !== $previousMail) { |
||
509 | // add old email address if it changed in order to inform old mail address |
||
510 | $recipients[] = $previousMail; |
||
511 | } |
||
512 | foreach ($recipients as $recipient) { |
||
513 | $taskHandler->createTask($typeConfirm, $recipient, json_encode($mailParams)); |
||
514 | } |
||
515 | } |
||
516 | } |
||
517 | // excetue mail sending by task handler |
||
518 | $taskHandler->processTasks(); |
||
519 | // redirect after insert |
||
520 | \redirect_header('registration.php?op=' . $redir . '&redir=' . $redir . '&evid=' . $regEvid. '&showinfo=' . $showinfo, 2, \_MA_WGEVENTS_FORM_OK); |
||
521 | } |
||
522 | // Get Form Error |
||
523 | $GLOBALS['xoopsTpl']->assign('error', $registrationObj->getHtmlErrors()); |
||
524 | $form = $registrationObj->getForm(); |
||
525 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
526 | break; |
||
527 | case 'edit': |
||
528 | // Breadcrumbs |
||
529 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_REGISTRATION_EDIT]; |
||
530 | // Check params |
||
531 | if (0 === $regId) { |
||
532 | \redirect_header('registration.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
533 | } |
||
534 | $verifKey = Request::getString('verifkey'); |
||
535 | // Check permissions |
||
536 | $registrationObj = $registrationHandler->get($regId); |
||
537 | $eventObj = $eventHandler->get($registrationObj->getVar('evid')); |
||
538 | $permEdit = $permissionsHandler->getPermRegistrationsEdit($registrationObj->getVar('ip'), $registrationObj->getVar('submitter'), $eventObj->getVar('submitter'), $eventObj->getVar('status')); |
||
539 | if (!$permEdit) { |
||
540 | // check for valid verifKey |
||
541 | $verifKeyArray = explode('||', base64_decode($verifKey, true)); |
||
542 | if ($regId > 0 && \is_object($registrationObj) && \WGEVENTS_URL === (string)$verifKeyArray[1] && |
||
543 | (int)$registrationObj->getVar('evid') === (int)$verifKeyArray[2] && |
||
544 | (string)$registrationObj->getVar('email') === (string)$verifKeyArray[3] && |
||
545 | (string)$registrationObj->getVar('verifkey') === (string)$verifKeyArray[4]) { |
||
546 | $permEdit = true; |
||
547 | } |
||
548 | } |
||
549 | if (!$permEdit) { |
||
550 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
551 | } |
||
552 | if ('' !== $verifKey) { |
||
553 | $redir = 'listmy'; |
||
554 | } |
||
555 | // Get Form |
||
556 | $registrationObj->setRedir($redir); |
||
557 | $registrationObj->setVerifkeyEdit($verifKey); |
||
558 | $registrationObj->setStart = $start; |
||
559 | $registrationObj->setLimit = $limit; |
||
560 | $form = $registrationObj->getForm(); |
||
561 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
562 | break; |
||
563 | |||
564 | case 'clone': |
||
565 | echo 'noch nicht programmiert';die; |
||
566 | // Breadcrumbs |
||
567 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_REGISTRATION_CLONE]; |
||
568 | // Check permissions |
||
569 | if (!$permissionsHandler->getPermGlobalSubmit()) { |
||
570 | \redirect_header('registration.php?op=list', 3, \_NOPERM); |
||
571 | } |
||
572 | // Request source |
||
573 | $regIdSource = Request::getInt('id_source'); |
||
574 | // Check params |
||
575 | if (0 === $regIdSource) { |
||
576 | \redirect_header('registration.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
577 | } |
||
578 | // Get Form |
||
579 | $registrationObjSource = $registrationHandler->get($regIdSource); |
||
580 | $registrationObj = $registrationObjSource->xoopsClone(); |
||
581 | $form = $registrationObj->getForm(); |
||
582 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
583 | break; |
||
584 | case 'delete': |
||
585 | // Breadcrumbs |
||
586 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_REGISTRATION_DELETE]; |
||
587 | // Check params |
||
588 | if (0 === $regId) { |
||
589 | \redirect_header('index.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
590 | } |
||
591 | // Check permissions |
||
592 | $registrationObj = $registrationHandler->get($regId); |
||
593 | if (!\is_object($registrationObj)) { |
||
594 | \redirect_header('index.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
595 | } |
||
596 | $eventObj = $eventHandler->get($registrationObj->getVar('evid')); |
||
597 | |||
598 | $mailsHandler = new MailHandler(); |
||
599 | $mailParams = $mailsHandler->getMailParam($eventObj, $regId); |
||
600 | unset($mailsHandler); |
||
601 | |||
602 | $mailParams['email'] = $registrationObj->getVar('email'); |
||
603 | if (isset($_REQUEST['ok']) && 1 === (int)$_REQUEST['ok']) { |
||
604 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
605 | \redirect_header('registration.php', 3, \implode(', ', $GLOBALS['xoopsSecurity']->getErrors())); |
||
606 | } |
||
607 | // create history |
||
608 | $registrationhistHandler->createHistory($registrationObj, 'delete'); |
||
609 | if ($registrationHandler->delete($registrationObj)) { |
||
610 | // create history |
||
611 | $answerhistHandler->createHistory($mailParams['evId'], $regId, 'delete'); |
||
612 | //delete existing answers |
||
613 | $answerHandler->cleanupAnswers($mailParams['evId'], $regId); |
||
614 | // TODO: Event delete notification |
||
615 | // send notifications/confirmation emails |
||
616 | $registerNotify = (string)$eventObj->getVar('register_notify', 'e'); |
||
617 | if ('' !== $registerNotify) { |
||
618 | // send notifications to emails of register_notify |
||
619 | $notifyEmails = $eventHandler->getRecipientsNotify($registerNotify); |
||
620 | if (\count($notifyEmails) > 0) { |
||
621 | foreach ($notifyEmails as $recipient) { |
||
622 | $taskHandler->createTask(Constants::MAIL_REG_NOTIFY_OUT, $recipient, json_encode($mailParams)); |
||
623 | } |
||
624 | } |
||
625 | } |
||
626 | // send email in any case if email is available |
||
627 | if ('' !== (string)$mailParams['regEmail']) { |
||
628 | // send confirmation |
||
629 | $taskHandler->createTask(Constants::MAIL_REG_CONFIRM_OUT, $mailParams['regEmail'], json_encode($mailParams)); |
||
630 | } |
||
631 | // execute mail sending by task handler |
||
632 | $taskHandler->processTasks(); |
||
633 | \redirect_header('registration.php?op=' . $redir . '&redir=' . $redir . '&id=' . $regId . '&evid=' . $regEvid, 3, \_MA_WGEVENTS_FORM_DELETE_OK); |
||
634 | } else { |
||
635 | $GLOBALS['xoopsTpl']->assign('error', $registrationObj->getHtmlErrors()); |
||
636 | } |
||
637 | } else { |
||
638 | $customConfirm = new Common\Confirm( |
||
639 | ['ok' => 1, 'id' => $regId, 'evid' => $regEvid, 'op' => 'delete', 'redir' => $redir], |
||
640 | $_SERVER['REQUEST_URI'], |
||
641 | \sprintf(\_MA_WGEVENTS_CONFIRMDELETE_REGISTRATION, $mailParams['regFirstname'] . ' ' . $mailParams['regLastname']), |
||
642 | \_MA_WGEVENTS_CONFIRMDELETE_TITLE, |
||
643 | \_MA_WGEVENTS_CONFIRMDELETE_LABEL |
||
644 | ); |
||
645 | $form = $customConfirm->getFormConfirm(); |
||
646 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
647 | } |
||
648 | break; |
||
649 | case 'change_financial': |
||
650 | /* function is handled by registration_ajax.php */ |
||
651 | echo 'registration.php: function change_financial is not used anymore'; |
||
652 | die; |
||
653 | case 'listwait_takeover': |
||
654 | /* function is handled by registration_ajax.php */ |
||
655 | echo 'registration.php: function listwait_takeover is not used anymore'; |
||
656 | die; |
||
657 | case 'approve_status': |
||
658 | /* function is handled by registration_ajax.php */ |
||
659 | echo 'registration.php: function approve_status is not used anymore'; |
||
660 | die; |
||
661 | case 'contactall': |
||
662 | // Breadcrumbs |
||
663 | $xoBreadcrumbs[] = ['title' => \_MA_WGEVENTS_CONTACT_ALL]; |
||
664 | // Check params |
||
665 | if (0 === $regEvid) { |
||
666 | \redirect_header('registration.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
667 | } |
||
668 | // Get Form |
||
669 | $eventObj = $eventHandler->get($regEvid); |
||
670 | $form = $eventObj->getFormContactAll($eventObj->getVar('register_sendermail'), $eventObj->getVar('name')); |
||
671 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
672 | break; |
||
673 | case 'exec_contactall': |
||
674 | case 'exec_contactall_test': |
||
675 | // Security Check |
||
676 | if (!$GLOBALS['xoopsSecurity']->check()) { |
||
677 | \redirect_header('registration.php', 3, \implode(',', $GLOBALS['xoopsSecurity']->getErrors())); |
||
678 | } |
||
679 | // Check params |
||
680 | if (0 === $regEvid) { |
||
681 | \redirect_header('index.php?op=list', 3, \_MA_WGEVENTS_INVALID_PARAM); |
||
682 | } |
||
683 | |||
684 | $eventObj = $eventHandler->get($regEvid); |
||
685 | // Check permissions |
||
686 | if (!$permissionsHandler->getPermEventsEdit($eventObj->getVar('submitter'), $eventObj->getVar('status'))) { |
||
687 | \redirect_header('index.php?op=list', 3, \_NOPERM); |
||
688 | } |
||
689 | $crRegistration = new \CriteriaCompo(); |
||
690 | $crRegistration->add(new \Criteria('evid', $regEvid)); |
||
691 | $numberRegCurr = $registrationHandler->getCount($crRegistration); |
||
692 | $mailToArr = []; |
||
693 | if ($numberRegCurr > 0 && 'exec_contactall' === $op) { |
||
694 | $registrationsAll = $registrationHandler->getAll($crRegistration); |
||
695 | foreach (\array_keys($registrationsAll) as $i) { |
||
696 | $mailToArr[$registrationsAll[$i]->getVar('email')] = $registrationsAll[$i]->getVar('email'); |
||
697 | } |
||
698 | } |
||
699 | $mailFrom = Request::getString('mail_from'); |
||
700 | $mailSubject = Request::getString('mail_subject'); |
||
701 | $mailBody = Request::getText('mail_body'); |
||
702 | $mailCopy = Request::getInt('mail_copy'); |
||
703 | if (1 === $mailCopy) { |
||
704 | $mailToArr[$mailFrom] = $mailFrom; |
||
705 | } |
||
706 | $mailParams = []; |
||
707 | $mailParams['evId'] = $regEvid; |
||
708 | $mailParams['evName'] = $eventObj->getVar('name'); |
||
709 | $mailParams['evDatefrom'] = $eventObj->getVar('datefrom'); |
||
710 | $mailParams['evLocation'] = $eventObj->getVar('location'); |
||
711 | $mailParams['evSubmitter'] = $eventObj->getVar('submitter'); |
||
712 | $mailParams['evStatus'] = $eventObj->getVar('status'); |
||
713 | $mailParams['evRegister_sendermail'] = $eventObj->getVar('register_sendermail'); |
||
714 | $mailParams['evRegister_sendername'] = $eventObj->getVar('register_sendername'); |
||
715 | $mailParams['evRegister_signature'] = $eventObj->getVar('register_signature'); |
||
716 | $mailParams['mailFrom'] = $mailFrom; |
||
717 | $mailParams['mailSubject'] = $mailSubject; |
||
718 | $mailParams['mailBody'] = $mailBody; |
||
719 | |||
720 | foreach ($mailToArr as $mail) { |
||
721 | $taskHandler->createTask(Constants::MAIL_EVENT_NOTIFY_ALL, $mail, json_encode($mailParams)); |
||
722 | } |
||
723 | |||
724 | $result = $taskHandler->processTasks(); |
||
725 | $counterDone = (int)$result['done']; |
||
726 | $counterPending = (int)$result['pending']; |
||
727 | |||
728 | if ($counterDone > 0 || $counterPending > 0) { |
||
729 | if ('exec_contactall_test' === $op && $counterDone > 0) { |
||
730 | $eventObj = $eventHandler->get($regEvid); |
||
731 | $form = $eventObj->getFormContactAll($mailFrom, $mailSubject, $mailBody, $mailCopy); |
||
732 | $GLOBALS['xoopsTpl']->assign('warning', \_MA_WGEVENTS_CONTACT_ALL_TEST_SUCCESS); |
||
733 | $GLOBALS['xoopsTpl']->assign('form', $form->render()); |
||
734 | break; |
||
735 | } |
||
736 | // redirect after insert |
||
737 | $message = ''; |
||
738 | if ($counterDone > 0) { |
||
739 | $message .= sprintf( \_MA_WGEVENTS_CONTACT_ALL_SUCCESS, $counterDone) . '<br>'; |
||
740 | } |
||
741 | if ($counterPending > 0) { |
||
742 | $message .= sprintf( \_MA_WGEVENTS_CONTACT_ALL_PENDING, $counterDone) . '<br>'; |
||
743 | } |
||
744 | \redirect_header('registration.php?op=listeventall&evid=' . $regEvid, 3, $message); |
||
745 | } else { |
||
746 | \redirect_header('index.php?op=list', 3, 'exec_contactall:' . \_MA_WGEVENTS_INVALID_PARAM); |
||
747 | } |
||
748 | |||
749 | break; |
||
750 | } |
||
751 | |||
752 | // Keywords |
||
753 | wgeventsMetaKeywords($helper->getConfig('keywords') . ', ' . \implode(',', $keywords)); |
||
754 | unset($keywords); |
||
755 | |||
756 | // Description |
||
757 | wgeventsMetaDescription(\_MA_WGEVENTS_REGISTRATIONS_DESC); |
||
758 | $GLOBALS['xoopsTpl']->assign('xoops_mpageurl', \WGEVENTS_URL.'/registration.php'); |
||
759 | $GLOBALS['xoopsTpl']->assign('wgevents_upload_url', \WGEVENTS_UPLOAD_URL); |
||
760 | |||
761 | require __DIR__ . '/footer.php'; |
||
762 |