Exemplo n.º 1
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>';
        }
    }
Exemplo n.º 2
0
    function getStamp($params)
    {
        $iCparams = JComponentHelper::getParams('com_icagenda');
        $eventTimeZone = null;
        // Itemid Request (automatic detection of the first iCagenda menu-link, by menuID)
        $iC_list_menus = icagendaMenus::iClistMenuItemsInfo();
        $nb_menu = count($iC_list_menus);
        $nolink = $nb_menu ? false : true;
        $app = JFactory::getApplication();
        $menu = $app->getMenu();
        $isSef = $app->getCfg('sef');
        $date_var = $isSef == 1 ? '?date=' : '&amp;date=';
        // Check if GD is enabled on the server
        if (extension_loaded('gd') && function_exists('gd_info')) {
            $thumb_generator = $iCparams->get('thumb_generator', 1);
        } else {
            $thumb_generator = 0;
        }
        $datetime_today = JHtml::date('now', 'Y-m-d H:i');
        $timeformat = $iCparams->get('timeformat', 1);
        $lang_time = $timeformat == 1 ? 'H:i' : 'h:i A';
        // Check if fopen is allowed
        $result = ini_get('allow_url_fopen');
        $fopen = empty($result) ? false : true;
        $this->start($params);
        // Get the database
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        // Build the query
        $query->select('e.*,
				e.place as place_name,
				c.title as cat_title,
				c.alias as cat_alias,
				c.color as cat_color,
				c.ordering as cat_order
			')->from($db->qn('#__icagenda_events') . ' AS e')->leftJoin($db->qn('#__icagenda_category') . ' AS c ON ' . $db->qn('c.id') . ' = ' . $db->qn('e.catid'));
        // Where Category is Published
        $query->where('c.state = 1');
        // Where State is Published
        $query->where('e.state = 1');
        // Where event is Approved
        $query->where('e.approval = 0');
        // Add filters
        if (isset($this->filter)) {
            foreach ($this->filter as $filter) {
                $query->where($filter);
            }
        }
        // Check Access Levels
        $user = JFactory::getUser();
        $userID = $user->id;
        $userLevels = $user->getAuthorisedViewLevels();
        if (version_compare(JVERSION, '3.0', 'lt')) {
            $userGroups = $user->getAuthorisedGroups();
        } else {
            $userGroups = $user->groups;
        }
        $userAccess = implode(', ', $userLevels);
        if (!in_array('8', $userGroups)) {
            $query->where('e.access IN (' . $userAccess . ')');
        }
        // Features - extract the number of displayable icons per event
        $query->select('feat.count AS features');
        $sub_query = $db->getQuery(true);
        $sub_query->select('fx.event_id, COUNT(*) AS count');
        $sub_query->from('`#__icagenda_feature_xref` AS fx');
        $sub_query->innerJoin("`#__icagenda_feature` AS f ON fx.feature_id=f.id AND f.state=1 AND f.icon<>'-1'");
        $sub_query->group('fx.event_id');
        $query->leftJoin('(' . (string) $sub_query . ') AS feat ON e.id=feat.event_id');
        // Registrations total
        $query->select('r.count AS registered, r.date AS reg_date');
        $sub_query = $db->getQuery(true);
        $sub_query->select('r.eventid, sum(r.people) AS count, r.date AS date');
        $sub_query->from('`#__icagenda_registration` AS r');
        $sub_query->where('r.state > 0');
        $sub_query->group('r.eventid');
        $query->leftJoin('(' . (string) $sub_query . ') AS r ON e.id=r.eventid');
        // Run the query
        $db->setQuery($query);
        // Invoke the query
        $result = $db->loadObjectList();
        $registrations = icagendaEventsData::registeredList();
        foreach ($result as $record) {
            $record_registered = array();
            foreach ($registrations as $reg_by_event) {
                $ex_reg_by_event = explode('@@', $reg_by_event);
                if ($ex_reg_by_event[0] == $record->id) {
                    $record_registered[] = $ex_reg_by_event[0] . '@@' . $ex_reg_by_event[1] . '@@' . $ex_reg_by_event[2];
                }
            }
            $record->registered = $record_registered;
        }
        // Set start/end dates of the current month
        $days = self::getNbOfDaysInMonth($this->date_start);
        $current_date_start = $this->date_start;
        $month_start = date('m', strtotime($current_date_start));
        $month_end = date('m', strtotime('+1 month', strtotime($current_date_start)));
        $day_end = date('m', strtotime('+' . $days . ' days', strtotime($current_date_start)));
        $year_end = $month_start == '12' ? date('Y', strtotime("+1 year", strtotime($this->date_start))) : date('Y', strtotime($this->date_start));
        $current_date_end = $year_end . '-' . $month_end . '-' . $day_end;
        $days = $this->getDays($this->date_start, 'Y-m-d H:i');
        $total_items = 0;
        $displayed_items = 0;
        foreach ($result as $item) {
            // Extract the feature details, if needed
            $features = array();
            if (is_null($item->features) || empty($this->features_icon_size)) {
                $item->features = array();
            } else {
                $item->features = icagendaEvents::featureIcons($item->id);
            }
            if (isset($item->features) && is_array($item->features)) {
                foreach ($item->features as $feature) {
                    $features[] = array('icon' => $feature->icon, 'icon_alt' => $feature->icon_alt);
                }
            }
            // list calendar dates
            $AllDates = array();
            $next = isset($next) ? $next : '';
            $allSingleDates_array = $this->getDatelist($item->dates, $next);
            // If Single Dates, added to all dates for this event
            if (isset($datemultiplelist) && $datemultiplelist != NULL && is_array($datemultiplelist)) {
                $allSingleDates_array = array_merge($AllDates, $datemultiplelist);
            }
            foreach ($allSingleDates_array as $sd) {
                $this_date = JHtml::date($sd, 'Y-m-d', null);
                if (strtotime($this_date) >= strtotime($current_date_start) && strtotime($this_date) < strtotime($current_date_end)) {
                    array_push($AllDates, $sd);
                }
            }
            // Get WeekDays Array
            $WeeksDays = iCDatePeriod::weekdaysToArray($item->weekdays);
            // Get Period Dates
            $StDate = JHtml::date($item->startdate, 'Y-m-d H:i', $eventTimeZone);
            $EnDate = JHtml::date($item->enddate, 'Y-m-d H:i', $eventTimeZone);
            $perioddates = iCDatePeriod::listDates($item->startdate, $item->enddate, $eventTimeZone);
            $onlyStDate = isset($this->onlyStDate) ? $this->onlyStDate : '';
            // Check the period if individual dates
            $only_startdate = $item->weekdays || $item->weekdays == '0' ? false : true;
            //			if (isset($perioddates) && $perioddates != NULL)
            //			{
            if ($onlyStDate == 1) {
                if (strtotime($StDate) >= strtotime($current_date_start) && strtotime($StDate) < strtotime($current_date_end)) {
                    array_push($AllDates, date('Y-m-d H:i', strtotime($item->startdate)));
                }
            } else {
                foreach ($perioddates as $Dat) {
                    $this_date = JHtml::date($Dat, 'Y-m-d', null);
                    if (in_array(date('w', strtotime($Dat)), $WeeksDays)) {
                        $SingleDate = date('Y-m-d H:i', strtotime($Dat));
                        if (strtotime($this_date) >= strtotime($current_date_start) && strtotime($this_date) < strtotime($current_date_end)) {
                            array_push($AllDates, $SingleDate);
                        }
                    }
                }
            }
            //			}
            rsort($AllDates);
            // requête Itemid
            $iCmenuitem = $params->get('iCmenuitem', '');
            if (is_numeric($iCmenuitem)) {
                $linkid = $iCmenuitem;
            } else {
                $linkid = icagendaMenus::thisEventItemid($item->next, $item->catid, $iC_list_menus);
            }
            $eventnumber = $item->id ? $item->id : null;
            $event_slug = $item->alias ? $item->id . ':' . $item->alias : $item->id;
            $total_items = $total_items + 1;
            if ($linkid && !$nolink && JComponentHelper::getComponent('com_icagenda', true)->enabled) {
                $displayed_items = $displayed_items + 1;
                $urlevent = JRoute::_('index.php?option=com_icagenda&amp;view=list&amp;layout=event&amp;id=' . $event_slug . '&amp;Itemid=' . (int) $linkid);
            } else {
                $urlevent = '#';
            }
            $descShort = icagendaEvents::shortDescription($item->desc, true, $this->filtering_shortDesc, $this->limit);
            /**
             * Get Thumbnail
             */
            // START iCthumb
            // Set if run iCthumb
            if ($item->image && $thumb_generator == 1) {
                // Generate small thumb if not exist
                $thumb_img = icagendaThumb::sizeSmall($item->image);
            } elseif ($item->image && $thumb_generator == 0) {
                $thumb_img = $item->image;
            } else {
                $thumb_img = $item->image ? 'media/com_icagenda/images/nophoto.jpg' : '';
            }
            // END iCthumb
            $evtParams = '';
            $evtParams = new JRegistry($item->params);
            // Display Time
            $r_time = $params->get('dp_time', 1) ? true : false;
            // Display City
            $r_city = $params->get('dp_city', 1) ? $item->city : false;
            // Display Country
            $r_country = $params->get('dp_country', 1) ? $item->country : false;
            // Display Venue Name
            $r_place = $params->get('dp_venuename', 1) ? $item->place_name : false;
            // Display Intro Text
            $dp_shortDesc = $params->get('dp_shortDesc', '');
            // Short Description
            if ($dp_shortDesc == '1') {
                $descShort = $item->shortdesc ? $item->shortdesc : false;
            } elseif ($dp_shortDesc == '2') {
                $descShort = $descShort ? $descShort : false;
            } elseif ($dp_shortDesc == '0') {
                $descShort = false;
            } else {
                $e_shortdesc = $item->shortdesc ? $item->shortdesc : $descShort;
                $descShort = $e_shortdesc ? $e_shortdesc : $item->metadesc;
            }
            // Display Registration Infos
            $dp_regInfos = $params->get('dp_regInfos', 1);
            $maxTickets = $dp_regInfos == 1 ? $evtParams->get('maxReg', '1000000') : false;
            $typeReg = $dp_regInfos == 1 ? $evtParams->get('typeReg', '1') : false;
            $event = array('id' => (int) $item->id, 'Itemid' => (int) $linkid, 'title' => $item->title, 'next' => $this->formatDate($item->next), 'image' => $thumb_img, 'file' => $item->file, 'address' => $item->address, 'city' => $r_city, 'country' => $r_country, 'place' => $r_place, 'description' => $item->desc, 'descShort' => $descShort, 'cat_title' => $item->cat_title, 'cat_order' => $item->cat_order, 'cat_color' => $item->cat_color, 'nb_events' => count($item->id), 'no_image' => JTEXT::_('MOD_ICCALENDAR_NO_IMAGE'), 'params' => $item->params, 'features_icon_size' => $this->features_icon_size, 'features_icon_root' => $this->features_icon_root, 'show_icon_title' => $this->show_icon_title, 'features' => $features, 'item' => $item);
            // Access Control
            $access = $item->access ? $item->access : '1';
            // Language Control
            $languages = array(JFactory::getLanguage()->getTag(), '*');
            $eventLang = isset($item->language) ? $item->language : '*';
            // Get Option Dislay Time
            $displaytime = isset($item->displaytime) ? $item->displaytime : '';
            $events_per_day = array();
            // Get List of Dates
            if ((in_array($access, $userLevels) || in_array('8', $userGroups)) && in_array($eventLang, $languages) && is_array($event) && $linkid) {
                $past_dates = 0;
                foreach ($AllDates as $d) {
                    // Control if date is past
                    if (strtotime($d) < strtotime($datetime_today)) {
                        $past_dates = $past_dates + 1;
                    }
                }
                foreach ($AllDates as $d) {
                    $this_date_control = date('Y-m-d H:i', strtotime($d));
                    if ($only_startdate && in_array($this_date_control, $perioddates)) {
                        $set_date_in_url = '';
                    } else {
                        $set_date_in_url = $date_var . iCDate::dateToAlias($d, 'Y-m-d H:i');
                    }
                    if ($r_time) {
                        $time = array('time' => date($lang_time, strtotime($d)), 'displaytime' => $displaytime, 'url' => $urlevent . $set_date_in_url);
                    } else {
                        $time = array('time' => '', 'displaytime' => '', 'url' => $urlevent . $set_date_in_url);
                    }
                    $event = array_merge($event, $time);
                    $this_date = $item->reg_date ? date('Y-m-d H:i:s', strtotime($d)) : 'period';
                    $registrations = $dp_regInfos == 1 ? true : false;
                    $registered = $dp_regInfos == 1 ? self::getNbTicketsBooked($this_date, $item->registered, $eventnumber, $set_date_in_url) : false;
                    $maxTickets = $maxTickets != '1000000' ? $maxTickets : false;
                    $TicketsLeft = $dp_regInfos == 1 && $maxTickets ? $maxTickets - self::getNbTicketsBooked($this_date, $item->registered, $eventnumber, $set_date_in_url) : false;
                    // If period started, and registration is set to "for all dates of the event"
                    if ($maxTickets && $past_dates && $typeReg == 2) {
                        $date_sold_out = JText::_('MOD_ICCALENDAR_REGISTRATION_CLOSED');
                    } elseif ($maxTickets) {
                        $date_sold_out = $TicketsLeft <= 0 ? JText::_('MOD_ICCALENDAR_REGISTRATION_DATE_NO_TICKETS_LEFT') : false;
                    } else {
                        $date_sold_out = false;
                    }
                    $reg_infos = array('registrations' => $registrations, 'registered' => $registered, 'maxTickets' => $maxTickets, 'TicketsLeft' => $TicketsLeft, 'date_sold_out' => $date_sold_out);
                    $event = array_merge($event, $reg_infos);
                    foreach ($days as $k => $dy) {
                        //						$d_date		= JHtml::date($d, 'Y-m-d', $eventTimeZone);
                        $d_date = date('Y-m-d', strtotime($d));
                        $dy_date = date('Y-m-d', strtotime($dy['date']));
                        if ($d_date == $dy_date) {
                            array_push($days[$k]['events'], $event);
                        }
                    }
                }
            }
        }
        $i = '';
        if ($nolink || !JComponentHelper::getComponent('com_icagenda', true)->enabled) {
            do {
                echo '<div style="color:#a40505; text-align: center;"><b>info :</b></div><div style="color:#a40505; font-size: 0.8em; text-align: center;">' . JText::_('MOD_ICCALENDAR_COM_ICAGENDA_MENULINK_UNPUBLISHED_MESSAGE') . '</div>';
            } while ($i > 0);
        }
        $db = JFactory::getDbo();
        $query = $db->getQuery(true);
        $query->select('id AS nbevt')->from('`#__icagenda_events` AS e')->where('e.state > 0');
        $db->setQuery($query);
        $nbevt = $db->loadResult();
        $nbevt = count($nbevt);
        $no_event_message = '<div class="ic-msg-no-event">' . JText::_('MOD_ICCALENDAR_NO_EVENT') . '</div>';
        if ($nbevt == NULL) {
            echo $no_event_message;
        }
        // To be Checked
        $total_items = count($result);
        if ($displayed_items == '0' && $total_items > 0) {
            echo $no_event_message;
        }
        if ($total_items > $displayed_items) {
            $not_displayed = $total_items - $displayed_items;
            $user = JFactory::getUser();
            if ($user->authorise('core.admin')) {
                echo '<div class="alert alert-warning">' . JText::sprintf('IC_MODULE_ALERT_EVENTS_NOT_DISPLAYED', $not_displayed) . '</div>';
            }
        }
        return $days;
    }
Exemplo n.º 3
0
 protected function datelistMkt($i)
 {
     $eventTimeZone = null;
     $date_today = JHtml::date('now', 'Y-m-d');
     $date_time_today = JHtml::date('now', 'Y-m-d H:i');
     $allDates = $this->eventAllDates($i);
     $timeformat = $this->options['timeformat'];
     $max_tickets = $this->evtParams($i)->get('maxReg', '1000000');
     $perioddates = iCDatePeriod::listDates($i->startdate, $i->enddate, $eventTimeZone);
     $regUntilEnd = JComponentHelper::getParams('com_icagenda')->get('reg_end_period', 0);
     // Check the period if individual dates
     $only_startdate = $i->weekdays || $i->weekdays == '0' ? false : true;
     $lang_time = $timeformat == 1 ? 'H:i' : 'h:i A';
     sort($allDates);
     $p = 0;
     foreach ($allDates as $k => $d) {
         $date_control = JHtml::date($d, 'Y-m-d H:i', $eventTimeZone);
         if ($only_startdate && in_array($date_control, $perioddates)) {
             $is_full_period = true;
             $datetime_date = $regUntilEnd == 1 ? date('Y-m-d H:i:s', strtotime($i->enddate)) : date('Y-m-d H:i:s', strtotime($i->startdate));
         } else {
             $is_full_period = false;
             $datetime_date = date('Y-m-d H:i:s', strtotime($d));
         }
         $nb_tickets_left = $max_tickets - self::getNbTicketsBooked($datetime_date, $i->registered, $i->id, $is_full_period);
         $date_today_compare = $this->displaytime($i) == 1 ? $date_time_today : $date_today;
         if (strtotime($datetime_date) > strtotime($date_today_compare) && $nb_tickets_left > 0) {
             $tickets_left = $max_tickets != '1000000' ? ' [' . $nb_tickets_left . ']' : '';
             if ($is_full_period) {
                 if ($p == 0) {
                     $upDays[$k] = '@@' . $this->formatDate($i->startdate) . ' &#x279c; ' . $this->formatDate($i->enddate) . $tickets_left;
                     $p = $p + 1;
                 }
             } else {
                 $date = $this->formatDate($d);
                 $event_time = $this->displaytime($i) == 1 ? ' - ' . date($lang_time, strtotime($datetime_date)) : '';
                 $upDays[$k] = $datetime_date . '@@' . $date . $event_time . $tickets_left;
             }
         }
     }
     if (isset($upDays)) {
         return $upDays;
     }
 }
Exemplo n.º 4
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);
     }
 }
Exemplo n.º 5
0
 /**
  * Get Next Date from Period
  */
 function getNextPeriod($period, $i_weekdays)
 {
     // Set Vars
     $eventTimeZone = null;
     $date_today = JHtml::date('now', 'Y-m-d');
     // Joomla Time Zone
     $WeeksDays = iCDatePeriod::weekdaysToArray($i_weekdays);
     // Set Next Date for Period, if dates exist in Period
     if (count($period)) {
         $nextPeriod = $period[0];
         foreach ($period as $e) {
             if (in_array(date('w', strtotime($e)), $WeeksDays)) {
                 if (strtotime($e) >= strtotime($date_today)) {
                     $nextPeriod = $e;
                 }
             }
         }
         return JHtml::date($nextPeriod, 'Y-m-d H:i', $eventTimeZone);
     }
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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;
 }