Example #1
0
 protected function getInput()
 {
     $id = JRequest::getInt('id');
     $class = !empty($this->class) ? ' ' . $this->class : '';
     $session = JFactory::getSession();
     $datesDB = $session->get('ic_submit_dates', '');
     if ($id && empty($datesDB)) {
         $db = JFactory::getDBO();
         $db->setQuery('SELECT a.dates' . ' FROM #__icagenda_events AS a' . ' WHERE a.id = ' . (int) $id);
         $datesDB = $db->loadResult();
     }
     $dates = iCString::isSerialized($datesDB) ? unserialize($datesDB) : false;
     $html = '<table id="dTable" style="border:0px">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th width="70%">';
     $html .= JText::_('COM_ICAGENDA_TB_DATE');
     $html .= '</th>';
     $html .= '<th width="30%">';
     //		$html.= JText::_('COM_ICAGENDA_TB_ACT');
     $html .= '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     if ($dates && $dates != array('0000-00-00 00:00')) {
         foreach ($dates as $date) {
             $html .= '<tr>';
             $html .= '<td>';
             $html .= '<input class="ic-date-input" type="text" name="d" value="' . $date . '" />';
             $html .= '</td>';
             $html .= '<td>';
             $html .= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
             $html .= '</td>';
             $html .= '</tr>';
         }
         // clear the data so we don't process it again
         $session->clear('ic_submit_dates');
     } else {
         $html .= '<tr>';
         $html .= '<td>';
         $html .= '<input class="ic-date-input" type="text" name="d" value="0000-00-00 00:00" />';
         $html .= '</td>';
         $html .= '<td>';
         $html .= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
         $html .= '</td>';
         $html .= '</tr>';
     }
     $html .= '</table>';
     $html .= '<a id="add" href="#"><span class="btn btn-success btn-small input-medium" style="float:left"><strong>' . JText::_('COM_ICAGENDA_ADD_DATE') . '</strong></span></a><br/>';
     $html .= '<input type="hidden"';
     $html .= ' class="date' . $class . '"';
     $html .= ' id="' . $this->id . '_id"';
     $html .= ' name="' . $this->name . '"';
     $html .= ' value=\'' . $datesDB . '\'';
     $html .= '/>';
     return $html;
 }
