]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/settings/func.inc
Imported Upstream version 0.1
[roundcube.git] / program / steps / settings / func.inc
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: func.inc 1176 2008-03-03 21:47:59Z thomasb $
19
20 */
21
22
23 if ($USER->ID)
24   $OUTPUT->set_pagetitle(rcube_label('settingsfor') . " ". $USER->get_username());
25
26
27
28 function rcmail_user_prefs_form($attrib)
29   {
30   global $DB, $CONFIG, $sess_user_lang;
31
32   $no_override = is_array($CONFIG['dont_override']) ? array_flip($CONFIG['dont_override']) : array();
33
34   // add some labels to client
35   rcube_add_label('nopagesizewarning');
36   
37   list($form_start, $form_end) = get_form_tags($attrib, 'save-prefs');
38   unset($attrib['form']);
39
40   // allow the following attributes to be added to the <table> tag
41   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id', 'cellpadding', 'cellspacing', 'border', 'summary'));
42
43   // return the complete edit form as table
44   $out = "$form_start<table" . $attrib_str . ">\n\n";
45
46   // show language selection
47   if (!isset($no_override['language']))
48     {
49     $a_lang = rcube_list_languages();
50     asort($a_lang);
51   
52     $field_id = 'rcmfd_lang';
53     $select_lang = new select(array('name' => '_language', 'id' => $field_id));
54     $select_lang->add(array_values($a_lang), array_keys($a_lang));
55   
56     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
57                     $field_id,
58                     Q(rcube_label('language')),
59                     $select_lang->show($sess_user_lang));
60     }
61
62
63   // show page size selection
64   if (!isset($no_override['timezone']))
65     {
66     $field_id = 'rcmfd_timezone';
67     $select_timezone = new select(array('name' => '_timezone', 'id' => $field_id));
68     $select_timezone->add('(GMT -11:00) Midway Island, Samoa', '-11');
69     $select_timezone->add('(GMT -10:00) Hawaii', '-10');
70     $select_timezone->add('(GMT -9:00) Alaska', '-9');
71     $select_timezone->add('(GMT -8:00) Pacific Time (US/Canada)', '-8');
72     $select_timezone->add('(GMT -7:00) Mountain Time (US/Canada)', '-7');
73     $select_timezone->add('(GMT -6:00) Central Time (US/Canada), Mexico City', '-6');
74     $select_timezone->add('(GMT -5:00) Eastern Time (US/Canada), Bogota, Lima', '-5');
75     $select_timezone->add('(GMT -4:00) Atlantic Time (Canada), Caracas, La Paz', '-4');
76     $select_timezone->add('(GMT -3:00) Brazil, Buenos Aires, Georgetown', '-3');
77     $select_timezone->add('(GMT -3:30) Nfld Time (Canada), Nfld, S. Labador', '-3.5');
78     $select_timezone->add('(GMT -2:00) Mid-Atlantic', '-2');
79     $select_timezone->add('(GMT -1:00) Azores, Cape Verde Islands', '-1');
80     $select_timezone->add('(GMT) Western Europe, London, Lisbon, Casablanca', '0');
81     $select_timezone->add('(GMT +1:00) Central European Time', '1');
82     $select_timezone->add('(GMT +2:00) EET: Kaliningrad, South Africa', '2');
83     $select_timezone->add('(GMT +3:00) Baghdad, Kuwait, Riyadh, Moscow, Nairobi', '3');
84     $select_timezone->add('(GMT +3:30) Tehran', '3.5');
85     $select_timezone->add('(GMT +4:00) Abu Dhabi, Muscat, Baku, Tbilisi', '4');
86     $select_timezone->add('(GMT +4:30) Kabul', '4.5');
87     $select_timezone->add('(GMT +5:00) Ekaterinburg, Islamabad, Karachi', '5');
88     $select_timezone->add('(GMT +5:30) Chennai, Kolkata, Mumbai, New Delhi', '5.5');
89     $select_timezone->add('(GMT +5:45) Kathmandu', '5.75');
90     $select_timezone->add('(GMT +6:00) Almaty, Dhaka, Colombo', '6');
91     $select_timezone->add('(GMT +7:00) Bangkok, Hanoi, Jakarta', '7');
92     $select_timezone->add('(GMT +8:00) Beijing, Perth, Singapore, Taipei', '8');
93     $select_timezone->add('(GMT +9:00) Tokyo, Seoul, Yakutsk', '9');
94     $select_timezone->add('(GMT +9:30) Adelaide, Darwin', '9.5');
95     $select_timezone->add('(GMT +10:00) EAST/AEST: Sydney, Guam, Vladivostok', '10');
96     $select_timezone->add('(GMT +11:00) Magadan, Solomon Islands', '11');
97     $select_timezone->add('(GMT +12:00) Auckland, Wellington, Kamchatka', '12');
98     $select_timezone->add('(GMT +13:00) Tonga, Pheonix Islands', '13');
99     $select_timezone->add('(GMT +14:00) Kiribati', '14');
100   
101   
102     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
103                     $field_id,
104                     Q(rcube_label('timezone')),
105                     $select_timezone->show((string)$CONFIG['timezone']));
106     }
107
108   // daylight savings
109   if (!isset($no_override['dst_active']))
110     {
111     $field_id = 'rcmfd_dst';
112     $input_dst = new checkbox(array('name' => '_dst_active', 'id' => $field_id, 'value' => 1));
113     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
114                     $field_id,
115                     Q(rcube_label('dstactive')),
116                     $input_dst->show($CONFIG['dst_active']));
117     }
118
119   // show page size selection
120   if (!isset($no_override['pagesize']))
121     {
122     $field_id = 'rcmfd_pgsize';
123     $input_pagesize = new textfield(array('name' => '_pagesize', 'id' => $field_id, 'size' => 5));
124
125     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
126                     $field_id,
127                     Q(rcube_label('pagesize')),
128                     $input_pagesize->show($CONFIG['pagesize']));
129     }
130
131   // MM: Show checkbox for toggling 'pretty dates' 
132   if (!isset($no_override['prettydate']))
133     {
134     $field_id = 'rcmfd_prettydate';
135     $input_prettydate = new checkbox(array('name' => '_pretty_date', 'id' => $field_id, 'value' => 1));
136
137     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
138                     $field_id,
139                     Q(rcube_label('prettydate')),
140                     $input_prettydate->show($CONFIG['prettydate']?1:0));
141     }
142
143   // show checkbox for HTML/plaintext messages
144   if (!isset($no_override['prefer_html']))
145     {
146     $field_id = 'rcmfd_htmlmsg';
147     $input_pagesize = new checkbox(array('name' => '_prefer_html', 'id' => $field_id, 'value' => 1));
148
149     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
150                     $field_id,
151                     Q(rcube_label('preferhtml')),
152                     $input_pagesize->show($CONFIG['prefer_html']?1:0));
153     }
154
155   // Show checkbox for HTML Editor
156   if (!isset($no_override['htmleditor']))
157     {
158     $field_id = 'rcmfd_htmleditor';
159     $input_htmleditor = new checkbox(array('name' => '_htmleditor', 'id' => $field_id, 'value' => 1));
160     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
161                     $field_id,
162                     Q(rcube_label('htmleditor')),
163                     $input_htmleditor->show($CONFIG['htmleditor']?1:0));
164     }
165
166   // show config parameter for preview pane
167   if (!isset($no_override['preview_pane']))
168     {
169     $field_id = 'rcmfd_preview';
170     $input_preview = new checkbox(array('name' => '_preview_pane', 'id' => $field_id, 'value' => 1));
171     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
172                     $field_id,
173                     Q(rcube_label('previewpane')),
174                     $input_preview->show($CONFIG['preview_pane']?1:0));
175     }
176                   
177   if (!empty($CONFIG['drafts_mbox']) && !isset($no_override['draft_autosave']))
178     {
179     $field_id = 'rcmfd_autosave';
180     $select_autosave = new select(array('name' => '_draft_autosave', 'id' => $field_id));
181     $select_autosave->add(rcube_label('never'), 0);
182     foreach (array(3, 5, 10) as $i => $min)
183       $select_autosave->add(rcube_label(array('name' => 'everynminutes', 'vars' => array('n' => $min))), $min*60);
184
185     $out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s</td></tr>\n",
186                     $field_id,
187                     Q(rcube_label('autosavedraft')),
188                     $select_autosave->show($CONFIG['draft_autosave']));
189     }
190
191   $out .= "\n</table>$form_end";
192
193   return $out;  
194   }
195
196
197
198 function rcmail_identities_list($attrib)
199   {
200   global $OUTPUT, $USER;
201
202   // add id to message list table if not specified
203   if (!strlen($attrib['id']))
204     $attrib['id'] = 'rcmIdentitiesList';
205
206   // define list of cols to be displayed
207   $a_show_cols = array('name', 'email', 'organization', 'reply-to');
208
209   // create XHTML table  
210   $out = rcube_table_output($attrib, $USER->list_identities(), $a_show_cols, 'identity_id');
211   
212   // set client env
213   $OUTPUT->add_gui_object('identitieslist', $attrib['id']);
214
215   return $out;
216   }
217
218
219
220 // similar function as in /steps/addressbook/edit.inc
221 function get_form_tags($attrib, $action, $add_hidden=array())
222   {
223   global $OUTPUT, $EDIT_FORM, $SESS_HIDDEN_FIELD;  
224
225   $form_start = '';
226   if (!strlen($EDIT_FORM))
227     {
228     $hiddenfields = new hiddenfield(array('name' => '_task', 'value' => $GLOBALS['_task']));
229     $hiddenfields->add(array('name' => '_action', 'value' => $action));
230     
231     if ($add_hidden)
232       $hiddenfields->add($add_hidden);
233     
234     if ($_GET['_framed'] || $_POST['_framed'])
235       $hiddenfields->add(array('name' => '_framed', 'value' => 1));
236     
237     $form_start = !strlen($attrib['form']) ? '<form name="form" action="./" method="post">' : '';
238     $form_start .= "\n$SESS_HIDDEN_FIELD\n";
239     $form_start .= $hiddenfields->show();
240     }
241     
242   $form_end = (!strlen($EDIT_FORM) && !strlen($attrib['form'])) ? '</form>' : '';
243   $form_name = strlen($attrib['form']) ? $attrib['form'] : 'form';
244
245   if (!strlen($EDIT_FORM))
246     $OUTPUT->add_gui_object('editform', $form_name);
247   
248   $EDIT_FORM = $form_name;
249
250   return array($form_start, $form_end);  
251   }
252
253
254 // register UI objects
255 $OUTPUT->add_handlers(array(
256   'userprefs' => 'rcmail_user_prefs_form',
257   'identitieslist' => 'rcmail_identities_list',
258   'itentitieslist' => 'rcmail_identities_list'  // keep this for backward compatibility
259 ));
260
261
262 ?>