fixed spamcop plugin
[squirrelmail.git] / src / options.php
CommitLineData
59177427 1<?php
d3cdb279 2
35586184 3/**
4 * options.php
5 *
35586184 6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
8 *
47ccfad4 9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
ca479ad1 13 * @subpackage prefs
35586184 14 */
cbe5423b 15
30967a1e 16/**
202bcbcc 17 * Include the SquirrelMail initialization file.
30967a1e 18 */
202bcbcc 19require('../include/init.php');
86725763 20
21/* SquirrelMail required files. */
202bcbcc 22
23//include(SM_PATH . 'functions/imap_general.php');
24require_once(SM_PATH . 'functions/options.php');
25require_once(SM_PATH . 'functions/forms.php');
cbe5423b 26
cbe5423b 27/*********************************/
28/*** Build the resultant page. ***/
29/*********************************/
30
cbe5423b 31define('SMOPT_MODE_DISPLAY', 'display');
32define('SMOPT_MODE_SUBMIT', 'submit');
33define('SMOPT_MODE_LINK', 'link');
34
35define('SMOPT_PAGE_MAIN', 'main');
36define('SMOPT_PAGE_PERSONAL', 'personal');
37define('SMOPT_PAGE_DISPLAY', 'display');
5ed9d4fd 38define('SMOPT_PAGE_COMPOSE', 'compose');
cbe5423b 39define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
40define('SMOPT_PAGE_FOLDER', 'folder');
41define('SMOPT_PAGE_ORDER', 'order');
42
43function process_optionmode_submit($optpage, $optpage_data) {
44 /* Initialize the maximum option refresh level. */
45 $max_refresh = SMOPT_REFRESH_NONE;
46
47 /* Save each option in each option group. */
48 foreach ($optpage_data['options'] as $option_grp) {
49 foreach ($option_grp['options'] as $option) {
534367eb 50 /* Remove Debug Mode Until Needed
cbe5423b 51 echo "name = '$option->name', "
52 . "value = '$option->value', "
6206f6c4 53 . "new_value = '$option->new_value'\n";
39bfea8f 54 echo "<br />";
534367eb 55 */
cbe5423b 56 if ($option->changed()) {
57 $option->save();
58 $max_refresh = max($max_refresh, $option->refresh_level);
59 }
60 }
61 }
1e0628fb 62
cbe5423b 63 /* Return the max refresh level. */
64 return ($max_refresh);
65}
66
67function process_optionmode_link($optpage) {
68 /* There will be something here, later. */
69}
70
0b0e96c5 71
0b0e96c5 72
73/* ---------------------------- main ---------------------------- */
74
a32985a5 75/* get the globals that we may need */
1e12d1ff 76sqgetGlobalVar('key', $key, SQ_COOKIE);
77sqgetGlobalVar('username', $username, SQ_SESSION);
78sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
79sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
80
81sqgetGlobalVar('optpage', $optpage);
5ccba4f3 82sqgetGlobalVar('optmode', $optmode, SQ_FORM);
1e12d1ff 83sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
a32985a5 84/* end of getting globals */
85
cbe5423b 86/* Make sure we have an Option Page set. Default to main. */
c1f7790a 87if ( !isset($optpage) || $optpage == '' ) {
88 $optpage = SMOPT_PAGE_MAIN;
89} else {
90 $optpage = strip_tags( $optpage );
cbe5423b 91}
92
93/* Make sure we have an Option Mode set. Default to display. */
94if (!isset($optmode)) {
95 $optmode = SMOPT_MODE_DISPLAY;
96}
97
0b0e96c5 98/*
91e0dccc 99 * First, set the load information for each option page.
0b0e96c5 100 */
cbe5423b 101
102/* Initialize load information variables. */
103$optpage_name = '';
104$optpage_file = '';
105$optpage_loader = '';
106
107/* Set the load information for each page. */
108switch ($optpage) {
91e0dccc 109 case SMOPT_PAGE_MAIN:
c1f7790a 110 break;
cbe5423b 111 case SMOPT_PAGE_PERSONAL:
a3439b27 112 $optpage_name = _("Personal Information");
08185f2a 113 $optpage_file = SM_PATH . 'include/options/personal.php';
a3439b27 114 $optpage_loader = 'load_optpage_data_personal';
115 $optpage_loadhook = 'optpage_loadhook_personal';
cbe5423b 116 break;
117 case SMOPT_PAGE_DISPLAY:
118 $optpage_name = _("Display Preferences");
08185f2a 119 $optpage_file = SM_PATH . 'include/options/display.php';
cbe5423b 120 $optpage_loader = 'load_optpage_data_display';
a3439b27 121 $optpage_loadhook = 'optpage_loadhook_display';
cbe5423b 122 break;
5ed9d4fd 123 case SMOPT_PAGE_COMPOSE:
124 $optpage_name = _("Compose Preferences");
125 $optpage_file = SM_PATH . 'include/options/compose.php';
126 $optpage_loader = 'load_optpage_data_compose';
127 $optpage_loadhook = 'optpage_loadhook_compose';
128 break;
cbe5423b 129 case SMOPT_PAGE_HIGHLIGHT:
130 $optpage_name = _("Message Highlighting");
08185f2a 131 $optpage_file = SM_PATH . 'include/options/highlight.php';
cbe5423b 132 $optpage_loader = 'load_optpage_data_highlight';
a3439b27 133 $optpage_loadhook = 'optpage_loadhook_highlight';
cbe5423b 134 break;
135 case SMOPT_PAGE_FOLDER:
136 $optpage_name = _("Folder Preferences");
08185f2a 137 $optpage_file = SM_PATH . 'include/options/folder.php';
cbe5423b 138 $optpage_loader = 'load_optpage_data_folder';
a3439b27 139 $optpage_loadhook = 'optpage_loadhook_folder';
cbe5423b 140 break;
141 case SMOPT_PAGE_ORDER:
142 $optpage_name = _("Index Order");
08185f2a 143 $optpage_file = SM_PATH . 'include/options/order.php';
cbe5423b 144 $optpage_loader = 'load_optpage_data_order';
a3439b27 145 $optpage_loadhook = 'optpage_loadhook_order';
cbe5423b 146 break;
2fad95fa 147 default: do_hook('optpage_set_loadinfo');
cbe5423b 148}
149
150/**********************************************************/
151/*** Second, load the option information for this page. ***/
152/**********************************************************/
153
a32985a5 154if ( !@is_file( $optpage_file ) ) {
c1f7790a 155 $optpage = SMOPT_PAGE_MAIN;
156} else if ($optpage != SMOPT_PAGE_MAIN ) {
cbe5423b 157 /* Include the file for this optionpage. */
91e0dccc 158
cbe5423b 159 require_once($optpage_file);
160
161 /* Assemble the data for this option page. */
162 $optpage_data = array();
163 $optpage_data = $optpage_loader();
a3439b27 164 do_hook($optpage_loadhook);
cbe5423b 165 $optpage_data['options'] =
166 create_option_groups($optpage_data['grps'], $optpage_data['vals']);
167}
168
169/***********************************************************/
170/*** Next, process anything that needs to be processed. ***/
171/***********************************************************/
172
288df1a0 173$optpage_save_error=array();
174
cc61478a 175if ( isset( $optpage_data ) ) {
176 switch ($optmode) {
177 case SMOPT_MODE_SUBMIT:
178 $max_refresh = process_optionmode_submit($optpage, $optpage_data);
179 break;
180 case SMOPT_MODE_LINK:
181 $max_refresh = process_optionmode_link($optpage, $optpage_data);
182 break;
183 }
cbe5423b 184}
cbe5423b 185
cbe5423b 186/*******************************************************************/
187/* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
188/*******************************************************************/
189
190/* If in submit mode, select a save hook name and run it. */
7e235a1a 191if ($optmode == SMOPT_MODE_SUBMIT) {
cbe5423b 192 /* Select a save hook name. */
193 switch ($optpage) {
194 case SMOPT_PAGE_PERSONAL:
195 $save_hook_name = 'options_personal_save';
196 break;
197 case SMOPT_PAGE_DISPLAY:
198 $save_hook_name = 'options_display_save';
199 break;
10ad5e30 200 case SMOPT_PAGE_COMPOSE:
201 $save_hook_name = 'options_compose_save';
202 break;
cbe5423b 203 case SMOPT_PAGE_FOLDER:
204 $save_hook_name = 'options_folder_save';
205 break;
91e0dccc 206 default:
cc61478a 207 $save_hook_name = 'options_save';
cbe5423b 208 break;
209 }
b5efadfa 210
cbe5423b 211 /* Run the options save hook. */
212 do_hook($save_hook_name);
213}
214
215/***************************************************************/
216/* Apply logic to decide what optpage we want to display next. */
217/***************************************************************/
218
219/* If this is the result of an option page being submitted, then */
220/* show the main page. Otherwise, show whatever page was called. */
221
222if ($optmode == SMOPT_MODE_SUBMIT) {
223 $optpage = SMOPT_PAGE_MAIN;
224}
225
cbe5423b 226
154ad299 227if (isset($max_refresh)) $oTemplate->assign('max_refresh',$max_refresh);
228$oTemplate->assign('color',$color);
229$oTemplate->assign('optpage',$optpage);
230$oTemplate->assign('optpage_name',$optpage_name);
231$oTemplate->assign('optpage_data',$optpage_data);
232$oTemplate->assign('optmode',$optmode);
cbe5423b 233
a2b193bc 234
154ad299 235$oTemplate->display('options.tpl');
6e4bf7c9 236$oTemplate->display('footer.tpl');
237?>