Example #2
0
 protected function getInput()
 {
     $lang = JFactory::getLanguage();
     $id_suffix = $lang->getTag() == 'fa-IR' ? '_jalali' : '';
     if ($lang->getTag() == 'fa-IR') {
         // Including fallback code for HTML5 non supported browsers.
         JHtml::_('jquery.framework');
         JHtml::_('script', 'system/html5fallback.js', false, true);
     }
     $id = JRequest::getInt('id');
     $class = !empty($this->class) ? ' ' . $this->class : '';
     $session = JFactory::getSession();
     $datesDB = $session->get('ic_submit_dates', '');
     if ($id && empty($datesDB)) {
         $db = JFactory::getDBO();
         $db->setQuery('SELECT a.dates' . ' FROM #__icagenda_events AS a' . ' WHERE a.id = ' . (int) $id);
         $datesDB = $db->loadResult();
     }
     $dates = iCString::isSerialized($datesDB) ? unserialize($datesDB) : false;
     //		if ($lang->getTag() == 'fa-IR'
     //			&& $dates
     //			&& $dates != array('0000-00-00 00:00'))
     //		{
     //			$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));
     //					$dates_to_sql[] = iCGlobalizeConvert::gregorianToJalali($year, $month, $day, true) . ' ' . $time;
     //				}
     //			}
     //			$dates = $dates_to_sql;
     //		}
     $html = '<table id="dTable' . $id_suffix . '" style="border:0px">';
     $html .= '<thead>';
     $html .= '<tr>';
     $html .= '<th width="70%">';
     $html .= JText::_('COM_ICAGENDA_TB_DATE');
     $html .= '</th>';
     $html .= '<th width="30%">';
     //		$html.= JText::_('COM_ICAGENDA_TB_ACT');
     $html .= '</th>';
     $html .= '</tr>';
     $html .= '</thead>';
     $add_counter = 0;
     if ($dates && $dates != array('0000-00-00 00:00')) {
         foreach ($dates as $date) {
             $html .= '<tr>';
             $html .= '<td>';
             if ($lang->getTag() == 'fa-IR') {
                 $add_counter = $add_counter + 1;
                 //					$this_number = $add_counter ? $add_counter : '';
                 $html .= JHtml::_('calendar', $date, 'd', 'date_jalali' . $add_counter, '%Y-%m-%d %H:%M', ' class="ic-date-input' . $id_suffix . '"');
             } else {
                 $html .= '<input class="ic-date-input' . $id_suffix . '" type="text" name="d" value="' . $date . '" />';
             }
             $html .= '</td>';
             $html .= '<td>';
             $html .= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
             $html .= '</td>';
             $html .= '</tr>';
         }
         // clear the data so we don't process it again
         $session->clear('ic_submit_dates');
     } else {
         $html .= '<tr>';
         $html .= '<td>';
         if ($lang->getTag() == 'fa-IR') {
             $html .= JHtml::_('calendar', '0000-00-00 00:00', 'd', 'date_jalali', '%Y-%m-%d %H:%M', ' class="ic-date-input' . $id_suffix . '"');
         } else {
             $html .= '<input class="ic-date-input' . $id_suffix . '" type="text" name="d" value="0000-00-00 00:00" />';
         }
         $html .= '</td>';
         $html .= '<td>';
         $html .= '<a class="del btn btn-danger btn-mini" href="#">' . JText::_('COM_ICAGENDA_DELETE_DATE') . '</a>';
         $html .= '</td>';
         $html .= '</tr>';
     }
     $html .= '</table>';
     $html .= '<a id="add" href="#"><span class="btn btn-success btn-small input-medium" style="float:left"><strong>' . JText::_('COM_ICAGENDA_ADD_DATE') . '</strong></span></a><br/>';
     $html .= '<input type="hidden"';
     $html .= ' class="date' . $class . '"';
     $html .= ' id="' . $this->id . '_id"';
     $html .= ' name="' . $this->name . '"';
     $html .= ' value=\'' . $datesDB . '\'';
     $html .= '/>';
     return $html;
 }
Example #3
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>';
        }
    }
Example #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;
 }
Example #5
0
 protected function wlivecalendarUrl($i)
 {
     $text = $i->title . ' (' . $i->cat_title . ')';
     $details = $i->desc;
     $venue = $i->place_name;
     $s_dates = $i->dates;
     //		$single_dates	= unserialize($s_dates);
     $single_dates = iCString::isSerialized($i->dates) ? unserialize($i->dates) : array();
     // returns array
     $website = $this->Event_Link($i);
     $location = $venue ? $venue . ' - ' . $i->address : $i->address;
     $get_date = '';
     $href = '#';
     $endday = '';
     if (JRequest::getVar('date')) {
         // if 'All Dates' set
         $get_date = JRequest::getVar('date');
     } else {
         // if 'Only Next/Last Date' set
         $get_date = date('Y-m-d-H-i', strtotime($i->next));
     }
     $ex = explode('-', $get_date);
     $this_date = $ex['0'] . '-' . $ex['1'] . '-' . $ex['2'] . ' ' . $ex['3'] . ':' . $ex['4'];
     $startdate = date('Y-m-d-H-i', strtotime($i->startdate));
     $enddate = date('Y-m-d-H-i', strtotime($i->enddate));
     if ($this->eventHasPeriod($i) && $get_date >= $startdate && $get_date <= $enddate && !in_array($this_date, $single_dates)) {
         $weekdays = $i->weekdays || $i->weekdays == '0' ? true : false;
         if ($weekdays) {
             $startdate = date('Y-m-d-H-i', strtotime($this_date));
             $enddate = date('Y-m-d', strtotime($this_date)) . '-' . date('H-i', strtotime($i->enddate));
         }
         $ex_S = explode('-', $startdate);
         $ex_E = explode('-', $enddate);
         $dateday = $ex_S['0'] . $ex_S['1'] . $ex_S['2'] . 'T' . $ex_S['3'] . $ex_S['4'] . '00';
         $endday = $ex_E['0'] . $ex_E['1'] . $ex_E['2'] . 'T' . $ex_E['3'] . $ex_E['4'] . '00';
     } else {
         $dateday = $ex['0'] . $ex['1'] . $ex['2'] . 'T' . $ex['3'] . $ex['4'] . '00';
     }
     $href = "http://calendar.live.com/calendar/calendar.aspx?rru=addevent";
     $href .= "&dtstart=" . $dateday;
     $href .= isset($endday) ? "&dtend=" . $endday : '';
     $href .= "&summary=" . urlencode($text);
     $href .= "&location=" . urlencode($location);
     // Shortens the description, if more than 1000 characters
     $lengthMax = '1000';
     $details = urlencode(strip_tags($details));
     $details = substr($details, 0, $lengthMax);
     $shortenedDetails = strrpos($details, '+');
     $details = substr($details, 0, $shortenedDetails);
     $href .= "&description=" . substr($details, 0, $lengthMax) . '...';
     return $href;
 }
