alecpl
2008-12-04 2a41355776b1c1bc82255b5712267b0368b51d10
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/settings/func.inc                                       |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
f11541 8  | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Provide functionality for user's settings & preferences             |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
681969 22 if (!$OUTPUT->ajax_call)
A 23   $OUTPUT->set_pagetitle(rcube_label('preferences'));
4e17e6 24
T 25 function rcmail_user_prefs_form($attrib)
6d6e06 26 {
5b8215 27   global $RCMAIL;
A 28   $config = $RCMAIL->config->all();
4e17e6 29
5b8215 30   $no_override = is_array($config['dont_override']) ? array_flip($config['dont_override']) : array();
b19097 31
10a699 32   // add some labels to client
112c91 33   $RCMAIL->output->add_label('nopagesizewarning');
10a699 34   
4e17e6 35   list($form_start, $form_end) = get_form_tags($attrib, 'save-prefs');
T 36   unset($attrib['form']);
37
6d6e06 38   $out = $form_start;
T 39   $table = new html_table(array('cols' => 2));
4e17e6 40
T 41   // show language selection
6d6e06 42   if (!isset($no_override['language'])) {
1854c4 43     $a_lang = $RCMAIL->list_languages();
b19097 44     asort($a_lang);
cd900d 45   
b19097 46     $field_id = 'rcmfd_lang';
47124c 47     $select_lang = new html_select(array('name' => '_language', 'id' => $field_id));
b19097 48     $select_lang->add(array_values($a_lang), array_keys($a_lang));
cd900d 49   
6d6e06 50     $table->add('title', html::label($field_id, Q(rcube_label('language'))));
cc669e 51     $table->add(null, $select_lang->show($RCMAIL->user->language));
6d6e06 52   }
4e17e6 53
T 54
55   // show page size selection
6d6e06 56   if (!isset($no_override['timezone'])) {
b19097 57     $field_id = 'rcmfd_timezone';
c8ae24 58     $select_timezone = new html_select(array('name' => '_timezone', 'id' => $field_id, 'onchange' => "document.getElementById('rcmfd_dst').disabled=this.selectedIndex==0"));
T 59     $select_timezone->add(rcube_label('autodetect'), 'auto');
b19097 60     $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11');
T 61     $select_timezone->add('(GMT -10:00) Hawaii', '-10');
c8b982 62     $select_timezone->add('(GMT -9:30) Marquesas Islands', '-9.5');
b19097 63     $select_timezone->add('(GMT -9:00) Alaska', '-9');
T 64     $select_timezone->add('(GMT -8:00) Pacific Time (US/Canada)', '-8');
65     $select_timezone->add('(GMT -7:00) Mountain Time (US/Canada)', '-7');
66     $select_timezone->add('(GMT -6:00) Central Time (US/Canada), Mexico City', '-6');
67     $select_timezone->add('(GMT -5:00) Eastern Time (US/Canada), Bogota, Lima', '-5');
c8b982 68     $select_timezone->add('(GMT -4:30) Caracas', '-4.5');
A 69     $select_timezone->add('(GMT -4:00) Atlantic Time (Canada), La Paz', '-4');
b19097 70     $select_timezone->add('(GMT -3:30) Nfld Time (Canada), Nfld, S. Labador', '-3.5');
c8b982 71     $select_timezone->add('(GMT -3:00) Brazil, Buenos Aires, Georgetown', '-3');
b19097 72     $select_timezone->add('(GMT -2:00) Mid-Atlantic', '-2');
T 73     $select_timezone->add('(GMT -1:00) Azores, Cape Verde Islands', '-1');
74     $select_timezone->add('(GMT) Western Europe, London, Lisbon, Casablanca', '0');
75     $select_timezone->add('(GMT +1:00) Central European Time', '1');
76     $select_timezone->add('(GMT +2:00) EET: Kaliningrad, South Africa', '2');
77     $select_timezone->add('(GMT +3:00) Baghdad, Kuwait, Riyadh, Moscow, Nairobi', '3');
78     $select_timezone->add('(GMT +3:30) Tehran', '3.5');
79     $select_timezone->add('(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', '4');
80     $select_timezone->add('(GMT +4:30) Kabul', '4.5');
81     $select_timezone->add('(GMT +5:00) Ekaterinburg, Islamabad, Karachi', '5');
82     $select_timezone->add('(GMT +5:30) Chennai, Kolkata, Mumbai, New Delhi', '5.5');
83     $select_timezone->add('(GMT +5:45) Kathmandu', '5.75');
84     $select_timezone->add('(GMT +6:00) Almaty, Dhaka, Colombo', '6');
c8b982 85     $select_timezone->add('(GMT +6:30) Cocos Islands, Myanmar', '6.5');
b19097 86     $select_timezone->add('(GMT +7:00) Bangkok, Hanoi, Jakarta', '7');
T 87     $select_timezone->add('(GMT +8:00) Beijing, Perth, Singapore, Taipei', '8');
c8b982 88     $select_timezone->add('(GMT +8:45) Caiguna, Eucla, Border Village', '8.75');
b19097 89     $select_timezone->add('(GMT +9:00) Tokyo, Seoul, Yakutsk', '9');
T 90     $select_timezone->add('(GMT +9:30) Adelaide, Darwin', '9.5');
2ad77d 91     $select_timezone->add('(GMT +10:00) EAST/AEST: Sydney, Guam, Vladivostok', '10');
c8b982 92     $select_timezone->add('(GMT +10:30) New South Wales', '10.5');
b19097 93     $select_timezone->add('(GMT +11:00) Magadan, Solomon Islands', '11');
c8b982 94     $select_timezone->add('(GMT +11:30) Norfolk Island', '11.5');
b19097 95     $select_timezone->add('(GMT +12:00) Auckland, Wellington, Kamchatka', '12');
c8b982 96     $select_timezone->add('(GMT +12:45) Chatham Islands', '12.75');
b19097 97     $select_timezone->add('(GMT +13:00) Tonga, Pheonix Islands', '13');
T 98     $select_timezone->add('(GMT +14:00) Kiribati', '14');
4e17e6 99   
6d6e06 100     $table->add('title', html::label($field_id, Q(rcube_label('timezone'))));
T 101     $table->add(null, $select_timezone->show((string)$config['timezone']));
102   }
4e17e6 103
b19097 104   // daylight savings
6d6e06 105   if (!isset($no_override['dst_active'])) {
b19097 106     $field_id = 'rcmfd_dst';
62784a 107     $input_dst = new html_checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1, 'disabled' => ($config['timezone'] === 'auto')));
6d6e06 108     
T 109     $table->add('title', html::label($field_id, Q(rcube_label('dstactive'))));
110     $table->add(null, $input_dst->show($config['dst_active']));
111   }
4647e1 112
30233b 113   // MM: Show checkbox for toggling 'pretty dates' 
6d6e06 114   if (!isset($no_override['prettydate'])) {
b19097 115     $field_id = 'rcmfd_prettydate';
47124c 116     $input_prettydate = new html_checkbox(array('name' => '_pretty_date', 'id' => $field_id, 'value' => 1));
30233b 117
6d6e06 118     $table->add('title', html::label($field_id, Q(rcube_label('prettydate'))));
T 119     $table->add(null, $input_prettydate->show($config['prettydate']?1:0));
120   }
b19097 121
f0d4b7 122   // show page size selection
6d6e06 123   if (!isset($no_override['pagesize'])) {
f0d4b7 124     $field_id = 'rcmfd_pgsize';
A 125     $input_pagesize = new html_inputfield(array('name' => '_pagesize', 'id' => $field_id, 'size' => 5));
b19097 126
6d6e06 127     $table->add('title', html::label($field_id, Q(rcube_label('pagesize'))));
T 128     $table->add(null, $input_pagesize->show($config['pagesize']));
129   }
d9b29a 130
3b6b91 131   // show drop-down for available skins
6d6e06 132   if (!isset($no_override['skin'])) {
3b6b91 133     $skins = rcmail_get_skins();
d9b29a 134
6d6e06 135     if (count($skins) > 1) {
3b6b91 136       $field_id = 'rcmfd_skin';
A 137       $input_skin = new html_select(array('name'=>'_skin', 'id'=>$field_id));
138       
139       foreach($skins as $skin)
140         $input_skin->add($skin, $skin);
141
6d6e06 142       $table->add('title', html::label($field_id, Q(rcube_label('skin'))));
T 143       $table->add(null, $input_skin->show($config['skin']));
d9b29a 144     }
6d6e06 145   }
d9b29a 146
6d6e06 147   $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('uisettings'))) . $table->show($attrib));
T 148   
149   $table = new html_table(array('cols' => 2));
d9b29a 150
06343d 151   if (!isset($no_override['focus_on_new_message'])) {
A 152     $field_id = 'rcmfd_focus_on_new_message';
153     $input_focus_on_new_message = new html_checkbox(array('name' => '_focus_on_new_message', 'id' => $field_id, 'value' => 1));
154     $table->add('title', html::label($field_id, Q(rcube_label('focusonnewmessage'))));
155     $table->add(null, $input_focus_on_new_message->show($config['focus_on_new_message']?1:0));
156   }
157
b19097 158   // show config parameter for preview pane
6d6e06 159   if (!isset($no_override['preview_pane'])) {
b19097 160     $field_id = 'rcmfd_preview';
47124c 161     $input_preview = new html_checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1));
6d6e06 162     
T 163     $table->add('title', html::label($field_id, Q(rcube_label('previewpane'))));
164     $table->add(null, $input_preview->show($config['preview_pane']?1:0));
165   }
3b6b91 166
6d6e06 167   if (!isset($no_override['mdn_requests'])) {
3b6b91 168     $field_id = 'rcmfd_mdn_requests';
A 169     $select_mdn_requests = new html_select(array('name' => '_mdn_requests', 'id' => $field_id));
170     $select_mdn_requests->add(rcube_label('askuser'), 0);
171     $select_mdn_requests->add(rcube_label('autosend'), 1);
172     $select_mdn_requests->add(rcube_label('ignore'), 2);
173
6d6e06 174     $table->add('title', html::label($field_id, Q(rcube_label('mdnrequests'))));
T 175     $table->add(null, $select_mdn_requests->show($config['mdn_requests']));
176   }
a901aa 177
95d90f 178   if (!isset($no_override['keep_alive'])) {
A 179     $field_id = 'rcmfd_keep_alive';
180     $select_keep_alive = new html_select(array('name' => '_keep_alive', 'id' => $field_id));
181
182     foreach(array(1, 3, 5, 10, 15, 30, 60) as $min)
183       if((!$config['min_keep_alive'] || $config['min_keep_alive'] <= $min * 60)
2fd975 184           && (!$config['session_lifetime'] || $config['session_lifetime'] > $min)) {
95d90f 185         $select_keep_alive->add(rcube_label(array('name' => 'keepaliveevery', 'vars' => array('n' => $min))), $min);
A 186       }
187
188     $table->add('title', html::label($field_id, Q(rcube_label('keepalive'))));
189     $table->add(null, $select_keep_alive->show($config['keep_alive']/60));
190   }
191
2fd975 192   if (!isset($no_override['check_all_folders'])) {
T 193     $field_id = 'rcmfd_check_all_folders';
194     $input_check_all = new html_checkbox(array('name' => '_check_all_folders', 'id' => $field_id, 'value' => 1));
195     $table->add('title', html::label($field_id, Q(rcube_label('checkallfolders'))));
196     $table->add(null, $input_check_all->show($config['check_all_folders']?1:0));
197   }
198
6d6e06 199   $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('mailboxview'))) . $table->show($attrib));
T 200
201   $table = new html_table(array('cols' => 2));
f0d4b7 202
A 203   // show checkbox for HTML/plaintext messages
6d6e06 204   if (!isset($no_override['prefer_html'])) {
f0d4b7 205     $field_id = 'rcmfd_htmlmsg';
A 206     $input_preferhtml = new html_checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1,
6d6e06 207       'onchange' => JS_OBJECT_NAME.'.toggle_prefer_html(this)'));
f0d4b7 208
6d6e06 209     $table->add('title', html::label($field_id, Q(rcube_label('preferhtml'))));
T 210     $table->add(null, $input_preferhtml->show($config['prefer_html']?1:0));
211   }
f0d4b7 212
2a4135 213   if (!isset($no_override['show_images'])) {
A 214     $field_id = 'rcmfd_show_images';
215     $input_show_images = new html_select(array('name' => '_show_images', 'id' => $field_id));
216     $input_show_images->add(rcube_label('never'), 0);
217     $input_show_images->add(rcube_label('fromknownsenders'), 1);
218     $input_show_images->add(rcube_label('always'), 2);
f0d4b7 219
2a4135 220     $table->add('title', html::label($field_id, Q(rcube_label('showremoteimages'))));
A 221     $table->add(null, $input_show_images->show($config['show_images']));
6d6e06 222   }
f0d4b7 223
6d6e06 224   if (!isset($no_override['inline_images'])) {
166b61 225     $field_id = 'rcmfd_inline_images';
A 226     $input_inline_images = new html_checkbox(array('name' => '_inline_images', 'id' => $field_id, 'value' => 1));
227
6d6e06 228     $table->add('title', html::label($field_id, Q(rcube_label('showinlineimages'))));
T 229     $table->add(null, $input_inline_images->show($config['inline_images']?1:0));
230   }
166b61 231
6d6e06 232   $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagesdisplaying'))) . $table->show($attrib));
T 233   
234   $table = new html_table(array('cols' => 2));
f0d4b7 235
A 236   // Show checkbox for HTML Editor
6d6e06 237   if (!isset($no_override['htmleditor'])) {
f0d4b7 238     $field_id = 'rcmfd_htmleditor';
A 239     $input_htmleditor = new html_checkbox(array('name' => '_htmleditor', 'id' => $field_id, 'value' => 1));
6d6e06 240     
T 241     $table->add('title', html::label($field_id, Q(rcube_label('htmleditor'))));
242     $table->add(null, $input_htmleditor->show($config['htmleditor']?1:0));
243   }
b19097 244                   
cb3538 245   if (!isset($no_override['draft_autosave'])) {
d656f1 246     $field_id = 'rcmfd_autosave';
cb3538 247     $select_autosave = new html_select(array('name' => '_draft_autosave', 'id' => $field_id, 'disabled' => empty($config['drafts_mbox'])));
d656f1 248     $select_autosave->add(rcube_label('never'), 0);
T 249     foreach (array(3, 5, 10) as $i => $min)
250       $select_autosave->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min*60);
251
6d6e06 252     $table->add('title', html::label($field_id, Q(rcube_label('autosavedraft'))));
T 253     $table->add(null, $select_autosave->show($config['draft_autosave']));
254   }
4e17e6 255
ffae15 256   if (!isset($no_override['mime_param_folding'])) {
A 257     $field_id = 'rcmfd_param_folding';
258     $select_param_folding = new html_select(array('name' => '_mime_param_folding', 'id' => $field_id));
259     $select_param_folding->add(rcube_label('2231folding'), 0);
260     $select_param_folding->add(rcube_label('miscfolding'), 1);
261     $select_param_folding->add(rcube_label('2047folding'), 2);
262
263     $table->set_row_attribs('advanced');
264     $table->add('title', html::label($field_id, Q(rcube_label('mimeparamfolding'))));
265     $table->add(null, $select_param_folding->show($config['mime_param_folding']));
266   }
267
6d6e06 268   $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagescomposition'))) . $table->show($attrib));
f0d4b7 269
cb3538 270   // Configure special folders
64f20d 271   if (!isset($no_override['default_imap_folders'])) {
cb3538 272     $RCMAIL->imap_init(true);
a81be1 273     $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true, 'maxlength' => 30));
cb3538 274     
T 275     $table = new html_table(array('cols' => 2));
276
e98809 277     if (!isset($no_override['drafts_mbox'])) {
A 278       $table->add('title', Q(rcube_label('drafts')));
279       $table->add(null, $select->show($config['drafts_mbox'], array('name' => "_drafts_mbox", 'onchange' => "document.getElementById('rcmfd_autosave').disabled=this.selectedIndex==0")));
280     }
281
282     if (!isset($no_override['sent_mbox'])) {
283       $table->add('title', Q(rcube_label('sent')));
284       $table->add(null, $select->show($config['sent_mbox'], array('name' => "_sent_mbox")));
285     }
286
287     if (!isset($no_override['junk_mbox'])) {
288       $table->add('title', Q(rcube_label('junk')));
289       $table->add(null, $select->show($config['junk_mbox'], array('name' => "_junk_mbox")));
290     }
291
292     if (!isset($no_override['trash_mbox'])) {
293       $table->add('title', Q(rcube_label('trash')));
294       $table->add(null, $select->show($config['trash_mbox'], array('name' => "_trash_mbox")));
295     }
296
cb3538 297     $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('specialfolders'))) . $table->show($attrib));
T 298   }
299
6d6e06 300   $table = new html_table(array('cols' => 2));
T 301
302   if (!isset($no_override['read_when_deleted'])) {
d9b29a 303     $field_id = 'rcmfd_read_deleted';
A 304     $input_readdeleted = new html_checkbox(array('name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1));
6d6e06 305     
T 306     $table->add('title', html::label($field_id, Q(rcube_label('readwhendeleted'))));
307     $table->add(null, $input_readdeleted->show($config['read_when_deleted']?1:0));
308   }
d9b29a 309
6d6e06 310   if (!isset($no_override['flag_for_deletion'])) {
3044ae 311     $field_id = 'rcmfd_flag_for_deletion';
A 312     $input_flagfordeletion = new html_checkbox(array('name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1));
6d6e06 313     
T 314     $table->add('title', html::label($field_id, Q(rcube_label('flagfordeletion'))));
315     $table->add(null, $input_flagfordeletion->show($config['flag_for_deletion']?1:0));
316   }
9b3d7f 317   
A 318   // don't show deleted messages
319   if (!isset($no_override['skip_deleted'])) {
320     $field_id = 'rcmfd_skip_deleted';
321     $input_purge = new html_checkbox(array('name' => '_skip_deleted', 'id' => $field_id, 'value' => 1));
322     
323     $table->add('title', html::label($field_id, Q(rcube_label('skipdeleted'))));
324     $table->add(null, $input_purge->show($config['skip_deleted']?1:0));
325   }
06343d 326
eaa394 327   // Trash purging on logout
6d6e06 328   if (!isset($no_override['logout_purge'])) {
eaa394 329     $field_id = 'rcmfd_logout_purge';
47124c 330     $input_purge = new html_checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
6d6e06 331     
T 332     $table->add('title', html::label($field_id, Q(rcube_label('logoutclear'))));
333     $table->add(null, $input_purge->show($config['logout_purge']?1:0));
334   }
9b3d7f 335   
eaa394 336   // INBOX compacting on logout
6d6e06 337   if (!isset($no_override['logout_expunge'])) {
eaa394 338     $field_id = 'rcmfd_logout_expunge';
47124c 339     $input_expunge = new html_checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
eaa394 340
6d6e06 341     $table->add('title', html::label($field_id, Q(rcube_label('logoutcompact'))));
T 342     $table->add(null, $input_expunge->show($config['logout_expunge']?1:0));
343   }
4e17e6 344
6d6e06 345   $out .= html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('serversettings'))) . $table->show($attrib));
T 346
347   return $out . $form_end;
4e17e6 348   }
T 349
350
351
352 function rcmail_identities_list($attrib)
353   {
fba1f5 354   global $OUTPUT, $USER;
4e17e6 355
T 356   // add id to message list table if not specified
357   if (!strlen($attrib['id']))
358     $attrib['id'] = 'rcmIdentitiesList';
359
360   // define list of cols to be displayed
f645ce 361   $a_show_cols = array('name', 'email');
4e17e6 362
T 363   // create XHTML table  
fba1f5 364   $out = rcube_table_output($attrib, $USER->list_identities(), $a_show_cols, 'identity_id');
4e17e6 365   
T 366   // set client env
f11541 367   $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
4e17e6 368
T 369   return $out;
370   }
371
372
373
374 // similar function as in /steps/addressbook/edit.inc
375 function get_form_tags($attrib, $action, $add_hidden=array())
376   {
197601 377   global $EDIT_FORM, $RCMAIL;
4e17e6 378
T 379   $form_start = '';
380   if (!strlen($EDIT_FORM))
381     {
197601 382     $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
4e17e6 383     $hiddenfields->add(array('name' => '_action', 'value' => $action));
T 384     
385     if ($add_hidden)
386       $hiddenfields->add($add_hidden);
387     
197601 388     $form_start = !strlen($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
4e17e6 389     $form_start .= $hiddenfields->show();
T 390     }
391     
392   $form_end = (!strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
393   $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
394
395   if (!strlen($EDIT_FORM))
197601 396     $RCMAIL->output->add_gui_object('editform', $form_name);
4e17e6 397   
T 398   $EDIT_FORM = $form_name;
399
197601 400   return array($form_start, $form_end);
4e17e6 401   }
T 402
3b6b91 403 function rcmail_get_skins()
A 404   {
405   $path = 'skins';
406   $skins = array();
407
408   $dir = opendir($path);
409   
410   if (!$dir)
411     return false;
412   
413   while (($file = readdir($dir)) !== false)
414     {
415     $filename = $path.'/'.$file;
416     if (is_dir($filename) && is_readable($filename) 
417     && !in_array($file, array('.', '..', '.svn')))
418       $skins[] = $file;
419     }
420
421   closedir($dir);
422
423   return $skins;
424   }
425
ec0171 426
A 427 function rcmail_get_email()
428   {
429   global $RCMAIL;
430   
431   if (strpos($RCMAIL->user->data['username'], '@'))
432     return $RCMAIL->user->data['username'];
433   else {
434     if ($RCMAIL->config->get('virtuser_file'))
435       $user_email = rcube_user::user2email($RCMAIL->user->data['username']);
436
437     if ($user_email == '')
438       $user_email = sprintf('%s@%s', $RCMAIL->user->data['username'], 
439             $RCMAIL->config->mail_domain($_SESSION['imap_host']));
440
441     return $user_email;
442     }              
443   }
4e17e6 444
f11541 445 // register UI objects
T 446 $OUTPUT->add_handlers(array(
447   'userprefs' => 'rcmail_user_prefs_form',
b89d5a 448   'identitieslist' => 'rcmail_identities_list',
T 449   'itentitieslist' => 'rcmail_identities_list'  // keep this for backward compatibility
f11541 450 ));
T 451
452
2ad77d 453 ?>