personal.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. <?php
  2. /**
  3. * options_personal.php
  4. *
  5. * Displays all options relating to personal information
  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. /** SquirrelMail required files. */
  13. require_once(SM_PATH . 'include/timezones.php');
  14. /* Define the group constants for the personal options page. */
  15. define('SMOPT_GRP_CONTACT', 0);
  16. define('SMOPT_GRP_REPLY', 1);
  17. define('SMOPT_GRP_SIG', 2);
  18. define('SMOPT_GRP_TZ', 3);
  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_personal() {
  33. global $data_dir, $username, $edit_identity, $edit_name,
  34. $full_name, $reply_to, $email_address, $signature, $tzChangeAllowed,
  35. $timeZone, $domain;
  36. /* Set the values of some global variables. */
  37. $full_name = getPref($data_dir, $username, 'full_name');
  38. $reply_to = getPref($data_dir, $username, 'reply_to');
  39. $email_address = getPref($data_dir, $username, 'email_address',SMPREF_NONE);
  40. $signature = getSig($data_dir, $username, 'g');
  41. // set email_address to default value, if it is not set in user's preferences
  42. if ($email_address == SMPREF_NONE) {
  43. if (preg_match("/(.+)@(.+)/",$username)) {
  44. $email_address = $username;
  45. } else {
  46. $email_address = $username . '@' . $domain ;
  47. }
  48. }
  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 Contact Information Options into the array ***/
  56. $optgrps[SMOPT_GRP_CONTACT] = _("Name and Address Options");
  57. $optvals[SMOPT_GRP_CONTACT] = array();
  58. /* Build a simple array into which we will build options. */
  59. $optvals = array();
  60. if (!isset($edit_identity)) {
  61. $edit_identity = TRUE;
  62. }
  63. if ($edit_identity || $edit_name) {
  64. $optvals[SMOPT_GRP_CONTACT][] = array(
  65. 'name' => 'full_name',
  66. 'caption' => _("Full Name"),
  67. 'type' => SMOPT_TYPE_STRING,
  68. 'refresh' => SMOPT_REFRESH_NONE,
  69. 'size' => SMOPT_SIZE_HUGE
  70. );
  71. } else {
  72. $optvals[SMOPT_GRP_CONTACT][] = array(
  73. 'name' => 'full_name',
  74. 'caption' => _("Full Name"),
  75. 'type' => SMOPT_TYPE_COMMENT,
  76. 'refresh' => SMOPT_REFRESH_NONE,
  77. 'comment' => $full_name
  78. );
  79. }
  80. if ($edit_identity) {
  81. $optvals[SMOPT_GRP_CONTACT][] = array(
  82. 'name' => 'email_address',
  83. 'caption' => _("E-mail Address"),
  84. 'type' => SMOPT_TYPE_STRING,
  85. 'refresh' => SMOPT_REFRESH_NONE,
  86. 'size' => SMOPT_SIZE_HUGE
  87. );
  88. } else {
  89. $optvals[SMOPT_GRP_CONTACT][] = array(
  90. 'name' => 'email_address',
  91. 'caption' => _("E-mail Address"),
  92. 'type' => SMOPT_TYPE_COMMENT,
  93. 'refresh' => SMOPT_REFRESH_NONE,
  94. 'comment' => htmlspecialchars($email_address)
  95. );
  96. }
  97. $optvals[SMOPT_GRP_CONTACT][] = array(
  98. 'name' => 'reply_to',
  99. 'caption' => _("Reply To"),
  100. 'type' => SMOPT_TYPE_STRING,
  101. 'refresh' => SMOPT_REFRESH_NONE,
  102. 'size' => SMOPT_SIZE_HUGE
  103. );
  104. $optvals[SMOPT_GRP_CONTACT][] = array(
  105. 'name' => 'signature',
  106. 'caption' => _("Signature"),
  107. 'type' => SMOPT_TYPE_TEXTAREA,
  108. 'refresh' => SMOPT_REFRESH_NONE,
  109. 'size' => SMOPT_SIZE_MEDIUM,
  110. 'save' => 'save_option_signature'
  111. );
  112. if ($edit_identity) {
  113. $identities_link_value = '<a href="options_identities.php">'
  114. . _("Edit Advanced Identities")
  115. . '</a> '
  116. . _("(discards changes made on this form so far)");
  117. $optvals[SMOPT_GRP_CONTACT][] = array(
  118. 'name' => 'identities_link',
  119. 'caption' => _("Multiple Identities"),
  120. 'type' => SMOPT_TYPE_COMMENT,
  121. 'refresh' => SMOPT_REFRESH_NONE,
  122. 'comment' => $identities_link_value
  123. );
  124. }
  125. if ( $tzChangeAllowed || function_exists('date_default_timezone_set')) {
  126. $TZ_ARRAY[SMPREF_NONE] = _("Same as server");
  127. $aTimeZones = sq_get_tz_array();
  128. unset($message);
  129. if (! empty($aTimeZones)) {
  130. // check if current timezone is linked to other TZ and update it
  131. if ($timeZone != SMPREF_NONE && $timeZone != "" &&
  132. isset($aTimeZones[$timeZone]['LINK'])) {
  133. $timeZone = $aTimeZones[$timeZone]['LINK'];
  134. // TODO: recheck setting of $timeZone
  135. // setPref($data_dir,$username,'timezone',$timeZone);
  136. }
  137. // sort time zones by name. sq_get_tz_array() returns sorted by key.
  138. // asort($aTimeZones);
  139. // add all 'TZ' entries to TZ_ARRAY
  140. foreach ($aTimeZones as $TzKey => $TzData) {
  141. if (! isset($TzData['LINK'])) {
  142. // Old display format
  143. $TZ_ARRAY[$TzKey] = $TzKey;
  144. // US Eastern standard time (America/New_York) - needs asort($aTimeZones)
  145. //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME']." ($TzKey)" : "($TzKey)");
  146. // US Eastern standard time if NAME is present or America/New_York if NAME not present
  147. // needs sorting after all data is added or uasort()
  148. //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME'] : $TzKey);
  149. // (America/New_Your) US Eastern standard time
  150. //$TZ_ARRAY[$TzKey] = "($TzKey)" . (isset($TzData['NAME']) ? ' '.$TzData['NAME'] : '');
  151. }
  152. }
  153. } else {
  154. $message = _("Error opening timezone config, contact administrator.");
  155. }
  156. // TODO: make error user friendly
  157. if (isset($message)) {
  158. plain_error_message($message);
  159. exit;
  160. }
  161. $optgrps[SMOPT_GRP_TZ] = _("Timezone Options");
  162. $optvals[SMOPT_GRP_TZ] = array();
  163. $optvals[SMOPT_GRP_TZ][] = array(
  164. 'name' => 'timezone',
  165. 'caption' => _("Your current timezone"),
  166. 'type' => SMOPT_TYPE_STRLIST,
  167. 'refresh' => SMOPT_REFRESH_NONE,
  168. 'posvals' => $TZ_ARRAY
  169. );
  170. }
  171. /*** Load the Reply Citation Options into the array ***/
  172. $optgrps[SMOPT_GRP_REPLY] = _("Reply Citation Options");
  173. $optvals[SMOPT_GRP_REPLY] = array();
  174. $optvals[SMOPT_GRP_REPLY][] = array(
  175. 'name' => 'reply_citation_style',
  176. 'caption' => _("Reply Citation Style"),
  177. 'type' => SMOPT_TYPE_STRLIST,
  178. 'refresh' => SMOPT_REFRESH_NONE,
  179. 'posvals' => array(SMPREF_NONE => _("No Citation"),
  180. 'author_said' => _("AUTHOR Wrote"),
  181. 'date_time_author' => _("On DATE, AUTHOR Wrote"),
  182. 'quote_who' => _("Quote Who XML"),
  183. 'user-defined' => _("User-Defined"))
  184. );
  185. $optvals[SMOPT_GRP_REPLY][] = array(
  186. 'name' => 'reply_citation_start',
  187. 'caption' => _("User-Defined Citation Start"),
  188. 'type' => SMOPT_TYPE_STRING,
  189. 'refresh' => SMOPT_REFRESH_NONE,
  190. 'size' => SMOPT_SIZE_MEDIUM
  191. );
  192. $optvals[SMOPT_GRP_REPLY][] = array(
  193. 'name' => 'reply_citation_end',
  194. 'caption' => _("User-Defined Citation End"),
  195. 'type' => SMOPT_TYPE_STRING,
  196. 'refresh' => SMOPT_REFRESH_NONE,
  197. 'size' => SMOPT_SIZE_MEDIUM
  198. );
  199. /*** Load the Signature Options into the array ***/
  200. $optgrps[SMOPT_GRP_SIG] = _("Signature Options");
  201. $optvals[SMOPT_GRP_SIG] = array();
  202. $optvals[SMOPT_GRP_SIG][] = array(
  203. 'name' => 'use_signature',
  204. 'caption' => _("Use Signature"),
  205. 'type' => SMOPT_TYPE_BOOLEAN,
  206. 'refresh' => SMOPT_REFRESH_NONE
  207. );
  208. $optvals[SMOPT_GRP_SIG][] = array(
  209. 'name' => 'prefix_sig',
  210. 'caption' => _("Prefix Signature with '-- ' Line"),
  211. 'type' => SMOPT_TYPE_BOOLEAN,
  212. 'refresh' => SMOPT_REFRESH_NONE
  213. );
  214. /* Assemble all this together and return it as our result. */
  215. $result = array(
  216. 'grps' => $optgrps,
  217. 'vals' => $optvals
  218. );
  219. return ($result);
  220. }
  221. /******************************************************************/
  222. /** Define any specialized save functions for this option page. ***/
  223. /******************************************************************/
  224. /**
  225. * Saves the signature option.
  226. */
  227. function save_option_signature($option) {
  228. global $data_dir, $username;
  229. setSig($data_dir, $username, 'g', $option->new_value);
  230. }