Ejemplo n.º 1
0
 /**
  * Function to test if date is a valid Datetime
  *
  * @access	public static
  * @param	$date : date to be tested (1993-04-30 14:33:00)
  * @return	alias
  *
  * @since   1.1.0
  */
 public static function isDate($date)
 {
     $stamp = strtotime($date);
     $date_numeric = iCDate::dateToNumeric($date);
     $date_valid = str_replace('0', '', $date_numeric);
     if (!is_numeric($stamp) || !$date_valid) {
         return false;
     }
     return true;
 }
Ejemplo n.º 2
0
 /**
  * Function to return all dates of a period (from ... to ...)
  *
  * @access	public static
  * @param	$startdate : start datetime of the period (0000-00-00 00:00:00)
  * 			$enddate : end datetime of the period (0000-00-00 00:00:00)
  * 			$timezone : Time zone to be used for the date.
  *						Special cases: boolean true for user setting, boolean false for server setting.
  *						Default: null, no timezone.
  * @return	array of all dates of the period
  *
  * @since	1.1.0
  */
 public static function listDates($startdate, $enddate, $timezone = null)
 {
     $test_startdate = iCDate::isDate($startdate);
     $test_enddate = iCDate::isDate($enddate);
     $out = array();
     if ($test_startdate && $test_enddate) {
         $timestartdate = date('H:i', strtotime($startdate));
         $timeenddate = date('H:i', strtotime($enddate));
         if (class_exists('DateInterval')) {
             // Create array with all dates of the period - PHP 5.3+
             $start = new DateTime($startdate);
             $interval = '+1 days';
             $date_interval = DateInterval::createFromDateString($interval);
             if ($timeenddate <= $timestartdate) {
                 $end = new DateTime("{$enddate} +1 days");
             } else {
                 $end = new DateTime($enddate);
             }
             // Return all dates.
             $perioddates = new DatePeriod($start, $date_interval, $end);
             foreach ($perioddates as $date) {
                 $out[] = $date->format('Y-m-d H:i');
             }
         } else {
             // TO BE REMOVED : when Joomla 2.5 and php 5.2 support will end
             // Create array with all dates of the period - PHP 5.2
             $nodate = '0000-00-00 00:00:00';
             if ($startdate != $nodate && $enddate != $nodate) {
                 $start = new DateTime($startdate);
                 if ($timeenddate <= $timestartdate) {
                     $end = new DateTime("{$enddate} +1 days");
                 } else {
                     $end = new DateTime($enddate);
                 }
                 while ($start < $end) {
                     $out[] = $start->format('Y-m-d H:i');
                     $start->modify('+1 day');
                 }
             }
         }
         return $out;
     } else {
         return array();
     }
 }
