Source for file options.php
Documentation is available at options.php
* Functions needed to display the options pages.
* @copyright © 1999-2006 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: options.php,v 1.66 2006/08/22 18:56:16 stevetruckstuff Exp $
/**********************************************/
/* Define constants used in the options code. */
/**********************************************/
/* Define constants for the various option types. */
define('SMOPT_TYPE_STRING', 0);
define('SMOPT_TYPE_STRLIST', 1);
define('SMOPT_TYPE_TEXTAREA', 2);
define('SMOPT_TYPE_INTEGER', 3);
define('SMOPT_TYPE_FLOAT', 4);
define('SMOPT_TYPE_BOOLEAN', 5);
define('SMOPT_TYPE_HIDDEN', 6);
define('SMOPT_TYPE_COMMENT', 7);
define('SMOPT_TYPE_FLDRLIST', 8);
/* Define constants for the options refresh levels. */
define('SMOPT_REFRESH_NONE', 0);
define('SMOPT_REFRESH_FOLDERLIST', 1);
define('SMOPT_REFRESH_ALL', 2);
/* Define constants for the options size. */
define('SMOPT_SIZE_SMALL', 1);
define('SMOPT_SIZE_MEDIUM', 2);
define('SMOPT_SIZE_LARGE', 3);
define('SMOPT_SIZE_NORMAL', 5);
define('SMOPT_SAVE_DEFAULT', 'save_option');
define('SMOPT_SAVE_NOOP', 'save_option_noop');
* SquirrelOption: An option for SquirrelMail.
* The name of this setting
* The text that prefaces setting on the preferences page
* The type of INPUT element
* See SMOPT_TYPE_* defines
* Indicates if a link should be shown to refresh part
* See SMOPT_REFRESH_* defines
* Specifies the size of certain input items
* See SMOPT_SIZE_* defines
* Text that follows a text input or
* select list input on the preferences page
* useful for indicating units, meanings of special values, etc.
* text displayed to the user
* Used with SMOPT_TYPE_COMMENT options
* additional javascript or other code added to the user input
* script (usually Javascript) that will be placed after (outside of)
* The name of the Save Function for this option.
/* The various 'values' for this options. */
* default/preselected value for this option
* associative array, where each key is an actual input value
* and the corresponding value is what is displayed to the user
* for that list item in the drop-down list
* disables html sanitizing.
* WARNING - don't use it, if user input is possible in option
* or use own sanitizing functions. Currently works only with
* Controls folder list limits in SMOPT_TYPE_FLDRLIST widget.
* See $flag argument in sqimap_mailbox_option_list() function.
* @param integer $refresh_level
* @param mixed $initial_value
* @param array $possible_values
* @param bool $htmlencoded
($name, $caption, $type, $refresh_level, $initial_value =
'', $possible_values =
'', $htmlencoded =
false) {
/* Set the basic stuff. */
//Check for a current value.
if (isset
($GLOBALS[$name])) {
$this->value =
$GLOBALS[$name];
} else if (!empty($initial_value)) {
$this->value =
$initial_value;
/* Check for a new value. */
/* Set the default save function. */
* Set the value for this option.
* Set the new value for this option.
* @param mixed $new_value
* Set the size for this option.
* Set the trailing_text for this option.
* @param string $trailing_text
* Set the comment for this option.
* Set the script for this option.
* Set the "post script" for this option.
* @param string $post_script
* Set the save function for this option.
* @param string $save_function
* Set the trailing_text for this option.
* @param string $folder_filter
* Creates fields on option pages according to option type
* Function that calls other createWidget* functions.
* @return string html formated option field
// Use new value if available
$tempValue =
$this->value;
/* Get the widget for this option type. */
$result =
'<font color="' .
$color[2] .
'">'
/* Add the "post script" for this option. */
// put correct value back if need be
$this->value =
$tempValue;
/* Now, return the created widget. */
* @return string html formated option field
$result =
"<input type=\"text\" name=\"new_$this->name\" value=\"" .
* @return string html formated selection box
/* Begin the select tag. */
$result =
"<select name=\"new_$this->name\" $this->script>\n";
/* Add each possible value to the select list. */
/* Start the next new option string. */
$new_option =
'<option value="' .
/* If this value is the current value, select it. */
if ($real_value ==
$this->value) {
$new_option .=
' selected="selected"';
/* Add the display value to our option string. */
/* And add the new option string to our select tag. */
/* Close the select tag and return our happy result. */
* Create folder selection box
* @return string html formated selection box
/* Add each possible value to the select list. */
/* For folder list, we passed in the array of boxes.. */
/* Start the next new option string. */
/* If this value is the current value, select it. */
if ($real_value ==
$this->value) {
$new_option .=
' selected="selected"';
/* Add the display value to our option string. */
/* And add the new option string to our select tag. */
// string is displayed when interface can't build folder selection box
/* Begin the select tag. */
$ret =
"<select name=\"new_$this->name\" $this->script>\n";
/* Close the select tag and return our happy result. */
* @return string html formated textarea field
default:
$rows =
5; $cols =
50;
$result =
"<textarea name=\"new_$this->name\" rows=\"$rows\" "
.
"cols=\"$cols\" $this->script>"
* Creates field for integer
* Difference from createWidget_String is visible only when javascript is enabled
* @return string html formated option field
// add onChange javascript handler to a regular string widget
// which will strip out all non-numeric chars
return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; '
.
'for (i=0;i<origVal.length;i++) { if (origVal.charAt(i)>=\'0\' '
.
'&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } '
* Creates field for floating number
* Difference from createWidget_String is visible only when javascript is enabled
* @return string html formated option field
// add onChange javascript handler to a regular string widget
// which will strip out all non-numeric (period also OK) chars
return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; '
.
'for (i=0;i<origVal.length;i++) { if ((origVal.charAt(i)>=\'0\' '
.
'&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') '
.
'newVal += origVal.charAt(i); } this.value=newVal;" />'
* Creates radio field (yes/no)
* @return string html formated radio field
/* Do the whole current value thing. */
$yes_chk =
' checked="checked"';
$no_chk =
' checked="checked"';
/* Build the yes choice. */
$yes_option =
'<input type="radio" id="new_' .
$this->name .
'_yes" '
.
$yes_chk .
' ' .
$this->script .
' /> '
.
'<label for="new_'.
$this->name.
'_yes">' .
_("Yes") .
'</label>';
/* Build the no choice. */
$no_option =
'<input type="radio" id="new_' .
$this->name .
'_no" '
.
$no_chk .
' ' .
$this->script .
' /> '
.
'<label for="new_'.
$this->name.
'_no">' .
_("No") .
'</label>';
/* Build and return the combined "boolean widget". */
$result =
"$yes_option $no_option";
* @return string html formated hidden input field
$result =
'<input type="hidden" name="new_' .
$this->name
.
'" ' .
$this->script .
' />';
} /* End of SquirrelOption class*/
* @param object $option object that holds option name and new_value
/* Can't save the pref if we don't have the username */
* save function that does not save
* Create hidden 'optpage' input field with value set by argument
* @param string $optpage identification of option page
* @return string html formated hidden input field
* Create hidden 'optmode' input field with value set by argument
* @return string html formated hidden input field
* @param string $name field name
* @param string $value field value
* @return string html formated hidden input field
$result =
'<input type="hidden" '
.
'name="' .
$name .
'" '
/* Build a simple array with which to start. */
/* Create option group for each option group name. */
foreach ($optgrps as $grpkey =>
$grpname) {
$result[$grpkey] =
array();
$result[$grpkey]['name'] =
$grpname;
$result[$grpkey]['options'] =
array();
/* Create a new SquirrelOption for each set of option values. */
foreach ($optvals as $grpkey =>
$grpopts) {
foreach ($grpopts as $optset) {
/* Create a new option with all values given. */
(isset
($optset['initial_value']) ?
$optset['initial_value'] :
''),
(isset
($optset['posvals']) ?
$optset['posvals'] :
''),
(isset
($optset['htmlencoded']) ?
$optset['htmlencoded'] :
false)
/* If provided, set the size for this option. */
if (isset
($optset['size'])) {
$next_option->setSize($optset['size']);
/* If provided, set the trailing_text for this option. */
if (isset
($optset['trailing_text'])) {
/* If provided, set the comment for this option. */
if (isset
($optset['comment'])) {
/* If provided, set the save function for this option. */
if (isset
($optset['save'])) {
/* If provided, set the script for this option. */
if (isset
($optset['script'])) {
/* If provided, set the "post script" for this option. */
if (isset
($optset['post_script'])) {
/* If provided, set the folder_filter for this option. */
if (isset
($optset['folder_filter'])) {
/* Add this option to the option array. */
$result[$grpkey]['options'][] =
$next_option;
/* Return our resulting array. */
* @param array $option_groups
/* Print each option group. */
foreach ($option_groups as $next_optgrp) {
/* If it is not blank, print the name for this option group. */
if ($next_optgrp['name'] !=
'') {
'<b>' .
$next_optgrp['name'] .
'</b>' ,
'center' ,'', 'valign="middle" colspan="2" style="white-space: nowrap;"' )
/* Print each option in this option group. */
foreach ($next_optgrp['options'] as $option) {
/* Print an empty row after this option group. */
html_tag( 'td', ' ', 'left', '', 'colspan="2"' )
* Create submit button inside table row.
html_tag( 'td', '<input type="submit" value="' .
_("Submit") .
'" name="' .
$name .
'" /> ', 'right', '', 'colspan="2"' )
Documentation generated on Sat, 07 Oct 2006 16:12:52 +0300 by phpDocumentor 1.3.0RC6