/** * Set the registration fields placeholders to the template * * @param \Cx\Core\Html\Sigma $objTpl Template instance * @param integer $regId Registration id */ function showRegistrationInputfields(\Cx\Core\Html\Sigma $objTpl, $regId = null) { global $_LANGID, $_ARRAYLANG; $i = 0; $objForm = new \Cx\Modules\Calendar\Controller\CalendarForm($this->formId); $objRegistration = new \Cx\Modules\Calendar\Controller\CalendarRegistration($this->formId, $regId); // parse the registration type for the add/edit subscription $regType = isset($_POST['registrationType']) ? (int) $_POST['registrationType'] : (!empty($regId) ? $objRegistration->type : 1); $regTypeField = '<select style="width: 208px;" class="calendarSelect" name="registrationType"> <option value="1" ' . ($regType == 1 ? "selected='selected'" : '') . ' />' . $_ARRAYLANG['TXT_CALENDAR_REG_REGISTRATION'] . '</option> <option value="0" ' . ($regType == 0 ? "selected='selected'" : '') . ' />' . $_ARRAYLANG['TXT_CALENDAR_REG_SIGNOFF'] . '</option> <option value="2" ' . ($regType == 2 ? "selected='selected'" : '') . ' />' . $_ARRAYLANG['TXT_CALENDAR_REG_WAITLIST'] . '</option> </select>'; $objTpl->setVariable(array($this->moduleLangVar . '_ROW' => $i % 2 == 0 ? 'row1' : 'row2', $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_NAME' => $_ARRAYLANG['TXT_CALENDAR_TYPE'], $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_VALUE' => $regTypeField)); $objTpl->parse('calendar_registration_inputfield'); $i++; if ($this->event && $this->event->seriesStatus && $this->event->independentSeries) { $endDate = new \DateTime(); $endDate->modify('+10 years'); $eventManager = new CalendarEventManager(null, $endDate); $objEvent = new \Cx\Modules\Calendar\Controller\CalendarEvent($this->event->id); if ($eventManager->_addToEventList($objEvent)) { $eventManager->eventList[] = $objEvent; } $eventManager->_setNextSeriesElement($objEvent); $regEventDateField = '<select style="width: 208px;" class="calendarSelect" name="registrationEventDate">'; foreach ($eventManager->eventList as $event) { $selectedDate = $objRegistration->eventDate == $event->startDate->getTimestamp() ? 'selected="selected"' : ''; $regEventDateField .= '<option value="' . $event->startDate->getTimestamp() . '" ' . $selectedDate . ' />' . $this->format2userDate($event->startDate) . '</option>'; } $regEventDateField .= '</select>'; $objTpl->setVariable(array($this->moduleLangVar . '_ROW' => $i % 2 == 0 ? 'row1' : 'row2', $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_NAME' => $_ARRAYLANG['TXT_CALENDAR_DATE_OF_THE_EVENT'], $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_VALUE' => $regEventDateField)); $objTpl->parse('calendar_registration_inputfield'); $i++; } foreach ($objForm->inputfields as $arrInputfield) { $inputfield = ''; $options = explode(',', $arrInputfield['default_value'][$_LANGID]); $optionSelect = true; if (isset($_POST['registrationField'][$arrInputfield['id']])) { $value = $_POST['registrationField'][$arrInputfield['id']]; } else { $value = $regId != null ? $objRegistration->fields[$arrInputfield['id']]['value'] : ''; } switch ($arrInputfield['type']) { case 'inputtext': case 'mail': case 'firstname': case 'lastname': $inputfield = '<input style="width: 200px;" type="text" class="calendarInputText" name="registrationField[' . $arrInputfield['id'] . ']" value="' . $value . '" />'; break; case 'textarea': $inputfield = '<textarea style="width: 196px;" class="calendarTextarea" name="registrationField[' . $arrInputfield['id'] . ']">' . $value . '</textarea>'; break; case 'seating': $optionSelect = false; case 'select': case 'salutation': $inputfield = '<select style="width: 208px;" class="calendarSelect" name="registrationField[' . $arrInputfield['id'] . ']">'; $selected = empty($_POST) ? 'selected="selected"' : ''; $inputfield .= $optionSelect ? '<option value="" ' . $selected . '>' . $_ARRAYLANG['TXT_CALENDAR_PLEASE_CHOOSE'] . '</option>' : ''; foreach ($options as $key => $name) { $selected = $key + 1 == $value ? 'selected="selected"' : ''; $inputfield .= '<option value="' . intval($key + 1) . '" ' . $selected . '>' . $name . '</option>'; } $inputfield .= '</select>'; break; case 'radio': $arrValue = explode('[[', $value); $value = $arrValue[0]; $input = str_replace(']]', '', $arrValue[1]); foreach ($options as $key => $name) { $checked = $key + 1 == $value || in_array($key + 1, $_POST['registrationField'][$arrInputfield['id']]) ? 'checked="checked"' : ''; $textfield = '<input type="text" class="calendarInputCheckboxAdditional" name="registrationFieldAdditional[' . $arrInputfield['id'] . '][' . $key . ']" value="' . ($checked ? $input : '') . '" />'; $name = str_replace('[[INPUT]]', $textfield, $name); $inputfield .= '<input type="radio" class="calendarInputCheckbox" name="registrationField[' . $arrInputfield['id'] . ']" value="' . intval($key + 1) . '" ' . $checked . '/> ' . $name . '<br />'; } break; case 'checkbox': $results = explode(',', $value); foreach ($results as $result) { list($value, $input) = explode('[[', $result); $value = !empty($value) ? $value : 0; $input = str_replace(']]', '', $input); $newResult[$value] = $input; } foreach ($options as $key => $name) { $checked = array_key_exists($key + 1, $newResult) || in_array($key + 1, $_POST['registrationField'][$arrInputfield['id']]) ? 'checked="checked"' : ''; $textfield = '<input type="text" class="calendarInputCheckboxAdditional" name="registrationFieldAdditional[' . $arrInputfield['id'] . '][' . $key . ']" value="' . ($checked ? $newResult[$key + 1] : '') . '" />'; $name = str_replace('[[INPUT]]', $textfield, $name); $inputfield .= '<input ' . $checked . ' type="checkbox" class="calendarInputCheckbox" name="registrationField[' . $arrInputfield['id'] . '][]" value="' . intval($key + 1) . '" /> ' . $name . '<br />'; } break; case 'agb': $checked = $value ? "checked='checked'" : ''; $inputfield = '<input ' . $checked . ' class="calendarInputCheckbox" type="checkbox" name="registrationField[' . $arrInputfield['id'] . '][]" value="1" /> ' . $_ARRAYLANG['TXT_CALENDAR_AGB'] . '<br />'; break; } if ($arrInputfield['type'] != 'fieldset') { $objTpl->setVariable(array($this->moduleLangVar . '_ROW' => $i % 2 == 0 ? 'row1' : 'row2', $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_NAME' => $arrInputfield['name'][$_LANGID], $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_REQUIRED' => $arrInputfield['required'] == 1 ? '<font class="calendarRequired"> *</font>' : '', $this->moduleLangVar . '_REGISTRATION_INPUTFIELD_VALUE' => $inputfield)); $objTpl->parse('calendar_registration_inputfield'); $i++; } } }
/** * Save the registration * * @param array $data posted data from the form * * @return boolean true if the registration saved, false otherwise */ function save($data) { global $objDatabase, $objInit, $_LANGID; /* foreach ($this->form->inputfields as $key => $arrInputfield) { if($arrInputfield['type'] == 'selectBillingAddress') { $affiliationStatus = $data['registrationField'][$arrInputfield['id']]; } } */ foreach ($this->form->inputfields as $key => $arrInputfield) { /* if($affiliationStatus == 'sameAsContact') { if($arrInputfield['required'] == 1 && empty($data['registrationField'][$arrInputfield['id']]) && $arrInputfield['affiliation'] != 'billing') { return false; } if($arrInputfield['required'] == 1 && $arrInputfield['type'] == 'mail' && $arrInputfield['affiliation'] != 'billing') { $objValidator = new FWValidator(); if(!$objValidator->isEmail($data['registrationField'][$arrInputfield['id']])) { return false; } } } else { */ if ($arrInputfield['required'] == 1 && empty($data['registrationField'][$arrInputfield['id']])) { return false; } if ($arrInputfield['required'] == 1 && $arrInputfield['type'] == 'mail') { $objValidator = new \FWValidator(); if (!$objValidator->isEmail($data['registrationField'][$arrInputfield['id']])) { return false; } } /* } */ } $regId = intval($data['regid']); $eventId = intval($data['id']); $formId = intval($data['form']); $eventDate = intval($data['date']); $userId = intval($data['userid']); $objEvent = new \Cx\Modules\Calendar\Controller\CalendarEvent($eventId); if ($objEvent->seriesStatus && $objEvent->independentSeries) { $eventDate = isset($data['registrationEventDate']) ? contrexx_input2int($data['registrationEventDate']) : $eventDate; $endDate = new \DateTime(); $endDate->modify('+10 years'); $eventManager = new CalendarEventManager(null, $endDate); $eventManager->getEvent($objEvent, $eventDate, true); $objEvent = $eventManager->eventList[0]; if (empty($objEvent)) { return false; } } $query = ' SELECT `id` FROM `' . DBPREFIX . 'module_' . $this->moduleTablePrefix . '_registration_form_field` WHERE `form` = ' . $formId . ' AND `type` = "seating" LIMIT 1 '; $objResult = $objDatabase->Execute($query); $numSeating = intval($data['registrationField'][$objResult->fields['id']]); $type = empty($regId) && intval($objEvent->getFreePlaces() - $numSeating) < 0 ? 2 : (isset($data['registrationType']) ? intval($data['registrationType']) : 1); $this->saveIn = intval($type); $paymentMethod = intval($data['paymentMethod']); $paid = intval($data['paid']); $hostName = 0; $ipAddress = 0; $key = $this->generateKey(); if ($regId == 0) { $submissionDate = $this->getDbDateTimeFromIntern($this->getInternDateTimeFromUser()); $query = 'INSERT INTO ' . DBPREFIX . 'module_' . $this->moduleTablePrefix . '_registration SET `event_id` = ' . $eventId . ', `submission_date` = "' . $submissionDate->format('Y-m-d H:i:s') . '", `date` = ' . $eventDate . ', `host_name` = "' . $hostName . '", `ip_address` = "' . $ipAddress . '", `type` = ' . $type . ', `key` = "' . $key . '", `user_id` = ' . $userId . ', `lang_id` = ' . $_LANGID . ', `export` = 0, `payment_method` = ' . $paymentMethod . ', `paid` = ' . $paid . ' '; $objResult = $objDatabase->Execute($query); if ($objResult !== false) { $this->id = $objDatabase->Insert_ID(); } else { return false; } } else { $query = 'UPDATE `' . DBPREFIX . 'module_' . $this->moduleTablePrefix . '_registration` SET `event_id` = ' . $eventId . ', `date` = ' . $eventDate . ', `host_name` = ' . $hostName . ', `ip_address` = ' . $ipAddress . ', `key` = "' . $key . '", `user_id` = ' . $userId . ', `type` = ' . $type . ', `lang_id` = ' . $_LANGID . ', `payment_method` = ' . $paymentMethod . ', `paid` = ' . $paid . ' WHERE `id` = ' . $regId; $objResult = $objDatabase->Execute($query); if ($objResult === false) { return false; } } if ($regId != 0) { $this->id = $regId; $deleteQuery = 'DELETE FROM ' . DBPREFIX . 'module_' . $this->moduleTablePrefix . '_registration_form_field_value WHERE `reg_id` = ' . $this->id; $objDeleteResult = $objDatabase->Execute($deleteQuery); if ($objDeleteResult === false) { return false; } } foreach ($this->form->inputfields as $key => $arrInputfield) { $value = $data['registrationField'][$arrInputfield['id']]; $id = $arrInputfield['id']; if (is_array($value)) { $subvalue = array(); foreach ($value as $key => $element) { if (!empty($data['registrationFieldAdditional'][$id][$element - 1])) { $subvalue[] = $element . '[[' . $data['registrationFieldAdditional'][$id][$element - 1] . ']]'; } else { $subvalue[] = $element; } } $value = join(",", $subvalue); } else { if (isset($data['registrationFieldAdditional'][$id][$value - 1])) { $value = $value . "[[" . $data['registrationFieldAdditional'][$id][$value - 1] . "]]"; } } $query = 'INSERT INTO ' . DBPREFIX . 'module_' . $this->moduleTablePrefix . '_registration_form_field_value (`reg_id`, `field_id`, `value`) VALUES (' . $this->id . ', ' . $id . ', "' . contrexx_input2db($value) . '")'; $objResult = $objDatabase->Execute($query); if ($objResult === false) { return false; } } if ($objInit->mode == 'frontend') { $objMailManager = new \Cx\Modules\Calendar\Controller\CalendarMailManager(); $templateId = $objEvent->emailTemplate[FRONTEND_LANG_ID]; $objMailManager->sendMail($objEvent, \Cx\Modules\Calendar\Controller\CalendarMailManager::MAIL_CONFIRM_REG, $this->id, $templateId); $objMailManager->sendMail($objEvent, \Cx\Modules\Calendar\Controller\CalendarMailManager::MAIL_ALERT_REG, $this->id); } return true; }