source: github/program/steps/settings/func.inc @ 3ca3bd4

HEADcourier-fixdev-browser-capabilitiespdorelease-0.6release-0.7release-0.8
Last change on this file since 3ca3bd4 was 3ca3bd4, checked in by thomascube <thomas@…>, 4 years ago

Add plugin hooks 'smtp_connect' and 'list_identities' (#1485954, #1485958)

  • Property mode set to 100644
File size: 20.0 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    $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
163   
164    if ($table->size())
165      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('uisettings'))) . $table->show($attrib));
166    break;
167
168
169  // Mailbox view (mail screen)
170  case 'mailbox':
171    $table = new html_table(array('cols' => 2));
172
173    if (!isset($no_override['focus_on_new_message'])) {
174      $field_id = 'rcmfd_focus_on_new_message';
175      $input_focus_on_new_message = new html_checkbox(array('name' => '_focus_on_new_message', 'id' => $field_id, 'value' => 1));
176      $table->add('title', html::label($field_id, Q(rcube_label('focusonnewmessage'))));
177      $table->add(null, $input_focus_on_new_message->show($config['focus_on_new_message']?1:0));
178    }
179
180    // show config parameter for preview pane
181    if (!isset($no_override['preview_pane'])) {
182      $field_id = 'rcmfd_preview';
183      $input_preview = new html_checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1));
184
185      $table->add('title', html::label($field_id, Q(rcube_label('previewpane'))));
186      $table->add(null, $input_preview->show($config['preview_pane']?1:0));
187    }
188
189    if (!isset($no_override['mdn_requests'])) {
190      $field_id = 'rcmfd_mdn_requests';
191      $select_mdn_requests = new html_select(array('name' => '_mdn_requests', 'id' => $field_id));
192      $select_mdn_requests->add(rcube_label('askuser'), 0);
193      $select_mdn_requests->add(rcube_label('autosend'), 1);
194      $select_mdn_requests->add(rcube_label('ignore'), 2);
195
196      $table->add('title', html::label($field_id, Q(rcube_label('mdnrequests'))));
197      $table->add(null, $select_mdn_requests->show($config['mdn_requests']));
198    }
199
200    if (!isset($no_override['keep_alive'])) {
201      $field_id = 'rcmfd_keep_alive';
202      $select_keep_alive = new html_select(array('name' => '_keep_alive', 'id' => $field_id));
203
204      foreach(array(1, 3, 5, 10, 15, 30, 60) as $min)
205        if((!$config['min_keep_alive'] || $config['min_keep_alive'] <= $min * 60)
206            && (!$config['session_lifetime'] || $config['session_lifetime'] > $min)) {
207          $select_keep_alive->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min);
208        }
209
210      $table->add('title', html::label($field_id, Q(rcube_label('keepalive'))));
211      $table->add(null, $select_keep_alive->show($config['keep_alive']/60));
212    }
213
214    if (!isset($no_override['check_all_folders'])) {
215      $field_id = 'rcmfd_check_all_folders';
216      $input_check_all = new html_checkbox(array('name' => '_check_all_folders', 'id' => $field_id, 'value' => 1));
217      $table->add('title', html::label($field_id, Q(rcube_label('checkallfolders'))));
218      $table->add(null, $input_check_all->show($config['check_all_folders']?1:0));
219    }
220
221    $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
222
223    if ($table->size())
224      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('mailboxview'))) . $table->show($attrib));
225    break;
226
227
228  // Message viewing
229  case 'mailview':
230    $table = new html_table(array('cols' => 2));
231
232    // show checkbox for HTML/plaintext messages
233    if (!isset($no_override['prefer_html'])) {
234      $field_id = 'rcmfd_htmlmsg';
235      $input_preferhtml = new html_checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1,
236        'onchange' => JS_OBJECT_NAME.'.toggle_prefer_html(this)'));
237
238      $table->add('title', html::label($field_id, Q(rcube_label('preferhtml'))));
239      $table->add(null, $input_preferhtml->show($config['prefer_html']?1:0));
240    }
241
242    if (!isset($no_override['show_images'])) {
243      $field_id = 'rcmfd_show_images';
244      $input_show_images = new html_select(array('name' => '_show_images', 'id' => $field_id));
245      $input_show_images->add(rcube_label('never'), 0);
246      $input_show_images->add(rcube_label('fromknownsenders'), 1);
247      $input_show_images->add(rcube_label('always'), 2);
248
249      $table->add('title', html::label($field_id, Q(rcube_label('showremoteimages'))));
250      $table->add(null, $input_show_images->show($config['show_images']));
251    }
252
253    if (!isset($no_override['inline_images'])) {
254      $field_id = 'rcmfd_inline_images';
255      $input_inline_images = new html_checkbox(array('name' => '_inline_images', 'id' => $field_id, 'value' => 1));
256
257      $table->add('title', html::label($field_id, Q(rcube_label('showinlineimages'))));
258      $table->add(null, $input_inline_images->show($config['inline_images']?1:0));
259    }
260
261    $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
262
263    if ($table->size())
264      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagesdisplaying'))) . $table->show($attrib));
265    break;
266
267
268  // Mail composition
269  case 'compose':
270    $table = new html_table(array('cols' => 2));
271
272    // Show checkbox for HTML Editor
273    if (!isset($no_override['htmleditor'])) {
274      $field_id = 'rcmfd_htmleditor';
275      $input_htmleditor = new html_checkbox(array('name' => '_htmleditor', 'id' => $field_id, 'value' => 1));
276
277      $table->add('title', html::label($field_id, Q(rcube_label('htmleditor'))));
278      $table->add(null, $input_htmleditor->show($config['htmleditor']?1:0));
279    }
280
281    if (!isset($no_override['draft_autosave'])) {
282      $field_id = 'rcmfd_autosave';
283      $select_autosave = new html_select(array('name' => '_draft_autosave', 'id' => $field_id, 'disabled' => empty($config['drafts_mbox'])));
284      $select_autosave->add(rcube_label('never'), 0);
285      foreach (array(1, 3, 5, 10) as $i => $min)
286        $select_autosave->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min*60);
287
288      $table->add('title', html::label($field_id, Q(rcube_label('autosavedraft'))));
289      $table->add(null, $select_autosave->show($config['draft_autosave']));
290    }
291
292    if (!isset($no_override['mime_param_folding'])) {
293      $field_id = 'rcmfd_param_folding';
294      $select_param_folding = new html_select(array('name' => '_mime_param_folding', 'id' => $field_id));
295      $select_param_folding->add(rcube_label('2231folding'), 0);
296      $select_param_folding->add(rcube_label('miscfolding'), 1);
297      $select_param_folding->add(rcube_label('2047folding'), 2);
298
299      $table->set_row_attribs('advanced');
300      $table->add('title', html::label($field_id, Q(rcube_label('mimeparamfolding'))));
301      $table->add(null, $select_param_folding->show($config['mime_param_folding']));
302    }
303
304    $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
305
306    if ($table->size())
307      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('messagescomposition'))) . $table->show($attrib));
308    break;
309
310
311  // Special IMAP folders
312  case 'folders':
313    // Configure special folders
314    if (!isset($no_override['default_imap_folders'])) {
315      $RCMAIL->imap_init(true);
316      $select = rcmail_mailbox_select(array('noselection' => '---', 'realnames' => true, 'maxlength' => 30));
317
318      $table = new html_table(array('cols' => 2));
319
320      if (!isset($no_override['drafts_mbox'])) {
321        $table->add('title', Q(rcube_label('drafts')));
322        $table->add(null, $select->show($config['drafts_mbox'], array('name' => "_drafts_mbox", 'onchange' => "document.getElementById('rcmfd_autosave').disabled=this.selectedIndex==0")));
323      }
324
325      if (!isset($no_override['sent_mbox'])) {
326        $table->add('title', Q(rcube_label('sent')));
327        $table->add(null, $select->show($config['sent_mbox'], array('name' => "_sent_mbox")));
328      }
329
330      if (!isset($no_override['junk_mbox'])) {
331        $table->add('title', Q(rcube_label('junk')));
332        $table->add(null, $select->show($config['junk_mbox'], array('name' => "_junk_mbox")));
333      }
334
335      if (!isset($no_override['trash_mbox'])) {
336        $table->add('title', Q(rcube_label('trash')));
337        $table->add(null, $select->show($config['trash_mbox'], array('name' => "_trash_mbox")));
338      }
339
340      $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
341
342      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('specialfolders'))) . $table->show($attrib));
343    }
344    break;
345
346
347  // Server settings
348  case 'server':
349    $table = new html_table(array('cols' => 2));
350
351    if (!isset($no_override['read_when_deleted'])) {
352      $field_id = 'rcmfd_read_deleted';
353      $input_readdeleted = new html_checkbox(array('name' => '_read_when_deleted', 'id' => $field_id, 'value' => 1));
354
355      $table->add('title', html::label($field_id, Q(rcube_label('readwhendeleted'))));
356      $table->add(null, $input_readdeleted->show($config['read_when_deleted']?1:0));
357    }
358
359    if (!isset($no_override['flag_for_deletion'])) {
360      $field_id = 'rcmfd_flag_for_deletion';
361      $input_flagfordeletion = new html_checkbox(array('name' => '_flag_for_deletion', 'id' => $field_id, 'value' => 1));
362
363      $table->add('title', html::label($field_id, Q(rcube_label('flagfordeletion'))));
364      $table->add(null, $input_flagfordeletion->show($config['flag_for_deletion']?1:0));
365    }
366
367    // don't show deleted messages
368    if (!isset($no_override['skip_deleted'])) {
369      $field_id = 'rcmfd_skip_deleted';
370      $input_purge = new html_checkbox(array('name' => '_skip_deleted', 'id' => $field_id, 'value' => 1));
371
372      $table->add('title', html::label($field_id, Q(rcube_label('skipdeleted'))));
373      $table->add(null, $input_purge->show($config['skip_deleted']?1:0));
374    }
375
376    // Trash purging on logout
377    if (!isset($no_override['logout_purge'])) {
378      $field_id = 'rcmfd_logout_purge';
379      $input_purge = new html_checkbox(array('name' => '_logout_purge', 'id' => $field_id, 'value' => 1));
380
381      $table->add('title', html::label($field_id, Q(rcube_label('logoutclear'))));
382      $table->add(null, $input_purge->show($config['logout_purge']?1:0));
383    }
384
385    // INBOX compacting on logout
386    if (!isset($no_override['logout_expunge'])) {
387      $field_id = 'rcmfd_logout_expunge';
388      $input_expunge = new html_checkbox(array('name' => '_logout_expunge', 'id' => $field_id, 'value' => 1));
389
390      $table->add('title', html::label($field_id, Q(rcube_label('logoutcompact'))));
391      $table->add(null, $input_expunge->show($config['logout_expunge']?1:0));
392    }
393
394    $RCMAIL->plugins->exec_hook('user_preferences', array('section' => $part, 'table' => $table));
395
396    if ($table->size())
397      $out = html::tag('fieldset', null, html::tag('legend', null, Q(rcube_label('serversettings'))) . $table->show($attrib));
398    break;
399
400
401    default:
402      $out = '';
403  }
404 
405  return $out;
406}
407
408
409function rcmail_identities_list($attrib)
410  {
411  global $OUTPUT, $USER, $RCMAIL;
412
413  // add id to message list table if not specified
414  if (!strlen($attrib['id']))
415    $attrib['id'] = 'rcmIdentitiesList';
416
417  // get all identites from DB and define list of cols to be displayed
418  $plugin = $RCMAIL->plugins->exec_hook('list_identities', array(
419    'list' => $USER->list_identities(),
420    'cols' => array('name', 'email')));
421
422  // create XHTML table 
423  $out = rcube_table_output($attrib, $plugin['list'], $plugin['cols'], 'identity_id');
424 
425  // set client env
426  $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
427
428  return $out;
429  }
430
431
432
433// similar function as in /steps/addressbook/edit.inc
434function get_form_tags($attrib, $action, $add_hidden=array())
435  {
436  global $EDIT_FORM, $RCMAIL;
437
438  $form_start = '';
439  if (!strlen($EDIT_FORM))
440    {
441    $hiddenfields = new html_hiddenfield(array('name' => '_task', 'value' => $RCMAIL->task));
442    $hiddenfields->add(array('name' => '_action', 'value' => $action));
443   
444    if ($add_hidden)
445      $hiddenfields->add($add_hidden);
446   
447    $form_start = !strlen($attrib['form']) ? $RCMAIL->output->form_tag(array('name' => "form", 'method' => "post")) : '';
448    $form_start .= $hiddenfields->show();
449    }
450   
451  $form_end = (!strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
452  $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
453
454  if (!strlen($EDIT_FORM))
455    $RCMAIL->output->add_gui_object('editform', $form_name);
456 
457  $EDIT_FORM = $form_name;
458
459  return array($form_start, $form_end);
460  }
461
462function rcmail_get_skins()
463  {
464  $path = 'skins';
465  $skins = array();
466
467  $dir = opendir($path);
468 
469  if (!$dir)
470        return false;
471 
472  while (($file = readdir($dir)) !== false)
473    {
474    $filename = $path.'/'.$file;
475    if (is_dir($filename) && is_readable($filename)
476        && !in_array($file, array('.', '..', '.svn')))
477      $skins[] = $file;
478    }
479
480  closedir($dir);
481
482  return $skins;
483  }
484
485
486// register UI objects
487$OUTPUT->add_handlers(array(
488  'userprefs' => 'rcmail_user_prefs_form',
489  'identitieslist' => 'rcmail_identities_list',
490  'itentitieslist' => 'rcmail_identities_list'  // keep this for backward compatibility
491));
492
493?>
Note: See TracBrowser for help on using the repository browser.