Ejemplo n.º 3
0
                echo $item->enddate;
                ?>
										<?php 
            }
            ?>
									<?php 
        } elseif (!$item->date && $item->period == 1) {
            ?>
										<?php 
            echo JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_FOR_ALL_DATES');
            ?>
									<?php 
        } else {
            ?>
										<?php 
            if (iCDate::isDate($item->date)) {
                ?>
											<?php 
                echo iCGlobalize::dateFormat($item->date, $dateFormat, $dateSeparator);
                ?>
											<?php 
                if ($item->displaytime) {
                    ?>
												<?php 
                    echo ' - ' . date($timeFormat, strtotime($item->date));
                    ?>
											<?php 
                }
                ?>
										<?php 
            } else {
Ejemplo n.º 4
0
 /**
  * Single Dates list for one event
  */
 private function getDatelist($dates, $next)
 {
     $dates = iCString::isSerialized($dates) ? unserialize($dates) : array();
     $da = array();
     foreach ($dates as $d) {
         if (strtotime($d) >= strtotime($next) && iCDate::isDate($d)) {
             array_push($da, date('Y-m-d H:i', strtotime($d)));
         }
     }
     return $da;
 }
Ejemplo n.º 5
0
    protected function AllDates($saved_date, $saved_time, $event_id, $saveddate, $data_eventid, $date_is_datetime_sql)
    {
        // Preparing connection to db
        $db = JFactory::getDbo();
        // Preparing the query
        $query = $db->getQuery(true);
        // Selectable items
        $query->select('next AS next, dates AS dates,
						startdate AS startdate, enddate AS enddate, weekdays AS weekdays,
						id AS id, state AS state, access AS access, params AS params');
        $query->from('`#__icagenda_events` AS e');
        //		$query->where(' e.id = '.$event_id);
        $list_of_dates_id = $event_id ? $event_id : $data_eventid;
        if ($list_of_dates_id) {
            $query->where('(' . $list_of_dates_id . ' = e.id)');
        }
        $db->setQuery($query);
        $allnext = $db->loadObjectList();
        foreach ($allnext as $i) {
            // Set Event Params
            $eventparam = new JRegistry($i->params);
            $typeReg = $eventparam->get('typeReg');
            // Declare AllDates array
            $AllDates = array();
            // Get WeekDays setting
            $WeeksDays = iCDatePeriod::weekdaysToArray($i->weekdays);
            // If Single Dates, added each one to All Dates for this event
            $singledates = iCString::isSerialized($i->dates) ? unserialize($i->dates) : array();
            foreach ($singledates as $sd) {
                $isValid = iCDate::isDate($sd);
                if ($isValid) {
                    array_push($AllDates, $sd);
                }
            }
            // If Period Dates, added each one to All Dates for this event (filter week Days, and if date not null)
            $perioddates = iCDatePeriod::listDates($i->startdate, $i->enddate);
            $onlyStDate = isset($this->onlyStDate) ? $this->onlyStDate : '';
            if (isset($perioddates) && is_array($perioddates)) {
                foreach ($perioddates as $Dat) {
                    if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                        // May not work in php < 5.2.3 (should return false if date null since 5.2.4)
                        $isValid = iCDate::isDate($Dat);
                        if ($isValid) {
                            $SingleDate = date('Y-m-d H:i', strtotime($Dat));
                            array_push($AllDates, $SingleDate);
                        }
                    }
                }
            }
        }
        $today = time();
        // get Time Format
        $timeformat = JComponentHelper::getParams('com_icagenda')->get('timeformat', '1');
        $lang_time = $timeformat == 1 ? 'H:i' : 'h:i A';
        if (!empty($AllDates)) {
            sort($AllDates);
        }
        $eventid_url = JRequest::getVar('eventid', '');
        echo '<div>';
        echo '<select type="hidden" name="' . $this->name . '">';
        if (!$eventid_url || $eventid_url == $data_eventid) {
            $date_value = $saveddate;
        } else {
            $date_value = '';
        }
        $selected = !strtotime($saveddate) ? ' selected="selected"' : '';
        $reg_datetime = date('Y-m-d H:i:s', strtotime($saved_date . ' ' . $saved_time));
        $is_valid = date('Y-m-d H:i:s', strtotime($reg_datetime)) == $saveddate;
        $if_old_value = !$is_valid ? $saveddate : '';
        echo '<option value="' . $if_old_value . '">- ' . JText::_('COM_ICAGENDA_REGISTRATION_NO_DATE_SELECTED') . ' -</option>';
        $date_exist = false;
        if ($list_of_dates_id) {
            foreach ($AllDates as $date) {
                if ($date && $date != '0000-00-00 00:00' && $date != '0000-00-00 00:00:00') {
                    $value_datetime = date('Y-m-d H:i:s', strtotime($date));
                    echo '<option value="' . $value_datetime . '"';
                    if ($reg_datetime == $value_datetime) {
                        $date_exist = true;
                        echo ' selected="selected"';
                    }
                    echo '>' . $this->formatDate($date) . ' - ' . date($lang_time, strtotime($date)) . '</option>';
                }
            }
        }
        echo '</select>';
        echo '</div>';
        if (!empty($AllDates) && !in_array(date('Y-m-d H:i', strtotime($saveddate)), $AllDates) && $date_is_datetime_sql) {
            $date_no_longer_exists = '<strong>"' . $saveddate . '"</strong>';
            echo '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_DATE_NO_LONGER_EXISTS', $date_no_longer_exists) . '</small></div>';
        }
    }
Ejemplo n.º 6
0
 /**
  * MONTH SHORT in Date Box (list of events)
  *
  * @since 3.5.0
  */
 public static function dateBox($date, $type, $ongoing = null)
 {
     $datetime_today = JHtml::date('now', 'Y-m-d H:i');
     $monthshort_date = iCDate::monthShortJoomla($date);
     $monthshort_today = iCDate::monthShortJoomla($datetime_today);
     $year_date = JHtml::date($date, 'Y', null);
     //		$year_date			= date('Y', strtotime($date));
     $year_today = JHtml::date('now', 'Y');
     if ($ongoing) {
         switch ($type) {
             case 'monthshort':
                 $value = $monthshort_today;
                 break;
             case 'year':
                 $value = $year_today;
                 break;
         }
     } else {
         switch ($type) {
             case 'monthshort':
                 $value = $monthshort_date;
                 break;
             case 'year':
                 $value = $year_date;
                 break;
         }
     }
     return $value;
 }
Ejemplo n.º 7
0
    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=' : '&amp;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('&amp;', '&', 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('&amp;', '&', 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('&amp;', '&', 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('&amp;', '&', 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, '&nbsp;' => ' ');
            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;
        }
    }
Ejemplo n.º 8
0
 /**
  * Get file name
  *
  * @return  string    The file name
  *
  * @since   1.6
  */
 public function getBaseName()
 {
     if (!isset($this->basename)) {
         $app = JFactory::getApplication();
         $basename = $this->getState('basename');
         $basename = str_replace('__SITE__', $app->getCfg('sitename'), $basename);
         $eventId = $this->getState('filter.events');
         if (is_numeric($eventId)) {
             $basename = str_replace('__EVENTID__', $eventId, $basename);
             $basename = str_replace('__EVENT__', $this->getEventTitle($eventId), $basename);
         } else {
             $basename = str_replace('__EVENTID__', '', $basename);
             $basename = str_replace('__EVENT__', '', $basename);
         }
         $date = $this->getState('filter.dates');
         if (!empty($date)) {
             if (iCDate::isDate($date)) {
                 $basename = str_replace('__DATE__', JHtml::date($date, JText::_('DATE_FORMAT_LC3'), null) . ' - ' . date('H:i', strtotime($date)), $basename);
             } else {
                 $basename = str_replace('__DATE__', $date, $basename);
             }
         } else {
             $basename = str_replace('__DATE__', '', $basename);
         }
         $this->basename = $basename;
     }
     return $this->basename;
 }
Ejemplo n.º 9
0
 /**
  * Send the email
  *
  * @return  boolean
  */
 public function send()
 {
     $app = JFactory::getApplication();
     $data = $app->input->post->get('jform', array(), 'array');
     $user = JFactory::getUser();
     $access = new JAccess();
     // Set Form Data to Session
     $session = JFactory::getSession();
     $session->set('ic_newsletter', $data);
     $mailer = JFactory::getMailer();
     $config = JFactory::getConfig();
     $send = '';
     $sender = array($app->getCfg('mailfrom'), $app->getCfg('fromname'));
     $mailer->setSender($sender);
     //		$list		= array_key_exists('list', $data) ? $data['list'] : ''; // DEPRECATED
     $eventid = array_key_exists('eventid', $data) ? $data['eventid'] : '';
     $date = array_key_exists('date', $data) ? $data['date'] : '';
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select('r.email, r.eventid, r.state, r.date, r.people')->from('`#__icagenda_registration` AS r');
     $query->where('r.state = 1');
     $query->where('r.email <> ""');
     $query->where('r.eventid = ' . (int) $eventid);
     if ($date != 'all') {
         if (iCDate::isDate($date)) {
             $query->where('r.date = ' . $db->q($date));
         } elseif ($date == 1) {
             $query->where('r.period = 1');
         } elseif ($date) {
             // Fix for old date saving data
             $query->where('r.date = ' . $db->q($date));
         } else {
             $query->where('r.period = 0');
         }
     }
     $db->setQuery($query);
     $result = $db->loadObjectList();
     $list = '';
     $people = 0;
     foreach ($result as $v) {
         $list .= $v->email . ', ';
         $people = $people + $v->people;
     }
     $subject = array_key_exists('subject', $data) ? $data['subject'] : '';
     $messageget = array_key_exists('message', $data) ? $data['message'] : '';
     $list_emails = explode(', ', $list);
     // Remove dupplicated email addresses
     $recipient = array_unique($list_emails);
     $dupplicated_emails = count($list_emails) - count($recipient);
     $obj = $subject;
     $message = $messageget;
     $recipient = array_filter($recipient);
     //		$mailer->addRecipient($recipient);
     //		$mailer->addRecipient($sender);
     $mailer->addBCC($recipient);
     $content = stripcslashes($message);
     $body = str_replace('src="images/', 'src="' . JURI::root() . '/images/', $content);
     //		$mailer->setSender(array( $mailfrom, $fromname ));
     $mailer->setSubject($obj);
     $mailer->isHTML(true);
     $mailer->Encoding = 'base64';
     $mailer->setBody($body);
     if ($obj && $body && $eventid && ($date || $date == '0')) {
         $send = $mailer->Send();
     }
     if ($send !== true) {
         $app->enqueueMessage(JText::_('COM_ICAGENDA_NEWSLETTER_ERROR_ALERT'), 'error');
         if (!$obj) {
             $app->enqueueMessage('- ' . JText::_('COM_ICAGENDA_NEWSLETTER_NO_OBJ_ALERT'), 'error');
         }
         if (!$body) {
             $app->enqueueMessage('- ' . JText::_('COM_ICAGENDA_NEWSLETTER_NO_BODY_ALERT'), 'error');
         }
         if (!$eventid && (!$date && $date != '0')) {
             $app->enqueueMessage('- ' . JText::_('COM_ICAGENDA_NEWSLETTER_NO_EVENT_SELECTED'), 'error');
         } elseif ($eventid && (!$date && $date != '0')) {
             $app->enqueueMessage('- ' . JText::_('COM_ICAGENDA_NEWSLETTER_NO_DATE_SELECTED'), 'error');
         }
         return false;
     } else {
         $app->enqueueMessage('<h2>' . JText::_('COM_ICAGENDA_NEWSLETTER_SUCCESS') . '</h2>', 'message');
         $app->enqueueMessage($this->listSend($recipient, 0, $people), 'message');
         if ($dupplicated_emails) {
             $app->enqueueMessage('<i>' . JText::sprintf('COM_ICAGENDA_NEWSLETTER_NB_EMAIL_NOT_SEND', $dupplicated_emails) . '</i>', 'message');
         }
         //			$app->setUserState('com_icagenda.mail.data', null);
         //			echo '<pre>'.print_r($recipient, true).'</pre>';
         return true;
     }
 }
Ejemplo n.º 10
0
 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('&amp;', '&', 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);
     }
 }
