]>
git.datanom.net - webcal.git/blob - templates/month_view.class.php
3 include_once 'view.class.php';
4 require_once 'helper.php';
6 class MonthView
extends View
{
12 private $year_and_month;
19 private $top = "<table style=\"width: 100%\">
21 <td style=\"width: 33%; text-align: left;\"><a href=
22 \"__URL__?year=__P_YEAR__&month=__PRIVIOUS__\">
23 <img style=\"border: 0\" src=\"__WEB_ROOT__/pixmaps/left.png\"
24 alt=\"Privious\"/></a></td><td style=\"width: 33%;
25 font-size: 2.5em; font-weight: bold;text-align: center\">
26 __YEAR_AND_MONTH__</td><td style=\"width: 33%;
27 text-align: right;\"><a href=
28 \"__URL__?year=__N_YEAR__&month=__NEXT__\">
29 <img style=\"border: 0\" src=\"__WEB_ROOT__/pixmaps/right.png\"
30 alt=\"next\"/></a></td></tr></table>";
33 function __construct(Calendar
$calendar = NULL) {
34 $this->url
= parent
::$root.'/navigate/show_month.php';
35 $this->calendar
= $calendar;
36 $this->range
= array();
39 protected function parseDate() {
40 if ($this->year
&& $this->month
) {
41 $month = $this->month
;
42 if ($month < 0 ||
$month > 12) {
52 $this->privious
= $month - 1;
53 $this->p_year
= $year;
54 if ($this->privious
< 1) {
58 $this->next
= $month +
1;
59 $this->n_year
= $year;
60 if ($this->next
> 12) {
64 $this->year_and_month
= date('F Y', mktime(0,0,0,$month,28,$year));
66 $this->month
= $month;
69 protected function getHead() {
71 $head = str_replace('__URL__', $this->url
, $this->top
);
72 $head = str_replace('__P_YEAR__', $this->p_year
, $head);
73 $head = str_replace('__PRIVIOUS__', $this->privious
, $head);
74 $head = str_replace('__WEB_ROOT__', parent
::$root, $head);
75 $head = str_replace('__YEAR_AND_MONTH__', $this->year_and_month
, $head);
76 $head = str_replace('__N_YEAR__', $this->n_year
, $head);
77 $head = str_replace('__NEXT__', $this->next
, $head);
78 $this->bottom
= $head;
79 return $this->applyLegend() . $head;
82 private function getCell($events, $day) {
83 $ts = gmmktime(0,0,0,$this->month
,$day,$this->year
);
84 //print date('c', $ts).'<br/>';
85 $icalDate = CaldavRessource
::timestamp2ICal($ts, FALSE);
88 $dateFormat = new dateFormat();
89 foreach ($events as $etag =>$infos) {
90 foreach ($infos['dates'] as $time) {
91 //if ('20100619T144500' == $time['start'])
92 //print "$icalDate:{$time['start']}:{$time['end']}<br/>";
93 $time['start'] = $dateFormat->UTC2Client($time['start']);
94 $time['end'] = $dateFormat->UTC2Client($time['end']);
95 $s_cmp = CaldavRessource
::cmpdate(
96 $icalDate, $time['start']);
97 $e_cmp = CaldavRessource
::cmpdate(
98 $icalDate, $time['end']);
99 if (($s_cmp >= 0 && $e_cmp <= 0) ||
100 ($s_cmp == 0 && $e_cmp > 0) ||
101 ($s_cmp > 0 && $e_cmp == 0)) {
102 $cell = $this->makeEvent($cell, $etag, $infos);
103 //print "$cell<br/>";
108 return ($cell == '') ?
' ' : $cell;
111 public function getView($year = NULL, $month = NULL) {
113 $this->month
= $month;
114 $calendar = $this->getHead();
115 $calendar .= '<br />';
116 $calendar .= $this->getViewHead('month');
117 $days = date('t', gmmktime(0,0,0,$this->month
,1,$this->year
));
118 $this->range
['start'] = gmmktime(0,0,0,$this->month
,1,$this->year
);
119 $this->range
['end'] = gmmktime(23,59,59,$this->month
,$days,$this->year
);
120 $adjust = (parent
::$start_sunday) ?
0 : 1;
122 $start = $this->getStartDay($this->year
, $this->month
);
123 if ($start == 0 && ! parent
::$start_sunday) {
126 case 29: $stop = 5; break;
130 else if ($start == 1 && ! parent
::$start_sunday) {
132 case 28: $stop = 4; break;
136 else if ($start == 0 && parent
::$start_sunday) {
138 case 28: $stop = 4; break;
142 else if ($start > 4 && parent
::$start_sunday) {
149 $events = $this->getEvents($this->range
);
150 for ($i = 0; $i < $stop; $i++
) {
151 $week = $this->get_week_number(
152 mktime(0,0,0,$this->month
,($i * 7)+
1,$this->year
));
153 $calendar .= "<tr><td class=\"weeknum\">$week</td>";
157 for ($notused = 0; $notused < $start - 1; $notused++
)
158 $calendar .= "<td class=\"notused\"> </td>";
159 for ($notused = 7 - $notused; $notused > 0; $notused--, $day++
) {
160 $cell = $this->getCell($events, $day);
161 if ($this->isToDay($this->year
, $this->month
, $day))
162 $calendar .= "<td class=\"today\">$cell<span class=\"date\">$day</span></td>";
164 $calendar .= "<td>$cell<span class=\"date\">$day</span></td>";
168 for ($notused = 0; $notused < 6; $notused++
)
169 $calendar .= "<td class=\"notused\"> </td>";
170 $cell = $this->getCell($events, $day);
171 if ($this->isToDay($this->year
, $this->month
, $day))
172 $calendar .= "<td class=\"today\">$cell<span class=\"date\">$day</span></td>";
174 $calendar .= "<td>$cell<span class=\"date\">$day</span></td>";
179 for ($notused = $start; $notused > 0; $notused--)
180 $calendar .= "<td class=\"notused\"></td>";
181 for ($notused = 7 - $start; $notused > 0; $notused--, $day++
) {
182 $cell = $this->getCell($events, $day);
183 if ($this->isToDay($this->year
, $this->month
, $day))
184 $calendar .= "<td class=\"today\">$cell<span class=\"date\">$day</span></td>";
186 $calendar .= "<td>$cell<span class=\"date\">$day</span></td>";
191 $j = $adjust +
($i * 7);
192 for (; $j < ($i * 7) +
(7 +
$adjust); $j++
, $day++
) {
195 $cell = $this->getCell($events, $day);
196 if ($this->isToDay($this->year
, $this->month
, $day))
197 $calendar .= "<td class=\"today\">$cell<span class=\"date\">$day</span></td>";
199 $calendar .= "<td>$cell<span class=\"date\">$day</span></td>";
201 while ($j < ($i * 7) +
(7 +
$adjust)) {
202 $calendar .= "<td class=\"notused\"> </td>";
206 $calendar .= "</tr>\n";
208 $calendar .= '</table></div>';
209 $calendar .= '<br />';
210 $calendar .= $this->bottom
;
This page took 0.100209 seconds and 6 git commands to generate.