Changeset View
Changeset View
Standalone View
Standalone View
plugins/calendar/drivers/database/database_driver.php
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | public function list_calendars($filter = 0) | ||||
// 'personal' is unsupported in this driver | // 'personal' is unsupported in this driver | ||||
// append the virtual birthdays calendar | // append the virtual birthdays calendar | ||||
if ($this->rc->config->get('calendar_contact_birthdays', false)) { | if ($this->rc->config->get('calendar_contact_birthdays', false)) { | ||||
$prefs = $this->rc->config->get('birthday_calendar', array('color' => '87CEFA')); | $prefs = $this->rc->config->get('birthday_calendar', array('color' => '87CEFA')); | ||||
$hidden = array_filter(explode(',', $this->rc->config->get('hidden_calendars', ''))); | $hidden = array_filter(explode(',', $this->rc->config->get('hidden_calendars', ''))); | ||||
$id = self::BIRTHDAY_CALENDAR_ID; | $id = self::BIRTHDAY_CALENDAR_ID; | ||||
if (!$active || !in_array($id, $hidden)) { | if (empty($active) || !in_array($id, $hidden)) { | ||||
$calendars[$id] = array( | $calendars[$id] = array( | ||||
'id' => $id, | 'id' => $id, | ||||
'name' => $this->cal->gettext('birthdays'), | 'name' => $this->cal->gettext('birthdays'), | ||||
'listname' => $this->cal->gettext('birthdays'), | 'listname' => $this->cal->gettext('birthdays'), | ||||
'color' => $prefs['color'], | 'color' => $prefs['color'], | ||||
'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'), | 'showalarms' => (bool)$this->rc->config->get('calendar_birthdays_alarm_type'), | ||||
'active' => !in_array($id, $hidden), | 'active' => !in_array($id, $hidden), | ||||
'group' => 'x-birthdays', | 'group' => 'x-birthdays', | ||||
Show All 19 Lines | class database_driver extends calendar_driver | ||||
{ | { | ||||
$result = $this->rc->db->query( | $result = $this->rc->db->query( | ||||
"INSERT INTO `{$this->db_calendars}`" | "INSERT INTO `{$this->db_calendars}`" | ||||
. " (`user_id`, `name`, `color`, `showalarms`)" | . " (`user_id`, `name`, `color`, `showalarms`)" | ||||
. " VALUES (?, ?, ?, ?)", | . " VALUES (?, ?, ?, ?)", | ||||
$this->rc->user->ID, | $this->rc->user->ID, | ||||
$prop['name'], | $prop['name'], | ||||
strval($prop['color']), | strval($prop['color']), | ||||
$prop['showalarms'] ? 1 : 0 | !empty($prop['showalarms']) ? 1 : 0 | ||||
); | ); | ||||
if ($result) { | if ($result) { | ||||
return $this->rc->db->insert_id($this->db_calendars); | return $this->rc->db->insert_id($this->db_calendars); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | private function _insert_event(&$event) | ||||
"INSERT INTO `{$this->db_events}`" | "INSERT INTO `{$this->db_events}`" | ||||
. " (`calendar_id`, `created`, `changed`, `uid`, `recurrence_id`, `instance`," | . " (`calendar_id`, `created`, `changed`, `uid`, `recurrence_id`, `instance`," | ||||
. " `isexception`, `start`, `end`, `all_day`, `recurrence`, `title`, `description`," | . " `isexception`, `start`, `end`, `all_day`, `recurrence`, `title`, `description`," | ||||
. " `location`, `categories`, `url`, `free_busy`, `priority`, `sensitivity`," | . " `location`, `categories`, `url`, `free_busy`, `priority`, `sensitivity`," | ||||
. " `status`, `attendees`, `alarms`, `notifyat`)" | . " `status`, `attendees`, `alarms`, `notifyat`)" | ||||
. " VALUES (?, $now, $now, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | . " VALUES (?, $now, $now, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", | ||||
$event['calendar'], | $event['calendar'], | ||||
strval($event['uid']), | strval($event['uid']), | ||||
intval($event['recurrence_id']), | isset($event['recurrence_id']) ? intval($event['recurrence_id']) : 0, | ||||
strval($event['_instance']), | isset($event['_instance']) ? strval($event['_instance']) : '', | ||||
intval($event['isexception']), | isset($event['isexception']) ? intval($event['isexception']) : 0, | ||||
$event['start']->format(self::DB_DATE_FORMAT), | $event['start']->format(self::DB_DATE_FORMAT), | ||||
$event['end']->format(self::DB_DATE_FORMAT), | $event['end']->format(self::DB_DATE_FORMAT), | ||||
intval($event['all_day']), | intval($event['all_day']), | ||||
$event['_recurrence'], | $event['_recurrence'], | ||||
strval($event['title']), | strval($event['title']), | ||||
strval($event['description']), | isset($event['description']) ? strval($event['description']) : '', | ||||
strval($event['location']), | isset($event['location']) ? strval($event['location']) : '', | ||||
join(',', (array)$event['categories']), | isset($event['categories']) ? join(',', (array) $event['categories']) : '', | ||||
strval($event['url']), | isset($event['url']) ? strval($event['url']) : '', | ||||
intval($event['free_busy']), | intval($event['free_busy']), | ||||
intval($event['priority']), | intval($event['priority']), | ||||
intval($event['sensitivity']), | intval($event['sensitivity']), | ||||
strval($event['status']), | isset($event['status']) ? strval($event['status']) : '', | ||||
$event['attendees'], | $event['attendees'], | ||||
$event['alarms'], | isset($event['alarms']) ? $event['alarms'] : null, | ||||
$event['notifyat'] | $event['notifyat'] | ||||
); | ); | ||||
$event_id = $this->rc->db->insert_id($this->db_events); | $event_id = $this->rc->db->insert_id($this->db_events); | ||||
if ($event_id) { | if ($event_id) { | ||||
$event['id'] = $event_id; | $event['id'] = $event_id; | ||||
Show All 26 Lines | public function edit_event($event) | ||||
$old = $this->get_event($event); | $old = $this->get_event($event); | ||||
$ret = true; | $ret = true; | ||||
// check if update affects scheduling and update attendee status accordingly | // check if update affects scheduling and update attendee status accordingly | ||||
$reschedule = $this->_check_scheduling($event, $old, true); | $reschedule = $this->_check_scheduling($event, $old, true); | ||||
// increment sequence number | // increment sequence number | ||||
if (empty($event['sequence']) && $reschedule) { | if (empty($event['sequence']) && $reschedule) { | ||||
$event['sequence'] = max($event['sequence'], $old['sequence']) + 1; | $event['sequence'] = $old['sequence'] + 1; | ||||
} | } | ||||
// modify a recurring event, check submitted savemode to do the right things | // modify a recurring event, check submitted savemode to do the right things | ||||
if ($old['recurrence'] || $old['recurrence_id']) { | if ($old['recurrence'] || $old['recurrence_id']) { | ||||
$master = $old['recurrence_id'] ? $this->get_event(array('id' => $old['recurrence_id'])) : $old; | $master = $old['recurrence_id'] ? $this->get_event(array('id' => $old['recurrence_id'])) : $old; | ||||
// keep saved exceptions (not submitted by the client) | // keep saved exceptions (not submitted by the client) | ||||
if ($old['recurrence']['EXDATE']) { | if (!empty($old['recurrence']['EXDATE'])) { | ||||
$event['recurrence']['EXDATE'] = $old['recurrence']['EXDATE']; | $event['recurrence']['EXDATE'] = $old['recurrence']['EXDATE']; | ||||
} | } | ||||
switch ($event['_savemode']) { | $savemode = isset($event['_savemode']) ? $event['_savemode'] : null; | ||||
switch ($savemode) { | |||||
case 'new': | case 'new': | ||||
$event['uid'] = $this->cal->generate_uid(); | $event['uid'] = $this->cal->generate_uid(); | ||||
return $this->new_event($event); | return $this->new_event($event); | ||||
case 'current': | case 'current': | ||||
// save as exception | // save as exception | ||||
$event['isexception'] = 1; | $event['isexception'] = 1; | ||||
$update_recurring = false; | $update_recurring = false; | ||||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | private function _check_scheduling(&$event, $old, $update = true) | ||||
if (isset($event['sequence']) || !empty($event['_method'])) { | if (isset($event['sequence']) || !empty($event['_method'])) { | ||||
return false; | return false; | ||||
} | } | ||||
$reschedule = false; | $reschedule = false; | ||||
// iterate through the list of properties considered 'significant' for scheduling | // iterate through the list of properties considered 'significant' for scheduling | ||||
foreach (self::$scheduling_properties as $prop) { | foreach (self::$scheduling_properties as $prop) { | ||||
$a = $old[$prop]; | $a = isset($old[$prop]) ? $old[$prop] : null; | ||||
$b = $event[$prop]; | $b = isset($event[$prop]) ? $event[$prop] : null; | ||||
if ($event['allday'] && ($prop == 'start' || $prop == 'end') && $a instanceof DateTime && $b instanceof DateTime) { | if (!empty($event['allday']) && ($prop == 'start' || $prop == 'end') | ||||
&& $a instanceof DateTime && $b instanceof DateTime | |||||
) { | |||||
$a = $a->format('Y-m-d'); | $a = $a->format('Y-m-d'); | ||||
$b = $b->format('Y-m-d'); | $b = $b->format('Y-m-d'); | ||||
} | } | ||||
if ($prop == 'recurrence' && is_array($a) && is_array($b)) { | if ($prop == 'recurrence' && is_array($a) && is_array($b)) { | ||||
unset($a['EXCEPTIONS'], $b['EXCEPTIONS']); | unset($a['EXCEPTIONS'], $b['EXCEPTIONS']); | ||||
$a = array_filter($a); | $a = array_filter($a); | ||||
$b = array_filter($b); | $b = array_filter($b); | ||||
// advanced rrule comparison: no rescheduling if series was shortened | // advanced rrule comparison: no rescheduling if series was shortened | ||||
if ($a['COUNT'] && $b['COUNT'] && $b['COUNT'] < $a['COUNT']) { | if (!empty($a['COUNT']) && !empty($b['COUNT']) && $b['COUNT'] < $a['COUNT']) { | ||||
unset($a['COUNT'], $b['COUNT']); | unset($a['COUNT'], $b['COUNT']); | ||||
} | } | ||||
else if ($a['UNTIL'] && $b['UNTIL'] && $b['UNTIL'] < $a['UNTIL']) { | else if (!empty($a['UNTIL']) && !empty($b['UNTIL']) && $b['UNTIL'] < $a['UNTIL']) { | ||||
unset($a['UNTIL'], $b['UNTIL']); | unset($a['UNTIL'], $b['UNTIL']); | ||||
} | } | ||||
} | } | ||||
if ($a != $b) { | if ($a != $b) { | ||||
$reschedule = true; | $reschedule = true; | ||||
break; | break; | ||||
} | } | ||||
Show All 36 Lines | private function _save_preprocess($event) | ||||
if (!$event['allday']) { | if (!$event['allday']) { | ||||
$event['start'] = clone $event['start']; | $event['start'] = clone $event['start']; | ||||
$event['start']->setTimezone($this->server_timezone); | $event['start']->setTimezone($this->server_timezone); | ||||
$event['end'] = clone $event['end']; | $event['end'] = clone $event['end']; | ||||
$event['end']->setTimezone($this->server_timezone); | $event['end']->setTimezone($this->server_timezone); | ||||
} | } | ||||
// compose vcalendar-style recurrencue rule from structured data | // compose vcalendar-style recurrencue rule from structured data | ||||
$rrule = $event['recurrence'] ? libcalendaring::to_rrule($event['recurrence']) : ''; | $rrule = !empty($event['recurrence']) ? libcalendaring::to_rrule($event['recurrence']) : ''; | ||||
$sensitivity = strtolower($event['sensitivity']); | |||||
$free_busy = strtolower($event['free_busy']); | |||||
$event['_recurrence'] = rtrim($rrule, ';'); | $event['_recurrence'] = rtrim($rrule, ';'); | ||||
$event['free_busy'] = intval($this->free_busy_map[strtolower($event['free_busy'])]); | $event['free_busy'] = isset($this->free_busy_map[$free_busy]) ? $this->free_busy_map[$free_busy] : null; | ||||
$event['sensitivity'] = intval($this->sensitivity_map[strtolower($event['sensitivity'])]); | $event['sensitivity'] = isset($this->sensitivity_map[$sensitivity]) ? $this->sensitivity_map[$sensitivity] : null; | ||||
$event['all_day'] = !empty($event['allday']) ? 1 : 0; | |||||
if ($event['free_busy'] == 'tentative') { | if ($event['free_busy'] == 'tentative') { | ||||
$event['status'] = 'TENTATIVE'; | $event['status'] = 'TENTATIVE'; | ||||
} | } | ||||
if (isset($event['allday'])) { | |||||
$event['all_day'] = $event['allday'] ? 1 : 0; | |||||
} | |||||
// compute absolute time to notify the user | // compute absolute time to notify the user | ||||
$event['notifyat'] = $this->_get_notification($event); | $event['notifyat'] = $this->_get_notification($event); | ||||
if (is_array($event['valarms'])) { | if (!empty($event['valarms'])) { | ||||
$event['alarms'] = $this->serialize_alarms($event['valarms']); | $event['alarms'] = $this->serialize_alarms($event['valarms']); | ||||
} | } | ||||
// process event attendees | // process event attendees | ||||
if (!empty($event['attendees'])) { | if (!empty($event['attendees'])) { | ||||
$event['attendees'] = json_encode((array)$event['attendees']); | $event['attendees'] = json_encode((array)$event['attendees']); | ||||
} | } | ||||
else { | else { | ||||
$event['attendees'] = ''; | $event['attendees'] = ''; | ||||
} | } | ||||
return $event; | return $event; | ||||
} | } | ||||
/** | /** | ||||
* Compute absolute time to notify the user | * Compute absolute time to notify the user | ||||
*/ | */ | ||||
private function _get_notification($event) | private function _get_notification($event) | ||||
{ | { | ||||
if ($event['valarms'] && $event['start'] > new DateTime()) { | if (!empty($event['valarms']) && $event['start'] > new DateTime()) { | ||||
$alarm = libcalendaring::get_next_alarm($event); | $alarm = libcalendaring::get_next_alarm($event); | ||||
if ($alarm['time'] && in_array($alarm['action'], $this->alarm_types)) { | if ($alarm['time'] && in_array($alarm['action'], $this->alarm_types)) { | ||||
return date('Y-m-d H:i:s', $alarm['time']); | return date('Y-m-d H:i:s', $alarm['time']); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Save the given event record to database | * Save the given event record to database | ||||
* | * | ||||
* @param array Event data | * @param array Event data | ||||
* @param boolean True if recurring events instances should be updated, too | * @param boolean True if recurring events instances should be updated, too | ||||
*/ | */ | ||||
private function _update_event($event, $update_recurring = true) | private function _update_event($event, $update_recurring = true) | ||||
{ | { | ||||
$event = $this->_save_preprocess($event); | $event = $this->_save_preprocess($event); | ||||
$sql_args = array(); | $sql_args = array(); | ||||
$set_cols = array('start', 'end', 'all_day', 'recurrence_id', 'isexception', 'sequence', | $set_cols = array('start', 'end', 'all_day', 'recurrence_id', 'isexception', 'sequence', | ||||
'title', 'description', 'location', 'categories', 'url', 'free_busy', 'priority', | 'title', 'description', 'location', 'categories', 'url', 'free_busy', 'priority', | ||||
'sensitivity', 'status', 'attendees', 'alarms', 'notifyat' | 'sensitivity', 'status', 'attendees', 'alarms', 'notifyat' | ||||
); | ); | ||||
foreach ($set_cols as $col) { | foreach ($set_cols as $col) { | ||||
if (is_object($event[$col]) && is_a($event[$col], 'DateTime')) { | if (!empty($event[$col]) && is_a($event[$col], 'DateTime')) { | ||||
$sql_args[$col] = $event[$col]->format(self::DB_DATE_FORMAT); | $sql_args[$col] = $event[$col]->format(self::DB_DATE_FORMAT); | ||||
} | } | ||||
else if (is_array($event[$col])) { | |||||
$sql_args[$col] = join(',', $event[$col]); | |||||
} | |||||
else if (array_key_exists($col, $event)) { | else if (array_key_exists($col, $event)) { | ||||
$sql_args[$col] = $event[$col]; | $sql_args[$col] = is_array($event[$col]) ? join(',', $event[$col]) : $event[$col]; | ||||
} | } | ||||
} | } | ||||
if ($event['_recurrence']) { | if (!empty($event['_recurrence'])) { | ||||
$sql_args['recurrence'] = $event['_recurrence']; | $sql_args['recurrence'] = $event['_recurrence']; | ||||
} | } | ||||
if ($event['_instance']) { | if (!empty($event['_instance'])) { | ||||
$sql_args['instance'] = $event['_instance']; | $sql_args['instance'] = $event['_instance']; | ||||
} | } | ||||
if ($event['_fromcalendar'] && $event['_fromcalendar'] != $event['calendar']) { | if (!empty($event['_fromcalendar']) && $event['_fromcalendar'] != $event['calendar']) { | ||||
$sql_args['calendar_id'] = $event['calendar']; | $sql_args['calendar_id'] = $event['calendar']; | ||||
} | } | ||||
$sql_set = ''; | $sql_set = ''; | ||||
foreach (array_keys($sql_args) as $col) { | foreach (array_keys($sql_args) as $col) { | ||||
$sql_set .= ", `$col` = ?"; | $sql_set .= ", `$col` = ?"; | ||||
} | } | ||||
Show All 13 Lines | private function _update_event($event, $update_recurring = true) | ||||
if ($success && !empty($event['attachments'])) { | if ($success && !empty($event['attachments'])) { | ||||
foreach ($event['attachments'] as $attachment) { | foreach ($event['attachments'] as $attachment) { | ||||
$this->add_attachment($attachment, $event['id']); | $this->add_attachment($attachment, $event['id']); | ||||
unset($attachment); | unset($attachment); | ||||
} | } | ||||
} | } | ||||
// remove attachments | // remove attachments | ||||
if ($success && !empty($event['deleted_attachments'])) { | if ($success && !empty($event['deleted_attachments']) && is_array($event['deleted_attachments'])) { | ||||
foreach ($event['deleted_attachments'] as $attachment) { | foreach ($event['deleted_attachments'] as $attachment) { | ||||
$this->remove_attachment($attachment, $event['id']); | $this->remove_attachment($attachment, $event['id']); | ||||
} | } | ||||
} | } | ||||
if ($success) { | if ($success) { | ||||
unset($this->cache[$event['id']]); | unset($this->cache[$event['id']]); | ||||
if ($update_recurring) { | if ($update_recurring) { | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | private function _update_recurring($event) | ||||
$recurrence_id_format = libcalendaring::recurrence_id_format($event); | $recurrence_id_format = libcalendaring::recurrence_id_format($event); | ||||
while ($next_start = $recurrence->next_start()) { | while ($next_start = $recurrence->next_start()) { | ||||
$instance = $next_start->format($recurrence_id_format); | $instance = $next_start->format($recurrence_id_format); | ||||
$datestr = substr($instance, 0, 8); | $datestr = substr($instance, 0, 8); | ||||
// skip exceptions | // skip exceptions | ||||
// TODO: merge updated data from master event | // TODO: merge updated data from master event | ||||
if ($exdata[$datestr]) { | if (!empty($exdata[$datestr])) { | ||||
continue; | continue; | ||||
} | } | ||||
$next_start->setTimezone($this->server_timezone); | $next_start->setTimezone($this->server_timezone); | ||||
$next_end = clone $next_start; | $next_end = clone $next_start; | ||||
$next_end->add($duration); | $next_end->add($duration); | ||||
$notify_at = $this->_get_notification(array( | $notify_at = $this->_get_notification(array( | ||||
'alarms' => $event['alarms'], | 'alarms' => !empty($event['alarms']) ? $event['alarms'] : null, | ||||
'start' => $next_start, | 'start' => $next_start, | ||||
'end' => $next_end, | 'end' => $next_end, | ||||
'status' => $event['status'] | 'status' => $event['status'] | ||||
)); | )); | ||||
$now = $this->rc->db->now(); | $now = $this->rc->db->now(); | ||||
$query = $this->rc->db->query( | $query = $this->rc->db->query( | ||||
"INSERT INTO `{$this->db_events}`" | "INSERT INTO `{$this->db_events}`" | ||||
Show All 12 Lines | private function _update_recurring($event) | ||||
$event['id'] | $event['id'] | ||||
); | ); | ||||
if (!$this->rc->db->affected_rows($query)) { | if (!$this->rc->db->affected_rows($query)) { | ||||
break; | break; | ||||
} | } | ||||
// stop adding events for inifinite recurrence after 20 years | // stop adding events for inifinite recurrence after 20 years | ||||
if (++$count > 999 || (!$recurrence->recurEnd && !$recurrence->recurCount && $next_start->format('Y') > date('Y') + 20)) { | if (++$count > 999 || (empty($recurrence->recurEnd) && empty($recurrence->recurCount) && $next_start->format('Y') > date('Y') + 20)) { | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
// remove all exceptions after recurrence end | // remove all exceptions after recurrence end | ||||
if ($next_end && !empty($exceptions)) { | if (!empty($next_end) && !empty($exceptions)) { | ||||
$this->rc->db->query( | $this->rc->db->query( | ||||
"DELETE FROM `{$this->db_events}`" | "DELETE FROM `{$this->db_events}`" | ||||
. " WHERE `recurrence_id` = ? AND `isexception` = 1 AND `start` > ?" | . " WHERE `recurrence_id` = ? AND `isexception` = 1 AND `start` > ?" | ||||
. " AND `calendar_id` IN ({$this->calendar_ids})", | . " AND `calendar_id` IN ({$this->calendar_ids})", | ||||
$event['id'], | $event['id'], | ||||
$next_end->format(self::DB_DATE_FORMAT) | $next_end->format(self::DB_DATE_FORMAT) | ||||
); | ); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | class database_driver extends calendar_driver | ||||
* @param mixed Hash array with event properties or event UID | * @param mixed Hash array with event properties or event UID | ||||
* @param integer Bitmask defining the scope to search events in | * @param integer Bitmask defining the scope to search events in | ||||
* @param boolean If true, recurrence exceptions shall be added | * @param boolean If true, recurrence exceptions shall be added | ||||
* | * | ||||
* @return array Hash array with event properties | * @return array Hash array with event properties | ||||
*/ | */ | ||||
public function get_event($event, $scope = 0, $full = false) | public function get_event($event, $scope = 0, $full = false) | ||||
{ | { | ||||
$id = is_array($event) ? ($event['id'] ?: $event['uid']) : $event; | $id = is_array($event) ? (!empty($event['id']) ? $event['id'] : $event['uid']) : $event; | ||||
$cal = is_array($event) ? $event['calendar'] : null; | $cal = is_array($event) && !empty($event['calendar']) ? $event['calendar'] : null; | ||||
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid'; | $col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid'; | ||||
if ($this->cache[$id]) { | if (!empty($this->cache[$id])) { | ||||
return $this->cache[$id]; | return $this->cache[$id]; | ||||
} | } | ||||
// get event from the address books birthday calendar | // get event from the address books birthday calendar | ||||
if ($cal == self::BIRTHDAY_CALENDAR_ID) { | if ($cal == self::BIRTHDAY_CALENDAR_ID) { | ||||
return $this->get_birthday_event($id); | return $this->get_birthday_event($id); | ||||
} | } | ||||
$where_add = ''; | $where_add = ''; | ||||
if (is_array($event) && !$event['id'] && !empty($event['_instance'])) { | if (is_array($event) && empty($event['id']) && !empty($event['_instance'])) { | ||||
$where_add = " AND e.instance = " . $this->rc->db->quote($event['_instance']); | $where_add = " AND e.instance = " . $this->rc->db->quote($event['_instance']); | ||||
} | } | ||||
if ($scope & self::FILTER_ACTIVE) { | if ($scope & self::FILTER_ACTIVE) { | ||||
$calendars = $this->calendars; | $calendars = []; | ||||
foreach ($calendars as $idx => $cal) { | foreach ($this->calendars as $idx => $cal) { | ||||
if (!$cal['active']) { | if (!empty($cal['active'])) { | ||||
unset($calendars[$idx]); | $calendars[] = $idx; | ||||
} | } | ||||
} | } | ||||
$cals = join(',', $calendars); | $cals = join(',', $calendars); | ||||
} | } | ||||
else { | else { | ||||
$cals = $this->calendar_ids; | $cals = $this->calendar_ids; | ||||
} | } | ||||
Show All 35 Lines | public function load_events($start, $end, $query = null, $calendars = null, $virtual = 1, $modifiedsince = null) | ||||
$calendars = explode(',', strval($calendars)); | $calendars = explode(',', strval($calendars)); | ||||
} | } | ||||
// only allow to select from calendars of this use | // only allow to select from calendars of this use | ||||
$calendar_ids = array_map(array($this->rc->db, 'quote'), array_intersect($calendars, array_keys($this->calendars))); | $calendar_ids = array_map(array($this->rc->db, 'quote'), array_intersect($calendars, array_keys($this->calendars))); | ||||
// compose (slow) SQL query for searching | // compose (slow) SQL query for searching | ||||
// FIXME: improve searching using a dedicated col and normalized values | // FIXME: improve searching using a dedicated col and normalized values | ||||
$sql_add = ''; | |||||
if ($query) { | if ($query) { | ||||
foreach (array('title','location','description','categories','attendees') as $col) { | foreach (array('title','location','description','categories','attendees') as $col) { | ||||
$sql_query[] = $this->rc->db->ilike($col, '%'.$query.'%'); | $sql_query[] = $this->rc->db->ilike($col, '%'.$query.'%'); | ||||
} | } | ||||
$sql_add = " AND (" . join(' OR ', $sql_query) . ")"; | $sql_add .= " AND (" . join(' OR ', $sql_query) . ")"; | ||||
} | } | ||||
if (!$virtual) { | if (!$virtual) { | ||||
$sql_add .= " AND e.recurrence_id = 0"; | $sql_add .= " AND e.recurrence_id = 0"; | ||||
} | } | ||||
if ($modifiedsince) { | if ($modifiedsince) { | ||||
$sql_add .= " AND e.changed >= " . $this->rc->db->quote(date('Y-m-d H:i:s', $modifiedsince)); | $sql_add .= " AND e.changed >= " . $this->rc->db->quote(date('Y-m-d H:i:s', $modifiedsince)); | ||||
Show All 35 Lines | public function load_events($start, $end, $query = null, $calendars = null, $virtual = 1, $modifiedsince = null) | ||||
if ($add) { | if ($add) { | ||||
$events[] = $event; | $events[] = $event; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// add events from the address books birthday calendar | // add events from the address books birthday calendar | ||||
if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars) && empty($query)) { | if (in_array(self::BIRTHDAY_CALENDAR_ID, $calendars) && empty($query)) { | ||||
$events = array_merge($events, $this->load_birthday_events($start, $end, $search, $modifiedsince)); | $events = array_merge($events, $this->load_birthday_events($start, $end, null, $modifiedsince)); | ||||
} | } | ||||
return $events; | return $events; | ||||
} | } | ||||
/** | /** | ||||
* Get number of events in the given calendar | * Get number of events in the given calendar | ||||
* | * | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | private function _read_postprocess($event) | ||||
if (strlen($event['instance'])) { | if (strlen($event['instance'])) { | ||||
$event['_instance'] = $event['instance']; | $event['_instance'] = $event['instance']; | ||||
if (empty($event['recurrence_id'])) { | if (empty($event['recurrence_id'])) { | ||||
$event['recurrence_date'] = rcube_utils::anytodatetime($event['_instance'], $event['start']->getTimezone()); | $event['recurrence_date'] = rcube_utils::anytodatetime($event['_instance'], $event['start']->getTimezone()); | ||||
} | } | ||||
} | } | ||||
if ($event['_attachments'] > 0) { | if (!empty($event['_attachments'])) { | ||||
$event['attachments'] = (array)$this->list_attachments($event); | $event['attachments'] = (array)$this->list_attachments($event); | ||||
} | } | ||||
// decode serialized event attendees | // decode serialized event attendees | ||||
if (strlen($event['attendees'])) { | if (strlen($event['attendees'])) { | ||||
$event['attendees'] = $this->unserialize_attendees($event['attendees']); | $event['attendees'] = $this->unserialize_attendees($event['attendees']); | ||||
} | } | ||||
else { | else { | ||||
▲ Show 20 Lines • Show All 152 Lines • ▼ Show 20 Lines | public function get_attachment($id, $event) | ||||
if (!empty($this->calendar_ids)) { | if (!empty($this->calendar_ids)) { | ||||
$result = $this->rc->db->query( | $result = $this->rc->db->query( | ||||
"SELECT `attachment_id` AS id, `filename` AS name, `mimetype`, `size` " | "SELECT `attachment_id` AS id, `filename` AS name, `mimetype`, `size` " | ||||
. " FROM `{$this->db_attachments}`" | . " FROM `{$this->db_attachments}`" | ||||
. " WHERE `attachment_id` = ? AND `event_id` IN (" | . " WHERE `attachment_id` = ? AND `event_id` IN (" | ||||
. "SELECT `event_id` FROM `{$this->db_events}`" | . "SELECT `event_id` FROM `{$this->db_events}`" | ||||
. " WHERE `event_id` = ? AND `calendar_id` IN ({$this->calendar_ids}))", | . " WHERE `event_id` = ? AND `calendar_id` IN ({$this->calendar_ids}))", | ||||
$id, | $id, | ||||
$event['recurrence_id'] ? $event['recurrence_id'] : $event['id'] | !empty($event['recurrence_id']) ? $event['recurrence_id'] : $event['id'] | ||||
); | ); | ||||
if ($result && ($arr = $this->rc->db->fetch_assoc($result))) { | if ($result && ($arr = $this->rc->db->fetch_assoc($result))) { | ||||
return $arr; | return $arr; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 120 Lines • Show Last 20 Lines |