4 * Event Calendar for Elxis CMS 2008.x and 2009.x
6 * Frontend Event Handler
9 * @package eventCalendar
10 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
11 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
12 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
16 // Prevent direct inclusion of this file
17 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
19 // Check the permissions
20 if ( $my->usertype
== '' ) {
21 $usertype = eUTF
::utf8_strtolower($acl->get_group_name('29'));
23 $usertype = eUTF
::utf8_strtolower($my->usertype
);
25 // Check if the user is allowed to access this component. If not then re-direct him to the main page.
26 if (($mosConfig_access == '1') |
($mosConfig_access == '3')) {
27 if (!($acl->acl_check( 'action', 'view', 'users', $usertype, 'components', 'all' ) ||
28 $acl->acl_check( 'action', 'view', 'users', $usertype, 'components', 'com_eventcalendar' ))) {
29 mosRedirect( 'index.php', _NOT_AUTH
);
34 require_once($mainframe->getCfg('absolute_path' ).'/components/com_eventcalendar/eventcalendar.class.php'); // Component's general class
35 require_once($mainframe->getCfg('absolute_path' ).'/components/com_eventcalendar/eventcalendar.html.php'); // Component's html file for the public area
37 /*************************************************************************/
38 /* THE CLASS THAT WILL CONTAIN THE COMPONENT'S FRONT-END FUNCTIONALITY */
39 /*************************************************************************/
40 class clsEventCalendar
{
42 // Initialize variables
43 public $live_path = ''; // component's live path
44 public $live_apath = ''; // component's live path (admin)
45 public $abs_path = ''; // component's absolute path
46 public $abs_apath = ''; // component's absolute path (admin)
47 public $lng = null; // component's language
48 public $params = array(); // component's parameters
49 public $timetable = array(); // user-set timetables
50 public $timetable_selected = 0; // selected timetable
51 public $weekdays = array(); // for offset calculation
52 public $events = array(); // store events
53 public $calendar = array(); // store calendar days
64 /****************************/
65 /* The class' constructor */
66 /****************************/
67 public function __construct() {
68 global $mainframe, $lang, $Itemid, $database;
70 // Set absolute and live path
71 $this->live_path
= $mainframe->getCfg('live_site').'/components/com_eventcalendar';
72 $this->live_apath
= $mainframe->getCfg('live_site').'/administrator/components/com_eventcalendar';
73 $this->abs_path
= $mainframe->getCfg('absolute_path').'/components/com_eventcalendar';
74 $this->abs_apath
= $mainframe->getCfg('absolute_path').'/administrator/components/com_eventcalendar';
77 if (file_exists($this->abs_path
.'/language/'.$lang.'.php')) {
78 require_once($this->abs_path
.'/language/'.$lang.'.php');
80 require_once($this->abs_path
.'/language/english.php');
82 $this->lng
= new clsEventCalendarLanguage();
84 // Load params from Event Calendar (component)
85 $database->setQuery("SELECT params FROM #__components WHERE link = 'option=com_eventcalendar'", '#__', 1, 0);
86 $result = $database->loadResult();
87 $com_params = new mosParameters($result);
88 // Load params from MENUITEM
89 $menu = new mosMenu($database);
91 $menu_params = new mosParameters($menu->params
);
92 // Create an array with parameters
93 $this->params
['com'] = $com_params;
94 $this->params
['menu'] = $menu_params;
95 $this->params
['menuobj'] = $menu;
97 // Unserialize and split timetable values
98 $this->timetable
= unserialize( $this->params
['com']->get('timetable', 'a:1:{i:0;s:10:"0:00-23:59";}'));
99 for ( $i = 0; $i < count($this->timetable
); $i++
) {
100 $this->timetable
[$i] = split( "-", $this->timetable
[$i]);
102 // Get selected timetable
103 $this->timetable_selected
= $this->params
['com']->get( 'timetable_selected', 0);
105 // Use english week-day-names for offset calculation
106 $this->weekdays
= array("sunday","monday","tuesday","wednesday","thursday","friday","saturday","sunday");
108 //Set current task and eventid
109 $this->task
= (string)mosGetParam($_REQUEST, 'task' , $this->params
['com']->get('default_view', 'monthview'));
110 $this->eventid
= intval( mosGetParam($_REQUEST, 'eventid' , '') );
111 // Set category id(s)
112 $this->catid
= mosGetParam($_REQUEST, 'catid' , '');
113 $this->catid
= $this->parseCatid( $this->catid
);
114 // Get date from REQUEST, else set current date
115 $this->year
= intval(mosGetParam($_REQUEST, 'year', date("Y", time())));
116 $this->week
= mosGetParam($_REQUEST, 'week');
118 $this->date
= strtotime("+".($this->week
- 1)." week", mktime(0,0,0,01,01,$this->year
));
119 $this->month
= date("m", $this->date
);
120 $this->day
= date("d", $this->date
);
122 $this->month
= mosGetParam($_REQUEST, 'month', date("m", time()));
123 $this->day
= mosGetParam($_REQUEST, 'day', date("d", time()));
124 $this->date
= strtotime($this->year
."-".$this->month
."-".$this->day
);
125 $this->week
= mosGetParam($_REQUEST, 'week', date("W", $this->date
));
130 /******************************/
131 /* The class' main function */
132 /******************************/
133 public function main() {
134 global $mainframe, $Itemid;
136 switch($this->task
) {
138 $this->displayEventEdit($this->eventid
);
144 $this->cancelEvent();
146 case 'eventview': // displays single event
148 $this->displayEventView();
150 case 'dayview': //shows daily view
151 $this->displayDayView();
153 case 'weekview': //shows weekly view
154 $this->displayWeekView();
156 case 'monthview': //shows monthly view
157 $this->displayMonthView();
159 case 'catview': //shows event-list
160 $this->displayCategoriesList();
162 case 'ajaxrsv': //set reservations
163 $this->ajaxReserve();
166 $this->eventSyndication();
168 default: // Redirect to default_view
169 mosRedirect( sefRelToAbs("index.php?option=com_eventcalendar&task=".$this->params
['com']->get('default_view', 'monthview')."&Itemid=".$Itemid, EVCALBASE
. "/") );
177 private function eventSyndication() {
178 global $database, $mainframe, $lang, $mosConfig_offset, $my, $Itemid;
180 require_once($mainframe->getCfg('absolute_path').'/includes/feedcreator.class.php' );
185 $live_bookmark = mosGetParam($_REQUEST, 'livebookmark' , '0');
186 $feed = strtoupper(mosGetParam( $_GET, 'feed', 'RSS2.0'));
187 $vfeeds = array( 'RSS0.91', 'RSS1.0', 'RSS2.0', 'OPML', 'ATOM0.3' ); //PIE0.1, MBOX, HTML, JS removed
188 if (!in_array($feed, $vfeeds)) { $feed = 'RSS2.0'; }
189 $now = date('Y-m-d H:i:s', time() +
$mosConfig_offset * 3600);
190 $iso = preg_split('/\=/', _ISO
);
192 $info['date'] = date( 'r' );
193 $info['year'] = date( 'Y' );
194 $info['encoding'] = $iso[1];
195 $info['link'] = htmlspecialchars($mainframe->getCfg('live_site'));
196 $info['cache'] = $this->params
['com']->get('rss_cache', '0');
197 $info['cache_time'] = intval($this->params
['com']->get('rss_cachetime', '3600'));
198 $info['count'] = intval($this->params
['com']->get('rss_num', '5'));
199 $info['multilingual'] = intval($this->params
['com']->get('rss_multilang', '0'));
200 $info['title'] = $this->params
['com']->get('rss_title', 'EventCalendar RSS feeds');
201 $info['description'] = $this->params
['com']->get('rss_description', 'EventCalendar web syndication.');
202 $info['image_file'] = $this->params
['com']->get( 'rss_img', 'elxis_rss.png' );
203 if ( $info['image_file'] == -1 ) {
204 $info['image'] = NULL;
206 $info['image'] = $mainframe->getCfg('live_site').'/images/M_images/'.$info['image_file'];
208 $info['image_alt'] = $this->params
['com']->get( 'rss_imgal', 'EventCalendar RSS feeds' );
209 $info['limit_text'] = $this->params
['com']->get( 'rss_limittext', 0 );
210 $info['text_length'] = $this->params
['com']->get( 'rss_textlength', 20 );
211 $info['feed'] = $feed;
213 $info['live_bookmark'] = $this->params
['com']->get( 'rss_live', '' );
215 if ( $info['live_bookmark'] ) {
216 $info['file'] = $mainframe->getCfg('absolute_path').'/cache/evlive.xml';
218 $info['file'] = eUTF
::utf8_strtolower( eUTF
::utf8_str_replace( '.', '', $info['feed'] ) );
219 $info['file'] = $mainframe->getCfg('absolute_path').'/cache/ev'.$info['file'].'.xml';
222 if ($info['multilingual']) { //multilingual feeds
223 $info['file'] = str_replace('.xml', '-'.$lang.'.xml', $info[ 'file' ]);
226 $rss = new UniversalFeedCreator();
227 $image = new FeedImage();
229 if ( $info[ 'cache' ] ) {
230 $rss->useCached( $info[ 'feed' ], $info[ 'file' ], $info[ 'cache_time' ] );
233 $rss->title
= $info[ 'title' ];
234 $rss->description
= $info[ 'description' ];
235 $rss->link
= $info[ 'link' ];
236 $rss->syndicationURL
= $info[ 'link' ];
237 $rss->cssStyleSheet
= NULL;
238 $rss->encoding
= $info[ 'encoding' ];
240 if ( $info[ 'image' ] ) {
241 $image->url
= $info[ 'image' ];
242 $image->link
= $info[ 'link' ];
243 $image->title
= $info[ 'image_alt' ];
244 $image->description
= $info[ 'description' ];
246 $rss->image
= $image;
248 $query = "SELECT e.id, e.title, e.seotitle, e.description FROM #__eventcalendar e"
249 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
250 . "\n WHERE e.published = '1' AND c.published = '1' AND c.access IN (".$my->allowed
.")"
251 . "\n AND (e.start_date >= '".date("Y-m-d H:m:s", time())."')"
252 . "\n AND ( (e.language IS NULL) OR (e.language LIKE '%".$lang."%') )"
253 . "\n AND ( (c.language IS NULL) OR (c.language LIKE '%".$lang."%') )"
254 . "\n ORDER BY e.start_date ASC";
256 if ( $info['count'] ) {
257 $database->setQuery( $query, '#__', $info[ 'count' ], 0 );
259 $database->setQuery( $query );
262 $rows = $database->loadObjectList();
265 foreach ( $rows as $row ) {
266 $item_title = htmlspecialchars( $row->title
);
267 $item_title = html_entity_decode( $item_title );
269 $query = "SELECT id FROM #__menu"
270 ."\n WHERE link = 'index.php?option=com_eventcalendar' AND published = '1'"
271 ."\n AND ((language IS NULL) OR (language LIKE '%".$xartis->maplang
."%'))";
272 $database->setQuery($query, '#__', 1, 0);
273 $_Itemid = intval($database->loadResult());
275 $item_link = $mainframe->getCfg('live_site').'/index.php?option=com_eventcalendar&task=eventview&eventid='.$row->id
.'&Itemid='.$_Itemid;
276 $item_link = sefRelToAbs( $item_link );
277 $item_link = str_replace('&', '&', $item_link);
279 $item_description = $row->description
;
280 $item_description = mosHTML
::cleanText( $item_description );
281 $item_description = html_entity_decode( $item_description );
282 if ($info['limit_text']) {
283 if ($info[ 'text_length']) {
284 $item_description_array = preg_split('/[\s]/', $item_description);
285 $count = count( $item_description_array );
286 if ( $count > $info['text_length']) {
287 $item_description = '';
288 for ( $a = 0; $a < $info['text_length']; $a++
) {
289 $item_description .= $item_description_array[$a]. ' ';
291 $item_description = eUTF
::utf8_trim( $item_description );
292 $item_description .= '...';
295 $item_description = NULL;
299 //load individual item creator class
300 $item = new FeedItem();
302 $item->title
= $item_title;
303 $item->link
= $item_link;
304 $item->description
= $item_description;
305 $item->source
= $info['link'];
307 //loads item info into rss array
308 $rss->addItem( $item );
312 $rss->saveFeed( $info[ 'feed' ], $info[ 'file' ], true );
315 /************************/
316 /* AJAX Reserveations */
317 /************************/
318 private function ajaxReserve() {
319 global $database, $my;
321 $elem = intval(mosGetParam($_REQUEST, 'elem', ''));
322 $user_id = intval(mosGetParam($_REQUEST, 'user-id', ''));
323 $state = strval(mosGetParam($_REQUEST, 'state', ''));
325 if ($this->eventid
) {
326 $event = new mosEventCalendar_Event( $database );
327 $event->load( $this->eventid
);
329 if ($state == 'reserve') {
330 $event->rsv
= ($event->rsv
)?
$event->rsv
.','.$user_id:$user_id;
331 if ($event->check($error)) {
332 if (!$event->store()) {
333 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$objEventCalendar->lng
->EDT_MSG_ERROR
."');</script>"._LEND
;
337 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$error."');</script>"._LEND
;
340 } elseif ($state == 'cancel') {
341 $users = explode(',', $event->rsv
);
342 if ( in_array($user_id, $users) ) {
343 foreach ($users as $key=>$value) {
344 if ($value == $user_id) {
349 $event->rsv
= implode(',', $users);
350 if ($event->check($error)) {
351 if (!$event->store()) {
352 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$objEventCalendar->lng
->EDT_MSG_ERROR
."');</script>"._LEND
;
356 echo "<script type=\"text/javascript\">alert('".$objEventCalendar->lng
->GEN_COMPONENT_TITLE
.": ".$error."');</script>"._LEND
;
363 $query = "SELECT name FROM #__users WHERE id IN (".$event->rsv
.")";
364 $database->setQuery( $query );
365 $users = $database->loadResultArray();
367 echo '<i>'.$users[0].'</i>';
368 for ($i = 1; $i < count($users); $i++
) {
369 echo ', '.'<i>'.$users[$i].'</i>';
372 echo '<i>'.$this->lng
->EDT_RSV_NONE
.'</i>';
376 if (in_array($my->id
, explode(',', $event->rsv
))) {
377 echo "<br/><br/>".$this->lng
->EDT_RSV_YES
."<br/>"; ?
>
378 <input
class="button" type
="button" value
="<?php echo $this->lng->EDT_RSV_CAN; ?>" id
="cancel-rsv" name
="cancel-rsv" onclick
="showReserve(<?php echo $my->id; ?>, <?php echo $event->id; ?>, 'cancel');" />
380 echo "<br/><br/>".$this->lng
->EDT_RSV_NO
."<br/>"; ?
>
381 <input
class="button" type
="button" value
="<?php echo $this->lng->EDT_RSV_SUB; ?>" id
="submit-rsv" name
="submit-rsv" onclick
="showReserve(<?php echo $my->id; ?>, <?php echo $event->id; ?>, 'reserve');" />
388 /***********************************/
389 /* Prepare to display month view */
390 /***********************************/
391 private function displayMonthView() {
394 $week_startingday = $this->params
['com']->get( 'week_startingday' , 0);
396 // Get timestamps for first and last day of month
397 $firstDay_stamp = mktime( 0, 0, 0, date("m", $this->date
), 1, date("Y", $this->date
) );
398 $lastDay_stamp = mktime( 0, 0, 0, date("m", $this->date
) +
1, 1, date("Y", $this->date
) );
399 $lastDay_stamp = strtotime("yesterday", $lastDay_stamp);
401 // Get how many days will be empty in the view before current month starts
402 $prevMonth_days = intval( strftime("%w", $firstDay_stamp) ) - $week_startingday;
403 $prevMonth_days = ($prevMonth_days < 0)?
$prevMonth_days +
7:$prevMonth_days;
405 // Get how many days will be empty in the view after current month ends
406 $nextMonth_days = intval( 6 - strftime("%w", $lastDay_stamp) +
$week_startingday);
407 $nextMonth_days = ($nextMonth_days == 7)?
0:$nextMonth_days;
409 // Loading weeknumbers
410 $working_date = $firstDay_stamp;
412 // Get amount of days to be displayed and divide them by seven,
413 // then ciel to round and get the number of weeks in the view
414 for($i = 0; $i < ( $prevMonth_days +
strftime("%d", $lastDay_stamp) +
$nextMonth_days ) / 7 ; $i++
) {
415 $weeknrs[] = ($fmanager->iswin
) ?
strftime("%U", $working_date) : strftime("%V", $working_date);
416 $working_date = strtotime("+ 1 week", $working_date);
419 // Create calender matrix of dates for days of month
420 $working_date = strtotime( '- '.$prevMonth_days.' days', $firstDay_stamp);
421 // Fill previous month days
422 for ($i = 0; $i < $prevMonth_days; $i++
) {
423 $this->calendar
[] = $working_date;
424 $working_date = strtotime( '+ 1 day', $working_date);
426 // Fill current month days
427 for ($i = 0; $i < strftime("%d", $lastDay_stamp); $i++
) {
428 $this->calendar
[] = $working_date;
429 $working_date = strtotime( '+ 1 day', $working_date);
431 // Fill next month days
432 for ($i = 0; $i < $nextMonth_days; $i++
) {
433 $this->calendar
[] = $working_date;
434 $working_date = strtotime( '+ 1 day', $working_date);
440 // Render month table
441 clsEventCalendarHTML
::displayMonthViewHTML($weeknrs);
444 $this->displayFooter();
447 /***********************************/
448 /* Prepare to display week view */
449 /***********************************/
450 protected function displayWeekView() {
452 $week_startingday = $this->params
['com']->get( 'week_startingday' , 0);
454 // Get timestamps for first and last day of week
455 $firstDay_stamp = (date("w", $this->date
) == $week_startingday)?
$this->date
:strtotime(('last '.$this->weekdays
[$week_startingday]), $this->date
);
456 //$lastDay_stamp = (date("w", $this->date) == ((($week_startingday - 1) < 0)?6:$week_startingday - 1))?$this->date:strtotime(('next '.$this->weekdays[((($week_startingday - 1) < 0)?6:$week_startingday - 1)]), $this->date);
458 $working_date = $firstDay_stamp;
459 for ($i = 0; $i <= 6; $i++
) {
460 $this->calendar
[] = $working_date;
461 $working_date = strtotime('+1 day', $working_date);
468 clsEventCalendarHTML
::displayWeekViewHTML();
471 $this->displayFooter();
474 /*********************************/
475 /* Prepare to display day view */
476 /*********************************/
477 protected function displayDayView() {
483 clsEventCalendarHTML
::displayDayViewHTML();
486 $this->displayFooter();
489 /***********************************/
490 /* Prepare to display event view */
491 /***********************************/
492 protected function displayEventView() {
493 global $database, $Itemid;
495 if ($this->eventid
) {
496 $event = new mosEventCalendar_Event( $database );
497 $event->load( $this->eventid
);
499 $category = new mosCategory( $database );
500 $category->load( $event->catid
);
502 clsEventCalendarHTML
::displayEventViewHTML( $event, $category );
505 if ($this->task
!= 'printevent') {
506 $this->displayFooter();
509 $menuitem = "&Itemid=".$Itemid;
510 if (isset($this->catid
)) {
511 $catids = (is_array($this->catid
))?
implode("+", $this->catid
):$this->catid
;
513 $catids = ($catids !== "")?
"&catid=".$catids:"";
515 mosRedirect( sefRelToAbs("index.php?option=com_eventcalendar&task=".$this->params
['com']->get('default_view', 'month')."&year=".$this->year
."&month=".$this->month
."&day=".$this->day
.$catids.$menuitem) );
519 /******************************************/
520 /* Prepare to display the category list */
521 /******************************************/
522 protected function displayCategoriesList() {
523 global $database, $my;
525 // Load categories from database
526 if (is_array( $this->catid
)) {
527 $filter = "\n AND id IN (" . implode( ",", $this->catid
) . ")";
528 } else if ($this->catid
) {
529 $filter = "\n AND id = " . $this->catid
;
531 $categories = $this->getCategories( $filter );
533 // Load events from database
534 $query = "SELECT e.id FROM #__eventcalendar e"
535 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
536 . "\n WHERE e.published = '1' AND c.published = '1' AND c.access IN (".$my->allowed
.")";
537 if (is_array( $this->catid
)) {
538 $query .= "\n AND c.id IN (" . implode( ",", $this->catid
) . ")";
539 } else if ($this->catid
) {
540 $query .= "\n AND c.id = " . $this->catid
;
542 $query .= "\n ORDER BY e.start_date ASC";
543 $database->setQuery( $query );
544 $results = $database->loadResultArray();
547 foreach ($results AS $event_id ) {
548 $load_event = new mosEventCalendar_Event( $database );
549 $load_event->load( $event_id );
550 $this->events
[] = clone( $load_event );
553 clsEventCalendarHTML
::displayCategoriesListHTML( $categories );
556 $this->displayFooter();
560 /********************************************/
561 /* Prepare to display the edit event form */
562 /********************************************/
563 protected function displayEventEdit($existing = '') {
564 global $my, $database;
566 // Validate once more permissions
571 $permits = explode(',', $my->allowed
);
572 if ($existing == '') {
573 if ( !in_array($this->params
['com']->get('who_can_post_events'), $permits) ) {
578 if ( !in_array($this->params
['com']->get('who_can_edit_events'), $permits) ) {
584 // Load event for edit/add
585 if (is_numeric($existing)) {
586 $event = new mosEventCalendar_Event($database);
587 $event->load($existing);
589 $existing->checkout( $my->id
);
592 clsEventCalendarHTML
::displayEventEditHTML($existing);
594 /*********************/
595 /* Save event form */
596 /*********************/
597 protected function saveEvent() {
598 global $my, $mainframe, $database, $Itemid;
601 $tokname = 'token'.$my->id
;
602 if ( !isset($_POST[$tokname]) ||
!isset($_SESSION[$tokname]) ||
($_POST[$tokname] != $_SESSION[$tokname]) ) {
603 die( 'Detected CSRF attack! Someone is forging your requests.' );
606 foreach ($_POST['languages'] as $xlang) {
607 if (trim($xlang) == '') { $newlangs = ''; }
609 if (!isset($newlangs)) {
610 $newlangs = implode(',', $_POST['languages']);
612 $_POST['language'] = $newlangs;
614 // Add a seotitle and a pending state
615 require_once($mainframe->getCfg('absolute_path' ).'/administrator/components/com_eventcalendar/eventcalendar.seovs.class.php');
616 $seo = new seovsEventCalendar('com_eventcalendar', $_POST['title']);
617 $seo->id
= $_POST['id'];
618 $seo->catid
= $_POST['catid'];
619 $_POST['seotitle'] = $seo->suggest();
620 $_POST['published'] = '-1';
623 $event = new mosEventCalendar_Event($database);
624 $event->bind( $_POST );
625 if ($event->check($error)) {
626 if (!$event->store()) {
627 echo "<script type=\"text/javascript\">alert('".$this->lng
->GEN_COMPONENT_TITLE
.": ".$this->lng
->EDT_MSG_ERROR
."'); window.history.go(-1);</script>"._LEND
;
631 echo "<script type=\"text/javascript\">alert('".$this->lng
->GEN_COMPONENT_TITLE
.": ".$error."'); window.history.go(-1);</script>"._LEND
;
635 // Redirect to default view
636 $menuitem = "&Itemid=".$Itemid;
637 mosRedirect( sefRelToAbs("index.php?option=com_eventcalendar&task=".$this->params
['com']->get('default_view', 'monthview') . "&year=".$this->year
. "&month=".$this->month
. "&day=".$this->day
. $menuitem) );
639 /***********************/
640 /* Cancel event form */
641 /***********************/
642 protected function cancelEvent() {
643 global $database, $Itemid;
645 $event = new mosEventCalendar_Event($database);
646 $event->checkin($_POST['id']);
649 // Redirect to default view
650 $menuitem = "&Itemid=".$Itemid;
651 mosRedirect( sefRelToAbs("index.php?option=com_eventcalendar&task=".$this->params
['com']->get('default_view', 'monthview') . "&year=".$this->year
. "&month=".$this->month
. "&day=".$this->day
. $menuitem) );
654 /***********************************/
655 /* Prepare to display the footer */
656 /***********************************/
657 protected function displayFooter() {
659 if ( $this->params
['com']->get('view_catlist', true) ) { //if the category-list is shown
660 if ( isset($this->catid
) ) {
661 // mark selected categories from $POST
662 $catids = (is_array($this->catid
))?
$this->catid
:array($this->catid
);
663 clsEventCalendarHTML
::displayFooterHTML( $this->getCategories(), $catids );
666 clsEventCalendarHTML
::displayFooterHTML( $this->getCategories() );
671 /***********************/
672 /* Helpful Functions */
673 /***********************/
675 protected function parseCatid( $catid ) {
677 $catid = split( " ", $catid );
679 // Clear empty and non numerics values
680 $filterFunct = create_function('$elem','return (isset($elem))?is_numeric($elem):false;');
681 $catid = array_filter( $catid, $filterFunct );
683 switch (count($catid)) {
684 case 0: // no category id is set (return empty)
687 case 1: // one category is set (return a simple variable)
688 $key = array_keys($catid);
689 return $catid[$key[0]];
691 default: // more categories are set (return an array)
698 /* Return an array with event-categories selected by filter string */
699 protected function getCategories($filter = '') {
700 global $database, $my;
702 $query = "SELECT id FROM #__categories"
703 . "\n WHERE section = 'com_eventcalendar' AND published = '1' AND access IN (".$my->allowed
.")"
705 . "\n ORDER BY ordering";
706 $database->setQuery ($query);
707 $results = $database->loadResultArray();
709 $categories = array();
710 foreach ($results AS $id) {
711 $category = new mosCategory($database);
712 $category->load($id);
713 $categories[] = clone( $category );
718 /* Get single values from params string */
719 public function getParam($key, $params) {
720 $parameter = new mosParameters( $params );
721 return ($parameter->get($key))?
$parameter->get($key):false;
724 /************************/
725 /* Recursion Functions */
726 /************************/
727 /* Calculate events */
728 protected function calcEvents() {
729 global $database, $my, $lang;
731 // Load events from database
732 $query = "SELECT e.id, e.start_date, e.end_date FROM #__eventcalendar e"
733 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
734 . "\n WHERE e.published = '1' AND c.published = '1' AND c.access IN (".$my->allowed
.")"
735 . "\n AND ( (e.language IS NULL) OR (e.language LIKE '%".$lang."%') )"
736 . "\n AND ( (c.language IS NULL) OR (c.language LIKE '%".$lang."%') )";
737 if (is_array( $this->catid
)) {
738 $query .= "\n AND c.id IN (" . implode( ",", $this->catid
) . ")";
739 } else if ($this->catid
) {
740 $query .= "\n AND c.id = " . $this->catid
;
742 $query .= "\n ORDER BY e.start_date ASC";
743 $database->setQuery( $query );
744 $results = $database->loadObjectList();
747 foreach ($results as $row_event) {
748 if ( (strtotime($row_event->start_date
) <= $this->calendar
[count($this->calendar
)-1]) ||
(strtotime($row_event->end_date
) >= $this->calendar
[0]) ) {
749 $load_event = new mosEventCalendar_Event($database);
750 $load_event->load($row_event->id
);
751 $this->events
[] = clone( $load_event );
756 /* Calculate exceptions */
757 public function calcExceptions( $event ) {
758 $events = split("\n", $event->recur_except
);
759 for ($i = 0; $i <= (count($events)-1); $i++
) {
760 $events[$i] = strtotime($events[$i]);
765 /* Calculate recursion */
766 public function calcRecursion ( $date, $event ) {
768 // Check if date is in event publishing range
769 if ( ((strtotime(date("Y-m-d", strtotime($event->start_date
)))) <= $date) && ((strtotime(date("Y-m-d", strtotime($event->end_date
)))) >= $date) ) {
771 switch ($event->recur_type
) {
773 return ( date("w", $date) == $event->recur_week
);
776 return ( $event->recur_month
== date("j", $date) );
779 return ( ($event->recur_year_d
."/".$event->recur_year_m
) == date("j/n", $date) );
793 // Initiate the class and execute it, then unset the
794 // object in order to free the allocated PHP memory.
795 $objEventCalendar = new clsEventCalendar();
796 $objEventCalendar->main();
797 unset($objEventCalendar);