calendar
[ class tree: calendar ] [ index: calendar ] [ all elements ]

Source for file Calendar.php

Documentation is available at Calendar.php

  1. <?php
  2. /**
  3.  * @version $Header$
  4.  * @package calendar
  5.  *
  6.  * @copyright Copyright (c) 2004-2006, bitweaver.org
  7.  *  All Rights Reserved. See below for details and a complete list of authors.
  8.  *  Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
  9.  */
  10.  
  11. /**
  12.  * Required setup
  13.  */
  14. include_once( KERNEL_PKG_PATH . 'BitDate.php' );
  15. // set week offset - start with a day other than monday
  16. define( 'WEEK_OFFSET', !empty( $gBitUser->mUserPrefs['calendar_week_offset'] ) ? $gBitUser->mUserPrefs['calendar_week_offset'] : $gBitSystem->getConfig( 'calendar_week_offset', 0 ) );
  17.  
  18. /**
  19.  * @package calendar
  20.  */
  21. class Calendar extends LibertyContent {
  22.  
  23.     var $display_offset;
  24.  
  25.     function Calendar() {
  26.         parent::__construct();
  27.         global $gBitUser;
  28.         $this->mDate = new BitDate(0);
  29.         $this->display_offset = $this->mDate->get_display_offset();
  30.     }
  31.  
  32.     /**
  33.     * get a full list of content for a given time period
  34.     * return array of items
  35.     *
  36.     * The output array will be a set of UTC tagged pages covering the period
  37.     * defined in the $pListHash. Items identified from the list will be tagged to
  38.     * the day identified in the selected timestamp from which the list was built.
  39.     * If the user has selected a local time display, then the day will be the actual
  40.     * UTC day that the item is in, rather than the UTC day of the item. In this way
  41.     * the display view provides a list of locally correct entries for each day.
  42.     **/
  43.  
  44.     function getList( $pListHash ) {
  45.         $ret = array();
  46.  
  47.         $pListHash['include_data'] = TRUE;
  48.         if( !empty( $pListHash['focus_date'] ) ) {
  49.             $calDates = $this->doRangeCalculations( $pListHash );
  50.             $pListHash['time_limit_start'] = $calDates['view_start'] - $this->display_offset;
  51.             $pListHash['time_limit_stop'] = $calDates['view_end'] - $this->display_offset;
  52.         }
  53. //        if (  empty( $pListHash['sort_mode'] ) ) {
  54. //            $pListHash['sort_mode'] = !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'event_time_asc';
  55. //        }
  56.         $pListHash['sort_mode'] = 'event_time_asc';
  57.         $pListHash['time_limit_column'] = preg_replace( "/(_asc$|_desc$)/i", "", $pListHash['sort_mode'] );
  58.  
  59.         if ( empty( $pListHash['user_id'] ) ) {
  60.             $pListHash['user_id'] = !empty( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : NULL;
  61.         }
  62.         if ( !empty( $_REQUEST['order_table'] ) ) {
  63.             $pListHash['order_table'] = $_REQUEST['order_table'];
  64.         }
  65.  
  66.         // Don't think this is required.
  67.         $pListHash['offset'] = 0;
  68.         // There should at least be a preference for this.
  69.         $pListHash['max_records'] = 500;
  70.  
  71.         $res = $this->getContentList( $pListHash );
  72.  
  73.         foreach( $res as $item ) {
  74.             // shift all time data by user timezone offset
  75.             // and then display as a simple UTC time
  76.             $item['timestamp']     = $item[$pListHash['time_limit_column']] + $this->display_offset;
  77.             $item['created']       = $item['created']       + $this->display_offset;
  78.             $item['last_modified'] = $item['last_modified'] + $this->display_offset;
  79.             $item['event_time']       = $item['event_time'] + $this->display_offset;
  80.              $item['parsed'] = $this->parseData($item['data'], $item['format_guid']);
  81.             $dstart = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( "m", $item['timestamp'], true ), $this->mDate->date( "d", $item['timestamp'], true ), $this->mDate->date( "Y", $item['timestamp'], true ) );
  82.             $ret[$dstart][] = $item;
  83.         }
  84.     return $ret;
  85.     }
  86.  
  87.     /**
  88.     * calculate the start and stop time for the current display page
  89.     **/
  90.  
  91.     function doRangeCalculations( $pDateHash ) {
  92.         $focus = $this->mDate->_getdate( $pDateHash['focus_date'], false, true );
  93.  
  94.         if( $pDateHash['view_mode'] == 'month' ) {
  95.             $view_start = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'],     1, $focus['year'] );
  96.             $view_end   = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, 1, $focus['year'] ) - 1;
  97.         } elseif( $pDateHash['view_mode'] == 'week' or $pDateHash['view_mode'] == 'weeklist') {
  98.             if ( $focus['wday'] == 0 ) {
  99.                 $wd = 7 + WEEK_OFFSET;
  100.             } else {
  101.                 $wd  = $focus['wday'] + WEEK_OFFSET;
  102.             }
  103.             // if we are moving out from the selected week, move us back in
  104.             if( $wd > 7 ) {
  105.                 $wd -= 7;
  106.             }
  107.  
  108.             $view_start = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - $wd, $focus['year'] );
  109.             $view_end   = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - $wd + 7, $focus['year'] ) - 1;
  110.         } else {
  111.             $view_start = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday']    , $focus['year'] );
  112.             $view_end   = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 1, $focus['year'] ) - 1;
  113.         }
  114.  
  115.         $start_year  = $this->mDate->date( 'Y', $view_start, true );
  116.         if ( $start_year < 1902 ) {
  117.             $view_start_iso = $view_start  = $this->mDate->date( 'Y-m-d', $view_start, true );
  118.             $view_end_iso = $view_end  = $this->mDate->date( 'Y-m-d', $view_start, true );
  119.             $view_start = 0;
  120.             $view_end = 0;
  121.         }
  122.  
  123.         $ret = array(
  124.             'view_start' => $view_start,
  125.             'view_end' => $view_end,
  126.         );
  127.         // Insert ISO dates if they are set - Used for dates pre 1902
  128.         if ( !empty($view_start_iso) ) {
  129.             $ret['view_start_iso'] = $view_start_iso;
  130.             $ret['view_end_iso'] = $view_end_iso;
  131.         }
  132.         return $ret;
  133.     }
  134.  
  135.     /**
  136.     * prepare ListHash to ensure errorfree usage
  137.     **/
  138.  
  139.     public static function prepGetList( &$pListHash ) {
  140.         $pListHash['include_data'] = TRUE;
  141.         if( !empty( $pListHash['focus_date'] ) ) {
  142.             $calDates = $this->doRangeCalculations( $pListHash );
  143.             $pListHash['time_limit_start'] = $calDates['view_start'] - $this->display_offset;
  144.             $pListHash['time_limit_stop'] = $calDates['view_end'] - $this->display_offset;
  145.         }
  146.         if (  empty( $pListHash['sort_mode'] ) ) {
  147.             $pListHash['sort_mode'] = !empty( $_REQUEST['sort_mode'] ) ? $_REQUEST['sort_mode'] : 'event_time_asc';
  148.         }
  149.         $pListHash['time_limit_column'] = preg_replace( "/(_asc$|_desc$)/i", "", $pListHash['sort_mode'] );
  150.  
  151.         if ( empty( $pListHash['user_id'] ) ) {
  152.             $pListHash['user_id'] = !empty( $_REQUEST['user_id'] ) ? $_REQUEST['user_id'] : NULL;
  153.         }
  154.         if ( !empty( $_REQUEST['order_table'] ) ) {
  155.             $pListHash['order_table'] = $_REQUEST['order_table'];
  156.         }
  157.  
  158.         // Don't think this is required.
  159.         $pListHash['offset'] = 0;
  160.         // There should at least be a preference for this.
  161.         $pListHash['max_records'] = 500;
  162.  
  163.         LibertyContent::prepGetList( $pListHash );
  164.         return TRUE;
  165.     }
  166.  
  167.     function buildDay( $pDateHash ) {
  168.         global $gBitSystem, $gBitUser;
  169.         $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true );
  170.  
  171.         $ret = array();
  172.         if( $pDateHash['view_mode'] == 'day' ) {
  173.             // calculare what the visible day view range is
  174.             $day_start   = isset( $gBitUser->mUserPrefs['calendar_day_start'] ) ? $gBitUser->mUserPrefs['calendar_day_start'] : $gBitSystem->getConfig( 'calendar_day_start', 0 );
  175.             $day_end     = isset( $gBitUser->mUserPrefs['calendar_day_end'] ) ? $gBitUser->mUserPrefs['calendar_day_end'] : $gBitSystem->getConfig( 'calendar_day_end', 24 );
  176.             $start_time  = $this->mDate->mktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] ) + ( 60 * 60 * $day_start );
  177.             $stop_time   = $this->mDate->mktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 1, $focus['year'] ) - ( 60 * 60 * ( 24 - $day_end ) );
  178.             $hours_count = ( $stop_time - $start_time ) / ( 60 * 60 );
  179.  
  180.             // allow for custom time intervals
  181.             $hour_fraction = !empty( $gBitUser->mUserPrefs['calendar_hour_fraction'] ) ? $gBitUser->mUserPrefs['calendar_hour_fraction'] : $gBitSystem->getConfig( 'calendar_hour_fraction', 1 );
  182.             $row_count = $hours_count * $hour_fraction;
  183.             $start_time_info = $this->mDate->getdate( $start_time, false, true );
  184.             $hour = $start_time_info['hours'] - 1;
  185.             $mins = 0;
  186.             for( $i = 0; $i < $row_count; $i++ ) {
  187.                 if( !( $i % $hour_fraction ) ) {
  188.                     // set vars
  189.                     $hour++;
  190.                     $mins = 0;
  191.                 }
  192.                 $ret[$i]['time'] = $this->mDate->gmmktime( $hour, $mins, 0, $focus['mon'], $focus['mday'], $focus['year'] );
  193.                 $mins += 60 / $hour_fraction;
  194.             }
  195.             // calendar data is added below
  196.         }
  197.         return $ret;
  198.     }
  199.  
  200.     /**
  201.      * build an array of unix UTC timestamps relating to the current
  202.      * calendar focus. This provides a fixed basis from which to apply local
  203.      * offsets provided by tz_offset information. Daylight saving information
  204.      * is not available via this route!
  205.      **/
  206.  
  207.     function buildCalendarNavigation( $pDateHash ) {
  208.         global $gBitUser, $gBitSystem;
  209.         $today = $this->mDate->getdate( time(), false, true );
  210.         $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true );
  211.  
  212.         $ret = array(
  213.             'before' => array(
  214.                 'day'   => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - 1, $focus['year'] ),
  215.                 'week'  => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] - 7, $focus['year'] ),
  216.                 'month' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] - 1, $focus['mday'], $focus['year'] ),
  217.                 'year'  => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] - 1 ),
  218.             ),
  219.             'after' => array(
  220.                 'day'   => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 1, $focus['year'] ),
  221.                 'week'  => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'] + 7, $focus['year'] ),
  222.                 'month' => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, $focus['mday'], $focus['year'] ),
  223.                 'year'  => $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $focus['mday'], $focus['year'] + 1 ),
  224.             ),
  225.             'focus_month' => $focus['mon'],
  226.             'focus_year' => $focus['year'],
  227.             'focus_date' => $focus[0],
  228.             'today'   => $this->mDate->gmmktime( 0, 0, 0, $today['mon'], $today['mday'], $today['year'] ),
  229.             'tz_flag' => $gBitUser->getPreference('site_display_utc', "Local"),
  230.             'display_focus_date' => $focus[0],
  231.         );
  232.  
  233.         return $ret;
  234.     }
  235.  
  236.     /**
  237.      * build a two dimensional array of unix timestamps
  238.      * The timestamps are either UTC or display local time depending on the
  239.      * setting of the current users display time offset
  240.      * mktime SHOULD NOT BE USED since it offsets the times based on server
  241.      * timezone and daylight saving, but the USERS daylight saving information
  242.      * is not available, which will cause some problems!
  243.      **/
  244.  
  245.     function buildMonth( $pDateHash ) {
  246.         global $gBitSmarty;
  247.  
  248.         $focus = $this->mDate->getdate( $pDateHash['focus_date'], false, true );
  249.  
  250.         $prev_month_end      = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'],     0, $focus['year'] );
  251.         $next_month_begin = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, 1, $focus['year'] );
  252.  
  253.         $prev_month_end_info = $this->mDate->getdate( $prev_month_end, false, true );
  254.         $prev_month = $prev_month_end_info['mon'];
  255.         $prev_month_year = $prev_month_end_info['year'];
  256.  
  257.         // Build a two-dimensional array of UNIX timestamps.
  258.         $cal = array();
  259.  
  260.         // Start the first row with the final day( s ) of the previous month.
  261.         $week = array();
  262.         $month_begin = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], WEEK_OFFSET, $focus['year'] );
  263.         $month_begin_day_of_week = $this->mDate->dayOfWeek( $focus['year'], $focus['mon'], WEEK_OFFSET );
  264.         $days_in_prev_month = $this->mDate->daysInMonth( $prev_month, $prev_month_year );
  265.  
  266.         // Fill out the first row with the last day( s ) of the previous month.
  267.         for( $day_of_week = 0; $day_of_week < $month_begin_day_of_week; $day_of_week++ ) {
  268.             $_day = $days_in_prev_month - $month_begin_day_of_week + $day_of_week + 1;
  269.             $week[]['day'] = $this->mDate->mktime( 0, 0, 0, $prev_month, $_day, $prev_month_year );
  270.         }
  271.  
  272.         // Fill in the days of the selected month.
  273.         $days_in_month = $this->mDate->daysInMonth( $focus['mon'], $focus['year'] );
  274.         for( $i = 1; $i <= $days_in_month; $i++ ) {
  275.             if( $day_of_week == 7 ) {
  276.                 $calendar[$this->mDate->weekOfYear( $focus['year'], $focus['mon'], $i )] = $week;
  277.  
  278.                 // re-initialize $day_of_week and $week
  279.                 $day_of_week = 0;
  280.                 $week = array();
  281.             }
  282.             $week[]['day'] = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'], $i, $focus['year'] );
  283.             $day_of_week++;
  284.         }
  285.  
  286.         // Fill out the last row with the first day( s ) of the next month.
  287.         for( $j = 1; $day_of_week < 7; $j++, $day_of_week++ ) {
  288.             $week[]['day'] = $this->mDate->gmmktime( 0, 0, 0, $focus['mon'] + 1, $j, $focus['year'] );
  289.         }
  290.         $week_num = $this->mDate->weekOfYear( $focus['year'], $focus['mon'], $days_in_month + $j );
  291.         $calendar[$week_num] = $week;
  292.  
  293.         // Modify offset to fix roll over on week numbers
  294.         // This is required because the week numbers are calculated for Sunday
  295.         // Offseting the result in BitDate is the real solution
  296.         if ( WEEK_OFFSET == 7 ) $offset = $focus['mday'] + 1;
  297.         else $offset = $focus['mday'] + 1 + WEEK_OFFSET;
  298.         // this week number has to be calculated, since the cal start can be configured
  299.         $week_num = $this->mDate->weekOfYear( $focus['year'], $focus['mon'], $offset );
  300.  
  301.         // if we only want to see a weeks / days worth of data, nuke all xs data
  302.         if( $pDateHash['view_mode'] == 'week' or $pDateHash['view_mode'] == 'weeklist' ) {
  303.             $cal = $calendar[$week_num];
  304.             $calendar = array();
  305.             $calendar[$week_num] = $cal;
  306.         } elseif( $pDateHash['view_mode'] == 'day' ) {
  307.             $calendar = array();
  308.             $calendar[$week_num][]['day'] = $pDateHash['focus_date'];
  309.         }
  310.  
  311.         return $calendar;
  312.     }
  313.  
  314.     // Setup the content types for use in the calendar.
  315.     function setupContentTypes() {
  316.         global $gLibertySystem, $gBitSmarty, $gBitSystem;
  317.         foreach( $gLibertySystem->mContentTypes as $cName => $cType ) {
  318.             if ( $gBitSystem->isPackageActive( $cType['handler_package'] ) ) {
  319.                 $contentTypes[$cType['content_type_guid']] = $gLibertySystem->getContentTypeName( $cType['content_type_guid'] );
  320.             }
  321.         }
  322.         asort($contentTypes);
  323.         $gBitSmarty->assign( 'calContentTypes', $contentTypes );
  324.     }
  325.  
  326.     // Setup the day names for use in the calendar
  327.     function setupDayNames() {
  328.         global $gBitSmarty;
  329.  
  330.         // set up daynames for the calendar
  331.         $dayNames = array(
  332.             tra( "Monday" ),
  333.             tra( "Tuesday" ),
  334.             tra( "Wednesday" ),
  335.             tra( "Thursday" ),
  336.             tra( "Friday" ),
  337.             tra( "Saturday" ),
  338.             tra( "Sunday" ),
  339.             );
  340.  
  341.         // depending on what day we want to view first, we need to adjust the dayNames array
  342.         for( $i = 0; $i < WEEK_OFFSET; $i++ ) {
  343.             $pop = array_pop( $dayNames );
  344.             array_unshift( $dayNames, $pop );
  345.         }
  346.         $gBitSmarty->assign( 'dayNames', $dayNames );
  347.     }
  348.  
  349.     function processRequestHash(&$pRequest, &$pStore) {
  350.         global $gBitUser;
  351.         if( !empty( $pRequest["content_type_guid"] ) ) {
  352.             if( $gBitUser->isRegistered() ) {
  353.                 $gBitUser->storePreference( 'calendar_default_guids', serialize( $pRequest['content_type_guid'] ) );
  354.             }
  355.             $pStore['content_type_guid'] = $pRequest["content_type_guid"];
  356.         } elseif( !isset( $pStore['content_type_guid'] ) && $gBitUser->getPreference( 'calendar_default_guids' ) && $gBitUser->isRegistered() ) {
  357.             $pStore['content_type_guid'] = unserialize( $gBitUser->getPreference( 'calendar_default_guids' ) );
  358.         } elseif( !isset( $pStore['content_type_guid'] ) ) {
  359.             $pStore['content_type_guid'] = array();
  360.         } elseif( isset( $pRequest["refresh"] ) && !isset( $pRequest["content_type_guid"] ) ) {
  361.             $pStore['content_type_guid'] = array();
  362.         }
  363.  
  364.         // set up the todate
  365.         if( !empty( $pRequest["todate"] ) ) {
  366.             // clean up todate. who knows where this has come from
  367.             if ( is_numeric( $pRequest['todate'] ) ) {
  368.                 $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm', $pRequest['todate'], true ), $this->mDate->date( 'd', $pRequest['todate'], true ), $this->mDate->date( 'Y', $pRequest['todate'], true ) );
  369.             } else {
  370.                 $pStore['focus_date'] = $pRequest['todate'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date2( 'm', $pRequest['todate'], true ), $this->mDate->date2( 'd', $pRequest['todate'], true ), $this->mDate->date2( 'Y', $pRequest['todate'], true ) );
  371.             }
  372.         } elseif( !empty( $pStore['focus_date'] ) ) {
  373.             $pRequest["todate"] = $pStore['focus_date'];
  374.         } else {
  375.             $pStore['focus_date'] = $this->mDate->gmmktime( 0, 0, 0, $this->mDate->date( 'm' ), $this->mDate->date( 'd' ), $this->mDate->date( 'Y' ) );
  376.             $pRequest["todate"] = $pStore['focus_date'];
  377.         }
  378.  
  379.         $focus = $pRequest['todate'];
  380.         if( !empty( $pRequest["view_mode"] ) ) {
  381.             $pStore['view_mode'] = $pRequest["view_mode"];
  382.         } elseif( empty( $pStore['view_mode'] ) ) {
  383.             $pStore['view_mode'] = 'month';
  384.         }
  385.     }
  386.  
  387.     function getEvents(&$pListHash) {
  388.         global $gBitSystem, $gLibertySystem;
  389.  
  390.         $bitEvents = array();
  391.         if ( !empty( $pListHash['content_type_guid'] ) ) {
  392.             // Verify that the type is still active
  393.             foreach ( $pListHash['content_type_guid'] as $index => $type ) {
  394.                 if ( !$gBitSystem->isPackageActive( $gLibertySystem->mContentTypes[$type]['handler_package'] ) ) {
  395.                     unset( $pListHash['content_type_guid'][$index] );
  396.                 }
  397.                 if ( !empty( $pListHash['content_type_guid'] ) ) {
  398.                     $bitEvents = $this->getList( $pListHash );
  399.                 }
  400.             }
  401.         }
  402.  
  403.         return $bitEvents;
  404.     }
  405.  
  406.     function buildCalendar(&$pListHash, &$pDateHash) {
  407.         global $gBitSmarty, $gBitSystem;
  408.  
  409.         if( isset($pDateHash['focus_date']) && !isset($pListHash['focus_date']) ) {
  410.             $pListHash['focus_date'] = $pDateHash['focus_date'];
  411.         }
  412.         if( isset($pDateHash['view_mode']) && !isset($pListHash['view_mode']) ) {
  413.             $pListHash['view_mode'] = $pDateHash['view_mode'];
  414.         }
  415.         $bitEvents = $this->getEvents($pListHash);
  416.  
  417.         $gBitSmarty->assign( 'navigation', $this->buildCalendarNavigation( $pDateHash ) );
  418.         $calMonth = $this->buildMonth( $pDateHash );
  419.         $calDay = $this->buildDay( $pDateHash );
  420.  
  421.         foreach( $calMonth as $w => $week ) {
  422.             foreach( $week as $d => $day ) {
  423.                 $dayEvents = array();
  424.                 if( !empty( $bitEvents[$day['day']] ) ) {
  425.                     $i = 0;
  426.                     foreach( $bitEvents[$day['day']] as $bitEvent ) {
  427.                         $bitEvent['parsed_data'] = $this->parseData($bitEvent);
  428.                         $dayEvents[$i] = $bitEvent;
  429.                         if (!$gBitSystem->isFeatureActive('calendar_ajax_popups')) {
  430.                             $gBitSmarty->assign( 'cellHash', $bitEvent );
  431.                             $dayEvents[$i]["over"] = $gBitSmarty->fetch( "bitpackage:calendar/calendar_box.tpl" );
  432.                         }
  433.  
  434.                         // populate $calDay array with events
  435.                         if( !empty ( $bitEvent ) && $pDateHash['view_mode'] == 'day' ) {
  436.                             foreach( $calDay as $key => $t ) {
  437.                                 // special case - last item entry in array - check this first
  438.  
  439.                                 if( $bitEvent['timestamp'] >= $calDay[$key]['time']  && empty( $calDay[$key + 1]['time'] ) ) {
  440.                                     $calDay[$key]['items'][] = $dayEvents[$i];
  441.                                 } elseif( $bitEvent['timestamp'] >= $calDay[$key]['time'] && $bitEvent['timestamp'] < $calDay[$key + 1]['time'] ) {
  442.                                     $calDay[$key]['items'][] = $dayEvents[$i];
  443.                                 }
  444.                             }
  445.                         }
  446.  
  447.                         $i++;
  448.                     }
  449.                 }
  450.                 if( !empty( $dayEvents ) ) {
  451.                     $calMonth[$w][$d]['items'] = array_values( $dayEvents );
  452.                 }
  453.             }
  454.         }
  455.         $gBitSmarty->assign_by_ref( 'calDay', $calDay );
  456.         $gBitSmarty->assign_by_ref( 'calMonth', $calMonth );
  457.     }
  458.  
  459.     function setupCalendar($pShowContentOptions = TRUE) {
  460.         global $gBitThemes, $gBitSmarty, $gBitSystem;
  461.         if ( $pShowContentOptions ) {
  462.             $this->setupContentTypes();
  463.         }
  464.         $this->setupDayNames();
  465.  
  466.         if ($gBitSystem->isFeatureActive('calendar_ajax_popups')) {
  467.             $gBitThemes->loadAjax( 'mochikit' );
  468.         }
  469.  
  470.         // TODO: make this a pref
  471.         $gBitSmarty->assign( 'trunc', $gBitSystem->getConfig( 'title_truncate', 32 ) );
  472.     }
  473.  
  474.     // Display the actual calendar doing any other work required for the template
  475.     function display($pTitle, $pShowContentOptions = TRUE, $pBaseUrl=NULL) {
  476.         global $gBitSystem, $gBitSmarty;
  477.  
  478.         $this->setupCalendar($pShowContentOptions);
  479.  
  480.         // A default base for the calendar
  481.         if( empty($pBaseUrl) ){
  482.             $pBaseUrl = CALENDAR_PKG_URL.'index.php';
  483.         }
  484.         // Asssign it so templates see it.
  485.         $gBitSmarty->assign('baseCalendarUrl', $pBaseUrl);
  486.  
  487.         $gBitSystem->display( 'bitpackage:calendar/calendar.tpl', $pTitle , array( 'display_mode' => 'display' ));
  488.  
  489.     }
  490. }
  491. ?>

Documentation generated on Wed, 29 Jul 2015 13:56:13 +0000 by phpDocumentor 1.5.0-lsces