6 * Functions needed to display the options pages.
8 * @copyright © 1999-2007 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
15 /**********************************************/
16 /* Define constants used in the options code. */
17 /**********************************************/
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 define('SMOPT_TYPE_STRLIST_RADIO', 14);
35 define('SMOPT_TYPE_SUBMIT', 15);
37 /* Define constants for the layout scheme for edit lists. */
38 define('SMOPT_EDIT_LIST_LAYOUT_LIST', 0);
39 define('SMOPT_EDIT_LIST_LAYOUT_SELECT', 1);
41 /* Define constants for the options refresh levels. */
42 define('SMOPT_REFRESH_NONE', 0);
43 define('SMOPT_REFRESH_FOLDERLIST', 1);
44 define('SMOPT_REFRESH_ALL', 2);
46 /* Define constants for the options size. */
47 define('SMOPT_SIZE_TINY', 0);
48 define('SMOPT_SIZE_SMALL', 1);
49 define('SMOPT_SIZE_MEDIUM', 2);
50 define('SMOPT_SIZE_LARGE', 3);
51 define('SMOPT_SIZE_HUGE', 4);
52 define('SMOPT_SIZE_NORMAL', 5);
54 define('SMOPT_SAVE_DEFAULT', 'save_option');
55 define('SMOPT_SAVE_NOOP', 'save_option_noop');
58 * SquirrelOption: An option for SquirrelMail.
60 * @package squirrelmail
63 class SquirrelOption
{
65 * The original option configuration array
68 var $raw_option_array;
70 * The name of this setting
75 * The text that prefaces setting on the preferences page
80 * The type of INPUT element
82 * See SMOPT_TYPE_* defines
87 * Indicates if a link should be shown to refresh part
88 * or all of the window
90 * See SMOPT_REFRESH_* defines
95 * Specifies the size of certain input items
97 * See SMOPT_SIZE_* defines
102 * Text that follows a text input or
103 * select list input on the preferences page
105 * useful for indicating units, meanings of special values, etc.
110 * Text that overrides the "Yes" label for boolean
111 * radio option widgets
117 * Text that overrides the "No" label for boolean
118 * radio option widgets
124 * Some widgets support more than one layout type
130 * Indicates if the Add widget should be included
137 * text displayed to the user
139 * Used with SMOPT_TYPE_COMMENT options
144 * additional javascript or other widget attributes added to the
145 * user input; must be an array where keys are attribute names
146 * ("onclick", etc) and values are the attribute values.
151 * script (usually Javascript) that will be placed after (outside of)
158 * The name of the Save Function for this option.
163 /* The various 'values' for this options. */
165 * default/preselected value for this option
175 * associative array, where each key is an actual input value
176 * and the corresponding value is what is displayed to the user
177 * for that list item in the drop-down list
180 var $possible_values;
182 * disables html sanitizing.
184 * WARNING - don't use it, if user input is possible in option
185 * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
188 var $htmlencoded=false;
190 * Controls folder list limits in SMOPT_TYPE_FLDRLIST and
191 * SMOPT_TYPE_FLDRLIST_MULTI widgets.
192 * See $flag argument in sqimap_mailbox_option_list() function.
196 var $folder_filter='noselect';
199 * Constructor function
200 * @param array $raw_option_array
201 * @param string $name
202 * @param string $caption
203 * @param integer $type
204 * @param integer $refresh_level
205 * @param mixed $initial_value
206 * @param array $possible_values
207 * @param bool $htmlencoded
209 function SquirrelOption
210 ($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) {
211 /* Set the basic stuff. */
212 $this->raw_option_array
= $raw_option_array;
214 $this->caption
= $caption;
216 $this->refresh_level
= $refresh_level;
217 $this->possible_values
= $possible_values;
218 $this->htmlencoded
= $htmlencoded;
219 $this->size
= SMOPT_SIZE_NORMAL
;
220 $this->trailing_text
= '';
221 $this->yes_text
= '';
224 $this->layout_type
= 0;
225 $this->use_add_widget
= TRUE;
226 $this->aExtraAttribs
= array();
227 $this->post_script
= '';
229 //Check for a current value.
230 if (isset($GLOBALS[$name])) {
231 $this->value
= $GLOBALS[$name];
232 } else if (!empty($initial_value)) {
233 $this->value
= $initial_value;
238 /* Check for a new value. */
239 if ( !sqgetGlobalVar("new_$name", $this->new_value
, SQ_POST
) ) {
240 $this->new_value
= NULL;
243 /* Set the default save function. */
244 if (($type != SMOPT_TYPE_HIDDEN
) && ($type != SMOPT_TYPE_COMMENT
)) {
245 $this->save_function
= SMOPT_SAVE_DEFAULT
;
247 $this->save_function
= SMOPT_SAVE_NOOP
;
251 /** Convenience function that identifies which types of
252 widgets are stored as (serialized) array values. */
253 function is_multiple_valued() {
254 return ($this->type
== SMOPT_TYPE_FLDRLIST_MULTI
255 ||
$this->type
== SMOPT_TYPE_STRLIST_MULTI
256 ||
$this->type
== SMOPT_TYPE_EDIT_LIST
);
260 * Set the value for this option.
261 * @param mixed $value
263 function setValue($value) {
264 $this->value
= $value;
268 * Set the new value for this option.
269 * @param mixed $new_value
271 function setNewValue($new_value) {
272 $this->new_value
= $new_value;
276 * Set the size for this option.
277 * @param integer $size
279 function setSize($size) {
284 * Set the trailing_text for this option.
285 * @param string $trailing_text
287 function setTrailingText($trailing_text) {
288 $this->trailing_text
= $trailing_text;
292 * Set the yes_text for this option.
293 * @param string $yes_text
295 function setYesText($yes_text) {
296 $this->yes_text
= $yes_text;
300 * Set the no_text for this option.
301 * @param string $no_text
303 function setNoText($no_text) {
304 $this->no_text
= $no_text;
307 /* Set the "use add widget" value for this option. */
308 function setUseAddWidget($use_add_widget) {
309 $this->use_add_widget
= $use_add_widget;
313 * Set the layout type for this option.
314 * @param int $layout_type
316 function setLayoutType($layout_type) {
317 $this->layout_type
= $layout_type;
321 * Set the comment for this option.
322 * @param string $comment
324 function setComment($comment) {
325 $this->comment
= $comment;
329 * Set the extra attributes for this option.
330 * @param array $aExtraAttribs
332 function setExtraAttributes($aExtraAttribs) {
333 $this->aExtraAttribs
= $aExtraAttribs;
337 * Set the "post script" for this option.
338 * @param string $post_script
340 function setPostScript($post_script) {
341 $this->post_script
= $post_script;
345 * Set the save function for this option.
346 * @param string $save_function
348 function setSaveFunction($save_function) {
349 $this->save_function
= $save_function;
353 * Set the folder_filter for this option.
354 * @param string $folder_filter
357 function setFolderFilter($folder_filter) {
358 $this->folder_filter
= $folder_filter;
362 * Creates fields on option pages according to option type
364 * This is the function that calls all other createWidget* functions.
366 * @return string The formated option field
369 function createWidget() {
372 // Use new value if available
373 if (!is_null($this->new_value
)) {
374 $tempValue = $this->value
;
375 $this->value
= $this->new_value
;
378 /* Get the widget for this option type. */
379 switch ($this->type
) {
380 case SMOPT_TYPE_STRING
:
381 $result = $this->createWidget_String();
383 case SMOPT_TYPE_STRLIST
:
384 $result = $this->createWidget_StrList();
386 case SMOPT_TYPE_TEXTAREA
:
387 $result = $this->createWidget_TextArea();
389 case SMOPT_TYPE_INTEGER
:
390 $result = $this->createWidget_Integer();
392 case SMOPT_TYPE_FLOAT
:
393 $result = $this->createWidget_Float();
395 case SMOPT_TYPE_BOOLEAN
:
396 $result = $this->createWidget_Boolean();
398 case SMOPT_TYPE_BOOLEAN_CHECKBOX
:
399 $result = $this->createWidget_Boolean(TRUE);
401 case SMOPT_TYPE_BOOLEAN_RADIO
:
402 $result = $this->createWidget_Boolean(FALSE);
404 case SMOPT_TYPE_HIDDEN
:
405 $result = $this->createWidget_Hidden();
407 case SMOPT_TYPE_COMMENT
:
408 $result = $this->createWidget_Comment();
410 case SMOPT_TYPE_FLDRLIST
:
411 $result = $this->createWidget_FolderList();
413 case SMOPT_TYPE_FLDRLIST_MULTI
:
414 $result = $this->createWidget_FolderList(TRUE);
416 case SMOPT_TYPE_EDIT_LIST
:
417 $result = $this->createWidget_EditList();
419 case SMOPT_TYPE_STRLIST_MULTI
:
420 $result = $this->createWidget_StrList(TRUE);
422 case SMOPT_TYPE_STRLIST_RADIO
:
423 $result = $this->createWidget_StrList(FALSE, TRUE);
425 case SMOPT_TYPE_SUBMIT
:
426 $result = $this->createWidget_Submit();
430 sprintf(_("Option Type '%s' Not Found"), $this->type
)
434 /* Add the "post script" for this option. */
435 $result .= $this->post_script
;
437 // put correct value back if need be
438 if (!is_null($this->new_value
)) {
439 $this->value
= $tempValue;
442 /* Now, return the created widget. */
447 * Create string field
448 * @return string html formated option field
450 function createWidget_String() {
451 switch ($this->size
) {
452 case SMOPT_SIZE_TINY
:
455 case SMOPT_SIZE_SMALL
:
458 case SMOPT_SIZE_LARGE
:
461 case SMOPT_SIZE_HUGE
:
464 case SMOPT_SIZE_NORMAL
:
469 return addInput('new_' . $this->name
, $this->value
, $width, 0, $this->aExtraAttribs
) . htmlspecialchars($this->trailing_text
);
473 * Create selection box or radio button group
475 * When $this->htmlencoded is TRUE, the keys and values in
476 * $this->possible_values are assumed to be display-safe.
479 * Note that when building radio buttons instead of a select
480 * widget, if the "size" attribute is SMOPT_SIZE_TINY, the
481 * radio buttons will be output one after another without
482 * linebreaks between them. Otherwise, each radio button
483 * goes on a line of its own.
485 * @param boolean $multiple_select When TRUE, the select widget
486 * will allow multiple selections
487 * (OPTIONAL; default is FALSE
488 * (single select list))
489 * @param boolean $radio_buttons When TRUE, the widget will
490 * instead be built as a group
491 * of radio buttons (and
492 * $multiple_select will be
493 * forced to FALSE) (OPTIONAL;
494 * default is FALSE (select widget))
496 * @return string html formated selection box or radio buttons
499 function createWidget_StrList($multiple_select=FALSE, $radio_buttons=FALSE) {
500 //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
502 // radio buttons instead of select widget?
504 if ($radio_buttons) {
508 foreach ($this->possible_values
as $real_value => $disp_value) {
509 $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);
510 if ($this->size
!= SMOPT_SIZE_TINY
)
518 // everything below applies to select widgets
520 switch ($this->size
) {
521 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
522 case SMOPT_SIZE_TINY
:
525 case SMOPT_SIZE_SMALL
:
528 case SMOPT_SIZE_LARGE
:
531 case SMOPT_SIZE_HUGE
:
534 case SMOPT_SIZE_NORMAL
:
539 return addSelect('new_' . $this->name
, $this->possible_values
, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height, !$this->htmlencoded
) . htmlspecialchars($this->trailing_text
);
544 * Create folder selection box
546 * @param boolean $multiple_select When TRUE, the select widget
547 * will allow multiple selections
548 * (OPTIONAL; default is FALSE
549 * (single select list))
551 * @return string html formated selection box
554 function createWidget_FolderList($multiple_select=FALSE) {
556 switch ($this->size
) {
557 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
558 case SMOPT_SIZE_TINY
:
561 case SMOPT_SIZE_SMALL
:
564 case SMOPT_SIZE_LARGE
:
567 case SMOPT_SIZE_HUGE
:
570 case SMOPT_SIZE_NORMAL
:
575 // possible values might include a nested array of
576 // possible values (list of folders)
578 $option_list = array();
579 foreach ($this->possible_values
as $value => $text) {
581 // list of folders (boxes array)
583 if (is_array($text)) {
584 $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter
));
586 // just one option here
589 $option_list = array_merge($option_list, array($value => $text));
593 if (empty($option_list))
594 $option_list = array('ignore' => _("unavailable"));
597 return addSelect('new_' . $this->name
, $option_list, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height) . htmlspecialchars($this->trailing_text
);
603 * @return string html formated textarea field
605 function createWidget_TextArea() {
606 switch ($this->size
) {
607 case SMOPT_SIZE_TINY
: $rows = 3; $cols = 10; break;
608 case SMOPT_SIZE_SMALL
: $rows = 4; $cols = 30; break;
609 case SMOPT_SIZE_LARGE
: $rows = 10; $cols = 60; break;
610 case SMOPT_SIZE_HUGE
: $rows = 20; $cols = 80; break;
611 case SMOPT_SIZE_NORMAL
:
612 default: $rows = 5; $cols = 50;
614 return addTextArea('new_' . $this->name
, $this->value
, $cols, $rows, $this->aExtraAttribs
);
618 * Creates field for integer
620 * Difference from createWidget_String is visible only when javascript is enabled
621 * @return string html formated option field
623 function createWidget_Integer() {
625 // add onChange javascript handler to a regular string widget
626 // which will strip out all non-numeric chars
627 if (checkForJavascript())
628 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
629 . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
630 . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
631 . 'this.value=newVal;';
633 return $this->createWidget_String();
637 * Creates field for floating number
638 * Difference from createWidget_String is visible only when javascript is enabled
639 * @return string html formated option field
641 function createWidget_Float() {
643 // add onChange javascript handler to a regular string widget
644 // which will strip out all non-numeric (period also OK) chars
645 if (checkForJavascript())
646 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
647 . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
648 . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
649 . 'newVal += origVal.charAt(i); } this.value=newVal;';
651 return $this->createWidget_String();
655 * Create boolean widget
657 * When creating Yes/No radio buttons, the "yes_text"
658 * and "no_text" option attributes are used to override
659 * the typical "Yes" and "No" text.
661 * @param boolean $checkbox When TRUE, the widget will be
662 * constructed as a checkbox,
663 * otherwise it will be a set of
664 * Yes/No radio buttons (OPTIONAL;
665 * default is TRUE (checkbox)).
667 * @return string html formated boolean widget
670 function createWidget_Boolean($checkbox=TRUE) {
672 global $oTemplate, $nbsp;
678 $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
);
685 /* Build the yes choice. */
686 $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');
688 /* Build the no choice. */
689 $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');
691 /* Build the combined "boolean widget". */
692 $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option";
700 * Creates hidden field
701 * @return string html formated hidden input field
703 function createWidget_Hidden() {
704 return addHidden('new_' . $this->name
, $this->value
, $this->aExtraAttribs
);
709 * @return string comment
711 function createWidget_Comment() {
712 $result = $this->comment
;
717 * Creates an edit list
719 * Note that multiple layout types are supported for this widget.
720 * $this->layout_type must be one of the SMOPT_EDIT_LIST_LAYOUT_*
723 * @return string html formated list of edit fields and
724 * their associated controls
726 function createWidget_EditList() {
730 switch ($this->size
) {
731 case SMOPT_SIZE_TINY
:
734 case SMOPT_SIZE_SMALL
:
737 case SMOPT_SIZE_MEDIUM
:
740 case SMOPT_SIZE_LARGE
:
743 case SMOPT_SIZE_HUGE
:
746 case SMOPT_SIZE_NORMAL
:
751 if (empty($this->possible_values
)) $this->possible_values
= array();
752 if (!is_array($this->possible_values
)) $this->possible_values
= array($this->possible_values
);
754 //FIXME: $this->aExtraAttribs probably should only be used in one place
755 $oTemplate->assign('input_widget', addInput('add_' . $this->name
, '', 38, 0, $this->aExtraAttribs
));
756 $oTemplate->assign('use_input_widget', $this->use_add_widget
);
758 $oTemplate->assign('trailing_text', $this->trailing_text
);
759 $oTemplate->assign('possible_values', $this->possible_values
);
760 $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));
761 $oTemplate->assign('checkbox_widget', addCheckBox('delete_' . $this->name
, FALSE, SMPREF_YES
, array_merge(array('id' => 'delete_' . $this->name
), $this->aExtraAttribs
)));
762 $oTemplate->assign('name', $this->name
);
764 switch ($this->layout_type
) {
765 case SMOPT_EDIT_LIST_LAYOUT_SELECT
:
766 return $oTemplate->fetch('edit_list_widget.tpl');
767 case SMOPT_EDIT_LIST_LAYOUT_LIST
:
768 return $oTemplate->fetch('edit_list_widget_list_style.tpl');
770 error_box(sprintf(_("Edit List Layout Type '%s' Not Found"), $layout_type));
776 * Creates a submit button
778 * @return string html formated submit button widget
781 function createWidget_Submit() {
783 return addSubmit($this->comment
, $this->name
, $this->aExtraAttribs
) . htmlspecialchars($this->trailing_text
);
791 $function = $this->save_function
;
800 // edit lists have a lot going on, so we'll always process them
802 if ($this->type
== SMOPT_TYPE_EDIT_LIST
) return TRUE;
804 return ($this->value
!= $this->new_value
);
806 } /* End of SquirrelOption class*/
809 * Saves the option value (this is the default save function
810 * unless overridden by the user)
812 * @param object $option object that holds option name and new_value
814 function save_option($option) {
816 // Can't save the pref if we don't have the username
818 if ( !sqgetGlobalVar('username', $username, SQ_SESSION
) ) {
824 // edit lists: first add new elements to list, then
825 // remove any selected ones (note that we must add
826 // before deleting because the javascript that populates
827 // the "add" textbox when selecting items in the list
830 if ($option->type
== SMOPT_TYPE_EDIT_LIST
) {
832 if (empty($option->possible_values
)) $option->possible_values
= array();
833 if (!is_array($option->possible_values
)) $option->possible_values
= array($option->possible_values
);
835 // add element if given
837 if ((isset($option->use_add_widget
) && $option->use_add_widget
)
838 && sqGetGlobalVar('add_' . $option->name
, $new_element, SQ_POST
)) {
839 $new_element = trim($new_element);
840 if (!empty($new_element)
841 && !in_array($new_element, $option->possible_values
))
842 $option->possible_values
[] = $new_element;
845 // delete selected elements if needed
847 if (is_array($option->new_value
)
848 && sqGetGlobalVar('delete_' . $option->name
, $ignore, SQ_POST
))
849 $option->possible_values
= array_diff($option->possible_values
, $option->new_value
);
851 // save full list (stored in "possible_values")
853 setPref($data_dir, $username, $option->name
, serialize($option->possible_values
));
855 // Certain option types need to be serialized because
856 // they are not scalar
858 } else if ($option->is_multiple_valued())
859 setPref($data_dir, $username, $option->name
, serialize($option->new_value
));
861 // Checkboxes, when unchecked, don't submit anything in
862 // the POST, so set to SMPREF_OFF if not found
864 else if (($option->type
== SMOPT_TYPE_BOOLEAN
865 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
866 && empty($option->new_value
))
867 setPref($data_dir, $username, $option->name
, SMPREF_OFF
);
870 setPref($data_dir, $username, $option->name
, $option->new_value
);
873 // if a checkbox or multi select is zeroed/cleared out, it
874 // needs to have an empty value pushed into its "new_value" slot
876 if (($option->type
== SMOPT_TYPE_STRLIST_MULTI
877 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
878 && is_null($option->new_value
))
879 $option->new_value
= '';
884 * save function that does not save
885 * @param object $option
887 function save_option_noop($option) {
888 /* Do nothing here... */
892 * Create hidden 'optpage' input field with value set by argument
893 * @param string $optpage identification of option page
894 * @return string html formated hidden input field
896 function create_optpage_element($optpage) {
897 return addHidden('optpage', $optpage);
901 * Create hidden 'optmode' input field with value set by argument
902 * @param string $optmode
903 * @return string html formated hidden input field
905 function create_optmode_element($optmode) {
906 return addHidden('optmode', $optmode);
910 * @param array $optgrps
911 * @param array $optvals
914 function create_option_groups($optgrps, $optvals) {
915 /* Build a simple array with which to start. */
918 /* Create option group for each option group name. */
919 foreach ($optgrps as $grpkey => $grpname) {
920 $result[$grpkey] = array();
921 $result[$grpkey]['name'] = $grpname;
922 $result[$grpkey]['options'] = array();
925 /* Create a new SquirrelOption for each set of option values. */
926 foreach ($optvals as $grpkey => $grpopts) {
927 foreach ($grpopts as $optset) {
928 /* Create a new option with all values given. */
929 $next_option = new SquirrelOption(
934 (isset($optset['refresh']) ?
$optset['refresh'] : SMOPT_REFRESH_NONE
),
935 (isset($optset['initial_value']) ?
$optset['initial_value'] : ''),
936 (isset($optset['posvals']) ?
$optset['posvals'] : ''),
937 (isset($optset['htmlencoded']) ?
$optset['htmlencoded'] : false)
940 /* If provided, set the size for this option. */
941 if (isset($optset['size'])) {
942 $next_option->setSize($optset['size']);
945 /* If provided, set the trailing_text for this option. */
946 if (isset($optset['trailing_text'])) {
947 $next_option->setTrailingText($optset['trailing_text']);
950 /* If provided, set the yes_text for this option. */
951 if (isset($optset['yes_text'])) {
952 $next_option->setYesText($optset['yes_text']);
955 /* If provided, set the no_text for this option. */
956 if (isset($optset['no_text'])) {
957 $next_option->setNoText($optset['no_text']);
960 /* If provided, set the layout type for this option. */
961 if (isset($optset['layout_type'])) {
962 $next_option->setLayoutType($optset['layout_type']);
965 /* If provided, set the use_add_widget value for this option. */
966 if (isset($optset['use_add_widget'])) {
967 $next_option->setUseAddWidget($optset['use_add_widget']);
970 /* If provided, set the comment for this option. */
971 if (isset($optset['comment'])) {
972 $next_option->setComment($optset['comment']);
975 /* If provided, set the save function for this option. */
976 if (isset($optset['save'])) {
977 $next_option->setSaveFunction($optset['save']);
980 /* If provided, set the extra attributes for this option. */
981 if (isset($optset['extra_attributes'])) {
982 $next_option->setExtraAttributes($optset['extra_attributes']);
985 /* If provided, set the "post script" for this option. */
986 if (isset($optset['post_script'])) {
987 $next_option->setPostScript($optset['post_script']);
990 /* If provided, set the folder_filter for this option. */
991 if (isset($optset['folder_filter'])) {
992 $next_option->setFolderFilter($optset['folder_filter']);
995 /* Add this option to the option array. */
996 $result[$grpkey]['options'][] = $next_option;
1000 /* Return our resulting array. */