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