summaryrefslogtreecommitdiffstats
path: root/lib/client/kolab_client_task_sharedfolder.php
blob: b02e007e3565c1a22f55a0253c1cb1249ca6ccd2 (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
<?php
/*
 +--------------------------------------------------------------------------+
 | This file is part of the Kolab Web Admin Panel                           |
 |                                                                          |
 | Copyright (C) 2011-2012, Kolab Systems AG                                |
 |                                                                          |
 | 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/>      |
 +--------------------------------------------------------------------------+
 | Author: Aleksander Machniak <machniak@kolabsys.com>                      |
 +--------------------------------------------------------------------------+
*/

class kolab_client_task_sharedfolder extends kolab_client_task
{
    protected $ajax_only = true;

    protected $menu = array(
        'add'  => 'sharedfolder.add',
    );

    protected $list_attribs = array('cn');

    /**
     * Default action.
     */
    public function action_default()
    {
        $this->output->set_object('content', 'sharedfolder', true);
        $this->output->set_object('task_navigation', $this->menu());

        $this->action_list();

        // display form to add a shared folder if logged-in user has right to do so
        $caps = $this->get_capability('actions');
        if (!empty($caps['sharedfolder.add'])) {
            $this->action_add();
        }
        else {
            $this->output->command('set_watermark', 'taskcontent');
        }
    }

    /**
     * Resource adding (form) action.
     */
    public function action_add()
    {
        $data   = $this->get_input('data', 'POST');
        $output = $this->sharedfolder_form(null, $data, true);

        $this->output->set_object('taskcontent', $output);
    }

    /**
     * Resource information (form) action.
     */
    public function action_info()
    {
        $id     = $this->get_input('id', 'POST');
        $result = $this->api_get('sharedfolder.info', array('id' => $id));
        $data   = $result->get();
        $output = $this->sharedfolder_form(null, $data);

        $this->output->set_object('taskcontent', $output);
    }

    private function sharedfolder_form($attribs, $data = array())
    {
        if (empty($attribs['id'])) {
            $attribs['id'] = 'sharedfolder-form';
        }

        // Form sections
        $sections = array(
            'system'        => 'sharedfolder.system',
            'other'         => 'sharedfolder.other',
        );

        // field-to-section map and fields order
        $fields_map = array(
            'type_id'                   => 'system',
            'type_id_name'              => 'system',

            'cn'                        => 'system',
            'ou'                        => 'system',
            'preferredlanguage'         => 'system',

            'mail'                      => 'system',
            'alias'                     => 'system',
            'mailalternateaddress'      => 'system',

            'member'                    => 'system',
            'uniquemember'              => 'system',
            'memberurl'                 => 'system',

            'nsrole'                    => 'system',
            'nsroledn'                  => 'system',

            /* Kolab Settings */
            'kolabhomeserver'           => 'system',
            'mailhost'                  => 'system',
            'mailquota'                 => 'system',
            'kolabfreebusyfuture'       => 'system',
            'kolabinvitationpolicy'     => 'system',
            'kolabdelegate'             => 'system',
            'kolaballowsmtprecipient'   => 'system',
            'kolaballowsmtpsender'      => 'system',
        );

        // Prepare fields
        $form = $this->form_prepare('sharedfolder', $data, array(), null, $fields_map['type_id']);
        list($fields, $types, $type, $add_mode) = $form;

        // Create form object and populate with fields
        $form = $this->form_create('sharedfolder', $attribs, $sections, $fields, $fields_map, $data, $add_mode);

        return $form->output();
    }
}