source: subversion/branches/devel-api/program/steps/settings/func.inc @ 2326

Last change on this file since 2326 was 2326, checked in by ziba, 4 years ago

New Plugin: Use Imap Subscriptions Option - by default roundcube only lists subscribed folders, this introduces an option to ignore subscriptions
New Plugin Hook: list_mailboxes - allows a plugin to provide the list of mailboxes instead of roundcube core
New Plugin Hook: manage_folders - allows a plugin to modify the main table on the manage folders screen
New Plugin Hook: user_preferences_server_settings - allows a plugin to modify the user preferences server settings table
New Plugin Hook: save_preferences - allows a plugin to inject data into the array of preferences about to be saved
Change to html class: added a remove_column method to give plugins a greater ability to modify the interface

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