- 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)
/**
* Function to create a selectlist from an array.
- * @param string $sName field name
- * @param array $aValues field values array(key => value) -> <option value="key">value</option>, although if $bUsekeys is FALSE, then <option value="value">value</option>
- * @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:
+ * <option value="key">value</option>,
+ * although if $bUsekeys is FALSE, then it changes to:
+ * <option value="value">value</option>
+ * @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);
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');
}
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);
*/
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
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)
/**
* 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)
// 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
//
$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);
}
* 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
}
-echo '<select name="' . $name . '"';
+echo '<select name="' . $name . ($multiple ? '[]" multiple="multiple" size="3"' : '"');
foreach ($aAttribs as $key => $value) {
echo ' ' . $key . (is_null($value) ? '' : '="' . $value . '"');
}
foreach ($aValues as $key => $value) {
if (!$bUsekeys) $key = $value;
- echo '<option value="' . $key . '"'
- . (($default == $key) ? ' selected="selected"' : '')
- . '>' . $label_open . $value . $label_close . "</option>\n";
+ echo '<option value="' . $key . '"';
+
+ // multiple select lists have possibly more than one default selection
+ //
+ if ($multiple) {
+ foreach ($default as $def) {
+ if ($def === $key) {
+ echo ' selected="selected"';
+ break;
+ }
+ }
+ }
+
+ // single select widget only needs to check for one default value
+ // (we could use the same code above, but we do this here to increase
+ // efficency and performance)
+ //
+ else if ($default[0] === $key)
+ echo ' selected="selected"';
+
+ echo '>' . $label_open . $value . $label_close . "</option>\n";
}
echo "</select>\n";