squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

options.php
Go to the documentation of this file.
1 <?php
2 
17 define('PAGE_NAME', 'options');
18 
23 define('SM_PATH','../');
24 
25 /* SquirrelMail required files. */
26 require_once(SM_PATH . 'include/validate.php');
27 require_once(SM_PATH . 'functions/global.php');
28 require_once(SM_PATH . 'functions/display_messages.php');
29 require_once(SM_PATH . 'functions/imap.php');
30 require_once(SM_PATH . 'functions/options.php');
31 require_once(SM_PATH . 'functions/strings.php');
32 require_once(SM_PATH . 'functions/html.php');
33 require_once(SM_PATH . 'functions/forms.php');
34 
35 /*********************************/
36 /*** Build the resultant page. ***/
37 /*********************************/
38 
39 define('SMOPT_MODE_DISPLAY', 'display');
40 define('SMOPT_MODE_SUBMIT', 'submit');
41 define('SMOPT_MODE_LINK', 'link');
42 
43 define('SMOPT_PAGE_MAIN', 'main');
44 define('SMOPT_PAGE_PERSONAL', 'personal');
45 define('SMOPT_PAGE_DISPLAY', 'display');
46 define('SMOPT_PAGE_HIGHLIGHT', 'highlight');
47 define('SMOPT_PAGE_FOLDER', 'folder');
48 define('SMOPT_PAGE_ORDER', 'order');
49 
63 function process_optionmode_submit($optpage, $optpage_data) {
64  /* Initialize the maximum option refresh level. */
65  $max_refresh = SMOPT_REFRESH_NONE;
66 
67  /* Save each option in each option group. */
68  foreach ($optpage_data['options'] as $option_grp) {
69  foreach ($option_grp['options'] as $option) {
70  /* Remove Debug Mode Until Needed
71  echo "name = '$option->name', "
72  . "value = '$option->value', "
73  . "new_value = '$option->new_value'\n";
74  echo "<br />";
75  */
76  if ($option->changed()) {
77  $option->save();
78  $max_refresh = max($max_refresh, $option->refresh_level);
79  }
80  }
81  }
82 
83  /* Return the max refresh level. */
84  return ($max_refresh);
85 }
86 
87 function process_optionmode_link($optpage) {
88  /* There will be something here, later. */
89 }
90 
91 
95 function print_optionpages_row($leftopt, $rightopt = false) {
96  global $color;
97 
98  if ($rightopt) {
99  $rightopt_name = html_tag( 'td', '<a href="' . $rightopt['url'] . '">' . $rightopt['name'] . '</a>', 'left', $color[9], 'valign="top" width="49%"' );
100  $rightopt_desc = html_tag( 'td', $rightopt['desc'], 'left', $color[0], 'valign="top" width="49%"' );
101  } else {
102  $rightopt_name = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
103  $rightopt_desc = html_tag( 'td', '&nbsp;', 'left', $color[4], 'valign="top" width="49%"' );
104  }
105 
106  echo
107  html_tag( 'table', "\n" .
108  html_tag( 'tr', "\n" .
109  html_tag( 'td', "\n" .
110  html_tag( 'table', "\n" .
111  html_tag( 'tr', "\n" .
112  html_tag( 'td',
113  '<a href="' . $leftopt['url'] . '">' . $leftopt['name'] . '</a>' ,
114  'left', $color[9], 'valign="top" width="49%"' ) .
115  html_tag( 'td',
116  '&nbsp;' ,
117  'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
118  $rightopt_name
119  ) . "\n" .
120  html_tag( 'tr', "\n" .
121  html_tag( 'td',
122  $leftopt['desc'] ,
123  'left', $color[0], 'valign="top" width="49%"' ) .
124  html_tag( 'td',
125  '&nbsp;' ,
126  'left', $color[4], 'valign="top" width="2%"' ) . "\n" .
127  $rightopt_desc
128  ) ,
129  '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) ,
130  'left', '', 'valign="top"' )
131  ) ,
132  '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' );
133 }
134 
135 /* ---------------------------- main ---------------------------- */
136 
137 /* get the globals that we may need */
138 sqgetGlobalVar('key', $key, SQ_COOKIE);
139 sqgetGlobalVar('username', $username, SQ_SESSION);
140 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
141 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
142 
143 sqgetGlobalVar('optpage', $optpage);
144 sqgetGlobalVar('optmode', $optmode, SQ_FORM);
145 sqgetGlobalVar('optpage_data',$optpage_data, SQ_POST);
146 if (!sqgetGlobalVar('smtoken',$submitted_token, SQ_FORM)) {
147  $submitted_token = '';
148 }
149 /* end of getting globals */
150 
151 /* Make sure we have an Option Page set. Default to main. */
152 if ( !isset($optpage) || $optpage == '' ) {
153  $optpage = SMOPT_PAGE_MAIN;
154 } else {
155  $optpage = strip_tags( $optpage );
156 }
157 
158 /* Make sure we have an Option Mode set. Default to display. */
159 if (!isset($optmode)) {
160  $optmode = SMOPT_MODE_DISPLAY;
161 }
162 
163 /*
164  * First, set the load information for each option page.
165  */
166 
167 /* Initialize load information variables. */
171 
172 /* Set the load information for each page. */
173 switch ($optpage) {
174  case SMOPT_PAGE_MAIN:
175  break;
176  case SMOPT_PAGE_PERSONAL:
177  $optpage_name = _("Personal Information");
178  $optpage_file = SM_PATH . 'include/options/personal.php';
179  $optpage_loader = 'load_optpage_data_personal';
180  $optpage_loadhook = 'optpage_loadhook_personal';
181  break;
182  case SMOPT_PAGE_DISPLAY:
183  $optpage_name = _("Display Preferences");
184  $optpage_file = SM_PATH . 'include/options/display.php';
185  $optpage_loader = 'load_optpage_data_display';
186  $optpage_loadhook = 'optpage_loadhook_display';
187  break;
189  $optpage_name = _("Message Highlighting");
190  $optpage_file = SM_PATH . 'include/options/highlight.php';
191  $optpage_loader = 'load_optpage_data_highlight';
192  $optpage_loadhook = 'optpage_loadhook_highlight';
193  break;
194  case SMOPT_PAGE_FOLDER:
195  $optpage_name = _("Folder Preferences");
196  $optpage_file = SM_PATH . 'include/options/folder.php';
197  $optpage_loader = 'load_optpage_data_folder';
198  $optpage_loadhook = 'optpage_loadhook_folder';
199  break;
200  case SMOPT_PAGE_ORDER:
201  $optpage_name = _("Index Order");
202  $optpage_file = SM_PATH . 'include/options/order.php';
203  $optpage_loader = 'load_optpage_data_order';
204  $optpage_loadhook = 'optpage_loadhook_order';
205  break;
206  default: do_hook('optpage_set_loadinfo');
207 }
208 
209 /**********************************************************/
210 /*** Second, load the option information for this page. ***/
211 /**********************************************************/
212 
213 if ( !@is_file( $optpage_file ) ) {
214  $optpage = SMOPT_PAGE_MAIN;
215 } else if ($optpage != SMOPT_PAGE_MAIN ) {
216  /* Include the file for this optionpage. */
217 
218  require_once($optpage_file);
219 
220  /* Assemble the data for this option page. */
221  $optpage_data = array();
222  $optpage_data = $optpage_loader();
223  do_hook($optpage_loadhook);
224  $optpage_data['options'] =
225  create_option_groups($optpage_data['grps'], $optpage_data['vals']);
226 }
227 
228 /***********************************************************/
229 /*** Next, process anything that needs to be processed. ***/
230 /***********************************************************/
231 
232 // security check before saving anything...
233 //FIXME: what about SMOPT_MODE_LINK??
234 if ($optmode == SMOPT_MODE_SUBMIT) {
235  sm_validate_security_token($submitted_token, 3600, TRUE);
236 }
237 
238 // set empty error message
240 
241 if ( isset( $optpage_data ) ) {
242  switch ($optmode) {
243  case SMOPT_MODE_SUBMIT:
244  $max_refresh = process_optionmode_submit($optpage, $optpage_data);
245  break;
246  case SMOPT_MODE_LINK:
247  $max_refresh = process_optionmode_link($optpage, $optpage_data);
248  break;
249  }
250 }
251 
252 $optpage_title = _("Options");
253 if (isset($optpage_name) && ($optpage_name != '')) {
254  $optpage_title .= " - $optpage_name";
255 }
256 
257 /*******************************************************************/
258 /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
259 /*******************************************************************/
260 
261 /* If in submit mode, select a save hook name and run it. */
262 if ($optmode == SMOPT_MODE_SUBMIT) {
263  /* Select a save hook name. */
264  switch ($optpage) {
265  case SMOPT_PAGE_PERSONAL:
266  $save_hook_name = 'options_personal_save';
267  break;
268  case SMOPT_PAGE_DISPLAY:
269  $save_hook_name = 'options_display_save';
270  break;
271  case SMOPT_PAGE_FOLDER:
272  $save_hook_name = 'options_folder_save';
273  break;
274  default:
275  $save_hook_name = 'options_save';
276  break;
277  }
278 
279  /* Run the options save hook. */
280  do_hook($save_hook_name);
281 }
282 
283 /***************************************************************/
284 /* Apply logic to decide what optpage we want to display next. */
285 /***************************************************************/
286 
287 /* If this is the result of an option page being submitted, then */
288 /* show the main page. Otherwise, show whatever page was called. */
289 
290 if ($optmode == SMOPT_MODE_SUBMIT) {
291  $optpage = SMOPT_PAGE_MAIN;
292  $optpage_title = _("Options");
293 }
294 
295 /***************************************************************/
296 /* Finally, display whatever page we are supposed to show now. */
297 /***************************************************************/
298 
299 displayPageHeader($color, 'None', (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
300 
301 echo html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . "\n" .
302  html_tag( 'tr' ) . "\n" .
303  html_tag( 'td', '', 'center' ) .
304  "<b>$optpage_title</b><br />\n".
305  html_tag( 'table', '', '', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . "\n" .
306  html_tag( 'tr' ) . "\n" .
307  html_tag( 'td', '', 'center', $color[4] ) . "\n";
308 
309 /*
310  * The main option page has a different layout then the rest of the option
311  * pages. Therefore, we create it here first, then the others below.
312  */
313 if ($optpage == SMOPT_PAGE_MAIN) {
314  /**********************************************************/
315  /* First, display the results of a submission, if needed. */
316  /**********************************************************/
317  if ($optmode == SMOPT_MODE_SUBMIT) {
318  if (!isset($frame_top)) {
319  $frame_top = '_top';
320  }
321 
322  if (isset($optpage_save_error) && $optpage_save_error!=array()) {
323  echo "<font color=\"$color[2]\"><b>" . _("Error(s) occurred while saving your options") . "</b></font><br />\n";
324  echo "<ul>\n";
325  foreach ($optpage_save_error as $error_message) {
326  echo '<li><small>' . $error_message . "</small></li>\n";
327  }
328  echo "</ul>\n";
329  echo '<b>' . _("Some of your preference changes were not applied.") . "</b><br />\n";
330  } else {
331  /* Display a message indicating a successful save. */
332  // i18n: The %s represents the name of the option page saving the options
333  echo '<b>' . sprintf(_("Successfully Saved Options: %s"), $optpage_name) . "</b><br />\n";
334  }
335 
336  /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
337  if ( !isset( $max_refresh ) ) {
338  } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST) {
339  echo '<a href="../src/left_main.php" target="left">' . _("Refresh Folder List") . '</a><br />';
340  } else if ($max_refresh) {
341  echo '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _("Refresh Page") . '</a><br />';
342  }
343  }
344  /******************************************/
345  /* Build our array of Option Page Blocks. */
346  /******************************************/
347  $optpage_blocks = array();
348 
349  /* Build a section for Personal Options. */
350  $optpage_blocks[] = array(
351  'name' => _("Personal Information"),
352  'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL,
353  'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
354  'js' => false
355  );
356 
357  /* Build a section for Display Options. */
358  $optpage_blocks[] = array(
359  'name' => _("Display Preferences"),
360  'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY,
361  'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
362  'js' => false
363  );
364 
365  /* Build a section for Message Highlighting Options. */
366  $optpage_blocks[] = array(
367  'name' =>_("Message Highlighting"),
368  'url' => 'options_highlight.php',
369  '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."),
370  'js' => false
371  );
372 
373  /* Build a section for Folder Options. */
374  $optpage_blocks[] = array(
375  'name' => _("Folder Preferences"),
376  'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER,
377  'desc' => _("These settings change the way your folders are displayed and manipulated."),
378  'js' => false
379  );
380 
381  /* Build a section for Index Order Options. */
382  $optpage_blocks[] = array(
383  'name' => _("Index Order"),
384  'url' => 'options_order.php',
385  'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
386  'js' => false
387  );
388 
389  /* Build a section for plugins wanting to register an optionpage. */
390  do_hook('optpage_register_block');
391 
392  /*****************************************************/
393  /* Let's sort Javascript Option Pages to the bottom. */
394  /*****************************************************/
395  $js_optpage_blocks = array();
396  $reg_optpage_blocks = array();
397  foreach ($optpage_blocks as $cur_optpage) {
398  if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
399  $reg_optpage_blocks[] = $cur_optpage;
400  } else if ($javascript_on == SMPREF_JS_ON) {
401  $js_optpage_blocks[] = $cur_optpage;
402  }
403  }
404  $optpage_blocks = array_merge($reg_optpage_blocks, $js_optpage_blocks);
405 
406  /********************************************/
407  /* Now, print out each option page section. */
408  /********************************************/
409  $first_optpage = false;
410  echo html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="0" cellspacing="5" border="0"' ) . "\n" .
411  html_tag( 'tr' ) . "\n" .
412  html_tag( 'td', '', 'left', '', 'valign="top"' ) .
413  html_tag( 'table', '', '', $color[4], 'width="100%" cellpadding="3" cellspacing="0" border="0"' ) . "\n" .
414  html_tag( 'tr' ) . "\n" .
415  html_tag( 'td', '', 'left' );
416  foreach ($optpage_blocks as $next_optpage) {
417  if ($first_optpage == false) {
418  $first_optpage = $next_optpage;
419  } else {
420  print_optionpages_row($first_optpage, $next_optpage);
421  $first_optpage = false;
422  }
423  }
424 
425  if ($first_optpage != false) {
426  print_optionpages_row($first_optpage);
427  }
428 
429  echo "</td></tr></table></td></tr></table>\n";
430 
431  do_hook('options_link_and_description');
432 
433 
434 /*************************************************************************/
435 /* If we are not looking at the main option page, display the page here. */
436 /*************************************************************************/
437 } else {
438  echo addForm('options.php', 'POST', 'f', '', '', '', TRUE)
439  . create_optpage_element($optpage)
441  . html_tag( 'table', '', '', '', 'width="100%" cellpadding="2" cellspacing="0" border="0"' ) . "\n"
442  . html_tag( 'tr' ) . "\n"
443  . html_tag( 'td', '', 'left' ) . "\n";
444 
445  /* Output the option groups for this page. */
446  print_option_groups($optpage_data['options']);
447 
448  /* Set the inside_hook_name and submit_name. */
449  switch ($optpage) {
450  case SMOPT_PAGE_PERSONAL:
451  $inside_hook_name = 'options_personal_inside';
452  $bottom_hook_name = 'options_personal_bottom';
453  $submit_name = 'submit_personal';
454  break;
455  case SMOPT_PAGE_DISPLAY:
456  $inside_hook_name = 'options_display_inside';
457  $bottom_hook_name = 'options_display_bottom';
458  $submit_name = 'submit_display';
459  break;
461  $inside_hook_name = 'options_highlight_inside';
462  $bottom_hook_name = 'options_highlight_bottom';
463  $submit_name = 'submit_highlight';
464  break;
465  case SMOPT_PAGE_FOLDER:
466  $inside_hook_name = 'options_folder_inside';
467  $bottom_hook_name = 'options_folder_bottom';
468  $submit_name = 'submit_folder';
469  break;
470  case SMOPT_PAGE_ORDER:
471  $inside_hook_name = 'options_order_inside';
472  $bottom_hook_name = 'options_order_bottom';
473  $submit_name = 'submit_order';
474  break;
475  default:
476  $inside_hook_name = '';
477  $bottom_hook_name = '';
478  $submit_name = 'submit';
479  }
480 
481  /* If it is not empty, trigger the inside hook. */
482  if ($inside_hook_name != '') {
483  do_hook($inside_hook_name);
484  }
485 
486  /* Spit out a submit button. */
487  OptionSubmit($submit_name);
488  echo '</td></tr></table></form>';
489 
490  /* If it is not empty, trigger the bottom hook. */
491  if ($bottom_hook_name != '') {
492  do_hook($bottom_hook_name);
493  }
494 }
495 ?>
496 </td></tr>
497 </table>
498 </td></tr>
499 </table>
500 </body></html>
SMOPT_PAGE_HIGHLIGHT
const SMOPT_PAGE_HIGHLIGHT
Definition: options.php:46
SMOPT_MODE_LINK
const SMOPT_MODE_LINK
Definition: options.php:41
$optpage_file
$optpage_file
Definition: options.php:169
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$optpage_title
if(isset( $optpage_data)) $optpage_title
Definition: options.php:252
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
$frame_top
$frame_top
Definition: config_default.php:84
SM_PATH
const SM_PATH
Definition: options.php:222
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$optpage_name
if(!isset($optmode)) $optpage_name
Definition: options.php:168
process_optionmode_link
process_optionmode_link($optpage)
Definition: options.php:87
displayPageHeader
displayPageHeader($color, $mailbox, $xtra='', $session=false)
Definition: page_header.php:105
SMOPT_MODE_DISPLAY
const SMOPT_MODE_DISPLAY
Definition: options.php:39
SMOPT_PAGE_FOLDER
const SMOPT_PAGE_FOLDER
Definition: options.php:47
$optpage_loader
$optpage_loader
Definition: options.php:170
addForm
addForm($action, $method='post', $name='', $enctype='', $charset='', $extra='', $add_token=FALSE)
Definition: forms.php:150
SMOPT_REFRESH_FOLDERLIST
const SMOPT_REFRESH_FOLDERLIST
Definition: options.php:45
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
html
Definition: html.class.php:18
SMPREF_JS_ON
const SMPREF_JS_ON
Definition: constants.php:53
print_optionpages_row
print_optionpages_row($leftopt, $rightopt=false)
Definition: options.php:95
do_hook
do_hook($name)
Definition: plugin.php:42
sm_validate_security_token
sm_validate_security_token($token, $validity_period=0, $show_error=FALSE)
Definition: strings.php:1405
create_optmode_element
create_optmode_element($optmode)
Definition: options.php:940
SMOPT_PAGE_MAIN
const SMOPT_PAGE_MAIN
Definition: options.php:43
OptionSubmit
OptionSubmit( $name)
Definition: options.php:1100
create_optpage_element
create_optpage_element($optpage)
Definition: options.php:936
process_optionmode_submit
process_optionmode_submit($optpage, $optpage_data)
Definition: options.php:63
SQ_POST
const SQ_POST
Definition: global.php:17
SMOPT_MODE_SUBMIT
const SMOPT_MODE_SUBMIT
Definition: options.php:40
$optpage_save_error
switch($optpage) if(! @is_file( $optpage_file)) else if($optpage !=SMOPT_PAGE_MAIN) if($optmode==SMOPT_MODE_SUBMIT) $optpage_save_error
Definition: options.php:239
_
_($str)
Definition: gettext.php:160
print_option_groups
print_option_groups($option_groups)
Definition: options.php:1046
SMOPT_REFRESH_NONE
const SMOPT_REFRESH_NONE
Definition: options.php:44
SQ_FORM
const SQ_FORM
Definition: global.php:21
SMOPT_PAGE_DISPLAY
const SMOPT_PAGE_DISPLAY
Definition: options.php:45
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
SMOPT_PAGE_ORDER
const SMOPT_PAGE_ORDER
Definition: options.php:48
$color
global $color
Definition: options.php:19
create_option_groups
create_option_groups($optgrps, $optvals)
Definition: options.php:951
$username
global $username
Definition: options.php:225
SMOPT_PAGE_PERSONAL
const SMOPT_PAGE_PERSONAL
Definition: options.php:44
$javascript_on
$javascript_on
Definition: load_prefs.php:270