X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Foptions.php;h=6647bd6832bfc37ef482affecac3acdc1713f0b6;hp=a8236919370cd4a2290b9c126cf8b4919fb312a0;hb=f2aba53660aa16ce179fe6a25b1d32d336791d45;hpb=f2e129237014bc6a796cee2085aaeb62b778d04b diff --git a/functions/options.php b/functions/options.php index a8236919..6647bd68 100644 --- a/functions/options.php +++ b/functions/options.php @@ -5,7 +5,7 @@ * * Functions needed to display the options pages. * - * @copyright © 1999-2006 The SquirrelMail Project Team + * @copyright © 1999-2007 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -26,6 +26,7 @@ define('SMOPT_TYPE_BOOLEAN', 5); define('SMOPT_TYPE_HIDDEN', 6); define('SMOPT_TYPE_COMMENT', 7); define('SMOPT_TYPE_FLDRLIST', 8); +define('SMOPT_TYPE_FLDRLIST_MULTI', 9); /* Define constants for the options refresh levels. */ define('SMOPT_REFRESH_NONE', 0); @@ -98,10 +99,12 @@ class SquirrelOption { */ var $comment; /** - * additional javascript or other code added to the user input - * @var string + * additional javascript or other widget attributes added to the + * user input; must be an array where keys are attribute names + * ("onclick", etc) and values are the attribute values. + * @var array */ - var $script; + var $aExtraAttribs; /** * script (usually Javascript) that will be placed after (outside of) * the INPUT tag @@ -137,13 +140,13 @@ class SquirrelOption { * disables html sanitizing. * * WARNING - don't use it, if user input is possible in option - * or use own sanitizing functions. Currently works only with - * SMOPT_TYPE_STRLIST. + * or use own sanitizing functions. Currently only works for SMOPT_TYPE_STRLIST. * @var bool */ var $htmlencoded=false; /** - * Controls folder list limits in SMOPT_TYPE_FLDRLIST widget. + * Controls folder list limits in SMOPT_TYPE_FLDRLIST and + * SMOPT_TYPE_FLDRLIST_MULTI widgets. * See $flag argument in sqimap_mailbox_option_list() function. * @var string * @since 1.5.1 @@ -172,23 +175,11 @@ class SquirrelOption { $this->size = SMOPT_SIZE_MEDIUM; $this->trailing_text = ''; $this->comment = ''; - $this->script = ''; + $this->aExtraAttribs = array(); $this->post_script = ''; - /** - * Check for a current value. If the $GLOBALS[] value exists, we also - * need to make sure it is the same data type as the initial value to - * make sure we are looking at the correct preference. - */ - $var_type = NULL; - if (!empty($initial_value)) { - $var_type = gettype($initial_value); - } elseif (is_array($possible_values)) { - list($index, $x) = each ($possible_values); - $var_type = gettype($index); - } - - if (isset($GLOBALS[$name]) && (is_null($var_type) ? true : $var_type == gettype($GLOBALS[$name]))) { + //Check for a current value. + if (isset($GLOBALS[$name])) { $this->value = $GLOBALS[$name]; } else if (!empty($initial_value)) { $this->value = $initial_value; @@ -250,11 +241,11 @@ class SquirrelOption { } /** - * Set the script for this option. - * @param string $script + * Set the extra attributes for this option. + * @param array $aExtraAttribs */ - function setScript($script) { - $this->script = $script; + function setExtraAttributes($aExtraAttribs) { + $this->aExtraAttribs = $aExtraAttribs; } /** @@ -326,10 +317,13 @@ class SquirrelOption { case SMOPT_TYPE_FLDRLIST: $result = $this->createWidget_FolderList(); break; + case SMOPT_TYPE_FLDRLIST_MULTI: + $result = $this->createWidget_FolderList(TRUE); + break; default: - $result = '' - . sprintf(_("Option Type '%s' Not Found"), $this->type) - . ''; + error_box ( + sprintf(_("Option Type '%s' Not Found"), $this->type) + ); } /* Add the "post script" for this option. */ @@ -367,86 +361,62 @@ class SquirrelOption { $width = 25; } - $result = "name\" value=\"" . - htmlspecialchars($this->value) . - "\" size=\"$width\" $this->script />$this->trailing_text\n"; - return ($result); + return addInput('new_' . $this->name, $this->value, $width, 0, $this->aExtraAttribs) . htmlspecialchars($this->trailing_text); } /** * Create selection box + * + * When $this->htmlencoded is TRUE, the keys and values in + * $this->possible_values are assumed to be display-safe. + * Use with care! + * * @return string html formated selection box */ function createWidget_StrList() { - /* Begin the select tag. */ - $result = "$this->trailing_text\n"; - return ($result); } /** * Create folder selection box + * + * @param boolean $multiple_select When TRUE, the select widget + * will allow multiple selections + * (OPTIONAL; default is FALSE + * (single select list)) + * * @return string html formated selection box + * */ - function createWidget_FolderList() { - $selected = array(strtolower($this->value)); + function createWidget_FolderList($multiple_select=FALSE) { - /* set initial value */ - $result = ''; - - /* Add each possible value to the select list. */ - foreach ($this->possible_values as $real_value => $disp_value) { - if ( is_array($disp_value) ) { - /* For folder list, we passed in the array of boxes.. */ - $new_option = sqimap_mailbox_option_list(0, $selected, 0, $disp_value, $this->folder_filter); - } else { - /* Start the next new option string. */ - $new_option = '\n"; + // just one option here + // + } else { + $option_list = array_merge($option_list, array($value => $text)); } - /* And add the new option string to our select tag. */ - $result .= $new_option; + } + if (empty($option_list)) + $option_list = array('ignore' => _("unavailable")); - if (empty($result)) { - // string is displayed when interface can't build folder selection box - return _("unavailable"); - } else { - /* Begin the select tag. */ - $ret = "\n"; - return ($ret); - } + // OK to use sq_htmlspecialchars() below because addSelect() already does + return addSelect('new_' . $this->name, $option_list, $this->value, TRUE, $this->aExtraAttribs, $multiple_select) . sq_htmlspecialchars($this->trailing_text); + } /** @@ -462,10 +432,7 @@ class SquirrelOption { case SMOPT_SIZE_NORMAL: default: $rows = 5; $cols = 50; } - $result = "\n"; - return ($result); + return addTextArea('new_' . $this->name, $this->value, $cols, $rows, $this->aExtraAttribs); } /** @@ -475,17 +442,16 @@ class SquirrelOption { * @return string html formated option field */ function createWidget_Integer() { - global $javascript_on; // add onChange javascript handler to a regular string widget // which will strip out all non-numeric chars - if ($javascript_on) - return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; ' + if (checkForJavascript()) + $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; ' . 'for (i=0;i=\'0\' ' . '&& origVal.charAt(i)<=\'9\') newVal += origVal.charAt(i); } ' - . 'this.value=newVal;" />', $this->createWidget_String()); - else - return $this->createWidget_String(); + . 'this.value=newVal;'; + + return $this->createWidget_String(); } /** @@ -494,18 +460,16 @@ class SquirrelOption { * @return string html formated option field */ function createWidget_Float() { - global $javascript_on; // add onChange javascript handler to a regular string widget // which will strip out all non-numeric (period also OK) chars - if ($javascript_on) - return preg_replace('/\/>/', ' onChange="origVal=this.value; newVal=\'\'; ' + if (checkForJavascript()) + $this->aExtraAttribs['onchange'] = 'origVal=this.value; newVal=\'\'; ' . 'for (i=0;i=\'0\' ' . '&& origVal.charAt(i)<=\'9\') || origVal.charAt(i)==\'.\') ' - . 'newVal += origVal.charAt(i); } this.value=newVal;" />' - , $this->createWidget_String()); - else - return $this->createWidget_String(); + . 'newVal += origVal.charAt(i); } this.value=newVal;'; + + return $this->createWidget_String(); } /** @@ -513,29 +477,18 @@ class SquirrelOption { * @return string html formated radio field */ function createWidget_Boolean() { - /* Do the whole current value thing. */ - if ($this->value != SMPREF_NO) { - $yes_chk = ' checked="checked"'; - $no_chk = ''; - } else { - $yes_chk = ''; - $no_chk = ' checked="checked"'; - } + + global $oTemplate; + $nbsp = $oTemplate->fetch('non_breaking_space.tpl'); /* Build the yes choice. */ - $yes_option = 'script . ' /> ' - . ''; + $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'); /* Build the no choice. */ - $no_option = 'script . ' /> ' - . ''; + $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'); /* Build and return the combined "boolean widget". */ - $result = "$yes_option    $no_option"; + $result = "$yes_option$nbsp$nbsp$nbsp$nbsp$no_option"; return ($result); } @@ -544,10 +497,7 @@ class SquirrelOption { * @return string html formated hidden input field */ function createWidget_Hidden() { - $result = 'script . ' />'; - return ($result); + return addHidden('new_' . $this->name, $this->value, $this->aExtraAttribs); } /** @@ -576,16 +526,29 @@ class SquirrelOption { } /* End of SquirrelOption class*/ /** - * Saves option + * Saves the option value (this is the default save function + * unless overridden by the user) + * * @param object $option object that holds option name and new_value */ function save_option($option) { + + // Can't save the pref if we don't have the username + // if ( !sqgetGlobalVar('username', $username, SQ_SESSION ) ) { - /* Can't save the pref if we don't have the username */ return; } + global $data_dir; - setPref($data_dir, $username, $option->name, $option->new_value); + + // Certain option types need to be serialized because + // they are not scalar + // + if ($option->type == SMOPT_TYPE_FLDRLIST_MULTI) + setPref($data_dir, $username, $option->name, serialize($option->new_value)); + else + setPref($data_dir, $username, $option->name, $option->new_value); + } /** @@ -602,7 +565,7 @@ function save_option_noop($option) { * @return string html formated hidden input field */ function create_optpage_element($optpage) { - return create_hidden_element('optpage', $optpage); + return addHidden('optpage', $optpage); } /** @@ -611,20 +574,7 @@ function create_optpage_element($optpage) { * @return string html formated hidden input field */ function create_optmode_element($optmode) { - return create_hidden_element('optmode', $optmode); -} - -/** - * Create hidden field. - * @param string $name field name - * @param string $value field value - * @return string html formated hidden input field - */ -function create_hidden_element($name, $value) { - $result = ''; - return ($result); + return addHidden('optmode', $optmode); } /** @@ -677,9 +627,9 @@ function create_option_groups($optgrps, $optvals) { $next_option->setSaveFunction($optset['save']); } - /* If provided, set the script for this option. */ - if (isset($optset['script'])) { - $next_option->setScript($optset['script']); + /* If provided, set the extra attributes for this option. */ + if (isset($optset['extra_attributes'])) { + $next_option->setExtraAttributes($optset['extra_attributes']); } /* If provided, set the "post script" for this option. */ @@ -701,48 +651,3 @@ function create_option_groups($optgrps, $optvals) { return ($result); } -/** - * @param array $option_groups - */ -function print_option_groups($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'] != '') { - echo html_tag( 'tr', "\n". - html_tag( 'td', - '' . $next_optgrp['name'] . '' , - 'center' ,'', 'valign="middle" colspan="2" style="white-space: nowrap;"' ) - ) ."\n"; - } - - /* Print each option in this option group. */ - foreach ($next_optgrp['options'] as $option) { - if ($option->type != SMOPT_TYPE_HIDDEN) { - echo html_tag( 'tr', "\n". - html_tag( 'td', $option->caption . ':', 'right' ,'', 'valign="middle"' ) . - html_tag( 'td', $option->createHTMLWidget(), 'left' ) - ) ."\n"; - } else { - echo $option->createHTMLWidget(); - } - } - - /* Print an empty row after this option group. */ - echo html_tag( 'tr', - html_tag( 'td', ' ', 'left', '', 'colspan="2"' ) - ) . "\n"; - } -} - -/** - * Create submit button inside table row. - * @param string $name - */ -function OptionSubmit( $name ) { - echo html_tag( 'tr', - html_tag( 'td', '    ', 'right', '', 'colspan="2"' ) - ) . "\n"; -} - -// vim: et ts=4