cb39ea7a76a1822542eb0d9f12b91b1de533aec1
[squirrelmail.git] / functions / options.php
1 <?php
2
3 /**
4 * options.php
5 *
6 * Functions needed to display the options pages.
7 *
8 * @copyright &copy; 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 * @subpackage prefs
13 */
14
15 /**********************************************/
16 /* Define constants used in the options code. */
17 /**********************************************/
18
19 /* Define constants for the various option types. */
20 define('SMOPT_TYPE_STRING', 0);
21 define('SMOPT_TYPE_STRLIST', 1);
22 define('SMOPT_TYPE_TEXTAREA', 2);
23 define('SMOPT_TYPE_INTEGER', 3);
24 define('SMOPT_TYPE_FLOAT', 4);
25 define('SMOPT_TYPE_BOOLEAN', 5);
26 define('SMOPT_TYPE_HIDDEN', 6);
27 define('SMOPT_TYPE_COMMENT', 7);
28 define('SMOPT_TYPE_FLDRLIST', 8);
29 define('SMOPT_TYPE_FLDRLIST_MULTI', 9);
30 define('SMOPT_TYPE_EDIT_LIST', 10);
31 define('SMOPT_TYPE_STRLIST_MULTI', 11);
32 define('SMOPT_TYPE_BOOLEAN_CHECKBOX', 12);
33 define('SMOPT_TYPE_BOOLEAN_RADIO', 13);
34
35 /* Define constants for the options refresh levels. */
36 define('SMOPT_REFRESH_NONE', 0);
37 define('SMOPT_REFRESH_FOLDERLIST', 1);
38 define('SMOPT_REFRESH_ALL', 2);
39
40 /* Define constants for the options size. */
41 define('SMOPT_SIZE_TINY', 0);
42 define('SMOPT_SIZE_SMALL', 1);
43 define('SMOPT_SIZE_MEDIUM', 2);
44 define('SMOPT_SIZE_LARGE', 3);
45 define('SMOPT_SIZE_HUGE', 4);
46 define('SMOPT_SIZE_NORMAL', 5);
47
48 define('SMOPT_SAVE_DEFAULT', 'save_option');
49 define('SMOPT_SAVE_NOOP', 'save_option_noop');
50
51 /**
52 * SquirrelOption: An option for SquirrelMail.
53 *
54 * @package squirrelmail
55 * @subpackage prefs
56 */
57 class SquirrelOption {
58 /**
59 * The name of this setting
60 * @var string
61 */
62 var $name;
63 /**
64 * The text that prefaces setting on the preferences page
65 * @var string
66 */
67 var $caption;
68 /**
69 * The type of INPUT element
70 *
71 * See SMOPT_TYPE_* defines
72 * @var integer
73 */
74 var $type;
75 /**
76 * Indicates if a link should be shown to refresh part
77 * or all of the window
78 *
79 * See SMOPT_REFRESH_* defines
80 * @var integer
81 */
82 var $refresh_level;
83 /**
84 * Specifies the size of certain input items
85 *
86 * See SMOPT_SIZE_* defines
87 * @var integer
88 */
89 var $size;
90 /**
91 * Text that follows a text input or
92 * select list input on the preferences page
93 *
94 * useful for indicating units, meanings of special values, etc.
95 * @var string
96 */
97 var $trailing_text;
98 /**
99 * text displayed to the user
100 *
101 * Used with SMOPT_TYPE_COMMENT options
102 * @var string
103 */
104 var $comment;
105 /**
106 * additional javascript or other widget attributes added to the
107 * user input; must be an array where keys are attribute names
108 * ("onclick", etc) and values are the attribute values.
109 * @var array
110 */
111 var $aExtraAttribs;
112 /**
113 * script (usually Javascript) that will be placed after (outside of)
114 * the INPUT tag
115 * @var string
116 */
117 var $post_script;
118
119 /**
120 * The name of the Save Function for this option.
121 * @var string
122 */
123 var $save_function;
124
125 /* The various 'values' for this options. */
126 /**
127 * default/preselected value for this option
128 * @var mixed
129 */
130 var $value;
131 /**
132 * new option value
133 * @var mixed
134 */
135 var $new_value;
136 /**
137 * associative array, where each key is an actual input value
138 * and the corresponding value is what is displayed to the user
139 * for that list item in the drop-down list
140 * @var array
141 */
142 var $possible_values;
143 /**
144 * disables html sanitizing.
145 *
146 * WARNING - don't use it, if user input is possible in option
147 * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
148 * @var bool
149 */
150 var $htmlencoded=false;
151 /**
152 * Controls folder list limits in SMOPT_TYPE_FLDRLIST and
153 * SMOPT_TYPE_FLDRLIST_MULTI widgets.
154 * See $flag argument in sqimap_mailbox_option_list() function.
155 * @var string
156 * @since 1.5.1
157 */
158 var $folder_filter='noselect';
159
160 /**
161 * Constructor function
162 * @param string $name
163 * @param string $caption
164 * @param integer $type
165 * @param integer $refresh_level
166 * @param mixed $initial_value
167 * @param array $possible_values
168 * @param bool $htmlencoded
169 */
170 function SquirrelOption
171 ($name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) {
172 /* Set the basic stuff. */
173 $this->name = $name;
174 $this->caption = $caption;
175 $this->type = $type;
176 $this->refresh_level = $refresh_level;
177 $this->possible_values = $possible_values;
178 $this->htmlencoded = $htmlencoded;
179 $this->size = SMOPT_SIZE_MEDIUM;
180 $this->trailing_text = '';
181 $this->comment = '';
182 $this->aExtraAttribs = array();
183 $this->post_script = '';
184
185 //Check for a current value.
186 if (isset($GLOBALS[$name])) {
187 $this->value = $GLOBALS[$name];
188 } else if (!empty($initial_value)) {
189 $this->value = $initial_value;
190 } else {
191 $this->value = '';
192 }
193
194 /* Check for a new value. */
195 if ( !sqgetGlobalVar("new_$name", $this->new_value, SQ_POST ) ) {
196 $this->new_value = '';
197 }
198
199 /* Set the default save function. */
200 if (($type != SMOPT_TYPE_HIDDEN) && ($type != SMOPT_TYPE_COMMENT)) {
201 $this->save_function = SMOPT_SAVE_DEFAULT;
202 } else {
203 $this->save_function = SMOPT_SAVE_NOOP;
204 }
205 }
206
207 /** Convenience function that identifies which types of
208 widgets are stored as (serialized) array values. */
209 function is_multiple_valued() {
210 return ($this->type == SMOPT_TYPE_FLDRLIST_MULTI
211 || $this->type == SMOPT_TYPE_STRLIST_MULTI
212 || $this->type == SMOPT_TYPE_EDIT_LIST);
213 }
214
215 /**
216 * Set the value for this option.
217 * @param mixed $value
218 */
219 function setValue($value) {
220 $this->value = $value;
221 }
222
223 /**
224 * Set the new value for this option.
225 * @param mixed $new_value
226 */
227 function setNewValue($new_value) {
228 $this->new_value = $new_value;
229 }
230
231 /**
232 * Set the size for this option.
233 * @param integer $size
234 */
235 function setSize($size) {
236 $this->size = $size;
237 }
238
239 /**
240 * Set the trailing_text for this option.
241 * @param string $trailing_text
242 */
243 function setTrailingText($trailing_text) {
244 $this->trailing_text = $trailing_text;
245 }
246
247 /**
248 * Set the comment for this option.
249 * @param string $comment
250 */
251 function setComment($comment) {
252 $this->comment = $comment;
253 }
254
255 /**
256 * Set the extra attributes for this option.
257 * @param array $aExtraAttribs
258 */
259 function setExtraAttributes($aExtraAttribs) {
260 $this->aExtraAttribs = $aExtraAttribs;
261 }
262
263 /**
264 * Set the "post script" for this option.
265 * @param string $post_script
266 */
267 function setPostScript($post_script) {
268 $this->post_script = $post_script;
269 }
270
271 /**
272 * Set the save function for this option.
273 * @param string $save_function
274 */
275 function setSaveFunction($save_function) {
276 $this->save_function = $save_function;
277 }
278
279 /**
280 * Set the trailing_text for this option.
281 * @param string $folder_filter
282 * @since 1.5.1
283 */
284 function setFolderFilter($folder_filter) {
285 $this->folder_filter = $folder_filter;
286 }
287
288 /**
289 * Creates fields on option pages according to option type
290 *
291 * This is the function that calls all other createWidget* functions.
292 *
293 * @return string The formated option field
294 *
295 */
296 function createWidget() {
297 global $color;
298
299 // Use new value if available
300 if (!empty($this->new_value)) {
301 $tempValue = $this->value;
302 $this->value = $this->new_value;
303 }
304
305 /* Get the widget for this option type. */
306 switch ($this->type) {
307 case SMOPT_TYPE_STRING:
308 $result = $this->createWidget_String();
309 break;
310 case SMOPT_TYPE_STRLIST:
311 $result = $this->createWidget_StrList();
312 break;
313 case SMOPT_TYPE_TEXTAREA:
314 $result = $this->createWidget_TextArea();
315 break;
316 case SMOPT_TYPE_INTEGER:
317 $result = $this->createWidget_Integer();
318 break;
319 case SMOPT_TYPE_FLOAT:
320 $result = $this->createWidget_Float();
321 break;
322 case SMOPT_TYPE_BOOLEAN:
323 $result = $this->createWidget_Boolean();
324 break;
325 case SMOPT_TYPE_BOOLEAN_CHECKBOX:
326 $result = $this->createWidget_Boolean(TRUE);
327 break;
328 case SMOPT_TYPE_BOOLEAN_RADIO:
329 $result = $this->createWidget_Boolean(FALSE);
330 break;
331 case SMOPT_TYPE_HIDDEN:
332 $result = $this->createWidget_Hidden();
333 break;
334 case SMOPT_TYPE_COMMENT:
335 $result = $this->createWidget_Comment();
336 break;
337 case SMOPT_TYPE_FLDRLIST:
338 $result = $this->createWidget_FolderList();
339 break;
340 case SMOPT_TYPE_FLDRLIST_MULTI:
341 $result = $this->createWidget_FolderList(TRUE);
342 break;
343 case SMOPT_TYPE_EDIT_LIST:
344 $result = $this->createWidget_EditList();
345 break;
346 case SMOPT_TYPE_STRLIST_MULTI:
347 $result = $this->createWidget_StrList(TRUE);
348 break;
349 default:
350 error_box (
351 sprintf(_("Option Type '%s' Not Found"), $this->type)
352 );
353 }
354
355 /* Add the "post script" for this option. */
356 $result .= $this->post_script;
357
358 // put correct value back if need be
359 if (!empty($this->new_value)) {
360 $this->value = $tempValue;
361 }
362
363 /* Now, return the created widget. */
364 return $result;
365 }
366
367 /**
368 * Create string field
369 * @return string html formated option field
370 */
371 function createWidget_String() {
372 switch ($this->size) {
373 case SMOPT_SIZE_TINY:
374 $width = 5;
375 break;
376 case SMOPT_SIZE_SMALL:
377 $width = 12;
378 break;
379 case SMOPT_SIZE_LARGE:
380 $width = 38;
381 break;
382 case SMOPT_SIZE_HUGE:
383 $width = 50;
384 break;
385 case SMOPT_SIZE_NORMAL:
386 default:
387 $width = 25;
388 }
389
390 return addInput('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . htmlspecialchars($this->trailing_text);
391 }
392
393 /**
394 * Create selection box
395 *
396 * When $this->htmlencoded is TRUE, the keys and values in
397 * $this->possible_values are assumed to be display-safe.
398 * Use with care!
399 *
400 * @param boolean $multiple_select When TRUE, the select widget
401 * will allow multiple selections
402 * (OPTIONAL; default is FALSE
403 * (single select list))
404 *
405 * @return string html formated selection box
406 *
407 */
408 function createWidget_StrList($multiple_select=FALSE) {
409 //FIXME: Currently, $this->htmlencoded is ignored here -- was removed when changing to template-based output; a fix is available as part of proposed centralized sanitizing patch
410
411 switch ($this->size) {
412 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
413 case SMOPT_SIZE_TINY:
414 $height = 3;
415 break;
416 case SMOPT_SIZE_SMALL:
417 $height = 8;
418 break;
419 case SMOPT_SIZE_LARGE:
420 $height = 15;
421 break;
422 case SMOPT_SIZE_HUGE:
423 $height = 25;
424 break;
425 case SMOPT_SIZE_NORMAL:
426 default:
427 $height = 5;
428 }
429
430 return addSelect('new_' . $this->name, $this->possible_values, $this->value, TRUE, $this->aExtraAttribs, $multiple_select, $height, !$this->htmlencoded) . htmlspecialchars($this->trailing_text);
431
432 }
433
434 /**
435 * Create folder selection box
436 *
437 * @param boolean $multiple_select When TRUE, the select widget
438 * will allow multiple selections
439 * (OPTIONAL; default is FALSE
440 * (single select list))
441 *
442 * @return string html formated selection box
443 *
444 */
445 function createWidget_FolderList($multiple_select=FALSE) {
446
447 switch ($this->size) {
448 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
449 case SMOPT_SIZE_TINY:
450 $height = 3;
451 break;
452 case SMOPT_SIZE_SMALL:
453 $height = 8;
454 break;
455 case SMOPT_SIZE_LARGE:
456 $height = 15;
457 break;
458 case SMOPT_SIZE_HUGE:
459 $height = 25;
460 break;
461 case SMOPT_SIZE_NORMAL:
462 default:
463 $height = 5;
464 }
465
466 // possible values might include a nested array of
467 // possible values (list of folders)
468 //
469 $option_list = array();
470 foreach ($this->possible_values as $value => $text) {
471
472 // list of folders (boxes array)
473 //
474 if (is_array($text)) {
475 $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter));
476
477 // just one option here
478 //
479 } else {
480 $option_list = array_merge($option_list, array($value => $text));
481 }
482
483 }
484 if (empty($option_list))
485 $option_list = array('ignore' => _("unavailable"));
486
487
488 return addSelect('new_' . $this->name, $option_list, $this->value, TRUE, $this->aExtraAttribs, $multiple_select, $height) . htmlspecialchars($this->trailing_text);
489
490 }
491
492 /**
493 * Creates textarea
494 * @return string html formated textarea field
495 */
496 function createWidget_TextArea() {
497 switch ($this->size) {
498 case SMOPT_SIZE_TINY: $rows = 3; $cols = 10; break;
499 case SMOPT_SIZE_SMALL: $rows = 4; $cols = 30; break;
500 case SMOPT_SIZE_LARGE: $rows = 10; $cols = 60; break;
501 case SMOPT_SIZE_HUGE: $rows = 20; $cols = 80; break;
502 case SMOPT_SIZE_NORMAL:
503 default: $rows = 5; $cols = 50;
504 }
505 return addTextArea('new_' . $this->name, $this->value, $cols, $rows, $this->aExtraAttribs);
506 }
507
508 /**
509 * Creates field for integer
510 *
511 * Difference from createWidget_String is visible only when javascript is enabled
512 * @return string html formated option field
513 */
514 function createWidget_Integer() {
515
516 // add onChange javascript handler to a regular string widget
517 // which will strip out all non-numeric chars
518 if (checkForJavascript())
519 $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; '
520 . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
521 . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
522 . 'this.value=newVal;';
523
524 return $this->createWidget_String();
525 }
526
527 /**
528 * Creates field for floating number
529 * Difference from createWidget_String is visible only when javascript is enabled
530 * @return string html formated option field
531 */
532 function createWidget_Float() {
533
534 // add onChange javascript handler to a regular string widget
535 // which will strip out all non-numeric (period also OK) chars
536 if (checkForJavascript())
537 $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; '
538 . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
539 . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
540 . 'newVal += origVal.charAt(i); } this.value=newVal;';
541
542 return $this->createWidget_String();
543 }
544
545 /**
546 * Create boolean widget
547 *
548 * @param boolean $checkbox When TRUE, the widget will be
549 * constructed as a checkbox,
550 * otherwise it will be a set of
551 * Yes/No radio buttons (OPTIONAL;
552 * default is FALSE (radio buttons)).
553 *
554 * @return string html formated boolean widget
555 *
556 */
557 function createWidget_Boolean($checkbox=FALSE) {
558
559 global $oTemplate, $nbsp;
560
561
562 // checkbox...
563 //
564 if ($checkbox) {
565 $result = addCheckbox('new_' . $this->name, ($this->value != SMPREF_NO), SMPREF_YES, array_merge(array('id' => 'new_' . $this->name), $this->aExtraAttribs)) . $nbsp . create_label($this->trailing_text, 'new_' . $this->name);
566 }
567
568 // radio buttons...
569 //
570 else {
571
572 /* Build the yes choice. */
573 $yes_option = addRadioBox('new_' . $this->name, ($this->value != SMPREF_NO), SMPREF_YES, array_merge(array('id' => 'new_' . $this->name . '_yes'), $this->aExtraAttribs)) . $nbsp . create_label(_("Yes"), 'new_' . $this->name . '_yes');
574
575 /* Build the no choice. */
576 $no_option = addRadioBox('new_' . $this->name, ($this->value == SMPREF_NO), SMPREF_NO, array_merge(array('id' => 'new_' . $this->name . '_no'), $this->aExtraAttribs)) . $nbsp . create_label(_("No"), 'new_' . $this->name . '_no');
577
578 /* Build the combined "boolean widget". */
579 $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option";
580
581 }
582
583 return ($result);
584 }
585
586 /**
587 * Creates hidden field
588 * @return string html formated hidden input field
589 */
590 function createWidget_Hidden() {
591 return addHidden('new_' . $this->name, $this->value, $this->aExtraAttribs);
592 }
593
594 /**
595 * Creates comment
596 * @return string comment
597 */
598 function createWidget_Comment() {
599 $result = $this->comment;
600 return ($result);
601 }
602
603 /**
604 * Creates an edit list
605 * @return string html formated list of edit fields and
606 * their associated controls
607 */
608 function createWidget_EditList() {
609
610 global $oTemplate;
611
612 switch ($this->size) {
613 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
614 case SMOPT_SIZE_TINY:
615 $height = 3;
616 break;
617 case SMOPT_SIZE_SMALL:
618 $height = 8;
619 break;
620 case SMOPT_SIZE_LARGE:
621 $height = 15;
622 break;
623 case SMOPT_SIZE_HUGE:
624 $height = 25;
625 break;
626 case SMOPT_SIZE_NORMAL:
627 default:
628 $height = 5;
629 }
630
631 if (empty($this->possible_values)) $this->possible_values = array();
632 if (!is_array($this->possible_values)) $this->possible_values = array($this->possible_values);
633
634 //FIXME: $this->aExtraAttribs probably should only be used in one place
635 $oTemplate->assign('input_widget', addInput('add_' . $this->name, '', 38, 0, $this->aExtraAttribs));
636 $oTemplate->assign('trailing_text', $this->trailing_text);
637 $oTemplate->assign('select_widget', addSelect('new_' . $this->name, $this->possible_values, $this->value, FALSE, !checkForJavascript() ? $this->aExtraAttribs : array_merge(array('onchange' => 'if (typeof(window.addinput) == \'undefined\') { var f = document.forms.length; var i = 0; var pos = -1; while( pos == -1 && i < f ) { var e = document.forms[i].elements.length; var j = 0; while( pos == -1 && j < e ) { if ( document.forms[i].elements[j].type == \'text\' && document.forms[i].elements[j].name == \'add_' . $this->name . '\' ) { pos = j; } j++; } i++; } if( pos >= 0 ) { window.addinput = document.forms[i-1].elements[pos]; } } for (x = 0; x < this.length; x++) { if (this.options[x].selected) { window.addinput.value = this.options[x].value; break; } }'), $this->aExtraAttribs), TRUE, $height));
638 $oTemplate->assign('checkbox_widget', addCheckBox('delete_' . $this->name, FALSE, SMPREF_YES, array_merge(array('id' => 'delete_' . $this->name), $this->aExtraAttribs)));
639 $oTemplate->assign('name', $this->name);
640 return $oTemplate->fetch('edit_list_widget.tpl');
641
642 }
643
644 /**
645 *
646 */
647 function save() {
648 $function = $this->save_function;
649 $function($this);
650 }
651
652 /**
653 *
654 */
655 function changed() {
656
657 // edit lists have a lot going on, so we'll always process them
658 //
659 if ($this->type == SMOPT_TYPE_EDIT_LIST) return TRUE;
660
661 return ($this->value != $this->new_value);
662 }
663 } /* End of SquirrelOption class*/
664
665 /**
666 * Saves the option value (this is the default save function
667 * unless overridden by the user)
668 *
669 * @param object $option object that holds option name and new_value
670 */
671 function save_option($option) {
672
673 // Can't save the pref if we don't have the username
674 //
675 if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) {
676 return;
677 }
678
679 global $data_dir;
680
681 // edit lists: first add new elements to list, then
682 // remove any selected ones (note that we must add
683 // before deleting because the javascript that populates
684 // the "add" textbox when selecting items in the list
685 // (for deletion))
686 //
687 if ($option->type == SMOPT_TYPE_EDIT_LIST) {
688
689 if (empty($option->possible_values)) $option->possible_values = array();
690 if (!is_array($option->possible_values)) $option->possible_values = array($option->possible_values);
691
692 // add element if given
693 //
694 if (sqGetGlobalVar('add_' . $option->name, $new_element, SQ_POST)) {
695 $new_element = trim($new_element);
696 if (!empty($new_element)
697 && !in_array($new_element, $option->possible_values))
698 $option->possible_values[] = $new_element;
699 }
700
701 // delete selected elements if needed
702 //
703 if (is_array($option->new_value)
704 && sqGetGlobalVar('delete_' . $option->name, $ignore, SQ_POST))
705 $option->possible_values = array_diff($option->possible_values, $option->new_value);
706
707 // save full list (stored in "possible_values")
708 //
709 setPref($data_dir, $username, $option->name, serialize($option->possible_values));
710
711 // Certain option types need to be serialized because
712 // they are not scalar
713 //
714 } else if ($option->is_multiple_valued())
715 setPref($data_dir, $username, $option->name, serialize($option->new_value));
716
717 else
718 setPref($data_dir, $username, $option->name, $option->new_value);
719
720 }
721
722 /**
723 * save function that does not save
724 * @param object $option
725 */
726 function save_option_noop($option) {
727 /* Do nothing here... */
728 }
729
730 /**
731 * Create hidden 'optpage' input field with value set by argument
732 * @param string $optpage identification of option page
733 * @return string html formated hidden input field
734 */
735 function create_optpage_element($optpage) {
736 return addHidden('optpage', $optpage);
737 }
738
739 /**
740 * Create hidden 'optmode' input field with value set by argument
741 * @param string $optmode
742 * @return string html formated hidden input field
743 */
744 function create_optmode_element($optmode) {
745 return addHidden('optmode', $optmode);
746 }
747
748 /**
749 * @param array $optgrps
750 * @param array $optvals
751 * @return array
752 */
753 function create_option_groups($optgrps, $optvals) {
754 /* Build a simple array with which to start. */
755 $result = array();
756
757 /* Create option group for each option group name. */
758 foreach ($optgrps as $grpkey => $grpname) {
759 $result[$grpkey] = array();
760 $result[$grpkey]['name'] = $grpname;
761 $result[$grpkey]['options'] = array();
762 }
763
764 /* Create a new SquirrelOption for each set of option values. */
765 foreach ($optvals as $grpkey => $grpopts) {
766 foreach ($grpopts as $optset) {
767 /* Create a new option with all values given. */
768 $next_option = new SquirrelOption(
769 $optset['name'],
770 $optset['caption'],
771 $optset['type'],
772 (isset($optset['refresh']) ? $optset['refresh'] : SMOPT_REFRESH_NONE),
773 (isset($optset['initial_value']) ? $optset['initial_value'] : ''),
774 (isset($optset['posvals']) ? $optset['posvals'] : ''),
775 (isset($optset['htmlencoded']) ? $optset['htmlencoded'] : false)
776 );
777
778 /* If provided, set the size for this option. */
779 if (isset($optset['size'])) {
780 $next_option->setSize($optset['size']);
781 }
782
783 /* If provided, set the trailing_text for this option. */
784 if (isset($optset['trailing_text'])) {
785 $next_option->setTrailingText($optset['trailing_text']);
786 }
787
788 /* If provided, set the comment for this option. */
789 if (isset($optset['comment'])) {
790 $next_option->setComment($optset['comment']);
791 }
792
793 /* If provided, set the save function for this option. */
794 if (isset($optset['save'])) {
795 $next_option->setSaveFunction($optset['save']);
796 }
797
798 /* If provided, set the extra attributes for this option. */
799 if (isset($optset['extra_attributes'])) {
800 $next_option->setExtraAttributes($optset['extra_attributes']);
801 }
802
803 /* If provided, set the "post script" for this option. */
804 if (isset($optset['post_script'])) {
805 $next_option->setPostScript($optset['post_script']);
806 }
807
808 /* If provided, set the folder_filter for this option. */
809 if (isset($optset['folder_filter'])) {
810 $next_option->setFolderFilter($optset['folder_filter']);
811 }
812
813 /* Add this option to the option array. */
814 $result[$grpkey]['options'][] = $next_option;
815 }
816 }
817
818 /* Return our resulting array. */
819 return ($result);
820 }
821