Ejemplo n.º 11
0
    protected function getInput()
    {
        $jinput = JFactory::getApplication()->input;
        $view = $jinput->get('view');
        $id = $jinput->get('id', null);
        $eventid = $jinput->get('eventid', $this->value);
        $class = isset($this->class) ? ' class="' . $this->class . '"' : '';
        $typeReg = $db_date = $db_period = $db_date_is_valid = '';
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('e.title, e.state, e.id, e.weekdays, e.params')->from('`#__icagenda_events` AS e');
        if ($view == 'mail') {
            // Join Total of registrations
            $query->select('r.count AS registered');
            $sub_query = $db->getQuery(true);
            $sub_query->select('r.state, r.date AS reg_date, r.period AS reg_period, r.eventid, sum(r.people) AS count');
            $sub_query->from('`#__icagenda_registration` AS r');
            $sub_query->where('r.state = 1');
            $sub_query->where('r.email <> ""');
            $sub_query->group('r.eventid');
            $query->leftJoin('(' . (string) $sub_query . ') AS r ON (e.id = r.eventid)');
            $query->where('r.count > 0');
        }
        $query->order('e.title ASC');
        $db->setQuery($query);
        $events = $db->loadObjectList();
        if ($eventid != 0 && $view == 'registration') {
            $query = $db->getQuery(true);
            $query->select('r.date AS reg_date, r.period AS reg_period')->from('`#__icagenda_registration` AS r');
            $query->where('r.eventid = ' . (int) $eventid);
            $query->where('r.id = ' . (int) $id);
            $db->setQuery($query);
            $reg = $db->loadObject();
            $db_date = $reg->reg_date;
            $db_date_is_valid = iCDate::isDate($db_date);
            $db_period = $reg->reg_period;
        }
        // User state used in Newsletter
        $data = JFactory::getApplication()->getUserState('com_icagenda.mail.data', array());
        $session_eventid = isset($data['eventid']) ? $data['eventid'] : $eventid;
        $session_date = isset($data['date']) ? $data['date'] : '';
        $html = '<div style="margin-bottom: 10px">';
        $html .= '<select id="' . $this->id . '_id"' . $class . ' name="' . $this->name . '">';
        $value = isset($this->value) ? $this->value : '';
        $html .= '<option value=""';
        if (!$id || !$this->value) {
            $html .= ' selected="selected"';
        }
        $html .= '>' . JText::_('COM_ICAGENDA_SELECT_EVENT') . '</option>';
        foreach ($events as $e) {
            if ($e->state == '1') {
                $html .= '<option value="' . $e->id . '"';
                if ($eventid == $e->id) {
                    $eventparam = new JRegistry($e->params);
                    $typeReg = $eventparam->get('typeReg', 1);
                    $weekdays = $e->weekdays;
                    $html .= ' selected="selected"';
                }
                if ($view == 'registration') {
                    $html .= '>' . $e->title . ' (id:' . $e->id . ')</option>';
                } else {
                    $html .= '>' . $e->title . ' (&#10003;' . $e->registered . ' - id:' . $e->id . ')</option>';
                }
            } elseif ($eventid == $e->id) {
                $html .= '<option value="' . $value . '"';
                $html .= ' selected="selected"';
                $html .= '>' . JText::_('COM_ICAGENDA_REGISTRATION_EVENT_NOT_PUBLISHED') . '</option>';
            }
        }
        $html .= '</select>';
        $html .= '</div>';
        $id_display = $id ? '&id=' . (int) $id : '';
        if ($view == 'registration') {
            // Info message with 'Registration Type' option setting, if the saved date is not in the list of dates for selected event.
            if ($typeReg == 1) {
                $reg_type = JText::_('COM_ICAGENDA_REG_BY_INDIVIDUAL_DATE');
            } elseif ($typeReg == 2) {
                $reg_type = JText::_('COM_ICAGENDA_REG_FOR_ALL_DATES');
            } else {
                $reg_type = JText::_('COM_ICAGENDA_REG_BY_DATE_OR_PERIOD');
            }
            $registration_type = '<strong>' . $reg_type . '</strong>';
            $alert_reg_type = '<div class="alert alert-info">';
            $alert_reg_type .= '<small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_TYPE_FOR_THIS_EVENT', $registration_type) . '</small>';
            $alert_reg_type .= '</div>';
            $alert_reg_type = addslashes($alert_reg_type);
            // Alert message for a date saved with a version before 3.3.3 (date not formatted as expected in sql format)
            $date_no_longer_exists = '<strong>"' . $db_date . '"</strong>';
            $alert_date_format = '<div class="ic-alert ic-alert-note"><span class="iCicon-info"></span> <strong>' . JText::_('NOTICE') . '</strong><br />' . JText::sprintf('COM_ICAGENDA_REGISTRATION_ERROR_DATE_CONTROL', $date_no_longer_exists) . '</div>';
            $alert_date_format = addslashes($alert_date_format);
            // Alert message if a date does not exist anymore for the selected event
            $alert_date_no_longer_exists = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_DATE_NO_LONGER_EXISTS', $date_no_longer_exists) . '</small></div>';
            $alert_date_no_longer_exists = addslashes($alert_date_no_longer_exists);
            // Alert message if a date does not exist anymore for the selected event
            $alert_full_period_no_longer_exists = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_PERIOD_NO_LONGER_EXISTS', $date_no_longer_exists) . '</small></div>';
            $alert_full_period_no_longer_exists = addslashes($alert_full_period_no_longer_exists);
            // Alert message if a date or period is set for the registration, but event registration type is now 'for all dates of the event'
            $for_all_dates = '<strong>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_FOR_ALL_DATES') . '</strong>';
            $alert_by_date_no_longer_possible = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_BY_DATE_NO_LONGER_POSSIBLE', $for_all_dates, $for_all_dates) . '</small></div>';
            $alert_by_date_no_longer_possible = addslashes($alert_by_date_no_longer_possible);
            // Alert message if registration for all dates of the event, but event registration type is now 'select list of dates'
            $by_date = '<strong>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_BY_INDIVIDUAL_DATE') . '</strong>';
            $alert_for_all_dates_no_longer_possible = '<div class="alert alert-error"><strong>' . JText::_('COM_ICAGENDA_FORM_WARNING') . '</strong><br /><small>' . JText::sprintf('COM_ICAGENDA_REGISTRATION_FOR_ALL_DATES_NO_LONGER_POSSIBLE', $by_date) . '</small></div>';
            $alert_for_all_dates_no_longer_possible = addslashes($alert_for_all_dates_no_longer_possible);
            $html .= '<div id="date-alert">';
            $html .= '</div>';
            if ($typeReg == '1') {
                ?>
				<script type="text/javascript">
					jQuery(document).ready(function($) {
						var value = $('#jform_date_id').val(),
							db_date = '<?php 
                echo $db_date;
                ?>
',
							db_period = '<?php 
                echo $db_period;
                ?>
',
							db_weekdays = '<?php 
                echo $weekdays;
                ?>
',
							db_date_is_valid = '<?php 
                echo $db_date_is_valid;
                ?>
',
							alert_reg_type = '<?php 
                echo $alert_reg_type;
                ?>
',
							alert_date_format = '<?php 
                echo $alert_date_format;
                ?>
',
							alert_date_no_longer_exists = '<?php 
                echo $alert_date_no_longer_exists;
                ?>
',
							alert_full_period_no_longer_exists = '<?php 
                echo $alert_full_period_no_longer_exists;
                ?>
',
							alert_for_all_dates_no_longer_possible = '<?php 
                echo $alert_for_all_dates_no_longer_possible;
                ?>
';

						if ( db_date == '' && db_period == '1' ) {
							// Registration for all dates, not possible if registration type is per date
							$('#date-alert').html(alert_reg_type+alert_for_all_dates_no_longer_possible);
						}
						else if ( !db_date_is_valid && db_date !== '' ) {
							// Date is not empty, but not a valid sql format (registration before release 3.3.3)
							$('#date-alert').html(alert_reg_type+alert_date_format);
						}
						else if ( db_date !== value && db_period !== '0') {
							// Date is not empty, but date is not anymore set for this event
							$('#date-alert').html(alert_date_no_longer_exists);
						}
						else if ( db_date == '' && db_period == '0' &&
							db_weekdays !== '' && db_weekdays !== '0') {
							// Date is not empty, but date is not anymore set for this event
							$('#date-alert').html(alert_full_period_no_longer_exists);
						}

						$('#jform_date_id').change(function(e) {
							$('#jform_period').val('0');
							$('#date-alert').html('');
						});
					});
				</script>
				<?php 
            } elseif ($typeReg == '2') {
                ?>
				<script type="text/javascript">
					jQuery(document).ready(function($) {
						var value = $('#jform_date_id').val(),
							db_date = '<?php 
                echo $db_date;
                ?>
',
							db_period = '<?php 
                echo $db_period;
                ?>
',
							alert_reg_type = '<?php 
                echo $alert_reg_type;
                ?>
',
							alert_by_date_no_longer_possible = '<?php 
                echo $alert_by_date_no_longer_possible;
                ?>
';

						$('#date-alert').html(alert_reg_type);

						if ( db_period !== '1' ) {
							// Date is empty, not possible if registration type is per date
							$('#date-alert').html(alert_reg_type+alert_by_date_no_longer_possible);
						}

						$('#jform_date_id').change(function(e) {
//							if ( value == 'update' ) {
								$('#jform_period').val('1');
								$('#date-alert').html('');
//							}
						});
					});
				</script>
			<?php 
            }
        }
        ?>
		<script type="text/javascript">
		jQuery(document).ready(function($) {
			var view = '<?php 
        echo $view;
        ?>
',
				regid = '<?php 
        echo $id;
        ?>
',
				eventid = '<?php 
        echo $session_eventid;
        ?>
',
				date = '<?php 
        echo $session_date;
        ?>
',
				list_target_id = 'jform_date_id',
				list_select_id = '<?php 
        echo $this->id;
        ?>
_id',
				initial_target_html = '<option value=""><?php 
        echo JText::_("COM_ICAGENDA_SELECT_NO_EVENT_SELECTED");
        ?>
...</option>',
				loading = '<?php 
        echo JText::_("IC_LOADING");
        ?>
';

			if (eventid) {
				$('#'+list_target_id).removeAttr('readonly');
				$('#'+list_target_id).val(date);

				$.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+eventid+'&regid='+regid,
					success: function(output) {
							$('#'+list_target_id).html(output);
					},
					error: function (xhr, ajaxOptions, thrownError) {
							alert(xhr.status + " "+ thrownError);
					}
				});

				$('#'+list_select_id).change(function(e) {
					$('#'+list_target_id).removeAttr('readonly');

					var selectvalue = $(this).val();

					$('#'+list_target_id).html('<option value="">'+loading+'</option>');

					if (selectvalue == "") {
						$('#'+list_target_id).attr('readonly', 'true');
						$('#'+list_target_id).html(initial_target_html);
					} else {
						$.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+selectvalue+'&regid='+regid,
							success: function(output) {
									$('#'+list_target_id).html(output);
							},
							error: function (xhr, ajaxOptions, thrownError) {
									alert(xhr.status + " "+ thrownError);
							}
						});
					}
				});
			} else {
				$('#'+list_target_id).attr('readonly', 'true');
				$('#'+list_target_id).html(initial_target_html);

				$('#'+list_select_id).change(function(e) {
					$('#'+list_target_id).removeAttr('readonly');

					var selectvalue = $(this).val();

					$('#'+list_target_id).html('<option value="">'+loading+'</option>');

					if (selectvalue == "") {
						$('#'+list_target_id).attr('readonly', 'true');
						$('#'+list_target_id).html(initial_target_html);
					} else {
						$.ajax({url: 'index.php?option=com_icagenda&task='+view+'.dates&eventid='+selectvalue+'&regid='+regid,
							success: function(output) {
									$('#'+list_target_id).html(output);
							},
							error: function (xhr, ajaxOptions, thrownError) {
									alert(xhr.status + " "+ thrownError);
							}
						});
					}
				});
			}
		});
		</script>
		<?php 
        return $html;
    }
