4 * Event Calendar (module) for Elxis CMS 2008.x and 2009.x+
7 * @package Event Calendar (module)
8 * @author Apostolos Koutsoulelos <akoutsoulelos@yahoo.gr>
9 * @copyright Copyright (C) 2009-2010 Apostolos Koutsoulelos. All rights reserved.
10 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
14 // Prevent direct inclusion of this file
15 defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
20 // Check if Event Calendar (component) is installed
21 if ( file_exists($mosConfig_absolute_path.'/components/com_eventcalendar/eventcalendar.class.php') ) {
22 require_once( $mosConfig_absolute_path.'/components/com_eventcalendar/eventcalendar.class.php' );
24 echo 'Event Calendar (component) not found!<br />';
29 if ( file_exists($mosConfig_absolute_path.'/modules/mod_eventcalendar/language/'.$lang.'.php') ) {
30 require_once( $mosConfig_absolute_path.'/modules/mod_eventcalendar/language/'.$lang.'.php' );
32 require_once( $mosConfig_absolute_path.'/modules/mod_eventcalendar/language/english.php' );
36 // Check if module is already declared
37 if (!class_exists('clsEventCalendarMOD')) {
38 class clsEventCalendarMOD
{
42 public $ec_month = '';
46 public $ec_modParams = null;
47 public $ec_comParams = null;
48 public $ec_comItemid = '';
50 public $ec_weeknrs = array();
51 public $ec_calendar = array();
52 public $ec_events = array();
54 /****************************/
55 /* The class' constructor */
56 /****************************/
57 public function __construct($params, $database) {
58 global $mainframe, $my, $Itemid;
60 // Load params from Event Calendar (module)
61 $this->ec_modParams
= $params;
63 // Load params from Event Calendar (component)
64 $database->setQuery("SELECT params FROM #__components WHERE link='option=com_eventcalendar'", '#__', 1, 0);
65 $result = $database->loadResult();
66 $this->ec_comParams
= new mosParameters($result);
68 // Get MENUITEM for links to Event Calendar (component)
69 $this->ec_comItemid
= $Itemid;
70 if ($mainframe->getCfg('sef') != 2) {
71 $access = !$mainframe->getCfg('shownoauth');
72 $query = "SELECT id FROM #__menu WHERE link='index.php?option=com_eventcalendar' AND published='1'"
73 ."\n AND ((language IS NULL) OR (language LIKE '%".$lang."%'))"
74 .($access ?
"\n AND access IN (".$my->allowed
.")" : "");
75 $database->setQuery($query, '#__', 1, 0);
76 $this->ec_comItemid
= intval($database->loadResult());
77 if (!$this->ec_comItemid
) { $this->ec_comItemid
= $Itemid; }
81 $this->ec_year
= (string)date("Y", time());
82 $this->ec_month
= (string)date("m", time());
83 $this->ec_day
= (string)date("d", time());
84 $this->ec_date
= strtotime($this->ec_year
."-".$this->ec_month
."-".$this->ec_day
);
87 /******************************/
88 /* The class' main function */
89 /******************************/
90 public function main() {
91 // standard functionality
92 $this->loadCalendar();
93 $this->drawCalendar();
96 /***************************************/
97 /* Prepare to display calendar table */
98 /***************************************/
99 protected function loadCalendar() {
102 $week_startingday = $this->ec_comParams
->get('week_startingday' , 0);
104 // Get timestamps for first and last day of month
105 $firstDay_stamp = mktime( 0, 0, 0, $this->ec_month
, 1, $this->ec_year
);
106 $lastDay_stamp = mktime( 0, 0, 0, $this->ec_month +
1, 1, $this->ec_year
);
107 $lastDay_stamp = strtotime("yesterday", $lastDay_stamp);
109 // Get how many days will be empty in the view before current month starts
110 $prevMonth_days = intval( strftime("%w", $firstDay_stamp) ) - $week_startingday;
111 $prevMonth_days = ($prevMonth_days < 0)?
$prevMonth_days +
7:$prevMonth_days;
113 // Get how many days will be empty in the view after current month ends
114 $nextMonth_days = intval( 6 - strftime("%w", $lastDay_stamp) +
$week_startingday);
115 $nextMonth_days = ($nextMonth_days == 7)?
0:$nextMonth_days;
117 // Loading weeknumbers
118 $working_date = $firstDay_stamp;
119 // Get the number of weeks in the view
120 for($i = 0; $i < ( $prevMonth_days +
strftime("%d", $lastDay_stamp) +
$nextMonth_days ) / 7 ; $i++
) {
121 $this->ec_weeknrs
[] = ($fmanager->iswin
) ?
strftime("%U", $working_date) : strftime("%V", $working_date);
122 $working_date = strtotime("+ 1 week", $working_date);
125 // Create calender matrix of dates for days of month
126 $working_date = strtotime( "- ".$prevMonth_days." days", $firstDay_stamp);
127 // Fill previous month days
128 for ($i = 0; $i < $prevMonth_days; $i++
) {
129 $this->ec_calendar
[] = $working_date;
130 $working_date = strtotime( "+ 1 day", $working_date);
132 // Fill current month days
133 for ($i = 0; $i < strftime("%d", $lastDay_stamp); $i++
) {
134 $this->ec_calendar
[] = $working_date;
135 $working_date = strtotime( "+ 1 day", $working_date);
137 // Fill next month days
138 for ($i = 0; $i < $nextMonth_days; $i++
) {
139 $this->ec_calendar
[] = $working_date;
140 $working_date = strtotime( "+ 1 day", $working_date);
147 /*************************/
148 /* Draw calendar table */
149 /*************************/
150 protected function drawCalendar() {
151 global $mainframe, $mosConfig_absolute_path, $lang;
153 // Load core HTML library
154 mosCommonHTML
::loadOverlib();
156 // Display month table
157 $thisMonth = mktime( 0, 0, 0, $this->ec_month
, 1, $this->ec_year
);
158 $lastMonth = strtotime( "1 month ago", $thisMonth );
159 $nextMonth = strtotime( "+ 1 month", $thisMonth );?
>
162 <!-- Calendar table
-->
164 <!-- Weeknum
empty -->
165 <?php
if ($this->ec_modParams
->get('show_weeknumber', true)) { ?
>
166 <td
class="weeknum_empty" rowspan
="2"></td
>
169 <td
class="navprev" colspan
="2">
171 if (($this->ec_month
- 1) <= 0) {
173 $year = $this->ec_year
- 1;
175 $month = $this->ec_month
- 1;
176 $month = (strlen($month) == 1) ?
("0".$month) : $month;
177 $year = $this->ec_year
;
180 <a href
="<?php echo sefRelToAbs("index
.php?option
=com_eventcalendar
&task
=monthview
&year
=".$year."&month
=".$month."&Itemid
=".$this->ec_comItemid, EVCALBASE."/all
/".$year."/".$month."/") ?>"> << </a
>
182 <td
class="nav" colspan
="3">
183 <a href
="<?php echo sefRelToAbs("index
.php?option
=com_eventcalendar
&task
=monthview
&year
=".date("Y
", $thisMonth)."&month
=".date("m
", $thisMonth)."&Itemid
=".$this->ec_comItemid, EVCALBASE."/all
/".date("Y
", $thisMonth)."/".date("m
", $thisMonth)."/") ?>">
184 <?php
echo strftime( "%B", $thisMonth ) . " " . strftime("%Y", $thisMonth) ?
>
187 <td
class="navnext" colspan
="2">
189 if (($this->ec_month +
1) > 12) {
191 $year = $this->ec_year +
1;
193 $month = $this->ec_month +
1;
194 $month = (strlen($month) == 1) ?
("0".$month) : $month;
195 $year = $this->ec_year
;
198 <a href
="<?php echo sefRelToAbs("index
.php?option
=com_eventcalendar
&task
=monthview
&year
=".$year."&month
=".$month."&Itemid
=".$this->ec_comItemid, EVCALBASE."/all
/".$year."/".$month."/") ?>"> >> </a
>
203 <?php
for($dcount = 0; $dcount < 7; $dcount++
) {?
>
204 <td
class="weeknames"><?php
echo strftime("%a", $this->ec_calendar
[$dcount]) ?
></td
>
207 <?php
for ($wcount = 1; $wcount <= count($this->ec_weeknrs
); $wcount++
) { ?
>
210 if ($this->ec_modParams
->get('show_weeknumber', true)) { ?
>
214 if ($this->ec_modParams
->get('week_number_links', true)) {
216 <a href
="<?php echo sefRelToAbs( "/index
.php?option
=com_eventcalendar
&task
=weekview
&year
=".$this->ec_year."&week
=".$this->ec_weeknrs[$wcount-1]."&Itemid
=".$this->ec_comItemid, EVCALBASE."/all
/".$this->ec_year."/".$this->ec_weeknrs[$wcount-1].".html
") ?>">
217 <?php
echo $this->ec_weeknrs
[$wcount-1]; ?
>
220 echo $this->ec_weeknrs
[$wcount-1];
225 for ($wdcount = 1; $wdcount <= 7; $wdcount++
) {
226 $working_day = $this->ec_calendar
[(($wcount * 7) - 7) +
($wdcount - 1)];
227 if (isset($working_day)) {
228 if (date("m", $working_day) < date("m", $this->ec_date
)) { ?
>
230 <td
class="othermonth">
231 <span
><?php
echo strftime("%b", $working_day) ?
></span
>
232 <?php
} elseif (date("m", $working_day) > date("m", $this->ec_date
)) { ?
>
234 <td
class="othermonth">
235 <span
><?php
echo strftime("%b", $working_day) ?
></span
>
239 foreach ($this->ec_events
as $day_event) {
240 // Calculate recursion
241 if ($this->calcRecursion($working_day, $day_event)) {
242 // Calculate exception days
243 $exceptions = $this->calcExceptions( $day_event );
244 if (array_search($working_day, $exceptions) === false) {
250 <td
class="<?php echo (strftime("%d
", $working_day) == strftime("%d
", time()))?'cur_':''; ?>day_event">
252 <a href
="<?php echo sefRelToAbs("index
.php?option
=com_eventcalendar
&task
=dayview
&year
=".$this->ec_year."&month
=".$this->ec_month."&day
=".strftime("%d
", $working_day)."&Itemid
=".$this->ec_comItemid, EVCALBASE."/all
/".$this->ec_year."/".$this->ec_month."/".strftime("%d
", $working_day).".html
") ?>">
254 echo (date("Y-m-d", $working_day) == strftime("Y-m-d", time()))?
'<b>':'';
255 echo strftime("%d", $working_day);
256 echo (date("Y-m-d", $working_day) == strftime("Y-m-d", time()))?
'</b>':'';
261 <td
class="<?php echo (strftime("%d
", $working_day) == strftime("%d
", time()))?'cur_':''; ?>day">
264 echo (date("Y-m-d", $working_day) == strftime("Y-m-d", time()))?
'<b>':'';
265 echo strftime("%d", $working_day);
266 echo (date("Y-m-d", $working_day) == strftime("Y-m-d", time()))?
'</b>':'';
277 // Forth-coming table
278 if ($this->ec_modParams
->get('view_forth') == '1') { ?
>
279 <tr
><td
class="spacer"></td
></tr
>
281 <td
class="subtitle" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
282 <h5
><?php
echo CX_EVCALMOD_FORTH_EVENTS
; ?
>:</h5
>
285 <td
class="forth_events" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
289 $working_day = strtotime( "+1 day", mktime(0, 0, 0, date("m"), date("d"), date("Y")) );
290 for ($i = 1; $i <= $this->ec_modParams
->get('view_forth_days'); $i++
) {
291 foreach ($this->ec_events
as $day_event) {
292 if ($forth_count <= $this->ec_modParams
->get('view_forth_num')) {
293 // Calculate recursion
294 if ($this->calcRecursion($working_day, $day_event)) {
295 // Calculate exception days
296 $exceptions = $this->calcExceptions( $day_event );
297 if (array_search($working_day, $exceptions) === false) {
298 // Prevent events been displayed more than once
299 if (array_search($day_event->id
, $displist) === false) { ?
>
300 <li
><a href
="<?php echo sefRelToAbs("index
.php?option
=com_eventcalendar
&task
=eventview
&eventid
=".$day_event->id."&Itemid
=".$this->ec_comItemid, EVCALBASE."/".$day_event->seotitle.".html
") ?>"><?php
echo $day_event->title
; ?
></a
></li
>
301 <?php
$forth_count++
;
302 $displist[] = $day_event->id
;
308 $working_day = strtotime("+1 day", $working_day);
310 if ($forth_count == 0) { ?
>
311 <p
><?php
echo CX_EVCALMOD_FORTH_NONE
; ?
></p
>
318 <?php
// Day info table
319 if ($this->ec_modParams
->get('view_info') == '1') {
320 require_once( $mosConfig_absolute_path.'/modules/mod_eventcalendar/sun/sun.php' );
321 require_once( $mosConfig_absolute_path.'/modules/mod_eventcalendar/sun/moon-phase.cls.php' );
322 if ( file_exists($mosConfig_absolute_path.'/modules/mod_eventcalendar/anniversaries/'.$lang.'.php') ) {
323 require_once( $mosConfig_absolute_path.'/modules/mod_eventcalendar/anniversaries/'.$lang.'.php' );
327 $objMoon = new moonPhase(-1);
328 $moon = round( $objMoon->getPeriodInDays() - $objMoon->getDaysUntilNextNewMoon(), 0);
329 $moon_name = $objMoon->getPhaseName();
331 if ( $moon_name == "New Moon" or $moon == 0 ) {
332 $moon_name = CX_EVCALMOD_INFO_NEWMOON
;
333 } elseif ( $moon_name == "First Quarter Moon" ) {
334 $moon_name = CX_EVCALMOD_INFO_FQMOON
;
335 } elseif ( $moon_name == "Full Moon" ) {
336 $moon_name = CX_EVCALMOD_INFO_FULLMOON
;
337 } elseif ( $moon_name == "Third Quarter Moon" ) {
338 $moon_name = CX_EVCALMOD_INFO_TQMOON
;
344 $moon_text = CX_EVCALMOD_INFO_MOONPRE
. ":<br/>" . $moon_name;
347 $moon_post = CX_EVCALMOD_INFO_MOONPOSTSING
;
349 $moon_post = CX_EVCALMOD_INFO_MOONPOSTPLUR
;
351 $moon_text = CX_EVCALMOD_INFO_MOONPRE
. "<br />" . $moon . " " . $moon_post;
354 <tr
><td
class="spacer"></td
></tr
>
356 <td
class="subtitle" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
357 <h5
><?php
echo CX_EVCALMOD_INFO_TODAY
.', '.$this->ec_year
.'/'.$this->ec_month
.'/'.$this->ec_day
; ?
></h5
>
360 <?php
if ($this->ec_modParams
->get('view_info_place')) { ?
>
362 <td
class="place" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
363 <?php
echo $this->ec_modParams
->get('view_info_place'); ?
>
368 <td
class="sun-moon" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
372 <?php
echo CX_EVCALMOD_INFO_SUNRISE
; ?
>: 
;<?php
echo date("H:i", sun
::rise($this->ec_date
, $this->ec_modParams
->get('view_info_timezone'), $this->ec_modParams
->get('view_info_latitude'), $this->ec_modParams
->get('view_info_longitude'), $this->ec_modParams
->get('view_info_zenith') )); ?
><br
/>
373 <?php
echo CX_EVCALMOD_INFO_SUNSET
; ?
>: 
;<?php
echo date("H:i", sun
::set($this->ec_date
, $this->ec_modParams
->get('view_info_timezone'), $this->ec_modParams
->get('view_info_latitude'), $this->ec_modParams
->get('view_info_longitude'), $this->ec_modParams
->get('view_info_zenith') )); ?
>
375 </td
><td
class="moon">
376 <p
><?php
echo $moon_text; ?
></p
>
382 <!-- Nameday table
-->
384 calcSpecialNamedays($this->ec_day
, $this->ec_month
, $namedays_long, $namedays_short, $moving_holidays); ?
>
385 <tr
><td
class="spacer"></td
></tr
>
386 <tr
><td
class="namedays" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
387 <p
><?php
echo $namedays_long[$this->ec_day
.'/'.$this->ec_month
] ?
><br
/><?php
echo isset($namedays_short[$this->ec_day
.'/'.$this->ec_month
]) ?
'('.$namedays_short[$this->ec_day
.'/'.$this->ec_month
].')' : '' ?
></p
>
390 <!-- Worldday table
-->
391 <tr
><td
class="spacer"></td
></tr
>
392 <tr
><td
class="worlddays" colspan
="<?php echo ($this->ec_modParams->get('show_weeknumber', true))?'8':'7'; ?>">
393 <p
><?php
echo getWorldday($this->ec_day
.'/'.$this->ec_month
, $worlddays); ?
></p
>
401 /********************/
402 /* Calculate events */
403 /********************/
404 protected function calcEvents() {
405 global $database, $my;
407 // Load events from database
408 $query = "SELECT e.id, e.start_date, e.end_date FROM #__eventcalendar e"
409 . "\n LEFT JOIN #__categories c ON c.id = e.catid"
410 . "\n WHERE e.published = '1' AND c.published = '1' AND c.access IN (".$my->allowed
.")"
411 . "\n ORDER BY e.start_date ASC";
412 $database->setQuery( $query );
413 $results = $database->loadObjectList();
416 foreach ($results as $row_event) {
417 if ( (strtotime($row_event->start_date
) <= $this->ec_calendar
[count($this->ec_calendar
)-1]) ||
(strtotime($row_event->end_date
) >= $this->ec_calendar
[0]) ) {
418 $load_event = new mosEventCalendar_Event($database);
419 $load_event->load($row_event->id
);
420 $this->ec_events
[] = clone( $load_event );
425 /************************/
426 /* Calculate exceptions */
427 /************************/
428 public function calcExceptions( $event ) {
429 $events = split("\n", $event->recur_except
);
430 for ($i = 0; $i <= (count($events)-1); $i++
) {
431 $events[$i] = strtotime($events[$i]);
436 /***********************/
437 /* Calculate recursion */
438 /***********************/
439 public function calcRecursion ( $date, $event ) {
441 // Check if date is in event publishing range
442 if ( ((strtotime(date("Y-m-d", strtotime($event->start_date
)))) <= $date) && ((strtotime(date("Y-m-d", strtotime($event->end_date
)))) >= $date) ) {
444 switch ($event->recur_type
) {
446 return ( date("w", $date) == $event->recur_week
);
449 return ( $event->recur_month
== date("j", $date) );
452 return ( ($event->recur_year_d
."/".$event->recur_year_m
) == date("j/n", $date) );
465 } // end if class_exists
468 $objEventCalendarMOD = new clsEventCalendarMOD($params, $database);
469 $objEventCalendarMOD->main();
470 unset($objEventCalendarMOD);