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