Ejemplo n.º 12
0
    }
    ?>

					</td>

					<!-- Dates -->
					<td class="small hidden-phone">
						<?php 
    $date_format_global = $this->params->get('date_format_global', 'Y - m - d');
    $separator = $this->params->get('date_separator', ' ');
    $eventDate = iCGlobalize::dateFormat($item->next, $date_format_global, $separator);
    $eventTime = $item->displaytime ? ' - ' . JHtml::date($item->next, 'H:i', null) : '';
    $eventDate = $eventDate ? $eventDate : date('Y-m-d', strtotime($item->next));
    $dateshow = $eventDate . $eventTime;
    // Upcoming Next Date
    if (iCDate::isDate($item->next)) {
        if ($nextdate > $today) {
            echo '<div class="ic-nextdate ic-upcoming">';
            echo JText::_('COM_ICAGENDA_EVENTS_NEXT_FUTUR') . '<br />';
            echo '<center>' . $dateshow . '</center>';
            echo '</div>';
        } elseif ($nextdate == $today) {
            echo '<div class="ic-nextdate ic-today">';
            echo JText::_('COM_ICAGENDA_EVENTS_NEXT_TODAY') . '<br />';
            echo '<center>' . $dateshow . '</center>';
            echo '</div>';
        } elseif ($nextdate < $today) {
            echo '<div class="ic-nextdate ic-past">';
            echo JText::_('COM_ICAGENDA_EVENTS_NEXT_PAST') . '<br />';
            echo '<center>' . $dateshow . '</center>';
            echo '</div>';
Ejemplo n.º 13
0
 public static function getOptionsAllDates($i, $view = null, $reg_date = null, $reg_period = null)
 {
     $options = '';
     if ($i) {
         // Set Event Params
         $eventparam = new JRegistry($i->params);
         $typeReg = $eventparam->get('typeReg');
         // Registration type for event is set to "All dates of the event"
         if ($typeReg == '2') {
             if ($reg_period != 1) {
                 $options .= '<option value="' . $reg_date . '" selected="selected">' . JText::_('COM_ICAGENDA_SELECT_DATE') . '</option>';
                 $options .= '<option value="update"';
                 $options .= '>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_FOR_ALL_DATES') . '</option>';
             } else {
                 $options .= '<option value=""';
                 $options .= ' selected="selected"';
                 $options .= '>' . JText::_('COM_ICAGENDA_ADMIN_REGISTRATION_FOR_ALL_DATES') . '</option>';
             }
         } else {
             if (!$reg_date && $reg_period == 1 || $reg_date && !iCDate::isDate($reg_date) || !$reg_date && $reg_period == 0 || iCDate::isDate($reg_date) && $reg_period == 1) {
                 $options .= '<option value="' . $reg_date . '"';
                 $options .= ' selected="selected"';
                 $options .= '>' . JText::_('COM_ICAGENDA_SELECT_DATE') . '</option>';
             }
             // Declare AllDates array
             $AllDates = array();
             // Get WeekDays setting
             $WeeksDays = iCDatePeriod::weekdaysToArray($i->weekdays);
             // If Single Dates, added each one to All Dates for this event
             $singledates = iCString::isSerialized($i->dates) ? unserialize($i->dates) : array();
             foreach ($singledates as $sd) {
                 if (iCDate::isDate($sd)) {
                     array_push($AllDates, $sd);
                 }
             }
             // If Period Dates, added each one to All Dates for this event (filter week Days, and if date not null)
             $perioddates = iCDatePeriod::listDates($i->startdate, $i->enddate);
             if (isset($perioddates) && is_array($perioddates)) {
                 // Check the period if is separated into individual dates
                 $is_full_period = $i->weekdays || $i->weekdays == '0' ? false : true;
                 if ($is_full_period && iCDate::isDate($i->startdate) && iCDate::isDate($i->enddate)) {
                     $value_datetime = '';
                     $options .= '<option value="' . $value_datetime . '"';
                     if ($reg_date == '' && $reg_period != 1) {
                         $date_exist = true;
                         $options .= ' selected="selected"';
                     }
                     $options .= '>' . self::formatDate($i->startdate) . ' &#x279c; ' . self::formatDate($i->startdate) . '</option>';
                 } else {
                     foreach ($perioddates as $Dat) {
                         if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                             // May not work in php < 5.2.3 (should return false if date null since 5.2.4)
                             $isValid = iCDate::isDate($Dat);
                             if ($isValid) {
                                 $SingleDate = date('Y-m-d H:i', strtotime($Dat));
                                 array_push($AllDates, $SingleDate);
                             }
                         }
                     }
                 }
             }
             // get Time Format
             $timeformat = JComponentHelper::getParams('com_icagenda')->get('timeformat', '1');
             $lang_time = $timeformat == 1 ? 'H:i' : 'h:i A';
             if (!empty($AllDates)) {
                 sort($AllDates);
             }
             foreach ($AllDates as $date) {
                 if (iCDate::isDate($date)) {
                     $value_datetime = date('Y-m-d H:i:s', strtotime($date));
                     $options .= '<option value="' . $value_datetime . '"';
                     if ($reg_date == $value_datetime) {
                         $date_exist = true;
                         $options .= ' selected="selected"';
                     }
                     $options .= '>' . self::formatDate($date) . ' - ' . date($lang_time, strtotime($date)) . '</option>';
                 }
             }
         }
         return $options;
     }
     return false;
 }
