From: pdontthink Date: Wed, 2 Jan 2008 12:11:46 +0000 (+0000) Subject: Add multiple select folder list option widget (SMOPT_TYPE_FLDRLIST_MULTI) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=42b7c9d4800d9a64222dc95caf91abacb3d7ae4a;p=squirrelmail.git Add multiple select folder list option widget (SMOPT_TYPE_FLDRLIST_MULTI) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@12842 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/ChangeLog b/ChangeLog index 8b4bf471..0477a97f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -241,6 +241,7 @@ Version 1.5.2 - SVN - Let configtest.php use optional PEAR dynamic extension loading, patch by Walter Huijbers (#1833123). - Fix for IMAP servers that were having problems saving sent messages + - Added multiple select folder list option widgets (SMOPT_TYPE_FLDRLIST_MULTI). Version 1.5.1 (branched on 2006-02-12) diff --git a/functions/forms.php b/functions/forms.php index 059d6945..8ec83d4d 100644 --- a/functions/forms.php +++ b/functions/forms.php @@ -159,16 +159,22 @@ function addInput($sName, $sValue = '', $iSize = 0, $iMaxlength = 0, $aAttribs=a /** * Function to create a selectlist from an array. - * @param string $sName field name - * @param array $aValues field values array(key => value) -> , although if $bUsekeys is FALSE, then - * @param mixed $default the key that will be selected - * @param boolean $bUsekeys use the keys of the array as option value or not - * @param array $aAttribs (since 1.5.1) extra attributes + * @param string $sName Field name + * @param array $aValues Field values array(key => value) results in: + * , + * although if $bUsekeys is FALSE, then it changes to: + * + * @param mixed $default The key(s) that will be selected (it is OK to pass + * in an array here in the case of multiple select lists) + * @param boolean $bUsekeys Use the keys of the array as option value or not + * @param array $aAttribs (since 1.5.1) Extra attributes + * @param boolean $bMultiple When TRUE, a multiple select list will be shown + * (OPTIONAL; default is FALSE (single select list)) * * @return string html formated selection box * @todo add attributes argument for option tags and default css */ -function addSelect($sName, $aValues, $default = null, $bUsekeys = false, $aAttribs = array()) { +function addSelect($sName, $aValues, $default = null, $bUsekeys = false, $aAttribs = array(), $bMultiple = FALSE) { // only one element if(count($aValues) == 1) { $k = key($aValues); $v = array_pop($aValues); @@ -176,14 +182,23 @@ function addSelect($sName, $aValues, $default = null, $bUsekeys = false, $aAttri htmlspecialchars($v) . "\n"; } + + // make sure $default is an array, since multiple select lists + // need the chance to have more than one default... + // + if (!is_array($default)) + $default = array($default); + + global $oTemplate; -//FIXME: all the values in the $aAttribs list and $sName and both the keys and values in $aValues used to go thru htmlspecialchars()... I would propose that most everything that is assigned to the template should go thru that *in the template class* on its way between here and the actual template file. Otherwise we have to do something like: foreach ($aAttribs as $key => $value) $aAttribs[$key] = htmlspecialchars($value); $sName = htmlspecialchars($sName); $aNewValues = array(); foreach ($aValues as $key => $value) $aNewValues[htmlspecialchars($key)] = htmlspecialchars($value); $aValues = $aNewValues; And probably this too because it has to be matched to a value that has already been sanitized: $default = htmlspecialchars($default); +//FIXME: all the values in the $aAttribs list and $sName and both the keys and values in $aValues used to go thru htmlspecialchars()... I would propose that most everything that is assigned to the template should go thru that *in the template class* on its way between here and the actual template file. Otherwise we have to do something like: foreach ($aAttribs as $key => $value) $aAttribs[$key] = htmlspecialchars($value); $sName = htmlspecialchars($sName); $aNewValues = array(); foreach ($aValues as $key => $value) $aNewValues[htmlspecialchars($key)] = htmlspecialchars($value); $aValues = $aNewValues; And probably this too because it has to be matched to a value that has already been sanitized: $default = htmlspecialchars($default); (oops, watch out for when $default is an array! (multiple select lists)) $oTemplate->assign('aAttribs', $aAttribs); $oTemplate->assign('aValues', $aValues); $oTemplate->assign('bUsekeys', $bUsekeys); $oTemplate->assign('default', $default); $oTemplate->assign('name', $sName); + $oTemplate->assign('multiple', $bMultiple); return $oTemplate->fetch('select.tpl'); } diff --git a/functions/options.php b/functions/options.php index 424e4c87..f593e1ae 100644 --- a/functions/options.php +++ b/functions/options.php @@ -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); @@ -144,7 +145,8 @@ class SquirrelOption { */ 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 @@ -315,6 +317,9 @@ class SquirrelOption { case SMOPT_TYPE_FLDRLIST: $result = $this->createWidget_FolderList(); break; + case SMOPT_TYPE_FLDRLIST_MULTI: + $result = $this->createWidget_FolderList(TRUE); + break; default: error_box ( sprintf(_("Option Type '%s' Not Found"), $this->type) @@ -376,9 +381,16 @@ class SquirrelOption { /** * 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() { + function createWidget_FolderList($multiple_select=FALSE) { // possible values might include a nested array of // possible values (list of folders) @@ -389,7 +401,7 @@ class SquirrelOption { // list of folders (boxes array) // if (is_array($text)) { - $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, array(strtolower($this->value)), 0, $text, $this->folder_filter)); + $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter)); // just one option here // @@ -402,7 +414,8 @@ class SquirrelOption { $option_list = array('ignore' => _("unavailable")); - return addSelect('new_' . $this->name, $option_list, $this->value, TRUE, $this->aExtraAttribs) . htmlspecialchars($this->trailing_text); + // 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); } diff --git a/templates/default/select.tpl b/templates/default/select.tpl index 288abd2b..e47349c5 100644 --- a/templates/default/select.tpl +++ b/templates/default/select.tpl @@ -6,22 +6,27 @@ * Template for constructing a select input tag. * * The following variables are available in this template: - * + $name - The name of the select input - * + $aValues - An associative array corresponding to each - * select option where keys must be used as - * the option value and the values must be used - * as the option text - * + $bUsekeys - When FALSE, the value of each option should - * be the same as the option text instead of - * using the array key for the option value - * + $default - The option value that should be selected by default - * + $aAttribs - Any extra attributes: an associative array, where - * keys are attribute names, and values (which are - * optional and might be null) should be placed - * in double quotes as attribute values (optional; - * may not be present) + * string $name The name of the select input + * array $aValues An associative array corresponding to each + * select option where keys must be used as + * the option value and the values must be used + * as the option text + * boolean $bUsekeys When FALSE, the value of each option should + * be the same as the option text instead of + * using the array key for the option value + * boolean $multiple When TRUE, a multiple select list should be + * shown. + * array $default An array of option values that should be + * selected by default (only will contain one + * array element unless this is a multiple select + * list) + * array $aAttribs Any extra attributes: an associative array, where + * keys are attribute names, and values (which are + * optional and might be null) should be placed + * in double quotes as attribute values (optional; + * may not be present) * - * @copyright © 1999-2006 The SquirrelMail Project Team + * @copyright © 1999-2008 The SquirrelMail Project Team * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @version $Id$ * @package squirrelmail @@ -43,7 +48,7 @@ if (isset($aAttribs['id'])) { } -echo '\n";