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