Example #6
0
 public static function nextDate($evt, $i)
 {
     $eventTimeZone = null;
     $singledates = iCString::isSerialized($i->dates) ? unserialize($i->dates) : array();
     // returns array
     $period = iCString::isSerialized($i->period) ? unserialize($i->period) : array();
     // returns array
     $startdatetime = $i->startdatetime;
     $enddatetime = $i->enddatetime;
     $weekdays = $i->weekdays;
     $site_today_date = JHtml::date('now', 'Y-m-d');
     $UTC_today_date = JHtml::date('now', 'Y-m-d', $eventTimeZone);
     $next_date = JHtml::date($evt, 'Y-m-d', $eventTimeZone);
     $next_datetime = JHtml::date($evt, 'Y-m-d H:i', $eventTimeZone);
     $start_date = JHtml::date($i->startdatetime, 'Y-m-d', $eventTimeZone);
     $end_date = JHtml::date($i->enddatetime, 'Y-m-d', $eventTimeZone);
     // Check if date from a period with weekdays has end time of the period set in next.
     //		$time_next_datetime	= JHtml::date($next_datetime, 'H:i', $eventTimeZone);
     $time_next_datetime = date('H:i', strtotime($next_datetime));
     $time_startdate = JHtml::date($i->startdatetime, 'H:i', $eventTimeZone);
     $time_enddate = JHtml::date($i->enddatetime, 'H:i', $eventTimeZone);
     $data_next_datetime = date('Y-m-d H:i', strtotime($evt));
     if ($next_date == $site_today_date && $time_next_datetime == $time_enddate) {
         $next_datetime = $next_date . ' ' . $time_startdate;
     }
     if ($period != NULL && in_array($data_next_datetime, $period)) {
         $next_is_in_period = true;
     } else {
         $next_is_in_period = false;
     }
     // Highlight event in progress
     if ($next_date == $site_today_date) {
         $start_span = '<span class="ic-next-today">';
         $end_span = '</span>';
     } else {
         $start_span = $end_span = '';
     }
     $separator = '<span class="ic-datetime-separator"> - </span>';
     // Format Next Date
     if ($next_is_in_period && ($start_date == $end_date || $weekdays != null)) {
         // Next in the period & (same start/end date OR one or more weekday selected)
         $nextDate = $start_span;
         $nextDate .= '<span class="ic-period-startdate">';
         $nextDate .= self::formatDate($evt);
         $nextDate .= '</span>';
         if ($i->displaytime == 1) {
             $nextDate .= ' <span class="ic-single-starttime">' . icagendaEvents::dateToTimeFormat($startdatetime) . '</span>';
             if (icagendaEvents::dateToTimeFormat($startdatetime) != icagendaEvents::dateToTimeFormat($enddatetime)) {
                 $nextDate .= $separator . '<span class="ic-single-endtime">' . icagendaEvents::dateToTimeFormat($enddatetime) . '</span>';
             }
         }
         $nextDate .= $end_span;
     } elseif ($next_is_in_period && $weekdays == null) {
         // Next in the period & different start/end date & no weekday selected
         $start = '<span class="ic-period-startdate">';
         $start .= self::formatDate($startdatetime);
         $start .= '</span>';
         $end = '<span class="ic-period-enddate">';
         $end .= self::formatDate($enddatetime);
         $end .= '</span>';
         if ($i->displaytime == 1) {
             $start .= ' <span class="ic-period-starttime">' . icagendaEvents::dateToTimeFormat($startdatetime) . '</span>';
             $end .= ' <span class="ic-period-endtime">' . icagendaEvents::dateToTimeFormat($enddatetime) . '</span>';
         }
         $nextDate = $start_span . $start . $separator . $end . $end_span;
     } else {
         // Next is a single date
         $nextDate = $start_span;
         $nextDate .= '<span class="ic-single-next">';
         $nextDate .= self::formatDate($evt);
         $nextDate .= '</span>';
         if ($i->displaytime == 1) {
             $nextDate .= ' <span class="ic-single-starttime">' . icagendaEvents::dateToTimeFormat($evt) . '</span>';
         }
         $nextDate .= $end_span;
     }
     return $nextDate;
 }
