]>
git.datanom.net - webcal.git/blob - templates/view.class.php
4 require_once 'user_validate.php';
8 include_once 'config.inc.php';
9 require_once 'helper.php';
11 include_once 'month_view.class.php';
12 include_once 'week_view.class.php';
13 include_once 'day_view.class.php';
14 include_once 'calendar.class.php';
17 protected static $start_sunday;
18 protected static $root;
19 protected static $start_hour;
20 protected static $end_hour;
21 private $heading = "<div id=\"events\"><table><tr>";
22 private $view_head_sunday = "
23 <th class=\"event\">Sunday</th>
24 <th class=\"event\">Monday</th>
25 <th class=\"event\">Tuesday</th>
26 <th class=\"event\">Wednedsday</th>
27 <th class=\"event\">Thursday</th>
28 <th class=\"event\">Friday</th>
29 <th class=\"event\">Saturday</th>
31 private $view_head_monday = "
32 <th class=\"event\">Monday</th>
33 <th class=\"event\">Tuesday</th>
34 <th class=\"event\">Wednedsday</th>
35 <th class=\"event\">Thursday</th>
36 <th class=\"event\">Friday</th>
37 <th class=\"event\">Saturday</th>
38 <th class=\"event\">Sunday</th>
40 private $view_head_day = "
41 <th class=\"day_event\">__DAY__</th>
44 function __construct($root, $start_hour, $end_hour, $start_sunday = FALSE) {
45 self
::$start_sunday = $start_sunday;
47 self
::$start_hour = $start_hour;
48 self
::$end_hour = $end_hour;
51 protected function applyLegend() {
52 $calenders = $_SESSION['user_settings']->getCalendars();
53 $legend = '<p style="text-align: center">';
54 foreach ($calenders as $calender) {
55 $legend .= '[<span style="background: ' . $calender->color
.
56 '"> </span>:' . $calender->name
. ']';
60 <p style="text-align: center">
61 Events outside configured range is only displayed
62 when Day or Week view is active
68 protected function getViewHead($kindOf) {
71 $return = $this->heading.'<th>Week</th>';
72 if (self::$start_sunday)
73 $return .= $this->view_head_sunday;
75 $return .= $this->view_head_monday;
79 if (self::$start_sunday) {
80 $head = str_replace('</th>', '<br/>__DATE__</th>',
81 $this->view_head_sunday);
84 $head = str_replace('</th>', '<br/>__DATE__</th>',
85 $this->view_head_monday);
87 $head = '<th>Time</th>' . $head;
88 return $this->heading . $head;
91 $return = $this->heading . '<th>Time</th>';
92 return $return . $this->view_head_day;
94 default: trigger_error("$kindOf: ['month', 'week', 'day']", E_USER_ERROR);
99 * Function get_week_number which returns the week number of the
100 * given date according to ISO 8601-1988
101 * http://www.php.happycodings.com/Date_Time/code22.html
103 protected function is_leap_year($year) {
104 if ((($year % 4) == 0 and ($year % 100)!=0) or ($year % 400)==0) {
111 /* define ISO_WEEK_START_WDAY 1 // Monday
112 * define ISO_WEEK1_WDAY 4 // Thursday
113 * define YDAY_MINIMUM (-366)
114 * int big_enough_multiple_of_7 = (-YDAY_MINIMUM / 7 + 2) * 7;
115 * return (yday - (yday - wday + ISO_WEEK1_WDAY +
116 * big_enough_multiple_of_7) % 7 + ISO_WEEK1_WDAY -
117 * ISO_WEEK_START_WDAY);
119 private function iso_week_days($yday, $wday) {
120 return $yday - (($yday - $wday + 382) % 7) + 3;
123 protected function get_week_number($timestamp) {
124 $d = getdate($timestamp);
125 $days = $this->iso_week_days($d[ "yday"], $d[ "wday"]);
128 $d[ "yday"] += 365 + $this->is_leap_year(--$d[ "year"]);
129 $days = $this->iso_week_days($d[ "yday"], $d[ "wday"]);
131 $d[ "yday"] -= 365 + $this->is_leap_year($d[ "year"]);
132 $d2 = $this->iso_week_days($d[ "yday"], $d[ "wday"]);
140 if ($_SESSION['user_settings']->getStartWeek() === true && $day == 0)
142 return (int)($days / 7) + $adjust;
145 protected function getStartDay($year, $month) {
146 /* date('w') returns start day counting from Sunday */
147 $start = date('w', mktime(0,0,0,$month,1,$year));
151 protected function isToDay($year, $month, $day) {
152 return ($year == date('Y') && $month == date('n') && $day == date('j'));
155 protected function lastDayInWeek($year, $week) {
156 $weekEndDay = 0; // 0 = Sunday.
157 $dayOfYear = 4 + (($week - 1) * 7);
158 $date = mktime(0, 0, 0, 1, $dayOfYear, $year);
159 // Find the last day of this week.
160 $dayOfWeek = date("w", $date);
161 $daysToAdd = ($weekEndDay - $dayOfWeek + 7) % 7;
162 $date += $daysToAdd * 24*60*60;
163 return (self::$start_sunday) ? $date - (24*60*60) : $date;
166 protected function dateFromDayInYear($year, $day) {
167 $now = mktime(0, 0, 0, 1, 1, $year);
168 return date('l, j F', strtotime("+$day days", $now));
171 protected function makeSummary($infos) {
172 $summary = 'Title: ';
173 $summary .= (isset($infos['summary']) && ! empty($infos['summary'])) ?
174 $infos['summary'] : 'Untitled';
176 $summary .= 'Date: ';
177 $start = strtotime($infos['dates'][0]['start']);
178 $date = date("D j M Y", $start);
179 $end = strtotime($infos['dates'][0]['end']);
180 $summary .= $date . ' ' . date("G:i", $start) . ' - ' . date("G:i", $end);
185 protected function makeEvent($cell, $uri, $infos) {
186 $history = $_SERVER['PHP_SELF'];
187 $summary = (isset($infos['summary']) && ! empty($infos['summary'])) ?
188 $infos['summary'] : 'Untitled';
189 $history .= (empty($_SERVER['QUERY_STRING'])) ? '' : '?'.$_SERVER['QUERY_STRING'];
190 //$url = WEB_ROOT . 'events/edit_event.php?etag='. $uri;
191 $url = 'etag='. $uri.'&referer='.$history.'&cal='.$infos['cal'];
192 $url = WEB_ROOT . 'events/edit_event.php?' . urlencode($url);
193 $c = '<span style="background: '.$infos['color'].';color: #E6E6E6;
194 font-weigth: bold;"><a href="'.$url.
195 '" title="'.$this->makeSummary($infos).'">'.$summary.'</a></span>';
196 return ($cell != '') ? "$cell<br/>$c" : $c;
199 protected function getEvents($range) {
201 $all_events = array();
203 $cals = $_SESSION['user_settings']->getCalendars();
204 //file_put_contents('/tmp/davical.log',
205 // __FILE__ . ": " . var_export($cals, TRUE), FILE_APPEND);
208 $start = CaldavRessource::timestamp2ICal($range['start'], TRUE);
209 if ($_SESSION['user_settings']->getStartWeek() === FALSE) {
210 $datetime = explode('T', $start);
211 //print_r($datetime);
212 $day = $datetime[0] + 1;
213 $start = $day.'T'.$datetime[1].'Z';
215 $end = CaldavRessource::timestamp2ICal($range['end'], TRUE);
216 $datetime = explode('T', $end);
217 $end = $datetime[0].'T'.'235959Z';
218 //print "$start:$end<br/>";
219 foreach ($cals as $cal) {
221 $conf = implode_cal(decode($cal->config));
223 $events = new Calendar($conf['url'], $conf['uid'], $conf['pwd']);
225 $events->getComponents($start, $end);
227 $all_events[$cal->name] = $events;
228 foreach ($events as $event) {
229 $dates = $event->getActiveDates();
230 //file_put_contents('/tmp/davical.log',
231 //__FILE__ . ": " . var_export($dates, TRUE), FILE_APPEND);
233 $comp = $event->getBaseComponent();
235 $summary = $comp->GetPValue('SUMMARY');
237 $dtend = explode('T', $comp->GetPValue('DTEND'));
238 //print_r($comp->GetPValue('DTEND'));
243 //print "<br/>--------------------------<br/>";
244 if (count($dates) > 0) {
245 foreach ($dates as $date) {
247 //print "<br/>--------------------------<br/>";
248 //$datetime = explode('T', $date);
250 //print "<br/>--------------------------<br/>";
251 //if (count($datetime) > 1) {
252 if (count($dtend) > 1) {
253 //if (count($dtend) < 2)
254 // array_push($dtend, '235959');
255 //$endtime = $datetime[0].'T'.$dtend[1];
256 $endtime = $dtend[0].'T'.$dtend[1];
259 //$endtime = $datetime[0];
260 $day = strtotime($dtend[0]);
261 $day = strtotime("-1 day", $day);
262 $endtime = date("Ymd\T235959", $day);
263 //$endtime = $endtime."T235959";
264 //$endtime = $dtend[0]."T000000";
266 //print "$date:$endtime<br/>";
267 array_push($item, array('start' => $date, 'end' => $endtime));
269 $list[$event->getEtag()] = array('color' => $cal->color,
270 'summary' => $summary, 'dates' => $item, 'cal' => $cal->name);
274 $_SESSION['all_events'] = $all_events;
279 protected abstract function parseDate();
280 protected abstract function getHead();
281 public abstract function getView($year = NULL, $other = NULL);
284 class PageView extends View {
289 function __construct($root, $start_hour, $end_hour, $start_sunday = FALSE) {
290 parent::__construct($root, $start_hour, $end_hour, $start_sunday);
293 public function createView($view) {
295 case (self::DAY): return new DayView(); break;
296 case (self::WEEK): return new WeekView(); break;
297 case (self::MONTH): return new MonthView(); break;
298 default: trigger_error("$view: ['MONTH', 'WEEK', 'DAY']", E_USER_ERROR);
302 protected function parseDate() {
303 throw new Exception("Function can only be called from a subclass");
306 protected function getHead() {
307 throw new Exception("Function can only be called from a subclass");
310 public function getView($year = NULL, $other = NULL) {
311 throw new Exception("Function can only be called from a subclass");
This page took 0.0960299999999999 seconds and 6 git commands to generate.