Ejemplo n.º 14
0
 /**
  * Return list of all dates (singles and period) from an event
  *
  * @since	3.5.0 (Not Yet Used)
  */
 public static function thisEventDates($id)
 {
     // Set vars
     $nodate = '0000-00-00 00:00:00';
     $ic_nodate = '0000-00-00 00:00';
     $eventTimeZone = null;
     // Get Data
     $db = Jfactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('e.next, e.dates, e.startdate, e.enddate, e.period, e.weekdays, e.displaytime, e.id');
     $query->from('#__icagenda_events AS e');
     $query->leftJoin('`#__icagenda_category` AS c ON c.id = e.catid');
     $query->where('c.state = 1');
     $query->where('e.id = ' . $db->q($id));
     $db->setQuery($query);
     $result = $db->loadObjectList();
     // Get Data
     $tId = $id;
     $tDates = $result->dates;
     $tStartdate = $result->startdate;
     $tEnddate = $result->enddate;
     $tWeekdays = $result->weekdays;
     // Declare AllDates array
     $thisEventDates = array();
     // Get WeekDays Array
     $WeeksDays = iCDatePeriod::weekdaysToArray($tWeekdays);
     // If Single Dates, added each one to All Dates for this event
     $singledates = unserialize($tDates);
     foreach ($singledates as $sd) {
         $isValid = iCDate::isDate($sd);
         if ($isValid) {
             array_push($thisEventDates, $sd);
         }
     }
     $perioddates = iCDatePeriod::listDates($tStartdate, $tEnddate, $eventTimeZone);
     if (isset($perioddates) && $perioddates != NULL) {
         foreach ($perioddates as $Dat) {
             if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                 $isValid = iCDate::isDate($Dat);
                 if ($isValid) {
                     //						$SingleDate = JHtml::date($Dat, 'Y-m-d H:i:s', $eventTimeZone);
                     $SingleDate = date('Y-m-d H:i:s', strtotime($Dat));
                     array_push($thisEventDates, $SingleDate);
                 }
             }
         }
     }
     return $thisEventDates;
 }