Example #7
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @since	3.4.0
  */
 protected function prepareTable($table)
 {
     $app = JFactory::getApplication();
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     if (empty($table->id)) {
         // Set the values
         $table->created = $date->toSql();
         // Set ordering to the last item if not set
         if (empty($table->ordering)) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true)->select('MAX(ordering)')->from($db->quoteName('#__icagenda_customfields'));
             $db->setQuery($query);
             $max = $db->loadResult();
             $table->ordering = $max + 1;
         }
     } else {
         // Set the values
         $table->modified = $date->toSql();
         $table->modified_by = $user->get('id');
     }
     // Alter the title for save as copy
     if ($app->input->get('task') == 'save2copy') {
         $table->title = iCString::increment($table->title);
         $table->alias = iCString::increment($table->alias, 'dash');
         $table->slug = iCString::increment($table->slug, 'underscore');
         $table->state = '0';
     }
 }
Example #8
0
 protected function frontendImageUpload($image)
 {
     // Get Joomla Images PATH set
     $params = JComponentHelper::getParams('com_media');
     $image_path = $params->get('image_path');
     // Clean up filename
     $imagename = JFile::makeSafe($image['name']);
     // Process filename
     while (JFile::exists(JPATH_ROOT . '/' . $image_path . '/icagenda/frontend/images/' . $imagename)) {
         $src = $image['tmp_name'];
         // Get Image title and extension type
         $decomposition = explode('/', $imagename);
         // in each parent
         $i = 0;
         while (isset($decomposition[$i])) {
             $i++;
         }
         $i--;
         $imgname = $decomposition[$i];
         $fichier = explode('.', $decomposition[$i]);
         $imgtitle = $fichier[0];
         $imgextension = isset($fichier[1]) ? $fichier[1] : '';
         // Increment filename if already exists
         $imagename = iCString::increment($imgtitle, 'dash') . '.' . $imgextension;
         // Controls image mimetype, and fixes file extension if missing in filename
         $allowed_mimetypes = array('jpg', 'jpeg', 'png', 'gif');
         if (!in_array($imgextension, $allowed_mimetypes)) {
             $fileinfos = getimagesize($src);
             $mimeType = $fileinfos['mime'];
             $ex_mimeType = explode('/', $mimeType);
             $file_extension = $ex_mimeType[1];
             $imagename = $imagename . '.' . $file_extension;
         }
     }
     if ($imagename != '') {
         //Set up the source and destination of the file
         $src = $image['tmp_name'];
         $dest = JPATH_SITE . '/images/icagenda/frontend/images/' . $imagename;
         // Create Folder iCagenda in ROOT/IMAGES_PATH/icagenda and sub-folders if do not exist
         $folder[0][0] = 'icagenda/frontend/';
         $folder[0][1] = JPATH_ROOT . '/' . $image_path . '/' . $folder[0][0];
         $folder[1][0] = 'icagenda/frontend/images/';
         $folder[1][1] = JPATH_ROOT . '/' . $image_path . '/' . $folder[1][0];
         $error = array();
         foreach ($folder as $key => $value) {
             if (!JFolder::exists($value[1])) {
                 if (JFolder::create($value[1], 0755)) {
                     $this->data = "<html>\n<body bgcolor=\"#FFFFFF\">\n</body>\n</html>";
                     JFile::write($value[1] . "/index.html", $this->data);
                     $error[] = 0;
                 } else {
                     $error[] = 1;
                 }
             } else {
                 $error[] = 0;
             }
         }
         if (JFile::upload($src, $dest, false)) {
             return 'images/icagenda/frontend/images/' . $imagename;
         }
     }
 }
