display.php 16 KB

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