3 class Calendar_Item extends DatabaseTable {
6 private $timedays = array();
8 public function __construct($id=false)
10 $this->idcolumn = 'dav_id';
11 $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS);
13 parent::__construct('calendar_item', $id, $db);
16 protected function postLoad()
18 $start = explode(' ', $this->data->dtstart);
19 $starttime = explode(':', $start[1]);
20 $end = explode(' ', $this->data->dtend);
21 $endtime = explode(':', $end[1]);
23 $this->isRegular = $start[0] == $end[0];
25 if ($this->isRegular) {
26 if ($starttime[1] == '00' && $endtime[1] == '00') {
27 if ($starttime[0] == $endtime[0])
28 $this->timespan = $starttime[0];
30 $this->timespan = $starttime[0] .'-'. $endtime[0];
32 $this->timespan = sprintf('%d:%02d-%d:%02d',
33 $starttime[0], $starttime[1],
34 $endtime[0], $endtime[1]);
37 $startTimeStamp = strtotime($start[0]) + (3*60*60);
38 $endTimeStamp = strtotime($end[0]);
40 while ($startTimeStamp < $endTimeStamp) {
41 $this->timeDays[] = date('Y-m-d', $startTimeStamp);
42 $startTimeStamp += (24*60*60);
48 public function isRegular()
50 return $this->isRegular;
53 public function timespan()
55 return $this->timespan;
58 public function getDays()
60 return $this->timeDays;
63 public function toSpan()
66 if ($this->data->description)
67 $tooltip .= (strlen($tooltip)?', ':'').$this->data->description;
68 if ($this->data->location)
69 $tooltip .= (strlen($tooltip)?', ':'').'Ort: '.$this->data->location;
72 $tooltip = sprintf(' title="%s"', $tooltip);
74 $sql = sprintf("SELECT color FROM calendar_item_data WHERE dav_id = %d", $this->id);
75 $bgcolor = $this->fetchValue($sql);
76 if ($bgcolor) $bgcolor = sprintf(' style="background:%s;"', $bgcolor);
78 return sprintf('<span dav_id="%d"%s%s>%s %s</span>',
82 $this->data->summary);
85 public function ajaxSetColor(Array $data)
87 $sql = sprintf("SELECT id FROM calendar_item_data WHERE dav_id = %d", $this->id);
88 $id = $this->fetchValue($sql);
91 $sql = sprintf("UPDATE calendar_item_data SET color = %s WHERE id = %d",
92 $this->quote($data['color']), $id);
94 $sql = sprintf("INSERT INTO calendar_item_data (dav_id, color) VALUES (%d,%s)",
95 $this->id, $this->quote($data['color']));
97 return $this->execute($sql);
100 public function ajaxLog(Array $data)
102 $title = $this->data->summary;
103 if ($this->data->location)
104 $title .= ', ' . $this->data->location;
106 $out = sprintf('<div class="caltitle">%s</div>', $title);
107 $out .= sprintf('<div>%s: Item created</div>', substr($this->data->created,0,16));
108 # $out .= sprintf('<div>Last modified %s</div>', $this->data->last_modified);
110 $sql = sprintf("SELECT name,url,comment,sys_edit,sys_user " .
111 "FROM calendar_item_log WHERE dav_id = %d ORDER BY sys_edit", $this->id);
112 foreach ($this->fetchObjectList($sql) as $row) {
113 if (strlen($row->url))
114 $out .= sprintf('<div>%s: <a href="%s" target="_blank">%s</a></div>',
115 substr($row->sys_edit,0,16),
117 $row->name ? $row->name : 'Link');
118 if (strlen($row->comment))
119 $out .= sprintf('<div>%s: %s</div>', substr($row->sys_edit,0,16), $row->comment);
122 return array('html' => array('log' => $out));
125 public function ajaxAddLog(Array $data)
127 if (!strlen($data['name']) && !strlen($data['url']) && !strlen($data['comment'])) return true;
129 $item = array('dav_id' => $this->id,
130 'name' => strlen($data['name']) ? $data['name'] : NULL,
131 'url' => strlen($data['url']) ? $data['url'] : NULL,
132 'comment' => strlen($data['comment']) ? $data['comment'] : NULL,
133 'sys_user' => $_SERVER['REMOTE_USER'],
134 'sys_edit' => 'now()');
136 return $this->db->insertInto('calendar_item_log', $item);