]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | include_once 'view.class.php'; | |
4 | require_once 'helper.php'; | |
5 | ||
6 | class MonthView extends View { | |
7 | ||
8 | private $view; | |
9 | private $url; | |
10 | private $p_year; | |
11 | private $privious; | |
12 | private $year_and_month; | |
13 | private $n_year; | |
14 | private $next; | |
15 | private $year; | |
16 | private $month; | |
17 | private $range; | |
18 | private $calendar; | |
19 | private $top = "<table style=\"width: 100%\"> | |
20 | <tr> | |
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>"; | |
31 | private $bottom; | |
32 | ||
33 | function __construct(Calendar $calendar = NULL) { | |
34 | $this->url = parent::$root.'/navigate/show_month.php'; | |
35 | $this->calendar = $calendar; | |
36 | $this->range = array(); | |
37 | } | |
38 | ||
39 | protected function parseDate() { | |
40 | if ($this->year && $this->month) { | |
41 | $month = $this->month; | |
42 | if ($month < 0 || $month > 12) { | |
43 | $month = date('n'); | |
44 | } | |
45 | $year = $this->year; | |
46 | } | |
47 | else { | |
48 | $month = date('n'); | |
49 | $year = date('Y'); | |
50 | } | |
51 | ||
52 | $this->privious = $month - 1; | |
53 | $this->p_year = $year; | |
54 | if ($this->privious < 1) { | |
55 | $this->privious = 12; | |
56 | $this->p_year -= 1; | |
57 | } | |
58 | $this->next = $month + 1; | |
59 | $this->n_year = $year; | |
60 | if ($this->next > 12) { | |
61 | $this->next = 1; | |
62 | $this->n_year += 1; | |
63 | } | |
64 | $this->year_and_month = date('F Y', mktime(0,0,0,$month,28,$year)); | |
65 | $this->year = $year; | |
66 | $this->month = $month; | |
67 | } | |
68 | ||
69 | protected function getHead() { | |
70 | $this->parseDate(); | |
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; | |
80 | } | |
81 | ||
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); | |
86 | $cell = ''; | |
87 | if ($events) { | |
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/>"; | |
104 | } | |
105 | } | |
106 | } | |
107 | } | |
108 | return ($cell == '') ? ' ' : $cell; | |
109 | } | |
110 | ||
111 | public function getView($year = NULL, $month = NULL) { | |
112 | $this->year = $year; | |
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; | |
121 | $day = 1; | |
122 | $start = $this->getStartDay($this->year, $this->month); | |
123 | if ($start == 0 && ! parent::$start_sunday) { | |
124 | switch ($days) { | |
125 | case 28: | |
126 | case 29: $stop = 5; break; | |
127 | default: $stop = 6; | |
128 | } | |
129 | } | |
130 | else if ($start == 1 && ! parent::$start_sunday) { | |
131 | switch ($days) { | |
132 | case 28: $stop = 4; break; | |
133 | default: $stop = 5; | |
134 | } | |
135 | } | |
136 | else if ($start == 0 && parent::$start_sunday) { | |
137 | switch ($days) { | |
138 | case 28: $stop = 4; break; | |
139 | default: $stop = 5; | |
140 | } | |
141 | } | |
142 | else if ($start > 4 && parent::$start_sunday) { | |
143 | if ($days > 29) | |
144 | $stop = 6; | |
145 | else | |
146 | $stop = 5; | |
147 | } | |
148 | else $stop = 5; | |
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>"; | |
154 | if ($i == 0) { | |
155 | if ($adjust) { | |
156 | if ($start > 0) { | |
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>"; | |
163 | else | |
164 | $calendar .= "<td>$cell<span class=\"date\">$day</span></td>"; | |
165 | } | |
166 | } | |
167 | else { | |
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>"; | |
173 | else | |
174 | $calendar .= "<td>$cell<span class=\"date\">$day</span></td>"; | |
175 | $day++; | |
176 | } | |
177 | } | |
178 | else { | |
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>"; | |
185 | else | |
186 | $calendar .= "<td>$cell<span class=\"date\">$day</span></td>"; | |
187 | } | |
188 | } | |
189 | } | |
190 | else { | |
191 | $j = $adjust + ($i * 7); | |
192 | for (; $j < ($i * 7) + (7 + $adjust); $j++, $day++) { | |
193 | if ($day > $days) | |
194 | break; | |
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>"; | |
198 | else | |
199 | $calendar .= "<td>$cell<span class=\"date\">$day</span></td>"; | |
200 | } | |
201 | while ($j < ($i * 7) + (7 + $adjust)) { | |
202 | $calendar .= "<td class=\"notused\"> </td>"; | |
203 | $j++; | |
204 | } | |
205 | } | |
206 | $calendar .= "</tr>\n"; | |
207 | } | |
208 | $calendar .= '</table></div>'; | |
209 | $calendar .= '<br />'; | |
210 | $calendar .= $this->bottom; | |
211 | return $calendar; | |
212 | } | |
213 | ||
214 | } |