From cbe5423b30fd1c50b7dd9546778cbebf48804953 Mon Sep 17 00:00:00 2001 From: thomppj Date: Sun, 18 Nov 2001 10:42:32 +0000 Subject: [PATCH] Cleaned up options main for IE and Netscape compatibility. Did major work on the great options rewrite. Cool stuff here, I think... :) git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@1774 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/constants.php | 2 +- functions/options.php | 175 ++++++------ functions/prefs.php | 2 +- plugins/filters/setup.php | 10 +- plugins/newmail/setup.php | 10 +- plugins/squirrelspell/setup.php | 8 +- plugins/translate/setup.php | 8 +- src/options.php | 473 +++++++++++++++++++++----------- src/options_display.php | 127 +++++---- src/options_folder.php | 154 ++++++----- src/options_personal.php | 101 +++---- 11 files changed, 621 insertions(+), 449 deletions(-) diff --git a/functions/constants.php b/functions/constants.php index 4734a819..c2b4ec26 100644 --- a/functions/constants.php +++ b/functions/constants.php @@ -46,5 +46,5 @@ define('SMPREF_JS_ON', 1); define('SMPREF_JS_AUTODETECT', 2); - do_hook("loading_constants"); + do_hook('loading_constants'); ?> diff --git a/functions/options.php b/functions/options.php index 959b92f1..a205bbf6 100644 --- a/functions/options.php +++ b/functions/options.php @@ -36,6 +36,9 @@ define('SMOPT_SIZE_MEDIUM', 2); define('SMOPT_SIZE_LARGE', 3); define('SMOPT_SIZE_HUGE', 4); +define('SMOPT_SAVE_DEFAULT', 'save_option'); +define('SMOPT_SAVE_NOOP', 'save_option_noop'); + /** * SquirrelOption: An option for Squirrelmail. * @@ -55,17 +58,16 @@ class SquirrelOption { var $refresh_level; var $size; var $comment; + var $script; + + /* The name of the Save Function for this option. */ + var $save_function; /* The various 'values' for this options. */ var $value; var $new_value; var $possible_values; - /* This variable needs to be made private so it can not be messed with. */ - /* I just don't remember how to do it right now and think it would be */ - /* better to keep coding. Someone can fix it, if they want. Or I will. */ - var $changed; - function SquirrelOption ($name, $caption, $type, $refresh_level, $possible_values = '') { /* Set the basic stuff. */ @@ -76,6 +78,7 @@ class SquirrelOption { $this->possible_values = $possible_values; $this->size = SMOPT_SIZE_MEDIUM; $this->comment = ''; + $this->script = ''; /* Check for a current value. */ if (isset($GLOBALS[$name])) { @@ -87,11 +90,26 @@ class SquirrelOption { /* Check for a new value. */ if (isset($GLOBALS["new_$name"])) { $this->new_value = $GLOBALS["new_$name"]; - $this->changed = ($this->value !== $this->new_value); } else { $this->new_value = ''; - $this->changed = false; } + + /* Set the default save function. */ + if ((type != SMOPT_TYPE_HIDDEN) && ($type != SMOPT_TYPE_COMMENT)) { + $this->save_function = SMOPT_SAVE_DEFAULT; + } else { + $this->save_function = SMOPT_SAVE_NOOP; + } + } + + /* Set the value for this option. */ + function setValue($value) { + $this->value = $value; + } + + /* Set the new value for this option. */ + function setNewValue($new_value) { + $this->new_value = $new_value; } /* Set the size for this option. */ @@ -104,7 +122,20 @@ class SquirrelOption { $this->comment = $comment; } + /* Set the script for this option. */ + function setScript($script) { + $this->script = $script; + } + + /* Set the save function for this option. */ + function setSaveFunction($save_function) { + $this->save_function = $save_function; + } + function createHTMLWidget() { + global $javascript_on; + + /* Get the widget for this option type. */ switch ($this->type) { case SMOPT_TYPE_STRING: $result = $this->createWidget_String(); @@ -136,6 +167,9 @@ class SquirrelOption { . ''; } + /* Add the script for this option. */ + $result .= $this->script; + /* Now, return the created widget. */ return ($result); } @@ -238,12 +272,49 @@ class SquirrelOption { return ($result); } - function hasChanged() { - return ($this->changed); + function save() { + $function = $this->save_function; + $function($this); } + + function changed() { + return ($this->value !== $this->new_value); + } +} + +function save_option($option) { + global $data_dir, $username; + setPref($data_dir, $username, $option->name, $option->new_value); + + /* I do not know if this next line does any good. */ + $GLOBALS[$name] = $option->new_value; +} + +function save_option_noop($option) { + /* Do nothing here... */ } +function create_optpage_element($optpage) { + return create_hidden_element('optpage', $optpage); +} + +function create_optmode_element($optmode) { + return create_hidden_element('optmode', $optmode); +} + +function create_hidden_element($name, $value) { + $result = ''; + return ($result); +} + + function createOptionGroups($optgrps, $optvals) { + return create_option_groups($optgrps, $optvals); +} + +function create_option_groups($optgrps, $optvals) { /* Build a simple array with which to start. */ $result = array(); @@ -286,6 +357,16 @@ function createOptionGroups($optgrps, $optvals) { $next_option->setComment($optset['comment']); } + /* If provided, set the save function for this option. */ + if (isset($optset['save'])) { + $next_option->setSaveFunction($optset['save']); + } + + /* If provided, set the script for this option. */ + if (isset($optset['script'])) { + $next_option->setScript($optset['script']); + } + /* Add this option to the option array. */ $result[$grpkey]['options'][] = $next_option; } @@ -296,6 +377,10 @@ function createOptionGroups($optgrps, $optvals) { } function printOptionGroups($option_groups) { + print_option_groups($option_groups); +} + +function print_option_groups($option_groups) { foreach ($option_groups as $next_optgrp) { echo '' . $next_optgrp['name'] . "\n"; @@ -314,78 +399,6 @@ function printOptionGroups($option_groups) { } } -function OptionSelect( $title, $name, $data, $default, $show = '', $store = '' ) { - - echo "$title: " . - "\n"; -} - -function OptionRadio( $title, $name, $data, $default, $show = '', $store = '', $sep = '   ' ) { - echo "$title: "; - foreach( $data as $key => $opt ) { - if ( $store == '' ) { - $vl = $key; - } else{ - $vl = $opt[$store]; - } - if ( $show == '' ) { - $nm = $opt; - } else{ - $nm = $opt[$show]; - } - if ( $nm <> '') { - echo "$nm $sep\n"; - } - } - echo "\n"; -} - -function OptionText( $title, $name, $value, $size ) { - echo "$title: " . - "" . - "\n"; -} - -function OptionHidden( $name, $value ) { - echo "\n"; -} - -function OptionCheck( $title, $name, $value, $comment ) { - if ( $value ) - $chk = 'checked'; - echo "$title: " . - " $comment" . - "\n"; -} - -function OptionTitle( $title ) { - echo "$title\n"; -} - function OptionSubmit( $name ) { echo ' ' . ''; diff --git a/functions/prefs.php b/functions/prefs.php index e719adf6..4f9d2a68 100644 --- a/functions/prefs.php +++ b/functions/prefs.php @@ -150,4 +150,4 @@ } return $sig; } -?> \ No newline at end of file +?> diff --git a/plugins/filters/setup.php b/plugins/filters/setup.php index 03decc5a..2fd817cd 100644 --- a/plugins/filters/setup.php +++ b/plugins/filters/setup.php @@ -67,17 +67,17 @@ $squirrelmail_plugin_hooks['left_main_before']['filters'] = 'start_filters'; if ($mailbox == 'INBOX') $squirrelmail_plugin_hooks["right_main_after_header"]['filters'] = 'start_filters'; - $squirrelmail_plugin_hooks['options_register']['filters'] = 'squirrelmail_plugin_register'; + $squirrelmail_plugin_hooks['optpage_register_block']['filters'] = 'squirrelmail_plugin_optpage_register_block'; } - function squirrelmail_plugin_register() { - global $optionpages; + function squirrelmail_plugin_optpage_register_block() { + global $optpage_blocks; - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("Message Filters"), 'url' => '../plugins/filters/options.php', 'desc' => _("Filtering enables messages with different criteria to be automatically filtered into different folders for easier organization."), 'js' => false ); } -?> \ No newline at end of file +?> diff --git a/plugins/newmail/setup.php b/plugins/newmail/setup.php index da34d6ca..95514c60 100644 --- a/plugins/newmail/setup.php +++ b/plugins/newmail/setup.php @@ -60,20 +60,20 @@ global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['left_main_before']['newmail'] = 'newmail_plugin'; - $squirrelmail_plugin_hooks['options_register']['newmail'] = 'newmail_options'; + $squirrelmail_plugin_hooks['optpage_register_block']['newmail'] = 'newmail_optpage_register_block'; $squirrelmail_plugin_hooks['options_link_and_description']['newmail'] = 'newmail_options'; $squirrelmail_plugin_hooks['options_save']['newmail'] = 'newmail_sav'; $squirrelmail_plugin_hooks['loading_prefs']['newmail'] = 'newmail_pref'; } - function newmail_options() { + function newmail_optpage_register_block() { // Gets added to the user's OPTIONS page. - global $optionpages; + global $optpage_blocks; if ( !soupNazi() ) { /* Register Squirrelspell with the $optionpages array. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("NewMail Options"), 'url' => '../plugins/newmail/newmail_opt.php', 'desc' => _("This configures settings for playing sounds and/or showing popup windows when new mail arrives."), @@ -238,4 +238,4 @@ window.onload = PopupScriptLoad; } } } -?> \ No newline at end of file +?> diff --git a/plugins/squirrelspell/setup.php b/plugins/squirrelspell/setup.php index 37ca6def..daa8c198 100644 --- a/plugins/squirrelspell/setup.php +++ b/plugins/squirrelspell/setup.php @@ -31,18 +31,18 @@ global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['compose_button_row']['squirrelspell'] = 'squirrelspell_setup'; - $squirrelmail_plugin_hooks['options_register']['squirrelspell'] = 'squirrelspell_options'; + $squirrelmail_plugin_hooks['optpage_register_block']['squirrelspell'] = 'squirrelspell_optpage_register_block'; $squirrelmail_plugin_hooks['options_link_and_description']['squirrelspell'] = 'squirrelspell_options'; } - function squirrelspell_options() { + function squirrelspell_optpage_register_block() { // Gets added to the user's OPTIONS page. - global $optionpages; + global $optpage_blocks; if ( !soupNazi() ) { /* Register Squirrelspell with the $optionpages array. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("SpellChecker Options"), 'url' => '../plugins/squirrelspell/sqspell_options.php', 'desc' => _("Here you may set up how your personal dictionary is stored, edit it, or choose which languages should be available to you when spell-checking."), diff --git a/plugins/translate/setup.php b/plugins/translate/setup.php index 99bf7760..0a79c351 100644 --- a/plugins/translate/setup.php +++ b/plugins/translate/setup.php @@ -27,7 +27,7 @@ function squirrelmail_plugin_init_translate() { global $squirrelmail_plugin_hooks; $squirrelmail_plugin_hooks['read_body_bottom']['translate'] = 'translate_read_form'; - $squirrelmail_plugin_hooks['options_register']['translate'] = 'translate_opt'; + $squirrelmail_plugin_hooks['optpage_register_block']['translate'] = 'translate_optpage_register_block'; $squirrelmail_plugin_hooks['options_save']['translate'] = 'translate_sav'; $squirrelmail_plugin_hooks['loading_prefs']['translate'] = 'translate_pref'; $squirrelmail_plugin_hooks['compose_button_row']['translate'] = 'translate_button'; @@ -90,9 +90,9 @@ function translate_button() { } -function translate_opt() { - global $optionpages; - $optionpages[] = array( +function translate_optpage_register_block() { + global $optpage_blocks; + $optpage_blocks[] = array( 'name' => _("Translation Options"), 'url' => '../plugins/translate/options.php', 'desc' => _("Which translator should be used when you get messages in a different language?"), diff --git a/src/options.php b/src/options.php index 47249899..44eb86df 100644 --- a/src/options.php +++ b/src/options.php @@ -1,177 +1,255 @@ name', " + . "value = '$option->value', " + . "new_value = '$option->new_value'
\n"; + if ($option->changed()) { + $option->save(); + $max_refresh = max($max_refresh, $option->refresh_level); + } + } + } - displayPageHeader($color, _("None")); + /* Return the max refresh level. */ + return ($max_refresh); +} + +function process_optionmode_link($optpage) { + /* There will be something here, later. */ +} + +/* Make sure we have an Option Page set. Default to main. */ +if (!isset($optpage)) { + $optpage = 'main'; +} + +/* Make sure we have an Option Mode set. Default to display. */ +if (!isset($optmode)) { + $optmode = SMOPT_MODE_DISPLAY; +} + +/*************************************************************/ +/*** First, set the load information for each option page. ***/ +/*************************************************************/ + +/* Initialize load information variables. */ +$optpage_name = ''; +$optpage_file = ''; +$optpage_loader = ''; + +/* Set the load information for each page. */ +switch ($optpage) { + case SMOPT_PAGE_MAIN: break; + case SMOPT_PAGE_PERSONAL: + $optpage_name = _("Personal Information"); + $optpage_file = 'options_personal.php'; + $optpage_loader = 'load_optpage_data_personal'; + break; + case SMOPT_PAGE_DISPLAY: + $optpage_name = _("Display Preferences"); + $optpage_file = 'options_display.php'; + $optpage_loader = 'load_optpage_data_display'; + break; + case SMOPT_PAGE_HIGHLIGHT: + $optpage_name = _("Message Highlighting"); + $optpage_file = 'options_highlight.php'; + $optpage_loader = 'load_optpage_data_highlight'; + break; + case SMOPT_PAGE_FOLDER: + $optpage_name = _("Folder Preferences"); + $optpage_file = 'options_folder.php'; + $optpage_loader = 'load_optpage_data_folder'; + break; + case SMOPT_PAGE_ORDER: + $optpage_name = _("Index Order"); + $optpage_file = 'options_order.php'; + $optpage_loader = 'load_optpage_data_order'; + break; + default: do_hook('set_optpage_loadinfo'); +} + +/**********************************************************/ +/*** Second, load the option information for this page. ***/ +/**********************************************************/ + +if ($optpage != SMOPT_PAGE_MAIN) { + /* Include the file for this optionpage. */ + require_once($optpage_file); + + /* Assemble the data for this option page. */ + $optpage_data = array(); + $optpage_data = $optpage_loader(); + $optpage_data['options'] = + create_option_groups($optpage_data['grps'], $optpage_data['vals']); +} + +/***********************************************************/ +/*** Next, process anything that needs to be processed. ***/ +/***********************************************************/ + +switch ($optmode) { + case SMOPT_MODE_SUBMIT: + $max_refresh = process_optionmode_submit($optpage, $optpage_data); + break; + case SMOPT_MODE_LINK: + $max_refresh = process_optionmode_link($optpage, $optpage_data); + break; +} + +/*** MOVE THIS DISPLAY CODE DOWN EVENTUALLY!!! ***/ + +$optpage_title = _("Options"); +if (isset($optpage_name) && ($optpage_name != '')) { + $optpage_title .= " - $optpage_name"; +} ?> -
- -
-
- +
+ +
+
-
+
'._("Successfully saved personal information!").'
'; - } else if (isset($submit_display)) { - /* Do checking to make sure $new_theme is in the array. */ - $theme_in_array = false; - for ($i=0; $i < count($theme); $i++) { - if ($theme[$i]['PATH'] == $new_chosen_theme) { - $theme_in_array = true; - break; - } - } - if (!$theme_in_array) { - $new_chosen_theme = ''; - } - - /* Save display preferences. */ - setPref($data_dir, $username, 'chosen_theme', $new_chosen_theme); - setPref($data_dir, $username, 'language', $new_language); - setPref($data_dir, $username, 'use_javascript_addr_book', $new_use_javascript_addr_book); - setPref($data_dir, $username, 'javascript_setting', $new_javascript_setting); - setPref($data_dir, $username, 'show_num', $new_show_num); - setPref($data_dir, $username, 'wrap_at', $new_wrap_at); - setPref($data_dir, $username, 'editor_size', $new_editor_size); - setPref($data_dir, $username, 'location_of_buttons', $new_location_of_buttons); - setPref($data_dir, $username, 'alt_index_colors', $new_alt_index_colors); - setPref($data_dir, $username, 'show_html_default', $new_show_html_default); - setPref($data_dir, $username, 'include_self_reply_all', $new_include_self_reply_all); - setPref($data_dir, $username, 'page_selector', $new_page_selector); - setPref($data_dir, $username, 'page_selector_max', $new_page_selector_max); - setPref($data_dir, $username, 'show_xmailer_default', $new_show_xmailer_default); - setPref($data_dir, $username, 'attachment_common_show_images', $new_attachment_common_show_images); - setPref($data_dir, $username, 'pf_subtle_link', $new_pf_subtle_link); - setPref($data_dir, $username, 'pf_cleandisplay', $new_pf_cleandisplay); - - $js_autodetect_results = (isset($new_js_autodetect_results) ? $new_js_autodetect_results : SMPREF_JS_OFF); - if ($new_javascript_setting == SMPREF_JS_AUTODETECT) { - if ($js_autodetect_results == SMPREF_JS_ON) { - setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON); - } else { - setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF); - } - } else { - setPref($data_dir, $username, 'javascript_on', $new_javascript_setting); - } - - do_hook('options_display_save'); - - echo '
'._("Successfully saved display preferences!").'
'; - echo '' . _("Refresh Page") . '
'; - } else if (isset($submit_folder)) { - /* Save trash folder preferences. */ - if ($new_trash_folder != SMPREF_NONE) { - setPref($data_dir, $username, 'move_to_trash', SMPREF_ON); - setPref($data_dir, $username, 'trash_folder', $new_trash_folder); - } else { - setPref($data_dir, $username, 'move_to_trash', SMPREF_OFF); - setPref($data_dir, $username, 'trash_folder', SMPREF_NONE); - } - - /* Save sent folder preferences. */ - if ($new_sent_folder != SMPREF_NONE) { - setPref($data_dir, $username, 'move_to_sent', SMPREF_ON); - setPref($data_dir, $username, 'sent_folder', $new_sent_folder); - } else { - setPref($data_dir, $username, 'move_to_sent', SMPREF_OFF); - setPref($data_dir, $username, 'sent_folder', SMPREF_NONE); - } - /* Save draft folder preferences. */ - if ($new_draft_folder != SMPREF_NONE) { - setPref($data_dir, $username, 'save_as_draft', SMPREF_ON); - setPref($data_dir, $username, 'draft_folder', $new_draft_folder); - } else { - setPref($data_dir, $username, 'save_as_draft', SMPREF_OFF); - setPref($data_dir, $username, 'draft_folder', SMPREF_NONE); - } +/*******************************************************************/ +/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */ +/*******************************************************************/ + +/* If in submit mode, select a save hook name and run it. */ +if ($optmode == SMOPT_MODE_SUBMIT) { + /* Select a save hook name. */ + switch ($optpage) { + case SMOPT_PAGE_PERSONAL: + $save_hook_name = 'options_personal_save'; + break; + case SMOPT_PAGE_DISPLAY: + $save_hook_name = 'options_display_save'; + break; + case SMOPT_PAGE_FOLDER: + $save_hook_name = 'options_folder_save'; + break; + default: $save_hook_name = 'options_save'; + break; + } - /* Save folder prefix preferences. */ - if (isset($folderprefix)) { - setPref($data_dir, $username, 'folder_prefix', $folderprefix); - } else { - setPref($data_dir, $username, 'folder_prefix', ''); + /* Run the options save hook. */ + do_hook($save_hook_name); +} + +/***************************************************************/ +/* Apply logic to decide what optpage we want to display next. */ +/***************************************************************/ + +/* If this is the result of an option page being submitted, then */ +/* show the main page. Otherwise, show whatever page was called. */ + +if ($optmode == SMOPT_MODE_SUBMIT) { + $optpage = SMOPT_PAGE_MAIN; +} + +/***************************************************************/ +/* Finally, display whatever page we are supposed to show now. */ +/***************************************************************/ + +/* + * The main option page has a different layout then the rest of the option + * pages. Therefore, we create it here first, then the others below. + */ +if ($optpage == SMOPT_PAGE_MAIN) { + /**********************************************************/ + /* First, display the results of a submission, if needed. */ + /**********************************************************/ + if ($optmode == SMOPT_MODE_SUBMIT) { + /* Display a message indicating a successful save. */ + echo '' . _("Successfully Saved Options") . ": $optpage_name
\n"; + + /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */ + if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) { + echo '' . _("Refresh Folder List") . '
'; + } else if ($max_refresh) { + echo '' . _("Refresh Page") . '
'; } - - setPref($data_dir, $username, 'location_of_bar', $new_location_of_bar); - setPref($data_dir, $username, 'left_size', $new_left_size); - setPref($data_dir, $username, 'left_refresh', $new_left_refresh); - setPref($data_dir, $username, 'unseen_notify', $new_unseen_notify); - setPref($data_dir, $username, 'unseen_type', $new_unseen_type); - setPref($data_dir, $username, 'collapse_folders', $new_collapse_folders); - setPref($data_dir, $username, 'date_format', $new_date_format); - setPref($data_dir, $username, 'hour_format', $new_hour_format); - - do_hook('options_folders_save'); - echo '
'._("Successfully saved folder preferences!").'
'; - echo '' . _("Refresh Folder List") . '
'; - } else { - do_hook('options_save'); } - - /****************************************/ - /* Now build our array of option pages. */ - /****************************************/ + /******************************************/ + /* Build our array of Option Page Blocks. */ + /******************************************/ + $optpage_blocks = array(); /* Build a section for Personal Options. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("Personal Information"), - 'url' => 'options_personal.php', + 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL, 'desc' => _("This contains personal information about yourself such as your name, your email address, etc."), 'js' => false ); /* Build a section for Display Options. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("Display Preferences"), - 'url' => 'options_display.php', + 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY, 'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."), 'js' => false ); /* Build a section for Message Highlighting Options. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' =>_("Message Highlighting"), 'url' => 'options_highlight.php', 'desc' =>_("Based upon given criteria, incoming messages can have different background colors in the message list. This helps to easily distinguish who the messages are from, especially for mailing lists."), @@ -179,36 +257,37 @@ ); /* Build a section for Folder Options. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("Folder Preferences"), - 'url' => 'options_folder.php', + 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER, 'desc' => _("These settings change the way your folders are displayed and manipulated."), 'js' => false ); /* Build a section for Index Order Options. */ - $optionpages[] = array( + $optpage_blocks[] = array( 'name' => _("Index Order"), 'url' => 'options_order.php', 'desc' => _("The order of the message index can be rearanged and changed to contain the headers in any order you want."), 'js' => false ); + /* Build a section for plugins wanting to register an optionpage. */ - do_hook('options_register'); + do_hook('optpage_register_block'); /*****************************************************/ /* Let's sort Javascript Option Pages to the bottom. */ /*****************************************************/ - $js_optionpages = array(); - $reg_optionpages = array(); - foreach ($optionpages as $optpage) { - if (!$optpage['js']) { - $reg_optionpages[] = $optpage; + $js_optpage_blocks = array(); + $reg_optpage_blocks = array(); + foreach ($optpage_blocks as $cur_optpage) { + if (!$cur_optpage['js']) { + $reg_optpage_blocks[] = $cur_optpage; } else if ($javascript_on == SMPREF_JS_ON) { - $js_optionpages[] = $optpage; + $js_optpage_blocks[] = $cur_optpage; } } - $optionpages = array_merge($reg_optionpages, $js_optionpages); + $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks); /********************************************/ /* Now, print out each option page section. */ @@ -217,7 +296,7 @@ echo "" . '' . - "
' . ""; - foreach ($optionpages as $next_optpage) { + foreach ($optpage_blocks as $next_optpage) { if ($first_optpage == false) { $first_optpage = $next_optpage; } else { @@ -230,12 +309,74 @@ print_optionpages_row($first_optpage); } - echo '
' . - '
\n"; + echo "
\n"; do_hook('options_link_and_description'); + +/*************************************************************************/ +/* If we are not looking at the main option page, display the page here. */ +/*************************************************************************/ +} else { + echo '

' . "\n" + . '' . "\n" + . create_optpage_element($optpage) + . create_optmode_element(SMOPT_MODE_SUBMIT); + + /* Output the option groups for this page. */ + print_option_groups($optpage_data['options']); + + /*** FIXME: CURRENTLY, THIS NEXT SWITCH STATEMENT DOES NOT TAKE + *** INTO ACCOUNT FOR PLUGINS. NEED TO FIX IT. ***/ + + /* Set the inside_hook_name and submit_name. */ + switch ($optpage) { + case SMOPT_PAGE_PERSONAL: + $inside_hook_name = 'options_personal_inside'; + $bottom_hook_name = 'options_personal_bottom'; + $submit_name = 'submit_personal'; + break; + case SMOPT_PAGE_DISPLAY: + $inside_hook_name = 'options_display_inside'; + $bottom_hook_name = 'options_display_bottom'; + $submit_name = 'submit_display'; + break; + case SMOPT_PAGE_HIGHLIGHT: + $inside_hook_name = 'options_highlight_inside'; + $bottom_hook_name = 'options_display_bottom'; + $submit_name = 'submit_highlight'; + break; + case SMOPT_PAGE_FOLDER: + $inside_hook_name = 'options_folder_inside'; + $bottom_hook_name = 'options_display_bottom'; + $submit_name = 'submit_folder'; + break; + case SMOPT_PAGE_ORDER: + $inside_hook_name = 'options_order_inside'; + $bottom_hook_name = 'options_order_bottom'; + $submit_name = 'submit_order'; + break; + default: + $inside_hook_name = ''; + $bottom_hook_name = ''; + $submit_name = 'submit'; + } + + /* If it is not empty, trigger the inside hook. */ + if ($inside_hook_name != '') { + do_hook($inside_hook_name); + } + + /* Spit out a submit button. */ + OptionSubmit($submit_name); + echo '
'; + + /* If it is not empty, trigger the bottom hook. */ + if ($bottom_hook_name != '') { + do_hook($bottom_hook_name); + } +} + ?>
@@ -243,7 +384,7 @@ - + ' . '' . - "" . + "" . $leftopt['desc'] . '' . " "; if ($rightopt) { - echo "" . + echo "" . $rightopt['desc'] . ''; } else { - echo " "; + echo " "; } echo '' . diff --git a/src/options_display.php b/src/options_display.php index c9a69b57..ccb337de 100644 --- a/src/options_display.php +++ b/src/options_display.php @@ -1,37 +1,24 @@ -
- - -
- -
- - -
- -

- - _("Theme"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_ALL, - 'posvals' => $theme_values + 'posvals' => $theme_values, + 'save' => 'save_option_theme' ); $language_values = array(); @@ -86,12 +71,19 @@ SMPREF_JS_OFF => _("Never")) ); + $js_autodetect_script = " + + "; $js_autodetect_results = SMPREF_JS_OFF; $optvals[SMOPT_GRP_GENERAL][] = array( 'name' => 'js_autodetect_results', 'caption' => '', 'type' => SMOPT_TYPE_HIDDEN, - 'refresh' => SMOPT_REFRESH_NONE + 'refresh' => SMOPT_REFRESH_NONE, + 'script' => $js_autodetect_script, + 'save' => 'save_option_javascript_autodetect' ); /*** Load the General Options into the array ***/ @@ -209,28 +201,51 @@ 'refresh' => SMOPT_REFRESH_NONE ); - /* Build and output the option groups. */ - $option_groups = createOptionGroups($optgrps, $optvals); - printOptionGroups($option_groups); - - do_hook('options_display_inside'); - echo "\n"; + /* Assemble all this together and return it as our result. */ + $result = array( + 'grps' => $optgrps, + 'vals' => $optvals + ); + return ($result); +} - OptionSubmit( 'submit_display' ); -?> +/******************************************************************/ +/** Define any specialized save functions for this option page. ***/ +/******************************************************************/ -
 
