]>
git.datanom.net - webcal.git/blob - templates/day_view.class.php
3 include_once 'view.class.php';
4 require_once 'caldavresource.class.php';
5 include_once 'dateformat.class.php';
6 require_once 'helper.php';
8 class DayView
extends View
{
13 private $year_and_day;
20 private $etags = array();
21 private $top = "<table style=\"width: 100%\">
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>
36 function __construct() {
37 $this->url
= parent
::$root.'/navigate/show_day.php';
38 $this->calendar
= $calendar;
39 $this->range
= array();
42 protected function parseDate() {
43 if ($this->year
&& $this->day
>= 0) {
45 if ($day < 0 ||
$day > 365) {
56 $now = mktime(0, 0, 0, 1, 1, $year);
57 $this->year_and_day
= "$year day ".(date('z', strtotime("+$day days", $now))+
1);
59 $this->privious
= $day - 1;
60 $this->p_year
= $year;
61 if ($this->privious
< 0) {
63 $this->privious
= date('z', mktime(0, 0, 0, 12, 31, $this->p_year
));
65 $this->next
= $day +
1;
66 $this->n_year
= $year;
67 if ($this->next
> date('z', mktime(0, 0, 0, 12, 31, $this->year
))) {
76 protected function getHead() {
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;
89 private function getCell($events, $day, $progress, $excluded = FALSE) {
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']);
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;
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];
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)
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)
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/>";
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/>";
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);
162 return ($cell == '') ?
' ' : $cell;
165 public function getView($year = NULL, $day = NULL) {
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";
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";
193 $calendar .= "<td>$cell</td>\n";
194 $calendar .= '</tr>';
196 $calendar .= '</table></div>';
197 $calendar .= '<br />';
198 $calendar .= $this->bottom
;
This page took 0.095231 seconds and 6 git commands to generate.