display.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <?php
  2. /**
  3. * options_display.php
  4. *
  5. * Copyright (c) 1999-2004 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. /**
  33. * This function builds an array with all the information about
  34. * the options available to the user, and returns it. The options
  35. * are grouped by the groups in which they are displayed.
  36. * For each option, the following information is stored:
  37. * - name: the internal (variable) name
  38. * - caption: the description of the option in the UI
  39. * - type: one of SMOPT_TYPE_*
  40. * - refresh: one of SMOPT_REFRESH_*
  41. * - size: one of SMOPT_SIZE_*
  42. * - save: the name of a function to call when saving this option
  43. * @return array all option information
  44. */
  45. function load_optpage_data_display() {
  46. global $theme, $language, $languages, $js_autodetect_results, $javascript_setting,
  47. $compose_new_win, $default_use_mdn, $squirrelmail_language, $allow_thread_sort,
  48. $optmode, $show_alternative_names, $available_languages, $use_icons;
  49. /* Build a simple array into which we will build options. */
  50. $optgrps = array();
  51. $optvals = array();
  52. /******************************************************/
  53. /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
  54. /******************************************************/
  55. /*** Load the General Options into the array ***/
  56. $optgrps[SMOPT_GRP_GENERAL] = _("General Display Options");
  57. $optvals[SMOPT_GRP_GENERAL] = array();
  58. /* Load the theme option. */
  59. $theme_values = array();
  60. foreach ($theme as $theme_key => $theme_attributes) {
  61. $theme_values[$theme_attributes['NAME']] = $theme_attributes['PATH'];
  62. }
  63. ksort($theme_values);
  64. $theme_values = array_flip($theme_values);
  65. $optvals[SMOPT_GRP_GENERAL][] = array(
  66. 'name' => 'chosen_theme',
  67. 'caption' => _("Theme"),
  68. 'type' => SMOPT_TYPE_STRLIST,
  69. 'refresh' => SMOPT_REFRESH_ALL,
  70. 'posvals' => $theme_values,
  71. 'save' => 'save_option_theme'
  72. );
  73. $css_values = array( 'none' => _("Default" ) );
  74. if (is_readable(SM_PATH . 'themes/css') && is_dir(SM_PATH . 'themes/css')) {
  75. $handle=opendir(SM_PATH . 'themes/css');
  76. while ($file = readdir($handle) ) {
  77. if ( substr( $file, -4 ) == '.css' ) {
  78. $css_values[$file] = substr( $file, 0, strlen( $file ) - 4 );
  79. }
  80. }
  81. closedir($handle);
  82. }
  83. if ( count( $css_values ) > 1 ) {
  84. $optvals[SMOPT_GRP_GENERAL][] = array(
  85. 'name' => 'custom_css',
  86. 'caption' => _("Custom Stylesheet"),
  87. 'type' => SMOPT_TYPE_STRLIST,
  88. 'refresh' => SMOPT_REFRESH_ALL,
  89. 'posvals' => $css_values
  90. );
  91. }
  92. // config.php can be unupdated.
  93. if (! isset($available_languages) || $available_languages=="" ) {
  94. $available_languages="ALL"; }
  95. $language_values = array();
  96. if ( strtoupper($available_languages)=='ALL') {
  97. foreach ($languages as $lang_key => $lang_attributes) {
  98. if (isset($lang_attributes['NAME'])) {
  99. $language_values[$lang_key] = $lang_attributes['NAME'];
  100. if ( isset($show_alternative_names) &&
  101. $show_alternative_names &&
  102. isset($lang_attributes['ALTNAME']) ) {
  103. $language_values[$lang_key] .= " / " . $lang_attributes['ALTNAME'];
  104. }
  105. }
  106. }
  107. } else if (strtoupper($available_languages)!='NONE') {
  108. // admin can set list of available languages in config
  109. $available_languages_array=explode (" ",$available_languages);
  110. foreach ($available_languages_array as $lang_key ) {
  111. if (isset($languages[$lang_key]['NAME'])) {
  112. $language_values[$lang_key] = $languages[$lang_key]['NAME'];
  113. if ( isset($show_alternative_names) &&
  114. $show_alternative_names &&
  115. isset($languages[$lang_key]['ALTNAME']) ) {
  116. $language_values[$lang_key] .= " / " . $languages[$lang_key]['ALTNAME'];
  117. }
  118. }
  119. }
  120. }
  121. asort($language_values);
  122. $language_values =
  123. array_merge(array('' => _("Default")), $language_values);
  124. $language = $squirrelmail_language;
  125. if (strtoupper($available_languages)!='NONE') {
  126. // if set to 'none', interface will use only default language
  127. $optvals[SMOPT_GRP_GENERAL][] = array(
  128. 'name' => 'language',
  129. 'caption' => _("Language"),
  130. 'type' => SMOPT_TYPE_STRLIST,
  131. 'refresh' => SMOPT_REFRESH_ALL,
  132. 'posvals' => $language_values
  133. );
  134. }
  135. /* Set values for the "use javascript" option. */
  136. $optvals[SMOPT_GRP_GENERAL][] = array(
  137. 'name' => 'javascript_setting',
  138. 'caption' => _("Use Javascript"),
  139. 'type' => SMOPT_TYPE_STRLIST,
  140. 'refresh' => SMOPT_REFRESH_ALL,
  141. 'posvals' => array(SMPREF_JS_AUTODETECT => _("Autodetect"),
  142. SMPREF_JS_ON => _("Always"),
  143. SMPREF_JS_OFF => _("Never")),
  144. 'save' => 'save_option_javascript_autodetect',
  145. 'script' => 'onclick="document.forms[0].new_js_autodetect_results.value = \'' . SMPREF_JS_ON . '\';"'
  146. );
  147. $optvals[SMOPT_GRP_GENERAL][] = array(
  148. 'name' => 'js_autodetect_results',
  149. 'caption' => '',
  150. 'type' => SMOPT_TYPE_HIDDEN,
  151. 'refresh' => SMOPT_REFRESH_NONE
  152. //'post_script' => $js_autodetect_script,
  153. );
  154. /*** Load the General Options into the array ***/
  155. $optgrps[SMOPT_GRP_MAILBOX] = _("Mailbox Display Options");
  156. $optvals[SMOPT_GRP_MAILBOX] = array();
  157. $optvals[SMOPT_GRP_MAILBOX][] = array(
  158. 'name' => 'show_num',
  159. 'caption' => _("Number of Messages to Index"),
  160. 'type' => SMOPT_TYPE_INTEGER,
  161. 'refresh' => SMOPT_REFRESH_NONE,
  162. 'size' => SMOPT_SIZE_TINY
  163. );
  164. $optvals[SMOPT_GRP_MAILBOX][] = array(
  165. 'name' => 'alt_index_colors',
  166. 'caption' => _("Enable Alternating Row Colors"),
  167. 'type' => SMOPT_TYPE_BOOLEAN,
  168. 'refresh' => SMOPT_REFRESH_NONE
  169. );
  170. if ($use_icons) {
  171. global $icon_themes, $icon_theme;
  172. $temp = array();
  173. for ($count = 0; $count < sizeof($icon_themes); $count++) {
  174. $temp[$count] = $icon_themes[$count]['NAME'];
  175. if ($icon_theme == $icon_themes[$count]['PATH'])
  176. $value = $count;
  177. }
  178. if (sizeof($icon_themes) > 0) {
  179. $optvals[SMOPT_GRP_MAILBOX][] = array(
  180. 'name' => 'icon_theme',
  181. 'caption' => _("Message Flags Icon Theme"),
  182. 'type' => SMOPT_TYPE_STRLIST,
  183. 'refresh' => SMOPT_REFRESH_NONE,
  184. 'posvals' => $temp,
  185. 'initial_value' => $value,
  186. 'save' => 'icon_theme_save'
  187. );
  188. }
  189. }
  190. $optvals[SMOPT_GRP_MAILBOX][] = array(
  191. 'name' => 'show_flag_buttons',
  192. 'caption' => _("Show Flag / Unflag Buttons"),
  193. 'type' => SMOPT_TYPE_BOOLEAN,
  194. 'refresh' => SMOPT_REFRESH_NONE
  195. );
  196. $optvals[SMOPT_GRP_MAILBOX][] = array(
  197. 'name' => 'page_selector',
  198. 'caption' => _("Enable Page Selector"),
  199. 'type' => SMOPT_TYPE_BOOLEAN,
  200. 'refresh' => SMOPT_REFRESH_NONE
  201. );
  202. $optvals[SMOPT_GRP_MAILBOX][] = array(
  203. 'name' => 'page_selector_max',
  204. 'caption' => _("Maximum Number of Pages to Show"),
  205. 'type' => SMOPT_TYPE_INTEGER,
  206. 'refresh' => SMOPT_REFRESH_NONE,
  207. 'size' => SMOPT_SIZE_TINY
  208. );
  209. $optvals[SMOPT_GRP_MAILBOX][] = array(
  210. 'name' => 'show_full_date',
  211. 'caption' => _("Always Show Full Date"),
  212. 'type' => SMOPT_TYPE_BOOLEAN,
  213. 'refresh' => SMOPT_REFRESH_NONE
  214. );
  215. $optvals[SMOPT_GRP_MAILBOX][] = array(
  216. 'name' => 'truncate_sender',
  217. 'caption' => _("Length of From/To Field (0 for full)"),
  218. 'type' => SMOPT_TYPE_INTEGER,
  219. 'refresh' => SMOPT_REFRESH_NONE,
  220. 'size' => SMOPT_SIZE_TINY
  221. );
  222. $optvals[SMOPT_GRP_MAILBOX][] = array(
  223. 'name' => 'truncate_subject',
  224. 'caption' => _("Length of Subject Field (0 for full)"),
  225. 'type' => SMOPT_TYPE_INTEGER,
  226. 'refresh' => SMOPT_REFRESH_NONE,
  227. 'size' => SMOPT_SIZE_TINY
  228. );
  229. $optvals[SMOPT_GRP_MAILBOX][] = array(
  230. 'name' => 'show_recipient_instead',
  231. 'caption' => _("Show recipient name if the message is from your default identity"),
  232. 'type' => SMOPT_TYPE_BOOLEAN,
  233. 'refresh' => SMOPT_REFRESH_NONE,
  234. 'size' => SMOPT_SIZE_TINY
  235. );
  236. /*** Load the General Options into the array ***/
  237. $optgrps[SMOPT_GRP_MESSAGE] = _("Message Display and Composition");
  238. $optvals[SMOPT_GRP_MESSAGE] = array();
  239. $optvals[SMOPT_GRP_MESSAGE][] = array(
  240. 'name' => 'wrap_at',
  241. 'caption' => _("Wrap Incoming Text At"),
  242. 'type' => SMOPT_TYPE_INTEGER,
  243. 'refresh' => SMOPT_REFRESH_NONE,
  244. 'size' => SMOPT_SIZE_TINY
  245. );
  246. $optvals[SMOPT_GRP_MESSAGE][] = array(
  247. 'name' => 'editor_size',
  248. 'caption' => _("Width of Editor Window"),
  249. 'type' => SMOPT_TYPE_INTEGER,
  250. 'refresh' => SMOPT_REFRESH_NONE,
  251. 'size' => SMOPT_SIZE_TINY
  252. );
  253. $optvals[SMOPT_GRP_MESSAGE][] = array(
  254. 'name' => 'editor_height',
  255. 'caption' => _("Height of Editor Window"),
  256. 'type' => SMOPT_TYPE_INTEGER,
  257. 'refresh' => SMOPT_REFRESH_NONE,
  258. 'size' => SMOPT_SIZE_TINY
  259. );
  260. $optvals[SMOPT_GRP_MESSAGE][] = array(
  261. 'name' => 'location_of_buttons',
  262. 'caption' => _("Location of Buttons when Composing"),
  263. 'type' => SMOPT_TYPE_STRLIST,
  264. 'refresh' => SMOPT_REFRESH_NONE,
  265. 'posvals' => array(SMPREF_LOC_TOP => _("Before headers"),
  266. SMPREF_LOC_BETWEEN => _("Between headers and message body"),
  267. SMPREF_LOC_BOTTOM => _("After message body"))
  268. );
  269. $optvals[SMOPT_GRP_MESSAGE][] = array(
  270. 'name' => 'use_javascript_addr_book',
  271. 'caption' => _("Addressbook Display Format"),
  272. 'type' => SMOPT_TYPE_STRLIST,
  273. 'refresh' => SMOPT_REFRESH_NONE,
  274. 'posvals' => array('1' => _("Javascript"),
  275. '0' => _("HTML"))
  276. );
  277. $optvals[SMOPT_GRP_MESSAGE][] = array(
  278. 'name' => 'show_html_default',
  279. 'caption' => _("Show HTML Version by Default"),
  280. 'type' => SMOPT_TYPE_BOOLEAN,
  281. 'refresh' => SMOPT_REFRESH_NONE
  282. );
  283. $optvals[SMOPT_GRP_MESSAGE][] = array(
  284. 'name' => 'enable_forward_as_attachment',
  285. 'caption' => _("Enable Forward as Attachment"),
  286. 'type' => SMOPT_TYPE_BOOLEAN,
  287. 'refresh' => SMOPT_REFRESH_NONE
  288. );
  289. $optvals[SMOPT_GRP_MESSAGE][] = array(
  290. 'name' => 'forward_cc',
  291. 'caption' => _("Include CCs when Forwarding Messages"),
  292. 'type' => SMOPT_TYPE_BOOLEAN,
  293. 'refresh' => SMOPT_REFRESH_NONE
  294. );
  295. $optvals[SMOPT_GRP_MESSAGE][] = array(
  296. 'name' => 'include_self_reply_all',
  297. 'caption' => _("Include Me in CC when I Reply All"),
  298. 'type' => SMOPT_TYPE_BOOLEAN,
  299. 'refresh' => SMOPT_REFRESH_NONE
  300. );
  301. $optvals[SMOPT_GRP_MESSAGE][] = array(
  302. 'name' => 'show_xmailer_default',
  303. 'caption' => _("Enable Mailer Display"),
  304. 'type' => SMOPT_TYPE_BOOLEAN,
  305. 'refresh' => SMOPT_REFRESH_NONE
  306. );
  307. $optvals[SMOPT_GRP_MESSAGE][] = array(
  308. 'name' => 'attachment_common_show_images',
  309. 'caption' => _("Display Attached Images with Message"),
  310. 'type' => SMOPT_TYPE_BOOLEAN,
  311. 'refresh' => SMOPT_REFRESH_NONE
  312. );
  313. $optvals[SMOPT_GRP_MESSAGE][] = array(
  314. 'name' => 'pf_cleandisplay',
  315. 'caption' => _("Enable Printer Friendly Clean Display"),
  316. 'type' => SMOPT_TYPE_BOOLEAN,
  317. 'refresh' => SMOPT_REFRESH_NONE
  318. );
  319. if ($default_use_mdn) {
  320. $optvals[SMOPT_GRP_MESSAGE][] = array(
  321. 'name' => 'mdn_user_support',
  322. 'caption' => _("Enable Mail Delivery Notification"),
  323. 'type' => SMOPT_TYPE_BOOLEAN,
  324. 'refresh' => SMOPT_REFRESH_NONE
  325. );
  326. }
  327. $optvals[SMOPT_GRP_MESSAGE][] = array(
  328. 'name' => 'compose_new_win',
  329. 'caption' => _("Compose Messages in New Window"),
  330. 'type' => SMOPT_TYPE_BOOLEAN,
  331. 'refresh' => SMOPT_REFRESH_ALL
  332. );
  333. $optvals[SMOPT_GRP_MESSAGE][] = array(
  334. 'name' => 'compose_width',
  335. 'caption' => _("Width of Compose Window"),
  336. 'type' => SMOPT_TYPE_INTEGER,
  337. 'refresh' => SMOPT_REFRESH_ALL,
  338. 'size' => SMOPT_SIZE_TINY
  339. );
  340. $optvals[SMOPT_GRP_MESSAGE][] = array(
  341. 'name' => 'compose_height',
  342. 'caption' => _("Height of Compose Window"),
  343. 'type' => SMOPT_TYPE_INTEGER,
  344. 'refresh' => SMOPT_REFRESH_ALL,
  345. 'size' => SMOPT_SIZE_TINY
  346. );
  347. $optvals[SMOPT_GRP_MESSAGE][] = array(
  348. 'name' => 'sig_first',
  349. 'caption' => _("Append Signature before Reply/Forward Text"),
  350. 'type' => SMOPT_TYPE_BOOLEAN,
  351. 'refresh' => SMOPT_REFRESH_NONE
  352. );
  353. $optvals[SMOPT_GRP_MESSAGE][] = array(
  354. 'name' => 'body_quote',
  355. 'caption' => _("Prefix for Original Message when Replying"),
  356. 'type' => SMOPT_TYPE_STRING,
  357. 'refresh' => SMOPT_REFRESH_NONE,
  358. 'size' => SMOPT_SIZE_TINY,
  359. 'save' => 'save_option_reply_prefix'
  360. );
  361. $optvals[SMOPT_GRP_MESSAGE][] = array(
  362. 'name' => 'reply_focus',
  363. 'caption' => _("Cursor Position when Replying"),
  364. 'type' => SMOPT_TYPE_STRLIST,
  365. 'refresh' => SMOPT_REFRESH_NONE,
  366. 'posvals' => array('' => _("To: field"),
  367. 'focus' => _("Focus in body"),
  368. 'select' => _("Select body"),
  369. 'none' => _("No focus"))
  370. );
  371. $optvals[SMOPT_GRP_MESSAGE][] = array(
  372. 'name' => 'strip_sigs',
  373. 'caption' => _("Strip signature when replying"),
  374. 'type' => SMOPT_TYPE_BOOLEAN,
  375. 'refresh' => SMOPT_REFRESH_NONE
  376. );
  377. $optvals[SMOPT_GRP_MESSAGE][] = array(
  378. 'name' => 'internal_date_sort',
  379. 'caption' => _("Enable Sort by of Receive Date"),
  380. 'type' => SMOPT_TYPE_BOOLEAN,
  381. 'refresh' => SMOPT_REFRESH_ALL
  382. );
  383. if ($allow_thread_sort == TRUE) {
  384. $optvals[SMOPT_GRP_MESSAGE][] = array(
  385. 'name' => 'sort_by_ref',
  386. 'caption' => _("Enable Thread Sort by References Header"),
  387. 'type' => SMOPT_TYPE_BOOLEAN,
  388. 'refresh' => SMOPT_REFRESH_ALL
  389. );
  390. $optvals[SMOPT_GRP_MESSAGE][] = array(
  391. 'name' => 'delete_prev_next_display',
  392. 'caption' => _("Show 'Delete & Prev/Next' Links"),
  393. 'type' => SMOPT_TYPE_BOOLEAN,
  394. 'refresh' => SMOPT_REFRESH_ALL
  395. );
  396. }
  397. /* Assemble all this together and return it as our result. */
  398. $result = array(
  399. 'grps' => $optgrps,
  400. 'vals' => $optvals
  401. );
  402. return ($result);
  403. }
  404. /******************************************************************/
  405. /** Define any specialized save functions for this option page. ***/
  406. /******************************************************************/
  407. function save_option_header($option) {
  408. }
  409. /**
  410. * This function saves a new theme setting.
  411. * It updates the theme array.
  412. */
  413. function save_option_theme($option) {
  414. global $theme;
  415. /* Do checking to make sure $new_theme is in the array. */
  416. $theme_in_array = false;
  417. for ($i = 0; $i < count($theme); ++$i) {
  418. if ($theme[$i]['PATH'] == $option->new_value) {
  419. $theme_in_array = true;
  420. break;
  421. }
  422. }
  423. if (!$theme_in_array) {
  424. $option->new_value = '';
  425. }
  426. /* Save the option like normal. */
  427. save_option($option);
  428. }
  429. /**
  430. * This function saves the javascript detection option.
  431. */
  432. function save_option_javascript_autodetect($option) {
  433. global $data_dir, $username;
  434. save_option($option);
  435. checkForJavascript(TRUE);
  436. }
  437. /**
  438. * This function saves the user's icon theme setting
  439. */
  440. function icon_theme_save($option) {
  441. global $icon_themes, $data_dir, $username;
  442. // Don't assume the new value is there, double check
  443. // and only save if found
  444. //
  445. if (isset($icon_themes[$option->new_value]['PATH']))
  446. setPref($data_dir, $username, 'icon_theme', $icon_themes[$option->new_value]['PATH']);
  447. else
  448. setPref($data_dir, $username, 'icon_theme', 'none');
  449. }
  450. /**
  451. * This function saves the reply prefix (body_quote) character(s)
  452. */
  453. function save_option_reply_prefix($option) {
  454. global $data_dir, $username, $new_javascript_setting;
  455. // save as "NONE" if it was blanked out
  456. //
  457. if (empty($option->new_value)) $option->new_value = 'NONE';
  458. // Save the option like normal.
  459. //
  460. save_option($option);
  461. }
  462. ?>