6 * Functions needed to display the options pages.
8 * @copyright © 1999-2009 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
16 * SquirrelOption: An option for SquirrelMail.
18 * @package squirrelmail
21 class SquirrelOption
{
23 * The original option configuration array
26 var $raw_option_array;
28 * The name of this setting
33 * The text that prefaces setting on the preferences page
38 * Whether or not the caption text is allowed to wrap
43 * The type of INPUT element
45 * See SMOPT_TYPE_* defines
50 * Indicates if a link should be shown to refresh part
51 * or all of the window
53 * See SMOPT_REFRESH_* defines
58 * Specifies the size of certain input items
60 * See SMOPT_SIZE_* defines
65 * Text that follows a text input or
66 * select list input on the preferences page
68 * useful for indicating units, meanings of special values, etc.
73 * Text that overrides the "Yes" label for boolean
74 * radio option widgets
80 * Text that overrides the "No" label for boolean
81 * radio option widgets
87 * Some widgets support more than one layout type
93 * Indicates if the Add widget should be included
100 * Indicates if the Delete widget should be included
105 var $use_delete_widget;
107 * text displayed to the user
109 * Used with SMOPT_TYPE_COMMENT options
114 * additional javascript or other widget attributes added to the
115 * user input; must be an array where keys are attribute names
116 * ("onclick", etc) and values are the attribute values.
121 * script (usually Javascript) that will be placed after (outside of)
128 * The name of the Save Function for this option.
133 /* The various 'values' for this options. */
135 * default/preselected value for this option
145 * associative array, where each key is an actual input value
146 * and the corresponding value is what is displayed to the user
147 * for that list item in the drop-down list
150 var $possible_values;
152 * disables html sanitizing.
154 * WARNING - don't use it, if user input is possible in option
155 * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
158 var $htmlencoded=false;
160 * Controls folder list limits in SMOPT_TYPE_FLDRLIST and
161 * SMOPT_TYPE_FLDRLIST_MULTI widgets.
162 * See $flag argument in sqimap_mailbox_option_list() function.
166 var $folder_filter='noselect';
169 * Constructor function
170 * @param array $raw_option_array
171 * @param string $name
172 * @param string $caption
173 * @param integer $type
174 * @param integer $refresh_level
175 * @param mixed $initial_value
176 * @param array $possible_values
177 * @param bool $htmlencoded
179 function SquirrelOption
180 ($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) {
181 /* Set the basic stuff. */
182 $this->raw_option_array
= $raw_option_array;
184 $this->caption
= $caption;
185 $this->caption_wrap
= TRUE;
187 $this->refresh_level
= $refresh_level;
188 $this->possible_values
= $possible_values;
189 $this->htmlencoded
= $htmlencoded;
190 $this->size
= SMOPT_SIZE_NORMAL
;
191 $this->trailing_text
= '';
192 $this->yes_text
= '';
195 $this->layout_type
= 0;
196 $this->use_add_widget
= TRUE;
197 $this->use_delete_widget
= TRUE;
198 $this->aExtraAttribs
= array();
199 $this->post_script
= '';
201 //Check for a current value.
202 if (isset($GLOBALS[$name])) {
203 $this->value
= $GLOBALS[$name];
204 } else if (!empty($initial_value)) {
205 $this->value
= $initial_value;
210 /* Check for a new value. */
211 if ( !sqgetGlobalVar("new_$name", $this->new_value
, SQ_POST
) ) {
212 $this->new_value
= NULL;
215 /* Set the default save function. */
216 if ($type != SMOPT_TYPE_HIDDEN
217 && $type != SMOPT_TYPE_INFO
218 && $type != SMOPT_TYPE_COMMENT
) {
219 $this->save_function
= SMOPT_SAVE_DEFAULT
;
221 $this->save_function
= SMOPT_SAVE_NOOP
;
225 /** Convenience function that identifies which types of
226 widgets are stored as (serialized) array values. */
227 function is_multiple_valued() {
228 return ($this->type
== SMOPT_TYPE_FLDRLIST_MULTI
229 ||
$this->type
== SMOPT_TYPE_STRLIST_MULTI
230 ||
$this->type
== SMOPT_TYPE_EDIT_LIST
);
234 * Set the value for this option.
235 * @param mixed $value
237 function setValue($value) {
238 $this->value
= $value;
242 * Set the new value for this option.
243 * @param mixed $new_value
245 function setNewValue($new_value) {
246 $this->new_value
= $new_value;
250 * Set whether the caption is allowed to wrap for this option.
251 * @param boolean $caption_wrap
253 function setCaptionWrap($caption_wrap) {
254 $this->caption_wrap
= $caption_wrap;
258 * Set the size for this option.
259 * @param integer $size
261 function setSize($size) {
266 * Set the trailing_text for this option.
267 * @param string $trailing_text
269 function setTrailingText($trailing_text) {
270 $this->trailing_text
= $trailing_text;
274 * Set the yes_text for this option.
275 * @param string $yes_text
277 function setYesText($yes_text) {
278 $this->yes_text
= $yes_text;
282 * Set the no_text for this option.
283 * @param string $no_text
285 function setNoText($no_text) {
286 $this->no_text
= $no_text;
289 /* Set the "use add widget" value for this option. */
290 function setUseAddWidget($use_add_widget) {
291 $this->use_add_widget
= $use_add_widget;
294 /* Set the "use delete widget" value for this option. */
295 function setUseDeleteWidget($use_delete_widget) {
296 $this->use_delete_widget
= $use_delete_widget;
300 * Set the layout type for this option.
301 * @param int $layout_type
303 function setLayoutType($layout_type) {
304 $this->layout_type
= $layout_type;
308 * Set the comment for this option.
309 * @param string $comment
311 function setComment($comment) {
312 $this->comment
= $comment;
316 * Set the extra attributes for this option.
317 * @param array $aExtraAttribs
319 function setExtraAttributes($aExtraAttribs) {
320 $this->aExtraAttribs
= $aExtraAttribs;
324 * Set the "post script" for this option.
325 * @param string $post_script
327 function setPostScript($post_script) {
328 $this->post_script
= $post_script;
332 * Set the save function for this option.
333 * @param string $save_function
335 function setSaveFunction($save_function) {
336 $this->save_function
= $save_function;
340 * Set the folder_filter for this option.
341 * @param string $folder_filter
344 function setFolderFilter($folder_filter) {
345 $this->folder_filter
= $folder_filter;
349 * Creates fields on option pages according to option type
351 * This is the function that calls all other createWidget* functions.
353 * @return string The formated option field
356 function createWidget() {
359 // Use new value if available
360 if (!is_null($this->new_value
)) {
361 $tempValue = $this->value
;
362 $this->value
= $this->new_value
;
365 /* Get the widget for this option type. */
366 switch ($this->type
) {
367 case SMOPT_TYPE_PASSWORD
:
368 $result = $this->createWidget_String(TRUE);
370 case SMOPT_TYPE_STRING
:
371 $result = $this->createWidget_String();
373 case SMOPT_TYPE_STRLIST
:
374 $result = $this->createWidget_StrList();
376 case SMOPT_TYPE_TEXTAREA
:
377 $result = $this->createWidget_TextArea();
379 case SMOPT_TYPE_INTEGER
:
380 $result = $this->createWidget_Integer();
382 case SMOPT_TYPE_FLOAT
:
383 $result = $this->createWidget_Float();
385 case SMOPT_TYPE_BOOLEAN
:
386 $result = $this->createWidget_Boolean();
388 case SMOPT_TYPE_BOOLEAN_CHECKBOX
:
389 $result = $this->createWidget_Boolean(TRUE);
391 case SMOPT_TYPE_BOOLEAN_RADIO
:
392 $result = $this->createWidget_Boolean(FALSE);
394 case SMOPT_TYPE_HIDDEN
:
395 $result = $this->createWidget_Hidden();
397 case SMOPT_TYPE_COMMENT
:
398 $result = $this->createWidget_Comment();
400 case SMOPT_TYPE_FLDRLIST
:
401 $result = $this->createWidget_FolderList();
403 case SMOPT_TYPE_FLDRLIST_MULTI
:
404 $result = $this->createWidget_FolderList(TRUE);
406 case SMOPT_TYPE_EDIT_LIST
:
407 $result = $this->createWidget_EditList();
409 case SMOPT_TYPE_STRLIST_MULTI
:
410 $result = $this->createWidget_StrList(TRUE);
412 case SMOPT_TYPE_STRLIST_RADIO
:
413 $result = $this->createWidget_StrList(FALSE, TRUE);
415 case SMOPT_TYPE_SUBMIT
:
416 $result = $this->createWidget_Submit();
418 case SMOPT_TYPE_INFO
:
419 $result = $this->createWidget_Info();
423 sprintf(_("Option Type '%s' Not Found"), $this->type
)
427 /* Add the "post script" for this option. */
428 $result .= $this->post_script
;
430 // put correct value back if need be
431 if (!is_null($this->new_value
)) {
432 $this->value
= $tempValue;
435 /* Now, return the created widget. */
441 * @return string html formated output
443 function createWidget_Info() {
444 return sq_htmlspecialchars($this->value
);
448 * Create string field
450 * @param boolean $password When TRUE, the text in the input
451 * widget will be obscured (OPTIONAL;
454 * @return string html formated option field
457 function createWidget_String($password=FALSE) {
458 switch ($this->size
) {
459 case SMOPT_SIZE_TINY
:
462 case SMOPT_SIZE_SMALL
:
465 case SMOPT_SIZE_LARGE
:
468 case SMOPT_SIZE_HUGE
:
471 case SMOPT_SIZE_NORMAL
:
476 //TODO: might be better to have a separate template file for all widgets, because then the layout of the widget and the "trailing text" can be customized - they are still hard coded here
478 return addPwField('new_' . $this->name
, $this->value
, $width, 0, $this->aExtraAttribs
) . ' ' . htmlspecialchars($this->trailing_text
);
480 return addInput('new_' . $this->name
, $this->value
, $width, 0, $this->aExtraAttribs
) . ' ' . htmlspecialchars($this->trailing_text
);
484 * Create selection box or radio button group
486 * When $this->htmlencoded is TRUE, the keys and values in
487 * $this->possible_values are assumed to be display-safe.
490 * Note that when building radio buttons instead of a select
491 * widget, if the "size" attribute is SMOPT_SIZE_TINY, the
492 * radio buttons will be output one after another without
493 * linebreaks between them. Otherwise, each radio button
494 * goes on a line of its own.
496 * @param boolean $multiple_select When TRUE, the select widget
497 * will allow multiple selections
498 * (OPTIONAL; default is FALSE
499 * (single select list))
500 * @param boolean $radio_buttons When TRUE, the widget will
501 * instead be built as a group
502 * of radio buttons (and
503 * $multiple_select will be
504 * forced to FALSE) (OPTIONAL;
505 * default is FALSE (select widget))
507 * @return string html formated selection box or radio buttons
510 function createWidget_StrList($multiple_select=FALSE, $radio_buttons=FALSE) {
511 //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
513 // radio buttons instead of select widget?
515 if ($radio_buttons) {
519 foreach ($this->possible_values
as $real_value => $disp_value) {
520 $result .= addRadioBox('new_' . $this->name
, ($this->value
== $real_value), $real_value, array_merge(array('id' => 'new_' . $this->name
. '_' . $real_value), $this->aExtraAttribs
)) . $nbsp . create_label($disp_value, 'new_' . $this->name
. '_' . $real_value);
521 if ($this->size
!= SMOPT_SIZE_TINY
)
529 // everything below applies to select widgets
531 switch ($this->size
) {
532 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
533 case SMOPT_SIZE_TINY
:
536 case SMOPT_SIZE_SMALL
:
539 case SMOPT_SIZE_LARGE
:
542 case SMOPT_SIZE_HUGE
:
545 case SMOPT_SIZE_NORMAL
:
550 return addSelect('new_' . $this->name
, $this->possible_values
, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height, !$this->htmlencoded
) . htmlspecialchars($this->trailing_text
);
555 * Create folder selection box
557 * @param boolean $multiple_select When TRUE, the select widget
558 * will allow multiple selections
559 * (OPTIONAL; default is FALSE
560 * (single select list))
562 * @return string html formated selection box
565 function createWidget_FolderList($multiple_select=FALSE) {
567 switch ($this->size
) {
568 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
569 case SMOPT_SIZE_TINY
:
572 case SMOPT_SIZE_SMALL
:
575 case SMOPT_SIZE_LARGE
:
578 case SMOPT_SIZE_HUGE
:
581 case SMOPT_SIZE_NORMAL
:
586 // possible values might include a nested array of
587 // possible values (list of folders)
589 $option_list = array();
590 foreach ($this->possible_values
as $value => $text) {
592 // list of folders (boxes array)
594 if (is_array($text)) {
595 $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter
));
597 // just one option here
600 $option_list = array_merge($option_list, array($value => $text));
604 if (empty($option_list))
605 $option_list = array('ignore' => _("unavailable"));
608 return addSelect('new_' . $this->name
, $option_list, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height) . htmlspecialchars($this->trailing_text
);
614 * @return string html formated textarea field
616 function createWidget_TextArea() {
617 switch ($this->size
) {
618 case SMOPT_SIZE_TINY
: $rows = 3; $cols = 10; break;
619 case SMOPT_SIZE_SMALL
: $rows = 4; $cols = 30; break;
620 case SMOPT_SIZE_LARGE
: $rows = 10; $cols = 60; break;
621 case SMOPT_SIZE_HUGE
: $rows = 20; $cols = 80; break;
622 case SMOPT_SIZE_NORMAL
:
623 default: $rows = 5; $cols = 50;
625 return addTextArea('new_' . $this->name
, $this->value
, $cols, $rows, $this->aExtraAttribs
);
629 * Creates field for integer
631 * Difference from createWidget_String is visible only when javascript is enabled
632 * @return string html formated option field
634 function createWidget_Integer() {
636 // add onChange javascript handler to a regular string widget
637 // which will strip out all non-numeric chars
638 if (checkForJavascript())
639 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
640 . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
641 . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
642 . 'this.value=newVal;';
644 return $this->createWidget_String();
648 * Creates field for floating number
649 * Difference from createWidget_String is visible only when javascript is enabled
650 * @return string html formated option field
652 function createWidget_Float() {
654 // add onChange javascript handler to a regular string widget
655 // which will strip out all non-numeric (period also OK) chars
656 if (checkForJavascript())
657 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
658 . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
659 . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
660 . 'newVal += origVal.charAt(i); } this.value=newVal;';
662 return $this->createWidget_String();
666 * Create boolean widget
668 * When creating Yes/No radio buttons, the "yes_text"
669 * and "no_text" option attributes are used to override
670 * the typical "Yes" and "No" text.
672 * @param boolean $checkbox When TRUE, the widget will be
673 * constructed as a checkbox,
674 * otherwise it will be a set of
675 * Yes/No radio buttons (OPTIONAL;
676 * default is TRUE (checkbox)).
678 * @return string html formated boolean widget
681 function createWidget_Boolean($checkbox=TRUE) {
683 global $oTemplate, $nbsp;
689 $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
);
696 /* Build the yes choice. */
697 $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((!empty($this->yes_text
) ?
$this->yes_text
: _("Yes")), 'new_' . $this->name
. '_yes');
699 /* Build the no choice. */
700 $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((!empty($this->no_text
) ?
$this->no_text
: _("No")), 'new_' . $this->name
. '_no');
702 /* Build the combined "boolean widget". */
703 $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option";
711 * Creates hidden field
712 * @return string html formated hidden input field
714 function createWidget_Hidden() {
715 return addHidden('new_' . $this->name
, $this->value
, $this->aExtraAttribs
);
720 * @return string comment
722 function createWidget_Comment() {
723 $result = $this->comment
;
728 * Creates an edit list
730 * Note that multiple layout types are supported for this widget.
731 * $this->layout_type must be one of the SMOPT_EDIT_LIST_LAYOUT_*
734 * @return string html formated list of edit fields and
735 * their associated controls
737 function createWidget_EditList() {
741 switch ($this->size
) {
742 case SMOPT_SIZE_TINY
:
745 case SMOPT_SIZE_SMALL
:
748 case SMOPT_SIZE_MEDIUM
:
751 case SMOPT_SIZE_LARGE
:
754 case SMOPT_SIZE_HUGE
:
757 case SMOPT_SIZE_NORMAL
:
762 if (empty($this->possible_values
)) $this->possible_values
= array();
763 if (!is_array($this->possible_values
)) $this->possible_values
= array($this->possible_values
);
765 //FIXME: $this->aExtraAttribs probably should only be used in one place
766 $oTemplate->assign('input_widget', addInput('add_' . $this->name
, '', 38, 0, $this->aExtraAttribs
));
767 $oTemplate->assign('use_input_widget', $this->use_add_widget
);
768 $oTemplate->assign('use_delete_widget', $this->use_delete_widget
);
770 $oTemplate->assign('trailing_text', $this->trailing_text
);
771 $oTemplate->assign('possible_values', $this->possible_values
);
772 $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_' . $this->name
. ') == \'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_' . $this->name
. ' = document.forms[i-1].elements[pos]; } } for (x = 0; x < this.length; x++) { if (this.options[x].selected) { window.addinput_' . $this->name
. '.value = this.options[x].value; break; } }'), $this->aExtraAttribs
), TRUE, $height));
773 $oTemplate->assign('checkbox_widget', addCheckBox('delete_' . $this->name
, FALSE, SMPREF_YES
, array_merge(array('id' => 'delete_' . $this->name
), $this->aExtraAttribs
)));
774 $oTemplate->assign('name', $this->name
);
776 switch ($this->layout_type
) {
777 case SMOPT_EDIT_LIST_LAYOUT_SELECT
:
778 return $oTemplate->fetch('edit_list_widget.tpl');
779 case SMOPT_EDIT_LIST_LAYOUT_LIST
:
780 return $oTemplate->fetch('edit_list_widget_list_style.tpl');
782 error_box(sprintf(_("Edit List Layout Type '%s' Not Found"), $layout_type));
788 * Creates a submit button
790 * @return string html formated submit button widget
793 function createWidget_Submit() {
795 return addSubmit($this->comment
, $this->name
, $this->aExtraAttribs
) . htmlspecialchars($this->trailing_text
);
803 $function = $this->save_function
;
812 // edit lists have a lot going on, so we'll always process them
814 if ($this->type
== SMOPT_TYPE_EDIT_LIST
) return TRUE;
816 return ($this->value
!= $this->new_value
);
818 } /* End of SquirrelOption class*/
821 * Saves the option value (this is the default save function
822 * unless overridden by the user)
824 * @param object $option object that holds option name and new_value
826 function save_option($option) {
828 // Can't save the pref if we don't have the username
830 if ( !sqgetGlobalVar('username', $username, SQ_SESSION
) ) {
836 // edit lists: first add new elements to list, then
837 // remove any selected ones (note that we must add
838 // before deleting because the javascript that populates
839 // the "add" textbox when selecting items in the list
842 if ($option->type
== SMOPT_TYPE_EDIT_LIST
) {
844 if (empty($option->possible_values
)) $option->possible_values
= array();
845 if (!is_array($option->possible_values
)) $option->possible_values
= array($option->possible_values
);
847 // add element if given
849 if ((isset($option->use_add_widget
) && $option->use_add_widget
)
850 && sqGetGlobalVar('add_' . $option->name
, $new_element, SQ_POST
)) {
851 $new_element = trim($new_element);
852 if (!empty($new_element)
853 && !in_array($new_element, $option->possible_values
))
854 $option->possible_values
[] = $new_element;
857 // delete selected elements if needed
859 if ((isset($option->use_delete_widget
) && $option->use_delete_widget
)
860 && is_array($option->new_value
)
861 && sqGetGlobalVar('delete_' . $option->name
, $ignore, SQ_POST
))
862 $option->possible_values
= array_diff($option->possible_values
, $option->new_value
);
864 // save full list (stored in "possible_values")
866 setPref($data_dir, $username, $option->name
, serialize($option->possible_values
));
868 // Certain option types need to be serialized because
869 // they are not scalar
871 } else if ($option->is_multiple_valued())
872 setPref($data_dir, $username, $option->name
, serialize($option->new_value
));
874 // Checkboxes, when unchecked, don't submit anything in
875 // the POST, so set to SMPREF_OFF if not found
877 else if (($option->type
== SMOPT_TYPE_BOOLEAN
878 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
879 && empty($option->new_value
))
880 setPref($data_dir, $username, $option->name
, SMPREF_OFF
);
883 setPref($data_dir, $username, $option->name
, $option->new_value
);
886 // if a checkbox or multi select is zeroed/cleared out, it
887 // needs to have an empty value pushed into its "new_value" slot
889 if (($option->type
== SMOPT_TYPE_STRLIST_MULTI
890 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
891 && is_null($option->new_value
))
892 $option->new_value
= '';
897 * save function that does not save
898 * @param object $option
900 function save_option_noop($option) {
901 /* Do nothing here... */
905 * Create hidden 'optpage' input field with value set by argument
906 * @param string $optpage identification of option page
907 * @return string html formated hidden input field
909 function create_optpage_element($optpage) {
910 return addHidden('optpage', $optpage);
914 * Create hidden 'optmode' input field with value set by argument
915 * @param string $optmode
916 * @return string html formated hidden input field
918 function create_optmode_element($optmode) {
919 return addHidden('optmode', $optmode);
923 * @param array $optgrps
924 * @param array $optvals
927 function create_option_groups($optgrps, $optvals) {
928 /* Build a simple array with which to start. */
931 /* Create option group for each option group name. */
932 foreach ($optgrps as $grpkey => $grpname) {
933 $result[$grpkey] = array();
934 $result[$grpkey]['name'] = $grpname;
935 $result[$grpkey]['options'] = array();
938 /* Create a new SquirrelOption for each set of option values. */
939 foreach ($optvals as $grpkey => $grpopts) {
940 foreach ($grpopts as $optset) {
941 /* Create a new option with all values given. */
942 $next_option = new SquirrelOption(
947 (isset($optset['refresh']) ?
$optset['refresh'] : SMOPT_REFRESH_NONE
),
948 (isset($optset['initial_value']) ?
$optset['initial_value'] : ''),
949 (isset($optset['posvals']) ?
$optset['posvals'] : ''),
950 (isset($optset['htmlencoded']) ?
$optset['htmlencoded'] : false)
953 /* If provided, set if the caption is allowed to wrap for this option. */
954 if (isset($optset['caption_wrap'])) {
955 $next_option->setCaptionWrap($optset['caption_wrap']);
958 /* If provided, set the size for this option. */
959 if (isset($optset['size'])) {
960 $next_option->setSize($optset['size']);
963 /* If provided, set the trailing_text for this option. */
964 if (isset($optset['trailing_text'])) {
965 $next_option->setTrailingText($optset['trailing_text']);
968 /* If provided, set the yes_text for this option. */
969 if (isset($optset['yes_text'])) {
970 $next_option->setYesText($optset['yes_text']);
973 /* If provided, set the no_text for this option. */
974 if (isset($optset['no_text'])) {
975 $next_option->setNoText($optset['no_text']);
978 /* If provided, set the layout type for this option. */
979 if (isset($optset['layout_type'])) {
980 $next_option->setLayoutType($optset['layout_type']);
983 /* If provided, set the use_add_widget value for this option. */
984 if (isset($optset['use_add_widget'])) {
985 $next_option->setUseAddWidget($optset['use_add_widget']);
988 /* If provided, set the use_delete_widget value for this option. */
989 if (isset($optset['use_delete_widget'])) {
990 $next_option->setUseDeleteWidget($optset['use_delete_widget']);
993 /* If provided, set the comment for this option. */
994 if (isset($optset['comment'])) {
995 $next_option->setComment($optset['comment']);
998 /* If provided, set the save function for this option. */
999 if (isset($optset['save'])) {
1000 $next_option->setSaveFunction($optset['save']);
1003 /* If provided, set the extra attributes for this option. */
1004 if (isset($optset['extra_attributes'])) {
1005 $next_option->setExtraAttributes($optset['extra_attributes']);
1008 /* If provided, set the "post script" for this option. */
1009 if (isset($optset['post_script'])) {
1010 $next_option->setPostScript($optset['post_script']);
1013 /* If provided, set the folder_filter for this option. */
1014 if (isset($optset['folder_filter'])) {
1015 $next_option->setFolderFilter($optset['folder_filter']);
1018 /* Add this option to the option array. */
1019 $result[$grpkey]['options'][] = $next_option;
1023 /* Return our resulting array. */