annotate plugins/libcalendaring/libcalendaring.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 * Library providing common functions for calendaring plugins
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 * Provides utility functions for calendar-related modules such as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 * - alarms display and dismissal
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * - attachment handling
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * - recurrence computation and UI elements
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * - ical parsing and exporting
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * - itip scheduling protocol
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * @version @package_version@
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * @author Thomas Bruederli <bruederli@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 * Copyright (C) 2012-2015, Kolab Systems AG <contact@kolabsys.com>
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * This program is free software: you can redistribute it and/or modify
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 * it under the terms of the GNU Affero General Public License as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * published by the Free Software Foundation, either version 3 of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * License, or (at your option) any later version.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 * This program is distributed in the hope that it will be useful,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 * GNU Affero General Public License for more details.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 * You should have received a copy of the GNU Affero General Public License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 class libcalendaring extends rcube_plugin
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 public $rc;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 public $timezone;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 public $gmt_offset;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 public $dst_active;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 public $timezone_offset;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 public $ical_parts = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 public $ical_message;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 public $defaults = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 'calendar_date_format' => "yyyy-MM-dd",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 'calendar_date_short' => "M-d",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 'calendar_date_long' => "MMM d yyyy",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 'calendar_date_agenda' => "ddd MM-dd",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 'calendar_time_format' => "HH:mm",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 'calendar_first_day' => 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 'calendar_first_hour' => 6,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 'calendar_date_format_sets' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 'yyyy-MM-dd' => array('MMM d yyyy', 'M-d', 'ddd MM-dd'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 'dd-MM-yyyy' => array('d MMM yyyy', 'd-M', 'ddd dd-MM'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 'yyyy/MM/dd' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54 'MM/dd/yyyy' => array('MMM d yyyy', 'M/d', 'ddd MM/dd'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 'dd/MM/yyyy' => array('d MMM yyyy', 'd/M', 'ddd dd/MM'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 'dd.MM.yyyy' => array('dd. MMM yyyy', 'd.M', 'ddd dd.MM.'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 'd.M.yyyy' => array('d. MMM yyyy', 'd.M', 'ddd d.MM.'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 ),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 private static $instance;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 private $mail_ical_parser;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 * Singleton getter to allow direct access from other plugins
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 public static function get_instance()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 if (!self::$instance) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 self::$instance = new libcalendaring(rcube::get_instance()->plugins);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 self::$instance->init_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 return self::$instance;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 * Initializes class properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 public function init_instance()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 $this->rc = rcube::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 // set user's timezone
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 try {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 $this->timezone = new DateTimeZone($this->rc->config->get('timezone', 'GMT'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 catch (Exception $e) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 $this->timezone = new DateTimeZone('GMT');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 $now = new DateTime('now', $this->timezone);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95 $this->gmt_offset = $now->getOffset();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 $this->dst_active = $now->format('I');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 $this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99 $this->add_texts('localization/', false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 * Required plugin startup method
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 public function init()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 self::$instance = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 $this->rc = rcube::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110 $this->init_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 // include client scripts and styles
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113 if ($this->rc->output) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 // add hook to display alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115 $this->add_hook('refresh', array($this, 'refresh'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 $this->register_action('plugin.alarms', array($this, 'alarms_action'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 $this->register_action('plugin.expand_attendee_group', array($this, 'expand_attendee_group'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 // proceed initialization in startup hook
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121 $this->add_hook('startup', array($this, 'startup'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 * Startup hook
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 public function startup($args)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 if ($this->rc->output && $this->rc->output->type == 'html') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 $this->rc->output->set_env('libcal_settings', $this->load_settings());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 $this->include_script('libcalendaring.js');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132 $this->include_stylesheet($this->local_skin_path() . '/libcal.css');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134 $this->add_label(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 'itipaccepted', 'itiptentative', 'itipdeclined',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 'itipdelegated', 'expandattendeegroup', 'expandattendeegroupnodata',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 'statusorganizer', 'statusaccepted', 'statusdeclined',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 'statusdelegated', 'statusunknown', 'statusneeds-action',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 'statustentative', 'statuscompleted', 'statusin-process',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 'delegatedto', 'delegatedfrom'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144 if ($args['task'] == 'mail') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 if ($args['action'] == 'show' || $args['action'] == 'preview') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 $this->add_hook('message_load', array($this, 'mail_message_load'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 * Load iCalendar functions
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 public static function get_ical()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 $self = self::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 require_once __DIR__ . '/libvcalendar.php';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 return new libvcalendar();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 * Load iTip functions
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 public static function get_itip($domain = 'libcalendaring')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 $self = self::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167 require_once __DIR__ . '/lib/libcalendaring_itip.php';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 return new libcalendaring_itip($self, $domain);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 * Load recurrence computation engine
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 public static function get_recurrence()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 $self = self::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177 require_once __DIR__ . '/lib/libcalendaring_recurrence.php';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 return new libcalendaring_recurrence($self);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
181 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
182 * Shift dates into user's current timezone
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
183 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
184 * @param mixed Any kind of a date representation (DateTime object, string or unix timestamp)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
185 * @return object DateTime object in user's timezone
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
186 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
187 public function adjust_timezone($dt, $dateonly = false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
188 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
189 if (is_numeric($dt))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
190 $dt = new DateTime('@'.$dt);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
191 else if (is_string($dt))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
192 $dt = rcube_utils::anytodatetime($dt);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
193
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
194 if ($dt instanceof DateTime && !($dt->_dateonly || $dateonly)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
195 $dt->setTimezone($this->timezone);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
196 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
197
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
198 return $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
199 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
200
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
201
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
202 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
203 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
204 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
205 public function load_settings()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
206 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
207 $this->date_format_defaults();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
208
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
209 $settings = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
210 $keys = array('date_format', 'time_format', 'date_short', 'date_long');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
211
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
212 foreach ($keys as $key) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
213 $settings[$key] = (string)$this->rc->config->get('calendar_' . $key, $this->defaults['calendar_' . $key]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
214 $settings[$key] = str_replace('Y', 'y', $settings[$key]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
215 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
216
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
217 $settings['dates_long'] = str_replace(' yyyy', '[ yyyy]', $settings['date_long']) . "{ '&mdash;' " . $settings['date_long'] . '}';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
218 $settings['first_day'] = (int)$this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
219 $settings['timezone'] = $this->timezone_offset;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
220 $settings['dst'] = $this->dst_active;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
221
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
222 // localization
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
223 $settings['days'] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
224 $this->rc->gettext('sunday'), $this->rc->gettext('monday'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
225 $this->rc->gettext('tuesday'), $this->rc->gettext('wednesday'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
226 $this->rc->gettext('thursday'), $this->rc->gettext('friday'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
227 $this->rc->gettext('saturday')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
228 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
229 $settings['days_short'] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
230 $this->rc->gettext('sun'), $this->rc->gettext('mon'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
231 $this->rc->gettext('tue'), $this->rc->gettext('wed'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
232 $this->rc->gettext('thu'), $this->rc->gettext('fri'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
233 $this->rc->gettext('sat')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
234 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
235 $settings['months'] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
236 $this->rc->gettext('longjan'), $this->rc->gettext('longfeb'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
237 $this->rc->gettext('longmar'), $this->rc->gettext('longapr'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
238 $this->rc->gettext('longmay'), $this->rc->gettext('longjun'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
239 $this->rc->gettext('longjul'), $this->rc->gettext('longaug'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
240 $this->rc->gettext('longsep'), $this->rc->gettext('longoct'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
241 $this->rc->gettext('longnov'), $this->rc->gettext('longdec')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
242 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
243 $settings['months_short'] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
244 $this->rc->gettext('jan'), $this->rc->gettext('feb'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
245 $this->rc->gettext('mar'), $this->rc->gettext('apr'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
246 $this->rc->gettext('may'), $this->rc->gettext('jun'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
247 $this->rc->gettext('jul'), $this->rc->gettext('aug'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
248 $this->rc->gettext('sep'), $this->rc->gettext('oct'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
249 $this->rc->gettext('nov'), $this->rc->gettext('dec')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
250 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
251 $settings['today'] = $this->rc->gettext('today');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
252
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
253 // define list of file types which can be displayed inline
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
254 // same as in program/steps/mail/show.inc
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
255 $settings['mimetypes'] = (array)$this->rc->config->get('client_mimetypes');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
256
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
257 return $settings;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
258 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
259
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
260
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
261 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
262 * Helper function to set date/time format according to config and user preferences
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
263 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
264 private function date_format_defaults()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
265 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
266 static $defaults = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
267
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
268 // nothing to be done
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
269 if (isset($defaults['date_format']))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
270 return;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
271
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
272 $defaults['date_format'] = $this->rc->config->get('calendar_date_format', self::from_php_date_format($this->rc->config->get('date_format')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
273 $defaults['time_format'] = $this->rc->config->get('calendar_time_format', self::from_php_date_format($this->rc->config->get('time_format')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
274
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
275 // override defaults
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
276 if ($defaults['date_format'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
277 $this->defaults['calendar_date_format'] = $defaults['date_format'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
278 if ($defaults['time_format'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
279 $this->defaults['calendar_time_format'] = $defaults['time_format'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
280
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
281 // derive format variants from basic date format
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
282 $format_sets = $this->rc->config->get('calendar_date_format_sets', $this->defaults['calendar_date_format_sets']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
283 if ($format_set = $format_sets[$this->defaults['calendar_date_format']]) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
284 $this->defaults['calendar_date_long'] = $format_set[0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
285 $this->defaults['calendar_date_short'] = $format_set[1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
286 $this->defaults['calendar_date_agenda'] = $format_set[2];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
287 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
288 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
289
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
290 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
291 * Compose a date string for the given event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
292 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
293 public function event_date_text($event, $tzinfo = false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
294 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
295 $fromto = '--';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
296
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
297 // handle task objects
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
298 if ($event['_type'] == 'task' && is_object($event['due'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
299 $date_format = $event['due']->_dateonly ? self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format'])) : null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
300 $fromto = $this->rc->format_date($event['due'], $date_format, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
301
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
302 // add timezone information
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
303 if ($fromto && $tzinfo && ($tzname = $this->timezone->getName())) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
304 $fromto .= ' (' . strtr($tzname, '_', ' ') . ')';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
305 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
306
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
307 return $fromto;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
308 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
309
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
310 // abort if no valid event dates are given
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
311 if (!is_object($event['start']) || !is_a($event['start'], 'DateTime') || !is_object($event['end']) || !is_a($event['end'], 'DateTime')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
312 return $fromto;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
313 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
314
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
315 $duration = $event['start']->diff($event['end'])->format('s');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
316
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
317 $this->date_format_defaults();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
318 $date_format = self::to_php_date_format($this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
319 $time_format = self::to_php_date_format($this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
320
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
321 if ($event['allday']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
322 $fromto = $this->rc->format_date($event['start'], $date_format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
323 if (($todate = $this->rc->format_date($event['end'], $date_format)) != $fromto)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
324 $fromto .= ' - ' . $todate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
325 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
326 else if ($duration < 86400 && $event['start']->format('d') == $event['end']->format('d')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
327 $fromto = $this->rc->format_date($event['start'], $date_format) . ' ' . $this->rc->format_date($event['start'], $time_format) .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
328 ' - ' . $this->rc->format_date($event['end'], $time_format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
329 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
330 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
331 $fromto = $this->rc->format_date($event['start'], $date_format) . ' ' . $this->rc->format_date($event['start'], $time_format) .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
332 ' - ' . $this->rc->format_date($event['end'], $date_format) . ' ' . $this->rc->format_date($event['end'], $time_format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
333 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
334
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
335 // add timezone information
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
336 if ($tzinfo && ($tzname = $this->timezone->getName())) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
337 $fromto .= ' (' . strtr($tzname, '_', ' ') . ')';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
338 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
339
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
340 return $fromto;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
341 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
342
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
343
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
344 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
345 * Render HTML form for alarm configuration
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
346 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
347 public function alarm_select($attrib, $alarm_types, $absolute_time = true)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
348 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
349 unset($attrib['name']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
350
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
351 $input_value = new html_inputfield(array('name' => 'alarmvalue[]', 'class' => 'edit-alarm-value', 'size' => 3));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
352 $input_date = new html_inputfield(array('name' => 'alarmdate[]', 'class' => 'edit-alarm-date', 'size' => 10));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
353 $input_time = new html_inputfield(array('name' => 'alarmtime[]', 'class' => 'edit-alarm-time', 'size' => 6));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
354 $select_type = new html_select(array('name' => 'alarmtype[]', 'class' => 'edit-alarm-type', 'id' => $attrib['id']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
355 $select_offset = new html_select(array('name' => 'alarmoffset[]', 'class' => 'edit-alarm-offset'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
356 $select_related = new html_select(array('name' => 'alarmrelated[]', 'class' => 'edit-alarm-related'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
357 $object_type = $attrib['_type'] ?: 'event';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
358
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
359 $select_type->add($this->gettext('none'), '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
360 foreach ($alarm_types as $type)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
361 $select_type->add($this->gettext(strtolower("alarm{$type}option")), $type);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
362
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
363 foreach (array('-M','-H','-D','+M','+H','+D') as $trigger)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
364 $select_offset->add($this->gettext('trigger' . $trigger), $trigger);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
365
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
366 $select_offset->add($this->gettext('trigger0'), '0');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
367 if ($absolute_time)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
368 $select_offset->add($this->gettext('trigger@'), '@');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
369
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
370 $select_related->add($this->gettext('relatedstart'), 'start');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
371 $select_related->add($this->gettext('relatedend' . $object_type), 'end');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
372
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
373 // pre-set with default values from user settings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
374 $preset = self::parse_alarm_value($this->rc->config->get('calendar_default_alarm_offset', '-15M'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
375 $hidden = array('style' => 'display:none');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
376 $html = html::span('edit-alarm-set',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
377 $select_type->show($this->rc->config->get('calendar_default_alarm_type', '')) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
378 html::span(array('class' => 'edit-alarm-values', 'style' => 'display:none'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
379 $input_value->show($preset[0]) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
380 $select_offset->show($preset[1]) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
381 $select_related->show() . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
382 $input_date->show('', $hidden) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
383 $input_time->show('', $hidden)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
384 )
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
385 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
386
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
387 // TODO: support adding more alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
388 #$html .= html::a(array('href' => '#', 'id' => 'edit-alam-add', 'title' => $this->gettext('addalarm')),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
389 # $attrib['addicon'] ? html::img(array('src' => $attrib['addicon'], 'alt' => 'add')) : '(+)');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
390
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
391 return $html;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
392 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
393
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
394 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
395 * Get a list of email addresses of the given user (from login and identities)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
396 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
397 * @param string User Email (default to current user)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
398 * @return array Email addresses related to the user
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
399 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
400 public function get_user_emails($user = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
401 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
402 static $_emails = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
403
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
404 if (empty($user)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
405 $user = $this->rc->user->get_username();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
406 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
407
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
408 // return cached result
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
409 if (is_array($_emails[$user])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
410 return $_emails[$user];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
411 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
412
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
413 $emails = array($user);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
414 $plugin = $this->rc->plugins->exec_hook('calendar_user_emails', array('emails' => $emails));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
415 $emails = array_map('strtolower', $plugin['emails']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
416
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
417 // add all emails from the current user's identities
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
418 if (!$plugin['abort'] && ($user == $this->rc->user->get_username())) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
419 foreach ($this->rc->user->list_emails() as $identity) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
420 $emails[] = strtolower($identity['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
421 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
422 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
423
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
424 $_emails[$user] = array_unique($emails);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
425 return $_emails[$user];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
426 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
427
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
428 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
429 * Set the given participant status to the attendee matching the current user's identities
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
430 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
431 * @param array Hash array with event struct
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
432 * @param string The PARTSTAT value to set
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
433 * @return mixed Email address of the updated attendee or False if none matching found
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
434 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
435 public function set_partstat(&$event, $status, $recursive = true)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
436 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
437 $success = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
438 $emails = $this->get_user_emails();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
439 foreach ((array)$event['attendees'] as $i => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
440 if ($attendee['email'] && in_array(strtolower($attendee['email']), $emails)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
441 $event['attendees'][$i]['status'] = strtoupper($status);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
442 $success = $attendee['email'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
443 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
444 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
445
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
446 // apply partstat update to each existing exception
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
447 if ($event['recurrence'] && is_array($event['recurrence']['EXCEPTIONS'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
448 foreach ($event['recurrence']['EXCEPTIONS'] as $i => $exception) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
449 $this->set_partstat($event['recurrence']['EXCEPTIONS'][$i], $status, false);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
450 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
451
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
452 // set link to top-level exceptions
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
453 $event['exceptions'] = &$event['recurrence']['EXCEPTIONS'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
454 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
455
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
456 return $success;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
457 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
458
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
459
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
460 /********* Alarms handling *********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
461
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
462 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
463 * Helper function to convert alarm trigger strings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
464 * into two-field values (e.g. "-45M" => 45, "-M")
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
465 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
466 public static function parse_alarm_value($val)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
467 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
468 if ($val[0] == '@') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
469 return array(new DateTime($val));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
470 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
471 else if (preg_match('/([+-]?)P?(T?\d+[HMSDW])+/', $val, $m) && preg_match_all('/T?(\d+)([HMSDW])/', $val, $m2, PREG_SET_ORDER)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
472 if ($m[1] == '')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
473 $m[1] = '+';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
474 foreach ($m2 as $seg) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
475 $prefix = $seg[2] == 'D' || $seg[2] == 'W' ? 'P' : 'PT';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
476 if ($seg[1] > 0) { // ignore zero values
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
477 // convert seconds to minutes
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
478 if ($seg[2] == 'S') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
479 $seg[2] = 'M';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
480 $seg[1] = max(1, round($seg[1]/60));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
481 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
482
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
483 return array($seg[1], $m[1].$seg[2], $m[1].$seg[1].$seg[2], $m[1].$prefix.$seg[1].$seg[2]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
484 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
485 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
486
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
487 // return zero value nevertheless
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
488 return array($seg[1], $m[1].$seg[2], $m[1].$seg[1].$seg[2], $m[1].$prefix.$seg[1].$seg[2]);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
489 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
490
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
491 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
492 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
493
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
494 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
495 * Convert the alarms list items to be processed on the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
496 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
497 public static function to_client_alarms($valarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
498 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
499 return array_map(function($alarm){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
500 if ($alarm['trigger'] instanceof DateTime) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
501 $alarm['trigger'] = '@' . $alarm['trigger']->format('U');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
502 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
503 else if ($trigger = libcalendaring::parse_alarm_value($alarm['trigger'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
504 $alarm['trigger'] = $trigger[2];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
505 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
506 return $alarm;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
507 }, (array)$valarms);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
508 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
509
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
510 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
511 * Process the alarms values submitted by the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
512 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
513 public static function from_client_alarms($valarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
514 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
515 return array_map(function($alarm){
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
516 if ($alarm['trigger'][0] == '@') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
517 try {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
518 $alarm['trigger'] = new DateTime($alarm['trigger']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
519 $alarm['trigger']->setTimezone(new DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
520 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
521 catch (Exception $e) { /* handle this ? */ }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
522 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
523 else if ($trigger = libcalendaring::parse_alarm_value($alarm['trigger'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
524 $alarm['trigger'] = $trigger[3];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
525 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
526 return $alarm;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
527 }, (array)$valarms);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
528 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
529
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
530 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
531 * Render localized text for alarm settings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
532 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
533 public static function alarms_text($alarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
534 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
535 if (is_array($alarms) && is_array($alarms[0])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
536 $texts = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
537 foreach ($alarms as $alarm) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
538 if ($text = self::alarm_text($alarm))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
539 $texts[] = $text;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
540 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
541
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
542 return join(', ', $texts);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
543 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
544 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
545 return self::alarm_text($alarms);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
546 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
547 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
548
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
549 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
550 * Render localized text for a single alarm property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
551 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
552 public static function alarm_text($alarm)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
553 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
554 if (is_string($alarm)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
555 list($trigger, $action) = explode(':', $alarm);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
556 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
557 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
558 $trigger = $alarm['trigger'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
559 $action = $alarm['action'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
560 $related = $alarm['related'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
561 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
562
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
563 $text = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
564 $rcube = rcube::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
565
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
566 switch ($action) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
567 case 'EMAIL':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
568 $text = $rcube->gettext('libcalendaring.alarmemail');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
569 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
570 case 'DISPLAY':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
571 $text = $rcube->gettext('libcalendaring.alarmdisplay');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
572 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
573 case 'AUDIO':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
574 $text = $rcube->gettext('libcalendaring.alarmaudio');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
575 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
576 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
577
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
578 if ($trigger instanceof DateTime) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
579 $text .= ' ' . $rcube->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
580 'name' => 'libcalendaring.alarmat',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
581 'vars' => array('datetime' => $rcube->format_date($trigger))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
582 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
583 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
584 else if (preg_match('/@(\d+)/', $trigger, $m)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
585 $text .= ' ' . $rcube->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
586 'name' => 'libcalendaring.alarmat',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
587 'vars' => array('datetime' => $rcube->format_date($m[1]))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
588 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
589 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
590 else if ($val = self::parse_alarm_value($trigger)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
591 $r = strtoupper($related ?: 'start') == 'END' ? 'end' : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
592 // TODO: for all-day events say 'on date of event at XX' ?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
593 if ($val[0] == 0) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
594 $text .= ' ' . $rcube->gettext('libcalendaring.triggerattime' . $r);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
595 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
596 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
597 $label = 'libcalendaring.trigger' . $r . $val[1];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
598 $text .= ' ' . intval($val[0]) . ' ' . $rcube->gettext($label);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
599 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
600 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
601 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
602 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
603 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
604
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
605 return $text;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
606 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
607
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
608 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
609 * Get the next alarm (time & action) for the given event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
610 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
611 * @param array Record data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
612 * @return array Hash array with alarm time/type or null if no alarms are configured
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
613 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
614 public static function get_next_alarm($rec, $type = 'event')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
615 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
616 if (!($rec['valarms'] || $rec['alarms']) || $rec['cancelled'] || $rec['status'] == 'CANCELLED')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
617 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
618
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
619 if ($type == 'task') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
620 $timezone = self::get_instance()->timezone;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
621 if ($rec['startdate'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
622 $rec['start'] = new DateTime($rec['startdate'] . ' ' . ($rec['starttime'] ?: '12:00'), $timezone);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
623 if ($rec['date'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
624 $rec[($rec['start'] ? 'end' : 'start')] = new DateTime($rec['date'] . ' ' . ($rec['time'] ?: '12:00'), $timezone);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
625 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
626
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
627 if (!$rec['end'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
628 $rec['end'] = $rec['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
629
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
630 // support legacy format
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
631 if (!$rec['valarms']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
632 list($trigger, $action) = explode(':', $rec['alarms'], 2);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
633 if ($alarm = self::parse_alarm_value($trigger)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
634 $rec['valarms'] = array(array('action' => $action, 'trigger' => $alarm[3] ?: $alarm[0]));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
635 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
636 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
637
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
638 $expires = new DateTime('now - 12 hours');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
639 $alarm_id = $rec['id']; // alarm ID eq. record ID by default to keep backwards compatibility
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
640
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
641 // handle multiple alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
642 $notify_at = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
643 foreach ($rec['valarms'] as $alarm) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
644 $notify_time = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
645
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
646 if ($alarm['trigger'] instanceof DateTime) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
647 $notify_time = $alarm['trigger'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
648 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
649 else if (is_string($alarm['trigger'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
650 $refdate = $alarm['related'] == 'END' ? $rec['end'] : $rec['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
651
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
652 // abort if no reference date is available to compute notification time
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
653 if (!is_a($refdate, 'DateTime'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
654 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
655
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
656 // TODO: for all-day events, take start @ 00:00 as reference date ?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
657
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
658 try {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
659 $interval = new DateInterval(trim($alarm['trigger'], '+-'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
660 $interval->invert = $alarm['trigger'][0] == '-';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
661 $notify_time = clone $refdate;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
662 $notify_time->add($interval);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
663 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
664 catch (Exception $e) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
665 rcube::raise_error($e, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
666 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
667 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
668 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
669
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
670 if ($notify_time && (!$notify_at || ($notify_time > $notify_at && $notify_time > $expires))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
671 $notify_at = $notify_time;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
672 $action = $alarm['action'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
673 $alarm_prop = $alarm;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
674
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
675 // generate a unique alarm ID if multiple alarms are set
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
676 if (count($rec['valarms']) > 1) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
677 $alarm_id = substr(md5($rec['id']), 0, 16) . '-' . $notify_at->format('Ymd\THis');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
678 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
679 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
680 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
681
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
682 return !$notify_at ? null : array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
683 'time' => $notify_at->format('U'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
684 'action' => $action ? strtoupper($action) : 'DISPLAY',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
685 'id' => $alarm_id,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
686 'prop' => $alarm_prop,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
687 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
688 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
689
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
690 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
691 * Handler for keep-alive requests
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
692 * This will check for pending notifications and pass them to the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
693 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
694 public function refresh($attr)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
695 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
696 // collect pending alarms from all providers (e.g. calendar, tasks)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
697 $plugin = $this->rc->plugins->exec_hook('pending_alarms', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
698 'time' => time(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
699 'alarms' => array(),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
700 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
701
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
702 if (!$plugin['abort'] && !empty($plugin['alarms'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
703 // make sure texts and env vars are available on client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
704 $this->add_texts('localization/', true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
705 $this->rc->output->add_label('close');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
706 $this->rc->output->set_env('snooze_select', $this->snooze_select());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
707 $this->rc->output->command('plugin.display_alarms', $this->_alarms_output($plugin['alarms']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
708 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
709 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
710
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
711 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
712 * Handler for alarm dismiss/snooze requests
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
713 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
714 public function alarms_action()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
715 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
716 // $action = rcube_utils::get_input_value('action', rcube_utils::INPUT_GPC);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
717 $data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
718
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
719 $data['ids'] = explode(',', $data['id']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
720 $plugin = $this->rc->plugins->exec_hook('dismiss_alarms', $data);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
721
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
722 if ($plugin['success'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
723 $this->rc->output->show_message('successfullysaved', 'confirmation');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
724 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
725 $this->rc->output->show_message('calendar.errorsaving', 'error');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
726 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
727
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
728 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
729 * Generate reduced and streamlined output for pending alarms
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
730 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
731 private function _alarms_output($alarms)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
732 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
733 $out = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
734 foreach ($alarms as $alarm) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
735 $out[] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
736 'id' => $alarm['id'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
737 'start' => $alarm['start'] ? $this->adjust_timezone($alarm['start'])->format('c') : '',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
738 'end' => $alarm['end'] ? $this->adjust_timezone($alarm['end'])->format('c') : '',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
739 'allDay' => $alarm['allday'] == 1,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
740 'action' => $alarm['action'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
741 'title' => $alarm['title'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
742 'location' => $alarm['location'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
743 'calendar' => $alarm['calendar'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
744 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
745 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
746
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
747 return $out;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
748 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
749
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
750 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
751 * Render a dropdown menu to choose snooze time
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
752 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
753 private function snooze_select($attrib = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
754 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
755 $steps = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
756 5 => 'repeatinmin',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
757 10 => 'repeatinmin',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
758 15 => 'repeatinmin',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
759 20 => 'repeatinmin',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
760 30 => 'repeatinmin',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
761 60 => 'repeatinhr',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
762 120 => 'repeatinhrs',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
763 1440 => 'repeattomorrow',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
764 10080 => 'repeatinweek',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
765 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
766
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
767 $items = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
768 foreach ($steps as $n => $label) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
769 $items[] = html::tag('li', null, html::a(array('href' => "#" . ($n * 60), 'class' => 'active'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
770 $this->gettext(array('name' => $label, 'vars' => array('min' => $n % 60, 'hrs' => intval($n / 60))))));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
771 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
772
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
773 return html::tag('ul', $attrib + array('class' => 'toolbarmenu'), join("\n", $items), html::$common_attrib);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
774 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
775
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
776
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
777 /********* Recurrence rules handling ********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
778
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
779 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
780 * Render localized text describing the recurrence rule of an event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
781 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
782 public function recurrence_text($rrule)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
783 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
784 $limit = 10;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
785 $exdates = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
786 $format = $this->rc->config->get('calendar_date_format', $this->defaults['calendar_date_format']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
787 $format = self::to_php_date_format($format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
788 $format_fn = function($dt) use ($format) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
789 return rcmail::get_instance()->format_date($dt, $format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
790 };
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
791
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
792 if (is_array($rrule['EXDATE']) && !empty($rrule['EXDATE'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
793 $exdates = array_map($format_fn, $rrule['EXDATE']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
794 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
795
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
796 if (empty($rrule['FREQ']) && !empty($rrule['RDATE'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
797 $rdates = array_map($format_fn, $rrule['RDATE']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
798
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
799 if (!empty($exdates)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
800 $rdates = array_diff($rdates, $exdates);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
801 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
802
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
803 if (count($rdates) > $limit) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
804 $rdates = array_slice($rdates, 0, $limit);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
805 $more = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
806 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
807
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
808 return $this->gettext('ondate') . ' ' . join(', ', $rdates)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
809 . ($more ? '...' : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
810 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
811
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
812 $output = sprintf('%s %d ', $this->gettext('every'), $rrule['INTERVAL'] ?: 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
813
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
814 switch ($rrule['FREQ']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
815 case 'DAILY':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
816 $output .= $this->gettext('days');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
817 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
818 case 'WEEKLY':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
819 $output .= $this->gettext('weeks');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
820 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
821 case 'MONTHLY':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
822 $output .= $this->gettext('months');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
823 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
824 case 'YEARLY':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
825 $output .= $this->gettext('years');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
826 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
827 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
828
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
829 if ($rrule['COUNT']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
830 $until = $this->gettext(array('name' => 'forntimes', 'vars' => array('nr' => $rrule['COUNT'])));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
831 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
832 else if ($rrule['UNTIL']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
833 $until = $this->gettext('recurrencend') . ' ' . $this->rc->format_date($rrule['UNTIL'], $format);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
834 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
835 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
836 $until = $this->gettext('forever');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
837 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
838
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
839 $output .= ', ' . $until;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
840
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
841 if (!empty($exdates)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
842 if (count($exdates) > $limit) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
843 $exdates = array_slice($exdates, 0, $limit);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
844 $more = true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
845 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
846
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
847 $output = '; ' . $this->gettext('except') . ' ' . join(', ', $exdates)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
848 . ($more ? '...' : '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
849 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
850
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
851 return $output;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
852 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
853
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
854 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
855 * Generate the form for recurrence settings
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
856 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
857 public function recurrence_form($attrib = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
858 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
859 switch ($attrib['part']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
860 // frequency selector
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
861 case 'frequency':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
862 $select = new html_select(array('name' => 'frequency', 'id' => 'edit-recurrence-frequency'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
863 $select->add($this->gettext('never'), '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
864 $select->add($this->gettext('daily'), 'DAILY');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
865 $select->add($this->gettext('weekly'), 'WEEKLY');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
866 $select->add($this->gettext('monthly'), 'MONTHLY');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
867 $select->add($this->gettext('yearly'), 'YEARLY');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
868 $select->add($this->gettext('rdate'), 'RDATE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
869 $html = html::label('edit-recurrence-frequency', $this->gettext('frequency')) . $select->show('');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
870 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
871
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
872 // daily recurrence
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
873 case 'daily':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
874 $select = $this->interval_selector(array('name' => 'interval', 'class' => 'edit-recurrence-interval', 'id' => 'edit-recurrence-interval-daily'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
875 $html = html::div($attrib, html::label('edit-recurrence-interval-daily', $this->gettext('every')) . $select->show(1) . html::span('label-after', $this->gettext('days')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
876 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
877
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
878 // weekly recurrence form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
879 case 'weekly':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
880 $select = $this->interval_selector(array('name' => 'interval', 'class' => 'edit-recurrence-interval', 'id' => 'edit-recurrence-interval-weekly'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
881 $html = html::div($attrib, html::label('edit-recurrence-interval-weekly', $this->gettext('every')) . $select->show(1) . html::span('label-after', $this->gettext('weeks')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
882 // weekday selection
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
883 $daymap = array('sun','mon','tue','wed','thu','fri','sat');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
884 $checkbox = new html_checkbox(array('name' => 'byday', 'class' => 'edit-recurrence-weekly-byday'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
885 $first = $this->rc->config->get('calendar_first_day', 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
886 for ($weekdays = '', $j = $first; $j <= $first+6; $j++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
887 $d = $j % 7;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
888 $weekdays .= html::label(array('class' => 'weekday'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
889 $checkbox->show('', array('value' => strtoupper(substr($daymap[$d], 0, 2)))) .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
890 $this->gettext($daymap[$d])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
891 ) . ' ';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
892 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
893 $html .= html::div($attrib, html::label(null, $this->gettext('bydays')) . $weekdays);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
894 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
895
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
896 // monthly recurrence form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
897 case 'monthly':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
898 $select = $this->interval_selector(array('name' => 'interval', 'class' => 'edit-recurrence-interval', 'id' => 'edit-recurrence-interval-monthly'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
899 $html = html::div($attrib, html::label('edit-recurrence-interval-monthly', $this->gettext('every')) . $select->show(1) . html::span('label-after', $this->gettext('months')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
900
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
901 $checkbox = new html_checkbox(array('name' => 'bymonthday', 'class' => 'edit-recurrence-monthly-bymonthday'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
902 for ($monthdays = '', $d = 1; $d <= 31; $d++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
903 $monthdays .= html::label(array('class' => 'monthday'), $checkbox->show('', array('value' => $d)) . $d);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
904 $monthdays .= $d % 7 ? ' ' : html::br();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
905 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
906
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
907 // rule selectors
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
908 $radio = new html_radiobutton(array('name' => 'repeatmode', 'class' => 'edit-recurrence-monthly-mode'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
909 $table = new html_table(array('cols' => 2, 'border' => 0, 'cellpadding' => 0, 'class' => 'formtable'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
910 $table->add('label', html::label(null, $radio->show('BYMONTHDAY', array('value' => 'BYMONTHDAY')) . ' ' . $this->gettext('each')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
911 $table->add(null, $monthdays);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
912 $table->add('label', html::label(null, $radio->show('', array('value' => 'BYDAY')) . ' ' . $this->gettext('onevery')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
913 $table->add(null, $this->rrule_selectors($attrib['part']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
914
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
915 $html .= html::div($attrib, $table->show());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
916 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
917
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
918 // annually recurrence form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
919 case 'yearly':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
920 $select = $this->interval_selector(array('name' => 'interval', 'class' => 'edit-recurrence-interval', 'id' => 'edit-recurrence-interval-yearly'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
921 $html = html::div($attrib, html::label('edit-recurrence-interval-yearly', $this->gettext('every')) . $select->show(1) . html::span('label-after', $this->gettext('years')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
922 // month selector
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
923 $monthmap = array('','jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
924 $checkbox = new html_checkbox(array('name' => 'bymonth', 'class' => 'edit-recurrence-yearly-bymonth'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
925 for ($months = '', $m = 1; $m <= 12; $m++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
926 $months .= html::label(array('class' => 'month'), $checkbox->show(null, array('value' => $m)) . $this->gettext($monthmap[$m]));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
927 $months .= $m % 4 ? ' ' : html::br();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
928 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
929 $html .= html::div($attrib + array('id' => 'edit-recurrence-yearly-bymonthblock'), $months);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
930
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
931 // day rule selection
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
932 $html .= html::div($attrib, html::label(null, $this->gettext('onevery')) . $this->rrule_selectors($attrib['part'], '---'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
933 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
934
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
935 // end of recurrence form
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
936 case 'until':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
937 $radio = new html_radiobutton(array('name' => 'repeat', 'class' => 'edit-recurrence-until'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
938 $select = $this->interval_selector(array('name' => 'times', 'id' => 'edit-recurrence-repeat-times'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
939 $input = new html_inputfield(array('name' => 'untildate', 'id' => 'edit-recurrence-enddate', 'size' => "10"));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
940
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
941 $html = html::div('line first',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
942 html::label(null, $radio->show('', array('value' => '', 'id' => 'edit-recurrence-repeat-forever')) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
943 $this->gettext('forever'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
944 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
945
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
946 $forntimes = $this->gettext(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
947 'name' => 'forntimes',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
948 'vars' => array('nr' => '%s'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
949 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
950 $html .= html::div('line',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
951 $radio->show('', array('value' => 'count', 'id' => 'edit-recurrence-repeat-count', 'aria-label' => sprintf($forntimes, 'N'))) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
952 sprintf($forntimes, $select->show(1))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
953 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
954
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
955 $html .= html::div('line',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
956 $radio->show('', array('value' => 'until', 'id' => 'edit-recurrence-repeat-until', 'aria-label' => $this->gettext('untilenddate'))) . ' ' .
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
957 $this->gettext('untildate') . ' ' . $input->show('', array('aria-label' => $this->gettext('untilenddate')))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
958 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
959
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
960 $html = html::div($attrib, html::label(null, ucfirst($this->gettext('recurrencend'))) . $html);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
961 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
962
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
963 case 'rdate':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
964 $ul = html::tag('ul', array('id' => 'edit-recurrence-rdates'), '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
965 $input = new html_inputfield(array('name' => 'rdate', 'id' => 'edit-recurrence-rdate-input', 'size' => "10"));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
966 $button = new html_inputfield(array('type' => 'button', 'class' => 'button add', 'value' => $this->gettext('addrdate')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
967 $html .= html::div($attrib, $ul . html::div('inputform', $input->show() . $button->show()));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
968 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
969 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
970
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
971 return $html;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
972 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
973
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
974 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
975 * Input field for interval selection
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
976 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
977 private function interval_selector($attrib)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
978 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
979 $select = new html_select($attrib);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
980 $select->add(range(1,30), range(1,30));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
981 return $select;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
982 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
983
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
984 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
985 * Drop-down menus for recurrence rules like "each last sunday of"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
986 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
987 private function rrule_selectors($part, $noselect = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
988 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
989 // rule selectors
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
990 $select_prefix = new html_select(array('name' => 'bydayprefix', 'id' => "edit-recurrence-$part-prefix"));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
991 if ($noselect) $select_prefix->add($noselect, '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
992 $select_prefix->add(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
993 $this->gettext('first'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
994 $this->gettext('second'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
995 $this->gettext('third'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
996 $this->gettext('fourth'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
997 $this->gettext('last')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
998 ),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
999 array(1, 2, 3, 4, -1));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1000
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1001 $select_wday = new html_select(array('name' => 'byday', 'id' => "edit-recurrence-$part-byday"));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1002 if ($noselect) $select_wday->add($noselect, '');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1003
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1004 $daymap = array('sunday','monday','tuesday','wednesday','thursday','friday','saturday');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1005 $first = $this->rc->config->get('calendar_first_day', 1);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1006 for ($j = $first; $j <= $first+6; $j++) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1007 $d = $j % 7;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1008 $select_wday->add($this->gettext($daymap[$d]), strtoupper(substr($daymap[$d], 0, 2)));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1009 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1010
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1011 return $select_prefix->show() . '&nbsp;' . $select_wday->show();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1012 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1013
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1014 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1015 * Convert the recurrence settings to be processed on the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1016 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1017 public function to_client_recurrence($recurrence, $allday = false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1018 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1019 if ($recurrence['UNTIL'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1020 $recurrence['UNTIL'] = $this->adjust_timezone($recurrence['UNTIL'], $allday)->format('c');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1021
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1022 // format RDATE values
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1023 if (is_array($recurrence['RDATE'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1024 $libcal = $this;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1025 $recurrence['RDATE'] = array_map(function($rdate) use ($libcal) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1026 return $libcal->adjust_timezone($rdate, true)->format('c');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1027 }, $recurrence['RDATE']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1028 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1029
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1030 unset($recurrence['EXCEPTIONS']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1031
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1032 return $recurrence;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1033 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1034
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1035 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1036 * Process the alarms values submitted by the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1037 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1038 public function from_client_recurrence($recurrence, $start = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1039 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1040 if (is_array($recurrence) && !empty($recurrence['UNTIL'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1041 $recurrence['UNTIL'] = new DateTime($recurrence['UNTIL'], $this->timezone);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1042 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1043
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1044 if (is_array($recurrence) && is_array($recurrence['RDATE'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1045 $tz = $this->timezone;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1046 $recurrence['RDATE'] = array_map(function($rdate) use ($tz, $start) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1047 try {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1048 $dt = new DateTime($rdate, $tz);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1049 if (is_a($start, 'DateTime'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1050 $dt->setTime($start->format('G'), $start->format('i'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1051 return $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1052 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1053 catch (Exception $e) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1054 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1055 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1056 }, $recurrence['RDATE']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1057 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1058
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1059 return $recurrence;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1060 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1061
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1062
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1063 /********* Attachments handling *********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1064
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1065 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1066 * Handler for attachment uploads
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1067 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1068 public function attachment_upload($session_key, $id_prefix = '')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1069 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1070 // Upload progress update
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1071 if (!empty($_GET['_progress'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1072 $this->rc->upload_progress();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1073 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1074
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1075 $recid = $id_prefix . rcube_utils::get_input_value('_id', rcube_utils::INPUT_GPC);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1076 $uploadid = rcube_utils::get_input_value('_uploadid', rcube_utils::INPUT_GPC);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1077
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1078 if (!is_array($_SESSION[$session_key]) || $_SESSION[$session_key]['id'] != $recid) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1079 $_SESSION[$session_key] = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1080 $_SESSION[$session_key]['id'] = $recid;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1081 $_SESSION[$session_key]['attachments'] = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1082 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1083
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1084 // clear all stored output properties (like scripts and env vars)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1085 $this->rc->output->reset();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1086
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1087 if (is_array($_FILES['_attachments']['tmp_name'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1088 foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1089 // Process uploaded attachment if there is no error
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1090 $err = $_FILES['_attachments']['error'][$i];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1091
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1092 if (!$err) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1093 $attachment = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1094 'path' => $filepath,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1095 'size' => $_FILES['_attachments']['size'][$i],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1096 'name' => $_FILES['_attachments']['name'][$i],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1097 'mimetype' => rcube_mime::file_content_type($filepath, $_FILES['_attachments']['name'][$i], $_FILES['_attachments']['type'][$i]),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1098 'group' => $recid,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1099 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1100
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1101 $attachment = $this->rc->plugins->exec_hook('attachment_upload', $attachment);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1102 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1103
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1104 if (!$err && $attachment['status'] && !$attachment['abort']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1105 $id = $attachment['id'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1106
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1107 // store new attachment in session
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1108 unset($attachment['status'], $attachment['abort']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1109 $_SESSION[$session_key]['attachments'][$id] = $attachment;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1110
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1111 if (($icon = $_SESSION[$session_key . '_deleteicon']) && is_file($icon)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1112 $button = html::img(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1113 'src' => $icon,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1114 'alt' => $this->rc->gettext('delete')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1115 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1116 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1117 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1118 $button = rcube::Q($this->rc->gettext('delete'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1119 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1120
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1121 $content = html::a(array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1122 'href' => "#delete",
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1123 'class' => 'delete',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1124 'onclick' => sprintf("return %s.remove_from_attachment_list('rcmfile%s')", rcmail_output::JS_OBJECT_NAME, $id),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1125 'title' => $this->rc->gettext('delete'),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1126 'aria-label' => $this->rc->gettext('delete') . ' ' . $attachment['name'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1127 ), $button);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1128
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1129 $content .= rcube::Q($attachment['name']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1130
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1131 $this->rc->output->command('add2attachment_list', "rcmfile$id", array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1132 'html' => $content,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1133 'name' => $attachment['name'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1134 'mimetype' => $attachment['mimetype'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1135 'classname' => rcube_utils::file2class($attachment['mimetype'], $attachment['name']),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1136 'complete' => true), $uploadid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1137 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1138 else { // upload failed
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1139 if ($err == UPLOAD_ERR_INI_SIZE || $err == UPLOAD_ERR_FORM_SIZE) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1140 $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1141 'size' => $this->rc->show_bytes(parse_bytes(ini_get('upload_max_filesize'))))));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1142 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1143 else if ($attachment['error']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1144 $msg = $attachment['error'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1145 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1146 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1147 $msg = $this->rc->gettext('fileuploaderror');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1148 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1149
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1150 $this->rc->output->command('display_message', $msg, 'error');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1151 $this->rc->output->command('remove_from_attachment_list', $uploadid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1152 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1153 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1154 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1155 else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1156 // if filesize exceeds post_max_size then $_FILES array is empty,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1157 // show filesizeerror instead of fileuploaderror
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1158 if ($maxsize = ini_get('post_max_size'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1159 $msg = $this->rc->gettext(array('name' => 'filesizeerror', 'vars' => array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1160 'size' => $this->rc->show_bytes(parse_bytes($maxsize)))));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1161 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1162 $msg = $this->rc->gettext('fileuploaderror');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1163
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1164 $this->rc->output->command('display_message', $msg, 'error');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1165 $this->rc->output->command('remove_from_attachment_list', $uploadid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1166 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1167
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1168 $this->rc->output->send('iframe');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1169 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1170
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1171
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1172 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1173 * Deliver an event/task attachment to the client
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1174 * (similar as in Roundcube core program/steps/mail/get.inc)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1175 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1176 public function attachment_get($attachment)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1177 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1178 ob_end_clean();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1179
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1180 if ($attachment && $attachment['body']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1181 // allow post-processing of the attachment body
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1182 $part = new rcube_message_part;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1183 $part->filename = $attachment['name'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1184 $part->size = $attachment['size'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1185 $part->mimetype = $attachment['mimetype'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1186
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1187 $plugin = $this->rc->plugins->exec_hook('message_part_get', array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1188 'body' => $attachment['body'],
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1189 'mimetype' => strtolower($attachment['mimetype']),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1190 'download' => !empty($_GET['_download']),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1191 'part' => $part,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1192 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1193
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1194 if ($plugin['abort'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1195 exit;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1196
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1197 $mimetype = $plugin['mimetype'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1198 list($ctype_primary, $ctype_secondary) = explode('/', $mimetype);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1199
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1200 $browser = $this->rc->output->browser;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1201
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1202 // send download headers
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1203 if ($plugin['download']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1204 header("Content-Type: application/octet-stream");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1205 if ($browser->ie)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1206 header("Content-Type: application/force-download");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1207 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1208 else if ($ctype_primary == 'text') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1209 header("Content-Type: text/$ctype_secondary");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1210 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1211 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1212 header("Content-Type: $mimetype");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1213 header("Content-Transfer-Encoding: binary");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1214 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1215
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1216 // display page, @TODO: support text/plain (and maybe some other text formats)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1217 if ($mimetype == 'text/html' && empty($_GET['_download'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1218 $OUTPUT = new rcmail_html_page();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1219 // @TODO: use washtml on $body
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1220 $OUTPUT->write($plugin['body']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1221 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1222 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1223 // don't kill the connection if download takes more than 30 sec.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1224 @set_time_limit(0);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1225
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1226 $filename = $attachment['name'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1227 $filename = preg_replace('[\r\n]', '', $filename);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1228
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1229 if ($browser->ie && $browser->ver < 7)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1230 $filename = rawurlencode(abbreviate_string($filename, 55));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1231 else if ($browser->ie)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1232 $filename = rawurlencode($filename);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1233 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1234 $filename = addcslashes($filename, '"');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1235
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1236 $disposition = !empty($_GET['_download']) ? 'attachment' : 'inline';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1237 header("Content-Disposition: $disposition; filename=\"$filename\"");
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1238
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1239 echo $plugin['body'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1240 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1241
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1242 exit;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1243 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1244
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1245 // if we arrive here, the requested part was not found
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1246 header('HTTP/1.1 404 Not Found');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1247 exit;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1248 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1249
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1250 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1251 * Show "loading..." page in attachment iframe
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1252 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1253 public function attachment_loading_page()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1254 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1255 $url = str_replace('&_preload=1', '', $_SERVER['REQUEST_URI']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1256 $message = $this->rc->gettext('loadingdata');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1257
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1258 header('Content-Type: text/html; charset=' . RCUBE_CHARSET);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1259 print "<html>\n<head>\n"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1260 . '<meta http-equiv="refresh" content="0; url='.rcube::Q($url).'">' . "\n"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1261 . '<meta http-equiv="content-type" content="text/html; charset='.RCUBE_CHARSET.'">' . "\n"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1262 . "</head>\n<body>\n$message\n</body>\n</html>";
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1263 exit;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1264 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1265
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1266 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1267 * Template object for attachment display frame
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1268 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1269 public function attachment_frame($attrib = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1270 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1271 $mimetype = strtolower($this->attachment['mimetype']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1272 list($ctype_primary, $ctype_secondary) = explode('/', $mimetype);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1273
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1274 $attrib['src'] = './?' . str_replace('_frame=', ($ctype_primary == 'text' ? '_show=' : '_preload='), $_SERVER['QUERY_STRING']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1275
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1276 $this->rc->output->add_gui_object('attachmentframe', $attrib['id']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1277
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1278 return html::iframe($attrib);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1279 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1280
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1281 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1282 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1283 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1284 public function attachment_header($attrib = array())
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1285 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1286 $rcmail = rcmail::get_instance();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1287 $dl_link = strtolower($attrib['downloadlink']) == 'true';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1288 $dl_url = $this->rc->url(array('_frame' => null, '_download' => 1) + $_GET);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1289
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1290 $table = new html_table(array('cols' => $dl_link ? 3 : 2));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1291
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1292 if (!empty($this->attachment['name'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1293 $table->add('title', rcube::Q($this->rc->gettext('filename')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1294 $table->add('header', rcube::Q($this->attachment['name']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1295 if ($dl_link) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1296 $table->add('download-link', html::a($dl_url, rcube::Q($this->rc->gettext('download'))));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1297 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1298 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1299
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1300 if (!empty($this->attachment['mimetype'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1301 $table->add('title', rcube::Q($this->rc->gettext('type')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1302 $table->add('header', rcube::Q($this->attachment['mimetype']));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1303 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1304
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1305 if (!empty($this->attachment['size'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1306 $table->add('title', rcube::Q($this->rc->gettext('filesize')));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1307 $table->add('header', rcube::Q($this->rc->show_bytes($this->attachment['size'])));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1308 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1309
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1310 $this->rc->output->set_env('attachment_download_url', $dl_url);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1311
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1312 return $table->show($attrib);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1313 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1314
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1315
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1316 /********* iTip message detection *********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1317
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1318 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1319 * Check mail message structure of there are .ics files attached
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1320 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1321 public function mail_message_load($p)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1322 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1323 $this->ical_message = $p['object'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1324 $itip_part = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1325
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1326 // check all message parts for .ics files
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1327 foreach ((array)$this->ical_message->mime_parts as $part) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1328 if (self::part_is_vcalendar($part, $this->ical_message)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1329 if ($part->ctype_parameters['method'])
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1330 $itip_part = $part->mime_id;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1331 else
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1332 $this->ical_parts[] = $part->mime_id;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1333 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1334 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1335
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1336 // priorize part with method parameter
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1337 if ($itip_part) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1338 $this->ical_parts = array($itip_part);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1339 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1340 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1341
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1342 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1343 * Getter for the parsed iCal objects attached to the current email message
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1344 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1345 * @return object libvcalendar parser instance with the parsed objects
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1346 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1347 public function get_mail_ical_objects()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1348 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1349 // create parser and load ical objects
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1350 if (!$this->mail_ical_parser) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1351 $this->mail_ical_parser = $this->get_ical();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1352
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1353 foreach ($this->ical_parts as $mime_id) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1354 $part = $this->ical_message->mime_parts[$mime_id];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1355 $charset = $part->ctype_parameters['charset'] ?: RCUBE_CHARSET;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1356 $this->mail_ical_parser->import($this->ical_message->get_part_body($mime_id, true), $charset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1357
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1358 // check if the parsed object is an instance of a recurring event/task
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1359 array_walk($this->mail_ical_parser->objects, 'libcalendaring::identify_recurrence_instance');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1360
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1361 // stop on the part that has an iTip method specified
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1362 if (count($this->mail_ical_parser->objects) && $this->mail_ical_parser->method) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1363 $this->mail_ical_parser->message_date = $this->ical_message->headers->date;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1364 $this->mail_ical_parser->mime_id = $mime_id;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1365
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1366 // store the message's sender address for comparisons
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1367 $from = rcube_mime::decode_address_list($this->ical_message->headers->from, 1, true, null, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1368 $this->mail_ical_parser->sender = !empty($from) ? $from[1] : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1369
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1370 if (!empty($this->mail_ical_parser->sender)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1371 foreach ($this->mail_ical_parser->objects as $i => $object) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1372 $this->mail_ical_parser->objects[$i]['_sender'] = $this->mail_ical_parser->sender;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1373 $this->mail_ical_parser->objects[$i]['_sender_utf'] = rcube_utils::idn_to_utf8($this->mail_ical_parser->sender);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1374 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1375 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1376
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1377 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1378 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1379 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1380 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1381
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1382 return $this->mail_ical_parser;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1383 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1384
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1385 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1386 * Read the given mime message from IMAP and parse ical data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1387 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1388 * @param string Mailbox name
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1389 * @param string Message UID
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1390 * @param string Message part ID and object index (e.g. '1.2:0')
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1391 * @param string Object type filter (optional)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1392 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1393 * @return array Hash array with the parsed iCal
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1394 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1395 public function mail_get_itip_object($mbox, $uid, $mime_id, $type = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1396 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1397 $charset = RCUBE_CHARSET;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1398
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1399 // establish imap connection
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1400 $imap = $this->rc->get_storage();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1401 $imap->set_folder($mbox);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1402
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1403 if ($uid && $mime_id) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1404 list($mime_id, $index) = explode(':', $mime_id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1405
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1406 $part = $imap->get_message_part($uid, $mime_id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1407 $headers = $imap->get_message_headers($uid);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1408 $parser = $this->get_ical();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1409
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1410 if ($part->ctype_parameters['charset']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1411 $charset = $part->ctype_parameters['charset'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1412 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1413
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1414 if ($part) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1415 $objects = $parser->import($part, $charset);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1416 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1417 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1418
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1419 // successfully parsed events/tasks?
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1420 if (!empty($objects) && ($object = $objects[$index]) && (!$type || $object['_type'] == $type)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1421 if ($parser->method)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1422 $object['_method'] = $parser->method;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1423
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1424 // store the message's sender address for comparisons
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1425 $from = rcube_mime::decode_address_list($headers->from, 1, true, null, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1426 $object['_sender'] = !empty($from) ? $from[1] : '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1427 $object['_sender_utf'] = rcube_utils::idn_to_utf8($object['_sender']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1428
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1429 // check if this is an instance of a recurring event/task
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1430 self::identify_recurrence_instance($object);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1431
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1432 return $object;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1433 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1434
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1435 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1436 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1437
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1438 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1439 * Checks if specified message part is a vcalendar data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1440 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1441 * @param rcube_message_part Part object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1442 * @param rcube_message Message object
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1443 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1444 * @return boolean True if part is of type vcard
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1445 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1446 public static function part_is_vcalendar($part, $message = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1447 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1448 // First check if the message is "valid" (i.e. not multipart/report)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1449 if ($message) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1450 $level = explode('.', $part->mime_id);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1451
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1452 while (array_pop($level) !== null) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1453 $parent = $message->mime_parts[join('.', $level) ?: 0];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1454 if ($parent->mimetype == 'multipart/report') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1455 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1456 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1457 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1458 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1459
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1460 return (
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1461 in_array($part->mimetype, array('text/calendar', 'text/x-vcalendar', 'application/ics')) ||
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1462 // Apple sends files as application/x-any (!?)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1463 ($part->mimetype == 'application/x-any' && $part->filename && preg_match('/\.ics$/i', $part->filename))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1464 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1465 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1466
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1467 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1468 * Single occourrences of recurring events are identified by their RECURRENCE-ID property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1469 * in iCal which is represented as 'recurrence_date' in our internal data structure.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1470 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1471 * Check if such a property exists and derive the '_instance' identifier and '_savemode'
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1472 * attributes which are used in the storage backend to identify the nested exception item.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1473 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1474 public static function identify_recurrence_instance(&$object)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1475 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1476 // for savemode=all, remove recurrence instance identifiers
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1477 if (!empty($object['_savemode']) && $object['_savemode'] == 'all' && $object['recurrence']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1478 unset($object['_instance'], $object['recurrence_date']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1479 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1480 // set instance and 'savemode' according to recurrence-id
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1481 else if (!empty($object['recurrence_date']) && is_a($object['recurrence_date'], 'DateTime')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1482 $object['_instance'] = self::recurrence_instance_identifier($object);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1483 $object['_savemode'] = $object['thisandfuture'] ? 'future' : 'current';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1484 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1485 else if (!empty($object['recurrence_id']) && !empty($object['_instance'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1486 if (strlen($object['_instance']) > 4) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1487 $object['recurrence_date'] = rcube_utils::anytodatetime($object['_instance'], $object['start']->getTimezone());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1488 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1489 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1490 $object['recurrence_date'] = clone $object['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1491 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1492 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1493 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1494
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1495 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1496 * Return a date() format string to render identifiers for recurrence instances
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1497 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1498 * @param array Hash array with event properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1499 * @return string Format string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1500 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1501 public static function recurrence_id_format($event)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1502 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1503 return $event['allday'] ? 'Ymd' : 'Ymd\THis';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1504 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1505
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1506 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1507 * Return the identifer for the given instance of a recurring event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1508 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1509 * @param array Hash array with event properties
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1510 * @param bool All-day flag from the main event
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1511 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1512 * @return mixed Format string or null if identifier cannot be generated
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1513 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1514 public static function recurrence_instance_identifier($event, $allday = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1515 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1516 $instance_date = $event['recurrence_date'] ?: $event['start'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1517
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1518 if ($instance_date && is_a($instance_date, 'DateTime')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1519 // According to RFC5545 (3.8.4.4) RECURRENCE-ID format should
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1520 // be date/date-time depending on the main event type, not the exception
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1521 if ($allday === null) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1522 $allday = $event['allday'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1523 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1524
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1525 return $instance_date->format($allday ? 'Ymd' : 'Ymd\THis');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1526 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1527 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1528
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1529
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1530 /********* Attendee handling functions *********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1531
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1532 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1533 * Handler for attendee group expansion requests
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1534 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1535 public function expand_attendee_group()
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1536 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1537 $id = rcube_utils::get_input_value('id', rcube_utils::INPUT_POST);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1538 $data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1539 $result = array('id' => $id, 'members' => array());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1540 $maxnum = 500;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1541
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1542 // iterate over all autocomplete address books (we don't know the source of the group)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1543 foreach ((array)$this->rc->config->get('autocomplete_addressbooks', 'sql') as $abook_id) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1544 if (($abook = $this->rc->get_address_book($abook_id)) && $abook->groups) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1545 foreach ($abook->list_groups($data['name'], 1) as $group) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1546 // this is the matching group to expand
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1547 if (in_array($data['email'], (array)$group['email'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1548 $abook->set_pagesize($maxnum);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1549 $abook->set_group($group['ID']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1550
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1551 // get all members
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1552 $res = $abook->list_records($this->rc->config->get('contactlist_fields'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1553
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1554 // handle errors (e.g. sizelimit, timelimit)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1555 if ($abook->get_error()) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1556 $result['error'] = $this->rc->gettext('expandattendeegrouperror', 'libcalendaring');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1557 $res = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1558 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1559 // check for maximum number of members (we don't wanna bloat the UI too much)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1560 else if ($res->count > $maxnum) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1561 $result['error'] = $this->rc->gettext('expandattendeegroupsizelimit', 'libcalendaring');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1562 $res = false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1563 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1564
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1565 while ($res && ($member = $res->iterate())) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1566 $emails = (array)$abook->get_col_values('email', $member, true);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1567 if (!empty($emails) && ($email = array_shift($emails))) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1568 $result['members'][] = array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1569 'email' => $email,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1570 'name' => rcube_addressbook::compose_list_name($member),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1571 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1572 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1573 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1574
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1575 break 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1576 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1577 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1578 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1579 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1580
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1581 $this->rc->output->command('plugin.expand_attendee_callback', $result);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1582 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1583
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1584 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1585 * Merge attendees of the old and new event version
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1586 * with keeping current user and his delegatees status
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1587 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1588 * @param array &$new New object data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1589 * @param array $old Old object data
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1590 * @param bool $status New status of the current user
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1591 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1592 public function merge_attendees(&$new, $old, $status = null)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1593 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1594 if (empty($status)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1595 $emails = $this->get_user_emails();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1596 $delegates = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1597 $attendees = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1598
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1599 // keep attendee status of the current user
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1600 foreach ((array) $new['attendees'] as $i => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1601 if (empty($attendee['email'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1602 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1603 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1604
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1605 $attendees[] = $email = strtolower($attendee['email']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1606
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1607 if (in_array($email, $emails)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1608 foreach ($old['attendees'] as $_attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1609 if ($attendee['email'] == $_attendee['email']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1610 $new['attendees'][$i] = $_attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1611 if ($_attendee['status'] == 'DELEGATED' && ($email = $_attendee['delegated-to'])) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1612 $delegates[] = strtolower($email);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1613 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1614
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1615 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1616 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1617 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1618 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1619 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1620
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1621 // make sure delegated attendee is not lost
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1622 foreach ($delegates as $delegatee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1623 if (!in_array($delegatee, $attendees)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1624 foreach ((array) $old['attendees'] as $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1625 if ($attendee['email'] && ($email = strtolower($attendee['email'])) && $email == $delegatee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1626 $new['attendees'][] = $attendee;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1627 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1628 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1629 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1630 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1631 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1632 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1633
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1634 // We also make sure that status of any attendee
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1635 // is not overriden by NEEDS-ACTION if it was already set
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1636 // which could happen if you work with shared events
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1637 foreach ((array) $new['attendees'] as $i => $attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1638 if ($attendee['email'] && $attendee['status'] == 'NEEDS-ACTION') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1639 foreach ($old['attendees'] as $_attendee) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1640 if ($attendee['email'] == $_attendee['email']) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1641 $new['attendees'][$i]['status'] = $_attendee['status'];
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1642 unset($new['attendees'][$i]['rsvp']);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1643 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1644 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1645 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1646 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1647 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1648 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1649
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1650
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1651 /********* Static utility functions *********/
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1652
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1653 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1654 * Convert the internal structured data into a vcalendar rrule 2.0 string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1655 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1656 public static function to_rrule($recurrence, $allday = false)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1657 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1658 if (is_string($recurrence))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1659 return $recurrence;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1660
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1661 $rrule = '';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1662 foreach ((array)$recurrence as $k => $val) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1663 $k = strtoupper($k);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1664 switch ($k) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1665 case 'UNTIL':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1666 // convert to UTC according to RFC 5545
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1667 if (is_a($val, 'DateTime')) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1668 if (!$allday && !$val->_dateonly) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1669 $until = clone $val;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1670 $until->setTimezone(new DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1671 $val = $until->format('Ymd\THis\Z');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1672 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1673 else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1674 $val = $val->format('Ymd');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1675 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1676 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1677 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1678 case 'RDATE':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1679 case 'EXDATE':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1680 foreach ((array)$val as $i => $ex) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1681 if (is_a($ex, 'DateTime'))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1682 $val[$i] = $ex->format('Ymd\THis');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1683 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1684 $val = join(',', (array)$val);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1685 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1686 case 'EXCEPTIONS':
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1687 continue 2;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1688 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1689
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1690 if (strlen($val))
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1691 $rrule .= $k . '=' . $val . ';';
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1692 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1693
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1694 return rtrim($rrule, ';');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1695 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1696
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1697 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1698 * Convert from fullcalendar date format to PHP date() format string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1699 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1700 public static function to_php_date_format($from)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1701 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1702 // "dd.MM.yyyy HH:mm:ss" => "d.m.Y H:i:s"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1703 return strtr(strtr($from, array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1704 'YYYY' => 'Y',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1705 'YY' => 'y',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1706 'yyyy' => 'Y',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1707 'yy' => 'y',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1708 'MMMM' => 'F',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1709 'MMM' => 'M',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1710 'MM' => 'm',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1711 'M' => 'n',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1712 'dddd' => 'l',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1713 'ddd' => 'D',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1714 'dd' => 'd',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1715 'd' => 'j',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1716 'HH' => '**',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1717 'hh' => '%%',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1718 'H' => 'G',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1719 'h' => 'g',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1720 'mm' => 'i',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1721 'ss' => 's',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1722 'TT' => 'A',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1723 'tt' => 'a',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1724 'T' => 'A',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1725 't' => 'a',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1726 'u' => 'c',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1727 )), array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1728 '**' => 'H',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1729 '%%' => 'h',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1730 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1731 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1732
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1733 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1734 * Convert from PHP date() format to fullcalendar format string
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1735 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1736 public static function from_php_date_format($from)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1737 {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1738 // "d.m.Y H:i:s" => "dd.MM.yyyy HH:mm:ss"
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1739 return strtr($from, array(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1740 'y' => 'yy',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1741 'Y' => 'yyyy',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1742 'M' => 'MMM',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1743 'F' => 'MMMM',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1744 'm' => 'MM',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1745 'n' => 'M',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1746 'j' => 'd',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1747 'd' => 'dd',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1748 'D' => 'ddd',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1749 'l' => 'dddd',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1750 'H' => 'HH',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1751 'h' => 'hh',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1752 'G' => 'H',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1753 'g' => 'h',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1754 'i' => 'mm',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1755 's' => 'ss',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1756 'A' => 'TT',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1757 'a' => 'tt',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1758 'c' => 'u',
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1759 ));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1760 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1761
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1762 }