44ef0f47 |
1 | <?php |
2ba13803 |
2 | |
35586184 |
3 | /** |
4 | * options.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Functions needed to display the options pages. |
10 | * |
31841a9e |
11 | * @version $Id$ |
d6c32258 |
12 | * @package squirrelmail |
ca479ad1 |
13 | * @subpackage prefs |
35586184 |
14 | */ |
a3ec3c91 |
15 | |
16 | /**********************************************/ |
17 | /* Define constants used in the options code. */ |
18 | /**********************************************/ |
19 | |
20 | /* Define constants for the various option types. */ |
21 | define('SMOPT_TYPE_STRING', 0); |
22 | define('SMOPT_TYPE_STRLIST', 1); |
7e6d5ea3 |
23 | define('SMOPT_TYPE_TEXTAREA', 2); |
a3ec3c91 |
24 | define('SMOPT_TYPE_INTEGER', 3); |
25 | define('SMOPT_TYPE_FLOAT', 4); |
26 | define('SMOPT_TYPE_BOOLEAN', 5); |
2a50fbd7 |
27 | define('SMOPT_TYPE_HIDDEN', 6); |
bbcafebd |
28 | define('SMOPT_TYPE_COMMENT', 7); |
be2d5495 |
29 | define('SMOPT_TYPE_FLDRLIST', 8); |
a3ec3c91 |
30 | |
31 | /* Define constants for the options refresh levels. */ |
32 | define('SMOPT_REFRESH_NONE', 0); |
33 | define('SMOPT_REFRESH_FOLDERLIST', 1); |
34 | define('SMOPT_REFRESH_ALL', 2); |
35 | |
bbcafebd |
36 | /* Define constants for the options size. */ |
37 | define('SMOPT_SIZE_TINY', 0); |
38 | define('SMOPT_SIZE_SMALL', 1); |
39 | define('SMOPT_SIZE_MEDIUM', 2); |
40 | define('SMOPT_SIZE_LARGE', 3); |
41 | define('SMOPT_SIZE_HUGE', 4); |
88cb1b4d |
42 | define('SMOPT_SIZE_NORMAL', 5); |
bbcafebd |
43 | |
cbe5423b |
44 | define('SMOPT_SAVE_DEFAULT', 'save_option'); |
45 | define('SMOPT_SAVE_NOOP', 'save_option_noop'); |
46 | |
9962527a |
47 | /** |
598294a7 |
48 | * SquirrelOption: An option for SquirrelMail. |
9962527a |
49 | * |
8f6f9ba5 |
50 | * @package squirrelmail |
b4856b14 |
51 | * @subpackage prefs |
9962527a |
52 | */ |
53 | class SquirrelOption { |
b4856b14 |
54 | /** |
55 | * The name of this setting |
56 | * @var string |
57 | */ |
9962527a |
58 | var $name; |
b4856b14 |
59 | /** |
60 | * The text that prefaces setting on the preferences page |
61 | * @var string |
62 | */ |
9962527a |
63 | var $caption; |
b4856b14 |
64 | /** |
65 | * The type of INPUT element |
66 | * |
67 | * See SMOPT_TYPE_* defines |
68 | * @var integer |
69 | */ |
9962527a |
70 | var $type; |
b4856b14 |
71 | /** |
598294a7 |
72 | * Indicates if a link should be shown to refresh part |
b4856b14 |
73 | * or all of the window |
74 | * |
75 | * See SMOPT_REFRESH_* defines |
76 | * @var integer |
77 | */ |
a3ec3c91 |
78 | var $refresh_level; |
b4856b14 |
79 | /** |
80 | * Specifies the size of certain input items |
81 | * |
82 | * See SMOPT_SIZE_* defines |
83 | * @var integer |
84 | */ |
bbcafebd |
85 | var $size; |
b4856b14 |
86 | /** |
598294a7 |
87 | * Text that follows a text input or |
b4856b14 |
88 | * select list input on the preferences page |
598294a7 |
89 | * |
b4856b14 |
90 | * useful for indicating units, meanings of special values, etc. |
91 | * @var string |
92 | */ |
361d6e1b |
93 | var $trailing_text; |
b4856b14 |
94 | /** |
95 | * text displayed to the user |
96 | * |
97 | * Used with SMOPT_TYPE_COMMENT options |
98 | * @var string |
99 | */ |
bbcafebd |
100 | var $comment; |
b4856b14 |
101 | /** |
102 | * additional javascript or other code added to the user input |
103 | * @var string |
104 | */ |
cbe5423b |
105 | var $script; |
b4856b14 |
106 | /** |
598294a7 |
107 | * script (usually Javascript) that will be placed after (outside of) |
b4856b14 |
108 | * the INPUT tag |
109 | * @var string |
110 | */ |
6ae9e729 |
111 | var $post_script; |
cbe5423b |
112 | |
b4856b14 |
113 | /** |
114 | * The name of the Save Function for this option. |
115 | * @var string |
116 | */ |
cbe5423b |
117 | var $save_function; |
9962527a |
118 | |
119 | /* The various 'values' for this options. */ |
b4856b14 |
120 | /** |
121 | * default/preselected value for this option |
122 | * @var mixed |
123 | */ |
9962527a |
124 | var $value; |
b4856b14 |
125 | /** |
126 | * new option value |
127 | * @var mixed |
128 | */ |
9962527a |
129 | var $new_value; |
b4856b14 |
130 | /** |
598294a7 |
131 | * associative array, where each key is an actual input value |
b4856b14 |
132 | * and the corresponding value is what is displayed to the user |
133 | * for that list item in the drop-down list |
134 | * @var array |
135 | */ |
a3ec3c91 |
136 | var $possible_values; |
b4856b14 |
137 | /** |
138 | * disables html sanitizing. |
598294a7 |
139 | * |
140 | * WARNING - don't use it, if user input is possible in option |
141 | * or use own sanitizing functions. Currently works only with |
b4856b14 |
142 | * SMOPT_TYPE_STRLIST. |
143 | * @var bool |
144 | */ |
28520c87 |
145 | var $htmlencoded=false; |
9962527a |
146 | |
b4856b14 |
147 | /** |
148 | * Constructor function |
149 | * @param string $name |
150 | * @param string $caption |
151 | * @param integer $type |
152 | * @param integer $refresh_level |
153 | * @param mixed $initial_value |
154 | * @param array $possible_values |
155 | * @param bool $htmlencoded |
156 | */ |
9962527a |
157 | function SquirrelOption |
28520c87 |
158 | ($name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) { |
9962527a |
159 | /* Set the basic stuff. */ |
160 | $this->name = $name; |
161 | $this->caption = $caption; |
9962527a |
162 | $this->type = $type; |
a3ec3c91 |
163 | $this->refresh_level = $refresh_level; |
164 | $this->possible_values = $possible_values; |
28520c87 |
165 | $this->htmlencoded = $htmlencoded; |
bbcafebd |
166 | $this->size = SMOPT_SIZE_MEDIUM; |
361d6e1b |
167 | $this->trailing_text = ''; |
bbcafebd |
168 | $this->comment = ''; |
cbe5423b |
169 | $this->script = ''; |
6ae9e729 |
170 | $this->post_script = ''; |
a3ec3c91 |
171 | |
172 | /* Check for a current value. */ |
6ae9e729 |
173 | if (!empty($initial_value)) { |
174 | $this->value = $initial_value; |
175 | } else if (isset($GLOBALS[$name])) { |
a3ec3c91 |
176 | $this->value = $GLOBALS[$name]; |
177 | } else { |
178 | $this->value = ''; |
179 | } |
9962527a |
180 | |
a3ec3c91 |
181 | /* Check for a new value. */ |
b4856b14 |
182 | if ( !sqgetGlobalVar("new_$name", $this->new_value, SQ_POST ) ) { |
a3ec3c91 |
183 | $this->new_value = ''; |
44ef0f47 |
184 | } |
cbe5423b |
185 | |
186 | /* Set the default save function. */ |
2a50fbd7 |
187 | if (($type != SMOPT_TYPE_HIDDEN) && ($type != SMOPT_TYPE_COMMENT)) { |
cbe5423b |
188 | $this->save_function = SMOPT_SAVE_DEFAULT; |
189 | } else { |
190 | $this->save_function = SMOPT_SAVE_NOOP; |
191 | } |
192 | } |
193 | |
b4856b14 |
194 | /** |
195 | * Set the value for this option. |
196 | * @param mixed $value |
197 | */ |
cbe5423b |
198 | function setValue($value) { |
199 | $this->value = $value; |
200 | } |
201 | |
b4856b14 |
202 | /** |
203 | * Set the new value for this option. |
204 | * @param mixed $new_value |
205 | */ |
cbe5423b |
206 | function setNewValue($new_value) { |
207 | $this->new_value = $new_value; |
9962527a |
208 | } |
44ef0f47 |
209 | |
b4856b14 |
210 | /** |
211 | * Set the size for this option. |
212 | * @param integer $size |
213 | */ |
bbcafebd |
214 | function setSize($size) { |
215 | $this->size = $size; |
216 | } |
217 | |
b4856b14 |
218 | /** |
219 | * Set the trailing_text for this option. |
220 | * @param string $trailing_text |
221 | */ |
361d6e1b |
222 | function setTrailingText($trailing_text) { |
223 | $this->trailing_text = $trailing_text; |
224 | } |
225 | |
b4856b14 |
226 | /** |
227 | * Set the comment for this option. |
228 | * @param string $comment |
229 | */ |
bbcafebd |
230 | function setComment($comment) { |
231 | $this->comment = $comment; |
232 | } |
233 | |
b4856b14 |
234 | /** |
235 | * Set the script for this option. |
598294a7 |
236 | * @param string $script |
b4856b14 |
237 | */ |
cbe5423b |
238 | function setScript($script) { |
239 | $this->script = $script; |
240 | } |
241 | |
b4856b14 |
242 | /** |
243 | * Set the "post script" for this option. |
244 | * @param string $post_script |
245 | */ |
6ae9e729 |
246 | function setPostScript($post_script) { |
247 | $this->post_script = $post_script; |
248 | } |
249 | |
b4856b14 |
250 | /** |
251 | * Set the save function for this option. |
252 | * @param string $save_function |
253 | */ |
cbe5423b |
254 | function setSaveFunction($save_function) { |
255 | $this->save_function = $save_function; |
256 | } |
257 | |
b4856b14 |
258 | /** |
259 | * Creates fields on option pages according to option type |
260 | * |
261 | * Function that calls other createWidget* functions. |
598294a7 |
262 | * @return string html formated option field |
b4856b14 |
263 | */ |
a3ec3c91 |
264 | function createHTMLWidget() { |
ce68b76b |
265 | global $color; |
cbe5423b |
266 | |
62f7daa5 |
267 | // Use new value if available |
74e44765 |
268 | if (!empty($this->new_value)) { |
269 | $tempValue = $this->value; |
270 | $this->value = $this->new_value; |
271 | } |
272 | |
cbe5423b |
273 | /* Get the widget for this option type. */ |
a3ec3c91 |
274 | switch ($this->type) { |
275 | case SMOPT_TYPE_STRING: |
37a3ed17 |
276 | $result = $this->createWidget_String(); |
a3ec3c91 |
277 | break; |
278 | case SMOPT_TYPE_STRLIST: |
37a3ed17 |
279 | $result = $this->createWidget_StrList(); |
a3ec3c91 |
280 | break; |
7e6d5ea3 |
281 | case SMOPT_TYPE_TEXTAREA: |
37a3ed17 |
282 | $result = $this->createWidget_TextArea(); |
a3ec3c91 |
283 | break; |
284 | case SMOPT_TYPE_INTEGER: |
37a3ed17 |
285 | $result = $this->createWidget_Integer(); |
a3ec3c91 |
286 | break; |
287 | case SMOPT_TYPE_FLOAT: |
37a3ed17 |
288 | $result = $this->createWidget_Float(); |
a3ec3c91 |
289 | break; |
290 | case SMOPT_TYPE_BOOLEAN: |
37a3ed17 |
291 | $result = $this->createWidget_Boolean(); |
a3ec3c91 |
292 | break; |
2a50fbd7 |
293 | case SMOPT_TYPE_HIDDEN: |
37a3ed17 |
294 | $result = $this->createWidget_Hidden(); |
a3ec3c91 |
295 | break; |
bbcafebd |
296 | case SMOPT_TYPE_COMMENT: |
37a3ed17 |
297 | $result = $this->createWidget_Comment(); |
bbcafebd |
298 | break; |
be2d5495 |
299 | case SMOPT_TYPE_FLDRLIST: |
37a3ed17 |
300 | $result = $this->createWidget_FolderList(); |
be2d5495 |
301 | break; |
a3ec3c91 |
302 | default: |
6b4bd11f |
303 | $result = '<font color="' . $color[2] . '">' |
a3ec3c91 |
304 | . sprintf(_("Option Type '%s' Not Found"), $this->type) |
6b4bd11f |
305 | . '</font>'; |
a3ec3c91 |
306 | } |
307 | |
6ae9e729 |
308 | /* Add the "post script" for this option. */ |
309 | $result .= $this->post_script; |
62f7daa5 |
310 | |
74e44765 |
311 | // put correct value back if need be |
312 | if (!empty($this->new_value)) { |
313 | $this->value = $tempValue; |
314 | } |
315 | |
a3ec3c91 |
316 | /* Now, return the created widget. */ |
317 | return ($result); |
318 | } |
319 | |
b4856b14 |
320 | /** |
321 | * Create string field |
322 | * @return string html formated option field |
323 | */ |
37a3ed17 |
324 | function createWidget_String() { |
bbcafebd |
325 | switch ($this->size) { |
88cb1b4d |
326 | case SMOPT_SIZE_TINY: |
327 | $width = 5; |
328 | break; |
329 | case SMOPT_SIZE_SMALL: |
330 | $width = 12; |
331 | break; |
332 | case SMOPT_SIZE_LARGE: |
333 | $width = 38; |
334 | break; |
335 | case SMOPT_SIZE_HUGE: |
336 | $width = 50; |
337 | break; |
bbcafebd |
338 | case SMOPT_SIZE_NORMAL: |
88cb1b4d |
339 | default: |
340 | $width = 25; |
bbcafebd |
341 | } |
342 | |
88440172 |
343 | $result = "<input type=\"text\" name=\"new_$this->name\" value=\"" . |
62f7daa5 |
344 | htmlspecialchars($this->value) . |
361d6e1b |
345 | "\" size=\"$width\" $this->script />$this->trailing_text\n"; |
a3ec3c91 |
346 | return ($result); |
347 | } |
348 | |
b4856b14 |
349 | /** |
350 | * Create selection box |
351 | * @return string html formated selection box |
352 | */ |
37a3ed17 |
353 | function createWidget_StrList() { |
a3ec3c91 |
354 | /* Begin the select tag. */ |
d6150d69 |
355 | $result = "<select name=\"new_$this->name\" $this->script>\n"; |
a3ec3c91 |
356 | |
357 | /* Add each possible value to the select list. */ |
358 | foreach ($this->possible_values as $real_value => $disp_value) { |
359 | /* Start the next new option string. */ |
62f7daa5 |
360 | $new_option = '<option value="' . |
28520c87 |
361 | ($this->htmlencoded ? $real_value : htmlspecialchars($real_value)) . '"'; |
a3ec3c91 |
362 | |
363 | /* If this value is the current value, select it. */ |
364 | if ($real_value == $this->value) { |
d6150d69 |
365 | $new_option .= ' selected="selected"'; |
a3ec3c91 |
366 | } |
367 | |
368 | /* Add the display value to our option string. */ |
28520c87 |
369 | $new_option .= '>' . ($this->htmlencoded ? $disp_value : htmlspecialchars($disp_value)) . "</option>\n"; |
a3ec3c91 |
370 | |
371 | /* And add the new option string to our select tag. */ |
372 | $result .= $new_option; |
373 | } |
374 | |
375 | /* Close the select tag and return our happy result. */ |
361d6e1b |
376 | $result .= "</select>$this->trailing_text\n"; |
a3ec3c91 |
377 | return ($result); |
378 | } |
379 | |
b4856b14 |
380 | /** |
381 | * Create folder selection box |
382 | * @return string html formated selection box |
383 | */ |
37a3ed17 |
384 | function createWidget_FolderList() { |
be2d5495 |
385 | $selected = array(strtolower($this->value)); |
386 | |
387 | /* Begin the select tag. */ |
d6150d69 |
388 | $result = "<select name=\"new_$this->name\" $this->script>\n"; |
be2d5495 |
389 | |
390 | /* Add each possible value to the select list. */ |
391 | foreach ($this->possible_values as $real_value => $disp_value) { |
62f7daa5 |
392 | if ( is_array($disp_value) ) { |
be2d5495 |
393 | /* For folder list, we passed in the array of boxes.. */ |
394 | $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value); |
395 | } else { |
396 | /* Start the next new option string. */ |
d6150d69 |
397 | $new_option = '<option value="' . htmlspecialchars($real_value) . '"'; |
62f7daa5 |
398 | |
be2d5495 |
399 | /* If this value is the current value, select it. */ |
400 | if ($real_value == $this->value) { |
d6150d69 |
401 | $new_option .= ' selected="selected"'; |
be2d5495 |
402 | } |
62f7daa5 |
403 | |
be2d5495 |
404 | /* Add the display value to our option string. */ |
d6150d69 |
405 | $new_option .= '>' . htmlspecialchars($disp_value) . "</option>\n"; |
be2d5495 |
406 | } |
407 | /* And add the new option string to our select tag. */ |
408 | $result .= $new_option; |
62f7daa5 |
409 | } |
be2d5495 |
410 | /* Close the select tag and return our happy result. */ |
d6150d69 |
411 | $result .= "</select>\n"; |
be2d5495 |
412 | return ($result); |
413 | } |
414 | |
b4856b14 |
415 | /** |
416 | * Creates textarea |
417 | * @return string html formated textarea field |
418 | */ |
37a3ed17 |
419 | function createWidget_TextArea() { |
bbcafebd |
420 | switch ($this->size) { |
421 | case SMOPT_SIZE_TINY: $rows = 3; $cols = 10; break; |
422 | case SMOPT_SIZE_SMALL: $rows = 4; $cols = 30; break; |
423 | case SMOPT_SIZE_LARGE: $rows = 10; $cols = 60; break; |
424 | case SMOPT_SIZE_HUGE: $rows = 20; $cols = 80; break; |
425 | case SMOPT_SIZE_NORMAL: |
426 | default: $rows = 5; $cols = 50; |
427 | } |
6b4bd11f |
428 | $result = "<textarea name=\"new_$this->name\" rows=\"$rows\" " |
d6150d69 |
429 | . "cols=\"$cols\" $this->script>" |
430 | . htmlspecialchars($this->value) . "</textarea>\n"; |
bbcafebd |
431 | return ($result); |
a3ec3c91 |
432 | } |
433 | |
b4856b14 |
434 | /** |
435 | * Creates field for integer |
436 | * |
437 | * Difference from createWidget_String is visible only when javascript is enabled |
438 | * @return string html formated option field |
439 | */ |
37a3ed17 |
440 | function createWidget_Integer() { |
b65d1a08 |
441 | global $javascript_on; |
0d08ea5a |
442 | |
b65d1a08 |
443 | // add onChange javascript handler to a regular string widget |
444 | // which will strip out all non-numeric chars |
445 | if ($javascript_on) |
d6150d69 |
446 | return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; ' |
b65d1a08 |
447 | . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' ' |
448 | . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } ' |
d6150d69 |
449 | . 'this.value=newVal;" />', $this->createWidget_String()); |
b65d1a08 |
450 | else |
37a3ed17 |
451 | return $this->createWidget_String(); |
a3ec3c91 |
452 | } |
453 | |
b4856b14 |
454 | /** |
455 | * Creates field for floating number |
456 | * Difference from createWidget_String is visible only when javascript is enabled |
457 | * @return string html formated option field |
458 | */ |
37a3ed17 |
459 | function createWidget_Float() { |
37a3ed17 |
460 | global $javascript_on; |
461 | |
b65d1a08 |
462 | // add onChange javascript handler to a regular string widget |
62f7daa5 |
463 | // which will strip out all non-numeric (period also OK) chars |
b65d1a08 |
464 | if ($javascript_on) |
d6150d69 |
465 | return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; ' |
b65d1a08 |
466 | . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' ' |
467 | . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') ' |
d6150d69 |
468 | . 'newVal += origVal.charAt(i); } this.value=newVal;" />' |
37a3ed17 |
469 | , $this->createWidget_String()); |
b65d1a08 |
470 | else |
37a3ed17 |
471 | return $this->createWidget_String(); |
a3ec3c91 |
472 | } |
473 | |
b4856b14 |
474 | /** |
475 | * Creates radio field (yes/no) |
476 | * @return string html formated radio field |
477 | */ |
37a3ed17 |
478 | function createWidget_Boolean() { |
fd87494d |
479 | /* Do the whole current value thing. */ |
480 | if ($this->value != SMPREF_NO) { |
62f7daa5 |
481 | $yes_chk = ' checked="checked"'; |
fd87494d |
482 | $no_chk = ''; |
483 | } else { |
484 | $yes_chk = ''; |
62f7daa5 |
485 | $no_chk = ' checked="checked"'; |
fd87494d |
486 | } |
487 | |
488 | /* Build the yes choice. */ |
f4c37e3c |
489 | $yes_option = '<input type="radio" id="new_' . $this->name . '_yes" ' |
490 | . 'name="new_' . $this->name . '" value="' . SMPREF_YES . '"' |
d6150d69 |
491 | . $yes_chk . ' ' . $this->script . ' /> ' |
f4c37e3c |
492 | . '<label for="new_'.$this->name.'_yes">' . _("Yes") . '</label>'; |
fd87494d |
493 | |
494 | /* Build the no choice. */ |
f4c37e3c |
495 | $no_option = '<input type="radio" id="new_' . $this->name . '_no" ' |
496 | . 'name="new_' . $this->name . '" value="' . SMPREF_NO . '"' |
d6150d69 |
497 | . $no_chk . ' ' . $this->script . ' /> ' |
f4c37e3c |
498 | . '<label for="new_'.$this->name.'_no">' . _("No") . '</label>'; |
fd87494d |
499 | |
500 | /* Build and return the combined "boolean widget". */ |
501 | $result = "$yes_option $no_option"; |
502 | return ($result); |
a3ec3c91 |
503 | } |
504 | |
b4856b14 |
505 | /** |
506 | * Creates hidden field |
507 | * @return string html formated hidden input field |
508 | */ |
37a3ed17 |
509 | function createWidget_Hidden() { |
6b4bd11f |
510 | $result = '<input type="hidden" name="new_' . $this->name |
d6150d69 |
511 | . '" value="' . htmlspecialchars($this->value) |
512 | . '" ' . $this->script . ' />'; |
a3ec3c91 |
513 | return ($result); |
514 | } |
515 | |
b4856b14 |
516 | /** |
517 | * Creates comment |
518 | * @return string comment |
519 | */ |
37a3ed17 |
520 | function createWidget_Comment() { |
bbcafebd |
521 | $result = $this->comment; |
522 | return ($result); |
523 | } |
524 | |
b4856b14 |
525 | /** |
526 | * |
527 | */ |
cbe5423b |
528 | function save() { |
529 | $function = $this->save_function; |
530 | $function($this); |
44ef0f47 |
531 | } |
cbe5423b |
532 | |
b4856b14 |
533 | /** |
534 | * |
535 | */ |
cbe5423b |
536 | function changed() { |
6206f6c4 |
537 | return ($this->value != $this->new_value); |
cbe5423b |
538 | } |
b4856b14 |
539 | } /* End of SquirrelOption class*/ |
cbe5423b |
540 | |
b4856b14 |
541 | /** |
542 | * Saves option |
543 | * @param object $option object that holds option name and new_value |
544 | */ |
cbe5423b |
545 | function save_option($option) { |
dac16606 |
546 | if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) { |
547 | /* Can't save the pref if we don't have the username */ |
548 | return; |
0b97a708 |
549 | } |
550 | global $data_dir; |
0b97a708 |
551 | setPref($data_dir, $username, $option->name, $option->new_value); |
cbe5423b |
552 | } |
553 | |
b4856b14 |
554 | /** |
555 | * save function that does not save |
556 | * @param object $option |
557 | */ |
cbe5423b |
558 | function save_option_noop($option) { |
559 | /* Do nothing here... */ |
9962527a |
560 | } |
44ef0f47 |
561 | |
b4856b14 |
562 | /** |
563 | * Create hidden 'optpage' input field with value set by argument |
564 | * @param string $optpage identification of option page |
565 | * @return string html formated hidden input field |
566 | */ |
cbe5423b |
567 | function create_optpage_element($optpage) { |
568 | return create_hidden_element('optpage', $optpage); |
569 | } |
570 | |
b4856b14 |
571 | /** |
572 | * Create hidden 'optmode' input field with value set by argument |
573 | * @param string $optmode |
574 | * @return string html formated hidden input field |
575 | */ |
cbe5423b |
576 | function create_optmode_element($optmode) { |
577 | return create_hidden_element('optmode', $optmode); |
578 | } |
579 | |
b4856b14 |
580 | /** |
581 | * Create hidden field. |
582 | * @param string $name field name |
583 | * @param string $value field value |
584 | * @return string html formated hidden input field |
585 | */ |
cbe5423b |
586 | function create_hidden_element($name, $value) { |
6b4bd11f |
587 | $result = '<input type="hidden" ' |
588 | . 'name="' . $name . '" ' |
d6150d69 |
589 | . 'value="' . htmlspecialchars($value) . '" />'; |
cbe5423b |
590 | return ($result); |
591 | } |
592 | |
b4856b14 |
593 | /** |
594 | * @param array $optgrps |
595 | * @param array $optvals |
596 | * @return array |
597 | */ |
cbe5423b |
598 | function create_option_groups($optgrps, $optvals) { |
a3ec3c91 |
599 | /* Build a simple array with which to start. */ |
600 | $result = array(); |
601 | |
bbcafebd |
602 | /* Create option group for each option group name. */ |
603 | foreach ($optgrps as $grpkey => $grpname) { |
604 | $result[$grpkey] = array(); |
605 | $result[$grpkey]['name'] = $grpname; |
606 | $result[$grpkey]['options'] = array(); |
607 | } |
608 | |
a3ec3c91 |
609 | /* Create a new SquirrelOption for each set of option values. */ |
bbcafebd |
610 | foreach ($optvals as $grpkey => $grpopts) { |
611 | foreach ($grpopts as $optset) { |
28520c87 |
612 | /* Create a new option with all values given. */ |
613 | $next_option = new SquirrelOption( |
7390e240 |
614 | $optset['name'], |
615 | $optset['caption'], |
616 | $optset['type'], |
617 | (isset($optset['refresh']) ? $optset['refresh'] : SMOPT_REFRESH_NONE), |
618 | (isset($optset['initial_value']) ? $optset['initial_value'] : ''), |
619 | (isset($optset['posvals']) ? $optset['posvals'] : ''), |
620 | (isset($optset['htmlencoded']) ? $optset['htmlencoded'] : false) |
621 | ); |
bbcafebd |
622 | |
623 | /* If provided, set the size for this option. */ |
624 | if (isset($optset['size'])) { |
625 | $next_option->setSize($optset['size']); |
626 | } |
627 | |
361d6e1b |
628 | /* If provided, set the trailing_text for this option. */ |
629 | if (isset($optset['trailing_text'])) { |
630 | $next_option->setTrailingText($optset['trailing_text']); |
631 | } |
632 | |
bbcafebd |
633 | /* If provided, set the comment for this option. */ |
634 | if (isset($optset['comment'])) { |
635 | $next_option->setComment($optset['comment']); |
636 | } |
637 | |
cbe5423b |
638 | /* If provided, set the save function for this option. */ |
639 | if (isset($optset['save'])) { |
640 | $next_option->setSaveFunction($optset['save']); |
641 | } |
642 | |
643 | /* If provided, set the script for this option. */ |
644 | if (isset($optset['script'])) { |
645 | $next_option->setScript($optset['script']); |
646 | } |
647 | |
6ae9e729 |
648 | /* If provided, set the "post script" for this option. */ |
649 | if (isset($optset['post_script'])) { |
650 | $next_option->setPostScript($optset['post_script']); |
651 | } |
652 | |
bbcafebd |
653 | /* Add this option to the option array. */ |
654 | $result[$grpkey]['options'][] = $next_option; |
a3ec3c91 |
655 | } |
656 | } |
657 | |
658 | /* Return our resulting array. */ |
659 | return ($result); |
660 | } |
661 | |
b4856b14 |
662 | /** |
663 | * @param array $option_groups |
664 | */ |
cbe5423b |
665 | function print_option_groups($option_groups) { |
2fad95fa |
666 | /* Print each option group. */ |
bbcafebd |
667 | foreach ($option_groups as $next_optgrp) { |
2fad95fa |
668 | /* If it is not blank, print the name for this option group. */ |
669 | if ($next_optgrp['name'] != '') { |
6b4bd11f |
670 | echo html_tag( 'tr', "\n". |
671 | html_tag( 'td', |
672 | '<b>' . $next_optgrp['name'] . '</b>' , |
c435f076 |
673 | 'center' ,'', 'valign="middle" colspan="2" style="white-space: nowrap;"' ) |
6b4bd11f |
674 | ) ."\n"; |
7e235a1a |
675 | } |
676 | |
677 | /* Print each option in this option group. */ |
bbcafebd |
678 | foreach ($next_optgrp['options'] as $option) { |
2a50fbd7 |
679 | if ($option->type != SMOPT_TYPE_HIDDEN) { |
6b4bd11f |
680 | echo html_tag( 'tr', "\n". |
681 | html_tag( 'td', $option->caption . ':', 'right' ,'', 'valign="middle"' ) . |
682 | html_tag( 'td', $option->createHTMLWidget(), 'left' ) |
683 | ) ."\n"; |
bbcafebd |
684 | } else { |
685 | echo $option->createHTMLWidget(); |
686 | } |
687 | } |
7e235a1a |
688 | |
689 | /* Print an empty row after this option group. */ |
6b4bd11f |
690 | echo html_tag( 'tr', |
691 | html_tag( 'td', ' ', 'left', '', 'colspan="2"' ) |
692 | ) . "\n"; |
bbcafebd |
693 | } |
694 | } |
695 | |
b4856b14 |
696 | /** |
697 | * Create submit button inside table row. |
698 | * @param string $name |
699 | */ |
9962527a |
700 | function OptionSubmit( $name ) { |
6b4bd11f |
701 | echo html_tag( 'tr', |
6fd95361 |
702 | html_tag( 'td', '<input type="submit" value="' . _("Submit") . '" name="' . $name . '" /> ', 'right', '', 'colspan="2"' ) |
6b4bd11f |
703 | ) . "\n"; |
9962527a |
704 | } |
02ddcd00 |
705 | |
d6150d69 |
706 | // vim: et ts=4 |
6fd95361 |
707 | ?> |