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 * Indicates if the Delete widget should be included
142 var $use_delete_widget;
144 * text displayed to the user
146 * Used with SMOPT_TYPE_COMMENT options
151 * additional javascript or other widget attributes added to the
152 * user input; must be an array where keys are attribute names
153 * ("onclick", etc) and values are the attribute values.
158 * script (usually Javascript) that will be placed after (outside of)
165 * The name of the Save Function for this option.
170 /* The various 'values' for this options. */
172 * default/preselected value for this option
182 * associative array, where each key is an actual input value
183 * and the corresponding value is what is displayed to the user
184 * for that list item in the drop-down list
187 var $possible_values;
189 * disables html sanitizing.
191 * WARNING - don't use it, if user input is possible in option
192 * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST.
195 var $htmlencoded=false;
197 * Controls folder list limits in SMOPT_TYPE_FLDRLIST and
198 * SMOPT_TYPE_FLDRLIST_MULTI widgets.
199 * See $flag argument in sqimap_mailbox_option_list() function.
203 var $folder_filter='noselect';
206 * Constructor function
207 * @param array $raw_option_array
208 * @param string $name
209 * @param string $caption
210 * @param integer $type
211 * @param integer $refresh_level
212 * @param mixed $initial_value
213 * @param array $possible_values
214 * @param bool $htmlencoded
216 function SquirrelOption
217 ($raw_option_array, $name, $caption, $type, $refresh_level, $initial_value = '', $possible_values = '', $htmlencoded = false) {
218 /* Set the basic stuff. */
219 $this->raw_option_array
= $raw_option_array;
221 $this->caption
= $caption;
223 $this->refresh_level
= $refresh_level;
224 $this->possible_values
= $possible_values;
225 $this->htmlencoded
= $htmlencoded;
226 $this->size
= SMOPT_SIZE_NORMAL
;
227 $this->trailing_text
= '';
228 $this->yes_text
= '';
231 $this->layout_type
= 0;
232 $this->use_add_widget
= TRUE;
233 $this->use_delete_widget
= TRUE;
234 $this->aExtraAttribs
= array();
235 $this->post_script
= '';
237 //Check for a current value.
238 if (isset($GLOBALS[$name])) {
239 $this->value
= $GLOBALS[$name];
240 } else if (!empty($initial_value)) {
241 $this->value
= $initial_value;
246 /* Check for a new value. */
247 if ( !sqgetGlobalVar("new_$name", $this->new_value
, SQ_POST
) ) {
248 $this->new_value
= NULL;
251 /* Set the default save function. */
252 if (($type != SMOPT_TYPE_HIDDEN
) && ($type != SMOPT_TYPE_COMMENT
)) {
253 $this->save_function
= SMOPT_SAVE_DEFAULT
;
255 $this->save_function
= SMOPT_SAVE_NOOP
;
259 /** Convenience function that identifies which types of
260 widgets are stored as (serialized) array values. */
261 function is_multiple_valued() {
262 return ($this->type
== SMOPT_TYPE_FLDRLIST_MULTI
263 ||
$this->type
== SMOPT_TYPE_STRLIST_MULTI
264 ||
$this->type
== SMOPT_TYPE_EDIT_LIST
);
268 * Set the value for this option.
269 * @param mixed $value
271 function setValue($value) {
272 $this->value
= $value;
276 * Set the new value for this option.
277 * @param mixed $new_value
279 function setNewValue($new_value) {
280 $this->new_value
= $new_value;
284 * Set the size for this option.
285 * @param integer $size
287 function setSize($size) {
292 * Set the trailing_text for this option.
293 * @param string $trailing_text
295 function setTrailingText($trailing_text) {
296 $this->trailing_text
= $trailing_text;
300 * Set the yes_text for this option.
301 * @param string $yes_text
303 function setYesText($yes_text) {
304 $this->yes_text
= $yes_text;
308 * Set the no_text for this option.
309 * @param string $no_text
311 function setNoText($no_text) {
312 $this->no_text
= $no_text;
315 /* Set the "use add widget" value for this option. */
316 function setUseAddWidget($use_add_widget) {
317 $this->use_add_widget
= $use_add_widget;
320 /* Set the "use delete widget" value for this option. */
321 function setUseDeleteWidget($use_delete_widget) {
322 $this->use_delete_widget
= $use_delete_widget;
326 * Set the layout type for this option.
327 * @param int $layout_type
329 function setLayoutType($layout_type) {
330 $this->layout_type
= $layout_type;
334 * Set the comment for this option.
335 * @param string $comment
337 function setComment($comment) {
338 $this->comment
= $comment;
342 * Set the extra attributes for this option.
343 * @param array $aExtraAttribs
345 function setExtraAttributes($aExtraAttribs) {
346 $this->aExtraAttribs
= $aExtraAttribs;
350 * Set the "post script" for this option.
351 * @param string $post_script
353 function setPostScript($post_script) {
354 $this->post_script
= $post_script;
358 * Set the save function for this option.
359 * @param string $save_function
361 function setSaveFunction($save_function) {
362 $this->save_function
= $save_function;
366 * Set the folder_filter for this option.
367 * @param string $folder_filter
370 function setFolderFilter($folder_filter) {
371 $this->folder_filter
= $folder_filter;
375 * Creates fields on option pages according to option type
377 * This is the function that calls all other createWidget* functions.
379 * @return string The formated option field
382 function createWidget() {
385 // Use new value if available
386 if (!is_null($this->new_value
)) {
387 $tempValue = $this->value
;
388 $this->value
= $this->new_value
;
391 /* Get the widget for this option type. */
392 switch ($this->type
) {
393 case SMOPT_TYPE_STRING
:
394 $result = $this->createWidget_String();
396 case SMOPT_TYPE_STRLIST
:
397 $result = $this->createWidget_StrList();
399 case SMOPT_TYPE_TEXTAREA
:
400 $result = $this->createWidget_TextArea();
402 case SMOPT_TYPE_INTEGER
:
403 $result = $this->createWidget_Integer();
405 case SMOPT_TYPE_FLOAT
:
406 $result = $this->createWidget_Float();
408 case SMOPT_TYPE_BOOLEAN
:
409 $result = $this->createWidget_Boolean();
411 case SMOPT_TYPE_BOOLEAN_CHECKBOX
:
412 $result = $this->createWidget_Boolean(TRUE);
414 case SMOPT_TYPE_BOOLEAN_RADIO
:
415 $result = $this->createWidget_Boolean(FALSE);
417 case SMOPT_TYPE_HIDDEN
:
418 $result = $this->createWidget_Hidden();
420 case SMOPT_TYPE_COMMENT
:
421 $result = $this->createWidget_Comment();
423 case SMOPT_TYPE_FLDRLIST
:
424 $result = $this->createWidget_FolderList();
426 case SMOPT_TYPE_FLDRLIST_MULTI
:
427 $result = $this->createWidget_FolderList(TRUE);
429 case SMOPT_TYPE_EDIT_LIST
:
430 $result = $this->createWidget_EditList();
432 case SMOPT_TYPE_STRLIST_MULTI
:
433 $result = $this->createWidget_StrList(TRUE);
435 case SMOPT_TYPE_STRLIST_RADIO
:
436 $result = $this->createWidget_StrList(FALSE, TRUE);
438 case SMOPT_TYPE_SUBMIT
:
439 $result = $this->createWidget_Submit();
443 sprintf(_("Option Type '%s' Not Found"), $this->type
)
447 /* Add the "post script" for this option. */
448 $result .= $this->post_script
;
450 // put correct value back if need be
451 if (!is_null($this->new_value
)) {
452 $this->value
= $tempValue;
455 /* Now, return the created widget. */
460 * Create string field
461 * @return string html formated option field
463 function createWidget_String() {
464 switch ($this->size
) {
465 case SMOPT_SIZE_TINY
:
468 case SMOPT_SIZE_SMALL
:
471 case SMOPT_SIZE_LARGE
:
474 case SMOPT_SIZE_HUGE
:
477 case SMOPT_SIZE_NORMAL
:
482 return addInput('new_' . $this->name
, $this->value
, $width, 0, $this->aExtraAttribs
) . htmlspecialchars($this->trailing_text
);
486 * Create selection box or radio button group
488 * When $this->htmlencoded is TRUE, the keys and values in
489 * $this->possible_values are assumed to be display-safe.
492 * Note that when building radio buttons instead of a select
493 * widget, if the "size" attribute is SMOPT_SIZE_TINY, the
494 * radio buttons will be output one after another without
495 * linebreaks between them. Otherwise, each radio button
496 * goes on a line of its own.
498 * @param boolean $multiple_select When TRUE, the select widget
499 * will allow multiple selections
500 * (OPTIONAL; default is FALSE
501 * (single select list))
502 * @param boolean $radio_buttons When TRUE, the widget will
503 * instead be built as a group
504 * of radio buttons (and
505 * $multiple_select will be
506 * forced to FALSE) (OPTIONAL;
507 * default is FALSE (select widget))
509 * @return string html formated selection box or radio buttons
512 function createWidget_StrList($multiple_select=FALSE, $radio_buttons=FALSE) {
513 //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
515 // radio buttons instead of select widget?
517 if ($radio_buttons) {
521 foreach ($this->possible_values
as $real_value => $disp_value) {
522 $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);
523 if ($this->size
!= SMOPT_SIZE_TINY
)
531 // everything below applies to select widgets
533 switch ($this->size
) {
534 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
535 case SMOPT_SIZE_TINY
:
538 case SMOPT_SIZE_SMALL
:
541 case SMOPT_SIZE_LARGE
:
544 case SMOPT_SIZE_HUGE
:
547 case SMOPT_SIZE_NORMAL
:
552 return addSelect('new_' . $this->name
, $this->possible_values
, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height, !$this->htmlencoded
) . htmlspecialchars($this->trailing_text
);
557 * Create folder selection box
559 * @param boolean $multiple_select When TRUE, the select widget
560 * will allow multiple selections
561 * (OPTIONAL; default is FALSE
562 * (single select list))
564 * @return string html formated selection box
567 function createWidget_FolderList($multiple_select=FALSE) {
569 switch ($this->size
) {
570 //FIXME: not sure about these sizes... seems like we could add another on the "large" side...
571 case SMOPT_SIZE_TINY
:
574 case SMOPT_SIZE_SMALL
:
577 case SMOPT_SIZE_LARGE
:
580 case SMOPT_SIZE_HUGE
:
583 case SMOPT_SIZE_NORMAL
:
588 // possible values might include a nested array of
589 // possible values (list of folders)
591 $option_list = array();
592 foreach ($this->possible_values
as $value => $text) {
594 // list of folders (boxes array)
596 if (is_array($text)) {
597 $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter
));
599 // just one option here
602 $option_list = array_merge($option_list, array($value => $text));
606 if (empty($option_list))
607 $option_list = array('ignore' => _("unavailable"));
610 return addSelect('new_' . $this->name
, $option_list, $this->value
, TRUE, $this->aExtraAttribs
, $multiple_select, $height) . htmlspecialchars($this->trailing_text
);
616 * @return string html formated textarea field
618 function createWidget_TextArea() {
619 switch ($this->size
) {
620 case SMOPT_SIZE_TINY
: $rows = 3; $cols = 10; break;
621 case SMOPT_SIZE_SMALL
: $rows = 4; $cols = 30; break;
622 case SMOPT_SIZE_LARGE
: $rows = 10; $cols = 60; break;
623 case SMOPT_SIZE_HUGE
: $rows = 20; $cols = 80; break;
624 case SMOPT_SIZE_NORMAL
:
625 default: $rows = 5; $cols = 50;
627 return addTextArea('new_' . $this->name
, $this->value
, $cols, $rows, $this->aExtraAttribs
);
631 * Creates field for integer
633 * Difference from createWidget_String is visible only when javascript is enabled
634 * @return string html formated option field
636 function createWidget_Integer() {
638 // add onChange javascript handler to a regular string widget
639 // which will strip out all non-numeric chars
640 if (checkForJavascript())
641 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
642 . 'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
643 . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
644 . 'this.value=newVal;';
646 return $this->createWidget_String();
650 * Creates field for floating number
651 * Difference from createWidget_String is visible only when javascript is enabled
652 * @return string html formated option field
654 function createWidget_Float() {
656 // add onChange javascript handler to a regular string widget
657 // which will strip out all non-numeric (period also OK) chars
658 if (checkForJavascript())
659 $this->aExtraAttribs
['onchange'] = 'origVal=this.value; newVal=\'\'; '
660 . 'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
661 . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
662 . 'newVal += origVal.charAt(i); } this.value=newVal;';
664 return $this->createWidget_String();
668 * Create boolean widget
670 * When creating Yes/No radio buttons, the "yes_text"
671 * and "no_text" option attributes are used to override
672 * the typical "Yes" and "No" text.
674 * @param boolean $checkbox When TRUE, the widget will be
675 * constructed as a checkbox,
676 * otherwise it will be a set of
677 * Yes/No radio buttons (OPTIONAL;
678 * default is TRUE (checkbox)).
680 * @return string html formated boolean widget
683 function createWidget_Boolean($checkbox=TRUE) {
685 global $oTemplate, $nbsp;
691 $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
);
698 /* Build the yes choice. */
699 $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');
701 /* Build the no choice. */
702 $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');
704 /* Build the combined "boolean widget". */
705 $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option";
713 * Creates hidden field
714 * @return string html formated hidden input field
716 function createWidget_Hidden() {
717 return addHidden('new_' . $this->name
, $this->value
, $this->aExtraAttribs
);
722 * @return string comment
724 function createWidget_Comment() {
725 $result = $this->comment
;
730 * Creates an edit list
732 * Note that multiple layout types are supported for this widget.
733 * $this->layout_type must be one of the SMOPT_EDIT_LIST_LAYOUT_*
736 * @return string html formated list of edit fields and
737 * their associated controls
739 function createWidget_EditList() {
743 switch ($this->size
) {
744 case SMOPT_SIZE_TINY
:
747 case SMOPT_SIZE_SMALL
:
750 case SMOPT_SIZE_MEDIUM
:
753 case SMOPT_SIZE_LARGE
:
756 case SMOPT_SIZE_HUGE
:
759 case SMOPT_SIZE_NORMAL
:
764 if (empty($this->possible_values
)) $this->possible_values
= array();
765 if (!is_array($this->possible_values
)) $this->possible_values
= array($this->possible_values
);
767 //FIXME: $this->aExtraAttribs probably should only be used in one place
768 $oTemplate->assign('input_widget', addInput('add_' . $this->name
, '', 38, 0, $this->aExtraAttribs
));
769 $oTemplate->assign('use_input_widget', $this->use_add_widget
);
770 $oTemplate->assign('use_delete_widget', $this->use_delete_widget
);
772 $oTemplate->assign('trailing_text', $this->trailing_text
);
773 $oTemplate->assign('possible_values', $this->possible_values
);
774 $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));
775 $oTemplate->assign('checkbox_widget', addCheckBox('delete_' . $this->name
, FALSE, SMPREF_YES
, array_merge(array('id' => 'delete_' . $this->name
), $this->aExtraAttribs
)));
776 $oTemplate->assign('name', $this->name
);
778 switch ($this->layout_type
) {
779 case SMOPT_EDIT_LIST_LAYOUT_SELECT
:
780 return $oTemplate->fetch('edit_list_widget.tpl');
781 case SMOPT_EDIT_LIST_LAYOUT_LIST
:
782 return $oTemplate->fetch('edit_list_widget_list_style.tpl');
784 error_box(sprintf(_("Edit List Layout Type '%s' Not Found"), $layout_type));
790 * Creates a submit button
792 * @return string html formated submit button widget
795 function createWidget_Submit() {
797 return addSubmit($this->comment
, $this->name
, $this->aExtraAttribs
) . htmlspecialchars($this->trailing_text
);
805 $function = $this->save_function
;
814 // edit lists have a lot going on, so we'll always process them
816 if ($this->type
== SMOPT_TYPE_EDIT_LIST
) return TRUE;
818 return ($this->value
!= $this->new_value
);
820 } /* End of SquirrelOption class*/
823 * Saves the option value (this is the default save function
824 * unless overridden by the user)
826 * @param object $option object that holds option name and new_value
828 function save_option($option) {
830 // Can't save the pref if we don't have the username
832 if ( !sqgetGlobalVar('username', $username, SQ_SESSION
) ) {
838 // edit lists: first add new elements to list, then
839 // remove any selected ones (note that we must add
840 // before deleting because the javascript that populates
841 // the "add" textbox when selecting items in the list
844 if ($option->type
== SMOPT_TYPE_EDIT_LIST
) {
846 if (empty($option->possible_values
)) $option->possible_values
= array();
847 if (!is_array($option->possible_values
)) $option->possible_values
= array($option->possible_values
);
849 // add element if given
851 if ((isset($option->use_add_widget
) && $option->use_add_widget
)
852 && sqGetGlobalVar('add_' . $option->name
, $new_element, SQ_POST
)) {
853 $new_element = trim($new_element);
854 if (!empty($new_element)
855 && !in_array($new_element, $option->possible_values
))
856 $option->possible_values
[] = $new_element;
859 // delete selected elements if needed
861 if ((isset($option->use_delete_widget
) && $option->use_delete_widget
)
862 && is_array($option->new_value
)
863 && sqGetGlobalVar('delete_' . $option->name
, $ignore, SQ_POST
))
864 $option->possible_values
= array_diff($option->possible_values
, $option->new_value
);
866 // save full list (stored in "possible_values")
868 setPref($data_dir, $username, $option->name
, serialize($option->possible_values
));
870 // Certain option types need to be serialized because
871 // they are not scalar
873 } else if ($option->is_multiple_valued())
874 setPref($data_dir, $username, $option->name
, serialize($option->new_value
));
876 // Checkboxes, when unchecked, don't submit anything in
877 // the POST, so set to SMPREF_OFF if not found
879 else if (($option->type
== SMOPT_TYPE_BOOLEAN
880 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
881 && empty($option->new_value
))
882 setPref($data_dir, $username, $option->name
, SMPREF_OFF
);
885 setPref($data_dir, $username, $option->name
, $option->new_value
);
888 // if a checkbox or multi select is zeroed/cleared out, it
889 // needs to have an empty value pushed into its "new_value" slot
891 if (($option->type
== SMOPT_TYPE_STRLIST_MULTI
892 ||
$option->type
== SMOPT_TYPE_BOOLEAN_CHECKBOX
)
893 && is_null($option->new_value
))
894 $option->new_value
= '';
899 * save function that does not save
900 * @param object $option
902 function save_option_noop($option) {
903 /* Do nothing here... */
907 * Create hidden 'optpage' input field with value set by argument
908 * @param string $optpage identification of option page
909 * @return string html formated hidden input field
911 function create_optpage_element($optpage) {
912 return addHidden('optpage', $optpage);
916 * Create hidden 'optmode' input field with value set by argument
917 * @param string $optmode
918 * @return string html formated hidden input field
920 function create_optmode_element($optmode) {
921 return addHidden('optmode', $optmode);
925 * @param array $optgrps
926 * @param array $optvals
929 function create_option_groups($optgrps, $optvals) {
930 /* Build a simple array with which to start. */
933 /* Create option group for each option group name. */
934 foreach ($optgrps as $grpkey => $grpname) {
935 $result[$grpkey] = array();
936 $result[$grpkey]['name'] = $grpname;
937 $result[$grpkey]['options'] = array();
940 /* Create a new SquirrelOption for each set of option values. */
941 foreach ($optvals as $grpkey => $grpopts) {
942 foreach ($grpopts as $optset) {
943 /* Create a new option with all values given. */
944 $next_option = new SquirrelOption(
949 (isset($optset['refresh']) ?
$optset['refresh'] : SMOPT_REFRESH_NONE
),
950 (isset($optset['initial_value']) ?
$optset['initial_value'] : ''),
951 (isset($optset['posvals']) ?
$optset['posvals'] : ''),
952 (isset($optset['htmlencoded']) ?
$optset['htmlencoded'] : false)
955 /* If provided, set the size for this option. */
956 if (isset($optset['size'])) {
957 $next_option->setSize($optset['size']);
960 /* If provided, set the trailing_text for this option. */
961 if (isset($optset['trailing_text'])) {
962 $next_option->setTrailingText($optset['trailing_text']);
965 /* If provided, set the yes_text for this option. */
966 if (isset($optset['yes_text'])) {
967 $next_option->setYesText($optset['yes_text']);
970 /* If provided, set the no_text for this option. */
971 if (isset($optset['no_text'])) {
972 $next_option->setNoText($optset['no_text']);
975 /* If provided, set the layout type for this option. */
976 if (isset($optset['layout_type'])) {
977 $next_option->setLayoutType($optset['layout_type']);
980 /* If provided, set the use_add_widget value for this option. */
981 if (isset($optset['use_add_widget'])) {
982 $next_option->setUseAddWidget($optset['use_add_widget']);
985 /* If provided, set the use_delete_widget value for this option. */
986 if (isset($optset['use_delete_widget'])) {
987 $next_option->setUseDeleteWidget($optset['use_delete_widget']);
990 /* If provided, set the comment for this option. */
991 if (isset($optset['comment'])) {
992 $next_option->setComment($optset['comment']);
995 /* If provided, set the save function for this option. */
996 if (isset($optset['save'])) {
997 $next_option->setSaveFunction($optset['save']);
1000 /* If provided, set the extra attributes for this option. */
1001 if (isset($optset['extra_attributes'])) {
1002 $next_option->setExtraAttributes($optset['extra_attributes']);
1005 /* If provided, set the "post script" for this option. */
1006 if (isset($optset['post_script'])) {
1007 $next_option->setPostScript($optset['post_script']);
1010 /* If provided, set the folder_filter for this option. */
1011 if (isset($optset['folder_filter'])) {
1012 $next_option->setFolderFilter($optset['folder_filter']);
1015 /* Add this option to the option array. */
1016 $result[$grpkey]['options'][] = $next_option;
1020 /* Return our resulting array. */