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 14845 2020-01-07 08:09:34Z pdontthink $
  12.  * @package squirrelmail
  13.  * @subpackage prefs
  14.  */
  15.  
  16. /** This is the options page */
  17. define('PAGE_NAME''options');
  18.  
  19. /**
  20.  * Include the SquirrelMail initialization file.
  21.  */
  22. require('../include/init.php');
  23.  
  24. /* SquirrelMail required files. */
  25.  
  26. //include(SM_PATH . 'functions/imap_general.php');
  27. require_once(SM_PATH 'functions/options.php');
  28. require_once(SM_PATH 'functions/forms.php');
  29.  
  30. /*********************************/
  31. /*** Build the resultant page. ***/
  32. /*********************************/
  33.  
  34. define('SMOPT_MODE_DISPLAY''display');
  35. define('SMOPT_MODE_SUBMIT''submit');
  36. define('SMOPT_MODE_LINK''link');
  37.  
  38. define('SMOPT_PAGE_MAIN''main');
  39. define('SMOPT_PAGE_PERSONAL''personal');
  40. define('SMOPT_PAGE_DISPLAY''display');
  41. define('SMOPT_PAGE_COMPOSE''compose');
  42. define('SMOPT_PAGE_ACCESSIBILITY''accessibility');
  43. define('SMOPT_PAGE_HIGHLIGHT''highlight');
  44. define('SMOPT_PAGE_FOLDER''folder');
  45. define('SMOPT_PAGE_ORDER''order');
  46.  
  47. /**
  48.   * Save submitted options and calculate the most
  49.   * we need to refresh the page
  50.   *
  51.   * @param string $optpage      The name of the page being submitted
  52.   * @param array  $optpage_data An array of all the submitted options
  53.   *
  54.   * @return int The highest level of screen refresh needed per
  55.   *              the options that were changed.  This value will
  56.   *              correspond to the SMOPT_REFRESH_* constants found
  57.   *              in functions/options.php.
  58.   *
  59.   */
  60. function process_optionmode_submit($optpage$optpage_data{
  61.     /* Initialize the maximum option refresh level. */
  62.     $max_refresh SMOPT_REFRESH_NONE;
  63.  
  64.         
  65.  
  66.     /* Save each option in each option group. */
  67.     foreach ($optpage_data['options'as $option_grp{
  68.         foreach ($option_grp['options'as $option{
  69.     
  70.             /* Special case: need to make sure emailaddress
  71.              * is saved if we use it as a test for ask_user_info */
  72.             global $ask_user_info;
  73.             if $optpage SMOPT_PAGE_PERSONAL && $ask_user_info &&
  74.                 $option->name == 'email_address' {
  75.                 $option->setValue('');
  76.             }
  77.             
  78.             /* Remove Debug Mode Until Needed
  79.             echo "name = '$option->name', "
  80.                . "value = '$option->value', "
  81.                . "new_value = '$option->new_value'\n";
  82. //FIXME: NO HTML IN THE CORE!
  83.             echo "<br />";
  84.             */
  85.             if ($option->changed()) {
  86.                 $option->save();
  87.                 $max_refresh max($max_refresh$option->refresh_level);
  88.             }
  89.         }
  90.     }
  91.  
  92.     /* Return the max refresh level. */
  93.     return ($max_refresh);
  94. }
  95.  
  96. function process_optionmode_link($optpage{
  97.    /* There will be something here, later. */
  98. }
  99.  
  100.  
  101.  
  102. /* ---------------------------- main ---------------------------- */
  103.  
  104. /* get the globals that we may need */
  105. sqgetGlobalVar('optpage',     $optpage);
  106. sqgetGlobalVar('optmode',     $optmode,         SQ_FORM);
  107. sqgetGlobalVar('optpage_data',$optpage_data,    SQ_POST);
  108. sqgetGlobalVar('smtoken',     $submitted_tokenSQ_FORM'');
  109. /* end of getting globals */
  110.  
  111. /* Make sure we have an Option Page set. Default to main. */
  112. if !isset($optpage|| $optpage == '' {
  113.     $optpage SMOPT_PAGE_MAIN;
  114. else {
  115.     $optpage strip_tags$optpage );
  116. }
  117.  
  118. /* Make sure we have an Option Mode set. Default to display. */
  119. if (!isset($optmode)) {
  120.     $optmode SMOPT_MODE_DISPLAY;
  121. }
  122.  
  123. /*
  124.  * First, set the load information for each option page.
  125.  */
  126.  
  127. /* Initialize load information variables. */
  128. $optpage_name '';
  129. $optpage_file '';
  130. $optpage_loader '';
  131.  
  132. /* Set the load information for each page. */
  133. switch ($optpage{
  134.     case SMOPT_PAGE_MAIN:
  135.         break;
  136.     case SMOPT_PAGE_PERSONAL:
  137.         $optpage_name     _("Personal Information");
  138.         $optpage_file     SM_PATH 'include/options/personal.php';
  139.         $optpage_loader   'load_optpage_data_personal';
  140.         $optpage_loadhook 'optpage_loadhook_personal';
  141.         break;
  142.     case SMOPT_PAGE_DISPLAY:
  143.         $optpage_name   _("Display Preferences");
  144.         $optpage_file   SM_PATH 'include/options/display.php';
  145.         $optpage_loader 'load_optpage_data_display';
  146.         $optpage_loadhook 'optpage_loadhook_display';
  147.         break;
  148.     case SMOPT_PAGE_COMPOSE:
  149.         $optpage_name   _("Compose Preferences");
  150.         $optpage_file   SM_PATH 'include/options/compose.php';
  151.         $optpage_loader 'load_optpage_data_compose';
  152.         $optpage_loadhook 'optpage_loadhook_compose';
  153.         break;
  154.         $optpage_name   _("Accessibility Preferences");
  155.         $optpage_file   SM_PATH 'include/options/accessibility.php';
  156.         $optpage_loader 'load_optpage_data_accessibility';
  157.         $optpage_loadhook 'optpage_loadhook_accessibility';
  158.         break;
  159.     case SMOPT_PAGE_HIGHLIGHT:
  160.         $optpage_name   _("Message Highlighting");
  161.         $optpage_file   SM_PATH 'include/options/highlight.php';
  162.         $optpage_loader 'load_optpage_data_highlight';
  163.         $optpage_loadhook 'optpage_loadhook_highlight';
  164.         break;
  165.     case SMOPT_PAGE_FOLDER:
  166.         $optpage_name   _("Folder Preferences");
  167.         $optpage_file   SM_PATH 'include/options/folder.php';
  168.         $optpage_loader 'load_optpage_data_folder';
  169.         $optpage_loadhook 'optpage_loadhook_folder';
  170.         break;
  171.     case SMOPT_PAGE_ORDER:
  172.         $optpage_name _("Index Order");
  173.         $optpage_file SM_PATH 'include/options/order.php';
  174.         $optpage_loader 'load_optpage_data_order';
  175.         $optpage_loadhook 'optpage_loadhook_order';
  176.         break;
  177.     defaultdo_hook('optpage_set_loadinfo'$null);
  178. }
  179.  
  180. /**********************************************************/
  181. /*** Second, load the option information for this page. ***/
  182. /**********************************************************/
  183.  
  184. if !@is_file$optpage_file ) ) {
  185.     $optpage SMOPT_PAGE_MAIN;
  186. elseif ($optpage != SMOPT_PAGE_MAIN {
  187.     /* Include the file for this optionpage. */
  188.  
  189.     require_once($optpage_file);
  190.  
  191.     /* Assemble the data for this option page. */
  192.     $optpage_data array();
  193.     $optpage_data $optpage_loader();
  194.     do_hook($optpage_loadhook$null);
  195.     $optpage_data['options'create_option_groups($optpage_data['grps']$optpage_data['vals']);
  196. }
  197.  
  198. /***********************************************************/
  199. /*** Next, process anything that needs to be processed. ***/
  200. /***********************************************************/
  201.  
  202. // security check before saving anything...
  203. //FIXME: what about SMOPT_MODE_LINK??
  204. if ($optmode == SMOPT_MODE_SUBMIT{
  205.    sm_validate_security_token($submitted_token-1TRUE);
  206. }
  207.  
  208. $optpage_save_error=array();
  209.  
  210. if isset$optpage_data ) ) {
  211.     switch ($optmode{
  212.         case SMOPT_MODE_SUBMIT:
  213.             $max_refresh process_optionmode_submit($optpage$optpage_data);
  214.             break;
  215.         case SMOPT_MODE_LINK:
  216.             $max_refresh process_optionmode_link($optpage$optpage_data);
  217.             break;
  218.     }
  219. }
  220.  
  221. $optpage_title _("Options");
  222. if (isset($optpage_name&& ($optpage_name != '')) {
  223.     $optpage_title .= " - $optpage_name";
  224. }
  225.  
  226. /*******************************************************************/
  227. /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
  228. /*******************************************************************/
  229.  
  230. //FIXME: let's remove these finally in 1.5.2..... but first, are there any plugins using them?
  231. /* If in submit mode, select a save hook name and run it. */
  232. if ($optmode == SMOPT_MODE_SUBMIT{
  233.     /* Select a save hook name. */
  234.     switch ($optpage{
  235.         case SMOPT_PAGE_PERSONAL:
  236.             $save_hook_name 'options_personal_save';
  237.             break;
  238.         case SMOPT_PAGE_DISPLAY:
  239.             $save_hook_name 'options_display_save';
  240.             break;
  241.         case SMOPT_PAGE_COMPOSE:
  242.             $save_hook_name 'options_compose_save';
  243.             break;
  244.         case SMOPT_PAGE_ACCESSIBILITY:
  245.             $save_hook_name 'options_accessibility_save';
  246.             break;
  247.         case SMOPT_PAGE_FOLDER:
  248.             $save_hook_name 'options_folder_save';
  249.             break;
  250.         default:
  251.             $save_hook_name 'options_save';
  252.             break;
  253.     }
  254.  
  255.     /* Run the options save hook. */
  256.     do_hook($save_hook_name$null);
  257. }
  258.  
  259. /***************************************************************/
  260. /* Apply logic to decide what optpage we want to display next. */
  261. /***************************************************************/
  262.  
  263. /* If this is the result of an option page being submitted, then */
  264. /* show the main page. Otherwise, show whatever page was called. */
  265.  
  266. if ($optmode == SMOPT_MODE_SUBMIT{
  267.     $optpage SMOPT_PAGE_MAIN;
  268.     $optpage_title _("Options");
  269. }
  270.  
  271. /***************************************************************/
  272. /* Finally, display whatever page we are supposed to show now. */
  273. /***************************************************************/
  274.  
  275. displayPageHeader($colornull(isset($optpage_data['xtra']$optpage_data['xtra'''));
  276.  
  277. /*
  278.  * The main option page has a different layout then the rest of the option
  279.  * pages. Therefore, we create it here first, then the others below.
  280.  */
  281. if ($optpage == SMOPT_PAGE_MAIN{
  282.     /**********************************************************/
  283.     /* First, display the results of a submission, if needed. */
  284.     /**********************************************************/
  285.     $notice '';
  286.     if ($optmode == SMOPT_MODE_SUBMIT{
  287.         if (!isset($frame_top)) {
  288.             $frame_top '_top';
  289.         }
  290.  
  291.         if (isset($optpage_save_error&& $optpage_save_error!=array()) {
  292. //FIXME: REMOVE HTML FROM CORE
  293.             $notice _("Error(s) occurred while saving your options""<br />\n<ul>\n";
  294.             foreach ($optpage_save_error as $error_message{
  295.                 $notice.= '<li><small>' $error_message "</small></li>\n";
  296.             }
  297.             $notice.= "</ul>\n" _("Some of your preference changes were not applied.""\n";
  298.         else {
  299.             /* Display a message indicating a successful save. */
  300.             // i18n: The %s represents the name of the option page saving the options
  301.             $notice sprintf(_("Successfully Saved Options: %s")$optpage_name"<br />\n";
  302.         }
  303.  
  304.         /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
  305.         if !isset$max_refresh ) ) {
  306.         else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST{
  307. //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the folder list is in a separate sibling frame under the same parent, and it is called "left"
  308.             if (checkForJavascript()) {
  309.                 $notice .= sprintf(_("Folder list should automatically %srefresh%s.")'<a href="../src/left_main.php" target="left">''</a>''<br /><script type="text/javascript">' "\n<!--\nparent.left.location = '../src/left_main.php';\n// -->\n</script>\n";
  310.             else {
  311.                 $notice .= '<a href="../src/left_main.php" target="left">' _("Refresh Folder List"'</a><br />';
  312.             }
  313.         else if ($max_refresh{
  314.             if (checkForJavascript()) {
  315. //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the parent is the top-most SM frame and is what should be refreshed with webmail.php
  316.                 $notice .= sprintf(_("This page should automatically %srefresh%s.")'<a href="../src/webmail.php?right_frame=options.php" target="' $frame_top '">''</a>''<br /><script type="text/javascript">' "\n<!--\nparent.location = '../src/webmail.php?right_frame=options.php';\n// -->\n</script>\n";
  317.             else {
  318.                 $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' $frame_top '">' _("Refresh Page"'</a><br />';
  319.             }
  320.         }
  321.     }
  322.     
  323.     if (!empty($notice)) {
  324.         $oTemplate->assign('note'$notice);
  325.         $oTemplate->display('note.tpl');
  326.     }
  327.     
  328.     /******************************************/
  329.     /* Build our array of Option Page Blocks. */
  330.     /******************************************/
  331.     $optpage_blocks array();
  332.  
  333.     // access keys...
  334.     global $accesskey_options_personal$accesskey_options_display,
  335.            $accesskey_options_highlighting$accesskey_options_folders,
  336.            $accesskey_options_index_order$accesskey_options_compose,
  337.            $accesskey_options_accessibility;
  338.  
  339.     /* Build a section for Personal Options. */
  340.     $optpage_blocks[array(
  341.         'name'      => _("Personal Information"),
  342.         'url'       => 'options.php?optpage=' SMOPT_PAGE_PERSONAL,
  343.         'desc'      => _("This contains personal information about yourself such as your name, your email address, etc."),
  344.         'js'        => false,
  345.         'accesskey' => $accesskey_options_personal,
  346.     );
  347.  
  348.     /* Build a section for Display Options. */
  349.     $optpage_blocks[array(
  350.         'name'      => _("Display Preferences"),
  351.         'url'       => 'options.php?optpage=' SMOPT_PAGE_DISPLAY,
  352.         'desc'      => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
  353.         'js'        => false,
  354.         'accesskey' => $accesskey_options_display,
  355.     );
  356.  
  357.     /* Build a section for Message Highlighting Options. */
  358.     $optpage_blocks[array(
  359.         'name'      =>_("Message Highlighting"),
  360.         'url'       => 'options_highlight.php',
  361.         '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."),
  362.         'js'        => false,
  363.         'accesskey' => $accesskey_options_highlighting,
  364.     );
  365.  
  366.     /* Build a section for Folder Options. */
  367.     $optpage_blocks[array(
  368.         'name'      => _("Folder Preferences"),
  369.         'url'       => 'options.php?optpage=' SMOPT_PAGE_FOLDER,
  370.         'desc'      => _("These settings change the way your folders are displayed and manipulated."),
  371.         'js'        => false,
  372.         'accesskey' => $accesskey_options_folders,
  373.     );
  374.  
  375.     /* Build a section for Index Order Options. */
  376.     $optpage_blocks[array(
  377.         'name'      => _("Index Order"),
  378.         'url'       => 'options_order.php',
  379.         'desc'      => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
  380.         'js'        => false,
  381.         'accesskey' => $accesskey_options_index_order,
  382.     );
  383.  
  384.     /* Build a section for Compose Options. */
  385.     $optpage_blocks[array(
  386.         'name'      => _("Compose Preferences"),
  387.         'url'       => 'options.php?optpage=' SMOPT_PAGE_COMPOSE,
  388.         'desc'      => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
  389.         'js'        => false,
  390.         'accesskey' => $accesskey_options_compose,
  391.     );
  392.  
  393.     /* Build a section for Accessibility Options. */
  394.     $optpage_blocks[array(
  395.         'name'      => _("Accessibility Preferences"),
  396.         'url'       => 'options.php?optpage=' SMOPT_PAGE_ACCESSIBILITY,
  397.         'desc'      => _("You can configure features that improve interface usability."),
  398.         'js'        => false,
  399.         'accesskey' => $accesskey_options_accessibility,
  400.     );
  401.  
  402.     /* Build a section for plugins wanting to register an optionpage. */
  403.     do_hook('optpage_register_block'$null);
  404.  
  405.     /*****************************************************/
  406.     /* Let's sort Javascript Option Pages to the bottom. */
  407.     /*****************************************************/
  408.     $js_optpage_blocks array();
  409.     $reg_optpage_blocks array();
  410.     foreach ($optpage_blocks as $cur_optpage{
  411.         if (!isset($cur_optpage['accesskey'])) {
  412.             $cur_optpage['accesskey''NONE';
  413.         }
  414.         if (!isset($cur_optpage['js']|| !$cur_optpage['js']{
  415.             $reg_optpage_blocks[$cur_optpage;
  416.         else if (checkForJavascript()) {
  417.             $js_optpage_blocks[$cur_optpage;
  418.         }
  419.     }
  420.     $optpage_blocks array_merge($reg_optpage_blocks$js_optpage_blocks);
  421.  
  422.     /********************************************/
  423.     /* Now, print out each option page section. */
  424.     /********************************************/
  425.     $oTemplate->assign('page_title'$optpage_title);
  426.     $oTemplate->assign('options'$optpage_blocks);
  427.  
  428.     $oTemplate->display('option_groups.tpl');
  429.     
  430.     do_hook('options_link_and_description'$null);
  431.  
  432.  
  433. /*************************************************************************/
  434. /* If we are not looking at the main option page, display the page here. */
  435. /*************************************************************************/
  436. else {
  437.     /* Set the bottom_hook_name and submit_name. */
  438.     switch ($optpage{
  439.         case SMOPT_PAGE_PERSONAL:
  440.             $bottom_hook_name 'options_personal_bottom';
  441.             $submit_name 'submit_personal';
  442.             break;
  443.         case SMOPT_PAGE_DISPLAY:
  444.             $bottom_hook_name 'options_display_bottom';
  445.             $submit_name 'submit_display';
  446.             break;
  447.         case SMOPT_PAGE_COMPOSE:
  448.             $bottom_hook_name 'options_compose_bottom';
  449.             $submit_name 'submit_compose';
  450.             break;
  451.         case SMOPT_PAGE_ACCESSIBILITY:
  452.             $bottom_hook_name 'options_accessibility_bottom';
  453.             $submit_name 'submit_accessibility';
  454.             break;
  455.         case SMOPT_PAGE_HIGHLIGHT:
  456.             $bottom_hook_name 'options_highlight_bottom';
  457.             $submit_name 'submit_highlight';
  458.             break;
  459.         case SMOPT_PAGE_FOLDER:
  460.             $bottom_hook_name 'options_folder_bottom';
  461.             $submit_name 'submit_folder';
  462.             break;
  463.         case SMOPT_PAGE_ORDER:
  464.             $bottom_hook_name 'options_order_bottom';
  465.             $submit_name 'submit_order';
  466.             break;
  467.         default:
  468.             $bottom_hook_name 'options_generic_bottom';
  469.             $submit_name 'submit';
  470.     }
  471.  
  472.     // Begin output form
  473.     echo addForm('options.php''post''option_form'''''array()TRUE)
  474.        . create_optpage_element($optpage)
  475.  
  476.     // This is the only variable that is needed by *just* the template.
  477.     $oTemplate->assign('option_groups'$optpage_data['options']);
  478.     
  479.     global $ask_user_info$org_name;
  480.     if $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info
  481.             && getPref($data_dir$username,'email_address'== "" {
  482.         $oTemplate->assign('topmessage',
  483.             sprintf(_("Welcome to %s. Please supply your full name and email address.")$org_name) );
  484.     }
  485.     
  486.     // These variables are not specifically needed by the template,
  487.     // but they are relevant to the page being built, so we'll add
  488.     // them in case some plugin is modifying the page, etc....
  489.     //
  490.     $oTemplate->assign('max_refresh'isset($max_refresh$max_refresh NULL);
  491.     $oTemplate->assign('page_title'$optpage_title);
  492.     $oTemplate->assign('optpage'$optpage);
  493.     $oTemplate->assign('optpage_name'$optpage_name);
  494.     $oTemplate->assign('optmode'$optmode);
  495.     $oTemplate->assign('optpage_data'$optpage_data);
  496.      
  497.     $oTemplate->assign('submit_name'$submit_name);
  498.     $oTemplate->display('options.tpl');
  499.  
  500.     $oTemplate->display('form_close.tpl');
  501.  
  502.     /* If it is not empty, trigger the bottom hook. */
  503.     if ($bottom_hook_name != ''{
  504.         do_hook($bottom_hook_name$null);
  505.     }
  506.     
  507. }
  508.  
  509. $oTemplate->display('footer.tpl');

Documentation generated on Mon, 13 Jan 2020 04:23:15 +0100 by phpDocumentor 1.4.3