-
+function save_option_theme($option) { + global $theme; - + /* Do checking to make sure $new_theme is in the array. */ + $theme_in_array = false; + for ($i = 0; $i < count($theme); ++$i) { + if ($theme[$i]['PATH'] == $option->new_value) { + $theme_in_array = true; + break; + } + } + + if (!$theme_in_array) { + $option->new_value = ''; + } -
+ /* Save the option like normal. */ + save_option($option); +} - +function save_option_javascript_autodetect($option) { + global $data_dir, $username, $new_javascript_setting; -
- + /* Set javascript either on or off. */ + if ($new_javascript_setting == SMPREF_JS_AUTODETECT) { + if ($option->new_value == SMPREF_JS_ON) { + setPref($data_dir, $username, 'javascript_on', SMPREF_JS_ON); + } else { + setPref($data_dir, $username, 'javascript_on', SMPREF_JS_OFF); + } + } else { + setPref($data_dir, $username, 'javascript_on', $new_javascript_setting); + } +} + +?> diff --git a/src/options_folder.php b/src/options_folder.php index 2e0e60fb..23b5b018 100644 --- a/src/options_folder.php +++ b/src/options_folder.php @@ -1,54 +1,32 @@ -
- - -
- - - - - -
- -

- - - - - - - - 'folder_prefix', + 'caption' => _("Folder Path"), + 'type' => SMOPT_TYPE_STRING, + 'refresh' => SMOPT_REFRESH_FOLDERLIST, + 'size' => SMOPT_SIZE_LARGE + ); + } + $special_folder_values = array(); foreach ($boxes as $folder) { if (strtolower($folder['unformatted']) != 'inbox') { @@ -80,7 +67,8 @@ 'caption' => _("Trash Folder"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, - 'posvals' => $trash_folder_values + 'posvals' => $trash_folder_values, + 'save' => 'save_option_trash_folder' ); $sent_none = array(SMPREF_NONE => _("Do not use Sent")); @@ -90,7 +78,8 @@ 'caption' => _("Sent Folder"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, - 'posvals' => $sent_folder_values + 'posvals' => $sent_folder_values, + 'save' => 'save_option_sent_folder' ); $draft_none = array(SMPREF_NONE => _("Do not use Drafts")); @@ -100,7 +89,8 @@ 'caption' => _("Draft Folder"), 'type' => SMOPT_TYPE_STRLIST, 'refresh' => SMOPT_REFRESH_FOLDERLIST, - 'posvals' => $draft_folder_values + 'posvals' => $draft_folder_values, + 'save' => 'save_option_draft_folder' ); /*** Load the General Options into the array ***/ @@ -195,24 +185,48 @@ SMPREF_TIME_24HR => _("24-hour clock")) ); + /* Assemble all this together and return it as our result. */ + $result = array( + 'grps' => $optgrps, + 'vals' => $optvals + ); + return ($result); +} + +/******************************************************************/ +/** Define any specialized save functions for this option page. ***/ +/******************************************************************/ +function save_option_trash_folder($option) { + global $data_dir, $username; + + /* Set move to trash on or off. */ + $trash_on = ($option->new_value == SMPREF_NONE ? SMPREF_OFF : SMPREF_ON); + setPref($data_dir, $username, 'move_to_trash', $trash_on); - /* Build and output the option groups. */ - $option_groups = createOptionGroups($optgrps, $optvals); - printOptionGroups($option_groups); - - echo '\n"; - OptionSubmit( 'submit_folder' ); -?> + /* Now just save the option as normal. */ + save_option($option); +} -
: - -
'; - else - echo '
'; -?> -
' - . _("Plugin Options") . "
-
+function save_option_sent_folder($option) { + global $data_dir, $username; - + /* Set move to sent on or off. */ + $sent_on = ($option->new_value == SMPREF_NONE ? SMPREF_OFF : SMPREF_ON); + setPref($data_dir, $username, 'move_to_sent', $sent_on); -
+ /* Now just save the option as normal. */ + save_option($option); +} -
- +function save_option_draft_folder($option) { + global $data_dir, $username; + + /* Set move to draft on or off. */ + $draft_on = ($option->new_value == SMPREF_NONE ? SMPREF_OFF : SMPREF_ON); + setPref($data_dir, $username, 'save_as_draft', $draft_on); + + /* Now just save the option as normal. */ + save_option($option); +} + +?> diff --git a/src/options_personal.php b/src/options_personal.php index 34a7695d..988ccb2c 100644 --- a/src/options_personal.php +++ b/src/options_personal.php @@ -1,41 +1,33 @@ -
- - -
- - - - - -
- -

- - _("Signature"), 'type' => SMOPT_TYPE_TEXTAREA, 'refresh' => SMOPT_REFRESH_NONE, - 'size' => SMOPT_SIZE_MEDIUM + 'size' => SMOPT_SIZE_MEDIUM, + 'save' => 'save_option_signature' ); - /* Build and output the option groups. */ - $option_groups = createOptionGroups($optgrps, $optvals); - printOptionGroups($option_groups); - - do_hook('options_personal_inside'); - OptionSubmit( 'submit_personal' ); - -?> -
-
+ /* Assemble all this together and return it as our result. */ + $result = array( + 'grps' => $optgrps, + 'vals' => $optvals + ); + return ($result); +} - +/******************************************************************/ +/** Define any specialized save functions for this option page. ***/ +/******************************************************************/ -
+function save_option_signature($option) { + global $data_dir, $username; + setSig($data_dir, $username, $option->new_value); +} -
- +?> -- 2.25.1