summaryrefslogtreecommitdiff
path: root/plugins/kolab_zpush/kolab_zpush_ui.php
blob: 0e8e6e9d4d9eefa5c47384a7e430685396270fe8 (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
<?php

/**
 * Z-Push configuration user interface builder
 *
 * @version 0.2
 * @author Thomas Bruederli <bruederli@kolabsys.com>
 *
 * Copyright (C) 2011, 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 kolab_zpush_ui
{
    private $rc;
    private $config;

    public function __construct($config)
    {
        $this->config = $config;
        $this->rc = rcube::get_instance();

        $skin = $this->rc->config->get('skin');
        $this->config->include_stylesheet('skins/' . $skin . '/config.css');
        $this->rc->output->include_script('list.js');
        $this->skin_path = $this->config->urlbase . 'skins/' . $skin . '/';
    }


    public function device_list($attrib = array())
    {
        $attrib += array('id' => 'devices-list');

        $devices = $this->config->list_devices();
        $table = new html_table();

        foreach ($devices as $id => $device) {
            $name = $device['ALIAS'] ? $device['ALIAS'] : $id;
            $table->add_row(array('id' => 'rcmrow' . $id));
            $table->add(null, html::span('devicealias', Q($name)) . html::span('devicetype', Q($device['TYPE'])));
        }

        $this->rc->output->add_gui_object('devicelist', $attrib['id']);
        $this->rc->output->set_env('devices', $devices);

        return $table->show($attrib);
    }


    public function device_config_form($attrib = array())
    {
        $table = new html_table(array('cols' => 2));

        $field_id = 'config-device-alias';
        $input = new html_inputfield(array('name' => 'devicealias', 'id' => $field_id, 'size' => 40));
        $table->add('title', html::label($field_id, $this->config->gettext('devicealias')));
        $table->add(null, $input->show());

        $field_id = 'config-device-mode';
        $select = new html_select(array('name' => 'syncmode', 'id' => $field_id));
        $select->add(array($this->config->gettext('modeauto'), $this->config->gettext('modeflat'), $this->config->gettext('modefolder')), array('-1', '0', '1'));
        $table->add('title', html::label($field_id, $this->config->gettext('syncmode')));
        $table->add(null, $select->show('-1'));

        $field_id = 'config-device-laxpic';
        $checkbox = new html_checkbox(array('name' => 'laxpic', 'value' => '1', 'id' => $field_id));
        $table->add('title', $this->config->gettext('imageformat'));
        $table->add(null, html::label($field_id, $checkbox->show() . ' ' . $this->config->gettext('laxpiclabel')));

        if ($attrib['form'])
            $this->rc->output->add_gui_object('editform', $attrib['form']);

        return $table->show($attrib);
    }


    public function folder_subscriptions($attrib = array())
    {
        if (!$attrib['id'])
            $attrib['id'] = 'foldersubscriptions';

        // group folders by type (show only known types)
        $folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array());
        $folder_meta = $this->config->folders_meta();
        foreach ($this->config->list_folders() as $folder) {
            $type = $folder_meta[$folder]['TYPE'] ? $folder_meta[$folder]['TYPE'] : 'mail';
            if (is_array($folder_groups[$type]))
                $folder_groups[$type][] = $folder;
        }

        // build block for every folder type
        foreach ($folder_groups as $type => $group) {
            if (empty($group))
                continue;
            $attrib['type'] = $type;
            $html .= html::div('subscriptionblock',
                html::tag('h3', $type, $this->config->gettext($type)) .
                $this->folder_subscriptions_block($group, $attrib));
        }
        
        $this->rc->output->add_gui_object('subscriptionslist', $attrib['id']);

        return html::div($attrib, $html);
    }

    public function folder_subscriptions_block($a_folders, $attrib)
    {
        $alarms = ($attrib['type'] == 'event' || $attrib['type'] == 'task');

        $table = new html_table(array('cellspacing' => 0));
        $table->add_header('subscription', $attrib['syncicon'] ? html::img(array('src' => $this->skin_path . $attrib['syncicon'], 'title' => $this->config->gettext('synchronize'))) : '');
        $table->add_header('alarm', $alarms && $attrib['alarmicon'] ? html::img(array('src' => $this->skin_path . $attrib['alarmicon'], 'title' => $this->config->gettext('withalarms'))) : '');
        $table->add_header('foldername', $this->config->gettext('folder'));

        $checkbox_sync = new html_checkbox(array('name' => 'subscribed[]', 'class' => 'subscription'));
        $checkbox_alarm = new html_checkbox(array('name' => 'alarm[]', 'class' => 'alarm'));

        $names = array();
        foreach ($a_folders as $folder) {
            $foldername = $origname = preg_replace('/^INBOX &raquo;\s+/', '', kolab_storage::object_name($folder));

            // find folder prefix to truncate (the same code as in kolab_addressbook plugin)
            for ($i = count($names)-1; $i >= 0; $i--) {
                if (strpos($foldername, $names[$i].' &raquo; ') === 0) {
                    $length = strlen($names[$i].' &raquo; ');
                    $prefix = substr($foldername, 0, $length);
                    $count  = count(explode(' &raquo; ', $prefix));
                    $foldername = str_repeat('&nbsp;&nbsp;', $count-1) . '&raquo; ' . substr($foldername, $length);
                    break;
                }
            }

            $names[] = $origname;
            $classes = array('mailbox');

            if ($folder_class = $this->rc->folder_classname($folder)) {
                $foldername = $this->rc->gettext($folder_class);
                $classes[] = $folder_class;
            }

            $folder_id = 'rcmf' . html_identifier($folder);

            $table->add_row();
            $table->add('subscription', $checkbox_sync->show('', array('value' => $folder, 'id' => $folder_id)));

            if ($alarms)
                $table->add('alarm', $checkbox_alarm->show('', array('value' => $folder, 'id' => $folder_id.'_alarm')));
            else
                $table->add('alarm', '');

            $table->add(join(' ', $classes), html::label($folder_id, Q($foldername)));
        }

        return $table->show();
    }

}