5c99590eaa21cb125693006a99f4088756a8af83
[squirrelmail.git] / include / options / personal.php
1 <?php
2
3 /**
4 * options_personal.php
5 *
6 * Displays all options relating to personal information
7 *
8 * @copyright 1999-2019 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** SquirrelMail required files. */
15 require_once(SM_PATH . 'include/timezones.php');
16
17 /* Define the group constants for the personal options page. */
18 define('SMOPT_GRP_CONTACT', 0);
19 define('SMOPT_GRP_REPLY', 1);
20 define('SMOPT_GRP_SIG', 2);
21 define('SMOPT_GRP_TZ', 3);
22
23 /**
24 * This function builds an array with all the information about
25 * the options available to the user, and returns it. The options
26 * are grouped by the groups in which they are displayed.
27 * For each option, the following information is stored:
28 * - name: the internal (variable) name
29 * - caption: the description of the option in the UI
30 * - type: one of SMOPT_TYPE_*
31 * - refresh: one of SMOPT_REFRESH_*
32 * - size: one of SMOPT_SIZE_*
33 * - save: the name of a function to call when saving this option
34 * @return array all option information
35 */
36 function load_optpage_data_personal() {
37 global $data_dir, $username, $edit_identity, $edit_name, $edit_reply_to,
38 $full_name, $reply_to, $email_address, $signature, $tzChangeAllowed,
39 $timeZone, $domain;
40
41 /* Set the values of some global variables. */
42 $full_name = getPref($data_dir, $username, 'full_name');
43 $reply_to = getPref($data_dir, $username, 'reply_to');
44 $email_address = getPref($data_dir, $username, 'email_address',SMPREF_NONE);
45 $signature = getSig($data_dir, $username, 'g');
46
47 // set email_address to default value, if it is not set in user's preferences
48 if ($email_address == SMPREF_NONE) {
49 if (preg_match("/(.+)@(.+)/",$username)) {
50 $email_address = $username;
51 } else {
52 $email_address = $username . '@' . $domain ;
53 }
54 }
55
56 /* Build a simple array into which we will build options. */
57 $optgrps = array();
58 $optvals = array();
59
60 /******************************************************/
61 /* LOAD EACH GROUP OF OPTIONS INTO THE OPTIONS ARRAY. */
62 /******************************************************/
63
64 /*** Load the Contact Information Options into the array ***/
65 $optgrps[SMOPT_GRP_CONTACT] = _("Name and Address Options");
66 $optvals[SMOPT_GRP_CONTACT] = array();
67
68 /* Build a simple array into which we will build options. */
69 $optvals = array();
70
71 if (!isset($edit_identity)) {
72 $edit_identity = TRUE;
73 }
74
75 if ($edit_identity || $edit_name) {
76 $optvals[SMOPT_GRP_CONTACT][] = array(
77 'name' => 'full_name',
78 'caption' => _("Full Name"),
79 'type' => SMOPT_TYPE_STRING,
80 'refresh' => SMOPT_REFRESH_NONE,
81 'size' => SMOPT_SIZE_HUGE
82 );
83 } else {
84 $optvals[SMOPT_GRP_CONTACT][] = array(
85 'name' => 'full_name',
86 'caption' => _("Full Name"),
87 'type' => SMOPT_TYPE_COMMENT,
88 'refresh' => SMOPT_REFRESH_NONE,
89 'comment' => $full_name
90 );
91 }
92
93 if ($edit_identity) {
94 $optvals[SMOPT_GRP_CONTACT][] = array(
95 'name' => 'email_address',
96 'caption' => _("E-mail Address"),
97 'type' => SMOPT_TYPE_STRING,
98 'refresh' => SMOPT_REFRESH_NONE,
99 'size' => SMOPT_SIZE_HUGE
100 );
101 } else {
102 $optvals[SMOPT_GRP_CONTACT][] = array(
103 'name' => 'email_address',
104 'caption' => _("E-mail Address"),
105 'type' => SMOPT_TYPE_COMMENT,
106 'refresh' => SMOPT_REFRESH_NONE,
107 'comment' => sm_encode_html_special_chars($email_address)
108 );
109 }
110
111 if ($edit_identity || $edit_reply_to) {
112 $optvals[SMOPT_GRP_CONTACT][] = array(
113 'name' => 'reply_to',
114 'caption' => _("Reply To"),
115 'type' => SMOPT_TYPE_STRING,
116 'refresh' => SMOPT_REFRESH_NONE,
117 'size' => SMOPT_SIZE_HUGE
118 );
119 } else {
120 //TODO: For many users, this is redundant to the email address above, especially if not editable -- so here instead of a comment, we could just hide it... in fact, that's what we'll do, but keep this code for posterity in case someone decides we shouldn't do this
121 /*
122 $optvals[SMOPT_GRP_CONTACT][] = array(
123 'name' => 'reply_to',
124 'caption' => _("Reply To"),
125 'type' => SMOPT_TYPE_COMMENT,
126 'refresh' => SMOPT_REFRESH_NONE,
127 'comment' => sm_encode_html_special_chars($reply_to),
128 );
129 */
130 }
131
132 $optvals[SMOPT_GRP_CONTACT][] = array(
133 'name' => 'signature',
134 'caption' => _("Signature"),
135 'type' => SMOPT_TYPE_TEXTAREA,
136 'refresh' => SMOPT_REFRESH_NONE,
137 'size' => SMOPT_SIZE_MEDIUM,
138 'save' => 'save_option_signature'
139 );
140
141 if ($edit_identity) {
142 $identities_link_value = '<a href="options_identities.php">'
143 . _("Edit Advanced Identities")
144 . '</a> '
145 . _("(discards changes made on this form so far)");
146 $optvals[SMOPT_GRP_CONTACT][] = array(
147 'name' => 'identities_link',
148 'caption' => _("Multiple Identities"),
149 'type' => SMOPT_TYPE_COMMENT,
150 'refresh' => SMOPT_REFRESH_NONE,
151 'comment' => $identities_link_value
152 );
153 }
154
155 if ( $tzChangeAllowed || function_exists('date_default_timezone_set')) {
156 $TZ_ARRAY[SMPREF_NONE] = _("Same as server");
157
158 $aTimeZones = sq_get_tz_array();
159 unset($message);
160 if (! empty($aTimeZones)) {
161 // check if current timezone is linked to other TZ and update it
162 if ($timeZone != SMPREF_NONE && $timeZone != "" &&
163 isset($aTimeZones[$timeZone]['LINK'])) {
164 $timeZone = $aTimeZones[$timeZone]['LINK'];
165 // TODO: recheck setting of $timeZone
166 // setPref($data_dir,$username,'timezone',$timeZone);
167 }
168
169 // sort time zones by name. sq_get_tz_array() returns sorted by key.
170 // asort($aTimeZones);
171
172 // add all 'TZ' entries to TZ_ARRAY
173 foreach ($aTimeZones as $TzKey => $TzData) {
174 if (! isset($TzData['LINK'])) {
175 // Old display format
176 $TZ_ARRAY[$TzKey] = $TzKey;
177
178 // US Eastern standard time (America/New_York) - needs asort($aTimeZones)
179 //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME']." ($TzKey)" : "($TzKey)");
180
181 // US Eastern standard time if NAME is present or America/New_York if NAME not present
182 // needs sorting after all data is added or uasort()
183 //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME'] : $TzKey);
184
185 // (America/New_Your) US Eastern standard time
186 //$TZ_ARRAY[$TzKey] = "($TzKey)" . (isset($TzData['NAME']) ? ' '.$TzData['NAME'] : '');
187 }
188 }
189 } else {
190 $message = _("Error opening timezone config, contact administrator.");
191 }
192
193 // TODO: make error user friendly
194 if (isset($message)) {
195 plain_error_message($message);
196 exit;
197 }
198
199 $optgrps[SMOPT_GRP_TZ] = _("Timezone Options");
200 $optvals[SMOPT_GRP_TZ] = array();
201
202 $optvals[SMOPT_GRP_TZ][] = array(
203 'name' => 'timezone',
204 'caption' => _("Your current timezone"),
205 'type' => SMOPT_TYPE_STRLIST,
206 'refresh' => SMOPT_REFRESH_NONE,
207 'posvals' => $TZ_ARRAY
208 );
209 }
210
211 /*** Load the Reply Citation Options into the array ***/
212 $optgrps[SMOPT_GRP_REPLY] = _("Reply Citation Options");
213 $optvals[SMOPT_GRP_REPLY] = array();
214
215 $optvals[SMOPT_GRP_REPLY][] = array(
216 'name' => 'reply_citation_style',
217 'caption' => _("Reply Citation Style"),
218 'type' => SMOPT_TYPE_STRLIST,
219 'refresh' => SMOPT_REFRESH_NONE,
220 'posvals' => array(SMPREF_NONE => _("No Citation"),
221 'author_said' => _("AUTHOR Wrote"),
222 'date_time_author' => _("On DATE, AUTHOR Wrote"),
223 'quote_who' => _("Quote Who XML"),
224 'user-defined' => _("User-Defined"))
225 );
226
227 $optvals[SMOPT_GRP_REPLY][] = array(
228 'name' => 'reply_citation_start',
229 'caption' => _("User-Defined Citation Start"),
230 'type' => SMOPT_TYPE_STRING,
231 'refresh' => SMOPT_REFRESH_NONE,
232 'size' => SMOPT_SIZE_MEDIUM
233 );
234
235 $optvals[SMOPT_GRP_REPLY][] = array(
236 'name' => 'reply_citation_end',
237 'caption' => _("User-Defined Citation End"),
238 'type' => SMOPT_TYPE_STRING,
239 'refresh' => SMOPT_REFRESH_NONE,
240 'size' => SMOPT_SIZE_MEDIUM
241 );
242
243 /*** Load the Signature Options into the array ***/
244 $optgrps[SMOPT_GRP_SIG] = _("Signature Options");
245 $optvals[SMOPT_GRP_SIG] = array();
246
247 $optvals[SMOPT_GRP_SIG][] = array(
248 'name' => 'use_signature',
249 'caption' => _("Use Signature"),
250 'type' => SMOPT_TYPE_BOOLEAN,
251 'refresh' => SMOPT_REFRESH_NONE
252 );
253
254 $optvals[SMOPT_GRP_SIG][] = array(
255 'name' => 'prefix_sig',
256 'caption' => _("Prefix Signature with '-- ' Line"),
257 'type' => SMOPT_TYPE_BOOLEAN,
258 'refresh' => SMOPT_REFRESH_NONE
259 );
260
261 /* Assemble all this together and return it as our result. */
262 $result = array(
263 'grps' => $optgrps,
264 'vals' => $optvals
265 );
266 return ($result);
267 }
268
269 /******************************************************************/
270 /** Define any specialized save functions for this option page. ***/
271 /******************************************************************/
272
273 /**
274 * Saves the signature option.
275 */
276 function save_option_signature($option) {
277 global $data_dir, $username;
278 setSig($data_dir, $username, 'g', $option->new_value);
279 }
280