display.php 18 KB

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