Example #9
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 = '')
 {
     // 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']);
     }
     $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);
             if (iCString::isSerialized($array['period'])) {
                 $period = unserialize($array['period']);
             } else {
                 $period = $this->getPeriod($array['period']);
             }
             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);
     // 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;
 }
Example #10
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;
 }
Example #11
0
    /**
     * Get and update NEXT DATE
     *
     * @since 3.5.4
     */
    public static function getNext()
    {
        $app = JFactory::getApplication();
        $params = $app->getParams();
        // Get Settings
        $filterTime = $params->get('time', 1);
        // Set vars
        $nodate = '0000-00-00 00:00:00';
        $eventTimeZone = null;
        $datetime_today = JHtml::date('now', 'Y-m-d H:i:s');
        // Joomla Time Zone
        $date_today = JHtml::date('now', 'Y-m-d');
        // Joomla Time Zone
        $time_today = JHtml::date('now', 'H:i:s');
        // Joomla Time Zone
        //		$datetime_today	= date('Y-m-d H:i:s');
        //		$date_today		= date('Y-m-d');
        //		$time_today		= date('H:i:s');
        // Preparing connection to db
        $db = Jfactory::getDbo();
        // Preparing the query
        $query = $db->getQuery(true);
        $query->select('next AS tNext, dates AS tDates, startdate AS tStartdate, enddate AS tEnddate,
						weekdays AS tWeekdays, id AS tId, state AS tState, access AS tAccess');
        $query->from('`#__icagenda_events` AS e');
        $query->where(' e.state = 1 OR e.state = 0 ');
        $db->setQuery($query);
        $all_next_dates = $db->loadObjectList();
        foreach ($all_next_dates as $nd) {
            $nd_next = $nd->tNext;
            $nd_id = $nd->tId;
            $nd_state = $nd->tState;
            $nd_dates = $nd->tDates;
            $nd_startdate = $nd->tStartdate;
            $nd_enddate = $nd->tEnddate;
            $nd_weekdays = $nd->tWeekdays;
            // If Single Dates, added to all dates for this event
            $singleDates = iCString::isSerialized($nd_dates) ? unserialize($nd_dates) : array();
            $AllDates = array();
            // Get WeekDays Array
            $WeeksDays = iCDatePeriod::weekdaysToArray($nd_weekdays);
            if (isset($singleDates) && $singleDates != NULL && !in_array($nodate, $singleDates) && !in_array('', $singleDates)) {
                $AllDates = array_merge($AllDates, $singleDates);
            } elseif (in_array('', $singleDates)) {
                $datesarray = array();
                $nodate = array('0000-00-00 00:00');
                $datesmerger = array_push($datesarray, $nodate);
                $DatesUpdate = serialize($nodate);
                $query = $db->getQuery(true);
                $query->update('#__icagenda_events');
                $query->set("`dates`='" . (string) $DatesUpdate . "'");
                $query->where('`id`=' . (int) $nd_id);
                $db->setQuery($query);
                $db->query($query);
                $nosingledates = unserialize($DatesUpdate);
                $AllDates = array_merge($AllDates, $nosingledates);
            }
            //			$StDate			= JHtml::date($nd_startdate, 'Y-m-d H:i', $eventTimeZone);
            //			$EnDate			= JHtml::date($nd_enddate, 'Y-m-d H:i', $eventTimeZone);
            //			$date_enddate	= JHtml::date($nd_enddate, 'Y-m-d', $eventTimeZone);
            //			$time_enddate	= JHtml::date($nd_enddate, 'H:i', $eventTimeZone);
            //			$date_startdate = JHtml::date($nd_startdate, 'Y-m-d', $eventTimeZone);
            //			$time_startdate = JHtml::date($nd_startdate, 'H:i', $eventTimeZone);
            $StDate = date('Y-m-d H:i', strtotime($nd_startdate));
            $EnDate = date('Y-m-d H:i', strtotime($nd_enddate));
            $date_enddate = date('Y-m-d', strtotime($nd_enddate));
            $time_enddate = date('H:i', strtotime($nd_enddate));
            $date_startdate = date('Y-m-d', strtotime($nd_startdate));
            $time_startdate = date('H:i', strtotime($nd_startdate));
            //			$perioddates	= iCDatePeriod::listDates($nd_startdate, $nd_enddate, $eventTimeZone);
            $perioddates = iCDatePeriod::listDates($nd_startdate, $nd_enddate);
            $only_startdate = $nd_weekdays || $nd_weekdays == '0' ? false : true;
            if (isset($perioddates) && $perioddates != NULL) {
                // Period with no weekdays in Upcoming and Past options
                if ($only_startdate && ($filterTime == '3' || $filterTime == '2')) {
                    array_push($AllDates, $StDate);
                } else {
                    foreach ($perioddates as $Dat) {
                        if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                            $date_Dat = date('Y-m-d', strtotime($Dat));
                            $SingleDate = date('Y-m-d H:i', strtotime($Dat));
                            if ($date_Dat == $date_today && $filterTime != 3) {
                                // Next in Period is today, so set end time
                                array_push($AllDates, $date_Dat . ' ' . $time_startdate);
                            } else {
                                array_push($AllDates, $SingleDate);
                            }
                        }
                    }
                }
            }
            rsort($AllDates);
            if ($AllDates == NULL) {
                $next = '0000-00-00 00:00:00';
            } else {
                $date_lastdate = date('Y-m-d', strtotime($AllDates[0]));
                $datetime_lastdate = date('Y-m-d H:i:s', strtotime($AllDates[0]));
                $date_startdate = date('Y-m-d', strtotime($nd_startdate));
                $date_enddate = date('Y-m-d', strtotime($nd_enddate));
                $time_startdate = date('H:i:s', strtotime($nd_startdate));
                $time_enddate = date('H:i:s', strtotime($nd_enddate));
                $returnNext = $nd_next;
                $next_is_set = '0';
                //				$today_SD	= '0';
                $today_upcoming_SD = '0';
                $upcoming_SD = '0';
                foreach ($AllDates as $a) {
                    $tsdate_a = date('Y-m-d', strtotime($a));
                    if ($tsdate_a == $date_today) {
                        // All single dates today
                        //						$today_SD = $today_SD + 1;
                        // All single dates today and not yet started
                        $today_upcoming_SD = strtotime($a) > strtotime($datetime_today) ? $today_upcoming_SD + 1 : $today_upcoming_SD;
                    }
                    if ($tsdate_a >= $datetime_today) {
                        // All upcoming single dates
                        $upcoming_SD = $upcoming_SD + 1;
                    }
                }
                $total_today_SD = $today_upcoming_SD;
                foreach ($AllDates as $a) {
                    $tsdatetime_a = date('Y-m-d H:i:s', strtotime($a));
                    $tsdate_a = date('Y-m-d', strtotime($a));
                    // Only past single dates
                    if ($datetime_lastdate < $datetime_today && $date_lastdate != $date_today && $next_is_set == '0') {
                        $returnNext = date('Y-m-d H:i:s', strtotime($AllDates[0]));
                        $next_is_set = $next_is_set + 1;
                    } elseif ($date_lastdate == $date_today && $next_is_set == '0' && $total_today_SD == 1) {
                        // Period divided into days
                        if ($nd_startdate != $nodate && $nd_enddate != $nodate && in_array($a, $perioddates) && !$only_startdate) {
                            $returnNext = date('Y-m-d', strtotime($nd_enddate)) . ' ' . $time_startdate;
                            $next_is_set = $next_is_set + 1;
                        } elseif ($nd_startdate != $nodate && $nd_enddate != $nodate && in_array($a, $perioddates) && $only_startdate) {
                            $returnNext = date('Y-m-d', strtotime($nd_startdate)) . ' ' . $time_startdate;
                            $next_is_set = $next_is_set + 1;
                        } else {
                            if ($datetime_lastdate > $datetime_today) {
                                $today_upcoming_SD = $today_upcoming_SD - 1;
                            }
                            if ($datetime_lastdate > $datetime_today && $today_upcoming_SD == '0') {
                                $returnNext = date('Y-m-d H:i:s', strtotime($AllDates[0]));
                                $next_is_set = $next_is_set + 1;
                            }
                        }
                    } elseif ($tsdatetime_a > $date_today && $next_is_set == '0') {
                        // Remaining Today's upcoming dates
                        if ($tsdate_a == $date_today) {
                            if ($tsdatetime_a > $datetime_today) {
                                $today_upcoming_SD = $today_upcoming_SD - 1;
                            }
                        }
                        // Remaining Upcoming dates
                        if ($tsdate_a >= $datetime_today) {
                            $upcoming_SD = $upcoming_SD - 1;
                        }
                        if ($today_upcoming_SD == '0' && $upcoming_SD == '0') {
                            $returnNext = date('Y-m-d H:i:s', strtotime($a));
                            $next_is_set = $next_is_set + 1;
                        }
                    }
                }
                // Test End Date if Next Date or Last Date (3.1.5)
                $date_returnNext = date('Y-m-d', strtotime($returnNext));
                $time_returnNext = date('H:i:s', strtotime($returnNext));
                if ($date_enddate != '0000-00-00' && ($date_today == $date_enddate || $date_today == $date_returnNext)) {
                    $time_LastTime = $time_startdate;
                } else {
                    $time_LastTime = $time_returnNext;
                }
                // Fix 3.1.12 (removed isset($tPeriod))
                if ($nd_enddate != $nodate && $date_startdate < $date_today && $date_enddate == $date_today && $time_LastTime >= $time_today) {
                    //					$returnNextPediod = JHtml::date($nd_enddate, 'Y-m-d', $eventTimeZone) . ' ' . $time_startdate;
                    $returnNextPediod = date('Y-m-d', strtotime($nd_enddate)) . ' ' . $time_startdate;
                } else {
                    $returnNextPediod = $returnNext;
                }
                // Set next var
                if ($date_returnNext == $date_enddate && $date_enddate == $date_today) {
                    $next = $returnNextPediod;
                } elseif (strtotime($date_startdate) < strtotime($date_today) && strtotime($date_enddate) >= strtotime($date_today) && strtotime($time_enddate) != strtotime($time_returnNext) && strtotime($time_LastTime) > strtotime($time_today)) {
                    $next = $date_returnNext . ' ' . date('H:i:s', strtotime($time_LastTime));
                } else {
                    $next = $returnNext;
                }
            }
            // 3.1.12 Fixed and update events with bug
            if ($nd_next == $nodate && $nd_state == 0 && $nd_startdate != $nodate && $nd_enddate != $nodate && strtotime($nd_enddate) >= strtotime($nd_startdate)) {
                $next = $returnNext;
                $query = $db->getQuery(true);
                $query->update('#__icagenda_events');
                $query->set('`state`=1');
                $query->where('`id`=' . (int) $nd_id);
                $db->setQuery($query);
                $db->query($query);
            }
            if ($next != $nd_next) {
                $query = $db->getQuery(true);
                $query->update('#__icagenda_events');
                $query->set("`next`='" . $next . "'");
                $query->where('`id`=' . (int) $nd_id);
                $db->setQuery($query);
                $db->query($query);
            }
        }
    }