David Carter
2013-05-29 52deb18d9646116114f9649c87ffc4f0bc378db1
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                     |
438753 8  | Copyright (C) 2005-2012, 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
681969 22 if (!$OUTPUT->ajax_call)
A 23   $OUTPUT->set_pagetitle(rcube_label('preferences'));
4e17e6 24
b19097 25
f05834 26 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
A 27 function rcmail_preferences_frame($attrib)
d11fb2 28 {
f05834 29   global $OUTPUT;
cb3538 30
f05834 31   if (!$attrib['id'])
A 32     $attrib['id'] = 'rcmprefsframe';
35c31e 33
28de39 34   return $OUTPUT->frame($attrib, true);
d11fb2 35 }
f05834 36
A 37
38 function rcmail_sections_list($attrib)
d11fb2 39 {
49771b 40   global $RCMAIL;
f8e8af 41
f05834 42   // add id to message list table if not specified
A 43   if (!strlen($attrib['id']))
44     $attrib['id'] = 'rcmsectionslist';
45
49771b 46   list($list, $cols) = rcmail_user_prefs();
f8e8af 47
f05834 48   // create XHTML table
49771b 49   $out = rcube_table_output($attrib, $list, $cols, 'id');
f05834 50
A 51   // set client env
52   $RCMAIL->output->add_gui_object('sectionslist', $attrib['id']);
53   $RCMAIL->output->include_script('list.js');
54
35c31e 55   return $out;
d11fb2 56 }
4e17e6 57
T 58
59 function rcmail_identities_list($attrib)
d11fb2 60 {
a90ad2 61   global $OUTPUT, $RCMAIL;
4e17e6 62
T 63   // add id to message list table if not specified
64   if (!strlen($attrib['id']))
65     $attrib['id'] = 'rcmIdentitiesList';
66
54759c 67   // get identities list and define 'mail' column
a90ad2 68   $list = $RCMAIL->user->list_identities();
54759c 69   foreach ($list as $idx => $row)
e8d5bd 70     $list[$idx]['mail'] = trim($row['name'] . ' <' . rcube_idn_to_utf8($row['email']) .'>');
54759c 71
3ca3bd 72   // get all identites from DB and define list of cols to be displayed
e6ce00 73   $plugin = $RCMAIL->plugins->exec_hook('identities_list', array(
54759c 74     'list' => $list,
A 75     'cols' => array('mail')));
4e17e6 76
54759c 77   // @TODO: use <UL> instead of <TABLE> for identities list
A 78   // create XHTML table
3ca3bd 79   $out = rcube_table_output($attrib, $plugin['list'], $plugin['cols'], 'identity_id');
54759c 80
4e17e6 81   // set client env
f11541 82   $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
4e17e6 83
T 84   return $out;
d11fb2 85 }
4e17e6 86
T 87
88 // similar function as in /steps/addressbook/edit.inc
57f0c8 89 function get_form_tags($attrib, $action, $id = null, $hidden = null)
d11fb2 90 {
197601 91   global $EDIT_FORM, $RCMAIL;
4e17e6 92
57f0c8 93   $form_start = $form_end = '';
f8e8af 94
57f0c8 95   if (empty($EDIT_FORM)) {
T 96     $request_key = $action . (isset($id) ? '.'.$id : '');
f05834 97     $form_start = $RCMAIL->output->request_form(array(
d11fb2 98       'name'    => 'form',
A 99       'method'  => 'post',
100       'task'    => $RCMAIL->task,
101       'action'  => $action,
102       'request' => $request_key,
103       'noclose' => true
104     ) + $attrib);
f8e8af 105
57f0c8 106     if (is_array($hidden)) {
T 107       $hiddenfields = new html_hiddenfield($hidden);
108       $form_start .= $hiddenfields->show();
4e17e6 109     }
f8e8af 110
57f0c8 111     $form_end = !strlen($attrib['form']) ? '</form>' : '';
4e17e6 112
57f0c8 113     $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
T 114     $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
115   }
4e17e6 116
197601 117   return array($form_start, $form_end);
d11fb2 118 }
4e17e6 119
ec0171 120
49771b 121 function rcmail_user_prefs($current=null)
A 122 {
123   global $RCMAIL;
124
125   $sections['general'] = array('id' => 'general', 'section' => rcube_label('uisettings'));
126   $sections['mailbox'] = array('id' => 'mailbox', 'section' => rcube_label('mailboxview'));
127   $sections['mailview'] = array('id' => 'mailview','section' => rcube_label('messagesdisplaying'));
271efe 128   $sections['compose'] = array('id' => 'compose', 'section' => rcube_label('messagescomposition'));
d73448 129   $sections['addressbook'] = array('id' => 'addressbook','section' => rcube_label('addressbook'));
49771b 130   $sections['folders'] = array('id' => 'folders', 'section' => rcube_label('specialfolders'));
A 131   $sections['server'] = array('id' => 'server',  'section' => rcube_label('serversettings'));
132
133   // hook + define list cols
e6ce00 134   $plugin = $RCMAIL->plugins->exec_hook('preferences_sections_list',
49771b 135         array('list' => $sections, 'cols' => array('section')));
A 136
137   $sections = $plugin['list'];
f8e8af 138
49771b 139   $config = $RCMAIL->config->all();
A 140   $no_override = array_flip($RCMAIL->config->get('dont_override', array()));
f8e8af 141
49771b 142   foreach ($sections as $idx => $sect) {
f8e8af 143
49771b 144     if ($current && $sect['id'] != $current)
A 145       continue;
f8e8af 146
49771b 147     $blocks = array();
f8e8af 148
49771b 149     switch ($sect['id']) {
A 150     // general
151     case 'general':
f8e8af 152
49771b 153     $blocks = array(
06c990 154       'main'    => array('name' => Q(rcube_label('mainoptions'))),
49771b 155     );
f8e8af 156
49771b 157     // language selection
A 158     if (!isset($no_override['language'])) {
159       $a_lang = $RCMAIL->list_languages();
160       asort($a_lang);
161
162       $field_id = 'rcmfd_lang';
163       $select_lang = new html_select(array('name' => '_language', 'id' => $field_id));
164       $select_lang->add(array_values($a_lang), array_keys($a_lang));
165
166       $blocks['main']['options']['language'] = array(
167         'title' => html::label($field_id, Q(rcube_label('language'))),
168         'content' => $select_lang->show($RCMAIL->user->language),
169       );
170     }
171
08ffd9 172     // timezone selection
49771b 173     if (!isset($no_override['timezone'])) {
A 174       $field_id = 'rcmfd_timezone';
5879c0 175       $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id));
49771b 176       $select_timezone->add(rcube_label('autodetect'), 'auto');
5879c0 177
a60d13 178       $zones = array();
5879c0 179       foreach (DateTimeZone::listIdentifiers() as $i => $tzs) {
476fa9 180         try {
AM 181           $tz = new DateTimeZone($tzs);
182           $date = new DateTime('2012-12-21', $tz);
183           $offset = $date->format('Z') + 45000;
184           $sortkey = sprintf('%06d.%s', $offset, $tzs);
185           $zones[$sortkey] = array($tzs, $date->format('P'));
186         }
187         catch (Exception $e) {}
5879c0 188       }
T 189
190       ksort($zones);
191       foreach ($zones as $zone) {
192         list($tzs, $offset) = $zone;
193         $select_timezone->add('(GMT ' . $offset . ') ' . strtr($tzs, '_', ' '), $tzs);
194       }
195
49771b 196       $blocks['main']['options']['timezone'] = array(
A 197         'title' => html::label($field_id, Q(rcube_label('timezone'))),
198         'content' => $select_timezone->show((string)$config['timezone']),
199       );
200     }
201
1cc9e2 202     // date/time formatting
T 203     if (!isset($no_override['time_format'])) {
204       $reftime = mktime(7,30,0);
205       $field_id = 'rcmfd_time_format';
206       $select_time = new html_select(array('name' => '_time_format', 'id' => $field_id));
207       foreach ((array)$RCMAIL->config->get('time_formats', array('G:i', 'H:i', 'g:i a', 'h:i A')) as $choice)
208         $select_time->add(date($choice, $reftime), $choice);
209
210       $blocks['main']['options']['time_format'] = array(
211         'title' => html::label($field_id, Q(rcube_label('timeformat'))),
212         'content' => $select_time->show($RCMAIL->config->get('time_format')),
213       );
214     }
215
216     if (!isset($no_override['date_format'])) {
217       $refdate = mktime(12,30,0,7,24);
218       $field_id = 'rcmfd_date_format';
219       $select_date = new html_select(array('name' => '_date_format', 'id' => $field_id));
220       foreach ((array)$RCMAIL->config->get('date_formats', array('Y-m-d','d-m-Y','Y/m/d','m/d/Y','d/m/Y','d.m.Y','j.n.Y')) as $choice)
221         $select_date->add(date($choice, $refdate), $choice);
222
223       $blocks['main']['options']['date_format'] = array(
224         'title' => html::label($field_id, Q(rcube_label('dateformat'))),
225         'content' => $select_date->show($config['date_format']),
226       );
227     }
228
49771b 229     // MM: Show checkbox for toggling 'pretty dates' 
A 230     if (!isset($no_override['prettydate'])) {
231       $field_id = 'rcmfd_prettydate';
232       $input_prettydate = new html_checkbox(array('name' => '_pretty_date', 'id' => $field_id, 'value' => 1));
233
234       $blocks['main']['options']['prettydate'] = array(
235         'title' => html::label($field_id, Q(rcube_label('prettydate'))),
236         'content' => $input_prettydate->show($config['prettydate']?1:0),
237       );
238     }
239
f22654 240     if (!isset($no_override['refresh_interval'])) {
AM 241       $field_id = 'rcmfd_refresh_interval';
242       $select_refresh_interval = new html_select(array('name' => '_refresh_interval', 'id' => $field_id));
aa8359 243
f22654 244       $select_refresh_interval->add(rcube_label('never'), 0);
aa8359 245       foreach (array(1, 3, 5, 10, 15, 30, 60) as $min) {
f22654 246         if (!$config['min_refresh_interval'] || $config['min_refresh_interval'] <= $min * 60) {
aa8359 247           $label = rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min)));
f22654 248           $select_refresh_interval->add($label, $min);
aa8359 249         }
AM 250       }
251
f22654 252       $blocks['main']['options']['refresh_interval'] = array(
aa8359 253         'title' => html::label($field_id, Q(rcube_label('refreshinterval'))),
f22654 254         'content' => $select_refresh_interval->show($config['refresh_interval']/60),
aa8359 255       );
AM 256     }
257
49771b 258     // show drop-down for available skins
A 259     if (!isset($no_override['skin'])) {
260       $skins = rcmail_get_skins();
261
262       if (count($skins) > 1) {
263         $field_id = 'rcmfd_skin';
18b738 264         $input_skin = new html_radiobutton(array('name'=>'_skin'));
49771b 265
18b738 266         $blocks['skin'] = array('name' => Q(rcube_label('skin')),);
49771b 267
18b738 268         foreach($skins as $skin) {
TB 269           $thumbnail = "./skins/$skin/thumbnail.png";
270           if (!is_file($thumbnail))
271             $thumbnail = './program/resources/blank.gif';
272
273           $skinname = ucfirst($skin);
274           $author_link = $license_link = '';
275           $meta = @json_decode(@file_get_contents("./skins/$skin/meta.json"), true);
276           if (is_array($meta) && $meta['name']) {
277             $skinname = $meta['name'];
278             $author_link  = $meta['url'] ? html::a(array('href' => $meta['url'], 'target' => '_blank'), Q($meta['author'])) : Q($meta['author']);
279             $license_link = $meta['license-url'] ? html::a(array('href' => $meta['license-url'], 'target' => '_blank'), Q($meta['license'])) : Q($meta['license']);
280           }
281
282           $blocks['skin']['options'][$skin]['content'] = html::label(array('class' => 'skinselection'),
283             html::span('skinitem', $input_skin->show($config['skin'], array('value' => $skin, 'id' => $field_id.$skin))) .
284             html::span('skinitem', html::img(array('src' => $thumbnail, 'class' => 'skinthumbnail', 'alt' => $skin, 'width' => 64, 'height' => 64))) .
285             html::span('skinitem', html::span('skinname', Q($skinname)) . html::br() .
286               html::span('skinauthor', $author_link ? 'by ' . $author_link : '') . html::br() .
287               html::span('skinlicense', $license_link ? rcube_label('license').':&nbsp;' . $license_link : ''))
288           );
289         }
49771b 290       }
A 291     }
f8e8af 292
06c990 293     $product_name = $RCMAIL->config->get('product_name', 'Roundcube Webmail');
A 294     $RCMAIL->output->add_script(sprintf("%s.check_protocol_handler('%s', '#mailtoprotohandler');",
295       JS_OBJECT_NAME, JQ($product_name)), 'foot');
296
18b738 297     $blocks['browser'] = array(
TB 298       'name' => Q(rcube_label('browseroptions')),
299       'options' => array('mailtoprotohandler' => array(
300         'content' => html::a(array(
301           'href' => '#',
302           'id' => 'mailtoprotohandler'), Q(rcube_label('mailtoprotohandler'))),
303         )),
06c990 304     );
A 305
f8e8af 306     break;
A 307
49771b 308     // Mailbox view (mail screen)
A 309     case 'mailbox':
f8e8af 310
49771b 311     $blocks = array(
A 312       'main' => array('name' => Q(rcube_label('mainoptions'))),
313       'new_message' => array('name' => Q(rcube_label('newmessage'))),
314     );
315
316     // show config parameter for preview pane
317     if (!isset($no_override['preview_pane'])) {
318       $field_id = 'rcmfd_preview';
bc4960 319       $input_preview = new html_checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1,
81c2ce 320         'onchange' => "$('#rcmfd_preview_pane_mark_read').prop('disabled', !this.checked)"));
49771b 321
A 322       $blocks['main']['options']['preview_pane'] = array(
323         'title' => html::label($field_id, Q(rcube_label('previewpane'))),
324         'content' => $input_preview->show($config['preview_pane']?1:0),
325       );
326     }
327
bc4960 328     // show config parameter for preview pane auto mark as read delay
T 329     if (!isset($no_override['preview_pane_mark_read'])) {
330       // apply default if config option is not set at all
331       $config['preview_pane_mark_read'] = $RCMAIL->config->get('preview_pane_mark_read', 0);
f8e8af 332
bc4960 333       $field_id = 'rcmfd_preview_pane_mark_read';
T 334       $select_delay = new html_select(array('name' => '_preview_pane_mark_read', 'id' => $field_id,
335         'disabled' => $config['preview_pane']?0:1));
336
337       $select_delay->add(rcube_label('never'), '-1');
338       $select_delay->add(rcube_label('immediately'), 0);
339       foreach(array(5, 10, 20, 30) as $sec)
340         $select_delay->add(rcube_label(array('name' => 'afternseconds', 'vars' => array('n' => $sec))), $sec);
341
342       $blocks['main']['options']['preview_pane_mark_read'] = array(
343         'title' => html::label($field_id, Q(rcube_label('previewpanemarkread'))),
344         'content' => $select_delay->show(intval($config['preview_pane_mark_read'])),
345       );
346     }
347
49771b 348     if (!isset($no_override['mdn_requests'])) {
A 349       $field_id = 'rcmfd_mdn_requests';
350       $select_mdn_requests = new html_select(array('name' => '_mdn_requests', 'id' => $field_id));
351       $select_mdn_requests->add(rcube_label('askuser'), 0);
352       $select_mdn_requests->add(rcube_label('autosend'), 1);
a99968 353       $select_mdn_requests->add(rcube_label('autosendknown'), 3);
6c6bb0 354       $select_mdn_requests->add(rcube_label('autosendknownignore'), 4);
49771b 355       $select_mdn_requests->add(rcube_label('ignore'), 2);
A 356
357       $blocks['main']['options']['mdn_requests'] = array(
358         'title' => html::label($field_id, Q(rcube_label('mdnrequests'))),
359         'content' => $select_mdn_requests->show($config['mdn_requests']),
360       );
361     }
362
c321a9 363     $storage             = $RCMAIL->get_storage();
T 364     $threading_supported = $storage->get_capability('THREAD');
63ab02 365
A 366     if (!isset($no_override['autoexpand_threads']) && $threading_supported) {
f52c93 367       $field_id = 'rcmfd_autoexpand_threads';
T 368       $select_autoexpand_threads = new html_select(array('name' => '_autoexpand_threads', 'id' => $field_id));
369       $select_autoexpand_threads->add(rcube_label('never'), 0);
370       $select_autoexpand_threads->add(rcube_label('do_expand'), 1);
371       $select_autoexpand_threads->add(rcube_label('expand_only_unread'), 2);
f8e8af 372
f52c93 373       $blocks['main']['options']['autoexpand_threads'] = array(
600bb1 374         'title' => html::label($field_id, Q(rcube_label('autoexpand_threads'))),
A 375         'content' => $select_autoexpand_threads->show($config['autoexpand_threads']),
08ffd9 376       );
A 377     }
378
379     // show page size selection
a61cce 380     if (!isset($no_override['mail_pagesize'])) {
A 381       $field_id = 'rcmfd_mail_pagesize';
382       $input_pagesize = new html_inputfield(array('name' => '_mail_pagesize', 'id' => $field_id, 'size' => 5));
383
384       $size = intval($config['mail_pagesize'] ? $config['mail_pagesize'] : $config['pagesize']);
08ffd9 385
A 386       $blocks['main']['options']['pagesize'] = array(
387         'title' => html::label($field_id, Q(rcube_label('pagesize'))),
a61cce 388         'content' => $input_pagesize->show($size ? $size : 50),
f52c93 389       );
T 390     }
49771b 391     if (!isset($no_override['check_all_folders'])) {
A 392       $field_id = 'rcmfd_check_all_folders';
393       $input_check_all = new html_checkbox(array('name' => '_check_all_folders', 'id' => $field_id, 'value' => 1));
394
395       $blocks['new_message']['options']['check_all_folders'] = array(
396         'title' => html::label($field_id, Q(rcube_label('checkallfolders'))),
397         'content' => $input_check_all->show($config['check_all_folders']?1:0),
398       );
399     }
400
401     break;
f8e8af 402
49771b 403     // Message viewing
A 404     case 'mailview':
f8e8af 405
49771b 406     $blocks = array(
A 407       'main' => array('name' => Q(rcube_label('mainoptions'))),
408     );
409
271efe 410     // show checkbox to open message view in new window
TB 411     if (!isset($no_override['message_extwin'])) {
412       $field_id = 'rcmfd_message_extwin';
413       $input_msgextwin = new html_checkbox(array('name' => '_message_extwin', 'id' => $field_id, 'value' => 1));
414
415       $blocks['main']['options']['message_extwin'] = array(
416         'title' => html::label($field_id, Q(rcube_label('showinextwin'))),
417         'content' => $input_msgextwin->show($config['message_extwin']?1:0),
418       );
419     }
420
969cb0 421     // show checkbox to show email instead of name
AM 422     if (!isset($no_override['message_show_email'])) {
423       $field_id = 'rcmfd_message_show_email';
424       $input_msgshowemail = new html_checkbox(array('name' => '_message_show_email', 'id' => $field_id, 'value' => 1));
425
426       $blocks['main']['options']['message_show_email'] = array(
427         'title' => html::label($field_id, Q(rcube_label('showemail'))),
428         'content' => $input_msgshowemail->show($config['message_show_email']?1:0),
429       );
430     }
431
49771b 432     // show checkbox for HTML/plaintext messages
A 433     if (!isset($no_override['prefer_html'])) {
434       $field_id = 'rcmfd_htmlmsg';
435       $input_preferhtml = new html_checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1,
81c2ce 436         'onchange' => "$('#rcmfd_show_images').prop('disabled', !this.checked).val(0)"));
49771b 437
A 438       $blocks['main']['options']['prefer_html'] = array(
439         'title' => html::label($field_id, Q(rcube_label('preferhtml'))),
440         'content' => $input_preferhtml->show($config['prefer_html']?1:0),
441       );
442     }
443
e55ab0 444     if (!isset($no_override['default_charset'])) {
A 445       $field_id = 'rcmfd_default_charset';
446
447       $blocks['main']['options']['default_charset'] = array(
448         'title' => html::label($field_id, Q(rcube_label('defaultcharset'))),
449         'content' => $RCMAIL->output->charset_selector(array(
81c2ce 450           'name' => '_default_charset', 'selected' => $config['default_charset']
A 451         ))
e55ab0 452       );
A 453     }
454
49771b 455     if (!isset($no_override['show_images'])) {
A 456       $field_id = 'rcmfd_show_images';
e01e79 457       $input_show_images = new html_select(array('name' => '_show_images', 'id' => $field_id,
A 458         'disabled' => !$config['prefer_html']));
49771b 459       $input_show_images->add(rcube_label('never'), 0);
A 460       $input_show_images->add(rcube_label('fromknownsenders'), 1);
461       $input_show_images->add(rcube_label('always'), 2);
462
463       $blocks['main']['options']['show_images'] = array(
464         'title' => html::label($field_id, Q(rcube_label('showremoteimages'))),
e01e79 465         'content' => $input_show_images->show($config['prefer_html'] ? $config['show_images'] : 0),
49771b 466       );
A 467     }
468
469     if (!isset($no_override['inline_images'])) {
470       $field_id = 'rcmfd_inline_images';
471       $input_inline_images = new html_checkbox(array('name' => '_inline_images', 'id' => $field_id, 'value' => 1));
472
473       $blocks['main']['options']['inline_images'] = array(
474         'title' => html::label($field_id, Q(rcube_label('showinlineimages'))),
475         'content' => $input_inline_images->show($config['inline_images']?1:0),
476       );
477     }
478
479     // "display after delete" checkbox
480     if (!isset($no_override['display_next'])) {
481       $field_id = 'rcmfd_displaynext';
482       $input_displaynext = new html_checkbox(array('name' => '_display_next', 'id' => $field_id, 'value' => 1));
483
484       $blocks['main']['options']['display_next'] = array(
485         'title' => html::label($field_id, Q(rcube_label('displaynext'))),
486         'content' => $input_displaynext->show($config['display_next']?1:0),
487       );
488     }
489
490     break;
f8e8af 491
49771b 492     // Mail composition
A 493     case 'compose':
f8e8af 494
49771b 495     $blocks = array(
66df08 496       'main'       => array('name' => Q(rcube_label('mainoptions'))),
A 497       'sig'        => array('name' => Q(rcube_label('signatureoptions'))),
cf8b9f 498       'spellcheck' => array('name' => Q(rcube_label('spellcheckoptions'))),
49771b 499     );
A 500
271efe 501     // show checkbox to compose messages in a new window
TB 502     if (!isset($no_override['compose_extwin'])) {
503       $field_id = 'rcmfdcompose_extwin';
504       $input_compextwin = new html_checkbox(array('name' => '_compose_extwin', 'id' => $field_id, 'value' => 1));
505
506       $blocks['main']['options']['compose_extwin'] = array(
507         'title' => html::label($field_id, Q(rcube_label('composeextwin'))),
508         'content' => $input_compextwin->show($config['compose_extwin']?1:0),
509       );
510     }
511
49771b 512     if (!isset($no_override['htmleditor'])) {
A 513       $field_id = 'rcmfd_htmleditor';
868deb 514       $select_htmleditor = new html_select(array('name' => '_htmleditor', 'id' => $field_id));
A 515       $select_htmleditor->add(rcube_label('never'), 0);
516       $select_htmleditor->add(rcube_label('always'), 1);
517       $select_htmleditor->add(rcube_label('htmlonreply'), 2);
8eefbb 518       $select_htmleditor->add(rcube_label('htmlonreplyandforward'), 3);
49771b 519
A 520       $blocks['main']['options']['htmleditor'] = array(
521         'title' => html::label($field_id, Q(rcube_label('htmleditor'))),
868deb 522         'content' => $select_htmleditor->show(intval($config['htmleditor'])),
49771b 523       );
A 524     }
525
526     if (!isset($no_override['draft_autosave'])) {
527       $field_id = 'rcmfd_autosave';
528       $select_autosave = new html_select(array('name' => '_draft_autosave', 'id' => $field_id, 'disabled' => empty($config['drafts_mbox'])));
529       $select_autosave->add(rcube_label('never'), 0);
530       foreach (array(1, 3, 5, 10) as $i => $min)
531         $select_autosave->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min*60);
532
533       $blocks['main']['options']['draft_autosave'] = array(
534         'title' => html::label($field_id, Q(rcube_label('autosavedraft'))),
535         'content' => $select_autosave->show($config['draft_autosave']),
536       );
537     }
538
539     if (!isset($no_override['mime_param_folding'])) {
540       $field_id = 'rcmfd_param_folding';
541       $select_param_folding = new html_select(array('name' => '_mime_param_folding', 'id' => $field_id));
542       $select_param_folding->add(rcube_label('2231folding'), 0);
543       $select_param_folding->add(rcube_label('miscfolding'), 1);
544       $select_param_folding->add(rcube_label('2047folding'), 2);
545
546       $blocks['main']['options']['mime_param_folding'] = array(
0207c4 547         'advanced' => true,
49771b 548         'title' => html::label($field_id, Q(rcube_label('mimeparamfolding'))),
A 549         'content' => $select_param_folding->show($config['mime_param_folding']),
550       );
551     }
47ad83 552
A 553     if (!isset($no_override['force_7bit'])) {
554       $field_id = 'rcmfd_force_7bit';
555       $input_7bit = new html_checkbox(array('name' => '_force_7bit', 'id' => $field_id, 'value' => 1));
556
557       $blocks['main']['options']['force_7bit'] = array(
558         'title' => html::label($field_id, Q(rcube_label('force7bit'))),
559         'content' => $input_7bit->show($config['force_7bit']?1:0),
560       );
561     }
562
b3660b 563     if (!isset($no_override['mdn_default'])) {
A 564       $field_id = 'rcmfd_mdn_default';
565       $input_mdn = new html_checkbox(array('name' => '_mdn_default', 'id' => $field_id, 'value' => 1));
566
567       $blocks['main']['options']['mdn_default'] = array(
568         'title' => html::label($field_id, Q(rcube_label('reqmdn'))),
569         'content' => $input_mdn->show($config['mdn_default']?1:0),
570       );
571     }
572
f22ea7 573     if (!isset($no_override['dsn_default'])) {
A 574       $field_id = 'rcmfd_dsn_default';
575       $input_dsn = new html_checkbox(array('name' => '_dsn_default', 'id' => $field_id, 'value' => 1));
576
577       $blocks['main']['options']['dsn_default'] = array(
578         'title' => html::label($field_id, Q(rcube_label('reqdsn'))),
579         'content' => $input_dsn->show($config['dsn_default']?1:0),
580       );
581     }
582
eeb85f 583     if (!isset($no_override['reply_same_folder'])) {
A 584       $field_id = 'rcmfd_reply_same_folder';
585       $input_reply_same_folder = new html_checkbox(array('name' => '_reply_same_folder', 'id' => $field_id, 'value' => 1));
586
587       $blocks['main']['options']['reply_same_folder'] = array(
588         'title' => html::label($field_id, Q(rcube_label('replysamefolder'))),
589         'content' => $input_reply_same_folder->show($config['reply_same_folder']?1:0),
590       );
591     }
592
651c7b 593     if (!isset($no_override['reply_mode'])) {
AM 594       $field_id = 'rcmfd_reply_mode';
1d4c84 595       $select_replymode = new html_select(array('name' => '_reply_mode', 'id' => $field_id));
651c7b 596       $select_replymode->add(rcube_label('replyempty'), -1);
0207c4 597       $select_replymode->add(rcube_label('replybottomposting'), 0);
T 598       $select_replymode->add(rcube_label('replytopposting'), 1);
50f56d 599
651c7b 600       $blocks['main']['options']['reply_mode'] = array(
0207c4 601         'title' => html::label($field_id, Q(rcube_label('whenreplying'))),
651c7b 602         'content' => $select_replymode->show(intval($config['reply_mode'])),
50f56d 603       );
A 604     }
605
1d5779 606     if (!isset($no_override['spellcheck_before_send']) && $config['enable_spellcheck']) {
A 607       $field_id = 'rcmfd_spellcheck_before_send';
608       $input_spellcheck = new html_checkbox(array('name' => '_spellcheck_before_send', 'id' => $field_id, 'value' => 1));
609
66df08 610       $blocks['spellcheck']['options']['spellcheck_before_send'] = array(
1d5779 611         'title' => html::label($field_id, Q(rcube_label('spellcheckbeforesend'))),
A 612         'content' => $input_spellcheck->show($config['spellcheck_before_send']?1:0),
613       );
614     }
615
66df08 616     if ($config['enable_spellcheck']) {
A 617       foreach (array('syms', 'nums', 'caps') as $key) {
618         $key = 'spellcheck_ignore_'.$key;
619         if (!isset($no_override[$key])) {
620           $input_spellcheck = new html_checkbox(array('name' => '_'.$key, 'id' => 'rcmfd_'.$key, 'value' => 1));
621
622           $blocks['spellcheck']['options'][$key] = array(
623             'title' => html::label($field_id, Q(rcube_label(str_replace('_', '', $key)))),
624             'content' => $input_spellcheck->show($config[$key]?1:0),
625           );
626         }
627       }
628     }
629
50f56d 630     if (!isset($no_override['show_sig'])) {
A 631       $field_id = 'rcmfd_show_sig';
632       $select_show_sig = new html_select(array('name' => '_show_sig', 'id' => $field_id));
0207c4 633       $select_show_sig->add(rcube_label('never'), 0);
T 634       $select_show_sig->add(rcube_label('always'), 1);
635       $select_show_sig->add(rcube_label('newmessageonly'), 2);
636       $select_show_sig->add(rcube_label('replyandforwardonly'), 3);
50f56d 637
0207c4 638       $blocks['sig']['options']['show_sig'] = array(
T 639         'title' => html::label($field_id, Q(rcube_label('autoaddsignature'))),
655bd9 640         'content' => $select_show_sig->show($RCMAIL->config->get('show_sig', 1)),
0207c4 641       );
T 642     }
643
644     if (!isset($no_override['strip_existing_sig'])) {
645       $field_id = 'rcmfd_strip_existing_sig';
646       $input_stripexistingsig = new html_checkbox(array('name' => '_strip_existing_sig', 'id' => $field_id, 'value' => 1));
647
648       $blocks['sig']['options']['strip_existing_sig'] = array(
649         'title' => html::label($field_id, Q(rcube_label('replyremovesignature'))),
650         'content' => $input_stripexistingsig->show($config['strip_existing_sig']?1:0),
50f56d 651       );
A 652     }
49771b 653
c08396 654     if (!isset($no_override['forward_attachment'])) {
AM 655       $field_id = 'rcmfd_forward_attachment';
656       $select = new html_select(array('name' => '_forward_attachment', 'id' => $field_id));
657       $select->add(rcube_label('inline'), 0);
658       $select->add(rcube_label('asattachment'), 1);
659
660       $blocks['main']['options']['forward_attachment'] = array(
661         'title' => html::label($field_id, Q(rcube_label('forwardmode'))),
662         'content' => $select->show(intval($config['forward_attachment'])),
663       );
664     }
665
7e263e 666     if (!isset($no_override['default_font'])) {
07795b 667       $field_id = 'rcmfd_default_font';
AM 668       $fonts    = rcube_fontdefs();
669       $selected = $config['default_font'];
7e263e 670
A 671       $select = '<select name="_default_font" id="'.$field_id.'">';
07795b 672       $select .= '<option value=""' . (!$selected ? ' selected="selected"' : '') . '>---</option>';
7e263e 673       foreach ($fonts as $fname => $font)
A 674         $select .= '<option value="'.$fname.'"'
07795b 675           . ($fname == $selected ? ' selected="selected"' : '')
7e263e 676           . ' style=\'font-family: ' . $font . '\'>'
A 677           . Q($fname) . '</option>';
678       $select .= '</select>';
679
680       $blocks['main']['options']['default_font'] = array(
681         'title' => html::label($field_id, Q(rcube_label('defaultfont'))),
682         'content' => $select
683       );
684     }
685
49771b 686     break;
f8e8af 687
d73448 688
A 689     // Addressbook config
690     case 'addressbook':
691
692     $blocks = array(
693       'main' => array('name' => Q(rcube_label('mainoptions'))),
694     );
695
696     if (!isset($no_override['default_addressbook'])
65dff8 697       && ($books = $RCMAIL->get_address_sources(true, true))
d73448 698     ) {
A 699       $field_id = 'rcmfd_default_addressbook';
700       $select_abook = new html_select(array('name' => '_default_addressbook', 'id' => $field_id));
701
702       foreach ($books as $book) {
5802cf 703         $select_abook->add(html_entity_decode($book['name'], ENT_COMPAT, 'UTF-8'), $book['id']);
d73448 704       }
A 705
706       $blocks['main']['options']['default_addressbook'] = array(
6459d8 707         'title' => html::label($field_id, Q(rcube_label('defaultabook'))),
d73448 708         'content' => $select_abook->show($config['default_addressbook']),
A 709       );
710     }
711
f9a967 712     // show addressbook listing mode selection
T 713     if (!isset($no_override['addressbook_name_listing'])) {
714       $field_id = 'rcmfd_addressbook_name_listing';
715       $select_listing = new html_select(array('name' => '_addressbook_name_listing', 'id' => $field_id));
716       $select_listing->add(rcube_label('name'), 0);
717       $select_listing->add(rcube_label('firstname') . ' '  . rcube_label('surname'), 1);
718       $select_listing->add(rcube_label('surname')   . ' '  . rcube_label('firstname'), 2);
719       $select_listing->add(rcube_label('surname')   . ', ' . rcube_label('firstname'), 3);
720
721       $blocks['main']['options']['list_name_listing'] = array(
722         'title' => html::label($field_id, Q(rcube_label('listnamedisplay'))),
723         'content' => $select_listing->show($config['addressbook_name_listing']),
724       );
725     }
726
438753 727     // show addressbook sort column
T 728     if (!isset($no_override['addressbook_sort_col'])) {
729       $field_id = 'rcmfd_addressbook_sort_col';
730       $select_sort = new html_select(array('name' => '_addressbook_sort_col', 'id' => $field_id));
731       $select_sort->add(rcube_label('name'), 'name');
732       $select_sort->add(rcube_label('firstname'), 'firstname');
733       $select_sort->add(rcube_label('surname'), 'surname');
710b1b 734
438753 735       $blocks['main']['options']['sort_col'] = array(
T 736         'title' => html::label($field_id, Q(rcube_label('listsorting'))),
737         'content' => $select_sort->show($config['addressbook_sort_col']),
710b1b 738       );
A 739     }
740
08ffd9 741     // show addressbook page size selection
A 742     if (!isset($no_override['addressbook_pagesize'])) {
743       $field_id = 'rcmfd_addressbook_pagesize';
744       $input_pagesize = new html_inputfield(array('name' => '_addressbook_pagesize', 'id' => $field_id, 'size' => 5));
745
a61cce 746       $size = intval($config['addressbook_pagesize'] ? $config['addressbook_pagesize'] : $config['pagesize']);
08ffd9 747
A 748       $blocks['main']['options']['pagesize'] = array(
749         'title' => html::label($field_id, Q(rcube_label('pagesize'))),
a61cce 750         'content' => $input_pagesize->show($size ? $size : 50),
08ffd9 751       );
A 752     }
753
438753 754     if (!isset($no_override['autocomplete_single'])) {
T 755       $field_id = 'rcmfd_autocomplete_single';
756       $checkbox = new html_checkbox(array('name' => '_autocomplete_single', 'id' => $field_id, 'value' => 1));
757
758       $blocks['main']['options']['autocomplete_single'] = array(
759         'title' => html::label($field_id, Q(rcube_label('autocompletesingle'))),
760         'content' => $checkbox->show($config['autocomplete_single']?1:0),
761       );
762     }
763
d73448 764     break;
A 765
49771b 766     // Special IMAP folders
A 767     case 'folders':
f8e8af 768
49771b 769     $blocks = array(
A 770       'main' => array('name' => Q(rcube_label('mainoptions'))),
771     );
772
52deb1 773
DC 774     if (!isset($no_override['show_actual_foldernames'])) {
775       $field_id = 'show_actual_foldernames';
776       $input_show_actual_foldernames =
777           new html_checkbox(array('name' => '_show_actual_foldernames',
778                                   'id' => $field_id, 'value' => 1));
779
780       $blocks['main']['options']['show_actul_foldernames'] = array(
781         'title' => html::label($field_id,
782                                Q(rcube_label('show_actual_foldernames'))),
783         'content' => $input_show_actual_foldernames->show($config['show_actual_foldernames']?1:0),
784       );
785     }
49771b 786     // Configure special folders
c321a9 787     if (!isset($no_override['default_folders'])) {
63ab02 788       // load folders list only when needed
A 789       if ($current) {
e2dfb5 790         $select = rcmail_mailbox_select(array(
A 791           'noselection'   => '---',
792           'realnames'     => true,
793           'maxlength'     => 30,
794           'folder_filter' => 'mail',
795           'folder_rights' => 'w',
796           // #1486114, #1488279
797           'onchange'      => "if ($(this).val() == 'INBOX') $(this).val('')",
798         ));
63ab02 799       }
A 800       else // dummy select
801         $select = new html_select();
49771b 802
A 803       if (!isset($no_override['drafts_mbox']))
804         $blocks['main']['options']['drafts_mbox'] = array(
805           'title' => Q(rcube_label('drafts')),
806           'content' => $select->show($config['drafts_mbox'], array('name' => "_drafts_mbox")),
807         );
808
809       if (!isset($no_override['sent_mbox']))
810         $blocks['main']['options']['sent_mbox'] = array(
811           'title' => Q(rcube_label('sent')),
812           'content' => $select->show($config['sent_mbox'], array('name' => "_sent_mbox")),
813     );
814
815       if (!isset($no_override['junk_mbox']))
816         $blocks['main']['options']['junk_mbox'] = array(
817           'title' => Q(rcube_label('junk')),
818           'content' => $select->show($config['junk_mbox'], array('name' => "_junk_mbox")),
819     );
820
821       if (!isset($no_override['trash_mbox']))
822         $blocks['main']['options']['trash_mbox'] = array(
823           'title' => Q(rcube_label('trash')),
824           'content' => $select->show($config['trash_mbox'], array('name' => "_trash_mbox")),
825         );
826     }
827
828     break;
f8e8af 829
49771b 830     // Server settings
A 831     case 'server':
f8e8af 832
49771b 833     $blocks = array(
A 834       'main' => array('name' => Q(rcube_label('mainoptions'))),
835       'maintenance' => array('name' => Q(rcube_label('maintenance'))),
836     );
837
838     if (!isset($no_override['read_when_deleted'])) {
839       $field_id = 'rcmfd_read_deleted';
840       $input_readdeleted = new html_checkbox(array('name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1));
841
842       $blocks['main']['options']['read_when_deleted'] = array(
843         'title' => html::label($field_id, Q(rcube_label('readwhendeleted'))),
844         'content' => $input_readdeleted->show($config['read_when_deleted']?1:0),
845       );
846     }
847
848     if (!isset($no_override['flag_for_deletion'])) {
849       $field_id = 'rcmfd_flag_for_deletion';
850       $input_flagfordeletion = new html_checkbox(array('name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1));
851
852       $blocks['main']['options']['flag_for_deletion'] = array(
853         'title' => html::label($field_id, Q(rcube_label('flagfordeletion'))),
854         'content' => $input_flagfordeletion->show($config['flag_for_deletion']?1:0),
855       );
856     }
857
858     // don't show deleted messages
859     if (!isset($no_override['skip_deleted'])) {
860       $field_id = 'rcmfd_skip_deleted';
861       $input_purge = new html_checkbox(array('name' => '_skip_deleted', 'id' => $field_id, 'value' => 1));
862
863       $blocks['main']['options']['skip_deleted'] = array(
864         'title' => html::label($field_id, Q(rcube_label('skipdeleted'))),
865         'content' => $input_purge->show($config['skip_deleted']?1:0),
866       );
867     }
868
b7f952 869     if (!isset($no_override['delete_always'])) {
A 870       $field_id = 'rcmfd_delete_always';
871       $input_delete_always = new html_checkbox(array('name' => '_delete_always', 'id' => $field_id, 'value' => 1));
872
873       $blocks['main']['options']['delete_always'] = array(
874         'title' => html::label($field_id, Q(rcube_label('deletealways'))),
875         'content' => $input_delete_always->show($config['delete_always']?1:0),
876       );
877     }
878
1b30a7 879     if (!isset($no_override['delete_junk'])) {
A 880       $field_id = 'rcmfd_delete_junk';
881       $input_delete_junk = new html_checkbox(array('name' => '_delete_junk', 'id' => $field_id, 'value' => 1));
882
883       $blocks['main']['options']['delete_junk'] = array(
884         'title' => html::label($field_id, Q(rcube_label('deletejunk'))),
885         'content' => $input_delete_junk->show($config['delete_junk']?1:0),
886       );
887     }
888
49771b 889     // Trash purging on logout
A 890     if (!isset($no_override['logout_purge'])) {
891       $field_id = 'rcmfd_logout_purge';
892       $input_purge = new html_checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
893
894       $blocks['maintenance']['options']['logout_purge'] = array(
895         'title' => html::label($field_id, Q(rcube_label('logoutclear'))),
896         'content' => $input_purge->show($config['logout_purge']?1:0),
897       );
898     }
899
900     // INBOX compacting on logout
901     if (!isset($no_override['logout_expunge'])) {
902       $field_id = 'rcmfd_logout_expunge';
903       $input_expunge = new html_checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
904
905       $blocks['maintenance']['options']['logout_expunge'] = array(
906         'title' => html::label($field_id, Q(rcube_label('logoutcompact'))),
907         'content' => $input_expunge->show($config['logout_expunge']?1:0),
908       );
909     }
f8e8af 910
49771b 911     break;
A 912     }
913
e6ce00 914     $data = $RCMAIL->plugins->exec_hook('preferences_list', array('section' => $sect['id'], 'blocks' => $blocks));
49771b 915     $found = false;
f8e8af 916
49771b 917     // create output
A 918     foreach ($data['blocks'] as $block) {
f8e8af 919       if (!empty($block['content']) || !empty($block['options'])) {
A 920         $found = true;
921         break;
49771b 922       }
A 923     }
924
925     if (!$found)
926       unset($sections[$idx]);
927     else
928       $sections[$idx]['blocks'] = $data['blocks'];
929   }
930
931   return array($sections, $plugin['cols']);
932 }
933
934
935 function rcmail_get_skins()
936 {
937   $path = 'skins';
938   $skins = array();
939
940   $dir = opendir($path);
f8e8af 941
49771b 942   if (!$dir)
A 943     return false;
f8e8af 944
49771b 945   while (($file = readdir($dir)) !== false)
A 946   {
947     $filename = $path.'/'.$file;
90b1cb 948     if (!preg_match('/^\./', $file) && is_dir($filename) && is_readable($filename))
49771b 949       $skins[] = $file;
A 950   }
951
952   closedir($dir);
953
954   return $skins;
955 }
956
bbce3e 957
254d5e 958 function rcmail_folder_options($mailbox)
bbce3e 959 {
A 960     global $RCMAIL;
961
c321a9 962     $options = $RCMAIL->get_storage()->folder_info($mailbox);
67975b 963     $options['protected'] = $options['is_root'] || ($options['special'] && $RCMAIL->config->get('protect_default_folders'));
bbce3e 964
1a0343 965     return $options;
bbce3e 966 }
A 967
1a0343 968 /**
A 969  * Updates (or creates) folder row in the subscriptions table
970  *
971  * @param string $name      Folder name
972  * @param string $oldname   Old folder name (for update)
973  * @param bool   $subscribe Checks subscription checkbox
974  * @param string $class     CSS class name for folder row
975  */
976 function rcmail_update_folder_row($name, $oldname=null, $subscribe=false, $class_name=null)
254d5e 977 {
63ff2a 978     global $RCMAIL, $OUTPUT;
A 979
980     $default_folders = (array) $RCMAIL->config->get('default_folders');
981     $protect_folders = $RCMAIL->config->get('protect_default_folders');
254d5e 982
c321a9 983     $storage      = $RCMAIL->get_storage();
T 984     $delimiter    = $storage->get_hierarchy_delimiter();
254d5e 985     $name_utf8    = rcube_charset_convert($name, 'UTF7-IMAP');
63ff2a 986     $protected    = $protect_folders && in_array($name, $default_folders);
254d5e 987
c321a9 988     $foldersplit  = explode($delimiter, $storage->mod_folder($name));
254d5e 989     $level        = count($foldersplit) - 1;
A 990     $display_name = str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $level)
991         . Q($protected ? rcmail_localize_foldername($name) : rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'));
992
993     if ($oldname === null)
1a0343 994         $OUTPUT->command('add_folder_row', $name_utf8, $display_name, $protected, $subscribe,
A 995             false, $class_name);
254d5e 996     else
A 997         $OUTPUT->command('replace_folder_row', rcube_charset_convert($oldname, 'UTF7-IMAP'),
1a0343 998             $name_utf8, $display_name, $protected, $class_name);
254d5e 999 }
A 1000
bbce3e 1001
f11541 1002 // register UI objects
T 1003 $OUTPUT->add_handlers(array(
f05834 1004   'prefsframe' => 'rcmail_preferences_frame',
A 1005   'sectionslist' => 'rcmail_sections_list',
b89d5a 1006   'identitieslist' => 'rcmail_identities_list',
f11541 1007 ));
T 1008
68d2d5 1009 // register action aliases
A 1010 $RCMAIL->register_action_map(array(
1011     'folders'       => 'folders.inc',
1012     'rename-folder' => 'folders.inc',
1013     'delete-folder' => 'folders.inc',
1014     'subscribe'     => 'folders.inc',
1015     'unsubscribe'   => 'folders.inc',
1016     'purge'         => 'folders.inc',
1017     'folder-size'   => 'folders.inc',
1018     'add-identity'  => 'edit_identity.inc',
1019 ));