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 &copy; 1999-2006 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: options.php,v 1.151 2006/08/17 19:35:27 stevetruckstuff Exp $
  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('optpage',     $optpage);
  77. sqgetGlobalVar('optmode',     $optmode,      SQ_FORM);
  78. sqgetGlobalVar('optpage_data',$optpage_dataSQ_POST);
  79. /* end of getting globals */
  80.  
  81. /* Make sure we have an Option Page set. Default to main. */
  82. if !isset($optpage|| $optpage == '' {
  83.     $optpage SMOPT_PAGE_MAIN;
  84. else {
  85.     $optpage strip_tags$optpage );
  86. }
  87.  
  88. /* Make sure we have an Option Mode set. Default to display. */
  89. if (!isset($optmode)) {
  90.     $optmode SMOPT_MODE_DISPLAY;
  91. }
  92.  
  93. /*
  94.  * First, set the load information for each option page.
  95.  */
  96.  
  97. /* Initialize load information variables. */
  98. $optpage_name '';
  99. $optpage_file '';
  100. $optpage_loader '';
  101.  
  102. /* Set the load information for each page. */
  103. switch ($optpage{
  104.     case SMOPT_PAGE_MAIN:
  105.         break;
  106.     case SMOPT_PAGE_PERSONAL:
  107.         $optpage_name     _("Personal Information");
  108.         $optpage_file     SM_PATH 'include/options/personal.php';
  109.         $optpage_loader   'load_optpage_data_personal';
  110.         $optpage_loadhook 'optpage_loadhook_personal';
  111.         break;
  112.     case SMOPT_PAGE_DISPLAY:
  113.         $optpage_name   _("Display Preferences");
  114.         $optpage_file   SM_PATH 'include/options/display.php';
  115.         $optpage_loader 'load_optpage_data_display';
  116.         $optpage_loadhook 'optpage_loadhook_display';
  117.         break;
  118.     case SMOPT_PAGE_COMPOSE:
  119.         $optpage_name   _("Compose Preferences");
  120.         $optpage_file   SM_PATH 'include/options/compose.php';
  121.         $optpage_loader 'load_optpage_data_compose';
  122.         $optpage_loadhook 'optpage_loadhook_compose';
  123.         break;
  124.     case SMOPT_PAGE_HIGHLIGHT:
  125.         $optpage_name   _("Message Highlighting");
  126.         $optpage_file   SM_PATH 'include/options/highlight.php';
  127.         $optpage_loader 'load_optpage_data_highlight';
  128.         $optpage_loadhook 'optpage_loadhook_highlight';
  129.         break;
  130.     case SMOPT_PAGE_FOLDER:
  131.         $optpage_name   _("Folder Preferences");
  132.         $optpage_file   SM_PATH 'include/options/folder.php';
  133.         $optpage_loader 'load_optpage_data_folder';
  134.         $optpage_loadhook 'optpage_loadhook_folder';
  135.         break;
  136.     case SMOPT_PAGE_ORDER:
  137.         $optpage_name _("Index Order");
  138.         $optpage_file SM_PATH 'include/options/order.php';
  139.         $optpage_loader 'load_optpage_data_order';
  140.         $optpage_loadhook 'optpage_loadhook_order';
  141.         break;
  142.     defaultdo_hook('optpage_set_loadinfo');
  143. }
  144.  
  145. /**********************************************************/
  146. /*** Second, load the option information for this page. ***/
  147. /**********************************************************/
  148.  
  149. if !@is_file$optpage_file ) ) {
  150.     $optpage SMOPT_PAGE_MAIN;
  151. elseif ($optpage != SMOPT_PAGE_MAIN {
  152.     /* Include the file for this optionpage. */
  153.  
  154.     require_once($optpage_file);
  155.  
  156.     /* Assemble the data for this option page. */
  157.     $optpage_data array();
  158.     $optpage_data $optpage_loader();
  159.     do_hook($optpage_loadhook);
  160.     $optpage_data['options'create_option_groups($optpage_data['grps']$optpage_data['vals']);
  161. }
  162.  
  163. /***********************************************************/
  164. /*** Next, process anything that needs to be processed. ***/
  165. /***********************************************************/
  166.  
  167. $optpage_save_error=array();
  168.  
  169. if isset$optpage_data ) ) {
  170.     switch ($optmode{
  171.         case SMOPT_MODE_SUBMIT:
  172.             $max_refresh process_optionmode_submit($optpage$optpage_data);
  173.             break;
  174.         case SMOPT_MODE_LINK:
  175.             $max_refresh process_optionmode_link($optpage$optpage_data);
  176.             break;
  177.     }
  178. }
  179.  
  180. $optpage_title _("Options");
  181. if (isset($optpage_name&& ($optpage_name != '')) {
  182.     $optpage_title .= " - $optpage_name";
  183. }
  184.  
  185. /*******************************************************************/
  186. /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
  187. /*******************************************************************/
  188.  
  189. /* If in submit mode, select a save hook name and run it. */
  190. if ($optmode == SMOPT_MODE_SUBMIT{
  191.     /* Select a save hook name. */
  192.     switch ($optpage{
  193.         case SMOPT_PAGE_PERSONAL:
  194.             $save_hook_name 'options_personal_save';
  195.             break;
  196.         case SMOPT_PAGE_DISPLAY:
  197.             $save_hook_name 'options_display_save';
  198.             break;
  199.         case SMOPT_PAGE_COMPOSE:
  200.             $save_hook_name 'options_compose_save';
  201.             break;
  202.         case SMOPT_PAGE_FOLDER:
  203.             $save_hook_name 'options_folder_save';
  204.             break;
  205.         default:
  206.             $save_hook_name 'options_save';
  207.             break;
  208.     }
  209.  
  210.     /* Run the options save hook. */
  211.     do_hook($save_hook_name);
  212. }
  213.  
  214. /***************************************************************/
  215. /* Apply logic to decide what optpage we want to display next. */
  216. /***************************************************************/
  217.  
  218. /* If this is the result of an option page being submitted, then */
  219. /* show the main page. Otherwise, show whatever page was called. */
  220.  
  221. if ($optmode == SMOPT_MODE_SUBMIT{
  222.     $optpage SMOPT_PAGE_MAIN;
  223. }
  224.  
  225. /***************************************************************/
  226. /* Finally, display whatever page we are supposed to show now. */
  227. /***************************************************************/
  228.  
  229. displayPageHeader($color'None'(isset($optpage_data['xtra']$optpage_data['xtra'''));
  230.  
  231. /*
  232.  * The main option page has a different layout then the rest of the option
  233.  * pages. Therefore, we create it here first, then the others below.
  234.  */
  235. if ($optpage == SMOPT_PAGE_MAIN{
  236.     /**********************************************************/
  237.     /* First, display the results of a submission, if needed. */
  238.     /**********************************************************/
  239.     $notice '';
  240.     if ($optmode == SMOPT_MODE_SUBMIT{
  241.         if (!isset($frame_top)) {
  242.             $frame_top '_top';
  243.         }
  244.  
  245.         if (isset($optpage_save_error&& $optpage_save_error!=array()) {
  246.             $notice _("Error(s) occurred while saving your options""<br />\n<ul>\n";
  247.             foreach ($optpage_save_error as $error_message{
  248.                 $notice.= '<li><small>' $error_message "</small></li>\n";
  249.             }
  250.             $notice.= "</ul>\n" _("Some of your preference changes were not applied.""\n";
  251.         else {
  252.             /* Display a message indicating a successful save. */
  253.             $notice _("Successfully Saved Options""$optpage_name</b><br />\n";
  254.         }
  255.  
  256.         /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
  257.         if !isset$max_refresh ) ) {
  258.         else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST{
  259.             $notice .= '<a href="../src/left_main.php" target="left">' _("Refresh Folder List"'</a><br />';
  260.         else if ($max_refresh{
  261.             $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' $frame_top '">' _("Refresh Page"'</a><br />';
  262.         }
  263.     }
  264.     
  265.     if (!empty($notice)) {
  266.         $oTemplate->assign('note'$notice);
  267.         $oTemplate->display('note.tpl');
  268.     }
  269.     
  270.     /******************************************/
  271.     /* Build our array of Option Page Blocks. */
  272.     /******************************************/
  273.     $optpage_blocks array();
  274.  
  275.     /* Build a section for Personal Options. */
  276.     $optpage_blocks[array(
  277.         'name' => _("Personal Information"),
  278.         'url'  => 'options.php?optpage=' SMOPT_PAGE_PERSONAL,
  279.         'desc' => _("This contains personal information about yourself such as your name, your email address, etc."),
  280.         'js'   => false
  281.     );
  282.  
  283.     /* Build a section for Display Options. */
  284.     $optpage_blocks[array(
  285.         'name' => _("Display Preferences"),
  286.         'url'  => 'options.php?optpage=' SMOPT_PAGE_DISPLAY,
  287.         'desc' => _("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
  288.         'js'   => false
  289.     );
  290.  
  291.     /* Build a section for Message Highlighting Options. */
  292.     $optpage_blocks[array(
  293.         'name' =>_("Message Highlighting"),
  294.         'url'  => 'options_highlight.php',
  295.         '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."),
  296.         'js'   => false
  297.     );
  298.  
  299.     /* Build a section for Folder Options. */
  300.     $optpage_blocks[array(
  301.         'name' => _("Folder Preferences"),
  302.         'url'  => 'options.php?optpage=' SMOPT_PAGE_FOLDER,
  303.         'desc' => _("These settings change the way your folders are displayed and manipulated."),
  304.         'js'   => false
  305.     );
  306.  
  307.     /* Build a section for Index Order Options. */
  308.     $optpage_blocks[array(
  309.         'name' => _("Index Order"),
  310.         'url'  => 'options_order.php',
  311.         'desc' => _("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
  312.         'js'   => false
  313.     );
  314.  
  315.     /* Build a section for Compose Options. */
  316.     $optpage_blocks[array(
  317.         'name' => _("Compose Preferences"),
  318.         'url'  => 'options.php?optpage=' SMOPT_PAGE_COMPOSE,
  319.         'desc' => _("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
  320.         'js'   => false
  321.     );
  322.  
  323.     /* Build a section for plugins wanting to register an optionpage. */
  324.     do_hook('optpage_register_block');
  325.  
  326.     /*****************************************************/
  327.     /* Let's sort Javascript Option Pages to the bottom. */
  328.     /*****************************************************/
  329.     $js_optpage_blocks array();
  330.     $reg_optpage_blocks array();
  331.     foreach ($optpage_blocks as $cur_optpage{
  332.         if (!isset($cur_optpage['js']|| !$cur_optpage['js']{
  333.             $reg_optpage_blocks[$cur_optpage;
  334.         else if ($javascript_on == SMPREF_JS_ON{
  335.             $js_optpage_blocks[$cur_optpage;
  336.         }
  337.     }
  338.     $optpage_blocks array_merge($reg_optpage_blocks$js_optpage_blocks);
  339.  
  340.     /********************************************/
  341.     /* Now, print out each option page section. */
  342.     /********************************************/
  343.     $oTemplate->assign('page_title'$optpage_title);
  344.     $oTemplate->assign('options'$optpage_blocks);
  345.  
  346.     $oTemplate->display('option_groups.tpl');
  347.     
  348.     do_hook('options_link_and_description');
  349.  
  350.  
  351. /*************************************************************************/
  352. /* If we are not looking at the main option page, display the page here. */
  353. /*************************************************************************/
  354. else {
  355.     /* Set the inside_hook_name and submit_name. */
  356.     switch ($optpage{
  357.         case SMOPT_PAGE_PERSONAL:
  358.             $inside_hook_name 'options_personal_inside';
  359.             $bottom_hook_name 'options_personal_bottom';
  360.             $submit_name 'submit_personal';
  361.             break;
  362.         case SMOPT_PAGE_DISPLAY:
  363.             $inside_hook_name 'options_display_inside';
  364.             $bottom_hook_name 'options_display_bottom';
  365.             $submit_name 'submit_display';
  366.             break;
  367.         case SMOPT_PAGE_COMPOSE:
  368.             $inside_hook_name 'options_compose_inside';
  369.             $bottom_hook_name 'options_compose_bottom';
  370.             $submit_name 'submit_compose';
  371.             break;
  372.         case SMOPT_PAGE_HIGHLIGHT:
  373.             $inside_hook_name 'options_highlight_inside';
  374.             $bottom_hook_name 'options_highlight_bottom';
  375.             $submit_name 'submit_highlight';
  376.             break;
  377.         case SMOPT_PAGE_FOLDER:
  378.             $inside_hook_name 'options_folder_inside';
  379.             $bottom_hook_name 'options_folder_bottom';
  380.             $submit_name 'submit_folder';
  381.             break;
  382.         case SMOPT_PAGE_ORDER:
  383.             $inside_hook_name 'options_order_inside';
  384.             $bottom_hook_name 'options_order_bottom';
  385.             $submit_name 'submit_order';
  386.             break;
  387.         default:
  388.             $inside_hook_name '';
  389.             $bottom_hook_name '';
  390.             $submit_name 'submit';
  391.     }
  392.  
  393.     // Begin output form
  394.         echo addForm('options.php''post''f')
  395.        . create_optpage_element($optpage)
  396.  
  397.     // Wrap the template in a table to keep from breaking the hooks below
  398.         echo "<table cellspacing=\"0\" class=\"table_blank\">\n" .
  399.          " <tr>\n" .
  400.          "  <td colspan=\"2\">\n";
  401.  
  402.     // This is the only variable that is needed by *just* the template.
  403.         $oTemplate->assign('options'$optpage_data['options']);
  404.     
  405.     /**
  406.      * The variables below should not be needed by the template since all plugin
  407.      * hooks are called here, not in the template.  If we find otherwise, these
  408.      * variables can be passed to the template.  Commenting out for not.
  409.      */
  410. /*
  411.     $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
  412.     $oTemplate->assign('page_title', $optpage_title);
  413.     $oTemplate->assign('optpage',$optpage);
  414.     $oTemplate->assign('optpage_name',$optpage_name);
  415.     $oTemplate->assign('optmode',$optmode);
  416.     $oTemplate->assign('optpage_data',$optpage_data);
  417. */
  418.     /**
  419.      * END comment block
  420.      */    
  421.      
  422.     $oTemplate->display('options.tpl');
  423.  
  424.     echo "  </td>\n" .
  425.          " </tr>\n";
  426.  
  427.     /* If it is not empty, trigger the inside hook. */
  428.     if ($inside_hook_name != ''{
  429.         do_hook($inside_hook_name);
  430.     }
  431.  
  432.     /* Spit out a submit button. */
  433.     OptionSubmit($submit_name);
  434.     echo "</table>\n" .
  435.          "</form>\n";
  436.  
  437.     /* If it is not empty, trigger the bottom hook. */
  438.     if ($bottom_hook_name != ''{
  439.         do_hook($bottom_hook_name);
  440.     }
  441.     
  442. }
  443.  
  444. $oTemplate->display('footer.tpl');
  445. ?>

Documentation generated on Sat, 07 Oct 2006 16:12:47 +0300 by phpDocumentor 1.3.0RC6