291d11d8f1f05f6b70dc724282aba2af49a7b141
[squirrelmail.git] / src / options.php
1 <?php
2
3 /**
4 * options.php
5 *
6 * Displays the options page. Pulls from proper user preference files
7 * and config.php. Displays preferences as selected and other options.
8 *
9 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @version $Id$
12 * @package squirrelmail
13 * @subpackage prefs
14 */
15
16 /**
17 * Include the SquirrelMail initialization file.
18 */
19 require('../include/init.php');
20
21 /* SquirrelMail required files. */
22
23 //include(SM_PATH . 'functions/imap_general.php');
24 require_once(SM_PATH . 'functions/options.php');
25 require_once(SM_PATH . 'functions/forms.php');
26
27 /*********************************/
28 /*** Build the resultant page. ***/
29 /*********************************/
30
31 define('SMOPT_MODE_DISPLAY', 'display');
32 define('SMOPT_MODE_SUBMIT', 'submit');
33 define('SMOPT_MODE_LINK', 'link');
34
35 define('SMOPT_PAGE_MAIN', 'main');
36 define('SMOPT_PAGE_PERSONAL', 'personal');
37 define('SMOPT_PAGE_DISPLAY', 'display');
38 define('SMOPT_PAGE_COMPOSE', 'compose');
39 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
40 define('SMOPT_PAGE_FOLDER', 'folder');
41 define('SMOPT_PAGE_ORDER', 'order');
42
43 function 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) {
50 /* Remove Debug Mode Until Needed
51 echo "name = '$option->name', "
52 . "value = '$option->value', "
53 . "new_value = '$option->new_value'\n";
54 echo "<br />";
55 */
56 if ($option->changed()) {
57 $option->save();
58 $max_refresh = max($max_refresh, $option->refresh_level);
59 }
60 }
61 }
62
63 /* Return the max refresh level. */
64 return ($max_refresh);
65 }
66
67 function process_optionmode_link($optpage) {
68 /* There will be something here, later. */
69 }
70
71
72
73 /* ---------------------------- main ---------------------------- */
74
75 /* get the globals that we may need */
76 sqgetGlobalVar('key', $key, SQ_COOKIE);
77 sqgetGlobalVar('username', $username, SQ_SESSION);
78 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
79 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
80
81 sqgetGlobalVar('optpage', $optpage);
82 sqgetGlobalVar('optmode', $optmode, SQ_FORM);
83 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
84 /* end of getting globals */
85
86 /* Make sure we have an Option Page set. Default to main. */
87 if ( !isset($optpage) || $optpage == '' ) {
88 $optpage = SMOPT_PAGE_MAIN;
89 } else {
90 $optpage = strip_tags( $optpage );
91 }
92
93 /* Make sure we have an Option Mode set. Default to display. */
94 if (!isset($optmode)) {
95 $optmode = SMOPT_MODE_DISPLAY;
96 }
97
98 /*
99 * First, set the load information for each option page.
100 */
101
102 /* Initialize load information variables. */
103 $optpage_name = '';
104 $optpage_file = '';
105 $optpage_loader = '';
106
107 /* Set the load information for each page. */
108 switch ($optpage) {
109 case SMOPT_PAGE_MAIN:
110 break;
111 case SMOPT_PAGE_PERSONAL:
112 $optpage_name = _("Personal Information");
113 $optpage_file = SM_PATH . 'include/options/personal.php';
114 $optpage_loader = 'load_optpage_data_personal';
115 $optpage_loadhook = 'optpage_loadhook_personal';
116 break;
117 case SMOPT_PAGE_DISPLAY:
118 $optpage_name = _("Display Preferences");
119 $optpage_file = SM_PATH . 'include/options/display.php';
120 $optpage_loader = 'load_optpage_data_display';
121 $optpage_loadhook = 'optpage_loadhook_display';
122 break;
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;
129 case SMOPT_PAGE_HIGHLIGHT:
130 $optpage_name = _("Message Highlighting");
131 $optpage_file = SM_PATH . 'include/options/highlight.php';
132 $optpage_loader = 'load_optpage_data_highlight';
133 $optpage_loadhook = 'optpage_loadhook_highlight';
134 break;
135 case SMOPT_PAGE_FOLDER:
136 $optpage_name = _("Folder Preferences");
137 $optpage_file = SM_PATH . 'include/options/folder.php';
138 $optpage_loader = 'load_optpage_data_folder';
139 $optpage_loadhook = 'optpage_loadhook_folder';
140 break;
141 case SMOPT_PAGE_ORDER:
142 $optpage_name = _("Index Order");
143 $optpage_file = SM_PATH . 'include/options/order.php';
144 $optpage_loader = 'load_optpage_data_order';
145 $optpage_loadhook = 'optpage_loadhook_order';
146 break;
147 default: do_hook('optpage_set_loadinfo');
148 }
149
150 /**********************************************************/
151 /*** Second, load the option information for this page. ***/
152 /**********************************************************/
153
154 if ( !@is_file( $optpage_file ) ) {
155 $optpage = SMOPT_PAGE_MAIN;
156 } else if ($optpage != SMOPT_PAGE_MAIN ) {
157 /* Include the file for this optionpage. */
158
159 require_once($optpage_file);
160
161 /* Assemble the data for this option page. */
162 $optpage_data = array();
163 $optpage_data = $optpage_loader();
164 do_hook($optpage_loadhook);
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
173 $optpage_save_error=array();
174
175 if ( 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 }
184 }
185
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. */
191 if ($optmode == SMOPT_MODE_SUBMIT) {
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;
200 case SMOPT_PAGE_COMPOSE:
201 $save_hook_name = 'options_compose_save';
202 break;
203 case SMOPT_PAGE_FOLDER:
204 $save_hook_name = 'options_folder_save';
205 break;
206 default:
207 $save_hook_name = 'options_save';
208 break;
209 }
210
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
222 if ($optmode == SMOPT_MODE_SUBMIT) {
223 $optpage = SMOPT_PAGE_MAIN;
224 }
225
226
227 if (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);
233
234
235 $oTemplate->display('options.tpl');
236 $oTemplate->display('footer.tpl');
237 ?>