]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | include_once 'view.class.php'; | |
4 | require_once 'caldavresource.class.php'; | |
5 | include_once 'dateformat.class.php'; | |
6 | require_once 'helper.php'; | |
7 | ||
8 | class DayView extends View { | |
9 | ||
10 | private $url; | |
11 | private $p_year; | |
12 | private $privious; | |
13 | private $year_and_day; | |
14 | private $n_year; | |
15 | private $next; | |
16 | private $year; | |
17 | private $day; | |
18 | private $range; | |
19 | private $calendar; | |
20 | private $etags = array(); | |
21 | private $top = "<table style=\"width: 100%\"> | |
22 | <tr> | |
23 | <td style=\"width: 33%; text-align: left;\"><a href= | |
24 | \"__URL__?year=__P_YEAR__&day=__PRIVIOUS__\"> | |
25 | <img style=\"border: 0\" src=\"__WEB_ROOT__/pixmaps/left.png\" | |
26 | alt=\"Privious\"/></a></td> | |
27 | <td style=\"width: 33%; font-size: 2.5em; font-weight: bold; | |
28 | text-align: center\">__YEAR_AND_DAY__</td> | |
29 | <td style=\"width: 33%; text-align: right;\"> | |
30 | <a href=\"__URL__?year=__N_YEAR__&day=__NEXT__\"> | |
31 | <img style=\"border: 0\" src=\"__WEB_ROOT__/pixmaps/right.png\" | |
32 | alt=\"next\"/></a></td> | |
33 | </tr></table>"; | |
34 | private $bottom; | |
35 | ||
36 | function __construct() { | |
37 | $this->url = parent::$root.'/navigate/show_day.php'; | |
38 | $this->calendar = $calendar; | |
39 | $this->range = array(); | |
40 | } | |
41 | ||
42 | protected function parseDate() { | |
43 | if ($this->year && $this->day >= 0) { | |
44 | $day = $this->day; | |
45 | if ($day < 0 || $day > 365) { | |
46 | $day = date('z'); | |
47 | $year = date('Y'); | |
48 | } | |
49 | else | |
50 | $year = $this->year; | |
51 | } | |
52 | else { | |
53 | $day = date('z'); | |
54 | $year = date('Y'); | |
55 | } | |
56 | $now = mktime(0, 0, 0, 1, 1, $year); | |
57 | $this->year_and_day = "$year day ".(date('z', strtotime("+$day days", $now))+1); | |
58 | ||
59 | $this->privious = $day - 1; | |
60 | $this->p_year = $year; | |
61 | if ($this->privious < 0) { | |
62 | $this->p_year -= 1; | |
63 | $this->privious = date('z', mktime(0, 0, 0, 12, 31, $this->p_year)); | |
64 | } | |
65 | $this->next = $day + 1; | |
66 | $this->n_year = $year; | |
67 | if ($this->next > date('z', mktime(0, 0, 0, 12, 31, $this->year))) { | |
68 | $this->next = 0; | |
69 | $this->n_year += 1; | |
70 | } | |
71 | ||
72 | $this->year = $year; | |
73 | $this->day = $day; | |
74 | } | |
75 | ||
76 | protected function getHead() { | |
77 | $this->parseDate(); | |
78 | $head = str_replace('__URL__', $this->url, $this->top); | |
79 | $head = str_replace('__P_YEAR__', $this->p_year, $head); | |
80 | $head = str_replace('__PRIVIOUS__', $this->privious, $head); | |
81 | $head = str_replace('__WEB_ROOT__', parent::$root, $head); | |
82 | $head = str_replace('__YEAR_AND_DAY__', $this->year_and_day, $head); | |
83 | $head = str_replace('__N_YEAR__', $this->n_year, $head); | |
84 | $head = str_replace('__NEXT__', $this->next, $head); | |
85 | $this->bottom = $head; | |
86 | return $this->applyLegend() . $head; | |
87 | } | |
88 | ||
89 | private function getCell($events, $day, $progress, $excluded = FALSE) { | |
90 | $cell = ''; | |
91 | //$etags = array(); | |
92 | if ($events) { | |
93 | $now = mktime(0, 0, 0, 1, 1, $this->year); | |
94 | $ts = strtotime("+$day days +$progress hours", $now); | |
95 | $ical_start = CaldavRessource::timestamp2ICal($ts, TRUE); | |
96 | $ts = strtotime("+$day days +".($progress+1)." hours", $now); | |
97 | $ical_end = CaldavRessource::timestamp2ICal($ts, TRUE); | |
98 | $dateFormat = new dateFormat(); | |
99 | foreach ($events as $etag =>$infos) { | |
100 | foreach ($infos['dates'] as $time) { | |
101 | CaldavRessource::fix_allday_event($time['start'],$time['end']); | |
102 | $time['start'] = $dateFormat->UTC2Client($time['start']); | |
103 | $time['end'] = $dateFormat->UTC2Client($time['end']); | |
104 | if ($excluded) { | |
105 | $ts = strtotime( | |
106 | "+$day days +".parent::$start_hour." hours", $now); | |
107 | $parent_start = CaldavRessource::timestamp2ICal($ts, TRUE); | |
108 | $end = (parent::$end_hour == 24) ? 23 : parent::$end_hour; | |
109 | $ts = strtotime( | |
110 | "+$day days +".$end." hours", $now); | |
111 | $parent_end = CaldavRessource::timestamp2ICal($ts, TRUE); | |
112 | $time_start = (strrchr($time['start'], 'Z')) ? | |
113 | trim($time['start'], "Z") : $time['start']; | |
114 | $time_end = (strrchr($time['end'], 'Z')) ? | |
115 | trim($time['end'], "Z") : $time['end']; | |
116 | $parts = explode("T", $time_end); | |
117 | if (substr($parts[1], 0, 2) == "00") { | |
118 | $parts[1] = "24" . substr($parts[1], 2, 4); | |
119 | $time_end = $parts[0] . "T" . $parts[1]; | |
120 | } | |
121 | //print substr($time_end, 0, 2)."b[$parent_start : $parent_end] [$time_start : $time_end]" . CaldavRessource::cmptime( | |
122 | // $parent_end, $time_end) ."<br/>"; | |
123 | /*if ((CaldavRessource::cmptime( | |
124 | $parent_start, $time_start) > 0 && | |
125 | CaldavRessource::cmpdate($parent_start, $time_start) == 0) | |
126 | || | |
127 | (CaldavRessource::cmptime( | |
128 | $parent_end, $time_end) < 0 && | |
129 | CaldavRessource::cmpdate($parent_end, $time_end) == 0)) {*/ | |
130 | if ((CaldavRessource::cmptime( | |
131 | $parent_start, $time_start) > 0 && | |
132 | CaldavRessource::cmpdate($parent_start, $time_end) == 0) | |
133 | || | |
134 | (CaldavRessource::cmptime( | |
135 | $parent_end, $time_end) < 0 && | |
136 | CaldavRessource::cmpdate($parent_end, $time_start) == 0)) { | |
137 | if (! in_array($etag, $this->etags)) { | |
138 | array_push($this->etags, $etag); | |
139 | $cell = $this->makeEvent($cell, $etag, $infos); | |
140 | //print "$cell<br/>"; | |
141 | } | |
142 | } | |
143 | //print "a[$parent_start : $parent_end] [$time_start : $time_end] parent_start:time_start" . CaldavRessource::cmptime( | |
144 | // $parent_start, $time_start) ."<br/>"; | |
145 | //print "a[$parent_start : $parent_end] [$time_start : $time_end] parent_end:time_end" . CaldavRessource::cmptime( | |
146 | // $parent_end, $time_end) ."<br/>"; | |
147 | } | |
148 | else { | |
149 | //print "$ical_start:$ical_end:{$time['start']}:{$time['end']}<br/>"; | |
150 | $s_cmp = CaldavRessource::datecmp($ical_start, $time['start']); | |
151 | $e_cmp = CaldavRessource::datecmp($ical_start, $time['end']); | |
152 | if ($s_cmp >= 0 && $e_cmp < 0) { | |
153 | // if (! in_array($etag, $this->etags)) { | |
154 | $cell = $this->makeEvent($cell, $etag, $infos); | |
155 | //print "$cell"; | |
156 | // } | |
157 | } | |
158 | } | |
159 | } | |
160 | } | |
161 | } | |
162 | return ($cell == '') ? ' ' : $cell; | |
163 | } | |
164 | ||
165 | public function getView($year = NULL, $day = NULL) { | |
166 | $this->year = $year; | |
167 | $this->day = $day; | |
168 | $calendar = $this->getHead(); | |
169 | $calendar .= '<br />'; | |
170 | $calendar .= str_replace('__DAY__', $this->dateFromDayInYear( | |
171 | $this->year, $this->day, $head), $this->getViewHead('day')); | |
172 | $now = mktime(0, 0, 0, 1, 1, $this->year); | |
173 | $this->range['start'] = strtotime("+".($this->day - 1)." days", $now); | |
174 | $this->range['end'] = strtotime("+".$this->day." days", $now); | |
175 | $events = $this->getEvents($this->range); | |
176 | $calendar .= "<tr><td class=\"time\">Excluded</td>\n"; | |
177 | $cell = $this->getCell($events, $this->day, 0, TRUE); | |
178 | if ($this->day == date('z')) { | |
179 | $calendar .= "<td class=\"today\">$cell</td>\n"; | |
180 | } | |
181 | else | |
182 | $calendar .= "<td>$cell</td>\n"; | |
183 | $calendar .= '</tr>'; | |
184 | for ($i = parent::$start_hour; $i < parent::$end_hour; $i++) { | |
185 | $s_time = ($i < 10) ? "0$i" : $i; | |
186 | $e_time = ($i < 9) ? '0'.($i + 1) : ($i + 1); | |
187 | $calendar .= "<tr><td class=\"time\">$s_time - $e_time</td>\n"; | |
188 | $cell = $this->getCell($events, $this->day, $i); | |
189 | if ($this->day == date('z')) { | |
190 | $calendar .= "<td class=\"today\">$cell</td>\n"; | |
191 | } | |
192 | else | |
193 | $calendar .= "<td>$cell</td>\n"; | |
194 | $calendar .= '</tr>'; | |
195 | } | |
196 | $calendar .= '</table></div>'; | |
197 | $calendar .= '<br />'; | |
198 | $calendar .= $this->bottom; | |
199 | return $calendar; | |
200 | } | |
201 | ||
202 | } |