]>
git.datanom.net - webcal.git/blob - templates/week_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 WeekView
extends View
{
13 private $year_and_week;
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__&week=__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_WEEK__</td>
29 <td style=\"width: 33%; text-align: right;\">
30 <a href=\"__URL__?year=__N_YEAR__&week=__NEXT__\">
31 <img style=\"border: 0\" src=\"__WEB_ROOT__/pixmaps/right.png\"
32 alt=\"next\"/></a></td>
36 function __construct(Calendar
$calendar = NULL) {
37 $this->url
= parent
::$root.'/navigate/show_week.php';
38 $this->calendar
= $calendar;
39 $this->range
= array();
42 protected function parseDate() {
43 if ($this->year
&& $this->week
) {
45 if ($week < 0 ||
$week > 53) {
46 $week = $this->get_week_number(time());
51 $week = $this->get_week_number(time());
54 $this->privious
= $week - 1;
55 $this->p_year
= $year;
56 if ($this->privious
== 0) {
58 if (date("w", strtotime($this->p_year
."/12/31")) > 3)
63 $this->next
= $week +
1;
64 $this->n_year
= $year;
65 if ($this->next
> 51) {
66 if ($this->get_week_number(strtotime("$year/12/31")) == 1 ||
73 $this->year_and_week
= "$year Week $week";
78 protected function getHead() {
80 $head = str_replace('__URL__', $this->url
, $this->top
);
81 $head = str_replace('__P_YEAR__', $this->p_year
, $head);
82 $head = str_replace('__PRIVIOUS__', $this->privious
, $head);
83 $head = str_replace('__WEB_ROOT__', parent
::$root, $head);
84 $head = str_replace('__YEAR_AND_WEEK__', $this->year_and_week
, $head);
85 $head = str_replace('__N_YEAR__', $this->n_year
, $head);
86 $head = str_replace('__NEXT__', $this->next
, $head);
87 $this->bottom
= $head;
88 return $this->applyLegend() . $head;
91 private function addDates($head) {
92 $timestamp = $this->lastDayInWeek($this->year
, $this->week
);
94 $this->range
['end'] = $timestamp;
96 $date = date('Y/m/d', $timestamp);
97 $timestamp = strtotime('-1 day', $timestamp);
98 $head = substr_replace($head, $date, strrpos($head, '__DATE__'), 8);
101 $this->range
['start'] = $timestamp;
105 private function getCell($events, $day, $progress, $excluded = FALSE) {
109 //print var_export($events,true)."<br/>";
110 $dateFormat = new dateFormat();
111 foreach ($events as $etag =>$infos) {
112 foreach ($infos['dates'] as $time) {
113 //print "{$time['start']}:{$time['end']}<br/>";
114 //print $time['end']."<br/>";
115 CaldavRessource
::fix_allday_event($time['start'],$time['end']);
116 //print $time['end']."<br/>";
117 //print "{$time['start']}:{$time['end']}<br/>";
118 $time['start'] = $dateFormat->UTC2Client($time['start']);
119 $time['end'] = $dateFormat->UTC2Client($time['end']);
120 //print $time['end']."<br/>";
122 $ts = strtotime("+$day day +".parent
::$start_hour." hour",
123 $this->range
['start']);
124 $ical_start = CaldavRessource
::timestamp2ICal($ts);
125 //print parent::$end_hour;
126 $end = (parent
::$end_hour == 24) ?
23 : parent
::$end_hour;
127 $ts = strtotime("+$day day +".$end." hour",
128 $this->range
['start']);
129 $ical_end = CaldavRessource
::timestamp2ICal($ts);
130 $time_start = (strrchr($time['start'], 'Z')) ?
131 trim($time['start'], "Z") : $time['start'];
132 $time_end = (strrchr($time['end'], 'Z')) ?
133 trim($time['end'], "Z") : $time['end'];
134 //print $time_end."\n";
135 $parts = explode("T", $time_end);
136 if (substr($parts[1], 0, 2) == "00") {
137 $parts[1] = "24" . substr($parts[1], 2, 4);
138 $time_end = $parts[0] . "T" . $parts[1];
140 //print "b[$time_start : $time_end]<br/>";
141 //print "a[$ical_start : $ical_end] [$time_start : $time_end]<br/>";
142 if ((CaldavRessource
::cmptime(
143 $ical_start, $time_start) > 0 &&
144 CaldavRessource
::cmpdate($ical_start, $time_end) == 0)
146 (CaldavRessource
::cmptime(
147 $ical_end, $time_end) < 0 &&
148 CaldavRessource
::cmpdate($ical_end, $time_start) == 0)) {
149 //print "b[$ical_start : $ical_end] [$time_start : $time_end]<br/>";
150 if (! in_array($etag, $this->etags
)) {
151 array_push($this->etags
, $etag);
152 $cell = $this->makeEvent($cell, $etag, $infos);
153 //print "$cell<br/>";
154 //print "exc: cell: $etag<br/>";
155 //print "exc: ".var_export($this->etags, true)."<br/>";
160 $ts = strtotime("+$day day +$progress hour",
161 $this->range
['start']);
162 $icalDate = CaldavRessource
::timestamp2ICal($ts, TRUE);
163 //print "$icalDate {$time['start']}:{$time['end']}<br/>";
164 $s_cmp = CaldavRessource
::datecmp($icalDate, $time['start']);
165 $e_cmp = CaldavRessource
::datecmp($icalDate, $time['end']);
166 //print "$s_cmp:$e_cmp<br/>";
167 if ($s_cmp >= 0 && $e_cmp < 0) {
168 //if (! in_array($etag, $this->etags)) {
169 $cell = $this->makeEvent($cell, $etag, $infos);
170 //print "$cell<br/>";
171 //print "inc: cell: $etag<br/>";
172 //print "inc: ".var_export($this->etags, true)."<br/>";
179 return ($cell == '') ?
' ' : $cell;
182 public function getView($year = NULL, $week = NULL) {
185 $calendar = $this->getHead();
186 $calendar .= '<br />';
187 $calendar .= $this->addDates($this->getViewHead('week'));
188 if ($this->get_week_number(time()) == $week ||
$week == NULL) {
190 if ($_SESSION['user_settings']->getStartWeek() === FALSE) {
199 $events = $this->getEvents($this->range
);
201 //var_dump($_SESSION['all_events']);
202 $calendar .= "<tr><td class=\"time\">Excluded</td>\n";
204 for ($d = 0; $d < 7; $d++
) {
205 $cell = $this->getCell($events, $d +
1, 0, TRUE);
206 if ($d == $day && ($year == date('Y') ||
$year == NULL)) {
207 $calendar .= "<td class=\"today\">$cell</td>\n";
210 $calendar .= "<td>$cell</td>\n";
213 // print "clean etags<br/>";
214 // $this->etags = array();
216 array_push($excluded, $this->etags
);
217 $this->etags
= array();
219 $calendar .= '</tr>';
220 for ($i = parent
::$start_hour; $i < parent
::$end_hour; $i++
) {
221 $s_time = ($i < 10) ?
"0$i" : $i;
222 $e_time = ($i < 9) ?
'0'.($i +
1) : ($i +
1);
223 $calendar .= "<tr><td class=\"time\">$s_time - $e_time</td>\n";
224 for ($d = 0; $d < 7; $d++
) {
225 $this->etags
= $excluded[$d];
227 $cell = $this->getCell($events, $d +
1, $progress);
229 if ($d == $day && ($year == date('Y') ||
$year == NULL)) {
230 $calendar .= "<td class=\"today\">$cell</td>\n";
233 $calendar .= "<td>$cell</td>\n";
235 $calendar .= '</tr>';
237 $calendar .= '</table></div>';
238 $calendar .= '<br />';
239 $calendar .= $this->bottom
;
240 //file_put_contents('/tmp/davical.log', $calendar);
244 function get_week_number($timestamp) {
245 return parent
::get_week_number($timestamp);
This page took 0.10885 seconds and 6 git commands to generate.