Source for file options.php

Documentation is available at options.php

  1. <?php
  2. /**
  3. * options.php
  4. *
  5. * Displays the options page. Pulls from proper user preference files
  6. * and config.php. Displays preferences as selected and other options.
  7. *
  8. * @copyright 1999-2020 The SquirrelMail Project Team
  9. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10. * @version $Id: options.php 14845 2020年01月07日 08:09:34Z pdontthink $
  11. * @package squirrelmail
  12. * @subpackage prefs
  13. */
  14. /** This is the options page */
  15. define ('PAGE_NAME', 'options');
  16. /**
  17. * Include the SquirrelMail initialization file.
  18. */
  19. require('../include/init.php');
  20. /* SquirrelMail required files. */
  21. //include(SM_PATH . 'functions/imap_general.php');
  22. require_once(SM_PATH . 'functions/options.php');
  23. require_once(SM_PATH . 'functions/forms.php');
  24. /*********************************/
  25. /*** Build the resultant page. ***/
  26. /*********************************/
  27. define ('SMOPT_MODE_DISPLAY', 'display');
  28. define ('SMOPT_MODE_SUBMIT', 'submit');
  29. define ('SMOPT_MODE_LINK', 'link');
  30. define ('SMOPT_PAGE_MAIN', 'main');
  31. define ('SMOPT_PAGE_PERSONAL', 'personal');
  32. define ('SMOPT_PAGE_DISPLAY', 'display');
  33. define ('SMOPT_PAGE_COMPOSE', 'compose');
  34. define ('SMOPT_PAGE_ACCESSIBILITY', 'accessibility');
  35. define ('SMOPT_PAGE_HIGHLIGHT', 'highlight');
  36. define ('SMOPT_PAGE_FOLDER', 'folder');
  37. define ('SMOPT_PAGE_ORDER', 'order');
  38. /**
  39. * Save submitted options and calculate the most
  40. * we need to refresh the page
  41. *
  42. * @param string $optpage The name of the page being submitted
  43. * @param array $optpage_data An array of all the submitted options
  44. *
  45. * @return int The highest level of screen refresh needed per
  46. * the options that were changed. This value will
  47. * correspond to the SMOPT_REFRESH_* constants found
  48. * in functions/options.php.
  49. *
  50. */
  51. function process_optionmode_submit ($optpage, $optpage_data) {
  52. /* Initialize the maximum option refresh level. */
  53. $max_refresh = SMOPT_REFRESH_NONE ;
  54. /* Save each option in each option group. */
  55. foreach ($optpage_data['options'] as $option_grp) {
  56. foreach ($option_grp['options'] as $option) {
  57. /* Special case: need to make sure emailaddress
  58. * is saved if we use it as a test for ask_user_info */
  59. global $ask_user_info ;
  60. if ( $optpage = SMOPT_PAGE_PERSONAL && $ask_user_info &&
  61. $option->name == 'email_address' ) {
  62. $option->setValue('');
  63. }
  64. /* Remove Debug Mode Until Needed
  65. echo "name = '$option->name', "
  66. . "value = '$option->value', "
  67. . "new_value = '$option->new_value'\n";
  68. //FIXME: NO HTML IN THE CORE!
  69. echo "<br />";
  70. */
  71. if ($option->changed()) {
  72. $option->save();
  73. $max_refresh = max ($max_refresh, $option->refresh_level);
  74. }
  75. }
  76. }
  77. /* Return the max refresh level. */
  78. return ($max_refresh);
  79. }
  80. function process_optionmode_link ($optpage) {
  81. /* There will be something here, later. */
  82. }
  83. /* ---------------------------- main ---------------------------- */
  84. /* get the globals that we may need */
  85. sqgetGlobalVar ('optpage', $optpage);
  86. sqgetGlobalVar ('optmode', $optmode, SQ_FORM );
  87. sqgetGlobalVar ('optpage_data',$optpage_data, SQ_POST );
  88. sqgetGlobalVar ('smtoken', $submitted_token, SQ_FORM , '');
  89. /* end of getting globals */
  90. /* Make sure we have an Option Page set. Default to main. */
  91. if ( !isset($optpage) || $optpage == '' ) {
  92. $optpage = SMOPT_PAGE_MAIN ;
  93. } else {
  94. $optpage = strip_tags ( $optpage );
  95. }
  96. /* Make sure we have an Option Mode set. Default to display. */
  97. if (!isset($optmode)) {
  98. $optmode = SMOPT_MODE_DISPLAY ;
  99. }
  100. /*
  101. * First, set the load information for each option page.
  102. */
  103. /* Initialize load information variables. */
  104. $optpage_name = '';
  105. $optpage_file = '';
  106. $optpage_loader = '';
  107. /* Set the load information for each page. */
  108. switch ($optpage) {
  109. break;
  110. $optpage_name = _ ("Personal Information");
  111. $optpage_file = SM_PATH . 'include/options/personal.php';
  112. $optpage_loader = 'load_optpage_data_personal';
  113. $optpage_loadhook = 'optpage_loadhook_personal';
  114. break;
  115. $optpage_name = _ ("Display Preferences");
  116. $optpage_file = SM_PATH . 'include/options/display.php';
  117. $optpage_loader = 'load_optpage_data_display';
  118. $optpage_loadhook = 'optpage_loadhook_display';
  119. break;
  120. $optpage_name = _ ("Compose Preferences");
  121. $optpage_file = SM_PATH . 'include/options/compose.php';
  122. $optpage_loader = 'load_optpage_data_compose';
  123. $optpage_loadhook = 'optpage_loadhook_compose';
  124. break;
  125. $optpage_name = _ ("Accessibility Preferences");
  126. $optpage_file = SM_PATH . 'include/options/accessibility.php';
  127. $optpage_loader = 'load_optpage_data_accessibility';
  128. $optpage_loadhook = 'optpage_loadhook_accessibility';
  129. break;
  130. $optpage_name = _ ("Message Highlighting");
  131. $optpage_file = SM_PATH . 'include/options/highlight.php';
  132. $optpage_loader = 'load_optpage_data_highlight';
  133. $optpage_loadhook = 'optpage_loadhook_highlight';
  134. break;
  135. $optpage_name = _ ("Folder Preferences");
  136. $optpage_file = SM_PATH . 'include/options/folder.php';
  137. $optpage_loader = 'load_optpage_data_folder';
  138. $optpage_loadhook = 'optpage_loadhook_folder';
  139. break;
  140. $optpage_name = _ ("Index Order");
  141. $optpage_file = SM_PATH . 'include/options/order.php';
  142. $optpage_loader = 'load_optpage_data_order';
  143. $optpage_loadhook = 'optpage_loadhook_order';
  144. break;
  145. default: do_hook ('optpage_set_loadinfo', $null);
  146. }
  147. /**********************************************************/
  148. /*** Second, load the option information for this page. ***/
  149. /**********************************************************/
  150. if ( !@is_file ( $optpage_file ) ) {
  151. $optpage = SMOPT_PAGE_MAIN ;
  152. } elseif ($optpage != SMOPT_PAGE_MAIN ) {
  153. /* Include the file for this optionpage. */
  154. require_once($optpage_file);
  155. /* Assemble the data for this option page. */
  156. $optpage_data = array();
  157. $optpage_data = $optpage_loader();
  158. do_hook ($optpage_loadhook, $null);
  159. $optpage_data['options'] = create_option_groups ($optpage_data['grps'], $optpage_data['vals']);
  160. }
  161. /***********************************************************/
  162. /*** Next, process anything that needs to be processed. ***/
  163. /***********************************************************/
  164. // security check before saving anything...
  165. //FIXME: what about SMOPT_MODE_LINK??
  166. if ($optmode == SMOPT_MODE_SUBMIT ) {
  167. sm_validate_security_token ($submitted_token, -1, TRUE);
  168. }
  169. $optpage_save_error=array();
  170. if ( isset( $optpage_data ) ) {
  171. switch ($optmode) {
  172. $max_refresh = process_optionmode_submit ($optpage, $optpage_data);
  173. break;
  174. $max_refresh = process_optionmode_link ($optpage, $optpage_data);
  175. break;
  176. }
  177. }
  178. $optpage_title = _ ("Options");
  179. if (isset($optpage_name) && ($optpage_name != '')) {
  180. $optpage_title .= " - $optpage_name";
  181. }
  182. /*******************************************************************/
  183. /* DO OLD SAVING OF SUBMITTED OPTIONS. THIS WILL BE REMOVED LATER. */
  184. /*******************************************************************/
  185. //FIXME: let's remove these finally in 1.5.2..... but first, are there any plugins using them?
  186. /* If in submit mode, select a save hook name and run it. */
  187. if ($optmode == SMOPT_MODE_SUBMIT ) {
  188. /* Select a save hook name. */
  189. switch ($optpage) {
  190. $save_hook_name = 'options_personal_save';
  191. break;
  192. $save_hook_name = 'options_display_save';
  193. break;
  194. $save_hook_name = 'options_compose_save';
  195. break;
  196. $save_hook_name = 'options_accessibility_save';
  197. break;
  198. $save_hook_name = 'options_folder_save';
  199. break;
  200. default:
  201. $save_hook_name = 'options_save';
  202. break;
  203. }
  204. /* Run the options save hook. */
  205. do_hook ($save_hook_name, $null);
  206. }
  207. /***************************************************************/
  208. /* Apply logic to decide what optpage we want to display next. */
  209. /***************************************************************/
  210. /* If this is the result of an option page being submitted, then */
  211. /* show the main page. Otherwise, show whatever page was called. */
  212. if ($optmode == SMOPT_MODE_SUBMIT ) {
  213. $optpage = SMOPT_PAGE_MAIN ;
  214. $optpage_title = _ ("Options");
  215. }
  216. /***************************************************************/
  217. /* Finally, display whatever page we are supposed to show now. */
  218. /***************************************************************/
  219. displayPageHeader ($color, null, (isset($optpage_data['xtra']) ? $optpage_data['xtra'] : ''));
  220. /*
  221. * The main option page has a different layout then the rest of the option
  222. * pages. Therefore, we create it here first, then the others below.
  223. */
  224. if ($optpage == SMOPT_PAGE_MAIN ) {
  225. /**********************************************************/
  226. /* First, display the results of a submission, if needed. */
  227. /**********************************************************/
  228. $notice = '';
  229. if ($optmode == SMOPT_MODE_SUBMIT ) {
  230. if (!isset($frame_top)) {
  231. $frame_top = '_top';
  232. }
  233. if (isset($optpage_save_error) && $optpage_save_error!=array()) {
  234. //FIXME: REMOVE HTML FROM CORE
  235. $notice = _ ("Error(s) occurred while saving your options") . "<br />\n<ul>\n";
  236. foreach ($optpage_save_error as $error_message) {
  237. $notice.= '<li><small>' . $error_message . "</small></li>\n";
  238. }
  239. $notice.= "</ul>\n" . _ ("Some of your preference changes were not applied.") . "\n";
  240. } else {
  241. /* Display a message indicating a successful save. */
  242. // i18n: The %s represents the name of the option page saving the options
  243. $notice = sprintf (_ ("Successfully Saved Options: %s"), $optpage_name) . "<br />\n";
  244. }
  245. /* If $max_refresh != SMOPT_REFRESH_NONE, provide a refresh link. */
  246. if ( !isset( $max_refresh ) ) {
  247. } else if ($max_refresh == SMOPT_REFRESH_FOLDERLIST ) {
  248. //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the folder list is in a separate sibling frame under the same parent, and it is called "left"
  249. $notice .= sprintf (_ ("Folder list should automatically %srefresh%s."), '<a href="../src/left_main.php" target="left">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.left.location = '../src/left_main.php';\n// -->\n</script>\n";
  250. } else {
  251. $notice .= '<a href="../src/left_main.php" target="left">' . _ ("Refresh Folder List") . '</a><br />';
  252. }
  253. } else if ($max_refresh) {
  254. //FIXME: REMOVE HTML FROM CORE - when migrating, keep in mind that the javascript below assumes the parent is the top-most SM frame and is what should be refreshed with webmail.php
  255. $notice .= sprintf (_ ("This page should automatically %srefresh%s."), '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">', '</a>') . '<br /><script type="text/javascript">' . "\n<!--\nparent.location = '../src/webmail.php?right_frame=options.php';\n// -->\n</script>\n";
  256. } else {
  257. $notice .= '<a href="../src/webmail.php?right_frame=options.php" target="' . $frame_top . '">' . _ ("Refresh Page") . '</a><br />';
  258. }
  259. }
  260. }
  261. if (!empty($notice)) {
  262. $oTemplate->assign('note', $notice);
  263. $oTemplate->display('note.tpl');
  264. }
  265. /******************************************/
  266. /* Build our array of Option Page Blocks. */
  267. /******************************************/
  268. $optpage_blocks = array();
  269. // access keys...
  270. global $accesskey_options_personal, $accesskey_options_display,
  271. $accesskey_options_highlighting, $accesskey_options_folders,
  272. $accesskey_options_index_order, $accesskey_options_compose,
  273. $accesskey_options_accessibility;
  274. /* Build a section for Personal Options. */
  275. $optpage_blocks[] = array(
  276. 'name' => _ ("Personal Information"),
  277. 'url' => 'options.php?optpage=' . SMOPT_PAGE_PERSONAL ,
  278. 'desc' => _ ("This contains personal information about yourself such as your name, your email address, etc."),
  279. 'js' => false,
  280. 'accesskey' => $accesskey_options_personal,
  281. );
  282. /* Build a section for Display Options. */
  283. $optpage_blocks[] = array(
  284. 'name' => _ ("Display Preferences"),
  285. 'url' => 'options.php?optpage=' . SMOPT_PAGE_DISPLAY ,
  286. 'desc' => _ ("You can change the way that SquirrelMail looks and displays information to you, such as the colors, the language, and other settings."),
  287. 'js' => false,
  288. 'accesskey' => $accesskey_options_display,
  289. );
  290. /* Build a section for Message Highlighting Options. */
  291. $optpage_blocks[] = array(
  292. 'name' =>_ ("Message Highlighting"),
  293. 'url' => 'options_highlight.php',
  294. 'desc' =>_ ("Based upon given criteria, incoming messages can have different background colors in the message list. This helps to easily distinguish who the messages are from, especially for mailing lists."),
  295. 'js' => false,
  296. 'accesskey' => $accesskey_options_highlighting,
  297. );
  298. /* Build a section for Folder Options. */
  299. $optpage_blocks[] = array(
  300. 'name' => _ ("Folder Preferences"),
  301. 'url' => 'options.php?optpage=' . SMOPT_PAGE_FOLDER ,
  302. 'desc' => _ ("These settings change the way your folders are displayed and manipulated."),
  303. 'js' => false,
  304. 'accesskey' => $accesskey_options_folders,
  305. );
  306. /* Build a section for Index Order Options. */
  307. $optpage_blocks[] = array(
  308. 'name' => _ ("Index Order"),
  309. 'url' => 'options_order.php',
  310. 'desc' => _ ("The order of the message index can be rearranged and changed to contain the headers in any order you want."),
  311. 'js' => false,
  312. 'accesskey' => $accesskey_options_index_order,
  313. );
  314. /* Build a section for Compose Options. */
  315. $optpage_blocks[] = array(
  316. 'name' => _ ("Compose Preferences"),
  317. 'url' => 'options.php?optpage=' . SMOPT_PAGE_COMPOSE ,
  318. 'desc' => _ ("Control the behaviour and layout of writing new mail messages, replying to and forwarding messages."),
  319. 'js' => false,
  320. 'accesskey' => $accesskey_options_compose,
  321. );
  322. /* Build a section for Accessibility Options. */
  323. $optpage_blocks[] = array(
  324. 'name' => _ ("Accessibility Preferences"),
  325. 'url' => 'options.php?optpage=' . SMOPT_PAGE_ACCESSIBILITY ,
  326. 'desc' => _ ("You can configure features that improve interface usability."),
  327. 'js' => false,
  328. 'accesskey' => $accesskey_options_accessibility,
  329. );
  330. /* Build a section for plugins wanting to register an optionpage. */
  331. do_hook ('optpage_register_block', $null);
  332. /*****************************************************/
  333. /* Let's sort Javascript Option Pages to the bottom. */
  334. /*****************************************************/
  335. $js_optpage_blocks = array();
  336. $reg_optpage_blocks = array();
  337. foreach ($optpage_blocks as $cur_optpage) {
  338. if (!isset($cur_optpage['accesskey'])) {
  339. $cur_optpage['accesskey'] = 'NONE';
  340. }
  341. if (!isset($cur_optpage['js']) || !$cur_optpage['js']) {
  342. $reg_optpage_blocks[] = $cur_optpage;
  343. } else if (checkForJavascript ()) {
  344. $js_optpage_blocks[] = $cur_optpage;
  345. }
  346. }
  347. $optpage_blocks = array_merge ($reg_optpage_blocks, $js_optpage_blocks);
  348. /********************************************/
  349. /* Now, print out each option page section. */
  350. /********************************************/
  351. $oTemplate->assign('page_title', $optpage_title);
  352. $oTemplate->assign('options', $optpage_blocks);
  353. $oTemplate->display('option_groups.tpl');
  354. do_hook ('options_link_and_description', $null);
  355. /*************************************************************************/
  356. /* If we are not looking at the main option page, display the page here. */
  357. /*************************************************************************/
  358. } else {
  359. /* Set the bottom_hook_name and submit_name. */
  360. switch ($optpage) {
  361. $bottom_hook_name = 'options_personal_bottom';
  362. $submit_name = 'submit_personal';
  363. break;
  364. $bottom_hook_name = 'options_display_bottom';
  365. $submit_name = 'submit_display';
  366. break;
  367. $bottom_hook_name = 'options_compose_bottom';
  368. $submit_name = 'submit_compose';
  369. break;
  370. $bottom_hook_name = 'options_accessibility_bottom';
  371. $submit_name = 'submit_accessibility';
  372. break;
  373. $bottom_hook_name = 'options_highlight_bottom';
  374. $submit_name = 'submit_highlight';
  375. break;
  376. $bottom_hook_name = 'options_folder_bottom';
  377. $submit_name = 'submit_folder';
  378. break;
  379. $bottom_hook_name = 'options_order_bottom';
  380. $submit_name = 'submit_order';
  381. break;
  382. default:
  383. $bottom_hook_name = 'options_generic_bottom';
  384. $submit_name = 'submit';
  385. }
  386. // Begin output form
  387. echo addForm ('options.php', 'post', 'option_form', '', '', array(), TRUE)
  388. // This is the only variable that is needed by *just* the template.
  389. $oTemplate->assign('option_groups', $optpage_data['options']);
  390. global $ask_user_info, $org_name;
  391. if ( $optpage == SMOPT_PAGE_PERSONAL && $ask_user_info
  392. && getPref ($data_dir, $username,'email_address') == "" ) {
  393. $oTemplate->assign('topmessage',
  394. sprintf (_ ("Welcome to %s. Please supply your full name and email address."), $org_name) );
  395. }
  396. // These variables are not specifically needed by the template,
  397. // but they are relevant to the page being built, so we'll add
  398. // them in case some plugin is modifying the page, etc....
  399. //
  400. $oTemplate->assign('max_refresh', isset($max_refresh) ? $max_refresh : NULL);
  401. $oTemplate->assign('page_title', $optpage_title);
  402. $oTemplate->assign('optpage', $optpage);
  403. $oTemplate->assign('optpage_name', $optpage_name);
  404. $oTemplate->assign('optmode', $optmode);
  405. $oTemplate->assign('optpage_data', $optpage_data);
  406. $oTemplate->assign('submit_name', $submit_name);
  407. $oTemplate->display('options.tpl');
  408. $oTemplate->display('form_close.tpl');
  409. /* If it is not empty, trigger the bottom hook. */
  410. if ($bottom_hook_name != '') {
  411. do_hook ($bottom_hook_name, $null);
  412. }
  413. }
  414. $oTemplate->display('footer.tpl');

Documentation generated on 2020年1月13日 04:23:15 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /