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; } }
protected function notificationManagerEmail($data, $site_menu_title, $user_id) { $event_id = $data->id; $event_title = $data->title; $event_site_itemid = $data->site_itemid; $event_username = $data->username; $event_user_email = $data->created_by_email; $event_ref = JHtml::date('now', 'Ymd') . $data->id; // Load iCagenda Global Options $iCparams = JComponentHelper::getParams('com_icagenda'); // Load Joomla Application $app = JFactory::getApplication(); // Load Joomla Config Mail Options $sitename = $app->getCfg('sitename'); $mailfrom = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $siteURL = JURI::base(); $siteURL = rtrim($siteURL, '/'); // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID, and depending of current language) $menu_items = icagendaMenus::iClistMenuItems(); $itemid_array = array(); foreach ($menu_items as $l) { array_push($itemid_array, $l->id); } sort($itemid_array); $itemID = $itemid_array[0]; // Set Notification Email to each User groups allowed to approve event submitted $groupid = $iCparams->get('approvalGroups', array("8")); // Load Global Option for Autologin $autologin = $iCparams->get('auto_login', 1); jimport('joomla.access.access'); $adminUsersArray = array(); foreach ($groupid as $gp) { $adminUsers = JAccess::getUsersByGroup($gp, False); $adminUsersArray = array_merge($adminUsersArray, $adminUsers); } $db = JFactory::getDbo(); $query = $db->getQuery(true); if ($user_id == NULL) { $user_id = 0; } if (!in_array($user_id, $adminUsersArray)) { $matches = implode(',', $adminUsersArray); $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id IN ({$matches}) "); } else { $matches = $user_id; $query->select('ui.username AS username, ui.email AS email, ui.password AS passw, ui.block AS block, ui.activation AS activation')->from('#__users AS ui')->where("ui.id = {$matches} "); } $db->setQuery($query); $managers = $db->loadObjectList(); foreach ($managers as $manager) { // Mail Replacements $replacements = array("\\n" => "\n", '[SITENAME]' => $sitename, '[USERNAME]' => $event_username, '[EMAIL]' => $event_user_email, '[EVENT_TITLE]' => $event_title, '[EVENT_REF]' => $event_ref, ' ' => ' '); if (!in_array($user_id, $adminUsersArray)) { $type = 'approval'; } else { $type = 'confirmation'; } // Create Admin Mailer $adminmailer = JFactory::getMailer(); // Set Sender of Notification Email $adminmailer->setSender(array($mailfrom, $fromname)); $username = $manager->username; $passw = $manager->passw; $email = $manager->email; // Set Recipient of Notification Email $adminrecipient = $email; $adminmailer->addRecipient($adminrecipient); // Set Subject of Admin Notification Email if (!in_array($user_id, $adminUsersArray)) { $adminsubject = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_SUBJECT', $event_username, $sitename); } else { $adminsubject = JText::sprintf('COM_ICAGENDA_LEGEND_NEW_EVENT') . ': ' . $event_title; } // Set Url to preview and checking of event submitted $baseURL = JURI::base(); $subpathURL = JURI::base(true); $baseURL = str_replace('/administrator', '', $baseURL); $subpathURL = str_replace('/administrator', '', $subpathURL); if ($autologin == 1) { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID . '&icu=' . $username . '&icp=' . $passw)); // $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid='.(int)$itemID).'&icu='.$username.'&icp='.$passw.'&filter_search='.$event_id); } else { $urlpreview = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID)); // $urlcheck = str_replace('&', '&', JRoute::_('administrator/index.php?option=com_icagenda&view=events&Itemid='.(int)$itemID).'&filter_search='.$event_id); } // $urlpreview = str_replace('&', '&', $siteURL.'/index.php?option=com_icagenda&view=list&layout=event&id='.(int)$event_id.'&Itemid='.(int)$itemID.'&icu='.$username.'&icp='.$passw); $urlpreviewshort = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=list&layout=event&id=' . (int) $event_id . '&Itemid=' . (int) $itemID)); // $urlcheckshort = str_replace('&', '&', $siteURL . '/administrator/index.php?option=com_icagenda&view=events'); // Sub Path filtering $subpathURL = ltrim($subpathURL, '/'); // URL Event Preview filtering $urlpreview = ltrim($urlpreview, '/'); $urlpreviewshort = ltrim($urlpreviewshort, '/'); if (substr($urlpreview, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlpreview = substr($urlpreview, strlen($subpathURL) + 1); } if (substr($urlpreviewshort, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") { $urlpreviewshort = substr($urlpreviewshort, strlen($subpathURL) + 1); } $urlpreview = rtrim($baseURL, '/') . '/' . ltrim($urlpreview, '/'); $urlpreviewshort = rtrim($baseURL, '/') . '/' . ltrim($urlpreviewshort, '/'); // URL Event Check filtering // $urlcheck = ltrim($urlcheck, '/'); // if (substr($urlcheck, 0, strlen($subpathURL)+1) == "$subpathURL/") // { // $urlcheck = substr($urlcheck, strlen($subpathURL)+1); // } // $urlcheck = rtrim($baseURL, '/') . '/' . ltrim($urlcheck, '/'); // Set Body of User Notification Email $adminbodycontent = JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_HELLO', $username) . ',<br /><br />'; if ($type == 'approval') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_NEW_EVENT') . '<br /><br />'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_INFO', $sitename) . '<br /><br />'; $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVE_LINK') . ': <a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } if ($type == 'confirmation') { $adminbodycontent .= JText::_('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_APPROVED_REVIEW') . '<br /><br />'; $adminbodycontent .= '<a href="' . $urlpreview . '">' . $urlpreviewshort . '</a><br /><br />'; } $user_email_mailto = '<a href="mailto:' . $event_user_email . '">' . $event_user_email . '</a>'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_SITE_MENUID', $event_site_itemid, $site_menu_title) . '<br />'; $adminbodycontent .= JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_USER_INFO', $event_username, $user_email_mailto) . '<br /><br />'; if ($autologin == 1) { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER', $sitename) . '<small>'; } else { $adminbodycontent .= '<hr><small>' . JText::sprintf('COM_ICAGENDA_SUBMISSION_ADMIN_EMAIL_FOOTER_NO_AUTOLOGIN', $sitename) . '<small>'; } $adminbody = rtrim($adminbodycontent); // Apply Replacements foreach ($replacements as $key => $value) { $adminsubject = str_replace($key, $value, $adminsubject); $adminbody = str_replace($key, $value, $adminbody); } $adminmailer->isHTML(true); $adminmailer->Encoding = 'base64'; // Set Subject $adminmailer->setSubject($adminsubject); // Set Body $adminmailer->setBody($adminbody); // Send User Notification Email if (isset($email)) { if ($manager->block == '0' && empty($manager->activation)) { $send = $adminmailer->Send(); } } } }