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