Also use $nbsp here as well
[squirrelmail.git] / functions / options.php
index d03d05babb998495fff8e47302f56773644e8177..b42b05b6c0f0762ddb0cea848b6137786930c15d 100644 (file)
@@ -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);
@@ -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,11 +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:
-//FIXME: can we throw an error here instead?  either way, we don't want HTML here!
-               $result = '<font color="' . $color[2] . '">'
-                       . sprintf(_("Option Type '%s' Not Found"), $this->type)
-                       . '</font>';
+                error_box ( 
+                    sprintf(_("Option Type '%s' Not Found"), $this->type)
+                    );
         }
 
         /* Add the "post script" for this option. */
@@ -370,16 +374,23 @@ class SquirrelOption {
      * @return string html formated selection box
      */
     function createWidget_StrList() {
-
-        return addSelect('new_' . $this->name, $this->possible_values, $this->value, TRUE, $this->aExtraAttribs, !$this->htmlencoded) . htmlspecialchars($this->trailing_text);
+//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
+        return addSelect('new_' . $this->name, $this->possible_values, $this->value, TRUE, $this->aExtraAttribs) . htmlspecialchars($this->trailing_text);
 
     }
 
     /**
      * 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)
@@ -390,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
             //
@@ -403,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);
 
     }
 
@@ -466,8 +478,7 @@ class SquirrelOption {
      */
     function createWidget_Boolean() {
 
-        global $oTemplate;
-        $nbsp = $oTemplate->fetch('non_breaking_space.tpl');
+        global $oTemplate, $nbsp;
 
         /* Build the yes choice. */
         $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');
@@ -514,16 +525,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);
+
 }
 
 /**
@@ -626,4 +650,3 @@ function create_option_groups($optgrps, $optvals) {
     return ($result);
 }
 
-// vim: et ts=4