c36ed9cf |
1 | <?php |
cd2b7182 |
2 | |
35586184 |
3 | /** |
4 | * options_personal.php |
5 | * |
35586184 |
6 | * Displays all options relating to personal information |
7 | * |
353d074a |
8 | * @copyright 1999-2018 The SquirrelMail Project Team |
4b4abf93 |
9 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
763b63fe |
10 | * @version $Id$ |
2b646597 |
11 | * @package squirrelmail |
35586184 |
12 | */ |
cbe5423b |
13 | |
2b646597 |
14 | /** SquirrelMail required files. */ |
2d3a630b |
15 | require_once(SM_PATH . 'include/timezones.php'); |
01265fba |
16 | |
cbe5423b |
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); |
397ddb13 |
21 | define('SMOPT_GRP_TZ', 3); |
cbe5423b |
22 | |
48af4b64 |
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 | */ |
cbe5423b |
36 | function load_optpage_data_personal() { |
3f7a756d |
37 | global $data_dir, $username, $edit_identity, $edit_name, $edit_reply_to, |
df442a10 |
38 | $full_name, $reply_to, $email_address, $signature, $tzChangeAllowed, |
ce8c6f42 |
39 | $timeZone, $domain; |
cbe5423b |
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'); |
8d6a0eb2 |
44 | $email_address = getPref($data_dir, $username, 'email_address',SMPREF_NONE); |
01265fba |
45 | $signature = getSig($data_dir, $username, 'g'); |
8d6a0eb2 |
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 | } |
bbcafebd |
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 | /******************************************************/ |
bbcafebd |
63 | |
8a2e4d5b |
64 | /*** Load the Contact Information Options into the array ***/ |
bbcafebd |
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 | |
26e2d3ef |
71 | if (!isset($edit_identity)) { |
72 | $edit_identity = TRUE; |
73 | } |
74 | |
8a7d0669 |
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 | } |
bbcafebd |
92 | |
8a7d0669 |
93 | if ($edit_identity) { |
94 | $optvals[SMOPT_GRP_CONTACT][] = array( |
95 | 'name' => 'email_address', |
674a2ca2 |
96 | 'caption' => _("E-mail Address"), |
8a7d0669 |
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', |
674a2ca2 |
104 | 'caption' => _("E-mail Address"), |
8a7d0669 |
105 | 'type' => SMOPT_TYPE_COMMENT, |
106 | 'refresh' => SMOPT_REFRESH_NONE, |
3047e291 |
107 | 'comment' => sm_encode_html_special_chars($email_address) |
8a7d0669 |
108 | ); |
109 | } |
bbcafebd |
110 | |
3f7a756d |
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 | } |
bbcafebd |
131 | |
01265fba |
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 | |
8a7d0669 |
141 | if ($edit_identity) { |
6fd95361 |
142 | $identities_link_value = '<a href="options_identities.php">' |
8a7d0669 |
143 | . _("Edit Advanced Identities") |
6fd95361 |
144 | . '</a> ' |
8a7d0669 |
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 | } |
91e0dccc |
154 | |
867fed37 |
155 | if ( $tzChangeAllowed || function_exists('date_default_timezone_set')) { |
4b50568d |
156 | $TZ_ARRAY[SMPREF_NONE] = _("Same as server"); |
2d3a630b |
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 { |
bb7173fa |
190 | $message = _("Error opening timezone config, contact administrator."); |
191 | } |
2d3a630b |
192 | |
193 | // TODO: make error user friendly |
bb7173fa |
194 | if (isset($message)) { |
ce8c6f42 |
195 | plain_error_message($message); |
bb7173fa |
196 | exit; |
197 | } |
7e235a1a |
198 | |
4b50568d |
199 | $optgrps[SMOPT_GRP_TZ] = _("Timezone Options"); |
200 | $optvals[SMOPT_GRP_TZ] = array(); |
7e235a1a |
201 | |
4b50568d |
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 | } |
91e0dccc |
210 | |
8a2e4d5b |
211 | /*** Load the Reply Citation Options into the array ***/ |
212 | $optgrps[SMOPT_GRP_REPLY] = _("Reply Citation Options"); |
bbcafebd |
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"), |
0e1a248b |
221 | 'author_said' => _("AUTHOR Wrote"), |
222 | 'date_time_author' => _("On DATE, AUTHOR Wrote"), |
bbcafebd |
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 | |
8a2e4d5b |
243 | /*** Load the Signature Options into the array ***/ |
244 | $optgrps[SMOPT_GRP_SIG] = _("Signature Options"); |
245 | $optvals[SMOPT_GRP_SIG] = array(); |
bbcafebd |
246 | |
8a2e4d5b |
247 | $optvals[SMOPT_GRP_SIG][] = array( |
bbcafebd |
248 | 'name' => 'use_signature', |
249 | 'caption' => _("Use Signature"), |
250 | 'type' => SMOPT_TYPE_BOOLEAN, |
251 | 'refresh' => SMOPT_REFRESH_NONE |
252 | ); |
253 | |
8a2e4d5b |
254 | $optvals[SMOPT_GRP_SIG][] = array( |
bbcafebd |
255 | 'name' => 'prefix_sig', |
256 | 'caption' => _("Prefix Signature with '-- ' Line"), |
257 | 'type' => SMOPT_TYPE_BOOLEAN, |
258 | 'refresh' => SMOPT_REFRESH_NONE |
259 | ); |
260 | |
cbe5423b |
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 | } |
e7db48af |
268 | |
cbe5423b |
269 | /******************************************************************/ |
270 | /** Define any specialized save functions for this option page. ***/ |
271 | /******************************************************************/ |
e7db48af |
272 | |
48af4b64 |
273 | /** |
274 | * Saves the signature option. |
275 | */ |
cbe5423b |
276 | function save_option_signature($option) { |
277 | global $data_dir, $username; |
01265fba |
278 | setSig($data_dir, $username, 'g', $option->new_value); |
cbe5423b |
279 | } |
209e24bb |
280 | |