/** * Add / Edit Event * * @param integer $eventId Event id * * @return null */ function modifyEvent($eventId = null) { global $_ARRAYLANG, $_CORELANG, $_LANGID; \JS::activate('cx'); \JS::activate('jqueryui'); \JS::registerJS('modules/Calendar/View/Script/Frontend.js'); $this->getFrontendLanguages(); $this->getSettings(); $this->_objTpl->setTemplate($this->pageContent, true, true); $showFrom = true; $objEvent = new \Cx\Modules\Calendar\Controller\CalendarEvent(); $isEventLoaded = false; if (isset($_POST['submitFormModifyEvent'])) { $arrData = array(); $arrData = $_POST; $arrData['access'] = 0; $arrData['priority'] = 3; if ($objEvent->save($arrData)) { $showFrom = false; $this->_objTpl->hideBlock('calendarEventModifyForm'); $this->_objTpl->touchBlock('calendarEventOkMessage'); // refresh event data after save $objEvent->get($eventId); $objEvent->getData(); $isEventLoaded = true; $objMailManager = new \Cx\Modules\Calendar\Controller\CalendarMailManager(); $objMailManager->sendMail($objEvent, \Cx\Modules\Calendar\Controller\CalendarMailManager::MAIL_NOTFY_NEW_APP); } else { $this->_objTpl->touchBlock('calendarEventErrMessage'); } } if ($eventId && !$isEventLoaded) { $objEvent->get($eventId); $objEvent->getData(); } $dateFormat = $this->getDateFormat(1); $locationType = $this->arrSettings['placeData'] == 3 ? $eventId != 0 ? $objEvent->locationType : 1 : $this->arrSettings['placeData']; $hostType = $this->arrSettings['placeDataHost'] == 3 ? $eventId != 0 ? $objEvent->hostType : 1 : $this->arrSettings['placeDataHost']; \ContrexxJavascript::getInstance()->setVariable(array('language_id' => \FWLanguage::getDefaultLangId(), 'active_lang' => implode(',', \FWLanguage::getIdArray())), 'calendar'); $javascript = <<<EOF <script language="JavaScript" type="text/javascript"> var defaultLang = cx.variables.get('language_id', 'calendar'); var activeLang = [cx.variables.get('active_lang', 'calendar')]; cx.ready(function() { var options = { dateFormat: '{$dateFormat}', timeFormat: 'hh:mm', showSecond: false, onSelect: function(dateText, inst){ var startDate = cx.jQuery( ".startDate" ).datetimepicker("getDate"); var endDate = cx.jQuery( ".endDate" ).datetimepicker("getDate"); if ( cx.jQuery( this )[0].id == 'startDate' ) { var prevStartDate = cx.jQuery( ".startDate" ).data('prevDate'); if (cx.jQuery(".all_day").is(':checked')) { prevStartDate.setHours(0, 0, 0); startDate.setHours(0, 0, 0); endDate.setHours(0, 0, 0); } if (prevStartDate.getTime() != startDate.getTime()) { var timeDiff = Math.abs(endDate.getTime() - prevStartDate.getTime()); endDate = new Date(startDate.getTime() + timeDiff); cx.jQuery( ".endDate" ).datetimepicker('setDate', endDate); } } else if (startDate.getTime() > endDate.getTime()) { endDate = new Date(startDate.getTime() + (30*60*1000)); cx.jQuery(".endDate").datetimepicker('setDate', endDate); } cx.jQuery( ".startDate" ).data('prevDate', cx.jQuery(".startDate").datetimepicker("getDate")); cx.jQuery( ".endDate" ).data('prevDate', cx.jQuery(".endDate").datetimepicker("getDate")); cx.jQuery( this ).datetimepicker('refresh'); } }; cx.jQuery('input[name=startDate]') .datetimepicker(options) .data('prevDate', cx.jQuery(".startDate").datetimepicker("getDate")); cx.jQuery('input[name=endDate]') .datetimepicker(options) .data('prevDate', cx.jQuery(".endDate").datetimepicker("getDate")); if ( \$J(".all_day").is(':checked') ) { modifyEvent._handleAllDayEvent( \$J(".all_day") ); } showOrHidePlaceFields('{$locationType}', 'place'); showOrHidePlaceFields('{$hostType}', 'host'); }); </script> EOF; if ($showFrom) { try { $javascript .= <<<UPLOADER {$this->getUploaderCode(self::PICTURE_FIELD_KEY, 'pictureUpload')} {$this->getUploaderCode(self::MAP_FIELD_KEY, 'mapUpload')} {$this->getUploaderCode(self::ATTACHMENT_FIELD_KEY, 'attachmentUpload', 'uploadFinished', false)} UPLOADER; } catch (Exception $e) { \DBG::msg("Error in initializing uploader"); } } $this->_objTpl->setGlobalVariable(array($this->moduleLangVar . '_EVENT_LANG_ID' => $_LANGID, $this->moduleLangVar . '_JAVASCRIPT' => $javascript)); $objCategoryManager = new \Cx\Modules\Calendar\Controller\CalendarCategoryManager(true); $objCategoryManager->getCategoryList(); if ($eventId) { $startDate = $objEvent->startDate; $endDate = $objEvent->endDate; } else { $startDate = new \DateTime(); $endDate = new \DateTime(); } $eventStartDate = $this->format2userDateTime($startDate); $eventEndDate = $this->format2userDateTime($endDate); $this->_objTpl->setGlobalVariable(array('TXT_' . $this->moduleLangVar . '_EVENT' => $_ARRAYLANG['TXT_CALENDAR_EVENT'], 'TXT_' . $this->moduleLangVar . '_EVENT_DETAILS' => $_ARRAYLANG['TXT_CALENDAR_EVENT_DETAILS'], 'TXT_' . $this->moduleLangVar . '_SAVE' => $_ARRAYLANG['TXT_CALENDAR_SAVE'], 'TXT_' . $this->moduleLangVar . '_EVENT_START' => $_ARRAYLANG['TXT_CALENDAR_START'], 'TXT_' . $this->moduleLangVar . '_EVENT_END' => $_ARRAYLANG['TXT_CALENDAR_END'], 'TXT_' . $this->moduleLangVar . '_EVENT_TITLE' => $_ARRAYLANG['TXT_CALENDAR_TITLE'], 'TXT_' . $this->moduleLangVar . '_EXPAND' => $_ARRAYLANG['TXT_CALENDAR_EXPAND'], 'TXT_' . $this->moduleLangVar . '_MINIMIZE' => $_ARRAYLANG['TXT_CALENDAR_MINIMIZE'], 'TXT_' . $this->moduleLangVar . '_EVENT_PLACE' => $_ARRAYLANG['TXT_CALENDAR_EVENT_PLACE'], 'TXT_' . $this->moduleLangVar . '_EVENT_STREET' => $_ARRAYLANG['TXT_CALENDAR_EVENT_STREET'], 'TXT_' . $this->moduleLangVar . '_EVENT_ZIP' => $_ARRAYLANG['TXT_CALENDAR_EVENT_ZIP'], 'TXT_' . $this->moduleLangVar . '_EVENT_CITY' => $_ARRAYLANG['TXT_CALENDAR_EVENT_CITY'], 'TXT_' . $this->moduleLangVar . '_EVENT_COUNTRY' => $_ARRAYLANG['TXT_CALENDAR_EVENT_COUNTRY'], 'TXT_' . $this->moduleLangVar . '_EVENT_WEBSITE' => $_ARRAYLANG['TXT_CALENDAR_EVENT_WEBSITE'], 'TXT_' . $this->moduleLangVar . '_EVENT_PHONE' => $_ARRAYLANG['TXT_CALENDAR_EVENT_PHONE'], 'TXT_' . $this->moduleLangVar . '_EVENT_MAP' => $_ARRAYLANG['TXT_CALENDAR_EVENT_MAP'], 'TXT_' . $this->moduleLangVar . '_EVENT_USE_GOOGLEMAPS' => $_ARRAYLANG['TXT_CALENDAR_EVENT_USE_GOOGLEMAPS'], 'TXT_' . $this->moduleLangVar . '_EVENT_LINK' => $_ARRAYLANG['TXT_CALENDAR_EVENT_LINK'], 'TXT_' . $this->moduleLangVar . '_EVENT_EMAIL' => $_ARRAYLANG['TXT_CALENDAR_EVENT_EMAIL'], 'TXT_' . $this->moduleLangVar . '_EVENT_PICTURE' => $_ARRAYLANG['TXT_CALENDAR_EVENT_PICTURE'], 'TXT_' . $this->moduleLangVar . '_EVENT_ATTACHMENT' => $_ARRAYLANG['TXT_CALENDAR_EVENT_ATTACHMENT'], 'TXT_' . $this->moduleLangVar . '_EVENT_CATEGORY' => $_ARRAYLANG['TXT_CALENDAR_CAT'], 'TXT_' . $this->moduleLangVar . '_EVENT_DESCRIPTION' => $_ARRAYLANG['TXT_CALENDAR_EVENT_DESCRIPTION'], 'TXT_' . $this->moduleLangVar . '_PLEASE_CHECK_INPUT' => $_ARRAYLANG['TXT_CALENDAR_PLEASE_CHECK_INPUT'], 'TXT_' . $this->moduleLangVar . '_EVENT_HOST' => $_ARRAYLANG['TXT_CALENDAR_EVENT_HOST'], 'TXT_' . $this->moduleLangVar . '_EVENT_NAME' => $_ARRAYLANG['TXT_CALENDAR_EVENT_NAME'], 'TXT_' . $this->moduleLangVar . '_EVENT_ALL_DAY' => $_ARRAYLANG['TXT_CALENDAR_EVENT_ALL_DAY'], 'TXT_' . $this->moduleLangVar . '_LANGUAGE' => $_ARRAYLANG['TXT_CALENDAR_LANG'], 'TXT_' . $this->moduleLangVar . '_EVENT_TYPE' => $_ARRAYLANG['TXT_CALENDAR_EVENT_TYPE'], 'TXT_' . $this->moduleLangVar . '_EVENT_TYPE_EVENT' => $_ARRAYLANG['TXT_CALENDAR_EVENT_TYPE_EVENT'], 'TXT_' . $this->moduleLangVar . '_EVENT_TYPE_REDIRECT' => $_ARRAYLANG['TXT_CALENDAR_EVENT_TYPE_REDIRECT'], 'TXT_' . $this->moduleLangVar . '_EVENT_DESCRIPTION' => $_ARRAYLANG['TXT_CALENDAR_EVENT_DESCRIPTION'], 'TXT_' . $this->moduleLangVar . '_EVENT_REDIRECT' => $_ARRAYLANG['TXT_CALENDAR_EVENT_TYPE_REDIRECT'], 'TXT_' . $this->moduleLangVar . '_PLACE_DATA_DEFAULT' => $_ARRAYLANG['TXT_CALENDAR_PLACE_DATA_DEFAULT'], 'TXT_' . $this->moduleLangVar . '_PLACE_DATA_FROM_MEDIADIR' => $_ARRAYLANG['TXT_CALENDAR_PLACE_DATA_FROM_MEDIADIR'], 'TXT_' . $this->moduleLangVar . '_PREV' => $_ARRAYLANG['TXT_CALENDAR_PREV'], 'TXT_' . $this->moduleLangVar . '_NEXT' => $_ARRAYLANG['TXT_CALENDAR_NEXT'], 'TXT_' . $this->moduleLangVar . '_MORE' => $_ARRAYLANG['TXT_CALENDAR_MORE'], 'TXT_' . $this->moduleLangVar . '_MINIMIZE' => $_ARRAYLANG['TXT_CALENDAR_MINIMIZE'], $this->moduleLangVar . '_EVENT_TYPE_EVENT' => $eventId != 0 ? $objEvent->type == 0 ? 'selected="selected"' : '' : '', $this->moduleLangVar . '_EVENT_TYPE_REDIRECT' => $eventId != 0 ? $objEvent->type == 1 ? 'selected="selected"' : '' : '', $this->moduleLangVar . '_EVENT_START_DATE' => $eventStartDate, $this->moduleLangVar . '_EVENT_END_DATE' => $eventEndDate, $this->moduleLangVar . '_EVENT_PICTURE' => $objEvent->pic, $this->moduleLangVar . '_EVENT_PICTURE_THUMB' => $objEvent->pic != '' ? '<img src="' . $objEvent->pic . '.thumb" alt="' . $objEvent->title . '" title="' . $objEvent->title . '" />' : '', $this->moduleLangVar . '_EVENT_ATTACHMENT' => $objEvent->attach, $this->moduleLangVar . '_EVENT_CATEGORIES' => $objCategoryManager->getCategoryDropdown(intval($objEvent->catId), 2), $this->moduleLangVar . '_EVENT_LINK' => $objEvent->link, $this->moduleLangVar . '_EVENT_PLACE' => $objEvent->place, $this->moduleLangVar . '_EVENT_STREET' => $objEvent->place_street, $this->moduleLangVar . '_EVENT_ZIP' => $objEvent->place_zip, $this->moduleLangVar . '_EVENT_CITY' => $objEvent->place_city, $this->moduleLangVar . '_EVENT_COUNTRY' => $objEvent->place_country, $this->moduleLangVar . '_EVENT_PLACE_WEBSITE' => $objEvent->place_website, $this->moduleLangVar . '_EVENT_PLACE_MAP' => $objEvent->place_map, $this->moduleLangVar . '_EVENT_PLACE_LINK' => $objEvent->place_link, $this->moduleLangVar . '_EVENT_PLACE_PHONE' => $objEvent->place_phone, $this->moduleLangVar . '_EVENT_MAP' => $objEvent->google == 1 ? 'checked="checked"' : '', $this->moduleLangVar . '_EVENT_HOST' => $objEvent->org_name, $this->moduleLangVar . '_EVENT_HOST_ADDRESS' => $objEvent->org_street, $this->moduleLangVar . '_EVENT_HOST_ZIP' => $objEvent->org_zip, $this->moduleLangVar . '_EVENT_HOST_CITY' => $objEvent->org_city, $this->moduleLangVar . '_EVENT_HOST_COUNTRY' => $objEvent->org_country, $this->moduleLangVar . '_EVENT_HOST_WEBSITE' => $objEvent->org_website, $this->moduleLangVar . '_EVENT_HOST_LINK' => $objEvent->org_link, $this->moduleLangVar . '_EVENT_HOST_PHONE' => $objEvent->org_phone, $this->moduleLangVar . '_EVENT_HOST_EMAIL' => $objEvent->org_email, $this->moduleLangVar . '_EVENT_LOCATION_TYPE_MANUAL' => $eventId != 0 ? $objEvent->locationType == 1 ? "checked='checked'" : '' : "checked='checked'", $this->moduleLangVar . '_EVENT_LOCATION_TYPE_MEDIADIR' => $eventId != 0 ? $objEvent->locationType == 2 ? "checked='checked'" : '' : "", $this->moduleLangVar . '_EVENT_HOST_TYPE_MANUAL' => $eventId != 0 ? $objEvent->hostType == 1 ? "checked='checked'" : '' : "checked='checked'", $this->moduleLangVar . '_EVENT_HOST_TYPE_MEDIADIR' => $eventId != 0 ? $objEvent->hostType == 2 ? "checked='checked'" : '' : "", $this->moduleLangVar . '_EVENT_ID' => $eventId, $this->moduleLangVar . '_EVENT_ALL_DAY' => $eventId != 0 && $objEvent->all_day ? 'checked="checked"' : '', $this->moduleLangVar . '_HIDE_ON_SINGLE_LANG' => count($this->arrFrontendLanguages) == 1 ? "display: none;" : "")); $multiLingualFields = array('place', 'place_city', 'place_country', 'org_name', 'org_city', 'org_country'); $isOneActiveLanguage = count($this->arrFrontendLanguages) == 1; foreach ($multiLingualFields as $inputField) { if ($isOneActiveLanguage) { $this->_objTpl->hideBlock('calendar_event_' . $inputField . '_expand'); } else { $this->_objTpl->touchBlock('calendar_event_' . $inputField . '_expand'); } } foreach ($this->arrFrontendLanguages as $arrLang) { //parse globals $this->_objTpl->setGlobalVariable(array($this->moduleLangVar . '_EVENT_LANG_SHORTCUT' => $arrLang['lang'], $this->moduleLangVar . '_EVENT_LANG_ID' => $arrLang['id'], 'TXT_' . $this->moduleLangVar . '_EVENT_LANG_NAME' => $arrLang['name'])); //parse "show in" checkboxes $arrShowIn = explode(",", $objEvent->showIn); $langChecked = false; if ($eventId != 0) { $langChecked = in_array($arrLang['id'], $arrShowIn) ? true : false; } else { $langChecked = $arrLang['is_default'] == 'true'; } //parse eventTabMenuDescTab $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_TAB_DISPLAY' => $langChecked ? 'block' : 'none', $this->moduleLangVar . '_EVENT_TAB_CLASS' => '')); $this->_objTpl->parse('eventTabMenuDescTab'); //parse eventDescTab $eventTitle = !empty($objEvent->arrData['title'][$arrLang['id']]) ? $objEvent->arrData['title'][$arrLang['id']] : (!empty($objEvent->arrData['redirect'][$_LANGID]) ? $objEvent->arrData['redirect'][$_LANGID] : ''); $eventDescription = !empty($objEvent->arrData['description'][$arrLang['id']]) ? $objEvent->arrData['description'][$arrLang['id']] : ''; $eventRedirect = !empty($objEvent->arrData['redirect'][$arrLang['id']]) ? $objEvent->arrData['redirect'][$arrLang['id']] : (!empty($objEvent->arrData['redirect'][$_LANGID]) ? $objEvent->arrData['redirect'][$_LANGID] : ''); $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_TAB_DISPLAY' => $langChecked ? 'block' : 'none', $this->moduleLangVar . '_EVENT_TITLE' => contrexx_raw2xhtml($eventTitle), $this->moduleLangVar . '_EVENT_DESCRIPTION' => new \Cx\Core\Wysiwyg\Wysiwyg("description[{$arrLang['id']}]", contrexx_raw2xhtml($eventDescription), $eventId != 0 ? 'small' : 'bbcode'), $this->moduleLangVar . '_EVENT_REDIRECT' => contrexx_raw2xhtml($eventRedirect), $this->moduleLangVar . '_EVENT_TYPE_EVENT_DISPLAY' => $objEvent->type == 0 ? 'block' : 'none', $this->moduleLangVar . '_EVENT_TYPE_REDIRECT_DISPLAY' => $objEvent->type == 1 ? 'block' : 'none')); $this->_objTpl->parse('eventDescTab'); //parse eventLingualFields foreach ($multiLingualFields as $inputField) { $this->_objTpl->setVariable($this->moduleLangVar . '_EVENT_' . strtoupper($inputField) . '_DEFAULT', $eventId != 0 ? $objEvent->{$inputField} : ''); $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_VALUE' => !empty($objEvent->arrData[$inputField][$arrLang['id']]) ? $objEvent->arrData[$inputField][$arrLang['id']] : ($eventId != 0 ? $objEvent->{$inputField} : ''))); $this->_objTpl->parse('calendar_event_' . $inputField); } $langChecked = $langChecked ? 'checked="checked"' : ''; $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_LANG_CHECKED' => $langChecked)); $this->_objTpl->parse('eventShowIn'); } //parse placeSelect if ((int) $this->arrSettings['placeData'] > 1) { $objMediadirEntries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry('MediaDir'); $objMediadirEntries->getEntries(null, null, null, null, null, null, true, 0, 'n', null, null, intval($this->arrSettings['placeDataForm'])); $placeOptions = '<option value="">' . $_ARRAYLANG['TXT_CALENDAR_PLEASE_CHOOSE'] . '</option>'; foreach ($objMediadirEntries->arrEntries as $key => $arrEntry) { $selectedPlace = $arrEntry['entryId'] == $objEvent->place_mediadir_id ? 'selected="selected"' : ''; $placeOptions .= '<option ' . $selectedPlace . ' value="' . $arrEntry['entryId'] . '">' . $arrEntry['entryFields'][0] . '</option>'; } $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_PLACE_OPTIONS' => $placeOptions)); $this->_objTpl->parse('eventPlaceSelect'); if ((int) $this->arrSettings['placeData'] == 2) { $this->_objTpl->hideBlock('eventPlaceInput'); $this->_objTpl->hideBlock('eventPlaceTypeRadio'); } else { $this->_objTpl->touchBlock('eventPlaceInput'); $this->_objTpl->touchBlock('eventPlaceTypeRadio'); } } else { $this->_objTpl->touchBlock('eventPlaceInput'); $this->_objTpl->hideBlock('eventPlaceSelect'); $this->_objTpl->hideBlock('eventPlaceTypeRadio'); } //parse placeHostSelect if ((int) $this->arrSettings['placeDataHost'] > 1) { $objMediadirEntries = new \Cx\Modules\MediaDir\Controller\MediaDirectoryEntry('MediaDir'); $objMediadirEntries->getEntries(null, null, null, null, null, null, true, 0, 'n', null, null, intval($this->arrSettings['placeDataHostForm'])); $placeOptions = '<option value="">' . $_ARRAYLANG['TXT_CALENDAR_PLEASE_CHOOSE'] . '</option>'; foreach ($objMediadirEntries->arrEntries as $key => $arrEntry) { $selectedPlace = $arrEntry['entryId'] == $objEvent->host_mediadir_id ? 'selected="selected"' : ''; $placeOptions .= '<option ' . $selectedPlace . ' value="' . $arrEntry['entryId'] . '">' . $arrEntry['entryFields'][0] . '</option>'; } $this->_objTpl->setVariable(array($this->moduleLangVar . '_EVENT_PLACE_OPTIONS' => $placeOptions)); $this->_objTpl->parse('eventHostSelect'); if ((int) $this->arrSettings['placeDataHost'] == 2) { $this->_objTpl->hideBlock('eventHostInput'); $this->_objTpl->hideBlock('eventHostTypeRadio'); } else { $this->_objTpl->touchBlock('eventHostInput'); $this->_objTpl->touchBlock('eventHostTypeRadio'); } } else { $this->_objTpl->touchBlock('eventHostInput'); $this->_objTpl->hideBlock('eventHostSelect'); $this->_objTpl->hideBlock('eventHostTypeRadio'); } }
/** * Save the event to the database * * @param array $data * * @return boolean true if saved successfully, false otherwise */ function save($data) { global $objDatabase, $_LANGID, $_CONFIG, $objInit; parent::getSettings(); if (empty($data['startDate']) || empty($data['endDate']) || empty($data['category']) || $data['seriesStatus'] == 1 && $data['seriesType'] == 2 && empty($data['seriesWeeklyDays'])) { return false; } foreach ($_POST['showIn'] as $key => $langId) { if (empty($_POST['title'][$langId]) && empty($_POST['title'][$_LANGID])) { return false; } } list($startDate, $strStartTime) = explode(' ', $data['startDate']); list($startHour, $startMin) = explode(':', $strStartTime); list($endDate, $strEndTime) = explode(' ', $data['endDate']); list($endHour, $endMin) = explode(':', $strEndTime); if ($data['all_day']) { list($startHour, $startMin) = array(0, 0); list($endHour, $endMin) = array(23, 59); } //event data $id = isset($data['copy']) && !empty($data['copy']) ? 0 : (isset($data['id']) ? intval($data['id']) : 0); $type = isset($data['type']) ? intval($data['type']) : 0; $startDate = date("Y-m-d H:i:s", parent::getDateTimestamp($startDate, intval($startHour), intval($startMin))); $endDate = date("Y-m-d H:i:s", parent::getDateTimestamp($endDate, intval($endHour), intval($endMin))); $google = isset($data['map'][$_LANGID]) ? intval($data['map'][$_LANGID]) : 0; $allDay = isset($data['all_day']) ? 1 : 0; $convertBBCode = $objInit->mode == 'frontend' && empty($id); $useCustomDateDisplay = isset($data['showDateSettings']) ? 1 : 0; $showStartDateList = isset($data['showStartDateList']) ? $data['showStartDateList'] : 0; $showEndDateList = isset($data['showEndDateList']) ? $data['showEndDateList'] : 0; if ($objInit->mode == 'backend') { // reset time values if "no time" is selected if ($data['showTimeTypeList'] == 0) { $showStartTimeList = 0; $showEndTimeList = 0; } else { $showStartTimeList = isset($data['showStartTimeList']) ? $data['showStartTimeList'] : ''; $showEndTimeList = isset($data['showEndTimeList']) ? $data['showEndTimeList'] : ''; } $showTimeTypeList = isset($data['showTimeTypeList']) ? $data['showTimeTypeList'] : ''; $showStartDateDetail = isset($data['showStartDateDetail']) ? $data['showStartDateDetail'] : ''; $showEndDateDetail = isset($data['showEndDateDetail']) ? $data['showEndDateDetail'] : ''; // reset time values if "no time" is selected if ($data['showTimeTypeDetail'] == 0) { $showStartTimeDetail = 0; $showEndTimeDetail = 0; } else { $showStartTimeDetail = isset($data['showStartTimeDetail']) ? $data['showStartTimeDetail'] : ''; $showEndTimeDetail = isset($data['showEndTimeDetail']) ? $data['showEndTimeDetail'] : ''; } $showTimeTypeDetail = isset($data['showTimeTypeDetail']) ? $data['showTimeTypeDetail'] : ''; } else { $showStartDateList = $this->arrSettings['showStartDateList'] == 1 ? 1 : 0; $showEndDateList = $this->arrSettings['showEndDateList'] == 1 ? 1 : 0; $showStartTimeList = $this->arrSettings['showStartTimeList'] == 1 ? 1 : 0; $showEndTimeList = $this->arrSettings['showEndTimeList'] == 1 ? 1 : 0; // reset time values if "no time" is selected if ($showStartTimeList == 1 || $showEndTimeList == 1) { $showTimeTypeList = 1; } else { $showStartTimeList = 0; $showEndTimeList = 0; $showTimeTypeList = 0; } $showStartDateDetail = $this->arrSettings['showStartDateDetail'] == 1 ? 1 : 0; $showEndDateDetail = $this->arrSettings['showEndDateDetail'] == 1 ? 1 : 0; $showStartTimeDetail = $this->arrSettings['showStartTimeDetail'] == 1 ? 1 : 0; $showEndTimeDetail = $this->arrSettings['showEndTimeDetail'] == 1 ? 1 : 0; // reset time values if "no time" is selected if ($showStartTimeDetail == 1 || $showEndTimeDetail == 1) { $showTimeTypeDetail = 1; } else { $showStartTimeDetail = 0; $showEndTimeDetail = 0; $showTimeTypeDetail = 0; } } $access = isset($data['access']) ? intval($data['access']) : 0; $priority = isset($data['priority']) ? intval($data['priority']) : 0; $placeMediadir = isset($data['placeMediadir']) ? intval($data['placeMediadir']) : 0; $hostMediadir = isset($data['hostMediadir']) ? intval($data['hostMediadir']) : 0; $price = isset($data['price']) ? contrexx_addslashes(contrexx_strip_tags($data['price'])) : 0; $link = isset($data['link']) ? contrexx_addslashes(contrexx_strip_tags($data['link'])) : ''; $pic = isset($data['picture']) ? contrexx_addslashes(contrexx_strip_tags($data['picture'])) : ''; $attach = isset($data['attachment']) ? contrexx_addslashes(contrexx_strip_tags($data['attachment'])) : ''; $catId = isset($data['category']) ? intval($data['category']) : ''; $showIn = isset($data['showIn']) ? contrexx_addslashes(contrexx_strip_tags(join(",", $data['showIn']))) : ''; $invited_groups = isset($data['selectedGroups']) ? join(',', $data['selectedGroups']) : ''; $invited_mails = isset($data['invitedMails']) ? contrexx_addslashes(contrexx_strip_tags($data['invitedMails'])) : ''; $send_invitation = isset($data['sendInvitation']) ? intval($data['sendInvitation']) : 0; $invitationTemplate = isset($data['invitationEmailTemplate']) ? contrexx_input2db($data['invitationEmailTemplate']) : 0; $registration = isset($data['registration']) ? intval($data['registration']) : 0; $registration_form = isset($data['registrationForm']) ? intval($data['registrationForm']) : 0; $registration_num = isset($data['numSubscriber']) ? intval($data['numSubscriber']) : 0; $registration_notification = isset($data['notificationTo']) ? contrexx_addslashes(contrexx_strip_tags($data['notificationTo'])) : ''; $email_template = isset($data['emailTemplate']) ? contrexx_input2db($data['emailTemplate']) : 0; $ticket_sales = isset($data['ticketSales']) ? intval($data['ticketSales']) : 0; $num_seating = isset($data['numSeating']) ? json_encode(explode(',', $data['numSeating'])) : ''; $related_hosts = isset($data['selectedHosts']) ? $data['selectedHosts'] : ''; $locationType = isset($data['eventLocationType']) ? (int) $data['eventLocationType'] : $this->arrSettings['placeData']; $hostType = isset($data['eventHostType']) ? (int) $data['eventHostType'] : $this->arrSettings['placeDataHost']; $place = isset($data['place']) ? contrexx_input2db(contrexx_strip_tags($data['place'])) : ''; $street = isset($data['street']) ? contrexx_input2db(contrexx_strip_tags($data['street'])) : ''; $zip = isset($data['zip']) ? contrexx_input2db(contrexx_strip_tags($data['zip'])) : ''; $city = isset($data['city']) ? contrexx_input2db(contrexx_strip_tags($data['city'])) : ''; $country = isset($data['country']) ? contrexx_input2db(contrexx_strip_tags($data['country'])) : ''; $placeLink = isset($data['placeLink']) ? contrexx_input2db($data['placeLink']) : ''; $placeMap = isset($data['placeMap']) ? contrexx_input2db($data['placeMap']) : ''; $update_invitation_sent = $send_invitation == 1; if (!empty($placeLink)) { if (!preg_match('%^(?:ftp|http|https):\\/\\/%', $placeLink)) { $placeLink = "http://" . $placeLink; } } if ($objInit->mode == 'frontend') { $unique_id = intval($_REQUEST[self::MAP_FIELD_KEY]); if (!empty($unique_id)) { $picture = $this->_handleUpload('mapUpload', $unique_id); if (!empty($picture)) { $placeMap = $picture; } } } $orgName = isset($data['organizerName']) ? contrexx_input2db($data['organizerName']) : ''; $orgStreet = isset($data['organizerStreet']) ? contrexx_input2db($data['organizerStreet']) : ''; $orgZip = isset($data['organizerZip']) ? contrexx_input2db($data['organizerZip']) : ''; $orgCity = isset($data['organizerCity']) ? contrexx_input2db($data['organizerCity']) : ''; $orgCountry = isset($data['organizerCountry']) ? contrexx_input2db($data['organizerCountry']) : ''; $orgLink = isset($data['organizerLink']) ? contrexx_input2db($data['organizerLink']) : ''; $orgEmail = isset($data['organizerEmail']) ? contrexx_input2db($data['organizerEmail']) : ''; if (!empty($orgLink)) { if (!preg_match('%^(?:ftp|http|https):\\/\\/%', $orgLink)) { $orgLink = "http://" . $orgLink; } } // create thumb if not exists if (!file_exists(\Env::get('cx')->getWebsitePath() . "{$placeMap}.thumb")) { $objImage = new \ImageManager(); $objImage->_createThumb(dirname(\Env::get('cx')->getWebsitePath() . "{$placeMap}") . "/", '', basename($placeMap), 180); } //frontend picture upload & thumbnail creation if ($objInit->mode == 'frontend') { $unique_id = intval($_REQUEST[self::PICTURE_FIELD_KEY]); $attachmentUniqueId = intval($_REQUEST[self::ATTACHMENT_FIELD_KEY]); if (!empty($unique_id)) { $picture = $this->_handleUpload('pictureUpload', $unique_id); if (!empty($picture)) { //delete thumb if (file_exists("{$this->uploadImgPath}{$pic}.thumb")) { \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$pic}.thumb"); } //delete image if (file_exists("{$this->uploadImgPath}{$pic}")) { \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$pic}"); } $pic = $picture; } } if (!empty($attachmentUniqueId)) { $attachment = $this->_handleUpload('attachmentUpload', $attachmentUniqueId); if ($attachment) { //delete file if (file_exists("{$this->uploadImgPath}{$attach}")) { \Cx\Lib\FileSystem\FileSystem::delete_file($this->uploadImgPath . "/.{$attach}"); } $attach = $attachment; } } } else { // create thumb if not exists if (!file_exists(\Env::get('cx')->getWebsitePath() . "{$pic}.thumb")) { $objImage = new \ImageManager(); $objImage->_createThumb(dirname(\Env::get('cx')->getWebsitePath() . "{$pic}") . "/", '', basename($pic), 180); } } $seriesStatus = isset($data['seriesStatus']) ? intval($data['seriesStatus']) : 0; //series pattern $seriesStatus = isset($data['seriesStatus']) ? intval($data['seriesStatus']) : 0; $seriesType = isset($data['seriesType']) ? intval($data['seriesType']) : 0; $seriesPatternCount = 0; $seriesPatternWeekday = 0; $seriesPatternDay = 0; $seriesPatternWeek = 0; $seriesPatternMonth = 0; $seriesPatternType = 0; $seriesPatternDouranceType = 0; $seriesPatternEnd = 0; $seriesExeptions = ''; $seriesPatternEndDate = 0; if ($seriesStatus == 1) { if (!empty($data['seriesExeptions'])) { $exeptions = array(); foreach ($data['seriesExeptions'] as $key => $exeptionDate) { $exeptions[] = date("Y-m-d", parent::getDateTimestamp($exeptionDate, 23, 59)); } sort($exeptions); $seriesExeptions = join(",", $exeptions); } switch ($seriesType) { case 1: if ($seriesStatus == 1) { $seriesPatternType = isset($data['seriesDaily']) ? intval($data['seriesDaily']) : 0; if ($seriesPatternType == 1) { $seriesPatternWeekday = 0; $seriesPatternDay = isset($data['seriesDailyDays']) ? intval($data['seriesDailyDays']) : 0; } else { $seriesPatternWeekday = "1111100"; $seriesPatternDay = 0; } $seriesPatternWeek = 0; $seriesPatternMonth = 0; $seriesPatternCount = 0; } break; case 2: if ($seriesStatus == 1) { $seriesPatternWeek = isset($data['seriesWeeklyWeeks']) ? intval($data['seriesWeeklyWeeks']) : 0; for ($i = 1; $i <= 7; $i++) { if (isset($data['seriesWeeklyDays'][$i])) { $weekdayPattern .= "1"; } else { $weekdayPattern .= "0"; } } $seriesPatternWeekday = $weekdayPattern; $seriesPatternCount = 0; $seriesPatternDay = 0; $seriesPatternMonth = 0; $seriesPatternType = 0; } break; case 3: if ($seriesStatus == 1) { $seriesPatternType = isset($data['seriesMonthly']) ? intval($data['seriesMonthly']) : 0; if ($seriesPatternType == 1) { $seriesPatternMonth = isset($data['seriesMonthlyMonth_1']) ? intval($data['seriesMonthlyMonth_1']) : 0; $seriesPatternDay = isset($data['seriesMonthlyDay']) ? intval($data['seriesMonthlyDay']) : 0; $seriesPatternWeekday = 0; } else { $seriesPatternCount = isset($data['seriesMonthlyDayCount']) ? intval($data['seriesMonthlyDayCount']) : 0; $seriesPatternMonth = isset($data['seriesMonthlyMonth_2']) ? intval($data['seriesMonthlyMonth_2']) : 0; if ($seriesPatternMonth < 1) { // the increment must be at least once a month, otherwise we will end up in a endless loop in the presence $seriesPatternMonth = 1; } $seriesPatternWeekday = isset($data['seriesMonthlyWeekday']) ? $data['seriesMonthlyWeekday'] : ''; $seriesPatternDay = 0; } $seriesPatternWeek = 0; } break; } $seriesPatternDouranceType = isset($data['seriesDouranceType']) ? intval($data['seriesDouranceType']) : 0; switch ($seriesPatternDouranceType) { case 1: $seriesPatternEnd = 0; break; case 2: $seriesPatternEnd = isset($data['seriesDouranceEvents']) ? intval($data['seriesDouranceEvents']) : 0; break; case 3: $seriesPatternEndDate = date("Y-m-d H:i:s", parent::getDateTimestamp($data['seriesDouranceDate'], 23, 59)); break; } } $formData = array('type' => $type, 'startdate' => $startDate, 'enddate' => $endDate, 'use_custom_date_display' => $useCustomDateDisplay, 'showStartDateList' => $showStartDateList, 'showEndDateList' => $showEndDateList, 'showStartTimeList' => $showStartTimeList, 'showEndTimeList' => $showEndTimeList, 'showTimeTypeList' => $showTimeTypeList, 'showStartDateDetail' => $showStartDateDetail, 'showEndDateDetail' => $showEndDateDetail, 'showStartTimeDetail' => $showStartTimeDetail, 'showEndTimeDetail' => $showEndTimeDetail, 'showTimeTypeDetail' => $showTimeTypeDetail, 'google' => $google, 'access' => $access, 'priority' => $priority, 'price' => $price, 'link' => $link, 'pic' => $pic, 'catid' => $catId, 'attach' => $attach, 'place_mediadir_id' => $placeMediadir, 'host_mediadir_id' => $hostMediadir, 'show_in' => $showIn, 'invited_groups' => $invited_groups, 'invited_mails' => $invited_mails, 'invitation_email_template' => json_encode($invitationTemplate), 'registration' => $registration, 'registration_form' => $registration_form, 'registration_num' => $registration_num, 'registration_notification' => $registration_notification, 'email_template' => json_encode($email_template), 'ticket_sales' => $ticket_sales, 'num_seating' => $num_seating, 'series_status' => $seriesStatus, 'series_type' => $seriesType, 'series_pattern_count' => $seriesPatternCount, 'series_pattern_weekday' => $seriesPatternWeekday, 'series_pattern_day' => $seriesPatternDay, 'series_pattern_week' => $seriesPatternWeek, 'series_pattern_month' => $seriesPatternMonth, 'series_pattern_type' => $seriesPatternType, 'series_pattern_dourance_type' => $seriesPatternDouranceType, 'series_pattern_end' => $seriesPatternEnd, 'series_pattern_end_date' => $seriesPatternEndDate, 'series_pattern_exceptions' => $seriesExeptions, 'all_day' => $allDay, 'location_type' => $locationType, 'host_type' => $hostType, 'place' => $place, 'place_id' => 0, 'place_street' => $street, 'place_zip' => $zip, 'place_city' => $city, 'place_country' => $country, 'place_link' => $placeLink, 'place_map' => $placeMap, 'org_name' => $orgName, 'org_street' => $orgStreet, 'org_zip' => $orgZip, 'org_city' => $orgCity, 'org_country' => $orgCountry, 'org_link' => $orgLink, 'org_email' => $orgEmail, 'invitation_sent' => $update_invitation_sent ? 1 : 0); if ($id != 0) { $query = \SQL::update("module_{$this->moduleTablePrefix}_event", $formData) . " WHERE id = '{$id}'"; $objResult = $objDatabase->Execute($query); if ($objResult !== false) { $this->id = $id; $query = "DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_event_field\n WHERE event_id = '" . $id . "'"; $objResult = $objDatabase->Execute($query); $query = "DELETE FROM " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_event_host\n WHERE event_id = '" . $id . "'"; $objResult = $objDatabase->Execute($query); } else { return false; } } else { $objFWUser = \FWUser::getFWUserObject(); $objUser = $objFWUser->objUser; if ($objInit->mode == 'frontend') { $status = 1; $confirmed = $this->arrSettings['confirmFrontendEvents'] == 1 ? 0 : 1; $author = $objUser->login() ? intval($objUser->getId()) : 0; } else { $status = 0; $confirmed = 1; $author = intval($objUser->getId()); } $formData['status'] = $status; $formData['confirmed'] = $confirmed; $formData['author'] = $author; $query = \SQL::insert("module_{$this->moduleTablePrefix}_event", $formData); $objResult = $objDatabase->Execute($query); if ($objResult !== false) { $id = intval($objDatabase->Insert_ID()); $this->id = $id; } else { return false; } } if ($id != 0) { foreach ($data['showIn'] as $key => $langId) { $title = contrexx_addslashes(contrexx_strip_tags($data['title'][$langId])); $description = contrexx_addslashes($data['description'][$langId]); if ($convertBBCode) { $description = \Cx\Core\Wysiwyg\Wysiwyg::prepareBBCodeForDb($data['description'][$langId], true); } $redirect = contrexx_addslashes($data['calendar-redirect'][$langId]); if ($type == 0) { $redirect = ''; } else { $description = ''; } $query = "INSERT INTO " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_event_field\n (`event_id`,`lang_id`,`title`, `description`,`redirect`)\n VALUES\n ('" . intval($id) . "','" . intval($langId) . "','" . $title . "','" . $description . "','" . $redirect . "')"; $objResult = $objDatabase->Execute($query); if ($objResult === false) { return false; } } if (!empty($related_hosts)) { foreach ($related_hosts as $key => $hostId) { $query = "INSERT INTO " . DBPREFIX . "module_" . $this->moduleTablePrefix . "_rel_event_host\n (`host_id`,`event_id`) \n VALUES ('" . intval($hostId) . "','" . intval($id) . "')"; $objResult = $objDatabase->Execute($query); } } } if ($send_invitation == 1) { $objMailManager = new \Cx\Modules\Calendar\Controller\CalendarMailManager(); foreach ($invitationTemplate as $templateId) { $objMailManager->sendMail(intval($id), \Cx\Modules\Calendar\Controller\CalendarMailManager::MAIL_INVITATION, null, $templateId); } } return true; }
/** * 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; }