Exemplo n.º 1
0
 public function getData()
 {
     $app = JFactory::getApplication();
     $user = JFactory::getUser();
     $lang = JFactory::getLanguage();
     $session = JFactory::getSession();
     jimport('joomla.filter.output');
     $eventTimeZone = null;
     $error_messages = array();
     // Get Params
     $params = $app->getParams();
     $submitAccess = $params->get('submitAccess', '');
     $approvalGroups = $params->get('approvalGroups', array("8"));
     // 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');
     // Redirection settings
     $baseURL = JURI::base();
     $subpathURL = JURI::base(true);
     $baseURL = str_replace('/administrator', '', $baseURL);
     $subpathURL = str_replace('/administrator', '', $subpathURL);
     $urlsend = str_replace('&', '&', JRoute::_('index.php?option=com_icagenda&view=submit&layout=send'));
     // Sub Path filtering
     $subpathURL = ltrim($subpathURL, '/');
     // URL List filtering
     $urlsend = ltrim($urlsend, '/');
     if (substr($urlsend, 0, strlen($subpathURL) + 1) == "{$subpathURL}/") {
         $urlsend = substr($urlsend, strlen($subpathURL) + 1);
     }
     $urlsend = rtrim($baseURL, '/') . '/' . ltrim($urlsend, '/');
     // Get return params
     $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;
     }
     // Set alert messages
     $alert_title = $params->get('alert_title', '');
     $alert_body = $params->get('alert_body', '');
     $url_redirect = isset($urlsend_custom) ? $urlsend_custom : $urlsend;
     // Url custom not yet available.
     $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');
     // Set post data
     $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);
     if (iCString::isSerialized($single_dates)) {
         $dates = unserialize($single_dates);
     } else {
         $dates = $this->getDates($single_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 = !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);
                 }
                 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);
                 $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(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->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);
     }
     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
     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);
     }
 }
Exemplo n.º 2
0
 function getDays($d, $f)
 {
     $lang = JFactory::getLanguage();
     $eventTimeZone = null;
     $days = self::getNbOfDaysInMonth($d);
     // Set Month and Year
     $ex_data = explode('-', $d);
     $month = $ex_data[1];
     $year = $ex_data[0];
     $jour = $ex_data[2];
     $list = array();
     //
     // Setting function of the visitor Time Zone
     //
     $today = time();
     $config = JFactory::getConfig();
     $joomla_offset = $config->get('offset');
     $displayDatesTimezone = '0';
     // Option not active
     $opt_TimeZone = isset($this->setTodayTimezone) ? $this->setTodayTimezone : '';
     $gmt_today = gmdate('Y-m-d H:i:s', $today);
     $today_timestamp = strtotime($gmt_today);
     $GMT_timezone = 'Etc/UTC';
     if ($opt_TimeZone == 'SITE') {
         // Joomla Server Time Zone
         $visitor_timezone = $joomla_offset;
         $offset = $this->get_timezone_offset($GMT_timezone, $visitor_timezone);
         $visitor_today = JHtml::date($today_timestamp + $offset, 'Y-m-d H:i:s', null);
         $UTCsite = $offset / 3600;
         if ($UTCsite > 0) {
             $UTCsite = '+' . $UTCsite;
         }
         if ($displayDatesTimezone == '1') {
             echo '<small>' . JHtml::date('now', 'Y-m-d H:i:s', true) . ' UTC' . $UTCsite . '</small><br />';
         }
     } elseif ($opt_TimeZone == 'UTC') {
         // UTC Time Zone
         $offset = 0;
         $visitor_today = JHtml::date($today_timestamp + $offset, 'Y-m-d H:i:s', null);
         $UTC = $offset / 3600;
         if ($UTC > 0) {
             $UTC = '+' . $UTC;
         }
         if ($displayDatesTimezone == '1') {
             echo '<small>' . gmdate('Y-m-d H:i:s', $today) . ' UTC' . $UTC . '</small><br />';
         }
     } else {
         $visitor_today = JHtml::date($today_timestamp, 'Y-m-d H:i:s', null);
     }
     $date_today = str_replace(' ', '-', $visitor_today);
     $date_today = str_replace(':', '-', $date_today);
     $ex_data = explode('-', $date_today);
     $v_month = $ex_data[1];
     $v_year = $ex_data[0];
     $v_day = $ex_data[2];
     $v_hours = $ex_data[3];
     $v_minutes = $ex_data[4];
     for ($a = 1; $a <= $days; $a++) {
         $calday = $a;
         $this_date_a = $year . '-' . $month . '-' . $a;
         if ($lang->getTag() == 'fa-IR') {
             $this_date_cal = iCGlobalizeConvert::jalaliToGregorian($year, $month, $a, true);
         } else {
             $this_date_cal = $year . '-' . $month . '-' . $a;
         }
         if ($a == $v_day && $month == $v_month && $year == $v_year) {
             $classDay = 'style_Today';
         } else {
             $classDay = 'style_Day';
         }
         $datejour = JHtml::date($this_date_cal, 'Y-m-d', $eventTimeZone);
         $this_year_month = $year . '-' . $month . '-00';
         $list_a_date = date('Y-m-d H:i', strtotime($this_date_a));
         // Set Date in tooltip header
         $date_to_format = $this->formatDate($this_date_cal, false);
         $list[$calday]['dateTitle'] = $date_to_format;
         //			$list[$calday]['datecal']		= JHtml::date($this_date_a, 'j', null);
         //			$list[$calday]['monthcal']		= JHtml::date($this_date_a, 'm', null);
         //			$list[$calday]['yearcal']		= JHtml::date($this_date_a, 'Y', null);
         $list[$calday]['date'] = date('Y-m-d H:i', strtotime($this_date_cal));
         //			$list[$calday]['dateFormat']	= strftime($f, strtotime($this_date_a));
         $list[$calday]['week'] = date('N', strtotime($this_date_a));
         $list[$calday]['day'] = '<div class="' . $classDay . '">' . $a . '</div>';
         // Set cal_date
         $list[$calday]['this_day'] = date('Y-m-d', strtotime($this_date_a));
         // Added in 2.1.2 (change in NAME_day.php)
         $list[$calday]['ifToday'] = $classDay;
         $list[$calday]['Days'] = $a;
         // Set event array
         $list[$calday]['events'] = array();
     }
     return $list;
 }
Exemplo n.º 3
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;
 }