display.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <?php
  2. /**
  3. * options_display.php
  4. *
  5. * Copyright (c) 1999-2005 The SquirrelMail Project Team
  6. * Licensed under the GNU GPL. For full terms see the file COPYING.
  7. *
  8. * Displays all optinos about display preferences
  9. *
  10. * @version $Id$
  11. * @package squirrelmail
  12. */
  13. /** Define the group constants for the display options page. */
  14. define('SMOPT_GRP_GENERAL', 0);
  15. define('SMOPT_GRP_MAILBOX', 1);
  16. define('SMOPT_GRP_MESSAGE', 2);
  17. // load icon themes if in use
  18. global $use_icons;
  19. if ($use_icons) {
  20. global $icon_themes;
  21. $dirName = SM_PATH . 'images/themes';
  22. if (is_readable($dirName) && is_dir($dirName)) {
  23. $d = dir($dirName);
  24. while($dir = $d->read()) {
  25. if ($dir != "." && $dir != "..") {
  26. if (is_dir($dirName."/".$dir) && file_exists("$dirName/$dir/theme.php"))
  27. include("$dirName/$dir/theme.php");
  28. }
  29. }
  30. }
  31. }
  32. global $use_iframe;
  33. if (! isset($use_iframe)) $use_iframe=false;
  34. /**
  35. * This function builds an array with all the information about
  36. * the options available to the user, and returns it. The options
  37. * are grouped by the groups in which they are displayed.
  38. * For each option, the following information is stored:
  39. * - name: the internal (variable) name
  40. * - caption: the description of the option in the UI
  41. * - type: one of SMOPT_TYPE_*
  42. * - refresh: one of SMOPT_REFRESH_*
  43. * - size: one of SMOPT_SIZE_*
  44. * - save: the name of a function to call when saving this option
  45. * @return array all option information
  46. */
  47. function load_optpage_data_display() {
  48. global $theme, $language, $languages,
  49. $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
  50. $show_alternative_names, $available_languages, $use_icons, $use_iframe;
  51. /* Build a simple array into which we will build options. */
  52. $optgrps = array();
  53. $optvals = array();
  54. /******************************************************/
  55. /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
  56. /******************************************************/
  57. /*** Load the General Options into the array ***/
  58. $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
  59. $optvals[SMOPT_GRP_GENERAL] = array();
  60. /* Load the theme option. */
  61. $theme_values = array();
  62. foreach ($theme as $theme_key => $theme_attributes) {
  63. $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
  64. }
  65. ksort($theme_values);
  66. $theme_values = array_flip($theme_values);
  67. $optvals[SMOPT_GRP_GENERAL][] = array(
  68. 'name' => 'chosen_theme',
  69. 'caption' => _("Theme"),
  70. 'type' => SMOPT_TYPE_STRLIST,
  71. 'refresh' => SMOPT_REFRESH_ALL,
  72. 'posvals' => $theme_values,
  73. 'save' => 'save_option_theme'
  74. );
  75. $css_values = array( 'none' => _("Default" ) );
  76. $css_dir = SM_PATH . 'themes/css';
  77. if (is_readable($css_dir) && is_dir($css_dir)) {
  78. $handle=opendir($css_dir);
  79. while ($file = readdir($handle) ) {
  80. if ( substr( $file, -4 ) == '.css' ) {
  81. $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
  82. }
  83. }
  84. closedir($handle);
  85. }
  86. if ( count( $css_values ) > 1 ) {
  87. $optvals[SMOPT_GRP_GENERAL][] = array(
  88. 'name' => 'custom_css',
  89. 'caption' => _("Custom Stylesheet"),
  90. 'type' => SMOPT_TYPE_STRLIST,
  91. 'refresh' => SMOPT_REFRESH_ALL,
  92. 'posvals' => $css_values
  93. );
  94. }
  95. // config.php can be unupdated.
  96. if (! isset($available_languages) || $available_languages=="" ) {
  97. $available_languages="ALL"; }
  98. $language_values = array();
  99. if ( strtoupper($available_languages)=='ALL') {
  100. foreach ($languages as $lang_key => $lang_attributes) {
  101. if (isset($lang_attributes['NAME'])) {
  102. $language_values[$lang_key] = $lang_attributes['NAME'];
  103. if ( isset($show_alternative_names) &&
  104. $show_alternative_names &&
  105. isset($lang_attributes['ALTNAME']) ) {
  106. $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
  107. }
  108. }
  109. }
  110. } else if (strtoupper($available_languages)!='NONE') {
  111. // admin can set list of available languages in config
  112. $available_languages_array=explode (" ",$available_languages);
  113. foreach ($available_languages_array as $lang_key ) {
  114. if (isset($languages[$lang_key]['NAME'])) {
  115. $language_values[$lang_key] = $languages[$lang_key]['NAME'];
  116. if ( isset($show_alternative_names) &&
  117. $show_alternative_names &&
  118. isset($languages[$lang_key]['ALTNAME']) ) {
  119. $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME'];
  120. }
  121. }
  122. }
  123. }
  124. asort($language_values);
  125. $language_values =
  126. array_merge(array('' => _("Default")), $language_values);
  127. $language = $squirrelmail_language;
  128. if (strtoupper($available_languages)!='NONE') {
  129. // if set to 'none', interface will use only default language
  130. $optvals[SMOPT_GRP_GENERAL][] = array(
  131. 'name' => 'language',
  132. 'caption' => _("Language"),
  133. 'type' => SMOPT_TYPE_STRLIST,
  134. 'refresh' => SMOPT_REFRESH_ALL,
  135. 'posvals' => $language_values,
  136. 'htmlencoded' => true
  137. );
  138. }
  139. /* Set values for the "use javascript" option. */
  140. $optvals[SMOPT_GRP_GENERAL][] = array(
  141. 'name' => 'javascript_setting',
  142. 'caption' => _("Use Javascript"),
  143. 'type' => SMOPT_TYPE_STRLIST,
  144. 'refresh' => SMOPT_REFRESH_ALL,
  145. 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
  146. SMPREF_JS_ON => _("Always"),
  147. SMPREF_JS_OFF => _("Never")),
  148. 'save' => 'save_option_javascript_autodetect',
  149. 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
  150. );
  151. $optvals[SMOPT_GRP_GENERAL][] = array(
  152. 'name' => 'js_autodetect_results',
  153. 'caption' => '',
  154. 'type' => SMOPT_TYPE_HIDDEN,
  155. 'refresh' => SMOPT_REFRESH_NONE
  156. //'post_script' => $js_autodetect_script,
  157. );
  158. $optvals[SMOPT_GRP_GENERAL][] = array(
  159. 'name' => 'hour_format',
  160. 'caption' => _("Hour Format"),
  161. 'type' => SMOPT_TYPE_STRLIST,
  162. 'refresh' => SMOPT_REFRESH_FOLDERLIST,
  163. 'posvals' => array(SMPREF_TIME_12HR => _("12-hour clock"),
  164. SMPREF_TIME_24HR => _("24-hour clock"))
  165. );
  166. /*** Load the General Options into the array ***/
  167. $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
  168. $optvals[SMOPT_GRP_MAILBOX] = array();
  169. $optvals[SMOPT_GRP_MAILBOX][] = array(
  170. 'name' => 'show_num',
  171. 'caption' => _("Number of Messages per Page"),
  172. 'type' => SMOPT_TYPE_INTEGER,
  173. 'refresh' => SMOPT_REFRESH_NONE,
  174. 'size' => SMOPT_SIZE_TINY
  175. );
  176. $optvals[SMOPT_GRP_MAILBOX][] = array(
  177. 'name' => 'alt_index_colors',
  178. 'caption' => _("Enable Alternating Row Colors"),
  179. 'type' => SMOPT_TYPE_BOOLEAN,
  180. 'refresh' => SMOPT_REFRESH_NONE
  181. );
  182. $optvals[SMOPT_GRP_MAILBOX][] = array(
  183. 'name' => 'fancy_index_highlite',
  184. 'caption' => _("Enable Fancy Row Mouseover Highlighting"),
  185. 'type' => SMOPT_TYPE_BOOLEAN,
  186. 'refresh' => SMOPT_REFRESH_NONE
  187. );
  188. if ($use_icons) {
  189. global $icon_themes, $icon_theme;
  190. $temp = array();
  191. for ($count = 0; $count < sizeof($icon_themes); $count++) {
  192. $temp[$count] = $icon_themes[$count]['NAME'];
  193. if ($icon_theme == $icon_themes[$count]['PATH'])
  194. $value = $count;
  195. }
  196. if (sizeof($icon_themes) > 0) {
  197. $optvals[SMOPT_GRP_MAILBOX][] = array(
  198. 'name' => 'icon_theme',
  199. 'caption' => _("Message Flags Icon Theme"),
  200. 'type' => SMOPT_TYPE_STRLIST,
  201. 'refresh' => SMOPT_REFRESH_NONE,
  202. 'posvals' => $temp,
  203. 'initial_value' => $value,
  204. 'save' => 'icon_theme_save'
  205. );
  206. }
  207. }
  208. $optvals[SMOPT_GRP_MAILBOX][] = array(
  209. 'name' => 'show_flag_buttons',
  210. 'caption' => _("Show Flag / Unflag Buttons"),
  211. 'type' => SMOPT_TYPE_BOOLEAN,
  212. 'refresh' => SMOPT_REFRESH_NONE
  213. );
  214. $optvals[SMOPT_GRP_MAILBOX][] = array(
  215. 'name' => 'page_selector',
  216. 'caption' => _("Enable Page Selector"),
  217. 'type' => SMOPT_TYPE_BOOLEAN,
  218. 'refresh' => SMOPT_REFRESH_NONE
  219. );
  220. $optvals[SMOPT_GRP_MAILBOX][] = array(
  221. 'name' => 'compact_paginator',
  222. 'caption' => _("Use Compact Page Selector"),
  223. 'type' => SMOPT_TYPE_BOOLEAN,
  224. 'refresh' => SMOPT_REFRESH_NONE
  225. );
  226. $optvals[SMOPT_GRP_MAILBOX][] = array(
  227. 'name' => 'page_selector_max',
  228. 'caption' => _("Maximum Number of Pages to Show"),
  229. 'type' => SMOPT_TYPE_INTEGER,
  230. 'refresh' => SMOPT_REFRESH_NONE,
  231. 'size' => SMOPT_SIZE_TINY
  232. );
  233. $optvals[SMOPT_GRP_MAILBOX][] = array(
  234. 'name' => 'show_full_date',
  235. 'caption' => _("Always Show Full Date"),
  236. 'type' => SMOPT_TYPE_BOOLEAN,
  237. 'refresh' => SMOPT_REFRESH_NONE
  238. );
  239. $optvals[SMOPT_GRP_MAILBOX][] = array(
  240. 'name' => 'truncate_sender',
  241. 'caption' => _("Length of From/To Field (0 for full)"),
  242. 'type' => SMOPT_TYPE_INTEGER,
  243. 'refresh' => SMOPT_REFRESH_NONE,
  244. 'size' => SMOPT_SIZE_TINY
  245. );
  246. $optvals[SMOPT_GRP_MAILBOX][] = array(
  247. 'name' => 'truncate_subject',
  248. 'caption' => _("Length of Subject Field (0 for full)"),
  249. 'type' => SMOPT_TYPE_INTEGER,
  250. 'refresh' => SMOPT_REFRESH_NONE,
  251. 'size' => SMOPT_SIZE_TINY
  252. );
  253. /*
  254. disabled because the template doesn't support it (yet?)
  255. $optvals[SMOPT_GRP_MAILBOX][] = array(
  256. 'name' => 'show_recipient_instead',
  257. 'caption' => _("Show recipient name if the message is from your default identity"),
  258. 'type' => SMOPT_TYPE_BOOLEAN,
  259. 'refresh' => SMOPT_REFRESH_NONE,
  260. 'size' => SMOPT_SIZE_TINY
  261. );
  262. */
  263. if ($allow_thread_sort == TRUE) {
  264. $optvals[SMOPT_GRP_MAILBOX][] = array(
  265. 'name' => 'sort_by_ref',
  266. 'caption' => _("Enable Thread Sort by References Header"),
  267. 'type' => SMOPT_TYPE_BOOLEAN,
  268. 'refresh' => SMOPT_REFRESH_ALL
  269. );
  270. }
  271. /*** Load the General Options into the array ***/
  272. $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display Options");
  273. $optvals[SMOPT_GRP_MESSAGE] = array();
  274. $optvals[SMOPT_GRP_MESSAGE][] = array(
  275. 'name' => 'wrap_at',
  276. 'caption' => _("Wrap Incoming Text At"),
  277. 'type' => SMOPT_TYPE_INTEGER,
  278. 'refresh' => SMOPT_REFRESH_NONE,
  279. 'size' => SMOPT_SIZE_TINY
  280. );
  281. $optvals[SMOPT_GRP_MESSAGE][] = array(
  282. 'name' => 'show_html_default',
  283. 'caption' => _("Show HTML Version by Default"),
  284. 'type' => SMOPT_TYPE_BOOLEAN,
  285. 'refresh' => SMOPT_REFRESH_NONE
  286. );
  287. if ($use_iframe) {
  288. // Type is set to string in order to be able to use 100%.
  289. $optvals[SMOPT_GRP_MESSAGE][] = array(
  290. 'name' => 'iframe_height',
  291. 'caption' => _("Height of inline frame"),
  292. 'type' => SMOPT_TYPE_STRING,
  293. 'size' => SMOPT_SIZE_TINY,
  294. 'refresh' => SMOPT_REFRESH_NONE
  295. );
  296. }
  297. $optvals[SMOPT_GRP_MESSAGE][] = array(
  298. 'name' => 'enable_forward_as_attachment',
  299. 'caption' => _("Enable Forward as Attachment"),
  300. 'type' => SMOPT_TYPE_BOOLEAN,
  301. 'refresh' => SMOPT_REFRESH_NONE
  302. );
  303. $optvals[SMOPT_GRP_MESSAGE][] = array(
  304. 'name' => 'show_xmailer_default',
  305. 'caption' => _("Enable Mailer Display"),
  306. 'type' => SMOPT_TYPE_BOOLEAN,
  307. 'refresh' => SMOPT_REFRESH_NONE
  308. );
  309. $optvals[SMOPT_GRP_MESSAGE][] = array(
  310. 'name' => 'attachment_common_show_images',
  311. 'caption' => _("Display Attached Images with Message"),
  312. 'type' => SMOPT_TYPE_BOOLEAN,
  313. 'refresh' => SMOPT_REFRESH_NONE
  314. );
  315. if ($default_use_mdn) {
  316. $optvals[SMOPT_GRP_MESSAGE][] = array(
  317. 'name' => 'mdn_user_support',
  318. 'caption' => _("Enable Mail Delivery Notification"),
  319. 'type' => SMOPT_TYPE_BOOLEAN,
  320. 'refresh' => SMOPT_REFRESH_NONE
  321. );
  322. }
  323. $optvals[SMOPT_GRP_MESSAGE][] = array(
  324. 'name' => 'delete_prev_next_display',
  325. 'caption' => _("Show 'Delete & Prev/Next' Links"),
  326. 'type' => SMOPT_TYPE_BOOLEAN,
  327. 'refresh' => SMOPT_REFRESH_ALL
  328. );
  329. /* Assemble all this together and return it as our result. */
  330. $result = array(
  331. 'grps' => $optgrps,
  332. 'vals' => $optvals
  333. );
  334. return ($result);
  335. }
  336. /******************************************************************/
  337. /** Define any specialized save functions for this option page. ***/
  338. /******************************************************************/
  339. /**
  340. * This function saves a new theme setting.
  341. * It updates the theme array.
  342. */
  343. function save_option_theme($option) {
  344. global $theme;
  345. /* Do checking to make sure $new_theme is in the array. */
  346. $theme_in_array = false;
  347. for ($i = 0; $i < count($theme); ++$i) {
  348. if ($theme[$i]['PATH'] == $option->new_value) {
  349. $theme_in_array = true;
  350. break;
  351. }
  352. }
  353. if (!$theme_in_array) {
  354. $option->new_value = '';
  355. }
  356. /* Save the option like normal. */
  357. save_option($option);
  358. }
  359. /**
  360. * This function saves the javascript detection option.
  361. */
  362. function save_option_javascript_autodetect($option) {
  363. save_option($option);
  364. checkForJavascript(TRUE);
  365. }
  366. /**
  367. * This function saves the user's icon theme setting
  368. */
  369. function icon_theme_save($option) {
  370. global $icon_themes, $data_dir, $username;
  371. // Don't assume the new value is there, double check
  372. // and only save if found
  373. //
  374. if (isset($icon_themes[$option->new_value]['PATH']))
  375. setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
  376. else
  377. setPref($data_dir, $username, 'icon_theme', 'none');
  378. }
  379. ?>