+ /**
+ * Set the new value for this option.
+ * @param mixed $new_value
+ */
+ function setNewValue($new_value) {
+ $this->new_value = $new_value;
+ }
+
+ /**
+ * Set the size for this option.
+ * @param integer $size
+ */
+ function setSize($size) {
+ $this->size = $size;
+ }
+
+ /**
+ * Set the trailing_text for this option.
+ * @param string $trailing_text
+ */
+ function setTrailingText($trailing_text) {
+ $this->trailing_text = $trailing_text;
+ }
+
+ /**
+ * Set the comment for this option.
+ * @param string $comment
+ */
+ function setComment($comment) {
+ $this->comment = $comment;
+ }
+
+ /**
+ * Set the extra attributes for this option.
+ * @param array $aExtraAttribs
+ */
+ function setExtraAttributes($aExtraAttribs) {
+ $this->aExtraAttribs = $aExtraAttribs;
+ }
+
+ /**
+ * Set the "post script" for this option.
+ * @param string $post_script
+ */
+ function setPostScript($post_script) {
+ $this->post_script = $post_script;
+ }
+
+ /**
+ * Set the save function for this option.
+ * @param string $save_function
+ */
+ function setSaveFunction($save_function) {
+ $this->save_function = $save_function;
+ }
+
+ /**
+ * Set the trailing_text for this option.
+ * @param string $folder_filter
+ * @since 1.5.1
+ */
+ function setFolderFilter($folder_filter) {
+ $this->folder_filter = $folder_filter;
+ }
+
+ /**
+ * Creates fields on option pages according to option type
+ *
+ * This is the function that calls all other createWidget* functions.
+ *
+ * @return string The formated option field
+ *
+ */
+ function createWidget() {
+ global $color;
+
+ // Use new value if available
+ if (!empty($this->new_value)) {
+ $tempValue = $this->value;
+ $this->value = $this->new_value;
+ }
+
+ /* Get the widget for this option type. */
+ switch ($this->type) {
+ case SMOPT_TYPE_STRING:
+ $result = $this->createWidget_String();
+ break;
+ case SMOPT_TYPE_STRLIST:
+ $result = $this->createWidget_StrList();
+ break;
+ case SMOPT_TYPE_TEXTAREA:
+ $result = $this->createWidget_TextArea();
+ break;
+ case SMOPT_TYPE_INTEGER:
+ $result = $this->createWidget_Integer();
+ break;
+ case SMOPT_TYPE_FLOAT:
+ $result = $this->createWidget_Float();
+ break;
+ case SMOPT_TYPE_BOOLEAN:
+ $result = $this->createWidget_Boolean();
+ break;
+ case SMOPT_TYPE_HIDDEN:
+ $result = $this->createWidget_Hidden();
+ break;
+ case SMOPT_TYPE_COMMENT:
+ $result = $this->createWidget_Comment();
+ break;
+ case SMOPT_TYPE_FLDRLIST:
+ $result = $this->createWidget_FolderList();
+ break;
+ case SMOPT_TYPE_FLDRLIST_MULTI:
+ $result = $this->createWidget_FolderList(TRUE);
+ break;
+ case SMOPT_TYPE_EDIT_LIST:
+ $result = $this->createWidget_EditList();
+ break;
+ case SMOPT_TYPE_STRLIST_MULTI:
+ $result = $this->createWidget_StrList(TRUE);
+ break;
+ default:
+ error_box (
+ sprintf(_("Option Type '%s' Not Found"), $this->type)
+ );
+ }
+
+ /* Add the "post script" for this option. */
+ $result .= $this->post_script;
+
+ // put correct value back if need be
+ if (!empty($this->new_value)) {
+ $this->value = $tempValue;
+ }
+
+ /* Now, return the created widget. */
+ return $result;
+ }
+
+ /**
+ * Create string field
+ * @return string html formated option field
+ */
+ function createWidget_String() {
+ switch ($this->size) {
+ case SMOPT_SIZE_TINY:
+ $width = 5;
+ break;
+ case SMOPT_SIZE_SMALL:
+ $width = 12;
+ break;
+ case SMOPT_SIZE_LARGE:
+ $width = 38;
+ break;
+ case SMOPT_SIZE_HUGE:
+ $width = 50;
+ break;
+ case SMOPT_SIZE_NORMAL:
+ default:
+ $width = 25;
+ }
+
+ 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!
+ *
+ * @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_StrList($multiple_select=FALSE) {
+//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
+
+ switch ($this->size) {
+//FIXME: not sure about these sizes... seems like we could add another on the "large" side...
+ case SMOPT_SIZE_TINY:
+ $height = 3;
+ break;
+ case SMOPT_SIZE_SMALL:
+ $height = 8;
+ break;
+ case SMOPT_SIZE_LARGE:
+ $height = 15;
+ break;
+ case SMOPT_SIZE_HUGE:
+ $height = 25;
+ break;
+ case SMOPT_SIZE_NORMAL:
+ default:
+ $height = 5;
+ }
+
+ return addSelect('new_' . $this->name, $this->possible_values, $this->value, TRUE, $this->aExtraAttribs, $multiple_select, $height, !$this->htmlencoded) . 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($multiple_select=FALSE) {
+
+ switch ($this->size) {
+//FIXME: not sure about these sizes... seems like we could add another on the "large" side...
+ case SMOPT_SIZE_TINY:
+ $height = 3;
+ break;
+ case SMOPT_SIZE_SMALL:
+ $height = 8;
+ break;
+ case SMOPT_SIZE_LARGE:
+ $height = 15;
+ break;
+ case SMOPT_SIZE_HUGE:
+ $height = 25;
+ break;
+ case SMOPT_SIZE_NORMAL:
+ default:
+ $height = 5;
+ }
+
+ // possible values might include a nested array of
+ // possible values (list of folders)
+ //
+ $option_list = array();
+ foreach ($this->possible_values as $value => $text) {
+
+ // list of folders (boxes array)
+ //
+ if (is_array($text)) {
+ $option_list = array_merge($option_list, sqimap_mailbox_option_array(0, 0, $text, $this->folder_filter));
+
+ // just one option here
+ //
+ } else {
+ $option_list = array_merge($option_list, array($value => $text));