forked from kolab-roundcube-plugins-mirror/calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar.php
3970 lines (3363 loc) · 161 KB
/
calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Calendar plugin for Roundcube webmail
*
* @author Lazlo Westerhof <[email protected]>
* @author Thomas Bruederli <[email protected]>
*
* Copyright (C) 2010, Lazlo Westerhof <[email protected]>
* Copyright (C) 2014-2015, Kolab Systems AG <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class calendar extends rcube_plugin
{
const FREEBUSY_UNKNOWN = 0;
const FREEBUSY_FREE = 1;
const FREEBUSY_BUSY = 2;
const FREEBUSY_TENTATIVE = 3;
const FREEBUSY_OOF = 4;
const SESSION_KEY = 'calendar_temp';
public $task = '?(?!logout).*';
public $rc;
public $lib;
public $resources_dir;
public $home; // declare public to be used in other classes
public $urlbase;
public $timezone;
public $timezone_offset;
public $gmt_offset;
public $ui;
public $defaults = [
'calendar_default_view' => "agendaWeek",
'calendar_timeslots' => 2,
'calendar_work_start' => 6,
'calendar_work_end' => 18,
'calendar_agenda_range' => 60,
'calendar_show_weekno' => 0,
'calendar_first_day' => 1,
'calendar_first_hour' => 6,
'calendar_time_format' => null,
'calendar_event_coloring' => 0,
'calendar_time_indicator' => true,
'calendar_allow_invite_shared' => false,
'calendar_itip_send_option' => 3,
'calendar_itip_after_action' => 0,
];
// These are implemented with __get()
// private $ical;
// private $itip;
// private $driver;
/**
* Plugin initialization.
*/
function init()
{
$this->rc = rcube::get_instance();
$this->register_task('calendar', 'calendar');
// load calendar configuration
$this->load_config();
// catch iTIP confirmation requests that don're require a valid session
if ($this->rc->action == 'attend' && !empty($_REQUEST['_t'])) {
$this->add_hook('startup', [$this, 'itip_attend_response']);
}
else if ($this->rc->action == 'feed' && !empty($_REQUEST['_cal'])) {
$this->add_hook('startup', [$this, 'ical_feed_export']);
}
else if ($this->rc->task != 'login') {
// default startup routine
$this->add_hook('startup', [$this, 'startup']);
}
$this->add_hook('user_delete', [$this, 'user_delete']);
}
/**
* Setup basic plugin environment and UI
*/
protected function setup()
{
$this->require_plugin('libcalendaring');
$this->require_plugin('libkolab');
$this->lib = libcalendaring::get_instance();
$this->timezone = $this->lib->timezone;
$this->gmt_offset = $this->lib->gmt_offset;
$this->dst_active = $this->lib->dst_active;
$this->timezone_offset = $this->gmt_offset / 3600 - $this->dst_active;
// load localizations
$this->add_texts('localization/', $this->rc->task == 'calendar' && (!$this->rc->action || $this->rc->action == 'print'));
require($this->home . '/lib/calendar_ui.php');
$this->ui = new calendar_ui($this);
}
/**
* Startup hook
*/
public function startup($args)
{
// the calendar module can be enabled/disabled by the kolab_auth plugin
if ($this->rc->config->get('calendar_disabled', false)
|| !$this->rc->config->get('calendar_enabled', true)
) {
return;
}
$this->setup();
// load Calendar user interface
if (!$this->rc->output->ajax_call
&& (empty($this->rc->output->env['framed']) || $args['action'] == 'preview')
) {
$this->ui->init();
// settings are required in (almost) every GUI step
if ($args['action'] != 'attend') {
$this->rc->output->set_env('calendar_settings', $this->load_settings());
}
}
if ($args['task'] == 'calendar' && $args['action'] != 'save-pref') {
if ($args['action'] != 'upload') {
$this->load_driver();
}
// register calendar actions
$this->register_action('index', [$this, 'calendar_view']);
$this->register_action('event', [$this, 'event_action']);
$this->register_action('calendar', [$this, 'calendar_action']);
$this->register_action('count', [$this, 'count_events']);
$this->register_action('load_events', [$this, 'load_events']);
$this->register_action('export_events', [$this, 'export_events']);
$this->register_action('import_events', [$this, 'import_events']);
$this->register_action('upload', [$this, 'attachment_upload']);
$this->register_action('get-attachment', [$this, 'attachment_get']);
$this->register_action('freebusy-status', [$this, 'freebusy_status']);
$this->register_action('freebusy-times', [$this, 'freebusy_times']);
$this->register_action('randomdata', [$this, 'generate_randomdata']);
$this->register_action('print', [$this,'print_view']);
$this->register_action('mailimportitip', [$this, 'mail_import_itip']);
$this->register_action('mailimportattach', [$this, 'mail_import_attachment']);
$this->register_action('dialog-ui', [$this, 'mail_message2event']);
$this->register_action('check-recent', [$this, 'check_recent']);
$this->register_action('itip-status', [$this, 'event_itip_status']);
$this->register_action('itip-remove', [$this, 'event_itip_remove']);
$this->register_action('itip-decline-reply', [$this, 'mail_itip_decline_reply']);
$this->register_action('itip-delegate', [$this, 'mail_itip_delegate']);
$this->register_action('resources-list', [$this, 'resources_list']);
$this->register_action('resources-owner', [$this, 'resources_owner']);
$this->register_action('resources-calendar', [$this, 'resources_calendar']);
$this->register_action('resources-autocomplete', [$this, 'resources_autocomplete']);
$this->add_hook('refresh', [$this, 'refresh']);
// remove undo information...
if (!empty($_SESSION['calendar_event_undo'])) {
$undo = $_SESSION['calendar_event_undo'];
// ...after timeout
$undo_time = $this->rc->config->get('undo_timeout', 0);
if ($undo['ts'] < time() - $undo_time) {
$this->rc->session->remove('calendar_event_undo');
// @TODO: do EXPUNGE on kolab objects?
}
}
}
else if ($args['task'] == 'settings') {
// add hooks for Calendar settings
$this->add_hook('preferences_sections_list', [$this, 'preferences_sections_list']);
$this->add_hook('preferences_list', [$this, 'preferences_list']);
$this->add_hook('preferences_save', [$this, 'preferences_save']);
}
else if ($args['task'] == 'mail') {
// hooks to catch event invitations on incoming mails
if ($args['action'] == 'show' || $args['action'] == 'preview') {
$this->add_hook('template_object_messagebody', [$this, 'mail_messagebody_html']);
}
// add 'Create event' item to message menu
if ($this->api->output->type == 'html' && (empty($_GET['_rel']) || $_GET['_rel'] != 'event')) {
$this->api->output->add_label('calendar.createfrommail');
$this->api->add_content(
html::tag('li', ['role' => 'menuitem'],
$this->api->output->button([
'command' => 'calendar-create-from-mail',
'label' => 'calendar.createfrommail',
'type' => 'link',
'classact' => 'icon calendarlink active',
'class' => 'icon calendarlink disabled',
'innerclass' => 'icon calendar',
])
),
'messagemenu'
);
}
$this->add_hook('messages_list', [$this, 'mail_messages_list']);
$this->add_hook('message_compose', [$this, 'mail_message_compose']);
}
else if ($args['task'] == 'addressbook') {
if ($this->rc->config->get('calendar_contact_birthdays')) {
$this->add_hook('contact_update', [$this, 'contact_update']);
$this->add_hook('contact_create', [$this, 'contact_update']);
}
}
// add hooks to display alarms
$this->add_hook('pending_alarms', [$this, 'pending_alarms']);
$this->add_hook('dismiss_alarms', [$this, 'dismiss_alarms']);
}
/**
* Helper method to load the backend driver according to local config
*/
private function load_driver()
{
if (!empty($this->driver)) {
return;
}
$driver_name = $this->rc->config->get('calendar_driver', 'database');
$driver_class = $driver_name . '_driver';
require_once($this->home . '/drivers/calendar_driver.php');
require_once($this->home . '/drivers/' . $driver_name . '/' . $driver_class . '.php');
$this->driver = new $driver_class($this);
if ($this->driver->undelete) {
$this->driver->undelete = $this->rc->config->get('undo_timeout', 0) > 0;
}
}
/**
* Load iTIP functions
*/
private function load_itip()
{
if (empty($this->itip)) {
require_once($this->home . '/lib/calendar_itip.php');
$this->itip = new calendar_itip($this);
if ($this->rc->config->get('kolab_invitation_calendars')) {
$this->itip->set_rsvp_actions(['accepted','tentative','declined','delegated','needs-action']);
}
}
return $this->itip;
}
/**
* Load iCalendar functions
*/
public function get_ical()
{
if (empty($this->ical)) {
$this->ical = libcalendaring::get_ical();
}
return $this->ical;
}
/**
* Get properties of the calendar this user has specified as default
*/
public function get_default_calendar($sensitivity = null, $calendars = null)
{
if ($calendars === null) {
$filter = calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_WRITEABLE;
$calendars = $this->driver->list_calendars($filter);
}
$default_id = $this->rc->config->get('calendar_default_calendar');
$calendar = !empty($calendars[$default_id]) ? $calendars[$default_id] : null;
$first = null;
if (!$calendar || $sensitivity) {
foreach ($calendars as $cal) {
if ($sensitivity && !empty($cal['subtype']) && $cal['subtype'] == $sensitivity) {
$calendar = $cal;
break;
}
if (!empty($cal['default']) && $cal['editable']) {
$calendar = $cal;
}
if ($cal['editable']) {
$first = $cal;
}
}
}
return $calendar ?: $first;
}
/**
* Render the main calendar view from skin template
*/
function calendar_view()
{
$this->rc->output->set_pagetitle($this->gettext('calendar'));
// Add JS files to the page header
$this->ui->addJS();
$this->ui->init_templates();
$this->rc->output->add_label('lowest','low','normal','high','highest','delete',
'cancel','uploading','noemailwarning','close'
);
// initialize attendees autocompletion
$this->rc->autocomplete_init();
$this->rc->output->set_env('timezone', $this->timezone->getName());
$this->rc->output->set_env('calendar_driver', $this->rc->config->get('calendar_driver'), false);
$this->rc->output->set_env('calendar_resources', (bool)$this->rc->config->get('calendar_resources_driver'));
$this->rc->output->set_env('identities-selector', $this->ui->identity_select([
'id' => 'edit-identities-list',
'aria-label' => $this->gettext('roleorganizer'),
'class' => 'form-control custom-select',
]));
$view = rcube_utils::get_input_value('view', rcube_utils::INPUT_GPC);
if (in_array($view, ['agendaWeek', 'agendaDay', 'month', 'list'])) {
$this->rc->output->set_env('view', $view);
}
if ($date = rcube_utils::get_input_value('date', rcube_utils::INPUT_GPC)) {
$this->rc->output->set_env('date', $date);
}
if ($msgref = rcube_utils::get_input_value('itip', rcube_utils::INPUT_GPC)) {
$this->rc->output->set_env('itip_events', $this->itip_events($msgref));
}
$this->rc->output->send('calendar.calendar');
}
/**
* Handler for preferences_sections_list hook.
* Adds Calendar settings sections into preferences sections list.
*
* @param array Original parameters
*
* @return array Modified parameters
*/
function preferences_sections_list($p)
{
$p['list']['calendar'] = [
'id' => 'calendar',
'section' => $this->gettext('calendar'),
];
return $p;
}
/**
* Handler for preferences_list hook.
* Adds options blocks into Calendar settings sections in Preferences.
*
* @param array Original parameters
*
* @return array Modified parameters
*/
function preferences_list($p)
{
if ($p['section'] != 'calendar') {
return $p;
}
$no_override = array_flip((array) $this->rc->config->get('dont_override'));
$p['blocks']['view']['name'] = $this->gettext('mainoptions');
if (!isset($no_override['calendar_default_view'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_default_view';
$view = $this->rc->config->get('calendar_default_view', $this->defaults['calendar_default_view']);
$select = new html_select(['name' => '_default_view', 'id' => $field_id]);
$select->add($this->gettext('day'), "agendaDay");
$select->add($this->gettext('week'), "agendaWeek");
$select->add($this->gettext('month'), "month");
$select->add($this->gettext('agenda'), "list");
$p['blocks']['view']['options']['default_view'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('default_view'))),
'content' => $select->show($view == 'table' ? 'list' : $view),
];
}
if (!isset($no_override['calendar_timeslots'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_timeslot';
$choices = ['1', '2', '3', '4', '6'];
$timeslots = $this->rc->config->get('calendar_timeslots', $this->defaults['calendar_timeslots']);
$select = new html_select(['name' => '_timeslots', 'id' => $field_id]);
$select->add($choices);
$p['blocks']['view']['options']['timeslots'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('timeslots'))),
'content' => $select->show(strval($timeslots)),
];
}
if (!isset($no_override['calendar_first_day'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_firstday';
$first_day = $this->rc->config->get('calendar_first_day', $this->defaults['calendar_first_day']);
$select = new html_select(['name' => '_first_day', 'id' => $field_id]);
$select->add($this->gettext('sunday'), '0');
$select->add($this->gettext('monday'), '1');
$select->add($this->gettext('tuesday'), '2');
$select->add($this->gettext('wednesday'), '3');
$select->add($this->gettext('thursday'), '4');
$select->add($this->gettext('friday'), '5');
$select->add($this->gettext('saturday'), '6');
$p['blocks']['view']['options']['first_day'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('first_day'))),
'content' => $select->show(strval($first_day)),
];
}
if (!isset($no_override['calendar_first_hour'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$first_hour = $this->rc->config->get('calendar_first_hour', $this->defaults['calendar_first_hour']);
$time_format = $this->rc->config->get('calendar_time_format', $this->defaults['calendar_time_format']);
$time_format = $this->rc->config->get('time_format', libcalendaring::to_php_date_format($time_format));
$field_id = 'rcmfd_firsthour';
$select_hours = new html_select(['name' => '_first_hour', 'id' => $field_id]);
for ($h = 0; $h < 24; $h++) {
$select_hours->add(date($time_format, mktime($h, 0, 0)), $h);
}
$p['blocks']['view']['options']['first_hour'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('first_hour'))),
'content' => $select_hours->show($first_hour),
];
}
if (!isset($no_override['calendar_work_start'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_workstart';
$work_start = $this->rc->config->get('calendar_work_start', $this->defaults['calendar_work_start']);
$work_end = $this->rc->config->get('calendar_work_end', $this->defaults['calendar_work_end']);
$p['blocks']['view']['options']['workinghours'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('workinghours'))),
'content' => html::div('input-group',
$select_hours->show($work_start, ['name' => '_work_start', 'id' => $field_id])
. html::span('input-group-append input-group-prepend', html::span('input-group-text',' — '))
. $select_hours->show($work_end, ['name' => '_work_end', 'id' => $field_id])
)
];
}
if (!isset($no_override['calendar_event_coloring'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_coloring';
$mode = $this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
$select_colors = new html_select(['name' => '_event_coloring', 'id' => $field_id]);
$select_colors->add($this->gettext('coloringmode0'), 0);
$select_colors->add($this->gettext('coloringmode1'), 1);
$select_colors->add($this->gettext('coloringmode2'), 2);
$select_colors->add($this->gettext('coloringmode3'), 3);
$p['blocks']['view']['options']['eventcolors'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('eventcoloring'))),
'content' => $select_colors->show($mode),
];
}
// loading driver is expensive, don't do it if not needed
$this->load_driver();
if (!isset($no_override['calendar_default_alarm_type']) || !isset($no_override['calendar_default_alarm_offset'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$alarm_type = $alarm_offset = '';
if (!isset($no_override['calendar_default_alarm_type'])) {
$field_id = 'rcmfd_alarm';
$select_type = new html_select(['name' => '_alarm_type', 'id' => $field_id]);
$select_type->add($this->gettext('none'), '');
foreach ($this->driver->alarm_types as $type) {
$select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
}
$alarm_type = $select_type->show($this->rc->config->get('calendar_default_alarm_type', ''));
}
if (!isset($no_override['calendar_default_alarm_offset'])) {
$field_id = 'rcmfd_alarm';
$input_value = new html_inputfield(['name' => '_alarm_value', 'id' => $field_id . 'value', 'size' => 3]);
$select_offset = new html_select(['name' => '_alarm_offset', 'id' => $field_id . 'offset']);
foreach (['-M','-H','-D','+M','+H','+D'] as $trigger) {
$select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
}
$preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_default_alarm_offset', '-15M'));
$alarm_offset = $input_value->show($preset[0]) . ' ' . $select_offset->show($preset[1]);
}
$p['blocks']['view']['options']['alarmtype'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('defaultalarmtype'))),
'content' => html::div('input-group', $alarm_type . ' ' . $alarm_offset),
];
}
if (!isset($no_override['calendar_default_calendar'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
// default calendar selection
$field_id = 'rcmfd_default_calendar';
$filter = calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_ACTIVE | calendar_driver::FILTER_INSERTABLE;
$select_cal = new html_select(['name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true]);
$default_calendar = null;
foreach ((array) $this->driver->list_calendars($filter) as $id => $prop) {
$select_cal->add($prop['name'], strval($id));
if (!empty($prop['default'])) {
$default_calendar = $id;
}
}
$p['blocks']['view']['options']['defaultcalendar'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('defaultcalendar'))),
'content' => $select_cal->show($this->rc->config->get('calendar_default_calendar', $default_calendar)),
];
}
if (!isset($no_override['calendar_show_weekno'])) {
if (empty($p['current'])) {
$p['blocks']['view']['content'] = true;
return $p;
}
$field_id = 'rcmfd_show_weekno';
$select = new html_select(['name' => '_show_weekno', 'id' => $field_id]);
$select->add($this->gettext('weeknonone'), -1);
$select->add($this->gettext('weeknodatepicker'), 0);
$select->add($this->gettext('weeknoall'), 1);
$p['blocks']['view']['options']['show_weekno'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('showweekno'))),
'content' => $select->show(intval($this->rc->config->get('calendar_show_weekno'))),
];
}
$p['blocks']['itip']['name'] = $this->gettext('itipoptions');
// Invitations handling
if (!isset($no_override['calendar_itip_after_action'])) {
if (empty($p['current'])) {
$p['blocks']['itip']['content'] = true;
return $p;
}
$field_id = 'rcmfd_after_action';
$select = new html_select([
'name' => '_after_action',
'id' => $field_id,
'onchange' => "\$('#{$field_id}_select')[this.value == 4 ? 'show' : 'hide']()"
]);
$select->add($this->gettext('afternothing'), '');
$select->add($this->gettext('aftertrash'), 1);
$select->add($this->gettext('afterdelete'), 2);
$select->add($this->gettext('afterflagdeleted'), 3);
$select->add($this->gettext('aftermoveto'), 4);
$val = $this->rc->config->get('calendar_itip_after_action', $this->defaults['calendar_itip_after_action']);
$folder = null;
if ($val !== null && $val !== '' && !is_int($val)) {
$folder = $val;
$val = 4;
}
$folders = $this->rc->folder_selector([
'id' => $field_id . '_select',
'name' => '_after_action_folder',
'maxlength' => 30,
'folder_filter' => 'mail',
'folder_rights' => 'w',
'style' => $val !== 4 ? 'display:none' : '',
]);
$p['blocks']['itip']['options']['after_action'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('afteraction'))),
'content' => html::div(
'input-group input-group-combo',
$select->show($val) . $folders->show($folder)
),
];
}
// category definitions
if (empty($this->driver->nocategories) && !isset($no_override['calendar_categories'])) {
$p['blocks']['categories']['name'] = $this->gettext('categories');
if (empty($p['current'])) {
$p['blocks']['categories']['content'] = true;
return $p;
}
$categories = (array) $this->driver->list_categories();
$categories_list = '';
foreach ($categories as $name => $color) {
$key = md5($name);
$field_class = 'rcmfd_category_' . str_replace(' ', '_', $name);
$category_remove = html::span('input-group-append',
html::a([
'class' => 'button icon delete input-group-text',
'onclick' => '$(this).parent().parent().remove()',
'title' => $this->gettext('remove_category'),
'href' => '#rcmfd_new_category',
],
html::span('inner', $this->gettext('delete'))
)
);
$category_name = new html_inputfield(array('name' => "_categories[$key]", 'class' => $field_class, 'size' => 30, 'disabled' => $this->driver->categoriesimmutable));
$category_color = new html_inputfield(array('name' => "_colors[$key]", 'class' => "$field_class colors", 'size' => 6));
$hidden = '';
if (!empty($this->driver->categoriesimmutable)) {
$hidden = html::tag('input', ['type' => 'hidden', 'name' => "_categories[$key]", 'value' => $name]);
}
$categories_list .= $hidden
. html::div('input-group', $category_name->show($name) . $category_color->show($color) . $category_remove);
}
$p['blocks']['categories']['options']['category_' . $name] = [
'content' => html::div(['id' => 'calendarcategories'], $categories_list),
];
$field_id = 'rcmfd_new_category';
$new_category = new html_inputfield(['name' => '_new_category', 'id' => $field_id, 'size' => 30]);
$add_category = html::span('input-group-append',
html::a(
[
'type' => 'button',
'class' => 'button create input-group-text',
'title' => $this->gettext('add_category'),
'onclick' => 'rcube_calendar_add_category()',
'href' => '#rcmfd_new_category',
],
html::span('inner', $this->gettext('add_category'))
)
);
$p['blocks']['categories']['options']['categories'] = [
'content' => html::div('input-group', $new_category->show('') . $add_category),
];
$this->rc->output->add_label('delete', 'calendar.remove_category');
$this->rc->output->add_script('
function rcube_calendar_add_category() {
var name = $("#rcmfd_new_category").val();
if (name.length) {
var button_label = rcmail.gettext("calendar.remove_category");
var input = $("<input>").attr({type: "text", name: "_categories[]", size: 30, "class": "form-control"}).val(name);
var color = $("<input>").attr({type: "text", name: "_colors[]", size: 6, "class": "colors form-control"}).val("000000");
var button = $("<a>").attr({"class": "button icon delete input-group-text", title: button_label, href: "#rcmfd_new_category"})
.click(function() { $(this).parent().parent().remove(); })
.append($("<span>").addClass("inner").text(rcmail.gettext("delete")));
$("<div>").addClass("input-group").append(input).append(color).append($("<span class=\'input-group-append\'>").append(button))
.appendTo("#calendarcategories");
color.minicolors(rcmail.env.minicolors_config || {});
$("#rcmfd_new_category").val("");
}
}',
'foot'
);
$this->rc->output->add_script('
$("#rcmfd_new_category").keypress(function(event) {
if (event.which == 13) {
rcube_calendar_add_category();
event.preventDefault();
}
});',
'docready'
);
// load miniColors js/css files
jqueryui::miniColors();
}
// virtual birthdays calendar
if (!isset($no_override['calendar_contact_birthdays'])) {
$p['blocks']['birthdays']['name'] = $this->gettext('birthdayscalendar');
if (empty($p['current'])) {
$p['blocks']['birthdays']['content'] = true;
return $p;
}
$field_id = 'rcmfd_contact_birthdays';
$input = new html_checkbox([
'name' => '_contact_birthdays',
'id' => $field_id,
'value' => 1,
'onclick' => '$(".calendar_birthday_props").prop("disabled",!this.checked)'
]);
$p['blocks']['birthdays']['options']['contact_birthdays'] = [
'title' => html::label($field_id, $this->gettext('displaybirthdayscalendar')),
'content' => $input->show($this->rc->config->get('calendar_contact_birthdays') ? 1 : 0),
];
$input_attrib = [
'class' => 'calendar_birthday_props',
'disabled' => !$this->rc->config->get('calendar_contact_birthdays'),
];
$sources = [];
$checkbox = new html_checkbox(['name' => '_birthday_adressbooks[]'] + $input_attrib);
foreach ($this->rc->get_address_sources(false, true) as $source) {
$active = in_array($source['id'], (array) $this->rc->config->get('calendar_birthday_adressbooks')) ? $source['id'] : '';
$sources[] = html::tag('li', null,
html::label(null,
$checkbox->show($active, ['value' => $source['id']])
. rcube::Q(!empty($source['realname']) ? $source['realname'] : $source['name'])
)
);
}
$p['blocks']['birthdays']['options']['birthday_adressbooks'] = [
'title' => rcube::Q($this->gettext('birthdayscalendarsources')),
'content' => html::tag('ul', 'proplist', implode("\n", $sources)),
];
$field_id = 'rcmfd_birthdays_alarm';
$select_type = new html_select(['name' => '_birthdays_alarm_type', 'id' => $field_id] + $input_attrib);
$select_type->add($this->gettext('none'), '');
foreach ($this->driver->alarm_types as $type) {
$select_type->add($this->rc->gettext(strtolower("alarm{$type}option"), 'libcalendaring'), $type);
}
$input_value = new html_inputfield(['name' => '_birthdays_alarm_value', 'id' => $field_id . 'value', 'size' => 3] + $input_attrib);
$select_offset = new html_select(['name' => '_birthdays_alarm_offset', 'id' => $field_id . 'offset'] + $input_attrib);
foreach (['-M','-H','-D'] as $trigger) {
$select_offset->add($this->rc->gettext('trigger' . $trigger, 'libcalendaring'), $trigger);
}
$preset = libcalendaring::parse_alarm_value($this->rc->config->get('calendar_birthdays_alarm_offset', '-1D'));
$preset_type = $this->rc->config->get('calendar_birthdays_alarm_type', '');
$p['blocks']['birthdays']['options']['birthdays_alarmoffset'] = [
'title' => html::label($field_id, rcube::Q($this->gettext('showalarms'))),
'content' => html::div('input-group',
$select_type->show($preset_type)
. $input_value->show($preset[0]) . ' ' . $select_offset->show($preset[1])
),
];
}
return $p;
}
/**
* Handler for preferences_save hook.
* Executed on Calendar settings form submit.
*
* @param array Original parameters
*
* @return array Modified parameters
*/
function preferences_save($p)
{
if ($p['section'] == 'calendar') {
$this->load_driver();
// compose default alarm preset value
$alarm_offset = rcube_utils::get_input_value('_alarm_offset', rcube_utils::INPUT_POST);
$alarm_value = rcube_utils::get_input_value('_alarm_value', rcube_utils::INPUT_POST);
$default_alarm = $alarm_offset[0] . intval($alarm_value) . $alarm_offset[1];
$birthdays_alarm_offset = rcube_utils::get_input_value('_birthdays_alarm_offset', rcube_utils::INPUT_POST);
$birthdays_alarm_value = rcube_utils::get_input_value('_birthdays_alarm_value', rcube_utils::INPUT_POST);
$birthdays_alarm_value = $birthdays_alarm_offset[0] . intval($birthdays_alarm_value) . $birthdays_alarm_offset[1];
$p['prefs'] = [
'calendar_default_view' => rcube_utils::get_input_value('_default_view', rcube_utils::INPUT_POST),
'calendar_timeslots' => intval(rcube_utils::get_input_value('_timeslots', rcube_utils::INPUT_POST)),
'calendar_first_day' => intval(rcube_utils::get_input_value('_first_day', rcube_utils::INPUT_POST)),
'calendar_first_hour' => intval(rcube_utils::get_input_value('_first_hour', rcube_utils::INPUT_POST)),
'calendar_work_start' => intval(rcube_utils::get_input_value('_work_start', rcube_utils::INPUT_POST)),
'calendar_work_end' => intval(rcube_utils::get_input_value('_work_end', rcube_utils::INPUT_POST)),
'calendar_show_weekno' => intval(rcube_utils::get_input_value('_show_weekno', rcube_utils::INPUT_POST)),
'calendar_event_coloring' => intval(rcube_utils::get_input_value('_event_coloring', rcube_utils::INPUT_POST)),
'calendar_default_alarm_type' => rcube_utils::get_input_value('_alarm_type', rcube_utils::INPUT_POST),
'calendar_default_alarm_offset' => $default_alarm,
'calendar_default_calendar' => rcube_utils::get_input_value('_default_calendar', rcube_utils::INPUT_POST),
'calendar_date_format' => null, // clear previously saved values
'calendar_time_format' => null,
'calendar_contact_birthdays' => (bool) rcube_utils::get_input_value('_contact_birthdays', rcube_utils::INPUT_POST),
'calendar_birthday_adressbooks' => (array) rcube_utils::get_input_value('_birthday_adressbooks', rcube_utils::INPUT_POST),
'calendar_birthdays_alarm_type' => rcube_utils::get_input_value('_birthdays_alarm_type', rcube_utils::INPUT_POST),
'calendar_birthdays_alarm_offset' => $birthdays_alarm_value ?: null,
'calendar_itip_after_action' => intval(rcube_utils::get_input_value('_after_action', rcube_utils::INPUT_POST)),
];
if ($p['prefs']['calendar_itip_after_action'] == 4) {
$p['prefs']['calendar_itip_after_action'] = rcube_utils::get_input_value('_after_action_folder', rcube_utils::INPUT_POST, true);
}
// categories
if (empty($this->driver->nocategories)) {
$old_categories = $new_categories = [];
foreach ($this->driver->list_categories() as $name => $color) {
$old_categories[md5($name)] = $name;
}
$categories = (array) rcube_utils::get_input_value('_categories', rcube_utils::INPUT_POST);
$colors = (array) rcube_utils::get_input_value('_colors', rcube_utils::INPUT_POST);
foreach ($categories as $key => $name) {
if (!isset($colors[$key])) {
continue;
}
$color = preg_replace('/^#/', '', strval($colors[$key]));
// rename categories in existing events -> driver's job
if (!empty($old_categories[$key])) {
$oldname = $old_categories[$key];
$this->driver->replace_category($oldname, $name, $color);
unset($old_categories[$key]);
}
else {
$this->driver->add_category($name, $color);
}
$new_categories[$name] = $color;
}
// these old categories have been removed, alter events accordingly -> driver's job
foreach ((array) $old_categories as $key => $name) {
$this->driver->remove_category($name);
}
$p['prefs']['calendar_categories'] = $new_categories;
}
}
return $p;
}
/**
* Dispatcher for calendar actions initiated by the client
*/
function calendar_action()
{
$action = rcube_utils::get_input_value('action', rcube_utils::INPUT_GPC);
$cal = rcube_utils::get_input_value('c', rcube_utils::INPUT_GPC);
$success = false;
$reload = false;
if (isset($cal['showalarms'])) {
$cal['showalarms'] = intval($cal['showalarms']);
}
switch ($action) {
case "form-new":
case "form-edit":
echo $this->ui->calendar_editform($action, $cal);
exit;
case "new":
$success = $this->driver->create_calendar($cal);
$reload = true;
break;
case "edit":
$success = $this->driver->edit_calendar($cal);
$reload = true;
break;
case "delete":
if ($success = $this->driver->delete_calendar($cal)) {
$this->rc->output->command('plugin.destroy_source', ['id' => $cal['id']]);
}
break;
case "subscribe":
if (!$this->driver->subscribe_calendar($cal)) {
$this->rc->output->show_message($this->gettext('errorsaving'), 'error');
}
else {
$calendars = $this->driver->list_calendars();
$calendar = !empty($calendars[$cal['id']]) ? $calendars[$cal['id']] : null;
// find parent folder and check if it's a "user calendar"
// if it's also activated we need to refresh it (#5340)
while (!empty($calendar['parent'])) {
if (isset($calendars[$calendar['parent']])) {
$calendar = $calendars[$calendar['parent']];
}
else {
break;
}
}
if ($calendar && $calendar['id'] != $cal['id']
&& !empty($calendar['active'])
&& $calendar['group'] == "other user"
) {
$this->rc->output->command('plugin.refresh_source', $calendar['id']);
}
}
return;
case "search":
$results = [];
$color_mode = $this->rc->config->get('calendar_event_coloring', $this->defaults['calendar_event_coloring']);
$query = rcube_utils::get_input_value('q', rcube_utils::INPUT_GPC);
$source = rcube_utils::get_input_value('source', rcube_utils::INPUT_GPC);
foreach ((array) $this->driver->search_calendars($query, $source) as $id => $prop) {
$editname = $prop['editname'];
unset($prop['editname']); // force full name to be displayed
$prop['active'] = false;
// let the UI generate HTML and CSS representation for this calendar
$html = $this->ui->calendar_list_item($id, $prop, $jsenv);
$cal = $jsenv[$id];
$cal['editname'] = $editname;
$cal['html'] = $html;
if (!empty($prop['color'])) {
$cal['css'] = $this->ui->calendar_css_classes($id, $prop, $color_mode);
}