4 +-----------------------------------------------------------------------+
5 | program/steps/settings/func.inc |
7 | This file is part of the RoundCube Webmail client |
8 | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland |
9 | Licensed under the GNU GPL |
12 | Provide functionality for user's settings & preferences |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com> |
16 +-----------------------------------------------------------------------+
18 $Id: func.inc 3055 2009-10-23 18:11:41Z alec $
22 if (!$OUTPUT->ajax_call)
23 $OUTPUT->set_pagetitle(rcube_label('preferences'));
26 // similar function as /steps/settings/identities.inc::rcmail_identity_frame()
27 function rcmail_preferences_frame($attrib)
32 $attrib['id'] = 'rcmprefsframe';
34 $attrib['name'] = $attrib['id'];
36 $OUTPUT->set_env('contentframe', $attrib['name']);
37 $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif');
39 return html::iframe($attrib);
43 function rcmail_sections_list($attrib)
47 // add id to message list table if not specified
48 if (!strlen($attrib['id']))
49 $attrib['id'] = 'rcmsectionslist';
51 list($list, $cols) = rcmail_user_prefs();
54 $out = rcube_table_output($attrib, $list, $cols, 'id');
57 $RCMAIL->output->add_gui_object('sectionslist', $attrib['id']);
58 $RCMAIL->output->include_script('list.js');
64 function rcmail_identities_list($attrib)
66 global $OUTPUT, $USER, $RCMAIL;
68 // add id to message list table if not specified
69 if (!strlen($attrib['id']))
70 $attrib['id'] = 'rcmIdentitiesList';
72 // get all identites from DB and define list of cols to be displayed
73 $plugin = $RCMAIL->plugins->exec_hook('list_identities', array(
74 'list' => $USER->list_identities(),
75 'cols' => array('name', 'email')));
78 $out = rcube_table_output($attrib, $plugin['list'], $plugin['cols'], 'identity_id');
81 $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
87 // similar function as in /steps/addressbook/edit.inc
88 function get_form_tags($attrib, $action, $id = null, $hidden = null)
90 global $EDIT_FORM, $RCMAIL;
92 $form_start = $form_end = '';
94 if (empty($EDIT_FORM)) {
95 $request_key = $action . (isset($id) ? '.'.$id : '');
96 $form_start = $RCMAIL->output->request_form(array(
97 'name' => 'form', 'method' => 'post',
98 'task' => $RCMAIL->task, 'action' => $action,
99 'request' => $request_key, 'noclose' => true) + $attrib);
101 if (is_array($hidden)) {
102 $hiddenfields = new html_hiddenfield($hidden);
103 $form_start .= $hiddenfields->show();
106 $form_end = !strlen($attrib['form']) ? '</form>' : '';
108 $EDIT_FORM = !empty($attrib['form']) ? $attrib['form'] : 'form';
109 $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
112 return array($form_start, $form_end);
116 function rcmail_user_prefs($current=null)
120 $sections['general'] = array('id' => 'general', 'section' => rcube_label('uisettings'));
121 $sections['mailbox'] = array('id' => 'mailbox', 'section' => rcube_label('mailboxview'));
122 $sections['compose'] = array('id' => 'compose', 'section' => rcube_label('messagescomposition'));
123 $sections['mailview'] = array('id' => 'mailview','section' => rcube_label('messagesdisplaying'));
124 $sections['folders'] = array('id' => 'folders', 'section' => rcube_label('specialfolders'));
125 $sections['server'] = array('id' => 'server', 'section' => rcube_label('serversettings'));
127 // hook + define list cols
128 $plugin = $RCMAIL->plugins->exec_hook('list_prefs_sections',
129 array('list' => $sections, 'cols' => array('section')));
131 $sections = $plugin['list'];
133 $config = $RCMAIL->config->all();
134 $no_override = array_flip($RCMAIL->config->get('dont_override', array()));
136 foreach ($sections as $idx => $sect) {
138 if ($current && $sect['id'] != $current)
143 switch ($sect['id']) {
148 'main' => array('name' => Q(rcube_label('mainoptions'))),
149 'list' => array('name' => Q(rcube_label('listoptions'))),
152 // language selection
153 if (!isset($no_override['language'])) {
154 $a_lang = $RCMAIL->list_languages();
157 $field_id = 'rcmfd_lang';
158 $select_lang = new html_select(array('name' => '_language', 'id' => $field_id));
159 $select_lang->add(array_values($a_lang), array_keys($a_lang));
161 $blocks['main']['options']['language'] = array(
162 'title' => html::label($field_id, Q(rcube_label('language'))),
163 'content' => $select_lang->show($RCMAIL->user->language),
167 // show page size selection
168 if (!isset($no_override['timezone'])) {
169 $field_id = 'rcmfd_timezone';
170 $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 'onchange' => "document.getElementById('rcmfd_dst').disabled=this.selectedIndex==0"));
171 $select_timezone->add(rcube_label('autodetect'), 'auto');
172 $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11');
173 $select_timezone->add('(GMT -10:00) Hawaii', '-10');
174 $select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5');
175 $select_timezone->add('(GMT -9:00) Alaska', '-9');
176 $select_timezone->add('(GMT -8:00) Pacific Time (US/Canada)', '-8');
177 $select_timezone->add('(GMT -7:00) Mountain Time (US/Canada)', '-7');
178 $select_timezone->add('(GMT -6:00) Central Time (US/Canada), Mexico City', '-6');
179 $select_timezone->add('(GMT -5:00) Eastern Time (US/Canada), Bogota, Lima', '-5');
180 $select_timezone->add('(GMT -4:30) Caracas', '-4.5');
181 $select_timezone->add('(GMT -4:00) Atlantic Time (Canada), La Paz', '-4');
182 $select_timezone->add('(GMT -3:30) Nfld Time (Canada), Nfld, S. Labador', '-3.5');
183 $select_timezone->add('(GMT -3:00) Brazil, Buenos Aires, Georgetown', '-3');
184 $select_timezone->add('(GMT -2:00) Mid-Atlantic', '-2');
185 $select_timezone->add('(GMT -1:00) Azores, Cape Verde Islands', '-1');
186 $select_timezone->add('(GMT) Western Europe, London, Lisbon, Casablanca', '0');
187 $select_timezone->add('(GMT +1:00) Central European Time', '1');
188 $select_timezone->add('(GMT +2:00) EET: Tallinn, Helsinki, Kaliningrad, South Africa', '2');
189 $select_timezone->add('(GMT +3:00) Baghdad, Kuwait, Riyadh, Moscow, Nairobi', '3');
190 $select_timezone->add('(GMT +3:30) Tehran', '3.5');
191 $select_timezone->add('(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', '4');
192 $select_timezone->add('(GMT +4:30) Kabul', '4.5');
193 $select_timezone->add('(GMT +5:00) Ekaterinburg, Islamabad, Karachi', '5');
194 $select_timezone->add('(GMT +5:30) Chennai, Kolkata, Mumbai, New Delhi', '5.5');
195 $select_timezone->add('(GMT +5:45) Kathmandu', '5.75');
196 $select_timezone->add('(GMT +6:00) Almaty, Dhaka, Colombo', '6');
197 $select_timezone->add('(GMT +6:30) Cocos Islands, Myanmar', '6.5');
198 $select_timezone->add('(GMT +7:00) Bangkok, Hanoi, Jakarta', '7');
199 $select_timezone->add('(GMT +8:00) Beijing, Perth, Singapore, Taipei', '8');
200 $select_timezone->add('(GMT +8:45) Caiguna, Eucla, Border Village', '8.75');
201 $select_timezone->add('(GMT +9:00) Tokyo, Seoul, Yakutsk', '9');
202 $select_timezone->add('(GMT +9:30) Adelaide, Darwin', '9.5');
203 $select_timezone->add('(GMT +10:00) EAST/AEST: Sydney, Guam, Vladivostok', '10');
204 $select_timezone->add('(GMT +10:30) New South Wales', '10.5');
205 $select_timezone->add('(GMT +11:00) Magadan, Solomon Islands', '11');
206 $select_timezone->add('(GMT +11:30) Norfolk Island', '11.5');
207 $select_timezone->add('(GMT +12:00) Auckland, Wellington, Kamchatka', '12');
208 $select_timezone->add('(GMT +12:45) Chatham Islands', '12.75');
209 $select_timezone->add('(GMT +13:00) Tonga, Pheonix Islands', '13');
210 $select_timezone->add('(GMT +14:00) Kiribati', '14');
212 $blocks['main']['options']['timezone'] = array(
213 'title' => html::label($field_id, Q(rcube_label('timezone'))),
214 'content' => $select_timezone->show((string)$config['timezone']),
219 if (!isset($no_override['dst_active'])) {
220 $field_id = 'rcmfd_dst';
221 $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] === 'auto')));
223 $blocks['main']['options']['dstactive'] = array(
224 'title' => html::label($field_id, Q(rcube_label('dstactive'))),
225 'content' => $input_dst->show($config['dst_active']),
229 // MM: Show checkbox for toggling 'pretty dates'
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));
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),
240 // show page size selection
241 if (!isset($no_override['pagesize'])) {
242 $field_id = 'rcmfd_pgsize';
243 $input_pagesize = new html_inputfield(array('name' => '_pagesize', 'id' => $field_id, 'size' => 5));
245 $blocks['list']['options']['pagesize'] = array(
246 'title' => html::label($field_id, Q(rcube_label('pagesize'))),
247 'content' => $input_pagesize->show($config['pagesize']),
251 // Show checkbox for toggling 'index_sort'
252 if (!isset($no_override['index_sort'])) {
253 $field_id = 'rcmfd_indexsort';
254 $input_indexsort = new html_checkbox(array('name' => '_index_sort', 'id' => $field_id, 'value' => 1));
256 $blocks['list']['options']['index_sort'] = array(
257 'title' => html::label($field_id, Q(rcube_label('indexsort'))),
258 'content' => $input_indexsort->show($config['index_sort']?1:0),
262 // show drop-down for available skins
263 if (!isset($no_override['skin'])) {
264 $skins = rcmail_get_skins();
266 if (count($skins) > 1) {
267 $field_id = 'rcmfd_skin';
268 $input_skin = new html_select(array('name'=>'_skin', 'id'=>$field_id));
270 foreach($skins as $skin)
271 $input_skin->add($skin, $skin);
273 $blocks['main']['options']['skin'] = array(
274 'title' => html::label($field_id, Q(rcube_label('skin'))),
275 'content' => $input_skin->show($config['skin']),
282 // Mailbox view (mail screen)
286 'main' => array('name' => Q(rcube_label('mainoptions'))),
287 'new_message' => array('name' => Q(rcube_label('newmessage'))),
290 // show config parameter for preview pane
291 if (!isset($no_override['preview_pane'])) {
292 $field_id = 'rcmfd_preview';
293 $input_preview = new html_checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1));
295 $blocks['main']['options']['preview_pane'] = array(
296 'title' => html::label($field_id, Q(rcube_label('previewpane'))),
297 'content' => $input_preview->show($config['preview_pane']?1:0),
301 if (!isset($no_override['mdn_requests'])) {
302 $field_id = 'rcmfd_mdn_requests';
303 $select_mdn_requests = new html_select(array('name' => '_mdn_requests', 'id' => $field_id));
304 $select_mdn_requests->add(rcube_label('askuser'), 0);
305 $select_mdn_requests->add(rcube_label('autosend'), 1);
306 $select_mdn_requests->add(rcube_label('ignore'), 2);
308 $blocks['main']['options']['mdn_requests'] = array(
309 'title' => html::label($field_id, Q(rcube_label('mdnrequests'))),
310 'content' => $select_mdn_requests->show($config['mdn_requests']),
314 if (!isset($no_override['focus_on_new_message'])) {
315 $field_id = 'rcmfd_focus_on_new_message';
316 $input_focus_on_new_message = new html_checkbox(array('name' => '_focus_on_new_message', 'id' => $field_id, 'value' => 1));
318 $blocks['new_message']['options']['focus_on_new_message'] = array(
319 'title' => html::label($field_id, Q(rcube_label('focusonnewmessage'))),
320 'content' => $input_focus_on_new_message->show($config['focus_on_new_message']?1:0),
324 if (!isset($no_override['keep_alive'])) {
325 $field_id = 'rcmfd_keep_alive';
326 $select_keep_alive = new html_select(array('name' => '_keep_alive', 'id' => $field_id));
328 foreach(array(1, 3, 5, 10, 15, 30, 60) as $min)
329 if((!$config['min_keep_alive'] || $config['min_keep_alive'] <= $min * 60)
330 && (!$config['session_lifetime'] || $config['session_lifetime'] > $min)) {
331 $select_keep_alive->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min);
334 $blocks['new_message']['options']['keep_alive'] = array(
335 'title' => html::label($field_id, Q(rcube_label('keepalive'))),
336 'content' => $select_keep_alive->show($config['keep_alive']/60),
340 if (!isset($no_override['check_all_folders'])) {
341 $field_id = 'rcmfd_check_all_folders';
342 $input_check_all = new html_checkbox(array('name' => '_check_all_folders', 'id' => $field_id, 'value' => 1));
344 $blocks['new_message']['options']['check_all_folders'] = array(
345 'title' => html::label($field_id, Q(rcube_label('checkallfolders'))),
346 'content' => $input_check_all->show($config['check_all_folders']?1:0),
356 'main' => array('name' => Q(rcube_label('mainoptions'))),
359 // show checkbox for HTML/plaintext messages
360 if (!isset($no_override['prefer_html'])) {
361 $field_id = 'rcmfd_htmlmsg';
362 $input_preferhtml = new html_checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1,
363 'onchange' => JS_OBJECT_NAME.'.toggle_prefer_html(this)'));
365 $blocks['main']['options']['prefer_html'] = array(
366 'title' => html::label($field_id, Q(rcube_label('preferhtml'))),
367 'content' => $input_preferhtml->show($config['prefer_html']?1:0),
371 if (!isset($no_override['show_images'])) {
372 $field_id = 'rcmfd_show_images';
373 $input_show_images = new html_select(array('name' => '_show_images', 'id' => $field_id));
374 $input_show_images->add(rcube_label('never'), 0);
375 $input_show_images->add(rcube_label('fromknownsenders'), 1);
376 $input_show_images->add(rcube_label('always'), 2);
378 $blocks['main']['options']['show_images'] = array(
379 'title' => html::label($field_id, Q(rcube_label('showremoteimages'))),
380 'content' => $input_show_images->show($config['show_images']),
384 if (!isset($no_override['inline_images'])) {
385 $field_id = 'rcmfd_inline_images';
386 $input_inline_images = new html_checkbox(array('name' => '_inline_images', 'id' => $field_id, 'value' => 1));
388 $blocks['main']['options']['inline_images'] = array(
389 'title' => html::label($field_id, Q(rcube_label('showinlineimages'))),
390 'content' => $input_inline_images->show($config['inline_images']?1:0),
394 // "display after delete" checkbox
395 if (!isset($no_override['display_next'])) {
396 $field_id = 'rcmfd_displaynext';
397 $input_displaynext = new html_checkbox(array('name' => '_display_next', 'id' => $field_id, 'value' => 1));
399 $blocks['main']['options']['display_next'] = array(
400 'title' => html::label($field_id, Q(rcube_label('displaynext'))),
401 'content' => $input_displaynext->show($config['display_next']?1:0),
411 'main' => array('name' => Q(rcube_label('mainoptions'))),
414 // Show checkbox for HTML Editor
415 if (!isset($no_override['htmleditor'])) {
416 $field_id = 'rcmfd_htmleditor';
417 $input_htmleditor = new html_checkbox(array('name' => '_htmleditor', 'id' => $field_id, 'value' => 1));
419 $blocks['main']['options']['htmleditor'] = array(
420 'title' => html::label($field_id, Q(rcube_label('htmleditor'))),
421 'content' => $input_htmleditor->show($config['htmleditor']?1:0),
425 if (!isset($no_override['draft_autosave'])) {
426 $field_id = 'rcmfd_autosave';
427 $select_autosave = new html_select(array('name' => '_draft_autosave', 'id' => $field_id, 'disabled' => empty($config['drafts_mbox'])));
428 $select_autosave->add(rcube_label('never'), 0);
429 foreach (array(1, 3, 5, 10) as $i => $min)
430 $select_autosave->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min*60);
432 $blocks['main']['options']['draft_autosave'] = array(
433 'title' => html::label($field_id, Q(rcube_label('autosavedraft'))),
434 'content' => $select_autosave->show($config['draft_autosave']),
438 if (!isset($no_override['mime_param_folding'])) {
439 $field_id = 'rcmfd_param_folding';
440 $select_param_folding = new html_select(array('name' => '_mime_param_folding', 'id' => $field_id));
441 $select_param_folding->add(rcube_label('2231folding'), 0);
442 $select_param_folding->add(rcube_label('miscfolding'), 1);
443 $select_param_folding->add(rcube_label('2047folding'), 2);
445 $blocks['main']['options']['mime_param_folding'] = array(
447 'title' => html::label($field_id, Q(rcube_label('mimeparamfolding'))),
448 'content' => $select_param_folding->show($config['mime_param_folding']),
454 // Special IMAP folders
458 'main' => array('name' => Q(rcube_label('mainoptions'))),
461 // Configure special folders
462 if (!isset($no_override['default_imap_folders'])) {
463 $RCMAIL->imap_init(true);
464 $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true,
465 'maxlength' => 30, 'exceptions' => array('INBOX')));
467 if (!isset($no_override['drafts_mbox']))
468 $blocks['main']['options']['drafts_mbox'] = array(
469 'title' => Q(rcube_label('drafts')),
470 'content' => $select->show($config['drafts_mbox'], array('name' => "_drafts_mbox")),
473 if (!isset($no_override['sent_mbox']))
474 $blocks['main']['options']['sent_mbox'] = array(
475 'title' => Q(rcube_label('sent')),
476 'content' => $select->show($config['sent_mbox'], array('name' => "_sent_mbox")),
479 if (!isset($no_override['junk_mbox']))
480 $blocks['main']['options']['junk_mbox'] = array(
481 'title' => Q(rcube_label('junk')),
482 'content' => $select->show($config['junk_mbox'], array('name' => "_junk_mbox")),
485 if (!isset($no_override['trash_mbox']))
486 $blocks['main']['options']['trash_mbox'] = array(
487 'title' => Q(rcube_label('trash')),
488 'content' => $select->show($config['trash_mbox'], array('name' => "_trash_mbox")),
498 'main' => array('name' => Q(rcube_label('mainoptions'))),
499 'maintenance' => array('name' => Q(rcube_label('maintenance'))),
502 if (!isset($no_override['read_when_deleted'])) {
503 $field_id = 'rcmfd_read_deleted';
504 $input_readdeleted = new html_checkbox(array('name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1));
506 $blocks['main']['options']['read_when_deleted'] = array(
507 'title' => html::label($field_id, Q(rcube_label('readwhendeleted'))),
508 'content' => $input_readdeleted->show($config['read_when_deleted']?1:0),
512 if (!isset($no_override['flag_for_deletion'])) {
513 $field_id = 'rcmfd_flag_for_deletion';
514 $input_flagfordeletion = new html_checkbox(array('name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1));
516 $blocks['main']['options']['flag_for_deletion'] = array(
517 'title' => html::label($field_id, Q(rcube_label('flagfordeletion'))),
518 'content' => $input_flagfordeletion->show($config['flag_for_deletion']?1:0),
522 // don't show deleted messages
523 if (!isset($no_override['skip_deleted'])) {
524 $field_id = 'rcmfd_skip_deleted';
525 $input_purge = new html_checkbox(array('name' => '_skip_deleted', 'id' => $field_id, 'value' => 1));
527 $blocks['main']['options']['skip_deleted'] = array(
528 'title' => html::label($field_id, Q(rcube_label('skipdeleted'))),
529 'content' => $input_purge->show($config['skip_deleted']?1:0),
533 // Trash purging on logout
534 if (!isset($no_override['logout_purge'])) {
535 $field_id = 'rcmfd_logout_purge';
536 $input_purge = new html_checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
538 $blocks['maintenance']['options']['logout_purge'] = array(
539 'title' => html::label($field_id, Q(rcube_label('logoutclear'))),
540 'content' => $input_purge->show($config['logout_purge']?1:0),
544 // INBOX compacting on logout
545 if (!isset($no_override['logout_expunge'])) {
546 $field_id = 'rcmfd_logout_expunge';
547 $input_expunge = new html_checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
549 $blocks['maintenance']['options']['logout_expunge'] = array(
550 'title' => html::label($field_id, Q(rcube_label('logoutcompact'))),
551 'content' => $input_expunge->show($config['logout_expunge']?1:0),
558 $data = $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $sect['id'], 'blocks' => $blocks));
562 foreach ($data['blocks'] as $block) {
563 if ($block['options']) {
564 foreach ($block['options'] as $option) {
572 unset($sections[$idx]);
574 $sections[$idx]['blocks'] = $data['blocks'];
577 return array($sections, $plugin['cols']);
581 function rcmail_get_skins()
586 $dir = opendir($path);
591 while (($file = readdir($dir)) !== false)
593 $filename = $path.'/'.$file;
594 if (is_dir($filename) && is_readable($filename)
595 && !in_array($file, array('.', '..', '.svn')))
605 // register UI objects
606 $OUTPUT->add_handlers(array(
607 'prefsframe' => 'rcmail_preferences_frame',
608 'sectionslist' => 'rcmail_sections_list',
609 'identitieslist' => 'rcmail_identities_list',