Source for file options.php

Documentation is available at 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 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: options.php 14840 2020-01-07 07:42:38Z pdontthink $
  12.  * @package squirrelmail
  13.  * @subpackage prefs
  14.  */
  15.  
  16. /** This is the options page */
  17. define('PAGE_NAME''options');
  18.  
  19. /**
  20.  * Path for SquirrelMail required files.
  21.  * @ignore
  22.  */
  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.  
  50. /**
  51.   * Save submitted options and calculate the most
  52.   * we need to refresh the page
  53.   *
  54.   * @param string $optpage      The name of the page being submitted
  55.   * @param array  $optpage_data An array of all the submitted options
  56.   *
  57.   * @return int The highest level of screen refresh needed per
  58.   *              the options that were changed.  This value will
  59.   *              correspond to the SMOPT_REFRESH_* constants found
  60.   *              in functions/options.php.
  61.   *
  62.   */
  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.  
  92. /**
  93.  * This function prints out an option page row.
  94.  */
  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_dataSQ_POST);
  146. if (!sqgetGlobalVar('smtoken',$submitted_tokenSQ_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. */
  168. $optpage_name '';
  169. $optpage_file '';
  170. $optpage_loader '';
  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;
  188.     case SMOPT_PAGE_HIGHLIGHT:
  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.     defaultdo_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-1TRUE);
  236. }
  237.  
  238. // set empty error message
  239. $optpage_save_error=array();
  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)
  440.        . html_tag'table''''''''width="100%" cellpadding="2" cellspacing="0" border="0"' "\n"
  441.        . html_tag'tr' "\n"
  442.        . html_tag'td''''left' "\n";
  443.  
  444.     /* Output the option groups for this page. */
  445.     print_option_groups($optpage_data['options']);
  446.  
  447.     /* Set the inside_hook_name and submit_name. */
  448.     switch ($optpage{
  449.         case SMOPT_PAGE_PERSONAL:
  450.             $inside_hook_name 'options_personal_inside';
  451.             $bottom_hook_name 'options_personal_bottom';
  452.             $submit_name 'submit_personal';
  453.             break;
  454.         case SMOPT_PAGE_DISPLAY:
  455.             $inside_hook_name 'options_display_inside';
  456.             $bottom_hook_name 'options_display_bottom';
  457.             $submit_name 'submit_display';
  458.             break;
  459.         case SMOPT_PAGE_HIGHLIGHT:
  460.             $inside_hook_name 'options_highlight_inside';
  461.             $bottom_hook_name 'options_highlight_bottom';
  462.             $submit_name 'submit_highlight';
  463.             break;
  464.         case SMOPT_PAGE_FOLDER:
  465.             $inside_hook_name 'options_folder_inside';
  466.             $bottom_hook_name 'options_folder_bottom';
  467.             $submit_name 'submit_folder';
  468.             break;
  469.         case SMOPT_PAGE_ORDER:
  470.             $inside_hook_name 'options_order_inside';
  471.             $bottom_hook_name 'options_order_bottom';
  472.             $submit_name 'submit_order';
  473.             break;
  474.         default:
  475.             $inside_hook_name '';
  476.             $bottom_hook_name 'options_generic_bottom';
  477.             $submit_name 'submit';
  478.     }
  479.  
  480.     /* If it is not empty, trigger the inside hook. */
  481.     if ($inside_hook_name != ''{
  482.         do_hook($inside_hook_name);    
  483.     }
  484.  
  485.     /* Spit out a submit button. */
  486.     OptionSubmit($submit_name);
  487.     echo '</td></tr></table></form>';
  488.  
  489.     /* If it is not empty, trigger the bottom hook. */
  490.     if ($bottom_hook_name != ''{
  491.         do_hook($bottom_hook_name);    
  492.     }
  493. }
  494. ?>
  495. </td></tr>
  496. </table>
  497. </td></tr>
  498. </table>
  499. </body></html>

Documentation generated on Mon, 13 Jan 2020 04:25:07 +0100 by phpDocumentor 1.4.3