+
+ // edit lists: first add new elements to list, then
+ // remove any selected ones (note that we must add
+ // before deleting because the javascript that populates
+ // the "add" textbox when selecting items in the list
+ // (for deletion))
+ //
+ if ($option->type == SMOPT_TYPE_EDIT_LIST) {
+
+ if (empty($option->possible_values)) $option->possible_values = array();
+ if (!is_array($option->possible_values)) $option->possible_values = array($option->possible_values);
+
+ // add element if given
+ //
+ if ((isset($option->use_add_widget) && $option->use_add_widget)
+ && sqGetGlobalVar('add_' . $option->name, $new_element, SQ_POST)) {
+ $new_element = trim($new_element);
+ if (!empty($new_element)
+ && !in_array($new_element, $option->possible_values))
+ $option->possible_values[] = $new_element;
+ }
+
+ // delete selected elements if needed
+ //
+ if ((isset($option->use_delete_widget) && $option->use_delete_widget)
+ && is_array($option->new_value)
+ && sqGetGlobalVar('delete_' . $option->name, $ignore, SQ_POST))
+ $option->possible_values = array_diff($option->possible_values, $option->new_value);
+
+ // save full list (stored in "possible_values")
+ //
+ setPref($data_dir, $username, $option->name, serialize($option->possible_values));
+
+ // Certain option types need to be serialized because
+ // they are not scalar
+ //
+ } else if ($option->is_multiple_valued())
+ setPref($data_dir, $username, $option->name, serialize($option->new_value));
+
+ // Checkboxes, when unchecked, don't submit anything in
+ // the POST, so set to SMPREF_OFF if not found
+ //
+ else if (($option->type == SMOPT_TYPE_BOOLEAN
+ || $option->type == SMOPT_TYPE_BOOLEAN_CHECKBOX)
+ && empty($option->new_value))
+ setPref($data_dir, $username, $option->name, SMPREF_OFF);
+
+ else
+ setPref($data_dir, $username, $option->name, $option->new_value);
+
+
+ // if a checkbox or multi select is zeroed/cleared out, it
+ // needs to have an empty value pushed into its "new_value" slot
+ //
+ if (($option->type == SMOPT_TYPE_STRLIST_MULTI
+ || $option->type == SMOPT_TYPE_BOOLEAN_CHECKBOX)
+ && is_null($option->new_value))
+ $option->new_value = '';
+