Source for file display.php

Documentation is available at display.php

  1. <?php
  2.  
  3. /**
  4.  * options_display.php
  5.  *
  6.  * Displays all optinos about display preferences
  7.  *
  8.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: display.php,v 1.73 2006/10/03 15:30:52 stevetruckstuff Exp $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /** Define the group constants for the display options page. */
  15. define('SMOPT_GRP_GENERAL'0);
  16. define('SMOPT_GRP_MAILBOX'1);
  17. define('SMOPT_GRP_MESSAGE'2);
  18.  
  19. global $use_iframe;
  20. if (isset($use_iframe)) $use_iframe=false;
  21.  
  22. /**
  23.  * This function builds an array with all the information about
  24.  * the options available to the user, and returns it. The options
  25.  * are grouped by the groups in which they are displayed.
  26.  * For each option, the following information is stored:
  27.  * - name: the internal (variable) name
  28.  * - caption: the description of the option in the UI
  29.  * - type: one of SMOPT_TYPE_*
  30.  * - refresh: one of SMOPT_REFRESH_*
  31.  * - size: one of SMOPT_SIZE_*
  32.  * - save: the name of a function to call when saving this option
  33.  * @return array all option information
  34.  */
  35.     global $theme$fontsets$language$languages,$aTemplateSet,
  36.     $default_use_mdn$squirrelmail_language$allow_thread_sort,
  37.     $sTemplateID$oTemplate,
  38.     $user_themes$chosen_theme;
  39.  
  40.     /* Build a simple array into which we will build options. */
  41.     $optgrps array();
  42.     $optvals array();
  43.  
  44.     /******************************************************/
  45.     /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
  46.     /******************************************************/
  47.  
  48.     /*** Load the General Options into the array ***/
  49.     $optgrps[SMOPT_GRP_GENERAL_("General Display Options");
  50.     $optvals[SMOPT_GRP_GENERALarray();
  51.  
  52.     /* load the template set option */
  53.     $templateset_values array();
  54.  
  55.     foreach ($aTemplateSet as $sKey => $aTemplateSetAttributes{
  56.         $templateset_values[$aTemplateSetAttributes['NAME']] $aTemplateSetAttributes['ID'];
  57.     }
  58.     ksort($templateset_values);
  59.     $templateset_values array_flip($templateset_values);
  60.     // display template options only when there is more than one template
  61.     if (count($templateset_values)>1{
  62.         $optvals[SMOPT_GRP_GENERAL][array(
  63.             'name'    => 'sTemplateID',
  64.             'caption' => _("Skin"),
  65.             'type'    => SMOPT_TYPE_STRLIST,
  66.             'refresh' => SMOPT_REFRESH_ALL,
  67.             'posvals' => $templateset_values,
  68.             'save'    => 'save_option_template'
  69.         );
  70.     }
  71.  
  72.     /* Load the theme option. */
  73.  
  74.     /**
  75.      * User themes start with a 'u_', template themes start with a 't_' to
  76.      * differentiate which is which.  This seems kind of hackish, but we can
  77.      * come up with a better solution later.
  78. PL: No need for the prefixes.  Just use full paths, no?
  79.  
  80. SB: Don't think so.  If the user chooses a template theme than changes the 
  81.     path to the template, it would error out, right?  Or should we worry about
  82.     that?
  83.      * 
  84.      * TODO: Clean me.
  85.      **/
  86.     $theme_values array();
  87.     
  88.     // Always provide the template default first.
  89.     $theme_values['none''Template Default Theme';
  90.  
  91.     // List alternate themes provided by templates first
  92.     $template_themes $oTemplate->get_alternative_stylesheets();
  93.     asort($template_themes);
  94.     foreach ($template_themes as $sheet=>$name{
  95.         $theme_values['t_'.$sheet'Template Theme - '.htmlspecialchars($name);
  96.     }
  97.     // Next, list user-provided styles
  98.     asort($user_themes);
  99.     foreach ($user_themes as $style{
  100.         if ($style['PATH'== 'none')
  101.             continue;
  102.         $theme_values['u_'.$style['PATH']] 'User Theme - '.htmlspecialchars($style['NAME']);
  103.     }
  104.  
  105.     if (count($user_themescount($template_themes1{
  106.         $optvals[SMOPT_GRP_GENERAL][array(
  107.             'name'    => 'chosen_theme',
  108.             'caption' => _("Theme"),
  109.             'type'    => SMOPT_TYPE_STRLIST,
  110.             'refresh' => SMOPT_REFRESH_ALL,
  111.             'posvals' => $theme_values,
  112.             'save'    => 'css_theme_save'
  113.         );
  114.     }
  115.  
  116.     /* Icon theme selection */
  117.     if ($use_icons{
  118.         global $icon_themes$icon_theme;
  119.  
  120.         $temp array();
  121.         $value 0;
  122.         for ($count 0$count sizeof($icon_themes)$count++{
  123.             $temp[$icon_themes[$count]['PATH']] $icon_themes[$count]['NAME'];
  124.         }
  125.         if (sizeof($icon_themes0{
  126.             $optvals[SMOPT_GRP_GENERAL][array(
  127.                 'name'          => 'icon_theme',
  128.                 'caption'       => _("Icon Theme"),
  129.                 'type'          => SMOPT_TYPE_STRLIST,
  130.                 'refresh'       => SMOPT_REFRESH_NONE,
  131.                 'posvals'       => $temp,
  132.                 'save'          => 'icon_theme_save'
  133.             );
  134.         }
  135.     }
  136.  
  137.     $fontset_values array();
  138.     $fontset_list array();
  139.  
  140.     if (!empty($fontsets&& is_array($fontsets)) {
  141.  
  142.         foreach (array_keys($fontsetsas $fontset_key{
  143.             $fontset_list[$fontset_key]=$fontset_key;
  144.         }
  145.         ksort($fontset_list);
  146.     }
  147.  
  148.     if (count($fontset_list1{
  149.         $fontset_list array_merge(array('' => _("Default font style"))$fontset_list);
  150.         $optvals[SMOPT_GRP_GENERAL][array(
  151.             'name'    => 'chosen_fontset',
  152.             'caption' => _("Font style"),
  153.             'type'    => SMOPT_TYPE_STRLIST,
  154.             'refresh' => SMOPT_REFRESH_ALL,
  155.             'posvals' => $fontset_list
  156.         );
  157.     }
  158.  
  159.     $optvals[SMOPT_GRP_GENERAL][array(
  160.         'name'    => 'chosen_fontsize',
  161.         'caption' => _("Font size"),
  162.         'type'    => SMOPT_TYPE_STRLIST,
  163.         'refresh' => SMOPT_REFRESH_ALL,
  164.         'posvals' => array('' => _("Default font size"),
  165.                            '8' => '8 px',
  166.                            '10' => '10 px',
  167.                            '12' => '12 px',
  168.                            '14' => '14 px')
  169.     );
  170.  
  171.     $language_values array();
  172.     foreach ($languages as $lang_key => $lang_attributes{
  173.         if (isset($lang_attributes['NAME'])) {
  174.             $language_values[$lang_key$lang_attributes['NAME'];
  175.             if isset($show_alternative_names&&
  176.                  $show_alternative_names &&
  177.                  isset($lang_attributes['ALTNAME']) ) {
  178.                 $language_values[$lang_key.= " / " $lang_attributes['ALTNAME'];
  179.             }
  180.         }
  181.     }
  182.  
  183.     asort($language_values);
  184.     $language_values =
  185.         array_merge(array('' => _("Default"))$language_values);
  186.     $language $squirrelmail_language;
  187.  
  188.     // add language selection only when more than 2 languages are available
  189.     // (default, English and some other)
  190.     if (count($language_values)>2{
  191.         $optvals[SMOPT_GRP_GENERAL][array(
  192.             'name'    => 'language',
  193.             'caption' => _("Language"),
  194.             'type'    => SMOPT_TYPE_STRLIST,
  195.             'refresh' => SMOPT_REFRESH_ALL,
  196.             'posvals' => $language_values,
  197.             'htmlencoded' => true
  198.         );
  199.     }
  200.  
  201.     /* Set values for the "use javascript" option. */
  202.     $optvals[SMOPT_GRP_GENERAL][array(
  203.         'name'    => 'javascript_setting',
  204.         'caption' => _("Use Javascript"),
  205.         'type'    => SMOPT_TYPE_STRLIST,
  206.         'refresh' => SMOPT_REFRESH_ALL,
  207.         'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
  208.                            SMPREF_JS_ON         => _("Always"),
  209.                            SMPREF_JS_OFF        => _("Never")),
  210.         'save'    => 'save_option_javascript_autodetect',
  211.         'script'  => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' SMPREF_JS_ON '\';"'
  212.     );
  213.  
  214.     $optvals[SMOPT_GRP_GENERAL][array(
  215.         'name'    => 'js_autodetect_results',
  216.         'caption' => '',
  217.         'type'    => SMOPT_TYPE_HIDDEN,
  218.         'refresh' => SMOPT_REFRESH_NONE
  219.         //'post_script' => $js_autodetect_script,
  220.     );
  221.  
  222.     $optvals[SMOPT_GRP_GENERAL][array(
  223.         'name'    => 'hour_format',
  224.         'caption' => _("Hour Format"),
  225.         'type'    => SMOPT_TYPE_STRLIST,
  226.         'refresh' => SMOPT_REFRESH_FOLDERLIST,
  227.         'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
  228.                            SMPREF_TIME_24HR => _("24-hour clock"))
  229.     );
  230.  
  231.     /*** Load the General Options into the array ***/
  232.     $optgrps[SMOPT_GRP_MAILBOX_("Mailbox Display Options");
  233.     $optvals[SMOPT_GRP_MAILBOXarray();
  234.  
  235.     $optvals[SMOPT_GRP_MAILBOX][array(
  236.         'name'    => 'show_num',
  237.         'caption' => _("Number of Messages per Page"),
  238.         'type'    => SMOPT_TYPE_INTEGER,
  239.         'refresh' => SMOPT_REFRESH_NONE,
  240.         'size'    => SMOPT_SIZE_TINY
  241.     );
  242.  
  243.     $optvals[SMOPT_GRP_MAILBOX][array(
  244.         'name'    => 'alt_index_colors',
  245.         'caption' => _("Enable Alternating Row Colors"),
  246.         'type'    => SMOPT_TYPE_BOOLEAN,
  247.         'refresh' => SMOPT_REFRESH_NONE
  248.     );
  249.  
  250.     $optvals[SMOPT_GRP_MAILBOX][array(
  251.         'name'    => 'fancy_index_highlite',
  252.         'caption' => _("Enable Fancy Row Mouseover Highlighting"),
  253.         'type'    => SMOPT_TYPE_BOOLEAN,
  254.         'refresh' => SMOPT_REFRESH_NONE
  255.     );
  256.  
  257.     $optvals[SMOPT_GRP_MAILBOX][array(
  258.         'name'    => 'show_flag_buttons',
  259.         'caption' => _("Show Flag / Unflag Buttons"),
  260.         'type'    => SMOPT_TYPE_BOOLEAN,
  261.         'refresh' => SMOPT_REFRESH_NONE
  262.     );
  263.  
  264.     $optvals[SMOPT_GRP_MAILBOX][array(
  265.         'name'    => 'show_copy_buttons',
  266.         'caption' => _("Enable Message Copy Buttons"),
  267.         'type'    => SMOPT_TYPE_BOOLEAN,
  268.         'refresh' => SMOPT_REFRESH_NONE
  269.     );
  270.  
  271.     $optvals[SMOPT_GRP_MAILBOX][array(
  272.         'name'    => 'page_selector',
  273.         'caption' => _("Enable Page Selector"),
  274.         'type'    => SMOPT_TYPE_BOOLEAN,
  275.         'refresh' => SMOPT_REFRESH_NONE
  276.     );
  277.  
  278.     $optvals[SMOPT_GRP_MAILBOX][array(
  279.         'name'    => 'compact_paginator',
  280.         'caption' => _("Use Compact Page Selector"),
  281.         'type'    => SMOPT_TYPE_BOOLEAN,
  282.         'refresh' => SMOPT_REFRESH_NONE
  283.     );
  284.  
  285.     $optvals[SMOPT_GRP_MAILBOX][array(
  286.         'name'    => 'page_selector_max',
  287.         'caption' => _("Maximum Number of Pages to Show"),
  288.         'type'    => SMOPT_TYPE_INTEGER,
  289.         'refresh' => SMOPT_REFRESH_NONE,
  290.         'size'    => SMOPT_SIZE_TINY
  291.     );
  292.  
  293.     $optvals[SMOPT_GRP_MAILBOX][array(
  294.         'name'    => 'show_full_date',
  295.         'caption' => _("Always Show Full Date"),
  296.         'type'    => SMOPT_TYPE_BOOLEAN,
  297.         'refresh' => SMOPT_REFRESH_NONE
  298.     );
  299.  
  300.     $optvals[SMOPT_GRP_MAILBOX][array(
  301.         'name'    => 'truncate_sender',
  302.         'caption' => _("Length of From/To Field (0 for full)"),
  303.         'type'    => SMOPT_TYPE_INTEGER,
  304.         'refresh' => SMOPT_REFRESH_NONE,
  305.         'size'    => SMOPT_SIZE_TINY
  306.     );
  307.  
  308.     $optvals[SMOPT_GRP_MAILBOX][array(
  309.         'name'    => 'truncate_subject',
  310.         'caption' => _("Length of Subject Field (0 for full)"),
  311.         'type'    => SMOPT_TYPE_INTEGER,
  312.         'refresh' => SMOPT_REFRESH_NONE,
  313.         'size'    => SMOPT_SIZE_TINY
  314.     );
  315. /*
  316. FIXME!
  317.   disabled because the template doesn't support it (yet?)
  318.     $optvals[SMOPT_GRP_MAILBOX][] = array(
  319.         'name'    => 'show_recipient_instead',
  320.         'caption' => _("Show recipient name if the message is from your default identity"),
  321.         'type'    => SMOPT_TYPE_BOOLEAN,
  322.         'refresh' => SMOPT_REFRESH_NONE,
  323.         'size'    => SMOPT_SIZE_TINY
  324.     );
  325. */
  326.  
  327.     if ($allow_thread_sort == TRUE{
  328.         $optvals[SMOPT_GRP_MAILBOX][array(
  329.             'name'    => 'sort_by_ref',
  330.             'caption' => _("Enable Thread Sort by References Header"),
  331.             'type'    => SMOPT_TYPE_BOOLEAN,
  332.             'refresh' => SMOPT_REFRESH_ALL
  333.         );
  334.     }
  335.  
  336.  
  337.  
  338.     /*** Load the General Options into the array ***/
  339.     $optgrps[SMOPT_GRP_MESSAGE_("Message Display Options");
  340.     $optvals[SMOPT_GRP_MESSAGEarray();
  341.  
  342.     $optvals[SMOPT_GRP_MESSAGE][array(
  343.         'name'    => 'wrap_at',
  344.         'caption' => _("Wrap Incoming Text At"),
  345.         'type'    => SMOPT_TYPE_INTEGER,
  346.         'refresh' => SMOPT_REFRESH_NONE,
  347.         'size'    => SMOPT_SIZE_TINY
  348.     );
  349.  
  350.     $optvals[SMOPT_GRP_MESSAGE][array(
  351.         'name'    => 'show_html_default',
  352.         'caption' => _("Show HTML Version by Default"),
  353.         'type'    => SMOPT_TYPE_BOOLEAN,
  354.         'refresh' => SMOPT_REFRESH_NONE
  355.     );
  356.  
  357.     if ($use_iframe{
  358.         // Type is set to string in order to be able to use 100%.
  359.         $optvals[SMOPT_GRP_MESSAGE][array(
  360.             'name'    => 'iframe_height',
  361.             'caption' => _("Height of inline frame"),
  362.             'type'    => SMOPT_TYPE_STRING,
  363.             'size'    => SMOPT_SIZE_TINY,
  364.             'refresh' => SMOPT_REFRESH_NONE
  365.         );
  366.     }
  367.     $optvals[SMOPT_GRP_MESSAGE][array(
  368.         'name'    => 'enable_forward_as_attachment',
  369.         'caption' => _("Enable Forward as Attachment"),
  370.         'type'    => SMOPT_TYPE_BOOLEAN,
  371.         'refresh' => SMOPT_REFRESH_NONE
  372.     );
  373.  
  374.     $optvals[SMOPT_GRP_MESSAGE][array(
  375.         'name'    => 'show_xmailer_default',
  376.         'caption' => _("Enable Mailer Display"),
  377.         'type'    => SMOPT_TYPE_BOOLEAN,
  378.         'refresh' => SMOPT_REFRESH_NONE
  379.     );
  380.  
  381.     $optvals[SMOPT_GRP_MESSAGE][array(
  382.         'name'    => 'attachment_common_show_images',
  383.         'caption' => _("Display Attached Images with Message"),
  384.         'type'    => SMOPT_TYPE_BOOLEAN,
  385.         'refresh' => SMOPT_REFRESH_NONE
  386.     );
  387.  
  388.     if ($default_use_mdn{
  389.         $optvals[SMOPT_GRP_MESSAGE][array(
  390.             'name'    => 'mdn_user_support',
  391.             'caption' => _("Enable Mail Delivery Notification"),
  392.             'type'    => SMOPT_TYPE_BOOLEAN,
  393.             'refresh' => SMOPT_REFRESH_NONE
  394.         );
  395.     }
  396.  
  397.     $optvals[SMOPT_GRP_MESSAGE][array(
  398.         'name'    => 'delete_prev_next_display',
  399.         'caption' => _("Show 'Delete &amp; Prev/Next' Links"),
  400.         'type'    => SMOPT_TYPE_BOOLEAN,
  401.         'refresh' => SMOPT_REFRESH_ALL
  402.     );
  403.  
  404.     /* Assemble all this together and return it as our result. */
  405.     $result array(
  406.         'grps' => $optgrps,
  407.         'vals' => $optvals
  408.     );
  409.     return ($result);
  410. }
  411.  
  412. /******************************************************************/
  413. /** Define any specialized save functions for this option page. ***/
  414. /******************************************************************/
  415.  
  416. /**
  417.  * This function saves a new template setting.
  418.  * It updates the template array.
  419.  */
  420. function save_option_template($option{
  421.     global $aTemplateSet;
  422.  
  423.     /* Do checking to make sure new template is in the available templates array. */
  424.     $templateset_in_array false;
  425.     for ($i 0$i count($aTemplateSet)++$i{
  426.         if ($aTemplateSet[$i]['ID'== $option->new_value{
  427.             $templateset_in_array true;
  428.             break;
  429.         }
  430.     }
  431.  
  432.     if (!$templateset_in_array{
  433.         $option->new_value '';
  434.     else {
  435.  
  436.         // clear template cache when changing template sets
  437.         // (in order to do so, we have to change the global
  438.         // template set ID now... should not be a problem --
  439.         // in fact, if we don't do it now, very anomalous
  440.         // problems occur)
  441.         //
  442.         global $sTemplateID;
  443.         $sTemplateID $option->new_value;
  444.         Template::cache_template_file_hierarchy(TRUE);
  445.  
  446.     }
  447.  
  448.     /* Save the option like normal. */
  449.     save_option($option);
  450. }
  451.  
  452. /**
  453.  * This function saves the javascript detection option.
  454.  */
  455. function save_option_javascript_autodetect($option{
  456.     save_option($option);
  457.     checkForJavascript(TRUE);
  458. }
  459.  
  460. /**
  461.  * This function saves the user's icon theme setting
  462.  */
  463. function icon_theme_save($option{
  464.     global $icon_themes;
  465.  
  466.  
  467.     // Don't assume the new value is there, double check
  468.     // and only save if found
  469.     $found false;
  470.     while (!$found && (list($index$dataeach($icon_themes))) {
  471.         if ($data['PATH'== $option->new_value)
  472.             $found true;
  473.     }
  474.     
  475.     if (!$found)
  476.         $option->new_value 'none';
  477.         
  478.     save_option($option);
  479. }
  480.  
  481. function css_theme_save ($option{
  482.     global $user_themes$oTemplate;
  483.  
  484.     // Don't assume the new value is there, double check
  485.     // and only save if found
  486.     $found false;
  487.     reset($user_themes);
  488.     while (!$found && (list($index$dataeach($user_themes))) {
  489.         if ('u_'.$data['PATH'== $option->new_value)
  490.             $found true;
  491.     }
  492.     
  493.     $template_themes $oTemplate->get_alternative_stylesheets();
  494.     foreach ($template_themes as $path=>$name{
  495.         if ('t_'.$path == $option->new_value)
  496.             $found true;
  497.     }
  498.     
  499.     if (!$found)
  500.         $option->new_value 'none';
  501.         
  502.     save_option($option);
  503. }

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