summaryrefslogtreecommitdiff
path: root/plugins/tasklist/drivers/kolab/tasklist_kolab_driver.php
blob: 4fccf7e5232983b0fc2bf0311cb3499e62d4d50c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
<?php

/**
 * Kolab Groupware driver for the Tasklist plugin
 *
 * @version @package_version@
 * @author Thomas Bruederli <bruederli@kolabsys.com>
 *
 * Copyright (C) 2012-2015, Kolab Systems AG <contact@kolabsys.com>
 *
 * 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 tasklist_kolab_driver extends tasklist_driver
{
    // features supported by the backend
    public $alarms      = false;
    public $attachments = true;
    public $attendees   = true;
    public $undelete    = false; // task undelete action
    public $alarm_types = array('DISPLAY','AUDIO');
    public $search_more_results;

    private $rc;
    private $plugin;
    private $lists;
    private $folders = array();
    private $tasks   = array();
    private $tags    = array();


    /**
     * Default constructor
     */
    public function __construct($plugin)
    {
        $this->rc = $plugin->rc;
        $this->plugin = $plugin;

        if (kolab_storage::$version == '2.0') {
            $this->alarm_absolute = false;
        }

        // tasklist use fully encoded identifiers
        kolab_storage::$encode_ids = true;

        $this->_read_lists();

        $this->plugin->register_action('folder-acl', array($this, 'folder_acl'));
    }

    /**
     * Read available calendars for the current user and store them internally
     */
    private function _read_lists($force = false)
    {
        // already read sources
        if (isset($this->lists) && !$force)
            return $this->lists;

        // get all folders that have type "task"
        $folders = kolab_storage::sort_folders(kolab_storage::get_folders('task'));
        $this->lists = $this->folders = array();

        $delim = $this->rc->get_storage()->get_hierarchy_delimiter();

        // find default folder
        $default_index = 0;
        foreach ($folders as $i => $folder) {
            if ($folder->default && strpos($folder->name, $delim) === false)
                $default_index = $i;
        }

        // put default folder (aka INBOX) on top of the list
        if ($default_index > 0) {
            $default_folder = $folders[$default_index];
            unset($folders[$default_index]);
            array_unshift($folders, $default_folder);
        }

        $prefs = $this->rc->config->get('kolab_tasklists', array());

        foreach ($folders as $folder) {
            $tasklist = $this->folder_props($folder, $prefs);

            $this->lists[$tasklist['id']] = $tasklist;
            $this->folders[$tasklist['id']] = $folder;
            $this->folders[$folder->name] = $folder;
        }
    }

    /**
     * Derive list properties from the given kolab_storage_folder object
     */
    protected function folder_props($folder, $prefs)
    {
        if ($folder->get_namespace() == 'personal') {
            $norename = false;
            $editable = true;
            $rights = 'lrswikxtea';
            $alarms = true;
        }
        else {
            $alarms = false;
            $rights = 'lr';
            $editable = false;
            if (($myrights = $folder->get_myrights()) && !PEAR::isError($myrights)) {
                $rights = $myrights;
                if (strpos($rights, 't') !== false || strpos($rights, 'd') !== false)
                    $editable = strpos($rights, 'i');
            }
            $info = $folder->get_folder_info();
            $norename = $readonly || $info['norename'] || $info['protected'];
        }

        $list_id = $folder->id; #kolab_storage::folder_id($folder->name);
        $old_id = kolab_storage::folder_id($folder->name, false);

        if (!isset($prefs[$list_id]['showalarms']) && isset($prefs[$old_id]['showalarms'])) {
            $prefs[$list_id]['showalarms'] = $prefs[$old_id]['showalarms'];
        }

        return array(
            'id' => $list_id,
            'name' => $folder->get_name(),
            'listname' => $folder->get_foldername(),
            'editname' => $folder->get_foldername(),
            'color' => $folder->get_color('0000CC'),
            'showalarms' => isset($prefs[$list_id]['showalarms']) ? $prefs[$list_id]['showalarms'] : $alarms,
            'editable' => $editable,
            'rights'    => $rights,
            'norename' => $norename,
            'active' => $folder->is_active(),
            'parentfolder' => $folder->get_parent(),
            'default' => $folder->default,
            'virtual' => $folder->virtual,
            'children' => true,  // TODO: determine if that folder indeed has child folders
            'subscribed' => (bool)$folder->is_subscribed(),
            'removable' => !$folder->default,
            'subtype'  => $folder->subtype,
            'group' => $folder->default ? 'default' : $folder->get_namespace(),
            'class' => trim($folder->get_namespace() . ($folder->default ? ' default' : '')),
            'caldavuid' => $folder->get_uid(),
        );
    }

    /**
     * Get a list of available task lists from this source
     */
    public function get_lists(&$tree = null)
    {
        // attempt to create a default list for this user
        if (empty($this->lists) && !isset($this->search_more_results)) {
            $prop = array('name' => 'Tasks', 'color' => '0000CC', 'default' => true);
            if ($this->create_list($prop))
                $this->_read_lists(true);
        }

        $folders = array();
        foreach ($this->lists as $id => $list) {
            if (!empty($this->folders[$id])) {
                $folders[] = $this->folders[$id];
            }
        }

        // include virtual folders for a full folder tree
        if (!is_null($tree)) {
            $folders = kolab_storage::folder_hierarchy($folders, $tree);
        }

        $delim = $this->rc->get_storage()->get_hierarchy_delimiter();
        $prefs = $this->rc->config->get('kolab_tasklists', array());

        $lists = array();
        foreach ($folders as $folder) {
            $list_id   = $folder->id; // kolab_storage::folder_id($folder->name);
            $imap_path = explode($delim, $folder->name);

            // find parent
            do {
              array_pop($imap_path);
              $parent_id = kolab_storage::folder_id(join($delim, $imap_path));
            }
            while (count($imap_path) > 1 && !$this->folders[$parent_id]);

            // restore "real" parent ID
            if ($parent_id && !$this->folders[$parent_id]) {
                $parent_id = kolab_storage::folder_id($folder->get_parent());
            }

            $fullname = $folder->get_name();
            $listname = $folder->get_foldername();

            // special handling for virtual folders
            if ($folder instanceof kolab_storage_folder_user) {
                $lists[$list_id] = array(
                    'id'       => $list_id,
                    'name'     => $folder->get_name(),
                    'listname' => $listname,
                    'title'    => $folder->get_title(),
                    'virtual'  => true,
                    'editable' => false,
                    'rights'   => 'l',
                    'group'    => 'other virtual',
                    'class'    => 'user',
                    'parent'   => $parent_id,
                );
            }
            else if ($folder->virtual) {
                $lists[$list_id] = array(
                    'id'       => $list_id,
                    'name'     => kolab_storage::object_name($fullname),
                    'listname' => $listname,
                    'virtual'  => true,
                    'editable' => false,
                    'rights'   => 'l',
                    'group'    => $folder->get_namespace(),
                    'class'    => 'folder',
                    'parent'   => $parent_id,
                );
            }
            else {
                if (!$this->lists[$list_id]) {
                    $this->lists[$list_id] = $this->folder_props($folder, $prefs);
                    $this->folders[$list_id] = $folder;
                }
                $this->lists[$list_id]['parent'] = $parent_id;
                $lists[$list_id] = $this->lists[$list_id];
            }
        }

        return $lists;
    }

    /**
     * Get the kolab_calendar instance for the given calendar ID
     *
     * @param string List identifier (encoded imap folder name)
     * @return object kolab_storage_folder Object nor null if list doesn't exist
     */
    protected function get_folder($id)
    {
        // create list and folder instance if necesary
        if (!$this->lists[$id]) {
            $folder = kolab_storage::get_folder(kolab_storage::id_decode($id));
            if ($folder->type) {
                $this->folders[$id] = $folder;
                $this->lists[$id] = $this->folder_props($folder, $this->rc->config->get('kolab_tasklists', array()));
            }
        }

        return $this->folders[$id];
    }


    /**
     * Create a new list assigned to the current user
     *
     * @param array Hash array with list properties
     *        name: List name
     *       color: The color of the list
     *  showalarms: True if alarms are enabled
     * @return mixed ID of the new list on success, False on error
     */
    public function create_list(&$prop)
    {
        $prop['type'] = 'task' . ($prop['default'] ? '.default' : '');
        $prop['active'] = true; // activate folder by default
        $prop['subscribed'] = true;
        $folder = kolab_storage::folder_update($prop);

        if ($folder === false) {
            $this->last_error = kolab_storage::$last_error;
            return false;
        }

        // create ID
        $id = kolab_storage::folder_id($folder);

        $prefs['kolab_tasklists'] = $this->rc->config->get('kolab_tasklists', array());

        if (isset($prop['showalarms']))
            $prefs['kolab_tasklists'][$id]['showalarms'] = $prop['showalarms'] ? true : false;

        if ($prefs['kolab_tasklists'][$id])
            $this->rc->user->save_prefs($prefs);

        // force page reload to properly render folder hierarchy
        if (!empty($prop['parent'])) {
            $prop['_reload'] = true;
        }
        else {
            $folder = kolab_storage::get_folder($folder);
            $prop += $this->folder_props($folder, array());
        }

        return $id;
    }

    /**
     * Update properties of an existing tasklist
     *
     * @param array Hash array with list properties
     *          id: List Identifier
     *        name: List name
     *       color: The color of the list
     *  showalarms: True if alarms are enabled (if supported)
     * @return boolean True on success, Fales on failure
     */
    public function edit_list(&$prop)
    {
        if ($prop['id'] && ($folder = $this->get_folder($prop['id']))) {
            $prop['oldname'] = $folder->name;
            $prop['type'] = 'task';
            $newfolder = kolab_storage::folder_update($prop);

            if ($newfolder === false) {
                $this->last_error = kolab_storage::$last_error;
                return false;
            }

            // create ID
            $id = kolab_storage::folder_id($newfolder);

            // fallback to local prefs
            $prefs['kolab_tasklists'] = $this->rc->config->get('kolab_tasklists', array());
            unset($prefs['kolab_tasklists'][$prop['id']]);

            if (isset($prop['showalarms']))
                $prefs['kolab_tasklists'][$id]['showalarms'] = $prop['showalarms'] ? true : false;

            if ($prefs['kolab_tasklists'][$id])
                $this->rc->user->save_prefs($prefs);

            // force page reload if folder name/hierarchy changed
            if ($newfolder != $prop['oldname'])
                $prop['_reload'] = true;

            return $id;
        }

        return false;
    }

    /**
     * Set active/subscribed state of a list
     *
     * @param array Hash array with list properties
     *          id: List Identifier
     *      active: True if list is active, false if not
     *   permanent: True if list is to be subscribed permanently
     * @return boolean True on success, Fales on failure
     */
    public function subscribe_list($prop)
    {
        if ($prop['id'] && ($folder = $this->get_folder($prop['id']))) {
            $ret = false;
            if (isset($prop['permanent']))
                $ret |= $folder->subscribe(intval($prop['permanent']));
            if (isset($prop['active']))
                $ret |= $folder->activate(intval($prop['active']));

            // apply to child folders, too
            if ($prop['recursive']) {
                foreach ((array)kolab_storage::list_folders($folder->name, '*', 'task') as $subfolder) {
                    if (isset($prop['permanent']))
                        ($prop['permanent'] ? kolab_storage::folder_subscribe($subfolder) : kolab_storage::folder_unsubscribe($subfolder));
                    if (isset($prop['active']))
                        ($prop['active'] ? kolab_storage::folder_activate($subfolder) : kolab_storage::folder_deactivate($subfolder));
                }
            }
            return $ret;
        }
        return false;
    }

    /**
     * Delete the given list with all its contents
     *
     * @param array Hash array with list properties
     *      id: list Identifier
     * @return boolean True on success, Fales on failure
     */
    public function delete_list($prop)
    {
        if ($prop['id'] && ($folder = $this->get_folder($prop['id']))) {
          if (kolab_storage::folder_delete($folder->name))
              return true;
          else
              $this->last_error = kolab_storage::$last_error;
        }

        return false;
    }

    /**
     * Search for shared or otherwise not listed tasklists the user has access
     *
     * @param string Search string
     * @param string Section/source to search
     * @return array List of tasklists
     */
    public function search_lists($query, $source)
    {
        if (!kolab_storage::setup()) {
            return array();
        }

        $this->search_more_results = false;
        $this->lists = $this->folders = array();

        // find unsubscribed IMAP folders that have "event" type
        if ($source == 'folders') {
            foreach ((array)kolab_storage::search_folders('task', $query, array('other')) as $folder) {
                $this->folders[$folder->id] = $folder;
                $this->lists[$folder->id] = $this->folder_props($folder, array());
            }
        }
        // search other user's namespace via LDAP
        else if ($source == 'users') {
            $limit = $this->rc->config->get('autocomplete_max', 15) * 2;  // we have slightly more space, so display twice the number
            foreach (kolab_storage::search_users($query, 0, array(), $limit * 10) as $user) {
                $folders = array();
                // search for tasks folders shared by this user
                foreach (kolab_storage::list_user_folders($user, 'task', false) as $foldername) {
                    $folders[] = new kolab_storage_folder($foldername, 'task');
                }

                if (count($folders)) {
                    $userfolder = new kolab_storage_folder_user($user['kolabtargetfolder'], '', $user);
                    $this->folders[$userfolder->id] = $userfolder;
                    $this->lists[$userfolder->id] = $this->folder_props($userfolder, array());

                    foreach ($folders as $folder) {
                        $this->folders[$folder->id] = $folder;
                        $this->lists[$folder->id] = $this->folder_props($folder, array());
                        $count++;
                    }
                }

                if ($count >= $limit) {
                    $this->search_more_results = true;
                    break;
                }
            }
        }

        return $this->get_lists();
    }

    /**
     * Get a list of tags to assign tasks to
     *
     * @return array List of tags
     */
    public function get_tags()
    {
        $config = kolab_storage_config::get_instance();
        $tags   = $config->get_tags();
        $backend_tags = array_map(function($v) { return $v['name']; }, $tags);

        return array_values(array_unique(array_merge($this->tags, $backend_tags)));
    }

    /**
     * Get number of tasks matching the given filter
     *
     * @param array List of lists to count tasks of
     * @return array Hash array with counts grouped by status (all|flagged|completed|today|tomorrow|nodate)
     */
    public function count_tasks($lists = null)
    {
        if (empty($lists))
            $lists = array_keys($this->lists);
        else if (is_string($lists))
            $lists = explode(',', $lists);

        $today_date = new DateTime('now', $this->plugin->timezone);
        $today = $today_date->format('Y-m-d');
        $tomorrow_date = new DateTime('now + 1 day', $this->plugin->timezone);
        $tomorrow = $tomorrow_date->format('Y-m-d');

        $counts = array('all' => 0, 'flagged' => 0, 'today' => 0, 'tomorrow' => 0, 'overdue' => 0, 'nodate' => 0, 'mytasks' => 0);
        foreach ($lists as $list_id) {
            if (!$folder = $this->get_folder($list_id)) {
                continue;
            }
            foreach ($folder->select(array(array('tags','!~','x-complete'))) as $record) {
                $rec = $this->_to_rcube_task($record, $list_id, false);

                if ($this->is_complete($rec))  // don't count complete tasks
                    continue;

                $counts['all']++;
                if ($rec['flagged'])
                    $counts['flagged']++;
                if (empty($rec['date']))
                    $counts['nodate']++;
                else if ($rec['date'] == $today)
                    $counts['today']++;
                else if ($rec['date'] == $tomorrow)
                    $counts['tomorrow']++;
                else if ($rec['date'] < $today)
                    $counts['overdue']++;
                if ($this->plugin->is_attendee($rec) !== false)
                    $counts['mytasks']++;
            }
        }

        // avoid session race conditions that will loose temporary subscriptions
        $this->plugin->rc->session->nowrite = true;

        return $counts;
    }

    /**
     * Get all taks records matching the given filter
     *
     * @param array Hash array with filter criterias:
     *  - mask:  Bitmask representing the filter selection (check against tasklist::FILTER_MASK_* constants)
     *  - from:  Date range start as string (Y-m-d)
     *  - to:    Date range end as string (Y-m-d)
     *  - search: Search query string
     * @param array List of lists to get tasks from
     * @return array List of tasks records matchin the criteria
     */
    public function list_tasks($filter, $lists = null)
    {
        if (empty($lists))
            $lists = array_keys($this->lists);
        else if (is_string($lists))
            $lists = explode(',', $lists);

        $results = array();

        // query Kolab storage
        $query = array();
        if ($filter['mask'] & tasklist::FILTER_MASK_COMPLETE)
            $query[] = array('tags','~','x-complete');
        else if (empty($filter['since']))
            $query[] = array('tags','!~','x-complete');

        // full text search (only works with cache enabled)
        if ($filter['search']) {
            $search = mb_strtolower($filter['search']);
            foreach (rcube_utils::normalize_string($search, true) as $word) {
                $query[] = array('words', '~', $word);
            }
        }

        if ($filter['since']) {
            $query[] = array('changed', '>=', $filter['since']);
        }

        // load all tags into memory first
        kolab_storage_config::get_instance()->get_tags();

        foreach ($lists as $list_id) {
            if (!$folder = $this->get_folder($list_id)) {
                continue;
            }
            foreach ($folder->select($query) as $record) {
                $this->load_tags($record);
                $task = $this->_to_rcube_task($record, $list_id);

                // TODO: post-filter tasks returned from storage

                $results[] = $task;
            }
        }

        // avoid session race conditions that will loose temporary subscriptions
        $this->plugin->rc->session->nowrite = true;

        return $results;
    }

    /**
     * Return data of a specific task
     *
     * @param mixed  Hash array with task properties or task UID
     * @return array Hash array with task properties or false if not found
     */
    public function get_task($prop)
    {
        $this->_parse_id($prop);
        $id      = $prop['uid'];
        $list_id = $prop['list'];
        $folders = $list_id ? array($list_id => $this->get_folder($list_id)) : $this->folders;

        // find task in the available folders
        foreach ($folders as $list_id => $folder) {
            if (is_numeric($list_id) || !$folder)
                continue;
            if (!$this->tasks[$id] && ($object = $folder->get_object($id))) {
                $this->load_tags($object);
                $this->tasks[$id] = $this->_to_rcube_task($object, $list_id);
                break;
            }
        }

        return $this->tasks[$id];
    }

    /**
     * Get all decendents of the given task record
     *
     * @param mixed  Hash array with task properties or task UID
     * @param boolean True if all childrens children should be fetched
     * @return array List of all child task IDs
     */
    public function get_childs($prop, $recursive = false)
    {
        if (is_string($prop)) {
            $task = $this->get_task($prop);
            $prop = array('uid' => $task['uid'], 'list' => $task['list']);
        }
        else {
            $this->_parse_id($prop);
        }

        $childs = array();
        $list_id = $prop['list'];
        $task_ids = array($prop['uid']);
        $folder = $this->get_folder($list_id);

        // query for childs (recursively)
        while ($folder && !empty($task_ids)) {
            $query_ids = array();
            foreach ($task_ids as $task_id) {
                $query = array(array('tags','=','x-parent:' . $task_id));
                foreach ($folder->select($query) as $record) {
                    // don't rely on kolab_storage_folder filtering
                    if ($record['parent_id'] == $task_id) {
                        $childs[] = $list_id . ':' . $record['uid'];
                        $query_ids[] = $record['uid'];
                    }
                }
            }

            if (!$recursive)
                break;

            $task_ids = $query_ids;
        }

        return $childs;
    }

    /**
     * Get a list of pending alarms to be displayed to the user
     *
     * @param  integer Current time (unix timestamp)
     * @param  mixed   List of list IDs to show alarms for (either as array or comma-separated string)
     * @return array   A list of alarms, each encoded as hash array with task properties
     * @see tasklist_driver::pending_alarms()
     */
    public function pending_alarms($time, $lists = null)
    {
        $interval = 300;
        $time -= $time % 60;

        $slot = $time;
        $slot -= $slot % $interval;

        $last = $time - max(60, $this->rc->config->get('refresh_interval', 0));
        $last -= $last % $interval;

        // only check for alerts once in 5 minutes
        if ($last == $slot)
            return array();

        if ($lists && is_string($lists))
            $lists = explode(',', $lists);

        $time = $slot + $interval;

        $candidates = array();
        $query = array(array('tags', '=', 'x-has-alarms'), array('tags', '!=', 'x-complete'));
        foreach ($this->lists as $lid => $list) {
            // skip lists with alarms disabled
            if (!$list['showalarms'] || ($lists && !in_array($lid, $lists)))
                continue;

            $folder = $this->get_folder($lid);
            foreach ($folder->select($query) as $record) {
                if (!($record['valarms'] || $record['alarms']) || $record['status'] == 'COMPLETED' || $record['complete'] == 100)  // don't trust query :-)
                    continue;

                $task = $this->_to_rcube_task($record, $lid, false);

                // add to list if alarm is set
                $alarm = libcalendaring::get_next_alarm($task, 'task');
                if ($alarm && $alarm['time'] && $alarm['time'] <= $time && in_array($alarm['action'], $this->alarm_types)) {
                    $id = $alarm['id'];  // use alarm-id as primary identifier
                    $candidates[$id] = array(
                        'id'       => $id,
                        'title'    => $task['title'],
                        'date'     => $task['date'],
                        'time'     => $task['time'],
                        'notifyat' => $alarm['time'],
                        'action'   => $alarm['action'],
                    );
                }
            }
        }

        // get alarm information stored in local database
        if (!empty($candidates)) {
            $alarm_ids = array_map(array($this->rc->db, 'quote'), array_keys($candidates));
            $result = $this->rc->db->query("SELECT *"
                . " FROM " . $this->rc->db->table_name('kolab_alarms', true)
                . " WHERE `alarm_id` IN (" . join(',', $alarm_ids) . ")"
                    . " AND `user_id` = ?",
                $this->rc->user->ID
            );

            while ($result && ($rec = $this->rc->db->fetch_assoc($result))) {
                $dbdata[$rec['alarm_id']] = $rec;
            }
        }

        $alarms = array();
        foreach ($candidates as $id => $task) {
          // skip dismissed
          if ($dbdata[$id]['dismissed'])
              continue;

          // snooze function may have shifted alarm time
          $notifyat = $dbdata[$id]['notifyat'] ? strtotime($dbdata[$id]['notifyat']) : $task['notifyat'];
          if ($notifyat <= $time)
              $alarms[] = $task;
        }

        return $alarms;
    }

    /**
     * (User) feedback after showing an alarm notification
     * This should mark the alarm as 'shown' or snooze it for the given amount of time
     *
     * @param  string  Task identifier
     * @param  integer Suspend the alarm for this number of seconds
     */
    public function dismiss_alarm($id, $snooze = 0)
    {
        // delete old alarm entry
        $this->rc->db->query(
            "DELETE FROM " . $this->rc->db->table_name('kolab_alarms', true) . "
             WHERE `alarm_id` = ? AND `user_id` = ?",
            $id,
            $this->rc->user->ID
        );

        // set new notifyat time or unset if not snoozed
        $notifyat = $snooze > 0 ? date('Y-m-d H:i:s', time() + $snooze) : null;

        $query = $this->rc->db->query(
            "INSERT INTO " . $this->rc->db->table_name('kolab_alarms', true) . "
             (`alarm_id`, `user_id`, `dismissed`, `notifyat`)
             VALUES (?, ?, ?, ?)",
            $id,
            $this->rc->user->ID,
            $snooze > 0 ? 0 : 1,
            $notifyat
        );

        return $this->rc->db->affected_rows($query);
    }

    /**
     * Remove alarm dismissal or snooze state
     *
     * @param  string  Task identifier
     */
    public function clear_alarms($id)
    {
        // delete alarm entry
        $this->rc->db->query(
            "DELETE FROM " . $this->rc->db->table_name('kolab_alarms', true) . "
             WHERE `alarm_id` = ? AND `user_id` = ?",
            $id,
            $this->rc->user->ID
        );

        return true;
    }

    /**
     * Get task tags
     */
    private function load_tags(&$object)
    {
        // this task hasn't been migrated yet
        if (!empty($object['categories'])) {
            // OPTIONAL: call kolab_storage_config::apply_tags() to migrate the object
            $object['tags'] = (array)$object['categories'];
            if (!empty($object['tags'])) {
                $this->tags = array_merge($this->tags, $object['tags']);
            }
        }
        else {
            $config = kolab_storage_config::get_instance();
            $tags   = $config->get_tags($object['uid']);
            $object['tags'] = array_map(function($v) { return $v['name']; }, $tags);
        }
    }

    /**
     * Update task tags
     */
    private function save_tags($uid, $tags)
    {
        $config = kolab_storage_config::get_instance();
        $config->save_tags($uid, $tags);
    }

    /**
     * Find messages linked with a task record
     */
    private function get_links($uid)
    {
        $config = kolab_storage_config::get_instance();
        return $config->get_object_links($uid);
    }

    /**
     *
     */
    private function save_links($uid, $links)
    {
        // make sure we have a valid array
        if (empty($links)) {
            $links = array();
        }

        $config = kolab_storage_config::get_instance();
        $remove = array_diff($config->get_object_links($uid), $links);
        return $config->save_object_links($uid, $links, $remove);
    }

    /**
     * Extract uid + list identifiers from the given input
     *
     * @param mixed array or string with task identifier(s)
     */
    private function _parse_id(&$prop)
    {
        $id_ = null;
        if (is_array($prop)) {
            // 'uid' + 'list' available, nothing to be done
            if (!empty($prop['uid']) && !empty($prop['list'])) {
                return;
            }

            // 'id' is given
            if (!empty($prop['id'])) {
                if (!empty($prop['list'])) {
                    $list_id = $prop['_fromlist'] ?: $prop['list'];
                    if (strpos($prop['id'], $list_id.':') === 0) {
                        $prop['uid'] = substr($prop['id'], strlen($list_id)+1);
                    }
                    else {
                        $prop['uid'] = $prop['id'];
                    }
                }
                else {
                    $id_ = $prop['id'];
                }
            }
        }
        else {
            $id_ = strval($prop);
            $prop = array();
        }

        // split 'id' into list + uid
        if (!empty($id_)) {
            list($list, $uid) = explode(':', $id_, 2);
            if (!empty($uid)) {
                $prop['uid'] = $uid;
                $prop['list'] = $list;
            }
            else {
                $prop['uid'] = $id_;
            }
        }
    }

    /**
     * Convert from Kolab_Format to internal representation
     */
    private function _to_rcube_task($record, $list_id, $all = true)
    {
        $id_prefix = $list_id . ':';
        $task = array(
            'id' => $id_prefix . $record['uid'],
            'uid' => $record['uid'],
            'title' => $record['title'],
//            'location' => $record['location'],
            'description' => $record['description'],
            'flagged' => $record['priority'] == 1,
            'complete' => floatval($record['complete'] / 100),
            'status' => $record['status'],
            'parent_id' => $record['parent_id'] ? $id_prefix . $record['parent_id'] : null,
            'recurrence' => $record['recurrence'],
            'attendees' => $record['attendees'],
            'organizer' => $record['organizer'],
            'sequence' => $record['sequence'],
            'tags' => $record['tags'],
            'list' => $list_id,
        );

        // we can sometimes skip this expensive operation
        if ($all) {
            $task['links'] = $this->get_links($task['uid']);
        }

        // convert from DateTime to internal date format
        if (is_a($record['due'], 'DateTime')) {
            $due = $this->plugin->lib->adjust_timezone($record['due']);
            $task['date'] = $due->format('Y-m-d');
            if (!$record['due']->_dateonly)
                $task['time'] = $due->format('H:i');
        }
        // convert from DateTime to internal date format
        if (is_a($record['start'], 'DateTime')) {
            $start = $this->plugin->lib->adjust_timezone($record['start']);
            $task['startdate'] = $start->format('Y-m-d');
            if (!$record['start']->_dateonly)
                $task['starttime'] = $start->format('H:i');
        }
        if (is_a($record['changed'], 'DateTime')) {
            $task['changed'] = $record['changed'];
        }
        if (is_a($record['created'], 'DateTime')) {
            $task['created'] = $record['created'];
        }

        if ($record['valarms']) {
            $task['valarms'] = $record['valarms'];
        }
        else if ($record['alarms']) {
            $task['alarms'] = $record['alarms'];
        }

        if (!empty($task['attendees'])) {
            foreach ((array)$task['attendees'] as $i => $attendee) {
                if (is_array($attendee['delegated-from'])) {
                    $task['attendees'][$i]['delegated-from'] = join(', ', $attendee['delegated-from']);
                }
                if (is_array($attendee['delegated-to'])) {
                    $task['attendees'][$i]['delegated-to'] = join(', ', $attendee['delegated-to']);
                }
            }
        }

        if (!empty($record['_attachments'])) {
            foreach ($record['_attachments'] as $key => $attachment) {
                if ($attachment !== false) {
                    if (!$attachment['name'])
                        $attachment['name'] = $key;
                    $attachments[] = $attachment;
                }
            }

            $task['attachments'] = $attachments;
        }

        return $task;
    }

    /**
     * Convert the given task record into a data structure that can be passed to kolab_storage backend for saving
     * (opposite of self::_to_rcube_event())
     */
    private function _from_rcube_task($task, $old = array())
    {
        $object = $task;
        $id_prefix = $task['list'] . ':';

        if (!empty($task['date'])) {
            $object['due'] = rcube_utils::anytodatetime($task['date'].' '.$task['time'], $this->plugin->timezone);
            if (empty($task['time']))
                $object['due']->_dateonly = true;
            unset($object['date']);
        }

        if (!empty($task['startdate'])) {
            $object['start'] = rcube_utils::anytodatetime($task['startdate'].' '.$task['starttime'], $this->plugin->timezone);
            if (empty($task['starttime']))
                $object['start']->_dateonly = true;
            unset($object['startdate']);
        }

        // as per RFC (and the Kolab schema validation), start and due dates need to be of the same type (#3614)
        // this should be catched in the client already but just make sure we don't write invalid objects
        if (!empty($object['start']) && !empty($object['due']) && $object['due']->_dateonly != $object['start']->_dateonly) {
            $object['start']->_dateonly = true;
            $object['due']->_dateonly = true;
        }

        $object['complete'] = $task['complete'] * 100;
        if ($task['complete'] == 1.0 && empty($task['complete']))
            $object['status'] = 'COMPLETED';

        if ($task['flagged'])
            $object['priority'] = 1;
        else
            $object['priority'] = $old['priority'] > 1 ? $old['priority'] : 0;

        // remove list: prefix from parent_id
        if (!empty($task['parent_id']) && strpos($task['parent_id'], $id_prefix) === 0) {
            $object['parent_id'] = substr($task['parent_id'], strlen($id_prefix));
        }

        // copy meta data (starting with _) from old object
        foreach ((array)$old as $key => $val) {
            if (!isset($object[$key]) && $key[0] == '_')
                $object[$key] = $val;
        }

        // copy recurrence rules if the client didn't submit it (#2713)
        if (!array_key_exists('recurrence', $object) && $old['recurrence']) {
            $object['recurrence'] = $old['recurrence'];
        }

        // delete existing attachment(s)
        if (!empty($task['deleted_attachments'])) {
            foreach ($task['deleted_attachments'] as $attachment) {
                if (is_array($object['_attachments'])) {
                    foreach ($object['_attachments'] as $idx => $att) {
                        if ($att['id'] == $attachment)
                            $object['_attachments'][$idx] = false;
                    }
                }
            }
            unset($task['deleted_attachments']);
        }

        // in kolab_storage attachments are indexed by content-id
        if (is_array($task['attachments'])) {
            foreach ($task['attachments'] as $idx => $attachment) {
                $key = null;
                // Roundcube ID has nothing to do with the storage ID, remove it
                if ($attachment['content'] || $attachment['path']) {
                    unset($attachment['id']);
                }
                else {
                    foreach ((array)$old['_attachments'] as $cid => $oldatt) {
                        if ($oldatt && $attachment['id'] == $oldatt['id'])
                            $key = $cid;
                    }
                }

                // replace existing entry
                if ($key) {
                    $object['_attachments'][$key] = $attachment;
                }
                // append as new attachment
                else {
                    $object['_attachments'][] = $attachment;
                }
            }

            unset($object['attachments']);
        }

        // allow sequence increments if I'm the organizer
        if ($this->plugin->is_organizer($object) && empty($object['_method'])) {
            unset($object['sequence']);
        }
        else if (isset($old['sequence']) && empty($object['_method'])) {
            $object['sequence'] = $old['sequence'];
        }

        unset($object['tempid'], $object['raw'], $object['list'], $object['flagged'], $object['tags'], $object['created']);
        return $object;
    }

    /**
     * Add a single task to the database
     *
     * @param array Hash array with task properties (see header of tasklist_driver.php)
     * @return mixed New task ID on success, False on error
     */
    public function create_task($task)
    {
        return $this->edit_task($task);
    }

    /**
     * Update an task entry with the given data
     *
     * @param array Hash array with task properties (see header of tasklist_driver.php)
     * @return boolean True on success, False on error
     */
    public function edit_task($task)
    {
        $this->_parse_id($task);
        $list_id = $task['list'];
        if (!$list_id || !($folder = $this->get_folder($list_id)))
            return false;

        // email links and tags are stored separately
        $links = $task['links'];
        $tags = $task['tags'];
        unset($task['tags'], $task['links']);

        // moved from another folder
        if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) {
            if (!$fromfolder->move($task['uid'], $folder))
                return false;

            unset($task['_fromlist']);
        }

        // load previous version of this task to merge
        if ($task['id']) {
            $old = $folder->get_object($task['uid']);
            if (!$old || PEAR::isError($old))
                return false;

            // merge existing properties if the update isn't complete
            if (!isset($task['title']) || !isset($task['complete']))
                $task += $this->_to_rcube_task($old, $list_id);
        }

        // generate new task object from RC input
        $object = $this->_from_rcube_task($task, $old);
        $saved  = $folder->save($object, 'task', $task['uid']);

        if (!$saved) {
            raise_error(array(
                'code' => 600, 'type' => 'php',
                'file' => __FILE__, 'line' => __LINE__,
                'message' => "Error saving task object to Kolab server"),
                true, false);
            $saved = false;
        }
        else {
            // save links in configuration.relation object
            $this->save_links($object['uid'], $links);
            // save tags in configuration.relation object
            $this->save_tags($object['uid'], $tags);

            $task = $this->_to_rcube_task($object, $list_id);
            $task['tags'] = (array) $tags;
            $this->tasks[$task['uid']] = $task;
        }

        return $saved;
    }

    /**
     * Move a single task to another list
     *
     * @param array   Hash array with task properties:
     * @return boolean True on success, False on error
     * @see tasklist_driver::move_task()
     */
    public function move_task($task)
    {
        $this->_parse_id($task);
        $list_id = $task['list'];
        if (!$list_id || !($folder = $this->get_folder($list_id)))
            return false;

        // execute move command
        if ($task['_fromlist'] && ($fromfolder = $this->get_folder($task['_fromlist']))) {
            return $fromfolder->move($task['uid'], $folder);
        }

        return false;
    }

    /**
     * Remove a single task from the database
     *
     * @param array   Hash array with task properties:
     *      id: Task identifier
     * @param boolean Remove record irreversible (mark as deleted otherwise, if supported by the backend)
     * @return boolean True on success, False on error
     */
    public function delete_task($task, $force = true)
    {
        $this->_parse_id($task);
        $list_id = $task['list'];
        if (!$list_id || !($folder = $this->get_folder($list_id)))
            return false;

        $status = $folder->delete($task['uid']);

        if ($status) {
            // remove tag assignments
            // @TODO: don't do this when undelete feature will be implemented
            $this->save_tags($task['uid'], null);
        }

        return $status;
    }

    /**
     * Restores a single deleted task (if supported)
     *
     * @param array Hash array with task properties:
     *      id: Task identifier
     * @return boolean True on success, False on error
     */
    public function undelete_task($prop)
    {
        // TODO: implement this
        return false;
    }


    /**
     * Get attachment properties
     *
     * @param string $id    Attachment identifier
     * @param array  $task  Hash array with event properties:
     *         id: Task identifier
     *       list: List identifier
     *
     * @return array Hash array with attachment properties:
     *         id: Attachment identifier
     *       name: Attachment name
     *   mimetype: MIME content type of the attachment
     *       size: Attachment size
     */
    public function get_attachment($id, $task)
    {
        $task = $this->get_task($task);

        if ($task && !empty($task['attachments'])) {
            foreach ($task['attachments'] as $att) {
                if ($att['id'] == $id)
                    return $att;
            }
        }

        return null;
    }

    /**
     * Get attachment body
     *
     * @param string $id    Attachment identifier
     * @param array  $task  Hash array with event properties:
     *         id: Task identifier
     *       list: List identifier
     *
     * @return string Attachment body
     */
    public function get_attachment_body($id, $task)
    {
        $this->_parse_id($task);
        if ($storage = $this->get_folder($task['list'])) {
            return $storage->get_attachment($task['uid'], $id);
        }

        return false;
    }

    /**
     * Build a struct representing the given message reference
     *
     * @see tasklist_driver::get_message_reference()
     */
    public function get_message_reference($uri_or_headers, $folder = null)
    {
        if (is_object($uri_or_headers)) {
            $uri_or_headers = kolab_storage_config::get_message_uri($uri_or_headers, $folder);
        }

        if (is_string($uri_or_headers)) {
            return kolab_storage_config::get_message_reference($uri_or_headers, 'task');
        }

        return false;
    }

    /**
     * Find tasks assigned to a specified message
     *
     * @see tasklist_driver::get_message_related_tasks()
     */
    public function get_message_related_tasks($headers, $folder)
    {
        $config = kolab_storage_config::get_instance();
        $result = $config->get_message_relations($headers, $folder, 'task');

        foreach ($result as $idx => $rec) {
            $result[$idx] = $this->_to_rcube_task($rec, kolab_storage::folder_id($rec['_mailbox']));
        }

        return $result;
    }

    /**
     * 
     */
    public function tasklist_edit_form($action, $list, $fieldprop)
    {
        if ($list['id'] && ($list = $this->lists[$list['id']])) {
            $folder_name = $this->get_folder($list['id'])->name; // UTF7
        }
        else {
            $folder_name = '';
        }

        $storage = $this->rc->get_storage();
        $delim   = $storage->get_hierarchy_delimiter();
        $form    = array();

        if (strlen($folder_name)) {
            $path_imap = explode($delim, $folder_name);
            array_pop($path_imap);  // pop off name part
            $path_imap = implode($path_imap, $delim);

            $options = $storage->folder_info($folder_name);
        }
        else {
            $path_imap = '';
        }

        $hidden_fields[] = array('name' => 'oldname', 'value' => $folder_name);

        // folder name (default field)
        $input_name = new html_inputfield(array('name' => 'name', 'id' => 'taskedit-tasklistame', 'size' => 20));
        $fieldprop['name']['value'] = $input_name->show($list['editname'], array('disabled' => ($options['norename'] || $options['protected'])));

        // prevent user from moving folder
        if (!empty($options) && ($options['norename'] || $options['protected'])) {
            $hidden_fields[] = array('name' => 'parent', 'value' => $path_imap);
        }
        else {
            $select = kolab_storage::folder_selector('task', array('name' => 'parent', 'id' => 'taskedit-parentfolder'), $folder_name);
            $fieldprop['parent'] = array(
                'id'    => 'taskedit-parentfolder',
                'label' => $this->plugin->gettext('parentfolder'),
                'value' => $select->show($path_imap),
            );
        }

        // General tab
        $form['properties'] = array(
            'name' => $this->rc->gettext('properties'),
            'fields' => array(),
        );

        foreach (array('name','parent','showalarms') as $f) {
            $form['properties']['fields'][$f] = $fieldprop[$f];
        }

        // add folder ACL tab
        if ($action != 'form-new') {
            $form['sharing'] = array(
                'name'    => Q($this->plugin->gettext('tabsharing')),
                'content' => html::tag('iframe', array(
                    'src' => $this->rc->url(array('_action' => 'folder-acl', '_folder' => $folder_name, 'framed' => 1)),
                    'width' => '100%',
                    'height' => 280,
                    'border' => 0,
                    'style' => 'border:0'),
                '')
            );
        }

        $form_html = '';
        if (is_array($hidden_fields)) {
            foreach ($hidden_fields as $field) {
                $hiddenfield = new html_hiddenfield($field);
                $form_html .= $hiddenfield->show() . "\n";
            }
        }

        // create form output
        foreach ($form as $tab) {
            if (is_array($tab['fields']) && empty($tab['content'])) {
                $table = new html_table(array('cols' => 2));
                foreach ($tab['fields'] as $col => $colprop) {
                    $label = !empty($colprop['label']) ? $colprop['label'] : $this->plugin->gettext($col);

                    $table->add('title', html::label($colprop['id'], Q($label)));
                    $table->add(null, $colprop['value']);
                }
                $content = $table->show();
            }
            else {
                $content = $tab['content'];
            }

            if (!empty($content)) {
                $form_html .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) . "\n";
            }
        }

        return $form_html;
    }

    /**
     * Handler to render ACL form for a notes folder
     */
    public function folder_acl()
    {
        $this->plugin->require_plugin('acl');
        $this->rc->output->add_handler('folderacl', array($this, 'folder_acl_form'));
        $this->rc->output->send('tasklist.kolabacl');
    }

    /**
     * Handler for ACL form template object
     */
    public function folder_acl_form()
    {
        $folder = rcube_utils::get_input_value('_folder', rcube_utils::INPUT_GPC);

        if (strlen($folder)) {
            $storage = $this->rc->get_storage();
            $options = $storage->folder_info($folder);

            // get sharing UI from acl plugin
            $acl = $this->rc->plugins->exec_hook('folder_form',
                array('form' => array(), 'options' => $options, 'name' => $folder));
        }

        return $acl['form']['sharing']['content'] ?: html::div('hint', $this->plugin->gettext('aclnorights'));
    }
}