5
* @version $Id: ucp_prefs.php,v 1.54 2007/10/05 14:36:34 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
21
* Changing user preferences
28
function main($id, $mode)
30
global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
32
$submit = (isset($_POST['submit'])) ? true : false;
33
$error = $data = array();
34
$s_hidden_fields = '';
39
add_form_key('ucp_prefs_personal');
41
'notifymethod' => request_var('notifymethod', $user->data['user_notify_type']),
42
'dateformat' => request_var('dateformat', $user->data['user_dateformat'], true),
43
'lang' => basename(request_var('lang', $user->data['user_lang'])),
44
'style' => request_var('style', (int) $user->data['user_style']),
45
'tz' => request_var('tz', (float) $user->data['user_timezone']),
47
'dst' => request_var('dst', (bool) $user->data['user_dst']),
48
'viewemail' => request_var('viewemail', (bool) $user->data['user_allow_viewemail']),
49
'massemail' => request_var('massemail', (bool) $user->data['user_allow_massemail']),
50
'hideonline' => request_var('hideonline', (bool) !$user->data['user_allow_viewonline']),
51
'notifypm' => request_var('notifypm', (bool) $user->data['user_notify_pm']),
52
'popuppm' => request_var('popuppm', (bool) $user->optionget('popuppm')),
53
'allowpm' => request_var('allowpm', (bool) $user->data['user_allow_pm']),
58
$data['style'] = ($config['override_user_style']) ? $config['default_style'] : $data['style'];
60
$error = validate_data($data, array(
61
'dateformat' => array('string', false, 1, 30),
62
'lang' => array('match', false, '#^[a-z0-9_\-]{2,}$#i'),
63
'tz' => array('num', false, -14, 14),
66
if (!check_form_key('ucp_prefs_personal'))
68
$error[] = 'FORM_INVALID';
73
$user->optionset('popuppm', $data['popuppm']);
76
'user_allow_pm' => $data['allowpm'],
77
'user_allow_viewemail' => $data['viewemail'],
78
'user_allow_massemail' => $data['massemail'],
79
'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'],
80
'user_notify_type' => $data['notifymethod'],
81
'user_notify_pm' => $data['notifypm'],
82
'user_options' => $user->data['user_options'],
84
'user_dst' => $data['dst'],
85
'user_dateformat' => $data['dateformat'],
86
'user_lang' => $data['lang'],
87
'user_timezone' => $data['tz'],
88
'user_style' => $data['style'],
91
$sql = 'UPDATE ' . USERS_TABLE . '
92
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
93
WHERE user_id = ' . $user->data['user_id'];
96
meta_refresh(3, $this->u_action);
97
$message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
98
trigger_error($message);
101
// Replace "error" strings with their real, localised form
102
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
105
$dateformat_options = '';
107
foreach ($user->lang['dateformats'] as $format => $null)
109
$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
110
$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
111
$dateformat_options .= '</option>';
116
$dateformat_options .= '<option value="custom"';
117
if (!in_array($data['dateformat'], array_keys($user->lang['dateformats'])))
119
$dateformat_options .= ' selected="selected"';
122
$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
124
$template->assign_vars(array(
125
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
127
'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
128
'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
129
'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
130
'S_VIEW_EMAIL' => $data['viewemail'],
131
'S_MASS_EMAIL' => $data['massemail'],
132
'S_ALLOW_PM' => $data['allowpm'],
133
'S_HIDE_ONLINE' => $data['hideonline'],
134
'S_NOTIFY_PM' => $data['notifypm'],
135
'S_POPUP_PM' => $data['popuppm'],
136
'S_DST' => $data['dst'],
138
'DATE_FORMAT' => $data['dateformat'],
139
'A_DATE_FORMAT' => addslashes($data['dateformat']),
140
'S_DATEFORMAT_OPTIONS' => $dateformat_options,
141
'S_CUSTOM_DATEFORMAT' => $s_custom,
142
'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
143
'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
145
'S_LANG_OPTIONS' => language_select($data['lang']),
146
'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']),
147
'S_TZ_OPTIONS' => tz_select($data['tz'], true),
148
'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false,
149
'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
156
add_form_key('ucp_prefs_view');
159
'topic_sk' => request_var('topic_sk', (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'),
160
'topic_sd' => request_var('topic_sd', (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'),
161
'topic_st' => request_var('topic_st', (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0),
163
'post_sk' => request_var('post_sk', (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'),
164
'post_sd' => request_var('post_sd', (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'),
165
'post_st' => request_var('post_st', (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0),
167
'images' => request_var('images', (bool) $user->optionget('viewimg')),
168
'flash' => request_var('flash', (bool) $user->optionget('viewflash')),
169
'smilies' => request_var('smilies', (bool) $user->optionget('viewsmilies')),
170
'sigs' => request_var('sigs', (bool) $user->optionget('viewsigs')),
171
'avatars' => request_var('avatars', (bool) $user->optionget('viewavatars')),
172
'wordcensor' => request_var('wordcensor', (bool) $user->optionget('viewcensors')),
177
$error = validate_data($data, array(
178
'topic_sk' => array('string', false, 1, 1),
179
'topic_sd' => array('string', false, 1, 1),
180
'post_sk' => array('string', false, 1, 1),
181
'post_sd' => array('string', false, 1, 1),
184
if (!check_form_key('ucp_prefs_view'))
186
$error[] = 'FORM_INVALID';
191
$user->optionset('viewimg', $data['images']);
192
$user->optionset('viewflash', $data['flash']);
193
$user->optionset('viewsmilies', $data['smilies']);
194
$user->optionset('viewsigs', $data['sigs']);
195
$user->optionset('viewavatars', $data['avatars']);
197
if ($auth->acl_get('u_chgcensors'))
199
$user->optionset('viewcensors', $data['wordcensor']);
203
'user_options' => $user->data['user_options'],
204
'user_topic_sortby_type' => $data['topic_sk'],
205
'user_post_sortby_type' => $data['post_sk'],
206
'user_topic_sortby_dir' => $data['topic_sd'],
207
'user_post_sortby_dir' => $data['post_sd'],
209
'user_topic_show_days' => $data['topic_st'],
210
'user_post_show_days' => $data['post_st'],
213
$sql = 'UPDATE ' . USERS_TABLE . '
214
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
215
WHERE user_id = ' . $user->data['user_id'];
216
$db->sql_query($sql);
218
meta_refresh(3, $this->u_action);
219
$message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
220
trigger_error($message);
223
// Replace "error" strings with their real, localised form
224
$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
227
$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
229
// Topic ordering options
230
$limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
232
$sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
233
$sort_by_topic_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'r' => 't.topic_replies', 's' => 't.topic_title', 'v' => 't.topic_views');
235
// Post ordering options
236
$limit_post_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
238
$sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
239
$sort_by_post_sql = array('a' => 'u.username_clean', 't' => 'p.post_id', 's' => 'p.post_subject');
241
$_options = array('topic', 'post');
242
foreach ($_options as $sort_option)
244
${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
245
foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
247
$selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
248
${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
250
${'s_limit_' . $sort_option . '_days'} .= '</select>';
252
${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
253
foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
255
$selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
256
${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
258
${'s_sort_' . $sort_option . '_key'} .= '</select>';
260
${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
261
foreach ($sort_dir_text as $key => $value)
263
$selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
264
${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
266
${'s_sort_' . $sort_option . '_dir'} .= '</select>';
269
$template->assign_vars(array(
270
'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
272
'S_IMAGES' => $data['images'],
273
'S_FLASH' => $data['flash'],
274
'S_SMILIES' => $data['smilies'],
275
'S_SIGS' => $data['sigs'],
276
'S_AVATARS' => $data['avatars'],
277
'S_DISABLE_CENSORS' => $data['wordcensor'],
279
'S_CHANGE_CENSORS' => ($auth->acl_get('u_chgcensors')) ? true : false,
281
'S_TOPIC_SORT_DAYS' => $s_limit_topic_days,
282
'S_TOPIC_SORT_KEY' => $s_sort_topic_key,
283
'S_TOPIC_SORT_DIR' => $s_sort_topic_dir,
284
'S_POST_SORT_DAYS' => $s_limit_post_days,
285
'S_POST_SORT_KEY' => $s_sort_post_key,
286
'S_POST_SORT_DIR' => $s_sort_post_dir)
294
'bbcode' => request_var('bbcode', $user->optionget('bbcode')),
295
'smilies' => request_var('smilies', $user->optionget('smilies')),
296
'sig' => request_var('sig', $user->optionget('attachsig')),
297
'notify' => request_var('notify', $user->data['user_notify']),
299
add_form_key('ucp_prefs_post');
303
if (check_form_key('ucp_prefs_post'))
305
$user->optionset('bbcode', $data['bbcode']);
306
$user->optionset('smilies', $data['smilies']);
307
$user->optionset('attachsig', $data['sig']);
310
'user_options' => $user->data['user_options'],
311
'user_notify' => $data['notify'],
314
$sql = 'UPDATE ' . USERS_TABLE . '
315
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
316
WHERE user_id = ' . $user->data['user_id'];
317
$db->sql_query($sql);
319
$msg = $user->lang['PREFERENCES_UPDATED'];
323
$msg = $user->lang['FORM_INVALID'];
325
meta_refresh(3, $this->u_action);
326
$message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
327
trigger_error($message);
330
$template->assign_vars(array(
331
'S_BBCODE' => $data['bbcode'],
332
'S_SMILIES' => $data['smilies'],
333
'S_SIG' => $data['sig'],
334
'S_NOTIFY' => $data['notify'])
339
$template->assign_vars(array(
340
'L_TITLE' => $user->lang['UCP_PREFS_' . strtoupper($mode)],
342
'S_HIDDEN_FIELDS' => $s_hidden_fields,
343
'S_UCP_ACTION' => $this->u_action)
346
$this->tpl_name = 'ucp_prefs_' . $mode;
347
$this->page_title = 'UCP_PREFS_' . strtoupper($mode);
b'\\ No newline at end of file'