17 require_once SQ_FUDGE_PATH.
'/general/text.inc';
18 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
19 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
20 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
21 require_once SQ_PACKAGES_PATH.
'/calendar/calendar_event/calendar_event.inc';
22 require_once SQ_PACKAGES_PATH.
'/calendar/calendar_events/calendar_event_recurring/calendar_event_recurring.inc';
23 require_once SQ_PACKAGES_PATH.
'/calendar/lib/calendar_common.inc';
45 var $day_names = Array(
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday');
52 var $month_names_full = Array(1=>
'January', 2=>
'February', 3=>
'March', 4=>
'April', 5=>
'May', 6=>
'June', 7=>
'July', 8=>
'August', 9=>
'September', 10=>
'October', 11=>
'November', 12=>
'December');
59 var $month_names_short = Array(1=>
'Jan', 2=>
'Feb', 3=>
'Mar', 4=>
'Apr', 5=>
'May', 6=>
'June', 7=>
'July', 8=>
'Aug', 9=>
'Sept', 10=>
'Oct', 11=>
'Nov', 12=>
'Dec');
72 $this->_ser_attrs = TRUE;
73 parent::__construct($assetid);
88 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
89 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
92 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
93 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
97 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
98 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
116 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'major',
'page_contents',
'1',
'1');
117 $bodycopy_no_results_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'major',
'page_contents_no_results',
'1',
'1');
120 if (!$GLOBALS[
'SQ_PURGING_TRASH']) {
123 if ((!empty($bodycopy_link)) && ($bodycopy_link[0][
'linkid'] == $linkid)) {
124 return translate(
'cal_page_error_bodycopy_link_cannot_delete');
125 }
else if ((!empty($bodycopy_no_results_link) && ($bodycopy_no_results_link[0][
'linkid'] == $linkid))) {
126 return translate(
'cal_page_error_bodycopy_no_results_link_cannot_delete');
130 return parent::isDeletableLink($linkid);
158 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
159 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'folder');
162 $page_contents_data = Array(
'content' =>
'<h2 style="text-align: center">%calendar_title%</h2><p style="text-align: center">%prev_link% %up_link% %next_link%</p>%calendar_contents%');
164 $copy_link = Array(
'asset' => &$this,
'value' =>
'page_contents' ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
165 $asset->setAttrValue(
'name',
'Page Contents');
166 if (!$asset->create($copy_link, $page_contents_data)) {
170 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
174 $copy_link = Array(
'asset' => &$this,
'value' =>
'type_formats' ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
175 $type_formats =
new Folder();
176 $type_formats->setAttrValue(
'name',
'Type Formats');
177 if (!$type_formats->create($copy_link)) {
183 $copy_link = Array(
'asset' => &$type_formats,
'value' =>
'' ,
'link_type' => SQ_LINK_TYPE_2,
'is_dependant' => 1,
'is_exclusive' => 1);
184 $event_bodycopy_data = Array(
'content' =>
'%asset_contents%');
185 $event_types = Array(
'single',
'recurring');
186 foreach ($event_types as $event_type) {
187 $copy_link[
'value'] =
'calendar_event_'.$event_type;
189 $asset->setAttrValue(
'name', ucfirst($event_type).
' Event Format');
190 if (!$asset->create($copy_link, $event_bodycopy_data)) {
194 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
198 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($type_formats);
199 unset($type_formats);
201 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
218 $page_links = parent::_getAllowedLinks();
219 $page_links[SQ_LINK_TYPE_2][
'folder'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
220 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
221 $page_links[SQ_LINK_TYPE_2][
'bodycopy'] = Array(
'card' => 2,
'exclusive' => TRUE);
236 return parent::printFrontend();
249 if (!isset($this->_tmp[
'valid_request'])) {
250 $this->_tmp[
'valid_request'] = $this->_validateRequest();
252 if (!$this->_tmp[
'valid_request'])
return;
254 $view = $_REQUEST[
'SQ_CALENDAR_VIEW'];
255 $format = array_get_index($this->
attr(
'enabled_views'), $view,
'');
256 if (in_array($view, Array(
'day',
'week')) && ($format ==
'calendar_format')) {
257 $partition_time = intval($this->
attr(
'day_partition_time'));
258 $partition_height = $this->
attr(
'day_partition_height');
259 $root_nodes = $this->
attr(
'root_nodes');
260 $width = ($view ==
'day') ? $this->
attr(
'day_column_width') : $this->
attr(
'table_column_width');
261 $click_to_add_ab = $this->
attr(
'asset_builder_page');
263 <style
type=
"text/css">
264 table#day tr td.sq-time-cell, table#week tr td.sq-time-cell {
265 width: <?php echo $width; ?>px;
266 height: <?php echo $partition_height; ?>px;
273 html>body table#day tr td.sq-time-cell, html>body table#week tr td.sq-time-cell {
274 height: <?php echo $partition_height+1; ?>px;
277 if ($click_to_add_ab) {
279 table#day tr td.sq-time-cell, table#week tr td.sq-time-cell, td.sq-allday-cell {
290 <link rel=
"stylesheet" type=
"text/css" href=
"<?php echo sq_web_path('data'); ?>/asset_types/page_calendar/css/calendar_default.css" />
305 $GLOBALS[
'SQ_SYSTEM']->pm->startTimer($this);
307 $root_node_ids = array_keys($this->
attr(
'root_nodes'));
309 $action = array_get_index($_REQUEST,
'SQ_CALENDAR_EVENT_ACTION',FALSE);
310 $event_id = array_get_index($_REQUEST,
'SQ_CALENDAR_EVENT_ID',FALSE);
313 $event_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset((
int)$_REQUEST[
'SQ_CALENDAR_EVENT_ID']);
314 if (!$event_asset->readAccess())
return;
318 if ($event_asset->readAccess()) {
319 $res = $event_asset->processEventAction($action);
322 $this->_tmp[
'valid_request'] = FALSE;
328 if (!isset($this->_tmp[
'valid_request'])) {
329 $this->_tmp[
'valid_request'] = $this->_validateRequest();
331 if (!$this->_tmp[
'valid_request'])
return;
334 $cache_key = $this->_getCacheKey();
335 $cached_contents = FALSE;
336 if (!empty($cache_key)) {
337 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
338 $cached_contents = $cm->loadFromCache($this->
id, $this->
type(), $cache_key);
340 if ($cached_contents !== FALSE) {
341 echo $cached_contents;
347 $replacements = Array();
354 $events_array = Array();
357 $calendar_date = $_REQUEST[
'SQ_CALENDAR_DATE'];
358 $cal_view = $_REQUEST[
'SQ_CALENDAR_VIEW'];
359 $replacements[
'calendar_contents'] = $this->getCalendarContents($events_array);
360 $_REQUEST[
'SQ_CALENDAR_DATE'] = $calendar_date;
362 $replacements[
'calendar_title'] = $this->getCalendarTitle();
363 $replacements[
'current_user'] = $GLOBALS[
'SQ_SYSTEM']->user->name;
365 $replacements += $this->_getNavLinkReplacements();
369 $contents_bodycopy =
'';
372 $nb_events = count($events_array);
374 if ($cal_view ==
'event') $event_view = TRUE;
375 if ($cal_view ==
'edit') $event_view = TRUE;
378 $use_no_results_body_copy = $this->
attr(
'use_no_results_body_copy');
380 if ( (!empty($use_no_results_body_copy)) && (($nb_events == 0) && !($event_view))) {
381 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'page_contents_no_results');
382 if (empty($bodycopy_link))
return FALSE;
383 $contents_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
385 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE,
'page_contents');
386 if (empty($bodycopy_link))
return FALSE;
387 $contents_bodycopy = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($bodycopy_link[
'minorid'], $bodycopy_link[
'minor_type_code']);
390 if (is_null($contents_bodycopy))
return FALSE;
395 echo
'<script type="text/javascript">if (typeof cal != "undefined") cal.setDate(\''.$_REQUEST[
'SQ_CALENDAR_DATE'].
'\')</script>
';
396 // print the contents of page - replacing the global keywords
397 $calendar_replacements = $replacements;
398 $keywords = $contents_bodycopy->getKeywords();
399 foreach ($keywords as $word) {
400 if (isset($calendar_replacements[$word]) && !empty($calendar_replacements[$word])) {
401 $replacements[$word] = $calendar_replacements[$word];
403 $replacements[$word] = $this->getKeywordReplacement($word);
406 $contents_bodycopy->setKeywordReplacements($replacements);
407 $contents_bodycopy->printBody();
408 if (!empty($cache_key)) {
409 $cm->saveToCache($this->id, $this->type(), $cache_key, ob_get_contents());
413 $GLOBALS['SQ_SYSTEM
']->am->forgetAsset($contents_bodycopy);
418 // stop performance mode timer
419 $GLOBALS['SQ_SYSTEM
']->pm->stopTimer($this);
437 function getKeywordReplacement($keyword)
439 $prefix = $this->getPrefix();
441 // No keywords here, just go and get the global keywords
442 return parent::getKeywordReplacement($keyword);
444 }//end getKeywordReplacement()
455 function _validateRequest()
458 // If we get a valid and available view type in the request, use it;
459 // otherwise use the initial view attribute.
460 $enabled_views = $this->attr('enabled_views
');
461 $enabled_views['edit
'] = 1;
462 $cal_view = array_get_index($_REQUEST, 'SQ_CALENDAR_VIEW
', FALSE);
463 if (!$cal_view || empty($enabled_views[$cal_view])) {
464 $cal_view = $this->attr('initial_view
');
468 // If no date supplied, use today's
470 $cal_date = array_get_index($_REQUEST,
'SQ_CALENDAR_DATE', date(
'Y-m-d'));
471 if (!is_iso8601($cal_date)) {
472 if (($cal_view ==
'month') && (strlen($cal_date) >= 7)) {
473 list($year, $month) = sscanf($cal_date,
'%04d-%02d');
474 $cal_date = sprintf(
'%04d-%02d-%02d', $year, $month, 1);
475 }
else if (($cal_view ==
'year') && (strlen($cal_date) >= 4)) {
477 list($year) = sscanf($cal_date,
'%04d');
478 $cal_date = sprintf(
'%04d-%02d-%02d', $year, 1, 1);
481 $cal_date = date(
'Y-m-d');
485 if ($cal_view ==
'week') {
486 $week_start_day = $this->day_names[$this->
attr(
'week_starts_on')];
487 if (date(
'l',strtotime($cal_date)) != $week_start_day) {
488 $cal_date = date(
'Y-m-d', strtotime(
'last '.$week_start_day, strtotime($cal_date)));
492 list($year, $month, $day) = explode(
'-', $cal_date);
493 if (!checkdate($month, $day, $year)) {
494 trigger_localised_error(
'CAL0022', E_USER_WARNING, $cal_date);
495 $cal_date = date(
'Y-m-d');
500 if (($cal_view ==
'event') || ($cal_view ==
'edit')) {
501 if (!isset($_REQUEST[
'SQ_CALENDAR_EVENT_ID'])) {
502 trigger_localised_error(
'CAL0023', E_USER_WARNING, ucfirst($cal_view));
505 if (!assert_valid_assetid($_REQUEST[
'SQ_CALENDAR_EVENT_ID'])) {
511 $_REQUEST[
'SQ_CALENDAR_VIEW'] = $cal_view;
512 $_REQUEST[
'SQ_CALENDAR_DATE'] = $cal_date;
524 function _getCacheKey()
527 $contextid = $GLOBALS[
'SQ_SYSTEM']->getContextId();
529 if (!isset($this->_tmp[
'valid_request'])) {
530 $this->_tmp[
'valid_request'] = $this->_validateRequest();
533 if ($this->_tmp[
'valid_request']) {
536 list($year, $month, $day) = explode(
'-', $_REQUEST[
'SQ_CALENDAR_DATE']);
537 switch ($_REQUEST[
'SQ_CALENDAR_VIEW']) {
539 $cache_key =
'Y'.$year;
541 $cache_key = sprintf(
'M%04d-%02d', $year, $month);
543 $cache_key = sprintf(
'W%04d-%02d-%02d', $year, $month, $day);
545 $cache_key = sprintf(
'D%04d-%02d-%02d', $year, $month, $day);
551 if ($cache_key !==
'') {
552 $cache_key .=
'-ctx'.$contextid;
567 function _getNavLinkReplacements()
569 $replacements = Array();
570 $cal_view = $_REQUEST[
'SQ_CALENDAR_VIEW'];
571 $cal_date = $_REQUEST[
'SQ_CALENDAR_DATE'];
573 $event_id = array_get_index($_REQUEST,
'SQ_CALENDAR_EVENT_ID', FALSE);
577 if ($cal_view ==
'month') {
578 $date_format =
'Y-m-01';
580 $date_format =
'Y-m-d';
583 $prev_date = date($date_format, strtotime(
'-1 '.$cal_view, strtotime(date($date_format, strtotime($cal_date)))));
584 $next_date = date($date_format, strtotime(
'+1 '.$cal_view, strtotime(date($date_format, strtotime($cal_date)))));
586 list ($forward_limit,$forward_date) = $this->formatDatesToCompare($cal_view,$next_date,
'forward',
'+');
587 list ($backward_limit,$backward_date) = $this->formatDatesToCompare($cal_view,$prev_date,
'backward',
'-');
589 if ($forward_limit ==
'' || $forward_limit >= $forward_date) {
590 $replacements[
'next_link'] = ($cal_view ==
'event') ?
'' :
'<a class="calendarNavLink" href="'.$this->
getURL().
'?SQ_CALENDAR_VIEW='.$cal_view.
'&SQ_CALENDAR_DATE='.$next_date.
'" rel="nofollow">'.(str_replace(
'%v%', ucfirst($cal_view), htmlentities($this->
attr(
'next_link_text')))).
'</a>';
592 $replacements[
'next_link'] =
'';
594 if ($backward_limit ==
'' || $backward_date >= $backward_limit) {
595 $replacements[
'prev_link'] = ($cal_view ==
'event') ?
'' :
'<a class="calendarNavLink" href="'.$this->
getURL().
'?SQ_CALENDAR_VIEW='.$cal_view.
'&SQ_CALENDAR_DATE='.$prev_date.
'" rel="nofollow">'.(str_replace(
'%v%', ucfirst($cal_view), htmlentities($this->
attr(
'prev_link_text')))).
'</a>';
597 $replacements[
'prev_link'] =
'';
599 if ($backward_date > $forward_limit || $forward_date < $backward_limit) {
600 $replacements[
'prev_link'] =
'';
601 $replacements[
'next_link'] =
'';
604 $enabled_views = $this->
attr(
'enabled_views');
605 $replacements[
'today_link'] = ($cal_view ==
'event') ?
'' :
'<a class="calendarNavLink calendarTodayLink" href="'.$this->
getURL().
'?SQ_CALENDAR_VIEW='.$cal_view.
'" rel="nofollow">'.htmlentities($this->
attr(
'today_link_text')).
'</a>';
607 if ($cal_view ==
'week') {
608 $cal_date = date(
'Y-m-01', iso8601_ts($cal_date));
612 foreach ($enabled_views as $view => $type) {
613 if ($view == $cal_view)
break;
614 if ($type) $up_view = $view;
619 if ($up_view ==
'event' && !empty($event_id)) {
620 $eventview =
'&SQ_CALENDAR_EVENT_ID='.$event_id;
623 $replacements[
'up_link'] = $up_view ?
'<a class="calendarNavLink" href="'.$this->getHref().
'?SQ_CALENDAR_VIEW='.$up_view.$eventview.
'&SQ_CALENDAR_DATE='.$cal_date.
'" rel="nofollow">'.str_replace(
'%v%', ucfirst($up_view), $this->
attr(
'up_link_text')).
'</a>' :
'';
625 return $replacements;
642 if (!isset($vars[
'keywords']))
return;
643 if (empty($vars[
'keywords'])) {
644 parent::onRequestKeywords($broadcaster, $vars);
646 $bc_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($broadcaster->id,
'bodycopy', FALSE);
647 if (empty($bc_parents))
return;
649 $tf_folder_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'type_formats');
650 $tf_bc_link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkByAsset($tf_folder_link[
'minorid'], key($bc_parents), SQ_SC_LINK_ALL);
651 if (empty($tf_bc_link)) {
653 $vars[
'keywords'] = array_merge($vars[
'keywords'], $this->_getContentsKeywords());
656 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($tf_bc_link[
'value']);
657 $dummy =
new $tf_bc_link[
'value']();
658 $vars[
'keywords'] = array_merge($vars[
'keywords'], $dummy->getAvailableKeywords());
677 function _getContentsKeywords()
680 'calendar_contents' => translate(
'cal_page_calendar_contents'),
681 'calendar_title' => translate(
'cal_page_calendar_title'),
682 'up_link' => translate(
'cal_page_up_link'),
683 'prev_link' => translate(
'cal_page_prev_link'),
684 'next_link' => translate(
'cal_page_next_link'),
685 'current_user' => translate(
'cal_page_current_user'),
686 'today_link' => translate(
'cal_page_today_link'),
700 function getViewOptions()
704 '' => translate(
'cal_no_display'),
705 'list_without_headings' => translate(
'cal_list_without_headings'),
706 'list_with_headings' => translate(
'cal_list_with_month_headings'),
707 'calendar_format' => translate(
'cal_calendar_format'),
710 '' => translate(
'cal_no_display'),
711 'list_without_headings' => translate(
'cal_list_without_headings'),
712 'list_with_headings' => translate(
'cal_list_with_day_headings'),
713 'calendar_format' => translate(
'cal_calendar_format'),
716 '' => translate(
'cal_no_display'),
717 'list_without_headings' => translate(
'cal_list_without_headings'),
718 'list_with_headings' => translate(
'cal_list_with_day_headings'),
719 'calendar_format' => translate(
'cal_calendar_format'),
722 '' => translate(
'cal_no_display'),
723 'list_without_headings' => translate(
'cal_list_without_headings'),
724 'calendar_format' => translate(
'cal_calendar_format'),
727 '' => translate(
'cal_no_display'),
728 'single_event_view' => translate(
'cal_show_single_event_view'),
729 'event_itself' => translate(
'cal_show_single_event_itself'),
747 function getCalendarTitle()
749 $title_formats = $this->
attr(
'view_title_formats');
750 $title_formats[
'edit'] = translate(
'cal_page_edit_event');
751 $view = $_REQUEST[
'SQ_CALENDAR_VIEW'];
752 if (($view ==
'event') || ($view ==
'edit')) {
754 $info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($_REQUEST[
'SQ_CALENDAR_EVENT_ID']));
755 return $info[$_REQUEST[
'SQ_CALENDAR_EVENT_ID']][
'name'];
757 return date($title_formats[$view], strtotime($_REQUEST[
'SQ_CALENDAR_DATE']));
772 function getCalendarContents(&$events_array)
774 $cal_view = $_REQUEST[
'SQ_CALENDAR_VIEW'];
775 $formats = $this->
attr(
'enabled_views');
776 $format = array_get_index($formats, $cal_view,
'');
777 $res = $this->_getGeneralScript();
778 if (strpos($format,
'list') === FALSE) {
779 $res .=
'<div id="calendarTable">';
781 $func =
'get'.ucfirst($cal_view).
'View';
782 $res .= (($cal_view ==
'event') || ($cal_view ==
'edit')) ? $this->$func($_REQUEST[
'SQ_CALENDAR_EVENT_ID']) : $this->$func($_REQUEST[
'SQ_CALENDAR_DATE'], $format, $events_array);
783 if (strpos($format,
'list') === FALSE) {
801 function getYearView($date, $format, &$events_array)
804 list($year, $month, $day) = explode(
'-', $date);
805 $enabled_views = $this->
attr(
'enabled_views');
807 if ($format ==
'list_without_headings') {
808 $list_entry_types = $this->
attr(
'list_entry_types');
809 $events = $this->getYearEvents($year);
810 $events_array = $events;
811 uasort($events, Array(
'Calendar_Common',
'compareStartDates'));
812 if ($list_entry_types[
'year'] ==
'title') {
813 echo $this->_getTitleList($events);
815 $this->_printEventList($events);
817 }
else if ($format ==
'list_with_headings') {
818 $list_entry_types = $this->
attr(
'list_entry_types');
820 $events = $this->getYearEventsByMonth($year);
823 foreach ($events as $month => $month_events) {
824 $events_array = array_merge($events_array, $month_events);
827 foreach ($this->month_names_full as $month_num => $month_name) {
828 $_REQUEST[
'SQ_CALENDAR_DATE']= $year.
'-'.sprintf(
'%02d', $month_num).
'-01';
829 uasort($events[$month_num], Array(
'Calendar_Common',
'compareStartDates'));
831 if ($enabled_views[
'month']) {
832 echo
'<a href="'.$this->getHref().
'?SQ_CALENDAR_VIEW=month&SQ_CALENDAR_DATE='.$year.
'-'.sprintf(
'%02d', $month_num).
'-01">';
835 if ($enabled_views[
'month']) echo
'</a>';
838 if ($list_entry_types[
'year'] ==
'title') {
839 echo $this->_getTitleList($events[$month_num], $enabled_views[
'event']);
841 $this->_printEventList($events[$month_num]);
845 $events = $this->getYearEventsByMonthAndDay($year);
848 foreach ($events as $month => $month_array) {
849 foreach ($month_array as $day => $day_events) {
850 $events_array = array_merge($events_array, $day_events);
854 $week_start_day = $this->
attr(
'week_starts_on');
855 $today_iso = date(
'Y-m-d');
859 <th
class=
"dayLabel" style=
"width: 6ex"> </th>
861 for ($i = $week_start_day; $i < $week_start_day + 37; $i++) {
862 $day = strtolower(substr($this->day_names[$i % 7], 0, 3));
863 $label = $this->
attr(
'label_'.$day);
865 <th
class=
"dayLabel<?php echo (($i%7)==0 || ($i%7)==6) ? ' dayLabelWeekend' : ''; ?>" style=
"width: 3.5ex"><b><?php echo substr($label, 0, 1); ?></b></th>
871 for ($current_month=1; $current_month<13; $current_month++) {
874 <th
class=
"monthLabel">
877 if ($enabled_views[
'month']) {
878 echo
'<a href="'.$this->getHref().
'?SQ_CALENDAR_VIEW=month&SQ_CALENDAR_DATE='.$year.
'-'.sprintf(
'%02d', $current_month).
'-01">';
880 echo $this->month_names_short[$current_month];
881 if ($enabled_views[
'month']) echo
'</a>';
888 $blank_days = (date(
'w', strtotime(
"$year-".sprintf(
'%02d', $current_month).
'-01')) + 7 - $week_start_day) % 7;
889 for ($i = 0; $i < $blank_days; $i++) {
891 <td
class=
"<?php echo (((($week_start_day + $i) % 7)==0) || ((($week_start_day + $i) % 7)==6)) ? ' weekend' : ''; ?> "> </td>
896 for ($current_day = 1; $current_day <= days_in_month($current_month, $year); $current_day++) {
898 $tag_attrs = Array();
899 $classes = Array(
'date');
900 if (sprintf(
'%04d-%02d-%02d', $year, $current_month, $current_day) == $today_iso) {
901 $classes[] =
'today';
903 if (in_array(date(
'D', strtotime(
"$year-$current_month-$current_day")), Array(
'Sat',
'Sun'))) {
904 $classes[] =
'weekend';
906 if (!empty($events[$current_month][$current_day])) {
907 $classes[] =
'eventDate';
909 $tag_attrs[] =
'class="'.implode(
' ', $classes).
'"';
910 $day_href = $this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.sprintf(
'%04d-%02d-%02d', $year, $current_month, $current_day);
911 echo
'<td '.implode(
' ', $tag_attrs).
'>';
912 echo
'<a href="'.$day_href.
'">'.$current_day.
'</a>';
920 <td
class=
"<?php echo (((($week_start_day + $i) % 7)==0) || ((($week_start_day + $i) % 7)==6)) ? ' weekend' : ''; ?>"> </td>
932 $res = ob_get_contents();
949 function getMonthView($date, $format, &$events_array)
951 $popups_enabled = $this->
attr(
'enable_description_popups');
952 if ($popups_enabled) $this->_printPopupsScript();
953 list($year, $month, $day) = explode(
'-', $date);
954 $enabled_views = $this->
attr(
'enabled_views');
955 $drill_down_views = Array(
'week',
'day');
956 $drill_down_view = current($drill_down_views);
957 while (empty($enabled_views[$drill_down_view]) && ($drill_down_view !== FALSE)) {
958 $drill_down_view = next($drill_down_views);
962 if ($format ==
'list_without_headings') {
963 $list_entry_types = $this->
attr(
'list_entry_types');
964 $raw_events = $this->getMonthEvents($year, $month);
965 $events_array = $raw_events;
966 $this->_initEventLabels(
'month', $raw_events);
967 $events = $this->groupMonthEventsByDay($raw_events, $year, $month);
968 $month_length = days_in_month($month, $year);
969 $done_events = Array();
973 for ($current_day = 1; $current_day <= $month_length; $current_day++) {
974 uasort($events[$current_day], Array(
'Calendar_Common',
'compareStartDates'));
975 $current_date = sprintf(
'%04s-%02s-%02s', $year, $month, $current_day);
976 $_REQUEST[
'SQ_CALENDAR_DATE'] = $current_date;
977 foreach ($events[$current_day] as $event_id => $event_data) {
978 list($event_assetid, ) = explode(
':', $event_id);
979 if (!isset($done_events[$event_assetid])) {
980 $done_events[$event_assetid] = 1;
982 unset($events[$current_day][$event_id]);
985 if ($list_entry_types[
'month'] ==
'title') {
986 echo $this->_getTitleList($events[$current_day], $enabled_views[
'event']);
988 $this->_printEventList($events[$current_day]);
991 }
else if ($format ==
'list_with_headings') {
993 $drill_down_view = $enabled_views[
'day'] ?
'day' :
'';
995 $list_entry_types = $this->
attr(
'list_entry_types');
996 $raw_events = $this->getMonthEvents($year, $month);
997 $events_array = $raw_events;
998 $this->_initEventLabels(
'month', $raw_events);
999 $events = $this->groupMonthEventsByDay($raw_events, $year, $month);
1000 $month_length = days_in_month($month, $year);
1001 $day_heading_format =
'l jS';
1002 $heading_formats = $this->
attr(
'view_heading_formats');
1003 if (isset($heading_formats[
'month_day']) && !empty($heading_formats[
'month_day'])) {
1004 $day_heading_format = $heading_formats[
'month_day'];
1006 for ($current_day = 1; $current_day <= $month_length; $current_day++) {
1007 uasort($events[$current_day], Array(
'Calendar_Common',
'compareStartDates'));
1009 if ($drill_down_view) {
1010 echo
'<a href="'.$this->getHref().
'?SQ_CALENDAR_VIEW='.$drill_down_view.
'&SQ_CALENDAR_DATE='.$year.
'-'.$month.
'-'.sprintf(
'%02d', $current_day).
'">';
1012 $current_date = sprintf(
'%04s-%02s-%02s', $year, $month, $current_day);
1013 $_REQUEST[
'SQ_CALENDAR_DATE'] = $current_date;
1014 echo date($day_heading_format, strtotime($current_date));
1015 if ($drill_down_view) echo
'</a>';
1017 if ($list_entry_types[
'month'] ==
'title') {
1018 echo $this->_getTitleList($events[$current_day], $enabled_views[
'event']);
1020 $this->_printEventList($events[$current_day]);
1024 $raw_events = $this->getMonthEvents($year, $month);
1025 $events_array = $raw_events;
1026 $this->_initEventLabels(
'month', $raw_events);
1027 $events = $this->groupMonthEventsByDay($raw_events, $year, $month);
1028 $column_width = $this->
attr(
'month_column_width');
1029 $row_height = $this->
attr(
'month_row_height');
1030 $week_start_day = $this->
attr(
'week_starts_on');
1032 $month_length = days_in_month($month, $year);
1034 $current_date = $_REQUEST[
'SQ_CALENDAR_DATE'];
1035 $current_day_name = date(
'l',iso8601_ts($current_date));
1036 $today_iso = date(
'Y-m-d');
1038 <table
id=
"month" style=
"width: <?php echo (7.35 * $column_width); ?>px">
1042 if ($this->
attr(
'month_links_to_week')) {
1043 echo
'<th class="dayLabel"> </th>';
1045 for ($i=0; $i < $week_length; $i++) {
1046 $day_name = $this->day_names[($week_start_day + $i) % 7];
1047 $day = substr(strtolower($day_name), 0, 3);
1048 $day_label = $this->
attr(
'label_'.$day);
1050 <th style=
"width: <?php echo $column_width; ?>px" class=
"dayLabel<?php echo (($day_name == 'Saturday') || ($day_name == 'Sunday')) ? 'Weekend' : ''; ?>">
1051 <?php echo $day_label; ?>
1060 if ($this->
attr(
'month_links_to_week')) {
1062 $day_in_seconds = 24 * 60 * 60;
1063 $first_week_link_date = $current_date;
1064 $week_start_index = $this->
attr(
'week_starts_on');
1065 $curr_day_index = array_search(date(
'l', iso8601_ts($current_date)), $this->day_names);
1066 if ($week_start_index != $curr_day_index) {
1067 if ($week_start_index < $curr_day_index) {
1068 $offset = $curr_day_index - $week_start_index;
1070 $offset = $curr_day_index + (7 - $week_start_index);
1073 $first_week_link_date = iso8601_date_component(ts_iso8601(iso8601_ts($current_date) - ($offset * $day_in_seconds)));
1075 <th
class=
"weekLink" onclick=
"clickChild(this)"><a
class=
"dateLink" href=
"<?php echo $this->getHref().'?SQ_CALENDAR_VIEW=week&SQ_CALENDAR_DATE='.$first_week_link_date ?>">»</a></th>
1081 $blank_days = (date(
'w', strtotime(
"$year-".sprintf(
'%02d', $month).
'-01')) + 7 - $week_start_day) % 7;
1082 for ($i = 0; $i < $blank_days; $i++) {
1084 <td
class=
"<?php echo (((($week_start_day + $i) % 7)==0) || ((($week_start_day + $i) % 7)==6)) ? 'weekend' : ''; ?>"> </td>
1089 for (; $i < $week_length; $i++) {
1090 $tag_attrs = Array();
1091 $current_date = sprintf(
'%04d-%02d-%02d', $year, $month, $current_day);
1092 $_REQUEST[
'SQ_CALENDAR_DATE'] = $current_date;
1093 $contents = $this->_getMonthCellContents($events[$current_day], $current_date, $column_width*0.99);
1094 $classes = Array(
'date');
1095 if ($current_date == $today_iso) $classes[] =
'today';
1096 if ($contents) $classes[] =
'eventDate';
1097 if (in_array(date(
'D', strtotime(
"$year-$month-$current_day")), Array(
'Sat',
'Sun'))) {
1098 $classes[] =
'weekend';
1100 $tag_attrs[] =
'class="'.implode(
' ', $classes).
'"';
1101 $tag_attrs[] =
'style="height: '.$row_height.
'px"';
1102 $date_url = $this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.$current_date;
1104 <td <?php echo implode(' ', $tag_attrs); ?>>
1105 <a
class=
"dateLink" href=
"<?php echo $date_url; ?>"><?php echo $current_day; ?></a>
1107 <?php echo $contents; ?>
1117 $num_full_weeks = floor(($month_length - $current_day) / 7);
1118 for ($w = 0; $w < $num_full_weeks; $w++) {
1122 if ($this->
attr(
'month_links_to_week')) {
1124 <th
class=
"weekLink" onclick=
"clickChild(this)"><a
class=
"dateLink" href=
"<?php echo $this->getHref().'?SQ_CALENDAR_VIEW=week&SQ_CALENDAR_DATE='.add_days_to_iso($current_date) ?>">»</a></th>
1127 for ($i=0; $i < $week_length; $i++) {
1128 $tag_attrs = Array();
1129 $current_date = sprintf(
'%04d-%02d-%02d', $year, $month, $current_day);
1130 $_REQUEST[
'SQ_CALENDAR_DATE'] = $current_date;
1131 $contents = $this->_getMonthCellContents($events[$current_day], $current_date, $column_width*0.99);
1132 $classes = Array(
'date');
1133 if ($current_date == date(
'Y-m-d')) {
1134 $classes[] =
'today';
1136 if ($contents) $classes[] =
'eventDate';
1137 if (in_array(date(
'D', strtotime(
"$year-$month-$current_day")), Array(
'Sat',
'Sun'))) {
1138 $classes[] =
'weekend';
1140 $tag_attrs[] =
'class="'.implode(
' ', $classes).
'"';
1141 $tag_attrs[] =
'style="height: '.$row_height.
'px"';
1142 $date_url = $this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.$current_date;
1144 <td <?php echo implode(' ', $tag_attrs); ?>>
1145 <a
class=
"dateLink" href=
"<?php echo $date_url; ?>"><?php echo $current_day; ?></a>
1147 <?php echo $contents; ?>
1156 $current_date = sprintf(
'%04d-%02d-%02d', $year, $month, $current_day);
1159 if ($current_day <= $month_length) {
1164 if ($this->
attr(
'month_links_to_week')) {
1166 <th
class=
"weekLink" onclick=
"clickChild(this)"><a
class=
"dateLink" href=
"<?php echo $this->getHref().'?SQ_CALENDAR_VIEW=week&SQ_CALENDAR_DATE='.$current_date ?>">»</a></th>
1169 while ($current_day <= $month_length) {
1170 $tag_attrs = Array();
1171 $current_date = sprintf(
'%04d-%02d-%02d', $year, $month, $current_day);
1172 $_REQUEST[
'SQ_CALENDAR_DATE'] = $current_date;
1173 $contents = $this->_getMonthCellContents($events[$current_day], $current_date, $column_width*0.99);
1174 $classes = Array(
'date');
1175 if ($current_date == date(
'Y-m-d')) {
1176 $classes[] =
'today';
1178 if ($contents) $classes[] =
'eventDate';
1179 if (in_array(date(
'D', strtotime(
"$year-$month-$current_day")), Array(
'Sat',
'Sun'))) {
1180 $classes[] =
'weekend';
1182 $tag_attrs[] =
'class="'.implode(
' ', $classes).
'"';
1183 $tag_attrs[] =
'style="height: '.$row_height.
'px"';
1184 $date_url = $this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.$current_date;
1186 <td <?php echo implode(' ', $tag_attrs); ?>>
1187 <a
class=
"dateLink" href=
"<?php echo $date_url; ?>"><?php echo $current_day; ?></a>
1189 <?php echo $contents; ?>
1197 while ($i < $week_length) {
1199 <td
class=
"<?php echo (((($week_start_day + $i) % 7)==0) || ((($week_start_day + $i) % 7)==6)) ? ' weekend' : ''; ?>"> </td>
1213 $res = ob_get_contents();
1230 function getWeekView($date, $format, &$events_array)
1233 $root_nodes = $this->
attr(
'root_nodes');
1234 $enabled_views = $this->
attr(
'enabled_views');
1235 if ($format ==
'list_without_headings') {
1236 $list_entry_types = $this->
attr(
'list_entry_types');
1237 $raw_events = $this->getWeekEvents($date);
1238 $events_array = $raw_events;
1239 $this->_initEventLabels(
'week', $raw_events);
1240 $events = $this->groupWeekEventsByDay($raw_events, $date);
1241 $done_events = Array();
1245 foreach ($events as $day_date => $day_events) {
1246 $_REQUEST[
'SQ_CALENDAR_DATE'] = $day_date;
1247 uasort($events[$day_date], Array(
'Calendar_Common',
'compareStartDates'));
1249 foreach ($events[$day_date] as $event_id => $event_data) {
1250 list($event_assetid, ) = explode(
':', $event_id);
1251 if (!isset($done_events[$event_assetid])) {
1252 $done_events[$event_assetid] = 1;
1254 unset($events[$day_date][$event_id]);
1258 if ($list_entry_types[
'week'] ==
'title') {
1259 echo $this->_getTitleList($events[$day_date], $enabled_views[
'event']);
1261 $this->_printEventList($events[$day_date]);
1265 }
else if ($format ==
'list_with_headings') {
1266 $list_entry_types = $this->
attr(
'list_entry_types');
1267 $raw_events = $this->getWeekEvents($date);
1268 $events_array = $raw_events;
1269 $this->_initEventLabels(
'week', $raw_events);
1270 $events = $this->groupWeekEventsByDay($raw_events, $date);
1271 $day_heading_format =
'l jS';
1272 $heading_formats = $this->
attr(
'view_heading_formats');
1273 if (isset($heading_formats[
'week_day']) && !empty($heading_formats[
'week_day'])) {
1274 $day_heading_format = $heading_formats[
'week_day'];
1276 foreach ($events as $day_date => $day_events) {
1277 $_REQUEST[
'SQ_CALENDAR_DATE'] = $day_date;
1278 uasort($events[$day_date], Array(
'Calendar_Common',
'compareStartDates'));
1279 echo
'<h3>'.(($enabled_views[
'day']) ?
'<a href="'.$this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.$day_date.
'">' :
'');
1280 echo date($day_heading_format, strtotime($day_date));
1281 echo (($enabled_views[
'day']) ?
'</a>' :
'').
'</h3>';
1282 if ($list_entry_types[
'week'] ==
'title') {
1283 echo $this->_getTitleList($events[$day_date], $enabled_views[
'event']);
1285 $this->_printEventList($events[$day_date]);
1289 $raw_events = $this->getWeekEvents($date);
1290 $events_array = $raw_events;
1291 $this->_initEventLabels(
'week', $raw_events);
1292 $events = $this->groupWeekEventsByDayAndTime($raw_events, $date);
1293 $column_names = Array();
1294 $column_links = Array();
1295 foreach ($events as $day_date => $day_events) {
1296 $_REQUEST[
'SQ_CALENDAR_DATE'] = $day_date;
1297 $date = date(
'l', strtotime($day_date));
1298 $day = strtolower(substr($date, 0, 3));
1299 $label = $this->
attr(
'label_'.$day);
1300 $column_names[$day_date] = $label.
' '.date(
'jS', strtotime($day_date));
1301 if ($enabled_views[
'week']) {
1302 $column_links[$day_date] = $this->
getHref().
'?SQ_CALENDAR_VIEW=day&SQ_CALENDAR_DATE='.$day_date;
1305 $this->_printTimedTable(
'week', $column_names, $column_links, $events, $enabled_views[
'event']);
1307 $res = ob_get_contents();
1324 function getDayView($date, $format, &$events_array)
1327 if (strpos($format,
'list') === 0) {
1328 $list_entry_types = $this->
attr(
'list_entry_types');
1329 $enabled_views = $this->
attr(
'enabled_views');
1330 $events = $this->getDayEvents($date);
1331 $events_array = $events;
1332 $this->_initEventLabels(
'day', $events);
1333 if ($list_entry_types[
'day'] ==
'title') {
1334 echo $this->_getTitleList($events, $enabled_views[
'event']);
1336 $this->_printEventList($events);
1339 $column_names = Array();
1340 $column_links = Array();
1341 $column_ids = $this->
attr(
'columnise_day_view_by_root_node');
1342 if (array_values($column_ids) != Array(
'*')) {
1343 $root_nodes = array_keys($this->
attr(
'root_nodes'));
1344 $column_names_raw = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($column_ids, Array(), TRUE,
'name');
1345 foreach ($column_ids as $column_id) {
1346 if (in_array($column_id, $root_nodes)) {
1347 $column_names[$column_id] = $column_names_raw[$column_id];
1351 if (in_array(
'*', $column_ids)) {
1352 $column_names[
'*'] = ($this->
attr(
'other_column_name') ==
'') ? translate(
'other') : $this->
attr(
'other_column_name');
1354 $raw_events = $this->getDayEvents($date);
1355 $events_array = $raw_events;
1356 $this->_initEventLabels(
'day', $raw_events);
1357 $events = $this->groupDayEventsByRootNodeAndTime($raw_events);
1359 $column_names[
'*'] = ($this->
attr(
'other_column_name') ==
'') ? translate(
'events') : $this->
attr(
'other_column_name');
1360 $raw_events = $this->getDayEvents($date);
1361 $events_array = $raw_events;
1362 $this->_initEventLabels(
'day', $raw_events);
1363 $events = Array(
'*' => $this->groupDayEventsByTime($raw_events, $date));
1365 $enabled_views = $this->
attr(
'enabled_views');
1366 $this->_printTimedTable(
'day', $column_names, $column_links, $events, $enabled_views[
'event']);
1369 $res = ob_get_contents();
1384 function getEventView($event_id)
1388 $info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($event_id));
1389 if (!empty($info)) $this->_printEventList($info);
1391 $res = ob_get_contents();
1409 function getEditView($event_id)
1411 $event = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($event_id);
1412 require_once SQ_INCLUDE_PATH.
'/limbo_outputter.inc';
1415 trigger_localised_error(
'CAL0024', E_USER_WARNING, $event_id);
1420 if (isset($_POST[
'asset_action'])) {
1421 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1422 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1424 if ($event->processBackend($o, $link)) {
1426 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1427 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1428 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($event_id,
'attributes');
1429 $_REQUEST[
'SQ_CALENDAR_VIEW'] =
'event';
1430 $_REQUEST[
'SQ_CALENDAR_EVENT_ID'] = $event_id;
1431 return $this->getEventView($event_id);
1434 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1435 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1440 if (!$GLOBALS[
'SQ_SYSTEM']->am->acquireLock($event_id,
'attributes')) {
1441 trigger_localised_error(
'CAL0025', E_USER_WARNING, $event->name, $event_id);
1442 return $this->getEventView($event_id);
1444 $o->addHiddenField(
'SQ_CALENDAR_VIEW',
'edit');
1445 $o->addHiddenField(
'SQ_CALENDAR_EVENT_ID', $event_id);
1446 $o->addHiddenField(
'SQ_CALENDAR_DATE', array_get_index($_REQUEST,
'SQ_CALENDAR_DATE'));
1447 $o->addHiddenField(
'asset_action',
'limbo');
1448 $o->addJsInclude(sq_web_path(
'lib').
'/html_form/html_form.js');
1450 $ei = $event->getEI();
1451 $ei->printEditInterface(
'screen_details', $event, $o);
1453 $o->commitButton(translate(
'cal_page_update_event'));
1457 $res = ob_get_contents();
1475 function _getTitleList($events)
1478 if (!empty($events)) {
1480 foreach ($events as $id => $data) {
1481 $real_id = strtok($id,
':');
1483 $event_date = sprintf(
'%04d-%02d-%02d', $data[
'start_date_year'], $data[
'start_date_mon'], $data[
'start_date_mday']);
1484 $event_url = $this->_getEventLinkHref($real_id, $event_date);
1485 if ($event_url) $res .=
'<a href="'.htmlentities($event_url).
'">';
1487 $current_view = htmlentities($_REQUEST[
'SQ_CALENDAR_VIEW']);
1488 switch ($current_view) {
1492 $res .= $this->_getEventLabel($current_view, $data);
1495 $res .= $data[
'name'];
1498 if ($event_url) $res .=
'</a>';
1521 function _printTimedTable($view, $column_names, $column_links, $events)
1523 $partition_time = intval($this->
attr(
'day_partition_time'));
1524 $partition_height = $this->
attr(
'day_partition_height');
1525 $columns_are_assets = ($view ==
'day') && (array_keys($column_names) != Array(
'*'));
1527 $root_nodes = $this->
attr(
'root_nodes');
1528 $width = ($view ==
'day') ? $this->
attr(
'day_column_width') : $this->
attr(
'table_column_width');
1530 $layout_maps = Array();
1531 foreach ($events as $date => $times_events) {
1532 $layout_maps[$date] = Array();
1533 foreach (array_keys($times_events) as $time) {
1534 $layout_maps[$date][$time] = Array();
1538 $dragging_enabled = $this->
attr(
'enable_event_dragging');
1539 $popups_enabled = $this->
attr(
'enable_description_popups');
1540 $click_to_add_ab = $this->
attr(
'asset_builder_page');
1541 $today_iso = date(
'Y-m-d');
1543 $mousedown_code = $dragging_enabled ?
'onmousedown="'.($popups_enabled ?
'stopTrailingPopup(); ' :
'').
'startDragging(this)"' :
'';
1544 $mouseup_code = $dragging_enabled ?
'onmouseup="stopDragging(); formSubmitted=true; setTimeout(\'formSubmitted=false\', 100)"' :
'';
1547 <table
id=
"<?php echo $view; ?>" border=
"0" cellspacing=
"0" cellpadding=
"0" summary=
"<?php echo translate('cal_page_events_in_this_'.$view); ?>" style=
"width: <?php echo ($width * count($events)) + 65; ?>px">
1553 <th><?php echo translate(
'time'); ?></th>
1555 foreach ($column_names as $id => $name) {
1556 $today_class = ($id == $today_iso) ?
' today' :
'';
1558 <th
class=
"columnLabel<?php echo $today_class; ?>" style=
"width: <?php echo $width; ?>px;">
1560 if (!empty($column_links)) {
1561 echo
'<a href="'.$column_links[$id].
'">';
1563 echo str_replace(
' ',
' ', $name);
1564 if (!empty($column_links)) echo
'</a>';
1572 $div_width = $width * 0.99;
1573 list($current_hour, $current_mins) = explode(
':', $this->
attr(
'day_starts_at'));
1574 list($end_hour, $end_mins) = explode(
':', $this->
attr(
'day_ends_at'));
1579 <th
class=
"timeLabel">*</th>
1581 foreach ($column_names as $id => $name) {
1582 $today_class = ($id == $today_iso) ?
' today' :
'';
1583 $col_events = $events[$id];
1584 $event_link_date = is_iso8601($id) ? $id : $_REQUEST[
'SQ_CALENDAR_DATE'];
1585 $click_to_add_code =
'';
1586 if ($click_to_add_ab) {
1587 $root_node_code = ($columns_are_assets && ($id !=
'*')) ?
', '.$id :
'';
1588 $click_to_add_code =
' onclick="addEvent(\''.$event_link_date.
'\', \
'*\''.$root_node_code.
');"';
1590 $cell_id = $event_link_date.
'_allday_'.($columns_are_assets ? $id :
'');
1592 <td
class=
"sq-allday-cell<?php echo $today_class; ?>" id=
"cell_<?php echo $cell_id; ?>"<?php echo $click_to_add_code; ?>>
1594 if (empty($col_events[
'all_day'])) echo
' ';
1595 foreach ($col_events[
'all_day'] as $assetid => $event) {
1596 $assetid = strtok($assetid,
':');
1597 $event_href = $this->_getEventLinkHref($assetid, $event_link_date);
1598 $event_classes = $this->_getClasses($event[
'treeid']);
1599 $event_classes[] =
'event';
1600 $onclick_code = $event_href ?
' onclick="sq_cal_redirect(this)"' :
'';
1601 $cursor_code = $event_href ?
' cursor: pointer; cursor: hand' :
'';
1602 $current_mouse_up_down_code = $mousedown_code.
' '.$mouseup_code;
1603 if (!empty($mousedown_code) && (($event[
'type_code'] ==
'calendar_event_recurring') || (isset($event[
'expanded'])))) {
1604 $current_mouse_up_down_code =
'onmousedown="statusBarMsg(\''.translate(
'cal_page_recurring_cannot_drag').
'\')
" onmouseup="statusBarMsg(\
'\');
"';
1606 $current_mouse_over_out_code = '';
1607 if (!empty($event['description'])) {
1608 if (!isset($this->_tmp['popup_printed'][$assetid])) {
1609 $popup_div_id = $assetid.'_'.$id;
1610 echo '<div id="event_
'.$popup_div_id.'_description
" class="popup
">'.$event['description'].'</div>';
1611 $this->_tmp['popup_printed'][$assetid] = 1;
1613 $current_mouse_over_out_code = 'onmouseover="startTrailingPopup(\
'event_'.$popup_div_id.
'_description\')" onmouseout="stopTrailingPopup()"';
1615 echo
'<div id="event_'.$assetid.
'" '.$current_mouse_up_down_code.
' '.$current_mouse_over_out_code.
' style="width: '.($width-2).
'px;'.$cursor_code.
'" class="'.implode(
' ', $event_classes).
'"'.$onclick_code.
'>';
1620 $label = $this->_getEventLabel($view, $event);
1621 if ($event_href && empty($mousedown_code)) {
1622 $label =
'<a class="'.implode(
' ', $event_classes).
'" href="'.htmlentities($event_href).
'">'.$label.
'</a>';
1627 $label =
'<span class="'.implode(
' ', $event_classes).
'">'.$label.
'</span>';
1628 $label .=
'<a style="display:none" href="'.htmlentities($event_href).
'"></a>';
1644 while (($current_hour*60 + $current_mins) < ($end_hour*60 + $end_mins)) {
1647 <th
class=
"timeLabel"><?php printf(
'%d:%02d', (($current_hour % 12 == 0) ? 12 : ($current_hour % 12)), $current_mins); ?></th>
1649 foreach ($column_names as $id => $name) {
1650 $today_class = ($id == $today_iso) ?
' today' :
'';
1651 $col_events = $events[$id];
1652 $event_link_date = is_iso8601($id) ? $id : $_REQUEST[
'SQ_CALENDAR_DATE'] ;
1653 $time_key = sprintf(
'%02d:%02d', $current_hour, $current_mins);
1654 if ($click_to_add_ab) {
1655 $root_node_code = ($columns_are_assets && ($id !=
'*')) ?
', '.$id :
'';
1656 $click_to_add_code =
' onclick="addEvent(\''.$event_link_date.
'\', \
''.$time_key.
'\''.$root_node_code.
');"';
1658 $cell_id = $event_link_date.
'_'.$time_key.
'_'.($columns_are_assets ? $id :
'');
1660 <td
id=
"cell_<?php echo $cell_id; ?>" class=
"sq-time-cell<?php echo $today_class; ?>" <?php echo $click_to_add_code; ?>>
1662 $denominator = max($col_events[
'_overlap_'], $this->
attr(
'column_capacity'));
1663 echo $this->_getTimedTableCellContents($view, $col_events[$time_key], $event_link_date, $root_nodes, ($current_mins + ($current_hour * 60)), $partition_time, $partition_height, $div_width / $denominator, $layout_maps[$id], $mousedown_code, $mouseup_code);
1665 <span style=
"font-size: 1px"> </span>
1672 $current_mins += $partition_time;
1673 $current_hour += floor($current_mins / 60);
1674 $current_mins = $current_mins % 60;
1681 if ($dragging_enabled) {
1682 $this->_printEventDraggingScript($view, ($view ==
'day') ? $column_names : NULL);
1684 if ($popups_enabled) $this->_printPopupsScript();
1685 if ($click_to_add_ab) {
1686 $this->_printAddEventScript($click_to_add_ab);
1711 function _getTimedTableCellContents($view, &$events, $event_link_date, &$root_nodes, $cell_ts, $partition_time, $cell_height, $event_width, &$layout_map, $mousedown_code, $mouseup_code)
1713 if (empty($events))
return '';
1715 $time_label = sprintf(
'%02d:%02d', (
int)($cell_ts / 60), $cell_ts % 60);
1718 uasort($events, Array(
'Calendar_Common',
'compareStartDates'));
1720 foreach ($events as $assetid => $details) {
1722 $real_assetid = current(explode(
':', $assetid));
1723 $event_href = $this->_getEventLinkHref($real_assetid, $event_link_date);
1726 $k = reset($layout_map);
1727 while ((key($layout_map) != $time_label) && (FALSE !== $k)) {
1730 $horizontal_index = 0;
1732 while (isset($layout_map[$time_label][$horizontal_index])) {
1733 $horizontal_index++;
1735 for ($i=0; $i < ceil(($details[
'end_date_minutes'] + $details[
'end_date_hours']*60 - $details[
'start_date_minutes']-$details[
'start_date_hours']*60) / $partition_time); $i++) {
1736 $layout_map[key($layout_map)][$horizontal_index] = 1;
1740 $event_left_margin = ($event_width * $horizontal_index);
1743 $event_ts = $details[
'start_date_minutes'] + (60 * $details[
'start_date_hours']);
1744 $end_ts = $details[
'end_date_minutes'] + (60 * $details[
'end_date_hours']);
1745 $event_top_margin = (($event_ts - $cell_ts) / $partition_time) * $cell_height;
1748 $event_duration = is_null($details[
'end_date_ts']) ? 0 : ($end_ts - $event_ts);
1749 $event_height = ($event_duration / $partition_time) * $cell_height;
1750 if ($event_height < 0)
continue;
1751 $event_height += floor($event_duration / $partition_time);
1754 $event_classes = $this->_getClasses($details[
'treeid']);
1755 $event_classes[] =
'event';
1758 $onclick_code = $event_href ?
'onclick="sq_cal_redirect(this)"' :
'';
1759 $current_mouse_up_down_code = $mousedown_code.
' '.$mouseup_code;
1760 if (!empty($mousedown_code) && (($details[
'type_code'] ==
'calendar_event_recurring') || (isset($details[
'expanded'])))) {
1761 $current_mouse_up_down_code =
'onmousedown="statusBarMsg(\''.translate(
'cal_page_recurring_cannot_drag').
'\')
" onmouseup="statusBarMsg(\
'\');
"';
1763 $current_mouse_over_out_code = '';
1765 if (!empty($details['description'])) {
1766 if (!isset($this->_tmp['popup_printed'][$assetid])) {
1767 $res .= '<div id="event_
'.$assetid.'_description
" class="popup
">'.$details['description'].'</div>';
1768 $this->_tmp['popup_printed'][$assetid] = 1;
1770 $current_mouse_over_out_code = 'onmouseover="startTrailingPopup(\
'event_'.$assetid.
'_description\')" onmouseout="stopTrailingPopup()"';
1774 $zero_length_code = $event_height ?
'' :
'border-style: dashed; border-bottom: 0px; border-left: 0px; border-right: 0px; padding-top: 0px; background-color: transparent;';
1775 $cursor_code = $event_href ?
'cursor: pointer; cursor: hand;' :
'';
1778 $res .=
'<div id="event_'.$assetid.
'" '.$current_mouse_up_down_code.
' '.$current_mouse_over_out_code.
' class="'.implode(
' ', $event_classes).
' event" style="float: left; position: absolute; width: '.($event_width-3).
'px; margin-left: '.$event_left_margin.
'px; margin-top: '.$event_top_margin.
'px; height: '.$event_height.
'px; border-width: 1px; '.$cursor_code.
' '.$zero_length_code.
'" '.$onclick_code.
'>';
1779 $res .=
'<div class="eventText" style="z-index: 30; position: absolute; width: '.($event_width-4).
'px; border: none; background-color: transparent">';
1784 $label = $this->_getEventLabel($view, $details);
1785 if ($event_href && empty($mousedown_code)) {
1786 $label =
'<a class="'.implode(
' ', $event_classes).
'" href="'.htmlentities($event_href).
'">'.$label.
'</a>';
1788 $label =
'<span class="'.implode(
' ', $event_classes).
'">'.$label.
'</span>';
1791 $label .=
'<a style="display:none" href="'.htmlentities($event_href).
'"></a>';
1795 $res .=
'</div></div>';
1813 function _getMonthCellContents(&$events, $event_link_date, $width)
1816 uasort($events, Array(
'Calendar_Common',
'compareStartDates'));
1818 foreach ($events as $assetid => $details) {
1819 $popup_div_id = str_replace(
':',
'_', $assetid);
1820 $assetid = strtok($assetid,
':');
1821 $event_url = htmlentities($this->_getEventLinkHref($assetid, $event_link_date));
1822 $event_classes = $this->_getClasses($details[
'treeid']);
1823 $event_classes[] =
'event';
1824 $onclick_code =$event_url ?
' onclick="clickChild(this); "' :
'';
1825 $cursor_code = $event_url ?
'cursor: pointer; cursor: hand;' :
'';
1827 $current_mouse_over_out_code =
'';
1829 if (!empty($details[
'description'])) {
1830 if (!isset($this->_tmp[
'popup_printed'][$assetid])) {
1831 $res .=
'<div id="event_'.$assetid.
'_description" class="popup">'.$details[
'description'].
'</div>';
1832 $this->_tmp[
'popup_printed'][$assetid] = 1;
1834 $current_mouse_over_out_code =
'onmouseover="startTrailingPopup(\'event_'.$assetid.
'_description\')" onmouseout="stopTrailingPopup()"';
1838 $res .=
'<div style="width: '.$width.
'px; '.$cursor_code.
'"'.$onclick_code.
' '.$current_mouse_over_out_code.
'><div style="width: auto; margin-bottom: 1px;" class="'.implode(
' ', $event_classes).
'">';
1840 $res .=
'<a href="'.$event_url.
'" class="'.implode(
' ', $event_classes).
'">';
1842 $res .= $this->_getEventLabel(
'month', $details);
1843 if ($event_url) $res .=
'</a>';
1844 $res .=
'</div></div>';
1857 function _getGeneralScript()
1859 $res =
'<script type="text/javascript" src="'.sq_web_path(
'lib').
'/js/general.js"></script>';
1860 foreach ($GLOBALS[
'SQ_SYSTEM']->lm->getJavascriptIncludes() as $js_include) {
1861 $res .=
'<script type="text/javascript" src="'.$js_include.
'"></script>';
1865 <!-- GENERAL CALENDAR PAGE JAVASCRIPT, ALWAYS PRESENT -->
1866 <script type="text/javascript">
1868 var formSubmitted = false;
1870 function clickChild(elt) {
1871 if (formSubmitted) {
1874 formSubmitted = true;
1875 linkChildren = elt.getElementsByTagName("A");
1876 if (linkChildren.length > 0) {
1877 linkChildren.item(0).click();
1880 function sq_cal_redirect(url) {
1881 if (url.getElementsByTagName) {
1882 url = url.getElementsByTagName("A")[0].href;
1884 if ((typeof moved == "undefined") || !moved) {
1885 document.location.href = url;
1886 formSubmitted = true;
1889 function statusBarMsg(m) {
1891 setTimeout(\'window.status=""\', 2000);
1895 <!-- /GENERAL CALENDAR PAGE JAVASCRIPT, ALWAYS PRESENT -->
1911 function _printAddEventScript($ab_id)
1915 <!-- SCRIPT FOR CLICK-TO-ADD-EVENT -->
1916 <script
type=
"text/javascript">
1918 function addEvent(date, time, node) {
1919 if (formSubmitted)
return;
1920 loc =
"<?php echo $GLOBALS['SQ_SYSTEM']->am->getAssetHref($ab_id); ?>?SQ_CALENDAR_DATE="+date;
1921 if (time !=
'*') loc +=
'&SQ_CALENDAR_TIME='+time+
'&SQ_CALENDAR_DURATION=<?php echo (int)$this->attr('day_partition_time
');?>_i';
1922 if (typeof node !=
'undefined') loc +=
'&SQ_CALENDAR_LOCATION='+node;
1923 document.location = loc;
1927 <!-- /SCRIPT FOR CLICK-TO-ADD-EVENT -->
1943 function _printEventDraggingScript($table_id, $columns=NULL)
1947 <!-- DRAG AND DROP SUPPORT -->
1948 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data'); ?>/asset_types/page_calendar/js/drag_n_drop.js"></script>
1949 <script type=
"text/javascript"><!--
1951 destinationTableId =
'<?php echo $table_id; ?>';
1952 columnNames =
new Array(<?php echo count($columns); ?>);
1954 if (!is_null($columns)) {
1955 foreach ($columns as $id => $name) {
1957 columnNames[
'<?php echo $id; ?>'] =
'<?php echo $name; ?>';
1962 document.onselectstart=
new Function (
"return false")
1965 <form method=
"get" id=
"dragForm" action=
"<?php echo $_SERVER['PHP_SELF']; ?>">
1966 <input type=
"hidden" name=
"SQ_CALENDAR_NEW_LOC" id=
"SQ_CALENDAR_NEW_LOC" />
1967 <input type=
"hidden" name=
"SQ_CALENDAR_OLD_LOC" id=
"SQ_CALENDAR_OLD_LOC" />
1968 <input type=
"hidden" name=
"SQ_CALENDAR_EVENT_ID" id=
"SQ_CALENDAR_EVENT_ID" />
1969 <input type=
"hidden" name=
"SQ_CALENDAR_DATE" value=
"<?php echo htmlspecialchars($_REQUEST['SQ_CALENDAR_DATE']); ?>" />
1970 <input type=
"hidden" name=
"SQ_CALENDAR_NEW_DATE" id=
"SQ_CALENDAR_NEW_DATE" />
1971 <input type=
"hidden" name=
"SQ_CALENDAR_NEW_TIME" id=
"SQ_CALENDAR_NEW_TIME" />
1972 <input type=
"hidden" name=
"SQ_CALENDAR_VIEW" value=
"<?php echo htmlspecialchars(array_get_index($_REQUEST, 'SQ_CALENDAR_VIEW', '')); ?>" />
1973 <input type=
"hidden" name=
"SQ_CALENDAR_EVENT_ACTION" id=
"SQ_CALENDAR_EVENT_ACTION" value=
"move" />
1975 <!-- /DRAG AND DROP SUPPORT -->
1988 function _printPopupsScript()
1992 <!-- DESCRIPTION POPUPS SUPPORT -->
1993 <script type=
"text/javascript" src=
"<?php echo sq_web_path('data'); ?>/asset_types/page_calendar/js/popup.js"></script>
1994 <!-- /DESCRIPTION POPUPS SUPPORT -->
2017 function _countOverlappingEvents(&$events, $start, $end, $spacing, $root_node=NULL)
2019 if (empty($events) || !is_array($events)) {
2023 list($start_time_h, $start_time_m) = explode(
':',$start);
2024 list($end_time_h, $end_time_m) = explode(
':',$end);
2027 $start_time = $start_time_h * 60 + $start_time_m;
2028 $end_time = $end_time_h * 60 + $end_time_m;
2030 $end_section = (ceil(($end_time - $start_time) / $spacing) - 1);
2032 $event_lists = Array();
2034 foreach (array_values($events) as $event) {
2035 if (empty($event[
'start_date_hours']))
continue;
2036 $event_start_time = $event[
'start_date_hours'] * 60 + $event[
'start_date_minutes'];
2037 if (is_null($event[
'end_date_hours']) || is_null($event[
'end_date_minutes'])) {
2038 $event_end_time = $event_start_time;
2040 $event_end_time = $event[
'end_date_hours'] * 60 + $event[
'end_date_minutes'];
2042 $event_start_section = floor(($event_start_time - $start_time) / $spacing);
2043 $event_end_section = (ceil(($event_end_time - $start_time) / $spacing) - 1);
2045 for ($i = $event_start_section; $i <= min($end_section, $event_end_section); $i++) {
2046 if ((!is_null($root_node)) && ($event[
'root_node'] != $root_node)) {
2049 if (!isset($event_lists[$i])) $event_lists[$i] = 0;
2055 array_multisort($event_lists, SORT_DESC, SORT_NUMERIC);
2056 return max(1,reset($event_lists));
2071 function _numPeriodsBetweenTimes($start, $end, $spacing)
2073 list($start_time_h, $start_time_m) = explode(
':',$start);
2074 list($end_time_h, $end_time_m) = explode(
':',$end);
2077 $start_time = $start_time_h * 60 + $start_time_m;
2078 $end_time = $end_time_h * 60 + $end_time_m;
2080 return ceil(($end_time - $start_time) / $spacing);
2095 function _addMinutes(&$current_hour, &$current_mins, $add_mins)
2097 $current_mins += $add_mins;
2098 $current_hour += floor($current_mins / 60);
2099 $current_mins = $current_mins % 60;
2116 function _trimEvent(&$details, $day_start_dts, $day_end_dts)
2118 $event_dts = $details[
'start_date_hours'] * 60 + $details[
'start_date_minutes'];
2119 $event_end_dts = $details[
'end_date_hours'] * 60 + $details[
'end_date_minutes'];
2120 if ((!empty($details[
'end_date_ts']) && ($event_end_dts < $day_start_dts)) || ($event_dts > $day_end_dts)) {
2127 if (($event_dts < $day_start_dts) && ($event_end_dts > $day_start_dts)) {
2128 $event_dts = $day_start_dts;
2129 $details[
'start_date_hours'] = floor($day_start_dts / 60);
2130 $details[
'start_date_minutes'] = $day_start_dts % 60;
2131 $details[
'trimmed'] = 1;
2133 if (($event_dts < $day_end_dts) && ($event_end_dts > $day_end_dts)) {
2134 $event_end_dts = $day_end_dts;
2135 $details[
'end_date_hours'] = floor($day_end_dts / 60);
2136 $details[
'end_date_minutes'] = $day_end_dts % 60;
2137 $details[
'trimmed'] = 1;
2154 function _printEventList(&$events)
2157 if (empty($events))
return;
2158 uasort($events, Array(
'Calendar_Common',
'compareStartDates'));
2160 $assetids = array_keys($events);
2161 $am =& $GLOBALS[
'SQ_SYSTEM']->am;
2164 if (!isset($this->_tmp[
'type_format_bcs'])) {
2166 $type_format_bodycopies = Array();
2167 $folder_link = $am->getLink($this->
id, SQ_LINK_TYPE_2,
'folder', TRUE,
'type_formats');
2168 $links = $am->getLinks($folder_link[
'minorid'], SQ_LINK_TYPE_2,
'bodycopy', TRUE);
2169 $this->_tmp[
'list_needs_asset_info'] = FALSE;
2170 foreach ($links as $bodycopy) {
2171 $bodycopy_type_code = $bodycopy[
'value'];
2172 $type_format_bodycopies[$bodycopy_type_code] = Array();
2173 $type_format_bodycopies[$bodycopy_type_code][
'obj'] = $am->getAsset($bodycopy[
'minorid'],
'bodycopy');
2174 $type_format_bodycopies[$bodycopy_type_code][
'keywords'] = $type_format_bodycopies[$bodycopy_type_code][
'obj']->getKeywords();
2175 $data_reqs = $this->_getKeywordDataRequirements($type_format_bodycopies[$bodycopy_type_code][
'keywords']);
2176 $type_format_bodycopies[$bodycopy_type_code][
'needs_asset'] = ($data_reqs == 2);
2177 if ($data_reqs == 1) {
2178 $this->_tmp[
'list_needs_asset_info'] = TRUE;
2181 $this->_tmp[
'type_format_bcs'] =& $type_format_bodycopies;
2183 $type_format_bodycopies =& $this->_tmp[
'type_format_bcs'];
2186 foreach ($assetids as $i => $assetid) {
2187 $assetids[$i] = strtok($assetid,
':');
2189 $assetids = array_unique($assetids);
2191 if ($this->_tmp[
'list_needs_asset_info']) {
2192 $this->_tmp[
'asset_infos'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($assetids);
2193 foreach ($this->_tmp[
'asset_infos'] as $id => $info) {
2194 $asset_info[$id][
'assetid'] = $id;
2199 foreach ($events as $assetid => $event) {
2200 $event[
'assetid'] = $assetid;
2201 $type_code = $event[
'type_code'];
2202 $assetid = strtok($assetid,
':');
2205 $found_bodycopy = FALSE;
2206 if (isset($type_format_bodycopies[$type_code])) {
2207 $bodycopy =& $type_format_bodycopies[$type_code];
2208 $found_bodycopy = TRUE;
2209 }
else if ($type_code ==
'calendar_event_modification' ) {
2211 $link = $am->getLink($assetid, SQ_LINK_TYPE_2,
'calendar_event_recurring', TRUE, NULL,
'minor');
2212 $bodycopy =& $type_format_bodycopies[$link[
'major_type_code']];
2213 $found_bodycopy = TRUE;
2214 }
else if ($type_code ==
'calendar_event_cancellation' ) {
2218 $type_ancestors = $am->getTypeAncestors($type_code);
2219 foreach ($type_ancestors as $parent_type) {
2220 if (isset($type_format_bodycopies[$parent_type])) {
2221 $type_format_bodycopies[$type_code] =& $type_format_bodycopies[$parent_type];
2222 $bodycopy =& $type_format_bodycopies[$parent_type];
2223 $found_bodycopy = TRUE;
2225 }
else if ($parent_type ==
'calendar_event_cancellation' ) {
2229 if (!$found_bodycopy) {
2230 trigger_localised_error(
'CAL0061', E_USER_WARNING, $assetid);
2235 $replacements = Array();
2236 if ($bodycopy[
'needs_asset']) {
2237 $event = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $type_code);
2238 foreach ($bodycopy[
'keywords'] as $keyword) {
2239 if ($keyword ==
'asset_contents') {
2241 $event->printBody();
2242 $replacements[
'asset_contents'] = ob_get_clean();
2244 $replacements[$keyword] = $event->getKeywordReplacement($keyword);
2248 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($event);
2250 foreach ($bodycopy[
'keywords'] as $keyword) {
2251 $replacements[$keyword] = $this->_getEventKeywordReplacement($keyword, $event);
2254 $bodycopy[
'obj']->setKeywordReplacements($replacements);
2255 $bodycopy[
'obj']->printBody();
2268 function _getRootNodeIds()
2270 $root_asset_ids = array_keys($this->
attr(
'root_nodes'));
2271 if (empty($root_asset_ids)) {
2272 $root_asset_ids = Array($this->
id);
2274 return $root_asset_ids;
2287 function _getClasses($treeids)
2289 usort($treeids, Array(&$this,
'_strlenCmp'));
2290 $treeid_key = implode(
',', $treeids);
2291 $root_nodes = $this->
attr(
'root_nodes');
2292 if (!isset($this->_tmp[
'treeid_map'])) {
2293 $root_node_roots = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids(array_keys($root_nodes));
2294 $treeid_map = Array();
2295 foreach ($root_node_roots as $assetid => $root_treeids) {
2296 $root_treeid = $root_treeids[0];
2297 $treeid_map[reset($root_treeid)] = $assetid;
2299 uksort($treeid_map, Array(&$this,
'_strlenCmp'));
2300 $this->_tmp[
'treeid_map'] = $treeid_map;
2302 $treeids = $treeids;
2305 foreach ($treeids as $treeid) {
2306 foreach ($this->_tmp[
'treeid_map'] as $class_treeid => $assetid) {
2307 if (0 === strpos($treeid, $class_treeid) && !empty($root_nodes[$assetid][
'class_name'])) {
2308 $res[] = $root_nodes[$assetid][
'class_name'];
2312 return array_unique($res);
2326 function _strlenCmp($a, $b)
2328 if (strlen($a) == strlen($b))
return $a > $b;
2329 return strlen($a) > strlen($b);
2346 function _getEventLinkHref($eventid, $date=NULL)
2348 if (!isset($this->_tmp[
'single_event_view'])) {
2349 $enabled_views = $this->
attr(
'enabled_views');
2350 $this->_tmp[
'single_event_view'] = $enabled_views[
'event'];
2353 switch ($this->_tmp[
'single_event_view']) {
2357 case 'single_event_view':
2358 $res = $this->
getURL().
'?SQ_CALENDAR_VIEW=event&SQ_CALENDAR_EVENT_ID='.$eventid;
2359 if (!empty($res) && !is_null($date)) {
2360 $res .=
'&SQ_CALENDAR_DATE='.$date;
2363 case 'event_itself':
2364 $res = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($eventid);
2365 if (!empty($res) && !is_null($date)) {
2366 $res .=
'?SQ_CALENDAR_DATE='.$date;
2384 function _initEventLabels($view, &$events)
2386 $this->_tmp[
'event_label_format'] = $this->
attr($view.
'_view_event_label_format');
2387 $this->_tmp[
'event_label_format_keywords'] = retrieve_keywords_replacements($this->_tmp[
'event_label_format']);
2388 $data_requirements = $this->_getKeywordDataRequirements($this->_tmp[
'event_label_format_keywords']);
2389 $this->_tmp[
'event_label_need_asset'] = ($data_requirements == 2);
2390 if ($data_requirements == 1) {
2391 $this->_tmp[
'asset_infos'] = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($events));
2408 function _getKeywordDataRequirements($keywords)
2410 $calendar_result_keywords = Array(
'asset_attribute_start_date',
'asset_attribute_end_date');
2411 $asset_info_fields = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfoFields();
2412 $date_formats = get_date_formats();
2413 $need_asset_info = FALSE;
2414 $need_asset = FALSE;
2415 foreach ($keywords as $keyword) {
2416 if ($keyword ==
'asset_name')
continue;
2417 foreach ($calendar_result_keywords as $calendar_keyword) {
2418 if ($keyword == $calendar_keyword)
continue 2;
2419 if (0 === strpos($keyword, $calendar_keyword.
'_')) {
2420 $suffix = substr($keyword, strlen($calendar_keyword)+1);
2421 if (isset($date_formats[$suffix]))
continue 2;
2424 if (0 === strpos($keyword,
'asset_')) {
2425 $fieldname = substr($keyword, 6);
2426 if (isset($asset_info_fields[$fieldname])) {
2427 $need_asset_info = TRUE;
2437 if ($need_asset)
return 2;
2438 if ($need_asset_info)
return 1;
2455 function _getEventLabel($view, &$event_data)
2457 $replacements = Array();
2458 if ($this->_tmp[
'event_label_need_asset']) {
2459 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($event_data[
'assetid']);
2460 foreach ($this->_tmp[
'event_label_format_keywords'] as $keyword) {
2461 $replacements[$keyword] = $asset->getKeywordReplacement($keyword);
2464 foreach ($this->_tmp[
'event_label_format_keywords'] as $keyword) {
2465 $replacements[$keyword] = $this->_getEventKeywordReplacement($keyword, $event_data);
2468 $fmt = $this->_tmp[
'event_label_format'];
2469 replace_keywords($fmt, $replacements);
2487 function _getEventKeywordReplacement($keyword, $event_data)
2489 $date_formats = get_date_formats();
2490 if ($keyword ==
'asset_name') {
2491 return $event_data[
'name'];
2493 if ($keyword ==
'asset_assetid') {
2494 return $event_data[
'assetid'];
2496 $calendar_result_keywords = Array(
'start_date',
'end_date');
2497 foreach ($calendar_result_keywords as $calendar_field) {
2498 if ($keyword ==
'asset_attribute_'.$calendar_field) {
2499 return ts_iso8601($event_data[$calendar_field.
'_ts']);
2501 if (0 === strpos($keyword,
'asset_attribute_'.$calendar_field.
'_')) {
2502 $suffix = substr($keyword, strlen($calendar_field)+17);
2503 if (isset($date_formats[$suffix])) {
2504 return date($date_formats[$suffix], $event_data[$calendar_field.
'_ts']);
2508 if (0 === strpos($keyword,
'asset_')) {
2509 $field = substr($keyword, 6);
2510 if (isset($this->_tmp[
'asset_infos'][$event_data[
'assetid']][$field])) {
2511 return $this->_tmp[
'asset_infos'][$event_data[
'assetid']][$field];
2530 function getYearEvents($year)
2535 $root_ids = $this->_getRootNodeIds();
2536 if (empty($root_ids)) {
2537 trigger_localised_error(
'CAL0026', E_USER_WARNING);
2542 $start_ts = strtotime(
"$year-01-01 00:00:00");
2543 $next_year = $year + 1;
2544 $end_ts = strtotime(
"$next_year-01-01 00:00:00") - 1;
2547 $bind_vars = Array();
2548 $date_sql =
'(cd.start_date_year = :start_date_year) OR (cd.end_date_year = :end_date_year) OR ((cd.start_date_ts < :start_date_ts) AND (cd.end_date_ts > :end_date_ts))';
2550 $sql .= $this->_getRootNodeRestrictionSQL();
2552 $single_events = Array();
2555 foreach($bind_vars as $bind_value => $bind_var) {
2564 }
catch (Exception $e) {
2565 throw new Exception($e->getMessage());
2571 $bind_vars = Array();
2572 $date_sql =
'cd.start_date_ts < :start_date_ts';
2574 $sql .= $this->_getRootNodeRestrictionSQL();
2576 $recurring_events = Array();
2579 foreach($bind_vars as $bind_value => $bind_var) {
2584 }
catch (Exception $e) {
2585 throw new Exception($e->getMessage());
2590 $res = $single_events + $recurring_events;
2605 function getYearEventsByMonth($year)
2609 foreach (range(1, 12) as $month_num) {
2610 $res[$month_num] = Array();
2613 $cal_date = sprintf(
'%04d-%02d-%02d', $year, 1, 1);
2614 $last_day = sprintf(
'%04d-%02d-%02d', $year, 12, 31);
2616 $plain_events = $this->getYearEvents($year);
2620 foreach ($events as $id => $details) {
2621 if ($details[
'start_date_year'] == $year) {
2622 $res[$details[
'start_date_mon']][strtok($id,
':')] = $details;
2641 function getYearEventsByMonthAndDay($year)
2645 foreach (range(1, 12) as $month_num) {
2646 $res[$month_num] = Array();
2647 foreach (range(1, days_in_month($month_num, $year)) as $dom) {
2648 $res[$month_num][$dom] = Array();
2652 $cal_date = sprintf(
'%04d-%02d-%02d', $year, 1, 1);
2653 $last_day = sprintf(
'%04d-%02d-%02d', $year, 12, 31);
2655 $plain_events = $this->getYearEvents($year);
2658 foreach ($events as $id => $details) {
2659 if ($details[
'start_date_year'] == $year) {
2660 $res[$details[
'start_date_mon']][$details[
'start_date_mday']][$id] = $details;
2663 foreach (array_keys($res) as $month) {
2664 foreach (array_keys($res[$month]) as $date) {
2683 function getMonthEvents($year, $month)
2688 $root_ids = $this->_getRootNodeIds();
2689 if (empty($root_ids)) {
2690 trigger_localised_error(
'CAL0027', E_USER_WARNING);
2695 $start_ts = strtotime(
"$year-$month-01 00:00:00 GMT");
2696 $next_month = ($month % 12) + 1;
2697 $next_year = ($next_month == 1) ? $year + 1 : $year;
2698 $end_ts = strtotime(
"$next_year-$next_month-01 00:00:00 GMT") - 1;
2701 $bind_vars = Array();
2702 $date_sql =
'((cd.start_date_year = :start_date_year AND (cd.start_date_mon = :start_date_month OR cd.end_date_mon = :end_date_month)) OR (cd.start_date_ts < :start_date_ts AND cd.end_date_ts > :end_date_ts))';
2704 $sql .= $this->_getRootNodeRestrictionSQL();
2706 $single_result = Array();
2709 foreach($bind_vars as $bind_value => $bind_var) {
2718 }
catch (Exception $e) {
2719 throw new Exception($e->getMessage());
2724 $cal_date = sprintf(
'%04d-%02d-%02d', $year, $month, 1);
2725 $first_day = iso8601_ts($cal_date);
2726 $last_day = sprintf(
'%04d-%02d-%02d', $year, $month, days_in_month($month, $year));
2730 $sql .= $this->_getRootNodeRestrictionSQL();
2732 $recur_result = Array();
2735 foreach($bind_vars as $bind_value => $bind_var) {
2739 }
catch (Exception $e) {
2740 throw new Exception($e->getMessage());
2744 $res = $single_result + $recur_result;
2745 if ($this->
attr(
'enable_description_popups')) {
2746 $descriptions = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'description',
'calendar_event', array_keys($res));
2747 foreach ($descriptions as $assetid => $description) {
2748 $res[$assetid][
'description'] = $description;
2766 function groupMonthEventsByDay($plain_events, $year, $month)
2768 $month_length = days_in_month($month, $year);
2771 for ($i = 1; $i <= $month_length; $i++) {
2775 $cal_date = sprintf(
'%04d-%02d-%02d', $year, $month, 1);
2776 $last_day = sprintf(
'%04d-%02d-%02d', $year, $month, $month_length);
2780 foreach ($events as $id => $details) {
2781 if (($details[
'start_date_mon'] == $month) && ($details[
'start_date_year'] == $year)) {
2782 $res[$details[
'start_date_mday']][$id] = $details;
2786 foreach ($res as $date => $events) {
2803 function getWeekEvents($date)
2807 list($year,$month,$day) = sscanf($date,
'%04d-%02d-%02d');
2809 $root_ids = $this->_getRootNodeIds();
2810 if (empty($root_ids)) {
2811 trigger_localised_error(
'CAL0028', E_USER_WARNING);
2816 $bind_vars = Array();
2818 $end_date_stamp = $start_date_stamp + 6;
2819 $date_sql =
'(cd.start_date_ds BETWEEN :start_date_ds AND :end_date_ds) OR (cd.start_date_ds < :start_date_ds_1 AND cd.end_date_ds >= :start_date_ds_2)';
2821 $sql .= $this->_getRootNodeRestrictionSQL();
2823 $single_result = Array();
2826 foreach($bind_vars as $bind_value => $bind_var) {
2834 }
catch (Exception $e) {
2835 throw new Exception($e->getMessage());
2842 $sql .= $this->_getRootNodeRestrictionSQL();
2844 $recur_result = Array();
2847 foreach($bind_vars as $bind_value => $bind_var) {
2851 }
catch (Exception $e) {
2852 throw new Exception($e->getMessage());
2857 $plain_events = $single_result + $recur_result;
2859 $week_start_day = $this->
attr(
'week_starts_on');
2860 $seconds_in_day = 86400;
2861 $first_day = iso8601_ts($date) - ((7+(date(
'w', iso8601_ts($date)) - $week_start_day))%7)*$seconds_in_day;
2862 $cal_date = date(
'Y-m-d', $first_day);
2864 $last_day = add_days_to_iso($cal_date, 6);
2869 foreach ($events as $id => $details) {
2870 $event_date = iso8601_ts(sprintf(
'%04d-%02d-%02d', $details[
'start_date_year'], $details[
'start_date_mon'], $details[
'start_date_mday']));
2871 list($assetid, ) = explode(
':', $id);
2872 if ($event_date >= iso8601_ts($date) && $event_date < iso8601_ts($date)+7*86400) {
2873 $res[$assetid] = $plain_events[$assetid];
2877 if ($this->
attr(
'enable_description_popups')) {
2878 $descriptions = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'description',
'calendar_event', array_keys($res));
2879 foreach ($descriptions as $assetid => $description) {
2880 $res[$assetid][
'description'] = $description;
2898 function groupWeekEventsByDay($plain_events, $date)
2901 $day_in_second = 24 * 60 * 60;
2902 $days_to_show = $this->
attr(
'week_view_show_days');
2904 $i = iso8601_ts($date);
2905 while ($i <= iso8601_ts(add_days_to_iso($date, 6))) {
2906 $iso_date = iso8601_date_component(ts_iso8601($i));
2907 if ($days_to_show[date(
'w', $i)]) {
2908 $res[$iso_date] = Array();
2910 $i = iso8601_ts(add_days_to_iso($iso_date));
2913 $week_start_day = $this->
attr(
'week_starts_on');
2914 $first_day = iso8601_ts($date) - ((7+(date(
'w', iso8601_ts($date)) - $week_start_day))%7)*$day_in_second;
2915 $cal_date = date(
'Y-m-d', $first_day);
2917 $last_day = add_days_to_iso($cal_date, 6);
2920 foreach ($events as $id => $details) {
2921 $event_date = sprintf(
'%04d-%02d-%02d', $details[
'start_date_year'], $details[
'start_date_mon'], $details[
'start_date_mday']);
2922 if (isset($res[$event_date])) {
2923 $res[$event_date][$id] = $details;
2927 foreach ($res as $date => $events) {
2948 function groupWeekEventsByDayAndTime($plain_events, $date, $first_time=
'', $time_partition=
'', $last_time=
'')
2951 $first_time = $this->
attr(
'day_starts_at');
2953 if (!$time_partition) {
2954 $time_partition = $this->
attr(
'day_partition_time');
2956 $days_to_show = $this->
attr(
'week_view_show_days');
2959 $last_time = $this->
attr(
'day_ends_at');
2961 $partition_keys = Array();
2962 list($e_hour, $e_mins) = explode(
':', $last_time);
2963 $end_ts = $e_mins + (60 * $e_hour);
2964 list($hour, $mins) = explode(
':', $first_time);
2965 $ts = $mins + (60 * $hour);
2967 while ($ts < $end_ts) {
2968 $partition_keys[$ts] = sprintf(
'%02d', $ts/60).
':'.sprintf(
'%02d', $ts%60);
2969 $ts += $time_partition;
2971 $partitions = array_flip($partition_keys);
2972 foreach ($partitions as $key => $val) {
2973 $partitions[$key] = Array();
2975 $partitions[
'all_day'] = Array();
2979 $week_start_day = $this->
attr(
'week_starts_on');
2980 $first_day = iso8601_ts($date) - ((7+(date(
'w', iso8601_ts($date)) - $week_start_day))%7)*86400;
2981 $cal_date = date(
'Y-m-d', $first_day);
2983 $last_day = add_days_to_iso($cal_date, 6);
2985 $i = iso8601_ts($cal_date);
2986 while ($i <= iso8601_ts(add_days_to_iso($cal_date, 6))) {
2987 $iso_date = iso8601_date_component(ts_iso8601($i));
2988 if ($days_to_show[date(
'w', $i)]) {
2989 $res[$iso_date] = $partitions;
2991 $i = iso8601_ts(add_days_to_iso($iso_date));
2994 $plain_events = $this->groupWeekEventsByDay($plain_events, $date);
2995 foreach ($plain_events as $event_date => $events) {
2996 $res[$event_date][
'_overlap_'] = $this->_countOverlappingEvents($events, $first_time, $last_time, $time_partition);
2997 foreach ($events as $id => $details) {
2998 if (isset($res[$event_date])) {
2999 if (is_null($details[
'start_date_hours']) || ($details[
'start_date_hours'] ==
'--')) {
3000 $res[$event_date][
'all_day'][$id] = $details;
3002 $this->_trimEvent($details, $start_ts, $end_ts);
3003 if (empty($details))
continue;
3004 $event_ts = $details[
'start_date_hours'] * 60 + $details[
'start_date_minutes'];
3005 foreach ($partition_keys as $partition_ts => $key) {
3006 if (($event_ts - $partition_ts) < $time_partition) {
3007 $res[$event_date][$key][$id] = $details;
3016 foreach ($res as $date => $events) {
3017 foreach ($partition_keys as $partition) {
3036 function getDayEvents($date)
3039 list($year,$month,$day) = sscanf($date,
'%04d-%02d-%02d');
3041 $root_ids = $this->_getRootNodeIds();
3042 if (empty($root_ids)) {
3043 trigger_localised_error(
'CAL0029', E_USER_WARNING);
3048 $bind_vars = Array();
3050 $date_sql =
'(('.$today_date_stamp.
' = cd.start_date_ds) OR ('.$today_date_stamp.
' BETWEEN cd.start_date_ds AND cd.end_date_ds))';
3052 $sql .= $this->_getRootNodeRestrictionSQL();
3054 $single_result = Array();
3057 foreach($bind_vars as $bind_value => $bind_var) {
3061 }
catch (Exception $e) {
3062 throw new Exception($e->getMessage());
3067 $bind_vars = Array();
3069 $sql .= $this->_getRootNodeRestrictionSQL();
3071 $recur_result = Array();
3074 foreach($bind_vars as $bind_value => $bind_var) {
3078 }
catch (Exception $e) {
3079 throw new Exception($e->getMessage());
3084 $res = $single_result + $recur_result;
3085 if ($this->
attr(
'enable_description_popups')) {
3086 $descriptions = $GLOBALS[
'SQ_SYSTEM']->am->getAttributeValuesByName(
'description',
'calendar_event', array_keys($res));
3087 foreach ($descriptions as $assetid => $description) {
3088 $res[$assetid][
'description'] = $description;
3095 uasort($res, Array(
'Calendar_Common',
'compareStartDates'));
3114 function groupDayEventsByTime($events, $date, $first_time=
'', $time_partition=
'', $last_time=
'')
3117 $first_time = $this->
attr(
'day_starts_at');
3119 if (!$time_partition) {
3120 $time_partition = $this->
attr(
'day_partition_time');
3123 $last_time = $this->
attr(
'day_ends_at');
3126 $partition_keys = Array();
3127 list($hour, $mins) = explode(
':', $last_time);
3128 $end_ts = $mins + (60 * $hour);
3129 list($hour, $mins) = explode(
':', $first_time);
3130 $ts = $mins + (60 * $hour);
3132 while ($ts < $end_ts) {
3133 $partition_keys[$ts] = sprintf(
'%02d', $ts/60).
':'.sprintf(
'%02d', $ts%60);
3134 $ts += $time_partition;
3136 $partitions = array_flip($partition_keys);
3137 foreach ($partitions as $key => $val) {
3138 $partitions[$key] = Array();
3140 $partitions[
'all_day'] = Array();
3144 foreach ($events as $id => $details) {
3145 $event_date = sprintf(
'%04d-%02d-%02d', $details[
'start_date_year'], $details[
'start_date_mon'], $details[
'start_date_mday']);
3146 if (($event_date == $date)) {
3147 if (is_null($details[
'start_date_hours']) || $details[
'start_date_hours'] ==
'--') {
3148 $res[
'all_day'][$id] = $details;
3150 $this->_trimEvent($details, $start_ts, $end_ts);
3151 if (empty($details))
continue;
3152 $event_ts = $details[
'start_date_hours'] * 60 + $details[
'start_date_minutes'];
3153 foreach ($partition_keys as $partition_ts => $key) {
3154 if (($event_ts - $partition_ts) < $time_partition) {
3155 $res[$key][$id] = $details;
3162 $res[
'_overlap_'] = $this->_countOverlappingEvents($events, $first_time, $last_time, $time_partition);
3180 function groupDayEventsByRootNodeAndTime($events, $first_time=
'', $time_partition=
'', $last_time=
'', $root_nodes=
'')
3183 $first_time = $this->
attr(
'day_starts_at');
3185 if (!$time_partition) {
3186 $time_partition = $this->
attr(
'day_partition_time');
3189 $last_time = $this->
attr(
'day_ends_at');
3192 $root_nodes = array_keys($this->
attr(
'root_nodes'));
3194 $partition_keys = Array();
3195 list($e_hour, $e_mins) = explode(
':', $last_time);
3196 $end_ts = $e_mins + (60 * $e_hour);
3197 list($hour, $mins) = explode(
':', $first_time);
3198 $ts = $mins + (60 * $hour);
3200 while ($ts < $end_ts) {
3201 $partition_keys[$ts] = sprintf(
'%02d', $ts/60).
':'.sprintf(
'%02d', $ts%60);
3202 $ts += $time_partition;
3204 $partitions = array_flip($partition_keys);
3205 foreach ($partitions as $key => $val) {
3206 $partitions[$key] = Array();
3208 $partitions[
'all_day'] = Array();
3213 $columnise_by_root = $this->
attr(
'columnise_day_view_by_root_node');
3214 foreach ($columnise_by_root as $node_id) {
3215 if (($node_id ==
'*') || in_array($node_id, $root_nodes)) {
3216 $res[$node_id] = $partitions;
3219 $column_treeids = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids(array_diff($columnise_by_root, Array(
'*')));
3221 foreach ($events as $id => $details) {
3222 $event_date = sprintf(
'%04d-%02d-%02d', $details[
'start_date_year'], $details[
'start_date_mon'], $details[
'start_date_mday']);
3225 foreach ($column_treeids as $column_id => $this_column_treeids) {
3226 foreach ($this_column_treeids[0] as $column_treeid) {
3227 foreach ($details[
'treeid'] as $event_treeid) {
3228 if (0 === strpos($event_treeid, $column_treeid)) {
3229 $cols[] = $column_id;
3234 if (empty($cols) && isset($res[
'*'])) {
3237 foreach ($cols as $col) {
3238 if (empty($details[
'start_date_hours'])) {
3239 $res[$col][
'all_day'][$id] = $details;
3241 $this->_trimEvent($details, $start_ts, $end_ts);
3242 if (empty($details))
continue;
3243 $event_ts = $details[
'start_date_hours'] * 60 + $details[
'start_date_minutes'];
3244 foreach ($partition_keys as $partition_ts => $key) {
3245 if (($event_ts - $partition_ts) < $time_partition) {
3246 $res[$col][$key][$id] = $details;
3254 foreach ($res as $root_node => $null) {
3257 foreach ($res[$root_node] as $key => $null) {
3258 foreach ($res[$root_node][$key] as $id => $null) {
3259 $rrn[] = &$res[$root_node][$key][$id];
3263 $max_events = max($max_events, $this->_countOverlappingEvents($rrn, $first_time, $last_time, $time_partition));
3265 $res[$root_node][
'_overlap_'] = $max_events;
3278 function _getRootNodeRestrictionSQL()
3280 $restrictive_roots = $this->_getRestrictiveRootNodeIds();
3281 if (!empty($restrictive_roots)) {
3282 $db = MatrixDal::getDb();
3283 $root_treeids = $GLOBALS[
'SQ_SYSTEM']->am->getAssetTreeids($restrictive_roots);
3284 $treeid_options = Array();
3285 foreach ($root_treeids as $rootid => $this_root_treeids) {
3287 $treeid_options[] =
'salt.treeid LIKE '.MatrixDAL::quote(reset(reset($this_root_treeids)).
'%');
3292 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk sal
3293 JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lnk_tree salt ON (sal.linkid = salt.linkid)
3294 WHERE ('.implode(
' OR ', $treeid_options).
')
3309 function _getRestrictiveRootNodeIds()
3312 if ($this->
attr(
'personalised')) {
3313 return Array($GLOBALS[
'SQ_SYSTEM']->user->id);
3318 $raw_dynamic_root_nodes = $parameter_map->getParameterValue(
'replacement_root_node');
3319 if (!empty($raw_dynamic_root_nodes)) {
3320 $dynamic_root_nodes = Array();
3323 if (!is_array($raw_dynamic_root_nodes)) {
3324 $raw_dynamic_root_nodes = explode(
',', $raw_dynamic_root_nodes);
3327 $original_root_ids = array_keys($this->
attr(
'root_nodes'));
3328 foreach ($raw_dynamic_root_nodes as $dynamic_root) {
3329 if (!strlen($dynamic_root))
continue;
3332 $dynamic_parents = $GLOBALS[
'SQ_SYSTEM']->am->getParents($dynamic_root);
3333 $matching_root_ids = array_intersect(array_keys($dynamic_parents), $original_root_ids);
3334 if (empty($matching_root_ids)) {
3335 trigger_localised_error(
'CAL0067', E_USER_WARNING, $dynamic_root, $this->
id);
3337 $dynamic_root_nodes[] = $dynamic_root;
3341 if (!empty($dynamic_root_nodes)) {
3342 return $dynamic_root_nodes;
3362 function formatDatesToCompare($view,$date,$direction, $operator)
3364 if ($view ==
'event' || $view ==
'edit') {
3365 return Array(
'',
'');
3368 $navi_limit = $this->
attr($view.
'_navi_limit');
3369 $curr_date = date(
'Y-m-d');
3372 if ($navi_limit[$direction] ==
'') {
3373 return Array(
'',
'');
3379 $limit_date = date(
'Y',strtotime($operator.$navi_limit[$direction].
' year',strtotime($curr_date)));
3380 $compared_date = date(
'Y',strtotime($date));
3383 $limit_date = date(
'Y-m',strtotime($operator.$navi_limit[$direction].
' month',strtotime($curr_date)));
3384 $compared_date = date(
'Y-m',strtotime($date));
3388 $day_in_seconds = 24 * 60 * 60;
3389 $week_start_index = $this->
attr(
'week_starts_on');
3390 $curr_day_index = array_search(date(
'l', iso8601_ts($curr_date)), $this->day_names);
3391 if ($week_start_index != $curr_day_index) {
3392 if ($week_start_index < $curr_day_index) {
3393 $offset = $curr_day_index - $week_start_index;
3395 $offset = $curr_day_index + (7 - $week_start_index);
3398 $limit_date = date(
'Y-m-d',strtotime($operator.$navi_limit[$direction].
' week',strtotime($curr_date)));
3399 $limit_date = strtotime($limit_date) - ($offset * $day_in_seconds);
3400 $limit_date = date(
'Y-m-d',$limit_date);
3403 $compared_day_index = array_search(date(
'l', iso8601_ts($date)), $this->day_names);
3404 if ($week_start_index != $compared_day_index) {
3405 if ($week_start_index < $compared_day_index) {
3406 $offset = $compared_day_index - $week_start_index;
3408 $offset = $compared_day_index + (7 - $week_start_index);
3411 $compared_date = strtotime($date) - ($offset * $day_in_seconds);
3412 $compared_date = date(
'Y-m-d',$compared_date);
3415 $limit_date = date(
'Y-m-d',strtotime($operator.$navi_limit[$direction].
' day',strtotime($curr_date)));
3416 $compared_date = $date;
3420 return Array($limit_date,$compared_date);
3431 function createNoResultsBodycopy()
3433 $bodycopy_name =
"page_contents_no_results";
3436 $bodycopy_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_TYPE_2,
'bodycopy', TRUE, $bodycopy_name);
3437 if (!empty($bodycopy_link)) {
3444 'link_type' => SQ_LINK_TYPE_2,
3445 'is_dependant' => 1,
3446 'is_exclusive' => 1,
3447 'value' => $bodycopy_name,
3450 $page_contents_data = Array(
3451 'content' =>
'<h2 style="text-align: center">%calendar_title%</h2><p style="text-align: center">%prev_link% %up_link% %next_link%</p><p>No events</p>',
3454 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'bodycopy');
3456 $bodycopy->setAttrValue(
'name',
"Page Contents (No Results)");
3458 if (!$bodycopy->create($copy_link, $page_contents_data)) {
3459 trigger_localised_error(
'CAL0062', E_USER_WARNING);