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

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