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