Aleksander Machniak
2016-02-23 b01689caf8e372d40112eda0f14a84eed41389d5
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/func.inc                                       |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
d575e4 8  | Copyright (C) 2005-2013, The Roundcube Dev Team                       |
7fe381 9  |                                                                       |
T 10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
4e17e6 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Provide functionality for user's settings & preferences             |
16  |                                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
21
c6406e 22 if (!$OUTPUT->ajax_call) {
6b2b2e 23     $OUTPUT->set_pagetitle($RCMAIL->gettext('preferences'));
c6406e 24 }
d575e4 25
AM 26 // register UI objects
27 $OUTPUT->add_handlers(array(
28     'settingstabs'   => 'rcmail_settings_tabs',
29     'prefsframe'     => 'rcmail_preferences_frame',
30     'sectionslist'   => 'rcmail_sections_list',
31     'identitieslist' => 'rcmail_identities_list',
32 ));
33
34 // register action aliases
35 $RCMAIL->register_action_map(array(
36     'folders'       => 'folders.inc',
37     'rename-folder' => 'folders.inc',
38     'delete-folder' => 'folders.inc',
39     'subscribe'     => 'folders.inc',
40     'unsubscribe'   => 'folders.inc',
41     'purge'         => 'folders.inc',
42     'folder-size'   => 'folders.inc',
43     'add-identity'  => 'edit_identity.inc',
44     'add-response'  => 'edit_response.inc',
45     'save-response' => 'edit_response.inc',
46     'delete-response' => 'responses.inc',
ca01e2 47     'delete-identity' => 'identities.inc',
3cc1af 48     'upload-display'  => 'upload.inc',
d575e4 49 ));
AM 50
b19097 51
f05834 52 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
A 53 function rcmail_preferences_frame($attrib)
d11fb2 54 {
c6406e 55     global $OUTPUT;
cb3538 56
c6406e 57     if (!$attrib['id']) {
AM 58         $attrib['id'] = 'rcmprefsframe';
59     }
35c31e 60
c6406e 61     return $OUTPUT->frame($attrib, true);
d11fb2 62 }
f05834 63
A 64
65 function rcmail_sections_list($attrib)
d11fb2 66 {
c6406e 67     global $RCMAIL;
f8e8af 68
c6406e 69     // add id to message list table if not specified
AM 70     if (!strlen($attrib['id'])) {
71         $attrib['id'] = 'rcmsectionslist';
72     }
f05834 73
c6406e 74     list($list, $cols) = rcmail_user_prefs();
f8e8af 75
c6406e 76     // create XHTML table
6b2b2e 77     $out = $RCMAIL->table_output($attrib, $list, $cols, 'id');
f05834 78
c6406e 79     // set client env
AM 80     $RCMAIL->output->add_gui_object('sectionslist', $attrib['id']);
81     $RCMAIL->output->include_script('list.js');
f05834 82
c6406e 83     return $out;
d11fb2 84 }
4e17e6 85
T 86
87 function rcmail_identities_list($attrib)
d11fb2 88 {
c6406e 89     global $OUTPUT, $RCMAIL;
4e17e6 90
c6406e 91     // add id to message list table if not specified
AM 92     if (!strlen($attrib['id'])) {
93         $attrib['id'] = 'rcmIdentitiesList';
94     }
4e17e6 95
c6406e 96     // get identities list and define 'mail' column
2f4678 97     $list = $RCMAIL->user->list_emails();
c6406e 98     foreach ($list as $idx => $row) {
2f4678 99         $list[$idx]['mail'] = trim($row['name'] . ' <' . rcube_utils::idn_to_utf8($row['email']) . '>');
c6406e 100     }
54759c 101
c6406e 102     // get all identites from DB and define list of cols to be displayed
AM 103     $plugin = $RCMAIL->plugins->exec_hook('identities_list', array(
104         'list' => $list,
105         'cols' => array('mail')
106     ));
4e17e6 107
c6406e 108     // @TODO: use <UL> instead of <TABLE> for identities list
AM 109     // create XHTML table
6b2b2e 110     $out = $RCMAIL->table_output($attrib, $plugin['list'], $plugin['cols'], 'identity_id');
54759c 111
c6406e 112     // set client env
AM 113     $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
4e17e6 114
c6406e 115     return $out;
d11fb2 116 }
4e17e6 117
T 118
119 // similar function as in /steps/addressbook/edit.inc
57f0c8 120 function get_form_tags($attrib, $action, $id = null, $hidden = null)
d11fb2 121 {
c6406e 122     global $EDIT_FORM, $RCMAIL;
4e17e6 123
c6406e 124     $form_start = $form_end = '';
f8e8af 125
c6406e 126     if (empty($EDIT_FORM)) {
AM 127         $request_key = $action . (isset($id) ? '.'.$id : '');
128         $form_start = $RCMAIL->output->request_form(array(
129             'name'    => 'form',
130             'method'  => 'post',
131             'task'    => $RCMAIL->task,
132             'action'  => $action,
133             'request' => $request_key,
134             'noclose' => true
135         ) + $attrib);
f8e8af 136
c6406e 137         if (is_array($hidden)) {
AM 138             $hiddenfields = new html_hiddenfield($hidden);
139             $form_start .= $hiddenfields->show();
140         }
141
142         $form_end = !strlen($attrib['form']) ? '</form>' : '';
143
144         $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
145         $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
4e17e6 146     }
f8e8af 147
c6406e 148     return array($form_start, $form_end);
d11fb2 149 }
4e17e6 150
ec0171 151
c6406e 152 function rcmail_user_prefs($current = null)
49771b 153 {
c6406e 154     global $RCMAIL;
49771b 155
6b2b2e 156     $sections['general']     = array('id' => 'general', 'section' => $RCMAIL->gettext('uisettings'));
AM 157     $sections['mailbox']     = array('id' => 'mailbox', 'section' => $RCMAIL->gettext('mailboxview'));
158     $sections['mailview']    = array('id' => 'mailview','section' => $RCMAIL->gettext('messagesdisplaying'));
159     $sections['compose']     = array('id' => 'compose', 'section' => $RCMAIL->gettext('messagescomposition'));
160     $sections['addressbook'] = array('id' => 'addressbook','section' => $RCMAIL->gettext('addressbook'));
161     $sections['folders']     = array('id' => 'folders', 'section' => $RCMAIL->gettext('specialfolders'));
162     $sections['server']      = array('id' => 'server',  'section' => $RCMAIL->gettext('serversettings'));
49771b 163
c6406e 164     // hook + define list cols
AM 165     $plugin = $RCMAIL->plugins->exec_hook('preferences_sections_list',
49771b 166         array('list' => $sections, 'cols' => array('section')));
A 167
c6406e 168     $sections    = $plugin['list'];
AM 169     $config      = $RCMAIL->config->all();
170     $no_override = array_flip((array)$RCMAIL->config->get('dont_override'));
f8e8af 171
c6406e 172     foreach ($sections as $idx => $sect) {
AM 173         if ($current && $sect['id'] != $current) {
174             continue;
476fa9 175         }
5879c0 176
c6406e 177         $blocks = array();
5879c0 178
c6406e 179         switch ($sect['id']) {
49771b 180
c6406e 181         // general
AM 182         case 'general':
183             $blocks = array(
6b2b2e 184                 'main'    => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 185                 'skin'    => array('name' => rcube::Q($RCMAIL->gettext('skin'))),
186                 'browser' => array('name' => rcube::Q($RCMAIL->gettext('browseroptions'))),
187                 'advanced'=> array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 188             );
1cc9e2 189
c6406e 190             // language selection
AM 191             if (!isset($no_override['language'])) {
192                 if (!$current) {
193                     continue 2;
194                 }
1cc9e2 195
c6406e 196                 $a_lang = $RCMAIL->list_languages();
AM 197                 asort($a_lang);
1cc9e2 198
c6406e 199                 $field_id = 'rcmfd_lang';
AM 200                 $select   = new html_select(array('name' => '_language', 'id' => $field_id));
201                 $select->add(array_values($a_lang), array_keys($a_lang));
1cc9e2 202
c6406e 203                 $blocks['main']['options']['language'] = array(
6b2b2e 204                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('language'))),
c6406e 205                     'content' => $select->show($RCMAIL->user->language),
AM 206                 );
207             }
49771b 208
c6406e 209             // timezone selection
AM 210             if (!isset($no_override['timezone'])) {
211                 if (!$current) {
212                     continue 2;
213                 }
49771b 214
c6406e 215                 $field_id = 'rcmfd_timezone';
AM 216                 $select   = new html_select(array('name' => '_timezone', 'id' => $field_id));
6b2b2e 217                 $select->add($RCMAIL->gettext('autodetect'), 'auto');
aa8359 218
c6406e 219                 $zones = array();
AM 220                 foreach (DateTimeZone::listIdentifiers() as $i => $tzs) {
221                     try {
222                         $tz      = new DateTimeZone($tzs);
d1bf0f 223                         $date    = new DateTime(date('Y') . '-12-21', $tz);
c6406e 224                         $offset  = $date->format('Z') + 45000;
AM 225                         $sortkey = sprintf('%06d.%s', $offset, $tzs);
226                         $zones[$sortkey] = array($tzs, $date->format('P'));
227                     }
228                     catch (Exception $e) {}
229                 }
aa8359 230
c6406e 231                 ksort($zones);
aa8359 232
c6406e 233                 foreach ($zones as $zone) {
AM 234                     list($tzs, $offset) = $zone;
235                     $select->add('(GMT ' . $offset . ') ' . strtr($tzs, '_', ' '), $tzs);
236                 }
49771b 237
c6406e 238                 $blocks['main']['options']['timezone'] = array(
6b2b2e 239                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('timezone'))),
c6406e 240                     'content' => $select->show((string)$config['timezone']),
AM 241                 );
242             }
49771b 243
c6406e 244             // date/time formatting
AM 245             if (!isset($no_override['time_format'])) {
246                 if (!$current) {
247                     continue 2;
248                 }
18b738 249
c6406e 250                 $reftime  = mktime(7,30,0);
AM 251                 $defaults = array('G:i', 'H:i', 'g:i a', 'h:i A');
252                 $formats  = (array)$RCMAIL->config->get('time_formats', $defaults);
253                 $field_id = 'rcmfd_time_format';
254                 $select   = new html_select(array('name' => '_time_format', 'id' => $field_id));
18b738 255
c6406e 256                 foreach ($formats as $choice) {
AM 257                     $select->add(date($choice, $reftime), $choice);
258                 }
f8e8af 259
c6406e 260                 $blocks['main']['options']['time_format'] = array(
6b2b2e 261                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('timeformat'))),
c6406e 262                     'content' => $select->show($RCMAIL->config->get('time_format')),
AM 263                 );
264             }
3863a9 265
c6406e 266             if (!isset($no_override['date_format'])) {
AM 267                 if (!$current) {
268                     continue 2;
269                 }
3863a9 270
c6406e 271                 $refdate  = mktime(12,30,0,7,24);
AM 272                 $defaults = array('Y-m-d','d-m-Y','Y/m/d','m/d/Y','d/m/Y','d.m.Y','j.n.Y');
273                 $formats  = (array)$RCMAIL->config->get('date_formats', $defaults);
274                 $field_id = 'rcmfd_date_format';
275                 $select   = new html_select(array('name' => '_date_format', 'id' => $field_id));
3863a9 276
c6406e 277                 foreach ($formats as $choice) {
AM 278                     $select->add(date($choice, $refdate), $choice);
279                 }
06c990 280
c6406e 281                 $blocks['main']['options']['date_format'] = array(
6b2b2e 282                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('dateformat'))),
c6406e 283                     'content' => $select->show($config['date_format']),
AM 284                 );
285             }
06c990 286
c6406e 287             // Show checkbox for toggling 'pretty dates'
AM 288             if (!isset($no_override['prettydate'])) {
289                 if (!$current) {
290                     continue 2;
291                 }
f8e8af 292
c6406e 293                 $field_id = 'rcmfd_prettydate';
AM 294                 $input    = new html_checkbox(array('name' => '_pretty_date', 'id' => $field_id, 'value' => 1));
f8e8af 295
c6406e 296                 $blocks['main']['options']['prettydate'] = array(
6b2b2e 297                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('prettydate'))),
c6406e 298                     'content' => $input->show($config['prettydate']?1:0),
AM 299                 );
300             }
49771b 301
c6406e 302             if (!isset($no_override['refresh_interval'])) {
AM 303                 if (!$current) {
304                     continue 2;
305                 }
49771b 306
c6406e 307                 $field_id = 'rcmfd_refresh_interval';
AM 308                 $select   = new html_select(array('name' => '_refresh_interval', 'id' => $field_id));
49771b 309
6b2b2e 310                 $select->add($RCMAIL->gettext('never'), 0);
c6406e 311                 foreach (array(1, 3, 5, 10, 15, 30, 60) as $min) {
AM 312                     if (!$config['min_refresh_interval'] || $config['min_refresh_interval'] <= $min * 60) {
6b2b2e 313                         $label = $RCMAIL->gettext(array('name' => 'everynminutes', 'vars' => array('n' => $min)));
c6406e 314                         $select->add($label, $min);
AM 315                     }
316                 }
f8e8af 317
c6406e 318                 $blocks['main']['options']['refresh_interval'] = array(
6b2b2e 319                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('refreshinterval'))),
c6406e 320                     'content' => $select->show($config['refresh_interval']/60),
AM 321                 );
322             }
bc4960 323
c6406e 324             // show drop-down for available skins
AM 325             if (!isset($no_override['skin'])) {
326                 if (!$current) {
327                     continue 2;
328                 }
bc4960 329
c6406e 330                 $skins = rcmail_get_skins();
bc4960 331
c6406e 332                 if (count($skins) > 1) {
AM 333                     $field_id = 'rcmfd_skin';
334                     $input    = new html_radiobutton(array('name'=>'_skin'));
49771b 335
c6406e 336                     foreach ($skins as $skin) {
681ba6 337                         $thumbnail   = "skins/$skin/thumbnail.png";
c6406e 338                         $skinname    = ucfirst($skin);
AM 339                         $author_link = $license_link = '';
681ba6 340                         $meta        = @json_decode(@file_get_contents(INSTALL_PATH . "skins/$skin/meta.json"), true);
63ab02 341
c6406e 342                         if (is_array($meta) && $meta['name']) {
AM 343                             $skinname     = $meta['name'];
6b2b2e 344                             $author_link  = $meta['url'] ? html::a(array('href' => $meta['url'], 'target' => '_blank'), rcube::Q($meta['author'])) : rcube::Q($meta['author']);
77043f 345                             $license_link = $meta['license-url'] ? html::a(array('href' => $meta['license-url'], 'target' => '_blank', 'tabindex' => '-1'), rcube::Q($meta['license'])) : rcube::Q($meta['license']);
c6406e 346                         }
f8e8af 347
681ba6 348                         $img = html::img(array(
AM 349                                 'src'     => $thumbnail,
350                                 'class'   => 'skinthumbnail',
351                                 'alt'     => $skin,
352                                 'width'   => 64,
353                                 'height'  => 64,
354                                 'onerror' => "this.src = rcmail.assets_path('program/resources/blank.gif')",
355                         ));
356
c75670 357                         $skinnames[] = mb_strtolower($skinname);
c6406e 358                         $blocks['skin']['options'][$skin]['content'] = html::label(array('class' => 'skinselection'),
AM 359                             html::span('skinitem', $input->show($config['skin'], array('value' => $skin, 'id' => $field_id.$skin))) .
681ba6 360                             html::span('skinitem', $img) .
6b2b2e 361                             html::span('skinitem', html::span('skinname', rcube::Q($skinname)) . html::br() .
c6406e 362                                 html::span('skinauthor', $author_link ? 'by ' . $author_link : '') . html::br() .
6b2b2e 363                                 html::span('skinlicense', $license_link ? $RCMAIL->gettext('license').':&nbsp;' . $license_link : ''))
c6406e 364                         );
AM 365                     }
c75670 366                     array_multisort($blocks['skin']['options'], SORT_ASC, SORT_STRING, $skinnames);
c6406e 367                 }
AM 368             }
08ffd9 369
c6406e 370             // standard_windows option decides if new windows should be
AM 371             // opened as popups or standard windows (which can be handled by browsers as tabs)
372             if (!isset($no_override['standard_windows'])) {
373                 if (!$current) {
374                     continue 2;
375                 }
a61cce 376
c6406e 377                 $field_id = 'rcmfd_standard_windows';
AM 378                 $checkbox = new html_checkbox(array('name' => '_standard_windows', 'id' => $field_id, 'value' => 1));
08ffd9 379
c6406e 380                 $blocks['browser']['options']['standard_windows'] = array(
6b2b2e 381                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('standardwindows'))),
c6406e 382                     'content' => $checkbox->show($config['standard_windows']?1:0),
AM 383                 );
384             }
49771b 385
c6406e 386             if ($current) {
AM 387                 $product_name = $RCMAIL->config->get('product_name', 'Roundcube Webmail');
388                 $RCMAIL->output->add_script(sprintf("%s.check_protocol_handler('%s', '#mailtoprotohandler');",
d22157 389                     rcmail_output::JS_OBJECT_NAME, rcube::JQ($product_name)), 'docready');
c6406e 390             }
49771b 391
c6406e 392             $blocks['browser']['options']['mailtoprotohandler'] = array(
AM 393                 'content' => html::a(array(
d22157 394                     'href'    => '#',
TB 395                     'id'      => 'mailtoprotohandler'
396                 ),
397                 rcube::Q($RCMAIL->gettext('mailtoprotohandler'))) .
398                 html::span('mailtoprotohandler-status', ''),
c6406e 399             );
f8e8af 400
3863a9 401         break;
c6406e 402
AM 403         // Mailbox view (mail screen)
404         case 'mailbox':
405             $blocks = array(
6b2b2e 406                 'main'        => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 407                 'new_message' => array('name' => rcube::Q($RCMAIL->gettext('newmessage'))),
408                 'advanced'    => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 409             );
AM 410
411             // show config parameter for preview pane
412             if (!isset($no_override['preview_pane'])) {
413                 if (!$current) {
414                     continue 2;
415                 }
416
417                 $field_id = 'rcmfd_preview';
418                 $input    = new html_checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1,
419                     'onchange' => "$('#rcmfd_preview_pane_mark_read').prop('disabled', !this.checked)"));
420
421                 $blocks['main']['options']['preview_pane'] = array(
6b2b2e 422                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('previewpane'))),
c6406e 423                     'content' => $input->show($config['preview_pane']?1:0),
AM 424                 );
425             }
426
427             // show config parameter for preview pane auto mark as read delay
428             if (!isset($no_override['preview_pane_mark_read'])) {
429                 if (!$current) {
430                     continue 2;
431                 }
432
433                 // apply default if config option is not set at all
434                 $config['preview_pane_mark_read'] = $RCMAIL->config->get('preview_pane_mark_read', 0);
435
436                 $field_id = 'rcmfd_preview_pane_mark_read';
437                 $select   = new html_select(array('name' => '_preview_pane_mark_read', 'id' => $field_id,
438                     'disabled' => $config['preview_pane']?0:1));
439
6b2b2e 440                 $select->add($RCMAIL->gettext('never'), '-1');
AM 441                 $select->add($RCMAIL->gettext('immediately'), 0);
c6406e 442
AM 443                 foreach (array(5, 10, 20, 30) as $sec) {
6b2b2e 444                     $label = $RCMAIL->gettext(array('name' => 'afternseconds', 'vars' => array('n' => $sec)));
c6406e 445                     $select->add($label, $sec);
AM 446                 }
447
448                 $blocks['main']['options']['preview_pane_mark_read'] = array(
6b2b2e 449                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('previewpanemarkread'))),
c6406e 450                     'content' => $select->show(intval($config['preview_pane_mark_read'])),
AM 451                 );
452             }
453
454             if (!isset($no_override['mdn_requests'])) {
455                 if (!$current) {
456                     continue 2;
457                 }
458
459                 $field_id = 'rcmfd_mdn_requests';
460                 $select   = new html_select(array('name' => '_mdn_requests', 'id' => $field_id));
6b2b2e 461                 $select->add($RCMAIL->gettext('askuser'), 0);
AM 462                 $select->add($RCMAIL->gettext('autosend'), 1);
463                 $select->add($RCMAIL->gettext('autosendknown'), 3);
464                 $select->add($RCMAIL->gettext('autosendknownignore'), 4);
61ca79 465                 $select->add($RCMAIL->gettext('ignorerequest'), 2);
c6406e 466
AM 467                 $blocks['main']['options']['mdn_requests'] = array(
6b2b2e 468                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('mdnrequests'))),
c6406e 469                     'content' => $select->show($config['mdn_requests']),
AM 470                 );
471             }
472
473             if (!isset($no_override['autoexpand_threads'])) {
474                 if (!$current) {
475                     continue 2;
476                 }
477
478                 $storage   = $RCMAIL->get_storage();
479                 $supported = $storage->get_capability('THREAD');
480
481                 if ($supported) {
482                     $field_id = 'rcmfd_autoexpand_threads';
483                     $select   = new html_select(array('name' => '_autoexpand_threads', 'id' => $field_id));
6b2b2e 484                     $select->add($RCMAIL->gettext('never'), 0);
AM 485                     $select->add($RCMAIL->gettext('do_expand'), 1);
486                     $select->add($RCMAIL->gettext('expand_only_unread'), 2);
c6406e 487
AM 488                     $blocks['main']['options']['autoexpand_threads'] = array(
6b2b2e 489                         'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('autoexpand_threads'))),
c6406e 490                         'content' => $select->show($config['autoexpand_threads']),
AM 491                     );
492                 }
493             }
494
495             // show page size selection
496             if (!isset($no_override['mail_pagesize'])) {
497                 if (!$current) {
498                     continue 2;
499                 }
500
501                 $field_id = 'rcmfd_mail_pagesize';
502                 $input    = new html_inputfield(array('name' => '_mail_pagesize', 'id' => $field_id, 'size' => 5));
503                 $size     = intval($config['mail_pagesize'] ? $config['mail_pagesize'] : $config['pagesize']);
504
505                 $blocks['main']['options']['pagesize'] = array(
6b2b2e 506                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('pagesize'))),
c6406e 507                     'content' => $input->show($size ? $size : 50),
AM 508                 );
509             }
510
511             if (!isset($no_override['check_all_folders'])) {
512                 if (!$current) {
513                     continue 2;
514                 }
515
516                 $field_id = 'rcmfd_check_all_folders';
517                 $input    = new html_checkbox(array('name' => '_check_all_folders', 'id' => $field_id, 'value' => 1));
518
519                 $blocks['new_message']['options']['check_all_folders'] = array(
6b2b2e 520                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('checkallfolders'))),
c6406e 521                     'content' => $input->show($config['check_all_folders']?1:0),
AM 522                 );
523             }
524         break;
525
526         // Message viewing
527         case 'mailview':
528             $blocks = array(
6b2b2e 529                 'main' => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 530                 'advanced'   => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 531             );
AM 532
533             // show checkbox to open message view in new window
534             if (!isset($no_override['message_extwin'])) {
535                 if (!$current) {
536                     continue 2;
537                 }
538
539                 $field_id = 'rcmfd_message_extwin';
540                 $input    = new html_checkbox(array('name' => '_message_extwin', 'id' => $field_id, 'value' => 1));
541
542                 $blocks['main']['options']['message_extwin'] = array(
6b2b2e 543                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('showinextwin'))),
c6406e 544                     'content' => $input->show($config['message_extwin']?1:0),
AM 545                 );
546             }
547
548             // show checkbox to show email instead of name
549             if (!isset($no_override['message_show_email'])) {
550                 if (!$current) {
551                     continue 2;
552                 }
553
554                 $field_id = 'rcmfd_message_show_email';
555                 $input    = new html_checkbox(array('name' => '_message_show_email', 'id' => $field_id, 'value' => 1));
556
557                 $blocks['main']['options']['message_show_email'] = array(
6b2b2e 558                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('showemail'))),
c6406e 559                     'content' => $input->show($config['message_show_email']?1:0),
AM 560                 );
561             }
562
563             // show checkbox for HTML/plaintext messages
564             if (!isset($no_override['prefer_html'])) {
565                 if (!$current) {
566                     continue 2;
567                 }
568
569                 $field_id = 'rcmfd_htmlmsg';
570                 $input    = new html_checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1,
571                     'onchange' => "$('#rcmfd_show_images').prop('disabled', !this.checked).val(0)"));
572
573                 $blocks['main']['options']['prefer_html'] = array(
6b2b2e 574                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('preferhtml'))),
c6406e 575                     'content' => $input->show($config['prefer_html']?1:0),
AM 576                 );
577             }
578
579             if (!isset($no_override['default_charset'])) {
580                 if (!$current) {
581                     continue 2;
582                 }
583
584                 $field_id = 'rcmfd_default_charset';
585
7be8a9 586                 $blocks['advanced']['options']['default_charset'] = array(
6b2b2e 587                     'title' => html::label($field_id, rcube::Q($RCMAIL->gettext('defaultcharset'))),
c6406e 588                     'content' => $RCMAIL->output->charset_selector(array(
7d7d14 589                         'id' => $field_id, 'name' => '_default_charset', 'selected' => $config['default_charset']
c6406e 590                 )));
AM 591             }
592
593             if (!isset($no_override['show_images'])) {
594                 if (!$current) {
595                     continue 2;
596                 }
597
598                 $field_id = 'rcmfd_show_images';
599                 $input    = new html_select(array('name' => '_show_images', 'id' => $field_id,
600                     'disabled' => !$config['prefer_html']));
601
6b2b2e 602                 $input->add($RCMAIL->gettext('never'), 0);
AM 603                 $input->add($RCMAIL->gettext('fromknownsenders'), 1);
604                 $input->add($RCMAIL->gettext('always'), 2);
c6406e 605
AM 606                 $blocks['main']['options']['show_images'] = array(
6b2b2e 607                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('showremoteimages'))),
c6406e 608                     'content' => $input->show($config['prefer_html'] ? $config['show_images'] : 0),
AM 609                 );
610             }
611
612             if (!isset($no_override['inline_images'])) {
613                 if (!$current) {
614                     continue 2;
615                 }
616
617                 $field_id = 'rcmfd_inline_images';
618                 $input    = new html_checkbox(array('name' => '_inline_images', 'id' => $field_id, 'value' => 1));
619
620                 $blocks['main']['options']['inline_images'] = array(
6b2b2e 621                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('showinlineimages'))),
c6406e 622                     'content' => $input->show($config['inline_images']?1:0),
AM 623                 );
624             }
625
626             // "display after delete" checkbox
627             if (!isset($no_override['display_next'])) {
628                 if (!$current) {
629                     continue 2;
630                 }
631
632                 $field_id = 'rcmfd_displaynext';
633                 $input    = new html_checkbox(array('name' => '_display_next', 'id' => $field_id, 'value' => 1));
634
635                 $blocks['main']['options']['display_next'] = array(
6b2b2e 636                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('displaynext'))),
c6406e 637                     'content' => $input->show($config['display_next']?1:0),
AM 638                 );
639             }
640         break;
641
642         // Mail composition
643         case 'compose':
644             $blocks = array(
6b2b2e 645                 'main'       => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 646                 'sig'        => array('name' => rcube::Q($RCMAIL->gettext('signatureoptions'))),
647                 'spellcheck' => array('name' => rcube::Q($RCMAIL->gettext('spellcheckoptions'))),
648                 'advanced'   => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 649             );
AM 650
651             // show checkbox to compose messages in a new window
652             if (!isset($no_override['compose_extwin'])) {
653                 if (!$current) {
654                     continue 2;
655                 }
656
657                 $field_id = 'rcmfdcompose_extwin';
658                 $input    = new html_checkbox(array('name' => '_compose_extwin', 'id' => $field_id, 'value' => 1));
659
660                 $blocks['main']['options']['compose_extwin'] = array(
6b2b2e 661                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('composeextwin'))),
c6406e 662                     'content' => $input->show($config['compose_extwin']?1:0),
AM 663                 );
664             }
665
666             if (!isset($no_override['htmleditor'])) {
667                 if (!$current) {
668                     continue 2;
669                 }
670
671                 $field_id = 'rcmfd_htmleditor';
672                 $select   = new html_select(array('name' => '_htmleditor', 'id' => $field_id));
673
6b2b2e 674                 $select->add($RCMAIL->gettext('never'), 0);
AM 675                 $select->add($RCMAIL->gettext('always'), 1);
676                 $select->add($RCMAIL->gettext('htmlonreply'), 2);
677                 $select->add($RCMAIL->gettext('htmlonreplyandforward'), 3);
c6406e 678
AM 679                 $blocks['main']['options']['htmleditor'] = array(
6b2b2e 680                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('htmleditor'))),
c6406e 681                     'content' => $select->show(intval($config['htmleditor'])),
AM 682                 );
683             }
684
685             if (!isset($no_override['draft_autosave'])) {
686                 if (!$current) {
687                     continue 2;
688                 }
689
690                 $field_id = 'rcmfd_autosave';
691                 $select   = new html_select(array('name' => '_draft_autosave', 'id' => $field_id, 'disabled' => empty($config['drafts_mbox'])));
692
6b2b2e 693                 $select->add($RCMAIL->gettext('never'), 0);
c6406e 694                 foreach (array(1, 3, 5, 10) as $i => $min) {
6b2b2e 695                     $label = $RCMAIL->gettext(array('name' => 'everynminutes', 'vars' => array('n' => $min)));
c6406e 696                     $select->add($label, $min*60);
AM 697                 }
698
699                 $blocks['main']['options']['draft_autosave'] = array(
6b2b2e 700                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('autosavedraft'))),
c6406e 701                     'content' => $select->show($config['draft_autosave']),
AM 702                 );
703             }
704
705             if (!isset($no_override['mime_param_folding'])) {
706                 if (!$current) {
707                     continue 2;
708                 }
709
710                 $field_id = 'rcmfd_param_folding';
711                 $select   = new html_select(array('name' => '_mime_param_folding', 'id' => $field_id));
712
6b2b2e 713                 $select->add($RCMAIL->gettext('2231folding'), 0);
AM 714                 $select->add($RCMAIL->gettext('miscfolding'), 1);
715                 $select->add($RCMAIL->gettext('2047folding'), 2);
c6406e 716
7be8a9 717                 $blocks['advanced']['options']['mime_param_folding'] = array(
6b2b2e 718                     'title'    => html::label($field_id, rcube::Q($RCMAIL->gettext('mimeparamfolding'))),
c6406e 719                     'content'  => $select->show($config['mime_param_folding']),
AM 720                 );
721             }
722
723             if (!isset($no_override['force_7bit'])) {
724                 if (!$current) {
725                     continue 2;
726                 }
727
728                 $field_id = 'rcmfd_force_7bit';
729                 $input    = new html_checkbox(array('name' => '_force_7bit', 'id' => $field_id, 'value' => 1));
730
7be8a9 731                 $blocks['advanced']['options']['force_7bit'] = array(
6b2b2e 732                     'title'    => html::label($field_id, rcube::Q($RCMAIL->gettext('force7bit'))),
c6406e 733                     'content'  => $input->show($config['force_7bit']?1:0),
AM 734                 );
735             }
736
737             if (!isset($no_override['mdn_default'])) {
738                 if (!$current) {
739                     continue 2;
740                 }
741
742                 $field_id = 'rcmfd_mdn_default';
743                 $input    = new html_checkbox(array('name' => '_mdn_default', 'id' => $field_id, 'value' => 1));
744
745                 $blocks['main']['options']['mdn_default'] = array(
6b2b2e 746                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('reqmdn'))),
c6406e 747                     'content' => $input->show($config['mdn_default']?1:0),
AM 748                 );
749             }
750
b01689 751             if (!isset($no_override['dsn_default']) && $RCMAIL->config->get('smtp_server')) {
c6406e 752                 if (!$current) {
AM 753                     continue 2;
754                 }
755
756                 $field_id = 'rcmfd_dsn_default';
757                 $input    = new html_checkbox(array('name' => '_dsn_default', 'id' => $field_id, 'value' => 1));
758
759                 $blocks['main']['options']['dsn_default'] = array(
6b2b2e 760                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('reqdsn'))),
c6406e 761                     'content' => $input->show($config['dsn_default']?1:0),
AM 762                 );
763             }
764
765             if (!isset($no_override['reply_same_folder'])) {
766                 if (!$current) {
767                     continue 2;
768                 }
769
770                 $field_id = 'rcmfd_reply_same_folder';
771                 $input    = new html_checkbox(array('name' => '_reply_same_folder', 'id' => $field_id, 'value' => 1));
772
773                 $blocks['main']['options']['reply_same_folder'] = array(
6b2b2e 774                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('replysamefolder'))),
c6406e 775                     'content' => $input->show($config['reply_same_folder']?1:0),
AM 776                 );
777             }
778
779             if (!isset($no_override['reply_mode'])) {
780                 if (!$current) {
781                     continue 2;
782                 }
783
784                 $field_id = 'rcmfd_reply_mode';
785                 $select   = new html_select(array('name' => '_reply_mode', 'id' => $field_id));
786
6b2b2e 787                 $select->add($RCMAIL->gettext('replyempty'), -1);
AM 788                 $select->add($RCMAIL->gettext('replybottomposting'), 0);
789                 $select->add($RCMAIL->gettext('replytopposting'), 1);
c6406e 790
AM 791                 $blocks['main']['options']['reply_mode'] = array(
6b2b2e 792                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('whenreplying'))),
c6406e 793                     'content' => $select->show(intval($config['reply_mode'])),
AM 794                 );
795             }
796
797             if (!isset($no_override['spellcheck_before_send']) && $config['enable_spellcheck']) {
798                 if (!$current) {
799                     continue 2;
800                 }
801
802                 $field_id = 'rcmfd_spellcheck_before_send';
803                 $input    = new html_checkbox(array('name' => '_spellcheck_before_send', 'id' => $field_id, 'value' => 1));
804
805                 $blocks['spellcheck']['options']['spellcheck_before_send'] = array(
6b2b2e 806                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('spellcheckbeforesend'))),
c6406e 807                     'content' => $input->show($config['spellcheck_before_send']?1:0),
AM 808                 );
809             }
810
811             if ($config['enable_spellcheck']) {
812                 if (!$current) {
813                     continue 2;
814                 }
815
816                 foreach (array('syms', 'nums', 'caps') as $key) {
817                     $key = 'spellcheck_ignore_'.$key;
818                     if (!isset($no_override[$key])) {
819                         $input = new html_checkbox(array('name' => '_'.$key, 'id' => 'rcmfd_'.$key, 'value' => 1));
820
821                         $blocks['spellcheck']['options'][$key] = array(
6b2b2e 822                             'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext(str_replace('_', '', $key)))),
c6406e 823                             'content' => $input->show($config[$key]?1:0),
AM 824                         );
825                     }
826                 }
827             }
828
829             if (!isset($no_override['show_sig'])) {
830                 if (!$current) {
831                     continue 2;
832                 }
833
834                 $field_id = 'rcmfd_show_sig';
835                 $select   = new html_select(array('name' => '_show_sig', 'id' => $field_id));
836
6b2b2e 837                 $select->add($RCMAIL->gettext('never'), 0);
AM 838                 $select->add($RCMAIL->gettext('always'), 1);
839                 $select->add($RCMAIL->gettext('newmessageonly'), 2);
840                 $select->add($RCMAIL->gettext('replyandforwardonly'), 3);
c6406e 841
AM 842                 $blocks['sig']['options']['show_sig'] = array(
6b2b2e 843                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('autoaddsignature'))),
c6406e 844                     'content' => $select->show($RCMAIL->config->get('show_sig', 1)),
AM 845                 );
846             }
847
ef595a 848             if (!isset($no_override['sig_below'])) {
AM 849                 if (!$current) {
850                     continue 2;
851                 }
852
853                 $field_id = 'rcmfd_sig_below';
854                 $input    = new html_checkbox(array('name' => '_sig_below', 'id' => $field_id, 'value' => 1));
855
856                 $blocks['sig']['options']['sig_below'] = array(
857                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('sigbelow'))),
858                     'content' => $input->show($RCMAIL->config->get('sig_below') ? 1 : 0),
859                 );
860             }
861
c6406e 862             if (!isset($no_override['strip_existing_sig'])) {
AM 863                 if (!$current) {
864                     continue 2;
865                 }
866
867                 $field_id = 'rcmfd_strip_existing_sig';
868                 $input    = new html_checkbox(array('name' => '_strip_existing_sig', 'id' => $field_id, 'value' => 1));
869
870                 $blocks['sig']['options']['strip_existing_sig'] = array(
6b2b2e 871                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('replyremovesignature'))),
c6406e 872                     'content' => $input->show($config['strip_existing_sig']?1:0),
AM 873                 );
874             }
875
876             if (!isset($no_override['forward_attachment'])) {
877                 if (!$current) {
878                     continue 2;
879                 }
880
881                 $field_id = 'rcmfd_forward_attachment';
882                 $select = new html_select(array('name' => '_forward_attachment', 'id' => $field_id));
883
6b2b2e 884                 $select->add($RCMAIL->gettext('inline'), 0);
AM 885                 $select->add($RCMAIL->gettext('asattachment'), 1);
c6406e 886
AM 887                 $blocks['main']['options']['forward_attachment'] = array(
6b2b2e 888                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('forwardmode'))),
c6406e 889                     'content' => $select->show(intval($config['forward_attachment'])),
AM 890                 );
891             }
892
f7b2bf 893             if (!isset($no_override['default_font']) || !isset($no_override['default_font_size'])) {
c6406e 894                 if (!$current) {
AM 895                     continue 2;
896                 }
897
d8d569 898                 // Default font size
D 899                 $field_id = 'rcmfd_default_font_size';
900                 $select_default_font_size = new html_select(array('name' => '_default_font_size', 'id' => $field_id));
c6406e 901
f7b2bf 902                 $fontsizes = array('', '8pt', '10pt', '12pt', '14pt', '18pt', '24pt', '36pt');
d8d569 903                 foreach ($fontsizes as $size) {
D 904                     $select_default_font_size->add($size, $size);
c6406e 905                 }
AM 906
d8d569 907                 // Default font
D 908                 $field_id = 'rcmfd_default_font';
909                 $select_default_font = new html_select(array('name' => '_default_font', 'id' => $field_id));
f7b2bf 910                 $select_default_font->add('', '');
c6406e 911
6b2b2e 912                 $fonts = rcmail::font_defs();
07a641 913                 foreach (array_keys($fonts) as $fname) {
d8d569 914                     $select_default_font->add($fname, $fname);
D 915                 }
c6406e 916
AM 917                 $blocks['main']['options']['default_font'] = array(
6b2b2e 918                     'title' => html::label($field_id, rcube::Q($RCMAIL->gettext('defaultfont'))),
c1ff57 919                     'content' => $select_default_font->show($RCMAIL->config->get('default_font', 1)) .
TB 920                         $select_default_font_size->show($RCMAIL->config->get('default_font_size', 1))
c6406e 921                 );
AM 922             }
b972b4 923
AM 924             if (!isset($no_override['reply_all_mode'])) {
925                 if (!$current) {
926                     continue 2;
927                 }
928
929                 $field_id = 'rcmfd_reply_all_mode';
930                 $select   = new html_select(array('name' => '_reply_all_mode', 'id' => $field_id));
931
6b2b2e 932                 $select->add($RCMAIL->gettext('replyalldefault'), 0);
AM 933                 $select->add($RCMAIL->gettext('replyalllist'), 1);
b972b4 934
AM 935                 $blocks['main']['options']['reply_all_mode'] = array(
6b2b2e 936                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('replyallmode'))),
b972b4 937                     'content' => $select->show(intval($config['reply_all_mode'])),
AM 938                 );
939             }
940
44b47d 941             if (!isset($no_override['compose_save_localstorage'])) {
TB 942                 if (!$current) {
943                     continue 2;
944                 }
945
946                 $field_id = 'rcmfd_compose_save_localstorage';
947                 $input    = new html_checkbox(array('name' => '_compose_save_localstorage', 'id' => $field_id, 'value' => 1));
948
949                 $blocks['advanced']['options']['compose_save_localstorage'] = array(
950                     'title'    => html::label($field_id, rcube::Q($RCMAIL->gettext('savelocalstorage'))),
951                     'content'  => $input->show($config['compose_save_localstorage']?1:0),
952                 );
953             }
954
c6406e 955         break;
AM 956
957         // Addressbook config
958         case 'addressbook':
959             $blocks = array(
6b2b2e 960                 'main'     => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 961                 'advanced' => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 962             );
AM 963
964             if (!isset($no_override['default_addressbook'])
965                 && (!$current || ($books = $RCMAIL->get_address_sources(true, true)))
966             ) {
967                 if (!$current) {
968                     continue 2;
969                 }
970
971                 $field_id = 'rcmfd_default_addressbook';
972                 $select   = new html_select(array('name' => '_default_addressbook', 'id' => $field_id));
973
974                 foreach ($books as $book) {
975                     $select->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']);
976                 }
977
978                 $blocks['main']['options']['default_addressbook'] = array(
6b2b2e 979                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('defaultabook'))),
c6406e 980                     'content' => $select->show($config['default_addressbook']),
AM 981                 );
982             }
983
984             // show addressbook listing mode selection
985             if (!isset($no_override['addressbook_name_listing'])) {
986                 if (!$current) {
987                     continue 2;
988                 }
989
990                 $field_id = 'rcmfd_addressbook_name_listing';
991                 $select   = new html_select(array('name' => '_addressbook_name_listing', 'id' => $field_id));
992
6b2b2e 993                 $select->add($RCMAIL->gettext('name'), 0);
AM 994                 $select->add($RCMAIL->gettext('firstname') . ' '  . $RCMAIL->gettext('surname'), 1);
995                 $select->add($RCMAIL->gettext('surname')   . ' '  . $RCMAIL->gettext('firstname'), 2);
996                 $select->add($RCMAIL->gettext('surname')   . ', ' . $RCMAIL->gettext('firstname'), 3);
c6406e 997
AM 998                 $blocks['main']['options']['list_name_listing'] = array(
6b2b2e 999                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('listnamedisplay'))),
c6406e 1000                     'content' => $select->show($config['addressbook_name_listing']),
AM 1001                 );
1002             }
1003
1004             // show addressbook sort column
1005             if (!isset($no_override['addressbook_sort_col'])) {
1006                 if (!$current) {
1007                     continue 2;
1008                 }
1009
1010                 $field_id = 'rcmfd_addressbook_sort_col';
1011                 $select   = new html_select(array('name' => '_addressbook_sort_col', 'id' => $field_id));
1012
6b2b2e 1013                 $select->add($RCMAIL->gettext('name'), 'name');
AM 1014                 $select->add($RCMAIL->gettext('firstname'), 'firstname');
1015                 $select->add($RCMAIL->gettext('surname'), 'surname');
c6406e 1016
AM 1017                 $blocks['main']['options']['sort_col'] = array(
6b2b2e 1018                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('listsorting'))),
c6406e 1019                     'content' => $select->show($config['addressbook_sort_col']),
AM 1020                 );
1021             }
1022
1023             // show addressbook page size selection
1024             if (!isset($no_override['addressbook_pagesize'])) {
1025                 if (!$current) {
1026                     continue 2;
1027                 }
1028
1029                 $field_id = 'rcmfd_addressbook_pagesize';
1030                 $input    = new html_inputfield(array('name' => '_addressbook_pagesize', 'id' => $field_id, 'size' => 5));
1031                 $size     = intval($config['addressbook_pagesize'] ? $config['addressbook_pagesize'] : $config['pagesize']);
1032
1033                 $blocks['main']['options']['pagesize'] = array(
6b2b2e 1034                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('pagesize'))),
c6406e 1035                     'content' => $input->show($size ? $size : 50),
AM 1036                 );
1037             }
1038
1039             if (!isset($no_override['autocomplete_single'])) {
1040                 if (!$current) {
1041                     continue 2;
1042                 }
1043
1044                 $field_id = 'rcmfd_autocomplete_single';
1045                 $checkbox = new html_checkbox(array('name' => '_autocomplete_single', 'id' => $field_id, 'value' => 1));
1046
1047                 $blocks['main']['options']['autocomplete_single'] = array(
6b2b2e 1048                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('autocompletesingle'))),
c6406e 1049                     'content' => $checkbox->show($config['autocomplete_single']?1:0),
AM 1050                 );
1051             }
1052         break;
1053
1054         // Special IMAP folders
1055         case 'folders':
1056             $blocks = array(
6b2b2e 1057                 'main'     => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 1058                 'advanced' => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 1059             );
AM 1060
1061             if (!isset($no_override['show_real_foldernames'])) {
1062                 if (!$current) {
1063                     continue 2;
1064                 }
1065
1066                 $field_id = 'show_real_foldernames';
1067                 $input    = new html_checkbox(array('name' => '_show_real_foldernames', 'id' => $field_id, 'value' => 1));
1068
1069                 $blocks['main']['options']['show_real_foldernames'] = array(
6b2b2e 1070                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('show_real_foldernames'))),
c6406e 1071                     'content' => $input->show($config['show_real_foldernames']?1:0),
AM 1072                 );
1073             }
1074
1075             // Configure special folders
dc0b50 1076             $set = array('drafts_mbox', 'sent_mbox', 'junk_mbox', 'trash_mbox');
AM 1077             if ($current && count(array_intersect($no_override, $set)) < 4) {
6b2b2e 1078                 $select = $RCMAIL->folder_selector(array(
c6406e 1079                     'noselection'   => '---',
AM 1080                     'realnames'     => true,
1081                     'maxlength'     => 30,
1082                     'folder_filter' => 'mail',
1083                     'folder_rights' => 'w',
1084                 ));
0c2ffb 1085
dc0b50 1086                 // #1486114, #1488279, #1489219
AM 1087                 $onchange = "if ($(this).val() == 'INBOX') $(this).val('')";
1088             }
c6406e 1089
AM 1090             if (!isset($no_override['drafts_mbox'])) {
1091                 if (!$current) {
1092                     continue 2;
1093                 }
1094
1095                 $blocks['main']['options']['drafts_mbox'] = array(
6b2b2e 1096                     'title'   => rcube::Q($RCMAIL->gettext('drafts')),
0c2ffb 1097                     'content' => $select->show($config['drafts_mbox'], array('name' => "_drafts_mbox", 'onchange' => $onchange)),
c6406e 1098                 );
AM 1099             }
1100
1101             if (!isset($no_override['sent_mbox'])) {
1102                 if (!$current) {
1103                     continue 2;
1104                 }
1105
1106                 $blocks['main']['options']['sent_mbox'] = array(
6b2b2e 1107                     'title'   => rcube::Q($RCMAIL->gettext('sent')),
0c2ffb 1108                     'content' => $select->show($config['sent_mbox'], array('name' => "_sent_mbox", 'onchange' => '')),
c6406e 1109                 );
AM 1110             }
1111
1112             if (!isset($no_override['junk_mbox'])) {
1113                 if (!$current) {
1114                     continue 2;
1115                 }
1116
1117                 $blocks['main']['options']['junk_mbox'] = array(
6b2b2e 1118                     'title'   => rcube::Q($RCMAIL->gettext('junk')),
0c2ffb 1119                     'content' => $select->show($config['junk_mbox'], array('name' => "_junk_mbox", 'onchange' => $onchange)),
c6406e 1120                 );
AM 1121             }
1122
1123             if (!isset($no_override['trash_mbox'])) {
1124                 if (!$current) {
1125                     continue 2;
1126                 }
1127
1128                 $blocks['main']['options']['trash_mbox'] = array(
6b2b2e 1129                     'title'   => rcube::Q($RCMAIL->gettext('trash')),
0c2ffb 1130                     'content' => $select->show($config['trash_mbox'], array('name' => "_trash_mbox", 'onchange' => $onchange)),
c6406e 1131                 );
AM 1132             }
1133         break;
1134
1135         // Server settings
1136         case 'server':
1137             $blocks = array(
6b2b2e 1138                 'main'        => array('name' => rcube::Q($RCMAIL->gettext('mainoptions'))),
AM 1139                 'maintenance' => array('name' => rcube::Q($RCMAIL->gettext('maintenance'))),
1140                 'advanced'    => array('name' => rcube::Q($RCMAIL->gettext('advancedoptions'))),
c6406e 1141             );
AM 1142
1143             if (!isset($no_override['read_when_deleted'])) {
1144                 if (!$current) {
1145                     continue 2;
1146                 }
1147
1148                 $field_id = 'rcmfd_read_deleted';
1149                 $input    = new html_checkbox(array('name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1));
1150
1151                 $blocks['main']['options']['read_when_deleted'] = array(
6b2b2e 1152                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('readwhendeleted'))),
c6406e 1153                     'content' => $input->show($config['read_when_deleted']?1:0),
AM 1154                 );
1155             }
1156
1157             if (!isset($no_override['flag_for_deletion'])) {
1158                 if (!$current) {
1159                     continue 2;
1160                 }
1161
1162                 $field_id = 'rcmfd_flag_for_deletion';
1163                 $input    = new html_checkbox(array('name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1));
1164
1165                 $blocks['main']['options']['flag_for_deletion'] = array(
6b2b2e 1166                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('flagfordeletion'))),
c6406e 1167                     'content' => $input->show($config['flag_for_deletion']?1:0),
AM 1168                 );
1169             }
1170
1171             // don't show deleted messages
1172             if (!isset($no_override['skip_deleted'])) {
1173                 if (!$current) {
1174                     continue 2;
1175                 }
1176
1177                 $field_id = 'rcmfd_skip_deleted';
1178                 $input    = new html_checkbox(array('name' => '_skip_deleted', 'id' => $field_id, 'value' => 1));
1179
1180                 $blocks['main']['options']['skip_deleted'] = array(
6b2b2e 1181                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('skipdeleted'))),
c6406e 1182                     'content' => $input->show($config['skip_deleted']?1:0),
AM 1183                 );
1184             }
1185
1186             if (!isset($no_override['delete_always'])) {
1187                 if (!$current) {
1188                     continue 2;
1189                 }
1190
1191                 $field_id = 'rcmfd_delete_always';
1192                 $input    = new html_checkbox(array('name' => '_delete_always', 'id' => $field_id, 'value' => 1));
1193
1194                 $blocks['main']['options']['delete_always'] = array(
6b2b2e 1195                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('deletealways'))),
c6406e 1196                     'content' => $input->show($config['delete_always']?1:0),
AM 1197                 );
1198             }
1199
1200             if (!isset($no_override['delete_junk'])) {
1201                 if (!$current) {
1202                     continue 2;
1203                 }
1204
1205                 $field_id = 'rcmfd_delete_junk';
1206                 $input    = new html_checkbox(array('name' => '_delete_junk', 'id' => $field_id, 'value' => 1));
1207
1208                 $blocks['main']['options']['delete_junk'] = array(
6b2b2e 1209                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('deletejunk'))),
c6406e 1210                     'content' => $input->show($config['delete_junk']?1:0),
AM 1211                 );
1212             }
1213
1214             // Trash purging on logout
1215             if (!isset($no_override['logout_purge'])) {
1216                 if (!$current) {
1217                     continue 2;
1218                 }
1219
1220                 $field_id = 'rcmfd_logout_purge';
1221                 $input    = new html_checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
1222
1223                 $blocks['maintenance']['options']['logout_purge'] = array(
6b2b2e 1224                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('logoutclear'))),
c6406e 1225                     'content' => $input->show($config['logout_purge']?1:0),
AM 1226                 );
1227             }
1228
1229             // INBOX compacting on logout
1230             if (!isset($no_override['logout_expunge'])) {
1231                 if (!$current) {
1232                     continue 2;
1233                 }
1234
1235                 $field_id = 'rcmfd_logout_expunge';
1236                 $input    = new html_checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
1237
1238                 $blocks['maintenance']['options']['logout_expunge'] = array(
6b2b2e 1239                     'title'   => html::label($field_id, rcube::Q($RCMAIL->gettext('logoutcompact'))),
c6406e 1240                     'content' => $input->show($config['logout_expunge']?1:0),
AM 1241                 );
1242             }
1243         }
1244
1245         $found = false;
1246         $data  = $RCMAIL->plugins->exec_hook('preferences_list',
1247             array('section' => $sect['id'], 'blocks' => $blocks, 'current' => $current));
1248
ee43f0 1249         $advanced_prefs = (array) $RCMAIL->config->get('advanced_prefs');
4a05e8 1250
c6406e 1251         // create output
4a05e8 1252         foreach ($data['blocks'] as $key => $block) {
c6406e 1253             if (!empty($block['content']) || !empty($block['options'])) {
AM 1254                 $found = true;
4a05e8 1255             }
TB 1256             // move some options to the 'advanced' block as configured by admin
1257             if ($key != 'advanced') {
1258                 foreach ($advanced_prefs as $opt) {
1259                     if ($block['options'][$opt]) {
1260                         $data['blocks']['advanced']['options'][$opt] = $block['options'][$opt];
1261                         unset($data['blocks'][$key]['options'][$opt]);
1262                     }
1263                 }
c6406e 1264             }
AM 1265         }
1266
f9c8e8 1267         // move 'advanced' block to the end of the list
TB 1268         if (!empty($data['blocks']['advanced'])) {
1269             $adv = $data['blocks']['advanced'];
1270             unset($data['blocks']['advanced']);
1271             $data['blocks']['advanced'] = $adv;
1272         }
1273
c6406e 1274         if (!$found)
AM 1275             unset($sections[$idx]);
1276         else
1277             $sections[$idx]['blocks'] = $data['blocks'];
49771b 1278     }
A 1279
dba1c6 1280     $data = $RCMAIL->plugins->exec_hook('preferences_section_header',
C 1281         array('section' => $sect['id'], 'header' => '', 'current' => $current));
1282
1283     if(!empty($data['header'])) {
1284         $sections[$idx]['header'] = $data['header'];
1285     }
1286
c6406e 1287     return array($sections, $plugin['cols']);
49771b 1288 }
A 1289
1290
1291 function rcmail_get_skins()
1292 {
b7addf 1293     $path  = RCUBE_INSTALL_PATH . 'skins';
c6406e 1294     $skins = array();
AM 1295     $dir   = opendir($path);
49771b 1296
c6406e 1297     if (!$dir) {
AM 1298         return false;
1299     }
f8e8af 1300
c6406e 1301     while (($file = readdir($dir)) !== false) {
AM 1302         $filename = $path.'/'.$file;
1303         if (!preg_match('/^\./', $file) && is_dir($filename) && is_readable($filename)) {
1304             $skins[] = $file;
1305         }
1306     }
f8e8af 1307
c6406e 1308     closedir($dir);
49771b 1309
c6406e 1310     return $skins;
49771b 1311 }
A 1312
bbce3e 1313
254d5e 1314 function rcmail_folder_options($mailbox)
bbce3e 1315 {
A 1316     global $RCMAIL;
1317
c321a9 1318     $options = $RCMAIL->get_storage()->folder_info($mailbox);
67975b 1319     $options['protected'] = $options['is_root'] || ($options['special'] && $RCMAIL->config->get('protect_default_folders'));
bbce3e 1320
1a0343 1321     return $options;
bbce3e 1322 }
A 1323
1a0343 1324 /**
A 1325  * Updates (or creates) folder row in the subscriptions table
1326  *
1327  * @param string $name      Folder name
1328  * @param string $oldname   Old folder name (for update)
1329  * @param bool   $subscribe Checks subscription checkbox
1330  * @param string $class     CSS class name for folder row
1331  */
1332 function rcmail_update_folder_row($name, $oldname=null, $subscribe=false, $class_name=null)
254d5e 1333 {
63ff2a 1334     global $RCMAIL, $OUTPUT;
A 1335
1336     $protect_folders = $RCMAIL->config->get('protect_default_folders');
dc0b50 1337     $storage         = $RCMAIL->get_storage();
AM 1338     $delimiter       = $storage->get_hierarchy_delimiter();
254d5e 1339
3cb61e 1340     $name_utf8    = rcube_charset::convert($name, 'UTF7-IMAP');
AM 1341     $protected    = $protect_folders && $storage->is_special_folder($name);
c321a9 1342     $foldersplit  = explode($delimiter, $storage->mod_folder($name));
254d5e 1343     $level        = count($foldersplit) - 1;
3cb61e 1344     $display_name = $protected ? $RCMAIL->localize_foldername($name) : rcube_charset::convert($foldersplit[$level], 'UTF7-IMAP');
AM 1345     $class_name   = trim($class_name . ' mailbox');
c6447e 1346
d575e4 1347     if ($oldname === null) {
3cb61e 1348         $OUTPUT->command('add_folder_row', $name, $name_utf8, $display_name, $protected, $subscribe,
AM 1349             $class_name);
d575e4 1350     }
AM 1351     else {
3cb61e 1352         $OUTPUT->command('replace_folder_row', $oldname, $name, $name_utf8, $display_name, $protected, $class_name);
d575e4 1353     }
254d5e 1354 }
A 1355
c49c35 1356 /**
TB 1357  * Render the list of settings sections (AKA tabs)
1358  */
1359 function rcmail_settings_tabs($attrib)
1360 {
1361     global $RCMAIL, $OUTPUT;
1362
1363     // add default attributes
1364     $attrib += array('tagname' => 'span', 'idprefix' => 'settingstab', 'selclass' => 'selected');
1365
1366     $default_actions = array(
1367         array('command' => 'preferences', 'type' => 'link', 'label' => 'preferences', 'title' => 'editpreferences'),
1368         array('command' => 'folders',     'type' => 'link', 'label' => 'folders',     'title' => 'managefolders'),
1369         array('command' => 'identities',  'type' => 'link', 'label' => 'identities',  'title' => 'manageidentities'),
1e22cb 1370         array('command' => 'responses',   'type' => 'link', 'label' => 'responses',   'title' => 'manageresponses'),
c49c35 1371     );
TB 1372
1373     // get all identites from DB and define list of cols to be displayed
1374     $plugin = $RCMAIL->plugins->exec_hook('settings_actions', array(
1375         'actions' => $default_actions,
d575e4 1376         'attrib'  => $attrib,
c49c35 1377     ));
TB 1378
d575e4 1379     $attrib  = $plugin['attrib'];
c49c35 1380     $tagname = $attrib['tagname'];
d575e4 1381     $tabs    = array();
c49c35 1382
07a641 1383     foreach ($plugin['actions'] as $action) {
c49c35 1384         if (!$action['command'] && !$action['href'] && $action['action']) {
TB 1385             $action['href'] = $RCMAIL->url(array('_action' => $action['action']));
1386         }
1387
1388         $button = $OUTPUT->button($action);
d575e4 1389         $attr   = $attrib;
c49c35 1390
TB 1391         $cmd = $action['action'] ? $action['action'] : $action['command'];
d575e4 1392         $id  = $action['id'] ? $action['id'] : $cmd;
AM 1393
c49c35 1394         if (!empty($id)) {
TB 1395             $attr['id'] = preg_replace('/[^a-z0-9]/i', '', $attrib['idprefix'] . $id);
1396         }
d575e4 1397
c49c35 1398         $classnames = array($attrib['class']);
TB 1399         if (!empty($action['class'])) {
1400             $classnames[] = $action['class'];
1401         }
1402         else if (!empty($cmd)) {
1403             $classnames[] = $cmd;
1404         }
1405         if ($RCMAIL->action == $cmd) {
1406             $classnames[] = $attrib['selclass'];
1407         }
d575e4 1408
c49c35 1409         $attr['class'] = join(' ', $classnames);
TB 1410         $tabs[] = html::tag($tagname, $attr, $button, html::$common_attrib);
1411     }
1412
1413     return join('', $tabs);
1414 }