Ejemplo n.º 15
0
 /**
  * Overloaded bind function to pre-process the params.
  *
  * @param	array		Named array
  * @return	null|string	null is operation was satisfactory, otherwise returns an error
  * @see		JTable:bind
  * @since	1.3
  */
 public function bind($array, $ignore = '')
 {
     $lang = JFactory::getLanguage();
     // Serialize Single Dates
     $dev_option = '0';
     // Set Vars
     $eventTimeZone = null;
     $nodate = '0000-00-00 00:00:00';
     $date_today = JHtml::date('now', 'Y-m-d');
     // Joomla Time Zone
     if (iCString::isSerialized($array['dates'])) {
         $dates = unserialize($array['dates']);
     } elseif ($dev_option == '1') {
         $dates = $this->setDatesOptions($array['dates']);
     } else {
         $dates = $this->getDates($array['dates']);
         if ($lang->getTag() == 'fa-IR' && $dates != array('0000-00-00 00:00') && $dates != array('')) {
             $dates_to_sql = array();
             foreach ($dates as $date) {
                 if (iCDate::isDate($date)) {
                     $year = date('Y', strtotime($date));
                     $month = date('m', strtotime($date));
                     $day = date('d', strtotime($date));
                     $time = date('H:i', strtotime($date));
                     $converted_date = iCGlobalizeConvert::jalaliToGregorian($year, $month, $day, true) . ' ' . $time;
                     $dates_to_sql[] = date('Y-m-d H:i', strtotime($converted_date));
                 }
             }
             $dates = $dates_to_sql;
         }
     }
     $dates = $dates == array('') ? array('0000-00-00 00:00') : $dates;
     rsort($dates);
     if ($dev_option == '1') {
         $array['dates'] = $array['dates'];
     } else {
         $array['dates'] = serialize($dates);
     }
     /**
      * Set Week Days
      */
     if (!isset($array['weekdays'])) {
         $array['weekdays'] = '';
     } elseif (is_array($array['weekdays'])) {
         $array['weekdays'] = implode(',', $array['weekdays']);
     }
     // Return the dates of the period.
     $startdate = $array['startdate'] == NULL ? $nodate : $array['startdate'];
     $enddate = $array['enddate'] == NULL ? $nodate : $array['enddate'];
     if ($startdate == $nodate && $enddate != $nodate) {
         $enddate = $nodate;
     }
     if (strtotime($startdate) > strtotime($enddate)) {
         $errorperiod = '1';
     } else {
         $errorperiod = '';
         $period_all_dates_array = iCDatePeriod::listDates($startdate, $enddate, $eventTimeZone);
         $WeeksDays = iCDatePeriod::weekdaysToArray($array['weekdays']);
         $period_array = array();
         foreach ($period_all_dates_array as $date_in_weekdays) {
             $datetime_period_date = JHtml::date($date_in_weekdays, 'Y-m-d H:i', $eventTimeZone);
             if (in_array(date('w', strtotime($datetime_period_date)), $WeeksDays)) {
                 array_push($period_array, $datetime_period_date);
             }
         }
     }
     // Serialize Period Dates
     if ($startdate != $nodate && $enddate != $nodate) {
         if ($errorperiod != '1') {
             $array['period'] = serialize($period_array);
             $period = iCString::isSerialized($array['period']) ? unserialize($array['period']) : array();
             if ($lang->getTag() == 'fa-IR') {
                 $period_to_sql = array();
                 foreach ($period as $date) {
                     if (iCDate::isDate($date)) {
                         $year = date('Y', strtotime($date));
                         $month = date('m', strtotime($date));
                         $day = date('d', strtotime($date));
                         $time = date('H:i', strtotime($date));
                         $converted_date = iCGlobalizeConvert::jalaliToGregorian($year, $month, $day, true) . ' ' . $time;
                         $period_to_sql[] = date('Y-m-d H:i', strtotime($converted_date));
                     }
                 }
                 $period = $period_to_sql;
             }
             rsort($period);
             $array['period'] = serialize($period);
         } else {
             $array['period'] = '';
         }
     } else {
         $array['period'] = '';
     }
     // Set Next Date
     $NextDates = $this->getNextDates($dates);
     $NextPeriod = isset($period) ? $this->getNextPeriod($period, $array['weekdays']) : $this->getNextDates($dates);
     $date_NextDates = JHtml::date($NextDates, 'Y-m-d', $eventTimeZone);
     $date_NextPeriod = JHtml::date($NextPeriod, 'Y-m-d', $eventTimeZone);
     $time_NextDates = JHtml::date($NextDates, 'H:i', $eventTimeZone);
     $time_NextPeriod = JHtml::date($NextPeriod, 'H:i', $eventTimeZone);
     //		$date_NextDates		= date('Y-m-d', strtotime($NextDates));
     //		$date_NextPeriod	= date('Y-m-d', strtotime($NextPeriod));
     //		$time_NextDates		= date('H:i', strtotime($NextDates));
     //		$time_NextPeriod	= date('H:i', strtotime($NextPeriod));
     // Control the next date
     if (strtotime($date_NextDates) >= strtotime($date_today) && strtotime($date_NextPeriod) >= strtotime($date_today)) {
         if (strtotime($date_NextDates) < strtotime($date_NextPeriod)) {
             $array['next'] = $this->getNextDates($dates);
         }
         if (strtotime($date_NextDates) > strtotime($date_NextPeriod)) {
             $array['next'] = $this->getNextPeriod($period, $array['weekdays']);
         }
         if (strtotime($date_NextDates) == strtotime($date_NextPeriod)) {
             if (strtotime($time_NextDates) >= strtotime($time_NextPeriod)) {
                 if (isset($period)) {
                     $array['next'] = $this->getNextPeriod($period, $array['weekdays']);
                 } else {
                     $array['next'] = $this->getNextDates($dates);
                 }
             } else {
                 $array['next'] = $this->getNextDates($dates);
             }
         }
     } elseif (strtotime($date_NextDates) < strtotime($date_today) && strtotime($date_NextPeriod) >= strtotime($date_today)) {
         $array['next'] = $this->getNextPeriod($period, $array['weekdays']);
     } elseif (strtotime($date_NextDates) >= strtotime($date_today) && strtotime($date_NextPeriod) < strtotime($date_today)) {
         $array['next'] = $this->getNextDates($dates);
     } elseif (strtotime($date_NextDates) < strtotime($date_today) && strtotime($date_NextPeriod) < strtotime($date_today)) {
         if (strtotime($date_NextDates) < strtotime($date_NextPeriod)) {
             $array['next'] = $this->getNextPeriod($period, $array['weekdays']);
         } else {
             $array['next'] = $this->getNextDates($dates);
         }
     }
     // Control of dates if valid (EDIT SINCE VERSION 3.0 - update 3.1.4)
     if (strtotime($NextDates) >= '943916400' && strtotime($NextDates) <= '944002800' && $errorperiod == '1') {
         $array['next'] = '-3600';
     }
     if ((strtotime($NextDates) == '943916400' || strtotime($NextDates) == '943920000') && (strtotime($NextPeriod) == '943916400' || strtotime($NextPeriod) == '943920000')) {
         $array['next'] = '-3600';
     }
     if ($array['next'] == '-3600') {
         $state = 0;
         $this->_db->setQuery('UPDATE `#__icagenda_events`' . ' SET `state` = ' . (int) $state . ' WHERE `id` = ' . (int) $array['id']);
         if (version_compare(JVERSION, '3.0', 'lt')) {
             $this->_db->query();
         } else {
             $this->_db->execute();
         }
     }
     $return[] = parent::bind($array, $ignore);
     // ====================================
     // START : HACK FOR A FEW PRO USERS !!!
     // ====================================
     $mail_new_event = JComponentHelper::getParams('com_icagenda')->get('mail_new_event', '0');
     if ($mail_new_event == 1) {
         $title = $array['title'];
         $id_event = $array['id'];
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('id AS eventID')->from('#__icagenda_events')->order('id DESC');
         $db->setQuery($query);
         $eventID = $db->loadResult();
         $new_event = JRequest::getVar('new_event');
         $title = $array['title'];
         $description = $array['desc'];
         $venue = '';
         if ($array['place']) {
             $venue .= $array['place'] . ' - ';
         }
         if ($array['city']) {
             $venue .= $array['city'];
         }
         if ($array['city'] && $array['country']) {
             $venue .= ', ';
         }
         if ($array['country']) {
             $venue .= $array['country'];
         }
         if (strtotime($array['startdate'])) {
             $date = 'Du ' . $array['startdate'] . ' au ' . $array['startdate'];
         } else {
             $date = $array['next'];
         }
         $baseURL = JURI::base();
         $baseURL = str_replace('/administrator', '', $baseURL);
         $baseURL = ltrim($baseURL, '/');
         if ($array['image']) {
             $image = '<img src="' . $baseURL . '/' . $array['image'] . '" />';
         }
         if ($new_event == '1' && $eventID && $array['state'] == '1' && $array['approval'] == '0') {
             $return[] = self::notificationNewEvent($eventID + 1, $title, $description, $venue, $date, $image, $new_event);
         }
     }
     // ====================================
     // END : HACK FOR A FEW PRO USERS !!!
     // ====================================
     return $return;
 }