\"Privious\"/ __YEAR_AND_MONTH__ \"next\"/"; private $bottom; function __construct(Calendar $calendar = NULL) { $this->url = parent::$root.'/navigate/show_month.php'; $this->calendar = $calendar; $this->range = array(); } protected function parseDate() { if ($this->year && $this->month) { $month = $this->month; if ($month < 0 || $month > 12) { $month = date('n'); } $year = $this->year; } else { $month = date('n'); $year = date('Y'); } $this->privious = $month - 1; $this->p_year = $year; if ($this->privious < 1) { $this->privious = 12; $this->p_year -= 1; } $this->next = $month + 1; $this->n_year = $year; if ($this->next > 12) { $this->next = 1; $this->n_year += 1; } $this->year_and_month = date('F Y', mktime(0,0,0,$month,28,$year)); $this->year = $year; $this->month = $month; } protected function getHead() { $this->parseDate(); $head = str_replace('__URL__', $this->url, $this->top); $head = str_replace('__P_YEAR__', $this->p_year, $head); $head = str_replace('__PRIVIOUS__', $this->privious, $head); $head = str_replace('__WEB_ROOT__', parent::$root, $head); $head = str_replace('__YEAR_AND_MONTH__', $this->year_and_month, $head); $head = str_replace('__N_YEAR__', $this->n_year, $head); $head = str_replace('__NEXT__', $this->next, $head); $this->bottom = $head; return $this->applyLegend() . $head; } private function getCell($events, $day) { $ts = gmmktime(0,0,0,$this->month,$day,$this->year); //print date('c', $ts).'
'; $icalDate = CaldavRessource::timestamp2ICal($ts, FALSE); $cell = ''; if ($events) { $dateFormat = new dateFormat(); foreach ($events as $etag =>$infos) { foreach ($infos['dates'] as $time) { //if ('20100619T144500' == $time['start']) //print "$icalDate:{$time['start']}:{$time['end']}
"; $time['start'] = $dateFormat->UTC2Client($time['start']); $time['end'] = $dateFormat->UTC2Client($time['end']); $s_cmp = CaldavRessource::cmpdate( $icalDate, $time['start']); $e_cmp = CaldavRessource::cmpdate( $icalDate, $time['end']); if (($s_cmp >= 0 && $e_cmp <= 0) || ($s_cmp == 0 && $e_cmp > 0) || ($s_cmp > 0 && $e_cmp == 0)) { $cell = $this->makeEvent($cell, $etag, $infos); //print "$cell
"; } } } } return ($cell == '') ? ' ' : $cell; } public function getView($year = NULL, $month = NULL) { $this->year = $year; $this->month = $month; $calendar = $this->getHead(); $calendar .= '
'; $calendar .= $this->getViewHead('month'); $days = date('t', gmmktime(0,0,0,$this->month,1,$this->year)); $this->range['start'] = gmmktime(0,0,0,$this->month,1,$this->year); $this->range['end'] = gmmktime(23,59,59,$this->month,$days,$this->year); $adjust = (parent::$start_sunday) ? 0 : 1; $day = 1; $start = $this->getStartDay($this->year, $this->month); if ($start == 0 && ! parent::$start_sunday) { switch ($days) { case 28: case 29: $stop = 5; break; default: $stop = 6; } } else if ($start == 1 && ! parent::$start_sunday) { switch ($days) { case 28: $stop = 4; break; default: $stop = 5; } } else if ($start == 0 && parent::$start_sunday) { switch ($days) { case 28: $stop = 4; break; default: $stop = 5; } } else if ($start > 4 && parent::$start_sunday) { if ($days > 29) $stop = 6; else $stop = 5; } else $stop = 5; $events = $this->getEvents($this->range); for ($i = 0; $i < $stop; $i++) { $week = $this->get_week_number( mktime(0,0,0,$this->month,($i * 7)+1,$this->year)); $calendar .= "$week"; if ($i == 0) { if ($adjust) { if ($start > 0) { for ($notused = 0; $notused < $start - 1; $notused++) $calendar .= " "; for ($notused = 7 - $notused; $notused > 0; $notused--, $day++) { $cell = $this->getCell($events, $day); if ($this->isToDay($this->year, $this->month, $day)) $calendar .= "$cell$day"; else $calendar .= "$cell$day"; } } else { for ($notused = 0; $notused < 6; $notused++) $calendar .= " "; $cell = $this->getCell($events, $day); if ($this->isToDay($this->year, $this->month, $day)) $calendar .= "$cell$day"; else $calendar .= "$cell$day"; $day++; } } else { for ($notused = $start; $notused > 0; $notused--) $calendar .= ""; for ($notused = 7 - $start; $notused > 0; $notused--, $day++) { $cell = $this->getCell($events, $day); if ($this->isToDay($this->year, $this->month, $day)) $calendar .= "$cell$day"; else $calendar .= "$cell$day"; } } } else { $j = $adjust + ($i * 7); for (; $j < ($i * 7) + (7 + $adjust); $j++, $day++) { if ($day > $days) break; $cell = $this->getCell($events, $day); if ($this->isToDay($this->year, $this->month, $day)) $calendar .= "$cell$day"; else $calendar .= "$cell$day"; } while ($j < ($i * 7) + (7 + $adjust)) { $calendar .= " "; $j++; } } $calendar .= "\n"; } $calendar .= ''; $calendar .= '
'; $calendar .= $this->bottom; return $calendar; } }