idcolumn = 'dav_id'; $db = new Database(DBDRIVER, DBHOST, DAV_DBNAME, DBUSER, DBPASS); parent::__construct('calendar_item', $id, $db); } protected function postLoad() { $start = explode(' ', $this->data->dtstart); $starttime = explode(':', $start[1]); $end = explode(' ', $this->data->dtend); $endtime = explode(':', $end[1]); $this->isRegular = $start[0] == $end[0]; if ($this->isRegular) { if ($starttime[1] == '00' && $endtime[1] == '00') { if ($starttime[0] == $endtime[0]) $this->timespan = $starttime[0]; else $this->timespan = $starttime[0] .'-'. $endtime[0]; } else { $this->timespan = sprintf('%d:%02d-%d:%02d', $starttime[0], $starttime[1], $endtime[0], $endtime[1]); } } else { $startTimeStamp = strtotime($start[0]) + (3*60*60); $endTimeStamp = strtotime($end[0]); while ($startTimeStamp < $endTimeStamp) { $this->timeDays[] = date('Y-m-d', $startTimeStamp); $startTimeStamp += (24*60*60); } } } public function isRegular() { return $this->isRegular; } public function timespan() { return $this->timespan; } public function getDays() { return $this->timeDays; } public function toSpan() { $tooltip = ''; if ($this->data->description) $tooltip .= (strlen($tooltip)?', ':'').$this->data->description; if ($this->data->location) $tooltip .= (strlen($tooltip)?', ':'').'Ort: '.$this->data->location; if (strlen($tooltip)) $tooltip = sprintf(' title="%s"', $tooltip); $sql = sprintf("SELECT color FROM calendar_item_data WHERE dav_id = %d", $this->id); $bgcolor = $this->fetchValue($sql); if ($bgcolor) $bgcolor = sprintf(' style="background:%s;"', $bgcolor); return sprintf('%s %s', $this->id, $tooltip, $bgcolor, $this->timespan(), $this->data->summary); } public function ajaxSetColor(Array $data) { $sql = sprintf("SELECT id FROM calendar_item_data WHERE dav_id = %d", $this->id); $id = $this->fetchValue($sql); if ($id) $sql = sprintf("UPDATE calendar_item_data SET color = %s WHERE id = %d", $this->quote($data['color']), $id); else $sql = sprintf("INSERT INTO calendar_item_data (dav_id, color) VALUES (%d,%s)", $this->id, $this->quote($data['color'])); return $this->execute($sql); } public function ajaxLog(Array $data) { $title = $this->data->summary; if ($this->data->location) $title .= ', ' . $this->data->location; $color = 0; $out = sprintf('
%s
', $title); $items = array(); $items[] = array('dt' => substr($this->data->created,0,16), 'log' => 'Item created'); $sql = sprintf("SELECT name,url,comment,sys_edit,sys_user " . "FROM calendar_item_log WHERE dav_id = %d ORDER BY sys_edit", $this->id); foreach ($this->fetchObjectList($sql) as $row) { if (strlen($row->url)) $items[] = array('dt' => substr($row->sys_edit,0,16), 'log' => sprintf('%s', $row->url, $row->name ? $row->name : 'Link')); if (strlen($row->comment)) $items[] = array('dt' => substr($row->sys_edit,0,16), 'log' => $row->comment); } foreach ($items as $item) { $color = !$color; $out .= sprintf('
%s
%s
', $color, $item['dt'], $item['log']); } return array('html' => array('log' => $out)); } public function ajaxAddLog(Array $data) { if (!strlen($data['name']) && !strlen($data['url']) && !strlen($data['comment'])) return true; $item = array('dav_id' => $this->id, 'name' => strlen($data['name']) ? $data['name'] : NULL, 'url' => strlen($data['url']) ? $data['url'] : NULL, 'comment' => strlen($data['comment']) ? nl2br(trim($data['comment'])) : NULL, 'sys_user' => $_SERVER['REMOTE_USER'], 'sys_edit' => 'now()'); return $this->db->insertInto('calendar_item_log', $item); } }