Example #1
0
function reverse_date($date, $sep)
{
    // get a date bit array
    if (!is_array($date)) {
        $date = date_bits($date, $sep);
    }
    // then reverse
    if (3 == count($date)) {
        $reversed = $date[2] . '-' . $date[1] . '-' . $date[0];
    }
    return $reversed;
}
Example #2
0
 public function get_calendar($calendar, $reload_url, $focus = null)
 {
     /* BENCHMARK */
     $this->benchmark->mark('func_get_calendar_start');
     $this->load->helper('data_helper');
     $this->load->model('slider_model');
     // default focus if not set
     if (null == $focus) {
         $focus = date('m-Y', time());
     }
     // get event array
     $events = json_decode($calendar['event_json'], true);
     // event nodes
     $event_nodes = $this->node_model->get_nodes(array('event.calendar_id' => $calendar['node_id'], 'type' => 'event'), 1);
     $this->event_nodes = $this->node_model->nodes_by_id($event_nodes);
     // set calendar into object and user, event default, colours etc
     $this->calendar = $calendar;
     $this->calendar['user'] = $this->node_model->get_node($this->calendar['user_id'], 'user');
     $event_default = $this->config->item('event_default');
     $this->colours = $event_default['colours'];
     // now
     $this->now = get_now();
     // break date
     $fdate_bits = date_bits($focus, '-');
     // get focus day and start of chunk
     $limit = array();
     if (is_numeric($focus)) {
         $cgran = 'year';
         $focus .= "0101";
         $limit['start'] = $focus;
         $sel_year = substr($limit['start'], 0, 4);
         $limit['end'] = $sel_year . "1232";
         // one day more than December this year will ensure only this year is output
     } elseif (8 == strlen($focus) or 7 == strlen($focus)) {
         $cgran = 'month';
         $month = is_numeric($fdate_bits[0]) ? $fdate_bits[0] : $this->month_names[strtolower($fdate_bits[0])];
         $focus = $fdate_bits[1] . $month . "01";
         $limit['start'] = $focus;
         $limit['end'] = substr($limit['start'], 0, 6) . "32";
         // one day more than any month will ensure only this month is output
     } elseif (10 == strlen($focus) or 11 == strlen($focus)) {
         $cgran = 'day';
         $month = is_numeric($fdate_bits[1]) ? $fdate_bits[1] : $this->month_names[strtolower($fdate_bits[1])];
         $focus = $fdate_bits[2] . $month . $fdate_bits[0];
         $limit['start'] = $focus;
         $limit['end'] = $limit['start'];
     } else {
         $cgran = 'month';
         $focus = str_replace('-', '', $this->now['string']);
         $limit['start'] = substr($focus, 0, 6) . "01";
         $limit['end'] = substr($focus, 0, 6) . "32";
         // one day more than any month will ensure only this month is output
     }
     // open the calendar
     $cale = '';
     $cal['meta_data'] = $calendar;
     $cal['granularity'] = $cgran;
     // back links
     $cal['back_links'] = array();
     if ('month' == $cgran) {
         // get bits
         $yf = $fdate_bits[1];
         // granularity links
         $cal['back_links']['year'] = "/" . $reload_url . "/" . $yf;
     } elseif ('day' == $cgran) {
         // get bits
         $yf = $fdate_bits[2];
         $mf = $fdate_bits[1] . '-' . $fdate_bits[2];
         // granularity links
         $cal['back_links']['year'] = "/" . $reload_url . "/" . $yf;
         $cal['back_links']['month'] = "/" . $reload_url . "/" . $mf;
     }
     // end limit
     // open the main calendar div
     // scroller
     // next and previous links
     $cal['next'] = array();
     $cal['previous'] = array();
     if ('day' == $cgran) {
         // open calendar
         $cale .= "<div id='day_chunk'>";
         // next and previous
         $y = substr($limit['start'], 0, 4);
         $m = substr($limit['start'], 4, 2);
         $d = substr($limit['start'], 6, 2);
         if ('01' == $d && '01' == $m) {
             $n = '02-01-' . $y;
             $l = '31-12-' . ($y - 1);
         } elseif ('31' == $d && '12' == $m) {
             $n = '01-01-' . ($y + 1);
             $l = '30-12-' . $y;
         } else {
             if ('01' == $d) {
                 $lm = $m - 1;
                 if ($lm < 10 ? $lm = '0' . $lm : ($lm = $lm)) {
                 }
                 $n = '02-' . $m . '-' . $y;
                 $l = days_in_month($m - 1, $y) . '-' . $lm . '-' . $y;
             } elseif ($d == days_in_month($m, $y)) {
                 $nm = $m + 1;
                 if ($nm < 10 ? $nm = '0' . $nm : ($nm = $nm)) {
                 }
                 $n = '01-' . $nm . '-' . $y;
                 $l = days_in_month($m, $y) - 1 . '-' . $m . '-' . $y;
             } else {
                 $nd = $d + 1;
                 $ld = $d - 1;
                 if ($nd < 10 ? $nd = '0' . $nd : ($nd = $nd)) {
                 }
                 if ($ld < 10 ? $ld = '0' . $ld : ($ld = $ld)) {
                 }
                 $n = $nd . '-' . $m . '-' . $y;
                 $l = $ld . '-' . $m . '-' . $y;
             }
         }
         // add next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . $n, 'label' => 'tomorrow');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . $l, 'label' => 'yesterday');
     } elseif ('month' == $cgran) {
         // open calendar
         $cale .= "<div id='month_chunk'>";
         // next and previous
         $y = substr($limit['start'], 0, 4);
         $m = substr($limit['start'], 4, 2);
         if (1 == $m) {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = '02';
                 $lm = '12';
             } else {
                 $nm = 'feb';
                 $lm = 'dec';
             }
             $n = $nm . '-' . $y;
             $l = $lm . '-' . ($y - 1);
         } elseif (12 == $m) {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = '01';
                 $lm = '11';
             } else {
                 $nm = 'jan';
                 $lm = 'nov';
             }
             $n = $nm . '-' . ($y + 1);
             $l = $lm . '-' . $y;
         } else {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = $m + 1;
                 $lm = $m - 1;
                 if ($nm < 10 ? $nm = '0' . $nm : ($nm = $nm)) {
                 }
                 if ($lm < 10 ? $lm = '0' . $lm : ($lm = $lm)) {
                 }
             } else {
                 $nm = $this->month_nums[$m + 1];
                 $lm = $this->month_nums[$m - 1];
             }
             $n = $nm . '-' . $y;
             $l = $lm . '-' . $y;
         }
         // add next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . $n, 'label' => 'next month');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . $l, 'label' => 'last month');
     } elseif ('year' == $cgran) {
         // open calendar
         $cale .= "<div id='year_chunk'>";
         // next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . ($sel_year + 1), 'label' => 'next year');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . ($sel_year - 1), 'label' => 'last year');
     }
     // day names in convenient array
     $this->day_names = array('skip_zero', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
     // output chunk
     $cal['cells'] = array();
     foreach ($events as $k => $v) {
         if ($k >= $limit['start'] && $k <= $limit['end']) {
             $cal['cells'][$k] = $v;
             /*dev_dump($k);
               dev_dump($v);*/
             // date details
             /*    $y=substr($k,0,4);
                                     $m=substr($k,4,2);
                                     $d=substr($k,6,2);
                                     $ym=substr($k,0,6);
                                     $ymd=$k;
                                     $day_name=strtolower(format_date($y."-".$m."-".$d,'D'));
                                     $day_num=format_date($y."-".$m."-".$d,'N');
                                     $date=format_date($y."-".$m."-".$d,'d m Y');
                                     $link_date=$d."-".$m."-".$y;
             
                                 // open month
                                     if (in_array($cgran,array('year','month')) &&
                                         '01'==$d)
                                     {
                                         // open the month div
                                             $cale.="<div class='m'>";
             
                                         // if this is a year calendar then show a month name and link
                                             if ('year'==$cgran)
                                             {
                                                 if (1==$this->config->item('full_month_names') ? $mname=$this->month_nums['f'.$m] : $mname=$this->month_nums[$m] );
                                                 $cale.="<span class='mh'><a href='/".$reload_url."/".$this->month_nums[$m]."-".$y."'>".$mname."</a></span>";
                                             }
             
                                         // add a row of day names
                                             $cale.="<div class='dhs'>";
                                             $cale.="<span class='d dh mon'>mon</span>";
                                             $cale.="<span class='d dh tue'>tue</span>";
                                             $cale.="<span class='d dh wed'>wed</span>";
                                             $cale.="<span class='d dh thu'>thu</span>";
                                             $cale.="<span class='d dh fri'>fri</span>";
                                             $cale.="<span class='d dh sat'>sat</span>";
                                             $cale.="<span class='d dh sun'>sun</span>";
                                             $cale.="</div>";
             
                                         // fill the month output with dead cells
                                             for ($x=1;$x<$day_num;$x++)
                                             {
                                                 $cale.="<span class='d dc ".$this->day_names[$x]."'></span>";
                                             }
                                     }
             
                                 // open day and mark now (but not if its a day granularity, then we mark the half hour)
                                     if ( $k==$this->now['numeric'] && $cgran!='day' ? $extra_class=' now ' : $extra_class='' );
             
                                     // set a class if the day has visible events
                                         if (count($v['e'])>0)
                                         {
                                             foreach ($v['e'] as $check_id=>$val)
                                             {
                                                 if (1==$this->event_nodes[$check_id]['visible'])
                                                 {
                                                     $extra_class.='has_e';
                                                     break;
                                                 }
                                             }
                                         }
             
                                     $cale.="<div id='d".$ymd."' class='d ".$day_name." ".$extra_class."'>";
             
                                 // add exclusivity field
                                     $exs='';
                                     if (is_array($v['x']))
                                     {
                                         foreach ($v['x'] as $xk=>$xv)
                                         {
                                             $exs.=$xk.'-'.$xv.'_';
                                         }
                                     }
                                     $cale.="<input id='x".$ymd."' type='hidden' value='".$exs."'/>";
             
                                 // date
                                     if (isset($this->date_formats['calendar']) ? $date_text=date($this->date_formats['calendar'],strtotime($y."-".$m."-".$d)) : $date_text=$day_name." ".$date );
                                     if ('day'==$cgran)
                                     {
                                         $cale.="<span id='date_".$ymd."' class='master_date'>".$date_text."</span>";
                                     }
                                     elseif ('month'==$cgran)
                                     {
                                         if (0==$this->calendar['gran_link_through'])
                                         {
                                             $cale.="<span class='date'>".$date_text."</span>";
                                         }
                                         else
                                         {
                                             $cale.="<span class='date'><a href='/".$reload_url."/".$link_date."'>".$date_text."</a></span>";
                                         }
                                     }
                                     else
                                     {
                                         if (0==$this->calendar['gran_link_through'])
                                         {
                                             $cale.="<span class='date'>".day_suffix($d)."</span>";
                                         }
                                         else
                                         {
                                             $cale.="<span class='date'><a href='/".$reload_url."/".$link_date."'>".$d."</a></span>";
                                         }
                                     }
             
                                 // if the granularity is day by day then we break the day cell down further into half hours
                                 // we then iterate over the events inside this but the day by day calendar only hits the outer loop once
                                 // high detail calendars will be unusual and maybe a bit heavier to handle
                                     if ('day'==$cgran or
                                         1==$calendar['high_detail'])
                                     {
                                         // if marked as 'd' then all day - this may be the case for more than one event on this day so we must check all
                                             foreach ($v['e'] as $meta_id=>$day_event)
                                             {
                                                 // use zero to get the first array element - if it is 'd' (today) then there will only be one
                                                     if ('d'==$day_event['t'][0]['t'])
                                                     {
                                                         // output a cell
                                                             $cale.="<div id='allday_".$meta_id."' class='half_hour all_day'>";
                                                             $cale.="<span class='time'>all day</span>";
                                                             $cale.="</div>";
                                                     }
                                             }
             
                                         // now do all the half hour slots for the day
             
                                             foreach ($this->times as $t)
                                             {
                                                 // time as number
                                                     $tnum=str_replace(':','',$t['time']);
             
                                                 // highlight now
                                                     $extra_class=
                                                     (   $this->now['time_numeric']>=$tnum &&
                                                         $this->now['time_numeric']<=$tnum+29 &&
                                                         $this->now['numeric']==$k) ? ' now ' : '';
             
                                                 // open the half hour output slot - only if there is an event or its high detail
                                                     $cale.="<div id='time_".$tnum."' class='".$extra_class." time_".$tnum."'>";
                                                     $cale.="<span class='time'>".$t['label']."</span>";
                                                     $cale.="</div>";
                                             }
                                     }
                                     else
                                     {
                                         // events - just normal output for months
                                             if ('month'==$cgran)
                                             {
                                                 $view_link="";
                                                 $event_counter=0;
                                             }
                                             else
                                             {
                                                 $cale.="<a class='bview' href='/".$reload_url."/".$link_date."'>vw</a>";
                                             }
                                     }
             
                                 // close day
                                     $cale.="</div>";
             
                                 // close month
                                     if ($d==days_in_month($m,$y))
                                     {
                                         $cale.="</div>";
                                     }*/
         }
     }
     /* BENCHMARK */
     $this->benchmark->mark('func_get_calendar_end');
     return $cal;
 }