<tbody valign="top"> <?php foreach ($this->items as $i => $item) { $ordering = $listOrder == 'a.ordering'; $canCreate = $user->authorise('core.create', 'com_icagenda'); $canEdit = $user->authorise('core.edit', 'com_icagenda'); $canCheckin = $user->authorise('core.manage', 'com_icagenda') || $item->checked_out == $userId || $item->checked_out == 0; $canChange = $user->authorise('core.edit.state', 'com_icagenda') && $canCheckin; $canEditOwn = $user->authorise('core.edit.own', 'com_icagenda') && $item->userid == $userId; // Get avatar of the registered user $avatar = md5(strtolower(trim($item->email))); // Get Username and name $data_name = $item->userid ? $item->fullname : $item->name; $data_username = $item->userid ? $item->username : false; // Load Custom fields DATA $customfields = icagendaCustomfields::getListNotEmpty($item->id, 1); ?> <tr class="row<?php echo $i % 2; ?> "> <?php // START J3 CODE ?> <?php if (version_compare(JVERSION, '3.0', 'ge')) { ?> <?php // *** Ordering (Joomla 3.x) ***
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.4.0 */ public function save($data) { $input = JFactory::getApplication()->input; $date = JFactory::getDate(); $user = JFactory::getUser(); // Fix version before 3.4.0 to set a created date (will use last modified date if exists, or current date) if (empty($data['created'])) { $data['created'] = !empty($data['modified']) ? $data['modified'] : $date->toSql(); } // Alter the title for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (int) $input->get('id') == 0) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); } $table = JTable::getInstance('Event', 'iCagendaTable'); if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) { $msg = JText::_('COM_ICAGENDA_ALERT_EVENT_SAVE_WARNING'); } list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } // Generates Alias if empty if ($data['alias'] == null || empty($data['alias'])) { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); if ($data['alias'] == null || empty($data['alias'])) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['created']); } } } // Set File Uploaded if (!isset($data['file'])) { $file = JRequest::getVar('jform', null, 'files', 'array'); $fileUrl = $this->upload($file); $data['file'] = $fileUrl; } // Set Creator infos $userId = $user->get('id'); $userName = $user->get('name'); if (empty($data['created_by'])) { $data['created_by'] = (int) $userId; } $data['username'] = $userName; // Set Params if (isset($data['params']) && is_array($data['params'])) { // Convert the params field to a string. $parameter = new JRegistry(); $parameter->loadArray($data['params']); $data['params'] = (string) $parameter; } // Get Event ID from the result back to the Table after saving. $table = $this->getTable(); if ($table->save($data) === true) { $data['id'] = $table->id; } else { $data['id'] = null; } if (parent::save($data)) { // Save Features to database $this->maintainFeatures($data); // Save Custom Fields to database if (isset($data['custom_fields']) && is_array($data['custom_fields'])) { icagendaCustomfields::saveToData($data['custom_fields'], $data['id'], 2); } return true; } return false; }
/** * Function to return script validation for a form used in iCagenda * * @access public static * @param $parent_form form type ID ('1' registration, '2' event edit or new) * // $form_location ('site' or 'admin') * @return script * * @since 3.4.0 */ public static function submit($parent_form = null) { if (!$parent_form) { return false; } if ($parent_form == 1) { $parent_name = 'registration'; } if ($parent_form == 2) { $parent_name = 'event'; } $app = JFactory::getApplication(); if ($app->isAdmin()) { $params = JComponentHelper::getParams('com_icagenda'); } if ($app->isSite()) { $params = $app->getParams(); } $submit_periodDisplay = $params->get('submit_periodDisplay', 1); $submit_datesDisplay = $params->get('submit_datesDisplay', 1); JText::script('COM_ICAGENDA_REGISTRATION_NO_EVENT_SELECTED_ALERT'); JText::script('COM_ICAGENDA_FORM_NC'); JText::script('COM_ICAGENDA_FORM_NO_DATES_ALERT'); JText::script('COM_ICAGENDA_TERMS_AND_CONDITIONS_NOT_CHECKED_REGISTRATION'); JText::script('COM_ICAGENDA_ALERT_TEXT_EXCEEDS_CHARACTER_LIMIT'); $prefix_id = $app->isAdmin() ? 'jform_' : ''; // Copyleft function strpos // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net) // + improved by: Onno Marsman // + bugfixed by: Daniel Esteban // + improved by: Brett Zamir (http://brett-zamir.me) // + edited by: Cyril Rezé (http://www.joomlic.com) // * example 1: strpos('Kevin van Zonneveld', 'e', 5); // * returns 1: 14 $ic_script = array(); if ($app->isSite()) { $ic_script[] = ' function iCheckForm() {'; $ic_script[] = ' var agree = document.getElementById("formAgree");'; if ($parent_form == 2) { $ic_script[] = ' if (agree.checked) {'; $ic_script[] = ' document.getElementById("tos").value = "checked";'; $ic_script[] = ' }'; } } elseif ($app->isAdmin()) { $ic_script[] = 'jQuery(document).ready(function() {'; $ic_script[] = ' Joomla.submitbutton = function(task) {'; } if ($parent_form == 1 && $app->isAdmin()) { $ic_script[] = ' var eventid = document.getElementById("' . $prefix_id . 'eventid_id");'; $ic_script[] = ' if ((eventid.value == "") && (task != "' . $parent_name . '.cancel")) {'; $ic_script[] = ' alert(Joomla.JText._("COM_ICAGENDA_REGISTRATION_NO_EVENT_SELECTED_ALERT"));'; $ic_script[] = ' return false;'; $ic_script[] = ' }'; } if ($parent_form == 2) { $ic_script[] = ' function strpos (haystack, needle, offset) {'; $ic_script[] = ' var i = (haystack + "").indexOf(needle, (offset || 0));'; $ic_script[] = ' return i === -1 ? false : i;'; $ic_script[] = ' }'; $ic_script[] = ' var nodate = "0";'; $ic_script[] = ' var noserialdate = \'a:1:{i:0;s:19:"0000-00-00 00:00:00";}\';'; $ic_script[] = ' var noserialdate2 = \'a:1:{i:0;s:16:"0000-00-00 00:00";}\';'; $ic_script[] = ' var emptydatetime = "0000-00-00 00:00:00";'; if ($submit_periodDisplay && $app->isSite()) { $ic_script[] = ' var startDate = document.getElementById("startdate");'; $ic_script[] = ' var endDate = document.getElementById("enddate");'; $ic_script[] = ' var isValidStartDate = strpos(startDate.value, nodate, 0);'; $ic_script[] = ' var isValidEndDate = strpos(endDate.value, nodate, 0);'; } elseif ($app->isAdmin()) { $ic_script[] = ' var startDate = document.getElementById("startdate");'; $ic_script[] = ' var endDate = document.getElementById("enddate");'; $ic_script[] = ' var isValidStartDate = strpos(startDate.value, nodate, 0);'; $ic_script[] = ' var isValidEndDate = strpos(endDate.value, nodate, 0);'; } if ($submit_datesDisplay && $app->isSite()) { $ic_script[] = ' var Dates = document.getElementById("' . $prefix_id . 'dates_id");'; $ic_script[] = ' var isValidSingleDate = strpos(Dates.value, nodate, 2);'; } elseif ($app->isAdmin()) { $ic_script[] = ' var Dates = document.getElementById("' . $prefix_id . 'dates_id");'; $ic_script[] = ' var isValidSingleDate = strpos(Dates.value, nodate, 2);'; } $ic_script[] = ' if ('; if ($submit_datesDisplay && $app->isSite()) { $ic_script[] = ' ( !isValidSingleDate'; $ic_script[] = ' || (Dates.value == noserialdate && isValidSingleDate)'; $ic_script[] = ' || (Dates.value == noserialdate2 && isValidSingleDate)'; $ic_script[] = ' || Dates.value == "" )'; } elseif ($app->isAdmin()) { $ic_script[] = ' ( !isValidSingleDate'; $ic_script[] = ' || (Dates.value == noserialdate && isValidSingleDate)'; $ic_script[] = ' || (Dates.value == noserialdate2 && isValidSingleDate)'; $ic_script[] = ' || Dates.value == "" )'; } if ($submit_periodDisplay && $submit_datesDisplay && $app->isSite()) { $ic_script[] = ' && '; } if ($submit_periodDisplay && $app->isSite()) { $ic_script[] = ' ( (!isValidStartDate || (startDate.value == emptydatetime)) )'; } elseif ($app->isAdmin()) { $ic_script[] = ' && ( (!isValidStartDate || (startDate.value == emptydatetime)) )'; } if ($app->isAdmin()) { $ic_script[] = ' && ( task != "' . $parent_name . '.cancel" ) '; } $ic_script[] = ' ) {'; $ic_script[] = ' alert(Joomla.JText._("COM_ICAGENDA_FORM_NO_DATES_ALERT"));'; $ic_script[] = ' document.getElementById("message_error").innerHTML = "' . JText::_("COM_ICAGENDA_FORM_NO_DATES_ALERT") . '";'; $ic_script[] = ' document.getElementById("form_errors").style.display = "block";'; if ($submit_periodDisplay && $app->isSite()) { $ic_script[] = ' document.getElementById("startdate").value = emptydatetime;'; $ic_script[] = ' document.getElementById("enddate").value = emptydatetime;'; $ic_script[] = ' document.getElementById("startdate").addClass("ic-date-invalid");'; $ic_script[] = ' document.getElementById("enddate").addClass("ic-date-invalid");'; } elseif ($app->isAdmin()) { $ic_script[] = ' document.getElementById("startdate").value = emptydatetime;'; $ic_script[] = ' document.getElementById("enddate").value = emptydatetime;'; $ic_script[] = ' document.getElementById("startdate").addClass("ic-date-invalid");'; $ic_script[] = ' document.getElementById("enddate").addClass("ic-date-invalid");'; } if ($submit_datesDisplay && $app->isSite()) { $ic_script[] = ' document.getElementById("dTable").addClass("ic-date-invalid");'; } elseif ($app->isAdmin()) { $ic_script[] = ' document.getElementById("dTable").addClass("ic-date-invalid");'; } $ic_script[] = ' scroll_to = document.getElementById("ic-dates-fieldset");'; $ic_script[] = ' scroll_to.scrollIntoView();'; $ic_script[] = ' return false;'; $ic_script[] = ' }'; $ic_script[] = ' else {'; $ic_script[] = ' document.getElementById("form_errors").style.display = "none";'; if ($submit_periodDisplay && $app->isSite()) { $ic_script[] = ' document.getElementById("startdate").removeClass("ic-date-invalid");'; $ic_script[] = ' document.getElementById("enddate").removeClass("ic-date-invalid");'; } elseif ($app->isAdmin()) { $ic_script[] = ' document.getElementById("startdate").removeClass("ic-date-invalid");'; $ic_script[] = ' document.getElementById("enddate").removeClass("ic-date-invalid");'; } if ($submit_datesDisplay && $app->isSite()) { $ic_script[] = ' document.getElementById("dTable").removeClass("ic-date-invalid");'; } elseif ($app->isAdmin()) { $ic_script[] = ' document.getElementById("dTable").removeClass("ic-date-invalid");'; } $ic_script[] = ' }'; if ($submit_periodDisplay && $app->isSite()) { $ic_script[] = ' if (isValidStartDate && !isValidEndDate) {'; $ic_script[] = ' document.getElementById("enddate").value = startDate.value;'; $ic_script[] = ' }'; } elseif ($app->isAdmin()) { $ic_script[] = ' if (isValidStartDate && !isValidEndDate) {'; $ic_script[] = ' document.getElementById("enddate").value = startDate.value;'; $ic_script[] = ' }'; } } $customfields = icagendaCustomfields::getCustomfields($parent_form); if ($customfields && $app->isAdmin()) { $options_required = array('list', 'radio'); foreach ($customfields as $icf) { // If type is list or radio, should have options. All, field required. if ((in_array($icf->type, $options_required) && $icf->options || !in_array($icf->type, $options_required)) && $icf->required) { $ic_script[] = ' var ' . $icf->slug . '_slug = document.getElementById("' . $icf->slug . '_slug");'; $ic_script[] = ' if ( ( ' . $icf->slug . '_slug.value == "" ) '; if ($app->isAdmin()) { $ic_script[] = ' && ( task != "' . $parent_name . '.cancel" ) '; } $ic_script[] = ' ) {'; $ic_script[] = ' alert(Joomla.JText._("COM_ICAGENDA_FORM_NC"));'; $ic_script[] = ' document.getElementById("message_error").innerHTML = "' . JText::sprintf("COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME", $icf->title) . '";'; $ic_script[] = ' document.getElementById("form_errors").style.display = "block";'; $ic_script[] = ' document.getElementById("' . $icf->alias . '_alias").addClass("ic-field-invalid");'; $ic_script[] = ' document.getElementById("' . $icf->slug . '_slug").addClass("ic-field-invalid");'; $ic_script[] = ' scroll_to = document.getElementById("' . $icf->alias . '_alias");'; $ic_script[] = ' scroll_to.scrollIntoView();'; $ic_script[] = ' return false;'; $ic_script[] = ' }'; $ic_script[] = ' else {'; $ic_script[] = ' document.getElementById("form_errors").style.display = "none";'; $ic_script[] = ' document.getElementById("' . $icf->alias . '_alias").removeClass("ic-field-invalid");'; $ic_script[] = ' document.getElementById("' . $icf->slug . '_slug").removeClass("ic-field-invalid");'; $ic_script[] = ' }'; } } } if ($app->isAdmin()) { $ic_script[] = ' if (task == "' . $parent_name . '.cancel"'; $ic_script[] = ' || document.formvalidator.isValid(document.id("' . $parent_name . '-form")))'; $ic_script[] = ' {'; $ic_script[] = ' // do field validation'; $ic_script[] = ' Joomla.submitform(task, document.getElementById("' . $parent_name . '-form"));'; $ic_script[] = ' }'; $ic_script[] = ' else {'; $ic_script[] = ' alert("' . JText::_("JGLOBAL_VALIDATION_FORM_FAILED") . '");'; $ic_script[] = ' }'; } if ($app->isSite()) { $ic_script[] = ' if (!agree.checked) {'; if ($parent_form == 1) { $ic_script[] = ' alert(Joomla.JText._("COM_ICAGENDA_TERMS_AND_CONDITIONS_NOT_CHECKED_REGISTRATION"));'; } if ($parent_form == 2) { $ic_script[] = ' alert(Joomla.JText._("COM_ICAGENDA_TERMS_OF_SERVICE_NOT_CHECKED_SUBMIT_EVENT"));'; } $ic_script[] = ' scroll_to = document.getElementById("content");'; $ic_script[] = ' scroll_to.scrollIntoView();'; $ic_script[] = ' return false;'; $ic_script[] = ' }'; } $ic_script[] = ' }'; if ($app->isAdmin()) { $ic_script[] = '});'; } return implode("\n", $ic_script); }
addFields = []; for (i = 2; i <= people; i++) { var input = '<div class="ic-control-group ic-clearfix"><div class="ic-control-label"><label>Name ' + i +'</label></div><div class="ic-controls"><input type="text" class="input-large" name="name_' + i +'" placeholder="Please, Enter Full Name" /></div></div>'; addFields.push(input); } $('#add_info').html(addFields); }); }) </script--> <?php // CUSTOM FIELDS ?> <?php // Load Custom fields - Registration form (1) echo icagendaCustomfields::loader(1); ?> <?php // NOTES FIELD ?> <?php if ($notesDisplay == 1) { ?> <div class="ic-control-group ic-clearfix"> <div class="ic-control-label"> <label><?php echo JText::_('ICAGENDA_REGISTRATION_FORM_NOTES'); ?> </label>
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.5.6 */ public function save($data) { $app = JFactory::getApplication(); $input = $app->input; $date = JFactory::getDate(); $user = JFactory::getUser(); // if (empty($data['created'])) // not to be used, to leave created empty if before update to 3.5.7 // { // $data['created'] = ( ! empty($data['modified'])) ? $data['modified'] : $date->toSql(); // } // Set registration creator if (empty($data['created_by'])) { $data['created_by'] = (int) $data['userid']; } // Set Params if (isset($data['params']) && is_array($data['params'])) { // Convert the params field to a string. $parameter = new JRegistry(); $parameter->loadArray($data['params']); $data['params'] = (string) $parameter; } if ($input->get('task') == 'delete') { icagendaCustomfields::deleteData($data['custom_fields'], $data['id'], 1); $app->enqueueMessage('Test', 'warning'); } // Get Registration ID from the result back to the Table after saving. $table = $this->getTable(); if ($table->save($data) === true) { $data['id'] = $table->id; } else { $data['id'] = null; } if (parent::save($data)) { // Save Custom Fields to database if (isset($data['custom_fields']) && is_array($data['custom_fields'])) { icagendaCustomfields::saveToData($data['custom_fields'], $data['id'], 1); } return true; } return false; }
/** * Return the HTML body of Custom fields for this parent form (parent_id) * * @return HTML fields * * @since 3.4.0 */ public static function loader($parent_form) { $app = JFactory::getApplication(); $session = JFactory::getSession(); $custom_fields = $session->get('custom_fields'); $customfields = icagendaCustomfields::getCustomfields($parent_form); $cf_display = ''; if ($customfields) { foreach ($customfields as $icf) { if (empty($icf->value)) { $icf->value = ''; } // if ($custom_fields) $icf->value = $custom_fields[$icf->slug]; if ($app->isSite()) { $icf->value = isset($custom_fields[$icf->slug]) ? $custom_fields[$icf->slug] : ''; } $options_required = array('list', 'radio'); // If type is list or radio, should have options if (in_array($icf->type, $options_required) && $icf->options || !in_array($icf->type, $options_required)) { $cf_display .= icagendaCustomfields::displayField($icf->type, $icf->title, $icf->alias, $icf->slug, $icf->description, $icf->value, $icf->options, $icf->required); } } if ($app->isAdmin()) { $cf_display .= '<hr>'; } } elseif ($app->isAdmin()) { $cf_display .= '<div class="alert alert-info">'; $cf_display .= JText::_('COM_ICAGENDA_CUSTOMFIELDS_NONE'); $cf_display .= '</div>'; } elseif ($app->isSite()) { return false; } return $cf_display; }
public function registration($array) { $menu_items = icagendaMenus::iClistMenuItems(); $itemid = JRequest::getVar('Itemid'); $linkexist = ''; foreach ($menu_items as $l) { if ($l->published == '1' && $l->id == $itemid) { $linkexist = '1'; } } if (is_numeric($itemid) && $itemid != 0 && $linkexist == 1) { // Import params - Limit Options for User Registration $app = JFactory::getApplication(); $date = JFactory::getDate(); $params = $app->getParams(); $isSef = $app->getCfg('sef'); $eventTimeZone = null; $data = new stdClass(); // Set the values $data->id = null; $data->eventid = '0'; $data->userid = isset($array['uid']) ? $array['uid'] : ''; if (isset($array['name'])) { $data->name = $array['name']; } $data->email = isset($array['email']) ? $array['email'] : ''; $data->phone = isset($array['phone']) ? $array['phone'] : ''; if (isset($array['date'])) { $data->date = $array['date']; } if (isset($array['period'])) { $data->period = $array['period']; } if (isset($array['people'])) { $data->people = $array['people']; } $data->notes = isset($array['notes']) ? htmlentities(strip_tags($array['notes'])) : ''; if (isset($array['event'])) { $data->eventid = $array['event']; } if (isset($array['menuID'])) { $data->itemid = $array['menuID']; } $data->created = $date->toSql(); $data->created_by = $data->userid; $current_url = isset($array['current_url']) ? $array['current_url'] : 'index.php'; $max_nb_of_tickets = isset($array['max_nb_of_tickets']) ? $array['max_nb_of_tickets'] : '1000000'; $tos = isset($array['tos']) ? 'checked' : ''; $custom_fields = isset($array['custom_fields']) ? $array['custom_fields'] : false; // $tickets_left = isset($array['tickets_left']) ? $array['tickets_left'] : '1000000'; $email2 = isset($array['email2']) ? $array['email2'] : false; // Filter Name $array['name'] = str_replace("'", '’', $array['name']); $array['name'] = (string) preg_replace('/[\\x00-\\x1F\\x7F]/', '', $array['name']); // Set Form Data to Session $session = JFactory::getSession(); $session->set('ic_registration', $array); $session->set('ic_submit_tos', $tos); $custom_fields_array = isset($array['custom_fields']) ? (array) $array['custom_fields'] : array(); $session->set('custom_fields', $custom_fields_array); $session->set('email2', $email2); // Control if still ticket left $db = JFactory::getDbo(); $query = $db->getQuery(true); // Registrations total $query->select('sum(r.people) AS registered'); $query->from('`#__icagenda_registration` AS r'); $query->where('r.state > 0'); $query->where('r.date = ' . $db->q($data->date)); $query->where('r.eventid = ' . (int) $data->eventid); $db->setQuery($query); $registered = $db->loadObject()->registered; $data->checked_out_time = date('Y-m-d H:i:s'); // Set Date in url $datesDisplay = $params->get('datesDisplay', 1); $date_alias = $data->date ? iCDate::dateToAlias(date('Y-m-d H:i', strtotime($data->date))) : false; $date_var = $isSef == 1 ? '?date=' : '&date='; $this_date = $date_alias ? $date_var . $date_alias : ''; $dateInUrl = $datesDisplay === 1 ? $this_date : ''; // Get the "event" URL $baseURL = JURI::base(); $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); // Sub Path filtering $subpathURL = ltrim($subpathURL, '/'); // URL Event Details filtering $urlEvent = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&Itemid=' . (int) $data->itemid . '&id=' . (int) $data->eventid)) . $dateInUrl; $urlEvent = ltrim($urlEvent, '/'); if (substr($urlEvent, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlEvent = substr($urlEvent, strlen($subpathURL) + 1); } $urlEvent = rtrim($baseURL, '/') . '/' . ltrim($urlEvent, '/'); // URL List filtering $urlList = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&Itemid=' . (int) $data->itemid)); $urlList = ltrim($urlList, '/'); if (substr($urlList, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlList = substr($urlList, strlen($subpathURL) + 1); } $urlList = rtrim($baseURL, '/') . '/' . ltrim($urlList, '/'); // URL Registration filtering // NOT USED $urlRegistration = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=registration&Itemid=' . (int) $data->itemid . '&id=' . (int) $data->eventid)); $urlRegistration = ltrim($urlRegistration, '/'); if (substr($urlRegistration, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlRegistration = substr($urlRegistration, strlen($subpathURL) + 1); } $urlRegistration = rtrim($baseURL, '/') . '/' . ltrim($urlRegistration, '/'); // URL Payment filtering $urlPayment = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=actions&Itemid=' . (int) $data->itemid . '&id=' . (int) $data->eventid)); $urlPayment = ltrim($urlPayment, '/'); if (substr($urlPayment, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlPayment = substr($urlPayment, strlen($subpathURL) + 1); } $urlPayment = rtrim($baseURL, '/') . '/' . ltrim($urlPayment, '/'); $urlPayment = $urlPayment . '?status=payment'; // Check number of tickets left $tickets_left = $max_nb_of_tickets - $registered; // IF NO TICKETS LEFT if ($tickets_left <= 0) { $app->enqueueMessage(JText::_('COM_ICAGENDA_ALERT_NO_TICKETS_AVAILABLE'), 'warning'); $app->redirect(htmlspecialchars_decode($urlEvent)); } elseif ($tickets_left < $data->people) { $msg = JText::_('COM_ICAGENDA_ALERT_NOT_ENOUGH_TICKETS_AVAILABLE') . '<br />'; $msg .= JText::sprintf('COM_ICAGENDA_ALERT_NOT_ENOUGH_TICKETS_AVAILABLE_NOW', $tickets_left) . '<br />'; $msg .= JText::_('COM_ICAGENDA_ALERT_NOT_ENOUGH_TICKETS_AVAILABLE_CHANGE_NUMBER'); $app->enqueueMessage($msg, 'error'); $app->redirect(htmlspecialchars_decode($current_url)); } // CONTROL NAME VALUE $name_isValid = '1'; // $pattern = "#[/\\\\/\<>/\"%;=\[\]\+()&]|^[0-9]#i"; $pattern = "#[/\\\\/\\<>/\";=\\[\\]\\+()%&]#i"; if ($array['name']) { $nbMatches = preg_match($pattern, $array['name']); // Name contains invalid characters if ($nbMatches && $nbMatches == 1) { $name_isValid = '0'; $app->enqueueMessage(JText::sprintf('COM_ICAGENDA_REGISTRATION_NAME_NOT_VALID', '<b>' . htmlentities($array['name'], ENT_COMPAT, 'UTF-8') . '</b>'), 'error'); } // Name is less than 2 characters if (strlen(utf8_decode($array['name'])) < 2) { $name_isValid = '0'; $app->enqueueMessage(JText::_('COM_ICAGENDA_REGISTRATION_NAME_MINIMUM_CHARACTERS'), 'error'); } } else { $app->enqueueMessage(JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . JText::_('ICAGENDA_REGISTRATION_FORM_NAME'), 'error'); } $data->name = filter_var($data->name, FILTER_SANITIZE_STRING); // CONTROL EMAIL VALUE $emailRequired = $params->get('emailRequired', 1); $emailConfirm = $params->get('emailConfirm', 1); // Check if Email not empty if ($emailRequired && !$data->email) { $app->enqueueMessage(JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . JText::_('ICAGENDA_REGISTRATION_FORM_EMAIL'), 'error'); } // Check if Confirm Email equals Email if ($emailConfirm && empty($data->userid) && $data->email != $email2) { $app->enqueueMessage(JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_INVALID') . ' ' . JText::_('IC_FORM_EMAIL_CONFIRM_LBL') . '<br />' . JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_EMAIL2_MESSAGE'), 'error'); } // Advanced Checkdnsrr email $emailCheckdnsrr = JComponentHelper::getParams('com_icagenda')->get('emailCheckdnsrr', '0'); if (!empty($data->email)) { $validEmail = true; $checkdnsrr = true; if ($emailCheckdnsrr == 1 and function_exists('checkdnsrr')) { $provider = explode('@', $data->email); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { if (version_compare(phpversion(), '5.3.0', '<')) { $checkdnsrr = true; } } else { $checkdnsrr = checkdnsrr($provider[1]); } } else { $checkdnsrr = true; } } else { $checkdnsrr = true; } // Check if valid email address $validEmail = $validEmail ? $this->validEmail($data->email) : false; if (!$checkdnsrr || !$validEmail && $data->email) { // message if email is invalid $app->enqueueMessage(JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_NOT_VALID'), 'error'); } $eventid = $data->eventid; $period = isset($data->period) ? $data->period : '0'; $people = $data->people; $name = $data->name; $email = $data->email; $phone = $data->phone; $notes = html_entity_decode($data->notes); $dateReg = $data->date; $limitRegEmail = $params->get('limitRegEmail', 1); $limitRegDate = $params->get('limitRegDate', 1); $alreadyexist = 'no'; if ($limitRegEmail == 1 || $limitRegDate == 1) { $cf = JRequest::getString('email', '', 'post'); if ($limitRegDate == 0) { $query = "\n\t\t\t\t\t\tSELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__icagenda_registration`\n\t\t\t\t\t\tWHERE `email` = '{$cf}' AND `eventid`='{$eventid}' AND `state`='1'\n\t\t\t\t\t"; } elseif ($limitRegDate == 1) { $query = "\n\t\t\t\t\t\tSELECT COUNT(*)\n\t\t\t\t\t\tFROM `#__icagenda_registration`\n\t\t\t\t\t\tWHERE `email` = '{$cf}' AND `eventid`='{$eventid}' AND `date`='{$dateReg}' AND `state`='1'\n\t\t\t\t\t"; } $db->setQuery($query); if ($email != NULL) { if ($db->loadResult()) { $alreadyexist = 'yes'; $app->enqueueMessage(JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_ALERT') . ' ' . $email, 'error'); } else { $alreadyexist = 'no'; } } } $email = $email ? $email : JText::_('COM_ICAGENDA_NOT_SPECIFIED'); // Check if Phone not empty $phoneRequired = $params->get('phoneRequired', 1); if ($phoneRequired && !$phone) { $app->enqueueMessage(JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . JText::_('ICAGENDA_REGISTRATION_FORM_PHONE'), 'error'); } $phone = $phone ? $phone : JText::_('COM_ICAGENDA_NOT_SPECIFIED'); // Check if Custom Fields required not empty $customfields_list = icagendaCustomfields::getListCustomFields($data->id, 1, 1); if ($customfields_list) { foreach ($customfields_list as $cf) { if ($cf->cf_required == 1) { if ($custom_fields[$cf->cf_slug] == '') { $app->enqueueMessage(JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . $cf->cf_title, 'error'); } } } } // Check if ToS not checked if (!$tos) { $app->enqueueMessage(JText::_('COM_ICAGENDA_TERMS_AND_CONDITIONS_NOT_CHECKED_REGISTRATION'), 'error'); } // RECAPTCHA $captcha_plugin = $params->get('captcha') ? $params->get('captcha') : $app->getCfg('captcha'); $reg_captcha = JComponentHelper::getParams('com_icagenda')->get('reg_captcha', 1); if ($captcha_plugin && $reg_captcha != '0') { JPluginHelper::importPlugin('captcha'); // JOOMLA 3.x/2.5 SWITCH if (version_compare(JVERSION, '3.0', 'ge')) { $dispatcher = JEventDispatcher::getInstance(); } else { $dispatcher = JDispatcher::getInstance(); } $res = $dispatcher->trigger('onCheckAnswer', $array['recaptcha_response_field']); if (!$res[0]) { // message if captcha is invalid $app->enqueueMessage(JText::_('PLG_RECAPTCHA_ERROR_INCORRECT_CAPTCHA_SOL'), 'error'); } } // Get the message queue $error_messages = $app->getMessageQueue(); if (count($error_messages)) { $app->redirect(htmlspecialchars_decode($current_url)); return false; } // clear the data so we don't process it again $session->clear('ic_registration'); $session->clear('custom_fields'); $session->clear('ic_submit_tos'); $session->clear('email2'); /** * SAVE REGISTRATION DATA TO DATABASE */ // Option Email required if ($emailRequired == '1') { if (is_numeric($eventid) && is_numeric($period) && is_numeric($people) && $name != NULL && $email != NULL) { $db->insertObject('#__icagenda_registration', $data, id); } } else { if (is_numeric($eventid) && is_numeric($period) && is_numeric($people) && $name != NULL) { $db->insertObject('#__icagenda_registration', $data, id); } } /** * SAVE CUSTOM FIELDS TO DATABASE */ if ($custom_fields && is_array($custom_fields)) { icagendaCustomfields::saveToData($custom_fields, $data->id, 1); } /** * NOTIFICATION EMAILS */ $author = '0'; // Preparing the query $query = $db->getQuery(true); $query->select('e.title AS title, e.startdate AS startdate, e.enddate AS enddate, e.created_by AS authorID, e.email AS contactemail, e.displaytime AS displaytime')->from('#__icagenda_events AS e')->where("(e.id={$data->eventid})"); $db->setQuery($query); $title = $db->loadObject()->title; $startdate = $db->loadObject()->startdate; $enddate = $db->loadObject()->enddate; $authorID = $db->loadObject()->authorID; $contactemail = $db->loadObject()->contactemail; $displayTime = $db->loadObject()->displaytime; $startD = $this->formatDate($startdate); $endD = $this->formatDate($enddate); $startT = JHtml::date($startdate, 'H:i', $eventTimeZone); $endT = JHtml::date($enddate, 'H:i', $eventTimeZone); $regDate = $this->formatDate($data->date); $regTime = JHtml::date($data->date, 'H:i', $eventTimeZone); $regDateTime = !empty($displayTime) ? $regDate . ' - ' . $regTime : $regDate; $regStartDateTime = !empty($displayTime) ? $startD . ' - ' . $startT : $startD; $regEndDateTime = !empty($displayTime) ? $endD . ' - ' . $endT : $endD; $periodreg = $data->period; $defaultemail = $params->get('regEmailUser', '1'); $emailUserSubjectPeriod = $params->get('emailUserSubjectPeriod', ''); $emailUserBodyPeriod = $params->get('emailUserBodyPeriod', ''); $emailUserSubjectDate = $params->get('emailUserSubjectDate', ''); $emailUserBodyDate = $params->get('emailUserBodyDate', ''); $emailAdminSend = $params->get('emailAdminSend', '1'); $emailAdminSend_select = $params->get('emailAdminSend_select', array('0')); $emailAdminSend_custom = $params->get('emailAdminSend_Placeholder', ''); $emailUserSend = $params->get('emailUserSend', '1'); $eUSP = isset($emailUserSubjectPeriod) ? $emailUserSubjectPeriod : JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_PERIOD_DEFAULT_SUBJECT'); $eUBP = isset($emailUserBodyPeriod) ? $emailUserBodyPeriod : JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_PERIOD_DEFAULT_BODY'); $eUSD = isset($emailUserSubjectDate) ? $emailUserSubjectDate : JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_DATE_DEFAULT_SUBJECT'); $eUBD = isset($emailUserBodyDate) ? $emailUserBodyDate : JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_DATE_DEFAULT_BODY'); $period_set = substr($startdate, 0, 4); if ($periodreg == 1 || $array['date'] == '' && !$periodreg) { $periodd = $period_set != '0000' ? JText::sprintf('COM_ICAGENDA_REGISTERED_EVENT_PERIOD', $startD, $startT, $endD, $endT) : ''; $adminsubject = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_ADMIN_DEFAULT_SUBJECT'); $adminbody = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_ADMIN_PERIOD_DEFAULT_BODY'); if ($defaultemail == 0) { $subject = $eUSP; $body = $eUBP; } else { $subject = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_PERIOD_DEFAULT_SUBJECT'); $body = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_PERIOD_DEFAULT_BODY'); } } else { // $periodd = ($period_set != '0000') // ? JText::sprintf( 'COM_ICAGENDA_REGISTERED_EVENT_DATE', $regDate, '' ) // : ''; $periodd = JText::sprintf('COM_ICAGENDA_REGISTERED_EVENT_DATE', $regDate, ''); $adminsubject = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_ADMIN_DEFAULT_SUBJECT'); $adminbody = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_ADMIN_DATE_DEFAULT_BODY'); if ($defaultemail == 0) { $subject = $eUSD; $body = $eUBD; } else { $subject = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_DATE_DEFAULT_SUBJECT'); $body = JText::_('COM_ICAGENDA_REGISTRATION_EMAIL_USER_DATE_DEFAULT_BODY'); } } // Get the site name $sitename = $app->getCfg('sitename'); $siteURL = JURI::base(); $siteURL = rtrim($siteURL, '/'); // Get Author Email $authormail = ''; if ($authorID != NULL) { // Preparing the query $query = $db->getQuery(true); $query->select('email AS authormail, name AS authorname')->from('#__users AS u')->where("(u.id={$authorID})"); $db->setQuery($query); $authormail = $db->loadObject()->authormail; $authorname = $db->loadObject()->authorname; if ($authormail == NULL) { $authormail = $app->getCfg('mailfrom'); } } // Generates filled custom fields into email body $customfields = icagendaCustomfields::getListNotEmpty($data->id); $custom_fields = ''; $newline = $defaultemail == '0' ? "<br />" : "\n"; if ($customfields) { foreach ($customfields as $customfield) { $cf_value = isset($customfield->cf_value) ? $customfield->cf_value : JText::_('IC_NOT_SPECIFIED'); $custom_fields .= $customfield->cf_title . ": " . $cf_value . $newline; } } // MAIL REPLACEMENTS $replacements = array("\\n" => "\n", '[SITENAME]' => $sitename, '[SITEURL]' => $siteURL, '[AUTHOR]' => $authorname, '[AUTHOREMAIL]' => $authormail, '[CONTACTEMAIL]' => $contactemail, '[TITLE]' => $title, '[EVENTURL]' => $urlEvent, '[NAME]' => $name, '[EMAIL]' => $email, '[PHONE]' => $phone, '[PLACES]' => $people, '[CUSTOMFIELDS]' => $custom_fields, '[NOTES]' => $notes, '[DATE]' => $regDate, '[TIME]' => $regTime, '[DATETIME]' => $regDateTime, '[STARTDATE]' => $startD, '[ENDDATE]' => $endD, '[STARTDATETIME]' => $regStartDateTime, '[ENDDATETIME]' => $regEndDateTime, ' ' => ' '); foreach ($replacements as $key => $value) { $subject = str_replace($key, $value, $subject); $body = str_replace($key, $value, $body); $adminsubject = str_replace($key, $value, $adminsubject); $adminbody = str_replace($key, $value, $adminbody); } // Set Sender of USER and ADMIN emails $mailer = JFactory::getMailer(); $adminmailer = JFactory::getMailer(); $mailfrom = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $mailer->setSender(array($mailfrom, $fromname)); $adminmailer->setSender(array($mailfrom, $fromname)); // Set Recipient of USER email $user = JFactory::getUser(); if (!isset($data->email)) { $recipient = $user->email; } else { $recipient = $data->email; } $mailer->addRecipient($recipient); // Set Recipient of ADMIN email $admin_array = array(); if (in_array('0', $emailAdminSend_select)) { array_push($admin_array, $mailfrom); } if (in_array('1', $emailAdminSend_select)) { array_push($admin_array, $authormail); } if (in_array('2', $emailAdminSend_select)) { $customs_emails = explode(',', $emailAdminSend_custom); $customs_emails = str_replace(' ', '', $customs_emails); foreach ($customs_emails as $cust_mail) { array_push($admin_array, $cust_mail); } } if (in_array('3', $emailAdminSend_select)) { array_push($admin_array, $contactemail); } $adminrecipient = $admin_array; $adminmailer->addRecipient($adminrecipient); // Set Subject of USER and ADMIN email $mailer->setSubject($subject); $adminmailer->setSubject($adminsubject); // Set Body of USER and ADMIN email if ($defaultemail == 0) { // HTML custom notification email send to user $mailer->isHTML(true); $mailer->Encoding = 'base64'; } $adminbody = str_replace("<br />", "\n", $adminbody); $mailer->setBody($body); $adminmailer->setBody($adminbody); // Optional file attached // $mailer->addAttachment(JPATH_COMPONENT.DS.'assets'.DS.'document.pdf'); // Send USER email confirmation, if enabled if ($emailUserSend == 1 && isset($data->email)) { $send = $mailer->Send(); } // Send ADMIN email notification, if enabled if ($emailAdminSend == 1) { if ($emailAdminSend == 1 && isset($data->eventid) && $data->eventid != '0' && $data->name != NULL) { $sendadmin = $adminmailer->Send(); } } $evtParams = $this->evtParams($i); $reg_payment = $evtParams->get('icpayment', ''); $iCpaymentPlugin = JPluginHelper::getPlugin('content', 'ic_payment'); if ($iCpaymentPlugin) { $plgParams = new JRegistry($iCpaymentPlugin->params); $reg_payment = $reg_payment ? $reg_payment : $plgParams->get('icpayment', ''); } if ($alreadyexist == 'no') { $thank_you = JText::_('COM_ICAGENDA_REGISTRATION_TY') . ' ' . $data->name; $thank_you .= ', ' . JText::sprintf('COM_ICAGENDA_REGISTRATION', $title); $thank_you .= '<br />' . $periodd . ' (<a href="' . $urlEvent . '">' . JText::_('COM_ICAGENDA_REGISTRATION_EVENT_LINK') . '</a>)'; // redirect after successful registration $app->enqueueMessage($thank_you, 'message'); if ($reg_payment) { $app->redirect(htmlspecialchars_decode($urlPayment)); } else { $app->redirect(htmlspecialchars_decode($urlList)); } } } else { JError::raiseError('404', JTEXT::_('JERROR_LAYOUT_PAGE_NOT_FOUND')); return false; } }
/** * Get the content * * @return string The content. * * @since 3.5.0 */ public function getContent() { if (!isset($this->content)) { foreach ($this->getItems() as $item) { // Adds filled custom fields $customfields = icagendaCustomfields::getList($item->id, 1); $header_cfs = array(); if ($customfields) { foreach ($customfields as $customfield) { $header_cfs[] = $customfield->cf_title; } } } // Add BOM UTF-8 to csv content $this->content = chr(239) . chr(187) . chr(191); $this->content .= ''; $this->content .= '"' . str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_EVENTID')) . '","' . str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_DATE')) . '","' . str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_TICKETS')) . '","' . str_replace('"', '""', JText::_('IC_NAME')) . '","' . str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_EMAIL')) . '","' . str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_PHONE')) . '","'; foreach ($header_cfs as $header) { $this->content .= str_replace('"', '""', $header) . '","'; } $this->content .= str_replace('"', '""', JText::_('COM_ICAGENDA_REGISTRATION_NOTES_DISPLAY_LABEL')) . '","' . str_replace('"', '""', JText::_('JSTATUS')) . '"' . "\n"; foreach ($this->getItems() as $item) { // Adds filled custom fields $customfields = icagendaCustomfields::getList($item->id, 1); $values_cfs = array(); if ($customfields) { foreach ($customfields as $customfield) { $cf_value = isset($customfield->cf_value) ? $customfield->cf_value : JText::_('IC_NOT_SPECIFIED'); $values_cfs[] = $cf_value; } } $this->content .= '"' . str_replace('"', '""', $item->event) . '","' . str_replace('"', '""', $item->period == 1 ? JText::_('COM_ICAGENDA_REGISTRATION_ALL_DATES') : $item->date) . '","' . str_replace('"', '""', $item->people) . '","' . str_replace('"', '""', $item->name) . '","' . str_replace('"', '""', $item->email) . '","' . str_replace('"', '""', $item->phone) . '","'; foreach ($values_cfs as $value) { $this->content .= str_replace('"', '""', $value) . '","'; } $this->content .= str_replace('"', '""', $item->notes) . '","' . str_replace('"', '""', $this->getStatusName($item->state)) . '"' . "\n"; } if ($this->getState('compressed')) { $app = JFactory::getApplication('administrator'); $this->content = str_replace(CHR(13) . CHR(10), " ", $this->content); $files = array(); $files['registrations'] = array(); $files['registrations']['name'] = $this->getBasename() . '.csv'; $files['registrations']['data'] = $this->content; $files['registrations']['time'] = time(); $ziproot = $app->get('tmp_path') . '/' . uniqid('icagenda_registrations_') . '.zip'; // Run the packager jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $delete = JFolder::files($app->get('tmp_path') . '/', uniqid('icagenda_registrations_'), false, true); if (!empty($delete)) { if (!JFile::delete($delete)) { // JFile::delete throws an error $this->setError(JText::_('COM_ICAGENDA_EXPORT_ERR_ZIP_DELETE_FAILURE')); return false; } } if (!($packager = JArchive::getAdapter('zip'))) { $this->setError(JText::_('COM_ICAGENDA_EXPORT_ERR_ZIP_ADAPTER_FAILURE')); return false; } elseif (!$packager->create($ziproot, $files)) { $this->setError(JText::_('COM_ICAGENDA_EXPORT_ERR_ZIP_CREATE_FAILURE')); return false; } $this->content = file_get_contents($ziproot); } } return $this->content; }
public function getData() { $app = JFactory::getApplication(); $eventTimeZone = null; $error_messages = array(); jimport('joomla.filter.output'); // Get Params $params = $app->getParams(); $submitAccess = $params->get('submitAccess', ''); $approvalGroups = $params->get('approvalGroups', array("8")); // Get User $user = JFactory::getUser(); // Get User Groups // Joomla 3.x/2.5 SWITCH if (version_compare(JVERSION, '3.0', 'ge')) { $userGroups = $user->groups; } else { $userGroups = $user->getAuthorisedGroups(); } $user_id = $user->get('id'); // logged-in Users: Name/User Name Option $nameJoomlaUser = $params->get('nameJoomlaUser', 1); $u_name = $nameJoomlaUser == 1 ? $user->get('name') : $user->get('username'); $this->data = new stdClass(); $this->data->id = null; $this->data->asset_id = JRequest::getVar('asset_id', '', 'post'); $this->data->ordering = 0; $this->data->state = 1; // Control: if Manager jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($approvalGroups as $ag) { $adminUsers = JAccess::getUsersByGroup($ag, False); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } $this->data->approval = in_array($user_id, $adminUsersArray) ? '0' : '1'; $this->data->access = 1; $this->data->language = '*'; // $menuID = JRequest::getVar('menuID', '', 'post'); // USER NAME $this->data->username = JRequest::getVar('username', '', 'post'); if (!$this->data->username) { $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_SUBMIT_FORM_USER_NAME')); } // USER EMAIL $this->data->created_by_email = JRequest::getVar('created_by_email', '', 'post'); if (!$this->data->created_by_email) { $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_SUBMIT_FORM_USER_EMAIL')); } // EVENT TITLE $this->data->title = JRequest::getVar('title', '', 'post'); if (!$this->data->title) { $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_FORM_LBL_EVENT_TITLE')); } // EVENT CATEGORY $this->data->catid = JRequest::getVar('catid', '', 'post'); if (!$this->data->catid) { $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED_NAME', JText::_('COM_ICAGENDA_FORM_LBL_EVENT_CATID')); } // EVENT IMAGE - Get and Upload Image $image = JRequest::getVar('image', null, 'files', 'array'); $image_session = JRequest::getVar('image_session', '', 'post'); if ($image_session && empty($image)) { $this->data->image = $image_session; } else { $this->data->image = $image; // Process upload of files $this->data->image = $this->frontendImageUpload($this->data->image); } $noDateTime = '0000-00-00 00:00:00'; $noDateTimeShort = '0000-00-00 00:00'; // Get Single Dates $single_dates = JRequest::getVar('dates', '', 'post'); $dates = iCString::isSerialized($single_dates) ? unserialize($single_dates) : $this->getDates($single_dates); // $dates = !empty($dates[0]) ? $dates : array($noDateTime); rsort($dates); $datesall = iCDate::isDate($dates[0]) ? $dates[0] : $noDateTimeShort; if ($datesall != $noDateTimeShort) { $this->data->dates = serialize($dates); } else { $no_date_array = array($noDateTimeShort); $this->data->dates = serialize($no_date_array); } // Set Next Date from Single Dates $dates_array = unserialize($this->data->dates); $today = JHtml::date('now', 'Y-m-d H:i:s', $eventTimeZone); $next = JHtml::date($this->data->dates[0], 'Y-m-d H:i:s', $eventTimeZone); rsort($dates_array); $nextDate = $next; if ($next <= $today) { foreach ($dates_array as $date) { $single_date = JHtml::date($date, 'Y-m-d H:i:s', $eventTimeZone); if ($single_date >= $today) { $nextDate = $single_date; } } } $single_dates_next = $nextDate; // PERIOD DATES $this->data->startdate = JRequest::getVar('startdate', '', 'post'); $this->data->enddate = JRequest::getVar('enddate', '', 'post'); $isDate_startdate = iCDate::isDate($this->data->startdate); $isDate_enddate = iCDate::isDate($this->data->enddate); $this->data->startdate = $isDate_startdate ? $this->data->startdate : $noDateTime; $this->data->enddate = $isDate_enddate ? $this->data->enddate : $noDateTime; // Dates from the period if ($isDate_startdate && $isDate_enddate) { $startdate = $this->data->startdate; $enddate = $this->data->enddate; if ($startdate == $noDateTime && $enddate != $noDateTime) { $enddate = $noDateTime; } $startcontrol = JHtml::date($startdate, 'Y-m-d H:i', $eventTimeZone); $endcontrol = JHtml::date($enddate, 'Y-m-d H:i', $eventTimeZone); $errorperiod = ''; if ($startcontrol > $endcontrol) { $errorperiod = '1'; } else { $period_all_dates_array = iCDatePeriod::listDates($startdate, $enddate); } // Serialize Dates of the Period if ($isDate_startdate && $isDate_enddate) { if ($errorperiod != '1') { $this->data->period = serialize($period_all_dates_array); $ctrl = unserialize($this->data->period); if (is_array($ctrl)) { $period = unserialize($this->data->period); } else { $period = $this->getPeriod($this->data->period); } rsort($period); $this->data->period = serialize($period); } else { $this->data->period = ''; } } $period_dates_next = $this->data->startdate; $dates_next = JHtml::date($single_dates_next, 'Y-m-d H:i:s', $eventTimeZone); $period_next = JHtml::date($period_dates_next, 'Y-m-d H:i:s', $eventTimeZone); if ($dates_next < $period_next) { $this->data->next = $period_next; } else { $this->data->next = $dates_next; } } else { $this->data->period = ''; $this->data->next = $single_dates_next; } // Period and Single Dates not displayed if ((in_array($noDateTime, $dates_array) || in_array($noDateTimeShort, $dates_array)) && (!$isDate_startdate || !$isDate_enddate)) { $this->data->state = '0'; $this->data->next = $today; // Error message if no valid dates $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_WARNING', JText::_('COM_ICAGENDA_FORM_ERROR_NO_DATES')); } // WEEK DAYS $this->data->weekdays = JRequest::getVar('weekdays', '', 'post'); if (!isset($this->data->weekdays) && !is_array($this->data->weekdays)) { $this->data->weekdays = ''; } if (isset($this->data->weekdays) && is_array($this->data->weekdays)) { $this->data->weekdays = implode(",", $this->data->weekdays); } // Joomla 3.x/2.5 SWITCH if (version_compare(JVERSION, '3.0', 'ge')) { $this->data->desc = JFactory::getApplication()->input->get('desc', '', 'RAW'); } else { $this->data->desc = JRequest::getVar('desc', '', 'post', 'string', JREQUEST_ALLOWHTML); } $this->data->shortdesc = JRequest::getVar('shortdesc', '', 'post'); $this->data->metadesc = JRequest::getVar('metadesc', '', 'post'); $this->data->place = JRequest::getVar('place', '', 'post'); $this->data->email = JRequest::getVar('email', '', 'post'); $this->data->phone = JRequest::getVar('phone', '', 'post'); $this->data->website = JRequest::getVar('website', '', 'post'); // ATTACHMENT FILE $file = JRequest::getVar('file', null, 'files', 'array'); $file_session = JRequest::getVar('file_session', '', 'post'); if ($file_session && empty($file)) { $this->data->file = $file_session; } else { $this->data->file = $file; // Process upload of files $this->data->file = $this->frontendFileUpload($this->data->file); } $this->data->address = JRequest::getVar('address', '', 'post'); $this->data->city = JRequest::getVar('city', '', 'post'); $this->data->country = JRequest::getVar('country', '', 'post'); $this->data->lat = JRequest::getVar('lat', '', 'post'); $this->data->lng = JRequest::getVar('lng', '', 'post'); $this->data->created_by = $user_id; $this->data->created_by_alias = JRequest::getVar('created_by_alias', '', 'post'); $this->data->created = JHtml::Date('now', 'Y-m-d H:i:s'); $this->data->checked_out = JRequest::getVar('checked_out', '', 'post'); $this->data->checked_out_time = JRequest::getVar('checked_out_time', '', 'post'); $this->data->params = JRequest::getVar('params', '', 'post'); $this->data->site_itemid = JRequest::getVar('site_itemid', '0', 'post'); $site_menu_title = JRequest::getVar('site_menu_title', '', 'post'); // Generate Alias $this->data->alias = JFilterOutput::stringURLSafe($this->data->title); // Alias is not generated if non-latin characters, so we fix it by using created date, or title if unicode is activated, as alias if ($this->data->alias == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $this->data->alias = JFilterOutput::stringURLUnicodeSlug($this->data->title); } else { $this->data->alias = JFilterOutput::stringURLSafe($this->data->created); } } // Convert the params field to a string. if (isset($this->data->params) && is_array($this->data->params)) { $parameter = new JRegistry(); $parameter->loadArray($this->data->params); $this->data->params = (string) $parameter; } $this->data->asset_id = null; $custom_fields = JRequest::getVar('custom_fields', '', 'post'); // Check if Custom Fields required not empty $customfields_list = icagendaCustomfields::getListCustomFields($this->data->id, 2, 1); if ($customfields_list) { foreach ($customfields_list as $cf) { if (isset($custom_fields[$cf->cf_slug]) && $cf->cf_required == 1 && $custom_fields[$cf->cf_slug] == '') { $options_required = array('list', 'radio'); // If type is list or radio, should have options if (in_array($cf->cf_type, $options_required) && $cf->cf_options || !in_array($cf->cf_type, $options_required)) { $error_messages[] = JText::_('COM_ICAGENDA_FORM_VALIDATE_FIELD_REQUIRED') . ' ' . $cf->cf_title; } } } } $address_session = JRequest::getVar('address_session', '', 'post'); $submit_tos = JRequest::getVar('submit_tos', '', 'post'); // Set Form Data to Session $session = JFactory::getSession(); $session->set('ic_submit', $this->data); $session->set('custom_fields', $custom_fields); $session->set('ic_submit_dates', $this->data->dates); $session->set('ic_submit_catid', $this->data->catid); $session->set('ic_submit_shortdesc', $this->data->shortdesc); $session->set('ic_submit_metadesc', $this->data->metadesc); $session->set('ic_submit_city', $this->data->city); $session->set('ic_submit_country', $this->data->country); $session->set('ic_submit_lat', $this->data->lat); $session->set('ic_submit_lng', $this->data->lng); $session->set('ic_submit_address', $this->data->address); $session->set('ic_submit_tos', $submit_tos); // Captcha Control $captcha = JRequest::getVar('recaptcha_response_field', '', 'post'); $captcha_plugin = $params->get('captcha') ? $params->get('captcha') : $app->getCfg('captcha'); $submit_captcha = $params->get('submit_captcha', 1); if ($captcha_plugin && $submit_captcha != '0') { JPluginHelper::importPlugin('captcha'); // JOOMLA 3.x/2.5 SWITCH if (version_compare(JVERSION, '3.0', 'ge')) { $dispatcher = JEventDispatcher::getInstance(); } else { $dispatcher = JDispatcher::getInstance(); } $res = $dispatcher->trigger('onCheckAnswer', $captcha); if (!$res[0]) { // message if captcha is invalid $error_messages[] = JText::sprintf('COM_ICAGENDA_FORM_ERROR', JText::_('COM_ICAGENDA_FORM_ERROR_INCORRECT_CAPTCHA_SOL')); } } // Get the message queue if (count($error_messages)) { $app->enqueueMessage('<strong>' . JText::_('COM_ICAGENDA_FORM_NC') . '</strong>', 'error'); foreach ($error_messages as $msg) { $app->enqueueMessage($msg, 'error'); } return false; } // clear the data so we don't process it again $session->clear('ic_submit'); $session->clear('custom_fields'); $session->clear('ic_submit_dates'); $session->clear('ic_submit_catid'); $session->clear('ic_submit_shortdesc'); $session->clear('ic_submit_metadesc'); $session->clear('ic_submit_city'); $session->clear('ic_submit_country'); $session->clear('ic_submit_lat'); $session->clear('ic_submit_lat'); $session->clear('ic_submit_address'); $session->clear('ic_submit_tos'); // insert Event in Database $db = JFactory::getDbo(); if ($this->data->username != NULL && $this->data->title != NULL && $this->data->created_by_email != NULL) { $db->insertObject('#__icagenda_events', $this->data, id); } else { JError::raiseError(500, implode('<br />', $errors)); return false; } // Save Custom Fields to database if (isset($custom_fields) && is_array($custom_fields)) { icagendaCustomfields::saveToData($custom_fields, $this->data->id, 2); } // Get the "event" URL $baseURL = JURI::base(); $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); $urlsend = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=submit&layout=send')); // Sub Path filtering $subpathURL = ltrim($subpathURL, '/'); // URL List filtering $urlsend = ltrim($urlsend, '/'); if (substr($urlsend, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlsend = substr($urlsend, strlen($subpathURL) + 1); } $urlsend = rtrim($baseURL, '/') . '/' . ltrim($urlsend, '/'); if (isset($this->data->id) and $this->data->id != '0' and $this->data->username != NULL and $this->data->title != NULL) { self::notificationManagerEmail($this->data, $site_menu_title, $user_id); if (!in_array($user_id, $adminUsersArray)) { self::notificationUserEmail($this->data, $urlsend); } } else { JError::raiseError(500, implode('<br />', $errors)); return false; } // redirect after successful submission $submit_return = $params->get('submitReturn', ''); $submit_return_article = $params->get('submitReturn_Article', $urlsend); $submit_return_url = $params->get('submitReturn_Url', $urlsend); if ($submit_return == 1 && is_numeric($submit_return_article)) { $url_return = JURI::root() . 'index.php?option=com_content&view=article&id=' . $submit_return_article; } elseif ($submit_return == 2) { $url_return = $submit_return_url; } else { $url_return = $urlsend; } $alert_title = $params->get('alert_title', ''); $alert_body = $params->get('alert_body', ''); $url_redirect = $urlsend_custom ? $urlsend_custom : $urlsend; $alert_title_redirect = $alert_title ? $alert_title : JText::_('COM_ICAGENDA_EVENT_SUBMISSION'); $alert_body_redirect = $alert_body ? $alert_body : JText::_('COM_ICAGENDA_EVENT_SUBMISSION_CONFIRMATION'); if ($submit_return != 2) { $app->enqueueMessage($alert_body_redirect, $alert_title_redirect); $app->redirect(htmlspecialchars_decode($url_return)); } else { $url_return = iCUrl::urlParsed($url_return, 'scheme'); $app->redirect($url_return); } }