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