Add option that allows users to have replies to their own messages sent to the recipi...
[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-2012 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,
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' => htmlspecialchars($email_address)
108 );
109 }
110
111 $optvals[SMOPT_GRP_CONTACT][] = array(
112 'name' => 'reply_to',
113 'caption' => _("Reply To"),
114 'type' => SMOPT_TYPE_STRING,
115 'refresh' => SMOPT_REFRESH_NONE,
116 'size' => SMOPT_SIZE_HUGE
117 );
118
119 $optvals[SMOPT_GRP_CONTACT][] = array(
120 'name' => 'signature',
121 'caption' => _("Signature"),
122 'type' => SMOPT_TYPE_TEXTAREA,
123 'refresh' => SMOPT_REFRESH_NONE,
124 'size' => SMOPT_SIZE_MEDIUM,
125 'save' => 'save_option_signature'
126 );
127
128 if ($edit_identity) {
129 $identities_link_value = '<a href="options_identities.php">'
130 . _("Edit Advanced Identities")
131 . '</a> '
132 . _("(discards changes made on this form so far)");
133 $optvals[SMOPT_GRP_CONTACT][] = array(
134 'name' => 'identities_link',
135 'caption' => _("Multiple Identities"),
136 'type' => SMOPT_TYPE_COMMENT,
137 'refresh' => SMOPT_REFRESH_NONE,
138 'comment' => $identities_link_value
139 );
140 }
141
142 if ( $tzChangeAllowed || function_exists('date_default_timezone_set')) {
143 $TZ_ARRAY[SMPREF_NONE] = _("Same as server");
144
145 $aTimeZones = sq_get_tz_array();
146 unset($message);
147 if (! empty($aTimeZones)) {
148 // check if current timezone is linked to other TZ and update it
149 if ($timeZone != SMPREF_NONE && $timeZone != "" &&
150 isset($aTimeZones[$timeZone]['LINK'])) {
151 $timeZone = $aTimeZones[$timeZone]['LINK'];
152 // TODO: recheck setting of $timeZone
153 // setPref($data_dir,$username,'timezone',$timeZone);
154 }
155
156 // sort time zones by name. sq_get_tz_array() returns sorted by key.
157 // asort($aTimeZones);
158
159 // add all 'TZ' entries to TZ_ARRAY
160 foreach ($aTimeZones as $TzKey => $TzData) {
161 if (! isset($TzData['LINK'])) {
162 // Old display format
163 $TZ_ARRAY[$TzKey] = $TzKey;
164
165 // US Eastern standard time (America/New_York) - needs asort($aTimeZones)
166 //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME']." ($TzKey)" : "($TzKey)");
167
168 // US Eastern standard time if NAME is present or America/New_York if NAME not present
169 // needs sorting after all data is added or uasort()
170 //$TZ_ARRAY[$TzKey] = (isset($TzData['NAME']) ? $TzData['NAME'] : $TzKey);
171
172 // (America/New_Your) US Eastern standard time
173 //$TZ_ARRAY[$TzKey] = "($TzKey)" . (isset($TzData['NAME']) ? ' '.$TzData['NAME'] : '');
174 }
175 }
176 } else {
177 $message = _("Error opening timezone config, contact administrator.");
178 }
179
180 // TODO: make error user friendly
181 if (isset($message)) {
182 plain_error_message($message);
183 exit;
184 }
185
186 $optgrps[SMOPT_GRP_TZ] = _("Timezone Options");
187 $optvals[SMOPT_GRP_TZ] = array();
188
189 $optvals[SMOPT_GRP_TZ][] = array(
190 'name' => 'timezone',
191 'caption' => _("Your current timezone"),
192 'type' => SMOPT_TYPE_STRLIST,
193 'refresh' => SMOPT_REFRESH_NONE,
194 'posvals' => $TZ_ARRAY
195 );
196 }
197
198 /*** Load the Reply Citation Options into the array ***/
199 $optgrps[SMOPT_GRP_REPLY] = _("Reply Citation Options");
200 $optvals[SMOPT_GRP_REPLY] = array();
201
202 $optvals[SMOPT_GRP_REPLY][] = array(
203 'name' => 'reply_citation_style',
204 'caption' => _("Reply Citation Style"),
205 'type' => SMOPT_TYPE_STRLIST,
206 'refresh' => SMOPT_REFRESH_NONE,
207 'posvals' => array(SMPREF_NONE => _("No Citation"),
208 'author_said' => _("AUTHOR Wrote"),
209 'date_time_author' => _("On DATE, AUTHOR Wrote"),
210 'quote_who' => _("Quote Who XML"),
211 'user-defined' => _("User-Defined"))
212 );
213
214 $optvals[SMOPT_GRP_REPLY][] = array(
215 'name' => 'reply_citation_start',
216 'caption' => _("User-Defined Citation Start"),
217 'type' => SMOPT_TYPE_STRING,
218 'refresh' => SMOPT_REFRESH_NONE,
219 'size' => SMOPT_SIZE_MEDIUM
220 );
221
222 $optvals[SMOPT_GRP_REPLY][] = array(
223 'name' => 'reply_citation_end',
224 'caption' => _("User-Defined Citation End"),
225 'type' => SMOPT_TYPE_STRING,
226 'refresh' => SMOPT_REFRESH_NONE,
227 'size' => SMOPT_SIZE_MEDIUM
228 );
229
230 /*** Load the Signature Options into the array ***/
231 $optgrps[SMOPT_GRP_SIG] = _("Signature Options");
232 $optvals[SMOPT_GRP_SIG] = array();
233
234 $optvals[SMOPT_GRP_SIG][] = array(
235 'name' => 'use_signature',
236 'caption' => _("Use Signature"),
237 'type' => SMOPT_TYPE_BOOLEAN,
238 'refresh' => SMOPT_REFRESH_NONE
239 );
240
241 $optvals[SMOPT_GRP_SIG][] = array(
242 'name' => 'prefix_sig',
243 'caption' => _("Prefix Signature with '-- ' Line"),
244 'type' => SMOPT_TYPE_BOOLEAN,
245 'refresh' => SMOPT_REFRESH_NONE
246 );
247
248 /* Assemble all this together and return it as our result. */
249 $result = array(
250 'grps' => $optgrps,
251 'vals' => $optvals
252 );
253 return ($result);
254 }
255
256 /******************************************************************/
257 /** Define any specialized save functions for this option page. ***/
258 /******************************************************************/
259
260 /**
261 * Saves the signature option.
262 */
263 function save_option_signature($option) {
264 global $data_dir, $username;
265 setSig($data_dir, $username, 'g', $option->new_value);
266 }
267