annotate plugins/calendar/drivers/calendar_driver.php @ 12:ff1f27bd05ad

partial success in getting back_link to message when making event from mail
author Charlie Root
date Sat, 13 Jan 2018 09:39:32 -0500
parents f6fe4b6ae66a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
1 <?php
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
2
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
3 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
4 * Driver interface for the Calendar plugin
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
5 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
6 * @version @package_version@
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
7 * @author Lazlo Westerhof <hello@lazlo.me>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
8 * @author Thomas Bruederli <bruederli@kolabsys.com>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
9 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
10 * Copyright (C) 2010, Lazlo Westerhof <hello@lazlo.me>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
11 * Copyright (C) 2012-2015, Kolab Systems AG <contact@kolabsys.com>
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
12 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
13 * This program is free software: you can redistribute it and/or modify
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
14 * it under the terms of the GNU Affero General Public License as
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
15 * published by the Free Software Foundation, either version 3 of the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
16 * License, or (at your option) any later version.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
17 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
18 * This program is distributed in the hope that it will be useful,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
21 * GNU Affero General Public License for more details.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
22 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
23 * You should have received a copy of the GNU Affero General Public License
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
25 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
26
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
27
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
28 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
29 * Struct of an internal event object how it is passed from/to the driver classes:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
30 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
31 * $event = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
32 * 'id' => 'Event ID used for editing',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
33 * 'uid' => 'Unique identifier of this event',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
34 * 'calendar' => 'Calendar identifier to add event to or where the event is stored',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
35 * 'start' => DateTime, // Event start date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
36 * 'end' => DateTime, // Event end date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
37 * 'allday' => true|false, // Boolean flag if this is an all-day event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
38 * 'changed' => DateTime, // Last modification date of event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
39 * 'title' => 'Event title/summary',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
40 * 'location' => 'Location string',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
41 * 'description' => 'Event description',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
42 * 'url' => 'URL to more information',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
43 * 'recurrence' => array( // Recurrence definition according to iCalendar (RFC 2445) specification as list of key-value pairs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
44 * 'FREQ' => 'DAILY|WEEKLY|MONTHLY|YEARLY',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
45 * 'INTERVAL' => 1...n,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
46 * 'UNTIL' => DateTime,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
47 * 'COUNT' => 1..n, // number of times
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
48 * // + more properties (see http://www.kanzaki.com/docs/ical/recur.html)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
49 * 'EXDATE' => array(), // list of DateTime objects of exception Dates/Times
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
50 * 'EXCEPTIONS' => array(<event>), list of event objects which denote exceptions in the recurrence chain
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
51 * ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
52 * 'recurrence_id' => 'ID of the recurrence group', // usually the ID of the starting event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
53 * '_instance' => 'ID of the recurring instance', // identifies an instance within a recurrence chain
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
54 * 'categories' => 'Event category',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
55 * 'free_busy' => 'free|busy|outofoffice|tentative', // Show time as
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
56 * 'status' => 'TENTATIVE|CONFIRMED|CANCELLED', // event status according to RFC 2445
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
57 * 'priority' => 0-9, // Event priority (0=undefined, 1=highest, 9=lowest)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
58 * 'sensitivity' => 'public|private|confidential', // Event sensitivity
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
59 * 'alarms' => '-15M:DISPLAY', // DEPRECATED Reminder settings inspired by valarm definition (e.g. display alert 15 minutes before event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
60 * 'valarms' => array( // List of reminders (new format), each represented as a hash array:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
61 * array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
62 * 'trigger' => '-PT90M', // ISO 8601 period string prefixed with '+' or '-', or DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
63 * 'action' => 'DISPLAY|EMAIL|AUDIO',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
64 * 'duration' => 'PT15M', // ISO 8601 period string
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
65 * 'repeat' => 0, // number of repetitions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
66 * 'description' => '', // text to display for DISPLAY actions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
67 * 'summary' => '', // message text for EMAIL actions
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
68 * 'attendees' => array(), // list of email addresses to receive alarm messages
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
69 * ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
70 * ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
71 * 'attachments' => array( // List of attachments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
72 * 'name' => 'File name',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
73 * 'mimetype' => 'Content type',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
74 * 'size' => 1..n, // in bytes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
75 * 'id' => 'Attachment identifier'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
76 * ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
77 * 'deleted_attachments' => array(), // array of attachment identifiers to delete when event is updated
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
78 * 'attendees' => array( // List of event participants
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
79 * 'name' => 'Participant name',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
80 * 'email' => 'Participant e-mail address', // used as identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
81 * 'role' => 'ORGANIZER|REQ-PARTICIPANT|OPT-PARTICIPANT|CHAIR',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
82 * 'status' => 'NEEDS-ACTION|UNKNOWN|ACCEPTED|TENTATIVE|DECLINED'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
83 * 'rsvp' => true|false,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
84 * ),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
85 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
86 * '_savemode' => 'all|future|current|new', // How changes on recurring event should be handled
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
87 * '_notify' => true|false, // whether to notify event attendees about changes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
88 * '_fromcalendar' => 'Calendar identifier where the event was stored before',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
89 * );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
90 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
91
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
92 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
93 * Interface definition for calendar driver classes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
94 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
95 abstract class calendar_driver
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
96 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
97 const FILTER_ALL = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
98 const FILTER_WRITEABLE = 1;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
99 const FILTER_INSERTABLE = 2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
100 const FILTER_ACTIVE = 4;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
101 const FILTER_PERSONAL = 8;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
102 const FILTER_PRIVATE = 16;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
103 const FILTER_CONFIDENTIAL = 32;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
104 const FILTER_SHARED = 64;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
105 const BIRTHDAY_CALENDAR_ID = '__bdays__';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
106
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
107 // features supported by backend
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
108 public $alarms = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
109 public $attendees = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
110 public $freebusy = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
111 public $attachments = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
112 public $undelete = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
113 public $history = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
114 public $categoriesimmutable = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
115 public $alarm_types = array('DISPLAY');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
116 public $alarm_absolute = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
117 public $last_error;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
118
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
119 protected $default_categories = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
120 'Personal' => 'c0c0c0',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
121 'Work' => 'ff0000',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
122 'Family' => '00ff00',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
123 'Holiday' => 'ff6600',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
124 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
125
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
126 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
127 * Get a list of available calendars from this source
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
128 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
129 * @param integer Bitmask defining filter criterias.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
130 * See FILTER_* constants for possible values.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
131 * @return array List of calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
132 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
133 abstract function list_calendars($filter = 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
134
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
135 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
136 * Create a new calendar assigned to the current user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
137 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
138 * @param array Hash array with calendar properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
139 * name: Calendar name
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
140 * color: The color of the calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
141 * showalarms: True if alarms are enabled
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
142 * @return mixed ID of the calendar on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
143 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
144 abstract function create_calendar($prop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
145
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
146 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
147 * Update properties of an existing calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
148 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
149 * @param array Hash array with calendar properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
150 * id: Calendar Identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
151 * name: Calendar name
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
152 * color: The color of the calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
153 * showalarms: True if alarms are enabled (if supported)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
154 * @return boolean True on success, Fales on failure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
155 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
156 abstract function edit_calendar($prop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
157
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
158 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
159 * Set active/subscribed state of a calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
160 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
161 * @param array Hash array with calendar properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
162 * id: Calendar Identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
163 * active: True if calendar is active, false if not
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
164 * @return boolean True on success, Fales on failure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
165 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
166 abstract function subscribe_calendar($prop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
167
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
168 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
169 * Delete the given calendar with all its contents
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
170 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
171 * @param array Hash array with calendar properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
172 * id: Calendar Identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
173 * @return boolean True on success, Fales on failure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
174 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
175 abstract function delete_calendar($prop);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
176
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
177 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
178 * Search for shared or otherwise not listed calendars the user has access
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
179 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
180 * @param string Search string
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
181 * @param string Section/source to search
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
182 * @return array List of calendars
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
183 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
184 abstract function search_calendars($query, $source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
185
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
186 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
187 * Add a single event to the database
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
188 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
189 * @param array Hash array with event properties (see header of this file)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
190 * @return mixed New event ID on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
191 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
192 abstract function new_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
193
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
194 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
195 * Update an event entry with the given data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
196 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
197 * @param array Hash array with event properties (see header of this file)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
198 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
199 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
200 abstract function edit_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
201
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
202 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
203 * Extended event editing with possible changes to the argument
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
204 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
205 * @param array Hash array with event properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
206 * @param string New participant status
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
207 * @param array List of hash arrays with updated attendees
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
208 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
209 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
210 public function edit_rsvp(&$event, $status, $attendees)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
211 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
212 return $this->edit_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
213 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
214
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
215 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
216 * Update the participant status for the given attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
217 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
218 * @param array Hash array with event properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
219 * @param array List of hash arrays each represeting an updated attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
220 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
221 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
222 public function update_attendees(&$event, $attendees)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
223 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
224 return $this->edit_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
225 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
226
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
227 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
228 * Move a single event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
229 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
230 * @param array Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
231 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
232 * start: Event start date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
233 * end: Event end date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
234 * allday: Boolean flag if this is an all-day event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
235 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
236 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
237 abstract function move_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
238
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
239 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
240 * Resize a single event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
241 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
242 * @param array Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
243 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
244 * start: Event start date/time as DateTime object with timezone
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
245 * end: Event end date/time as DateTime object with timezone
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
246 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
247 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
248 abstract function resize_event($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
249
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
250 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
251 * Remove a single event from the database
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
252 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
253 * @param array Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
254 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
255 * @param boolean Remove event irreversible (mark as deleted otherwise,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
256 * if supported by the backend)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
257 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
258 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
259 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
260 abstract function remove_event($event, $force = true);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
261
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
262 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
263 * Restores a single deleted event (if supported)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
264 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
265 * @param array Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
266 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
267 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
268 * @return boolean True on success, False on error
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
269 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
270 public function restore_event($event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
271 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
272 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
273 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
274
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
275 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
276 * Return data of a single event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
277 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
278 * @param mixed UID string or hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
279 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
280 * uid: Event UID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
281 * _instance: Instance identifier in combination with uid (optional)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
282 * calendar: Calendar identifier (optional)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
283 * @param integer Bitmask defining the scope to search events in.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
284 * See FILTER_* constants for possible values.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
285 * @param boolean If true, recurrence exceptions shall be added
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
286 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
287 * @return array Event object as hash array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
288 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
289 abstract function get_event($event, $scope = 0, $full = false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
290
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
291 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
292 * Get events from source.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
293 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
294 * @param integer Date range start (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
295 * @param integer Date range end (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
296 * @param string Search query (optional)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
297 * @param mixed List of calendar IDs to load events from (either as array or comma-separated string)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
298 * @param boolean Include virtual/recurring events (optional)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
299 * @param integer Only list events modified since this time (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
300 * @return array A list of event objects (see header of this file for struct of an event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
301 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
302 abstract function load_events($start, $end, $query = null, $calendars = null, $virtual = 1, $modifiedsince = null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
303
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
304 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
305 * Get number of events in the given calendar
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
306 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
307 * @param mixed List of calendar IDs to count events (either as array or comma-separated string)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
308 * @param integer Date range start (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
309 * @param integer Date range end (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
310 * @return array Hash array with counts grouped by calendar ID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
311 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
312 abstract function count_events($calendars, $start, $end = null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
313
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
314 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
315 * Get a list of pending alarms to be displayed to the user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
316 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
317 * @param integer Current time (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
318 * @param mixed List of calendar IDs to show alarms for (either as array or comma-separated string)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
319 * @return array A list of alarms, each encoded as hash array:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
320 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
321 * uid: Unique identifier of this event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
322 * start: Event start date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
323 * end: Event end date/time as DateTime object
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
324 * allday: Boolean flag if this is an all-day event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
325 * title: Event title/summary
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
326 * location: Location string
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
327 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
328 abstract function pending_alarms($time, $calendars = null);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
329
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
330 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
331 * (User) feedback after showing an alarm notification
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
332 * This should mark the alarm as 'shown' or snooze it for the given amount of time
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
333 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
334 * @param string Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
335 * @param integer Suspend the alarm for this number of seconds
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
336 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
337 abstract function dismiss_alarm($event_id, $snooze = 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
338
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
339 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
340 * Check the given event object for validity
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
341 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
342 * @param array Event object as hash array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
343 * @return boolean True if valid, false if not
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
344 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
345 public function validate($event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
346 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
347 $valid = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
348
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
349 if (!is_object($event['start']) || !is_a($event['start'], 'DateTime'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
350 $valid = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
351 if (!is_object($event['end']) || !is_a($event['end'], 'DateTime'))
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
352 $valid = false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
353
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
354 return $valid;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
355 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
356
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
357
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
358 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
359 * Get list of event's attachments.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
360 * Drivers can return list of attachments as event property.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
361 * If they will do not do this list_attachments() method will be used.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
362 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
363 * @param array $event Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
364 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
365 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
366 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
367 * @return array List of attachments, each as hash array:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
368 * id: Attachment identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
369 * name: Attachment name
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
370 * mimetype: MIME content type of the attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
371 * size: Attachment size
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
372 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
373 public function list_attachments($event) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
374
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
375 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
376 * Get attachment properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
377 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
378 * @param string $id Attachment identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
379 * @param array $event Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
380 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
381 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
382 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
383 * @return array Hash array with attachment properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
384 * id: Attachment identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
385 * name: Attachment name
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
386 * mimetype: MIME content type of the attachment
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
387 * size: Attachment size
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
388 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
389 public function get_attachment($id, $event) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
390
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
391 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
392 * Get attachment body
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
393 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
394 * @param string $id Attachment identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
395 * @param array $event Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
396 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
397 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
398 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
399 * @return string Attachment body
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
400 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
401 public function get_attachment_body($id, $event) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
402
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
403 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
404 * Build a struct representing the given message reference
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
405 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
406 * @param object|string $uri_or_headers rcube_message_header instance holding the message headers
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
407 * or an URI from a stored link referencing a mail message.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
408 * @param string $folder IMAP folder the message resides in
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
409 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
410 * @return array An struct referencing the given IMAP message
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
411 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
412 public function get_message_reference($uri_or_headers, $folder = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
413 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
414 // to be implemented by the derived classes
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
415 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
416 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
417
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
418 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
419 * List availabale categories
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
420 * The default implementation reads them from config/user prefs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
421 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
422 public function list_categories()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
423 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
424 $rcmail = rcube::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
425 return $rcmail->config->get('calendar_categories', $this->default_categories);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
426 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
427
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
428 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
429 * Create a new category
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
430 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
431 public function add_category($name, $color) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
432
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
433 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
434 * Remove the given category
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
435 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
436 public function remove_category($name) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
437
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
438 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
439 * Update/replace a category
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
440 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
441 public function replace_category($oldname, $name, $color) { }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
442
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
443 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
444 * Fetch free/busy information from a person within the given range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
445 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
446 * @param string E-mail address of attendee
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
447 * @param integer Requested period start date/time as unix timestamp
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
448 * @param integer Requested period end date/time as unix timestamp
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
449 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
450 * @return array List of busy timeslots within the requested range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
451 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
452 public function get_freebusy_list($email, $start, $end)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
453 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
454 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
455 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
456
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
457 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
458 * Create instances of a recurring event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
459 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
460 * @param array Hash array with event properties
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
461 * @param object DateTime Start date of the recurrence window
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
462 * @param object DateTime End date of the recurrence window
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
463 * @return array List of recurring event instances
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
464 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
465 public function get_recurring_events($event, $start, $end = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
466 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
467 $events = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
468
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
469 if ($event['recurrence']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
470 // include library class
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
471 require_once(dirname(__FILE__) . '/../lib/calendar_recurrence.php');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
472
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
473 $rcmail = rcmail::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
474 $recurrence = new calendar_recurrence($rcmail->plugins->get_plugin('calendar'), $event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
475 $recurrence_id_format = libcalendaring::recurrence_id_format($event);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
476
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
477 // determine a reasonable end date if none given
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
478 if (!$end) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
479 switch ($event['recurrence']['FREQ']) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
480 case 'YEARLY': $intvl = 'P100Y'; break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
481 case 'MONTHLY': $intvl = 'P20Y'; break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
482 default: $intvl = 'P10Y'; break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
483 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
484
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
485 $end = clone $event['start'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
486 $end->add(new DateInterval($intvl));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
487 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
488
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
489 $i = 0;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
490 while ($next_event = $recurrence->next_instance()) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
491 // add to output if in range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
492 if (($next_event['start'] <= $end && $next_event['end'] >= $start)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
493 $next_event['_instance'] = $next_event['start']->format($recurrence_id_format);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
494 $next_event['id'] = $next_event['uid'] . '-' . $exception['_instance'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
495 $next_event['recurrence_id'] = $event['uid'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
496 $events[] = $next_event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
497 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
498 else if ($next_event['start'] > $end) { // stop loop if out of range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
499 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
500 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
501
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
502 // avoid endless recursion loops
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
503 if (++$i > 1000) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
504 break;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
505 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
506 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
507 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
508
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
509 return $events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
510 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
511
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
512 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
513 * Provide a list of revisions for the given event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
514 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
515 * @param array $event Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
516 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
517 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
518 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
519 * @return array List of changes, each as a hash array:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
520 * rev: Revision number
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
521 * type: Type of the change (create, update, move, delete)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
522 * date: Change date
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
523 * user: The user who executed the change
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
524 * ip: Client IP
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
525 * destination: Destination calendar for 'move' type
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
526 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
527 public function get_event_changelog($event)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
528 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
529 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
530 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
531
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
532 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
533 * Get a list of property changes beteen two revisions of an event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
534 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
535 * @param array $event Hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
536 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
537 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
538 * @param mixed $rev1 Old Revision
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
539 * @param mixed $rev2 New Revision
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
540 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
541 * @return array List of property changes, each as a hash array:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
542 * property: Revision number
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
543 * old: Old property value
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
544 * new: Updated property value
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
545 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
546 public function get_event_diff($event, $rev1, $rev2)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
547 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
548 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
549 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
550
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
551 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
552 * Return full data of a specific revision of an event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
553 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
554 * @param mixed UID string or hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
555 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
556 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
557 * @param mixed $rev Revision number
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
558 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
559 * @return array Event object as hash array
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
560 * @see self::get_event()
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
561 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
562 public function get_event_revison($event, $rev)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
563 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
564 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
565 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
566
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
567 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
568 * Command the backend to restore a certain revision of an event.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
569 * This shall replace the current event with an older version.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
570 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
571 * @param mixed UID string or hash array with event properties:
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
572 * id: Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
573 * calendar: Calendar identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
574 * @param mixed $rev Revision number
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
575 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
576 * @return boolean True on success, False on failure
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
577 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
578 public function restore_event_revision($event, $rev)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
579 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
580 return false;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
581 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
582
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
583
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
584 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
585 * Callback function to produce driver-specific calendar create/edit form
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
586 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
587 * @param string Request action 'form-edit|form-new'
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
588 * @param array Calendar properties (e.g. id, color)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
589 * @param array Edit form fields
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
590 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
591 * @return string HTML content of the form
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
592 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
593 public function calendar_form($action, $calendar, $formfields)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
594 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
595 $html = '';
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
596 foreach ($formfields as $field) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
597 $html .= html::div('form-section',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
598 html::label($field['id'], $field['label']) .
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
599 $field['value']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
600 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
601
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
602 return $html;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
603 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
604
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
605 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
606 * Compose a list of birthday events from the contact records in the user's address books.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
607 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
608 * This is a default implementation using Roundcube's address book API.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
609 * It can be overriden with a more optimized version by the individual drivers.
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
610 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
611 * @param integer Event's new start (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
612 * @param integer Event's new end (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
613 * @param string Search query (optional)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
614 * @param integer Only list events modified since this time (unix timestamp)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
615 * @return array A list of event records
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
616 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
617 public function load_birthday_events($start, $end, $search = null, $modifiedsince = null)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
618 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
619 // ignore update requests for simplicity reasons
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
620 if (!empty($modifiedsince)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
621 return array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
622 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
623
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
624 // convert to DateTime for comparisons
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
625 $start = new DateTime('@'.$start);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
626 $end = new DateTime('@'.$end);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
627 // extract the current year
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
628 $year = $start->format('Y');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
629 $year2 = $end->format('Y');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
630
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
631 $events = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
632 $search = mb_strtolower($search);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
633 $rcmail = rcmail::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
634 $cache = $rcmail->get_cache('calendar.birthdays', 'db', 3600);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
635 $cache->expunge();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
636
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
637 $alarm_type = $rcmail->config->get('calendar_birthdays_alarm_type', '');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
638 $alarm_offset = $rcmail->config->get('calendar_birthdays_alarm_offset', '-1D');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
639 $alarms = $alarm_type ? $alarm_offset . ':' . $alarm_type : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
640
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
641 // let the user select the address books to consider in prefs
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
642 $selected_sources = $rcmail->config->get('calendar_birthday_adressbooks');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
643 $sources = $selected_sources ?: array_keys($rcmail->get_address_sources(false, true));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
644 foreach ($sources as $source) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
645 $abook = $rcmail->get_address_book($source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
646
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
647 // skip LDAP address books unless selected by the user
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
648 if (!$abook || ($abook instanceof rcube_ldap && empty($selected_sources))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
649 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
650 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
651
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
652 $abook->set_pagesize(10000);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
653
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
654 // check for cached results
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
655 $cache_records = array();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
656 $cached = $cache->get($source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
657
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
658 // iterate over (cached) contacts
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
659 foreach (($cached ?: $abook->search('*', '', 2, true, true, array('birthday'))) as $contact) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
660 $event = self::parse_contact($contact, $source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
661
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
662 if (empty($event)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
663 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
664 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
665
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
666 // add stripped record to cache
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
667 if (empty($cached)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
668 $cache_records[] = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
669 'ID' => $contact['ID'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
670 'name' => $event['_displayname'],
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
671 'birthday' => $event['start']->format('Y-m-d'),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
672 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
673 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
674
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
675 // filter by search term (only name is involved here)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
676 if (!empty($search) && strpos(mb_strtolower($event['title']), $search) === false) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
677 continue;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
678 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
679
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
680 $bday = clone $event['start'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
681 $byear = $bday->format('Y');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
682
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
683 // quick-and-dirty recurrence computation: just replace the year
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
684 $bday->setDate($year, $bday->format('n'), $bday->format('j'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
685 $bday->setTime(12, 0, 0);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
686 $this_year = $year;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
687
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
688 // date range reaches over multiple years: use end year if not in range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
689 if (($bday > $end || $bday < $start) && $year2 != $year) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
690 $bday->setDate($year2, $bday->format('n'), $bday->format('j'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
691 $this_year = $year2;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
692 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
693
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
694 // birthday is within requested range
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
695 if ($bday <= $end && $bday >= $start) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
696 unset($event['_displayname']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
697 $event['alarms'] = $alarms;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
698
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
699 // if this is not the first occurence modify event details
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
700 // but not when this is "all birthdays feed" request
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
701 if ($year2 - $year < 10 && ($age = ($this_year - $byear))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
702 $event['description'] = $rcmail->gettext(array('name' => 'birthdayage', 'vars' => array('age' => $age)), 'calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
703 $event['start'] = $bday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
704 $event['end'] = clone $bday;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
705 unset($event['recurrence']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
706 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
707
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
708 // add the main instance
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
709 $events[] = $event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
710 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
711 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
712
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
713 // store collected contacts in cache
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
714 if (empty($cached)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
715 $cache->write($source, $cache_records);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
716 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
717 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
718
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
719 return $events;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
720 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
721
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
722 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
723 * Get a single birthday calendar event
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
724 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
725 public function get_birthday_event($id)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
726 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
727 // decode $id
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
728 list(,$source,$contact_id,$year) = explode(':', rcube_ldap::dn_decode($id));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
729
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
730 $rcmail = rcmail::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
731
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
732 if ($source && $contact_id && ($abook = $rcmail->get_address_book($source))) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
733 if ($contact = $abook->get_record($contact_id, true)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
734 return self::parse_contact($contact, $source);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
735 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
736 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
737 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
738
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
739 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
740 * Parse contact and create an event for its birthday
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
741 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
742 * @param array $contact Contact data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
743 * @param string $source Addressbook source ID
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
744 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
745 * @return array Birthday event data
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
746 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
747 public static function parse_contact($contact, $source)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
748 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
749 if (!is_array($contact)) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
750 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
751 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
752
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
753 if (is_array($contact['birthday'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
754 $contact['birthday'] = reset($contact['birthday']);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
755 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
756
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
757 if (empty($contact['birthday'])) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
758 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
759 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
760
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
761 try {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
762 $bday = $contact['birthday'];
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
763 if (!$bday instanceof DateTime) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
764 $bday = new DateTime($bday, new DateTimezone('UTC'));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
765 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
766 $bday->_dateonly = true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
767 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
768 catch (Exception $e) {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
769 rcube::raise_error(array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
770 'code' => 600, 'type' => 'php',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
771 'file' => __FILE__, 'line' => __LINE__,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
772 'message' => 'BIRTHDAY PARSE ERROR: ' . $e->getMessage()),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
773 true, false);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
774 return;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
775 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
776
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
777 $rcmail = rcmail::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
778 $birthyear = $bday->format('Y');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
779 $display_name = rcube_addressbook::compose_display_name($contact);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
780 $label = array('name' => 'birthdayeventtitle', 'vars' => array('name' => $display_name));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
781 $event_title = $rcmail->gettext($label, 'calendar');
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
782 $uid = rcube_ldap::dn_encode('bday:' . $source . ':' . $contact['ID'] . ':' . $birthyear);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
783
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
784 $event = array(
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
785 'id' => $uid,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
786 'uid' => $uid,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
787 'calendar' => self::BIRTHDAY_CALENDAR_ID,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
788 'title' => $event_title,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
789 'description' => '',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
790 'allday' => true,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
791 'start' => $bday,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
792 'end' => clone $bday,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
793 'recurrence' => array('FREQ' => 'YEARLY', 'INTERVAL' => 1),
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
794 'free_busy' => 'free',
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
795 '_displayname' => $display_name,
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
796 );
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
797
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
798 return $event;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
799 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
800
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
801 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
802 * Store alarm dismissal for birtual birthay events
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
803 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
804 * @param string Event identifier
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
805 * @param integer Suspend the alarm for this number of seconds
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
806 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
807 public function dismiss_birthday_alarm($event_id, $snooze = 0)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
808 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
809 $rcmail = rcmail::get_instance();
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
810 $cache = $rcmail->get_cache('calendar.birthdayalarms', 'db', 86400 * 30);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
811 $cache->remove($event_id);
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
812
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
813 // compute new notification time or disable if not snoozed
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
814 $notifyat = $snooze > 0 ? time() + $snooze : null;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
815 $cache->set($event_id, array('snooze' => $snooze, 'notifyat' => $notifyat));
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
816
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
817 return true;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
818 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
819
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
820 /**
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
821 * Handler for user_delete plugin hook
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
822 *
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
823 * @param array Hash array with hook arguments
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
824 * @return array Return arguments for plugin hooks
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
825 */
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
826 public function user_delete($args)
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
827 {
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
828 // TO BE OVERRIDDEN
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
829 return $args;
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
830 }
f6fe4b6ae66a calendar plugin nearly as distributed
Charlie Root
parents:
diff changeset
831 }