source: trunk/forum/includes/ucp/ucp_prefs.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 13.9 KB
Line 
1<?php
2/**
3*
4* @package ucp
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14if (!defined('IN_PHPBB'))
15{
16 exit;
17}
18
19/**
20* ucp_prefs
21* Changing user preferences
22* @package ucp
23*/
24class ucp_prefs
25{
26 var $u_action;
27
28 function main($id, $mode)
29 {
30 global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx;
31
32 $submit = (isset($_POST['submit'])) ? true : false;
33 $error = $data = array();
34 $s_hidden_fields = '';
35
36 switch ($mode)
37 {
38 case 'personal':
39 add_form_key('ucp_prefs_personal');
40 $data = array(
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']),
46
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']),
54 );
55
56 if ($data['notifymethod'] == NOTIFY_IM && (!$config['jab_enable'] || !$user->data['user_jabber'] || !@extension_loaded('xml')))
57 {
58 // Jabber isnt enabled, or no jabber field filled in. Update the users table to be sure its correct.
59 $data['notifymethod'] = NOTIFY_BOTH;
60 }
61
62 if ($submit)
63 {
64 $data['style'] = ($config['override_user_style']) ? $config['default_style'] : $data['style'];
65
66 $error = validate_data($data, array(
67 'dateformat' => array('string', false, 1, 30),
68 'lang' => array('match', false, '#^[a-z0-9_\-]{2,}$#i'),
69 'tz' => array('num', false, -14, 14),
70 ));
71
72 if (!check_form_key('ucp_prefs_personal'))
73 {
74 $error[] = 'FORM_INVALID';
75 }
76
77 if (!sizeof($error))
78 {
79 $user->optionset('popuppm', $data['popuppm']);
80
81 $sql_ary = array(
82 'user_allow_pm' => $data['allowpm'],
83 'user_allow_viewemail' => $data['viewemail'],
84 'user_allow_massemail' => $data['massemail'],
85 'user_allow_viewonline' => ($auth->acl_get('u_hideonline')) ? !$data['hideonline'] : $user->data['user_allow_viewonline'],
86 'user_notify_type' => $data['notifymethod'],
87 'user_notify_pm' => $data['notifypm'],
88 'user_options' => $user->data['user_options'],
89
90 'user_dst' => $data['dst'],
91 'user_dateformat' => $data['dateformat'],
92 'user_lang' => $data['lang'],
93 'user_timezone' => $data['tz'],
94 'user_style' => $data['style'],
95 );
96
97 $sql = 'UPDATE ' . USERS_TABLE . '
98 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
99 WHERE user_id = ' . $user->data['user_id'];
100 $db->sql_query($sql);
101
102 meta_refresh(3, $this->u_action);
103 $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
104 trigger_error($message);
105 }
106
107 // Replace "error" strings with their real, localised form
108 $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
109 }
110
111 $dateformat_options = '';
112
113 foreach ($user->lang['dateformats'] as $format => $null)
114 {
115 $dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
116 $dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
117 $dateformat_options .= '</option>';
118 }
119
120 $s_custom = false;
121
122 $dateformat_options .= '<option value="custom"';
123 if (!isset($user->lang['dateformats'][$data['dateformat']]))
124 {
125 $dateformat_options .= ' selected="selected"';
126 $s_custom = true;
127 }
128 $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
129
130 $template->assign_vars(array(
131 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
132
133 'S_NOTIFY_EMAIL' => ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
134 'S_NOTIFY_IM' => ($data['notifymethod'] == NOTIFY_IM) ? true : false,
135 'S_NOTIFY_BOTH' => ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
136 'S_VIEW_EMAIL' => $data['viewemail'],
137 'S_MASS_EMAIL' => $data['massemail'],
138 'S_ALLOW_PM' => $data['allowpm'],
139 'S_HIDE_ONLINE' => $data['hideonline'],
140 'S_NOTIFY_PM' => $data['notifypm'],
141 'S_POPUP_PM' => $data['popuppm'],
142 'S_DST' => $data['dst'],
143
144 'DATE_FORMAT' => $data['dateformat'],
145 'A_DATE_FORMAT' => addslashes($data['dateformat']),
146 'S_DATEFORMAT_OPTIONS' => $dateformat_options,
147 'S_CUSTOM_DATEFORMAT' => $s_custom,
148 'DEFAULT_DATEFORMAT' => $config['default_dateformat'],
149 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']),
150
151 'S_LANG_OPTIONS' => language_select($data['lang']),
152 'S_STYLE_OPTIONS' => ($config['override_user_style']) ? '' : style_select($data['style']),
153 'S_TZ_OPTIONS' => tz_select($data['tz'], true),
154 'S_CAN_HIDE_ONLINE' => ($auth->acl_get('u_hideonline')) ? true : false,
155 'S_SELECT_NOTIFY' => ($config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml')) ? true : false)
156 );
157
158 break;
159
160 case 'view':
161
162 add_form_key('ucp_prefs_view');
163
164 $data = array(
165 'topic_sk' => request_var('topic_sk', (!empty($user->data['user_topic_sortby_type'])) ? $user->data['user_topic_sortby_type'] : 't'),
166 'topic_sd' => request_var('topic_sd', (!empty($user->data['user_topic_sortby_dir'])) ? $user->data['user_topic_sortby_dir'] : 'd'),
167 'topic_st' => request_var('topic_st', (!empty($user->data['user_topic_show_days'])) ? $user->data['user_topic_show_days'] : 0),
168
169 'post_sk' => request_var('post_sk', (!empty($user->data['user_post_sortby_type'])) ? $user->data['user_post_sortby_type'] : 't'),
170 'post_sd' => request_var('post_sd', (!empty($user->data['user_post_sortby_dir'])) ? $user->data['user_post_sortby_dir'] : 'a'),
171 'post_st' => request_var('post_st', (!empty($user->data['user_post_show_days'])) ? $user->data['user_post_show_days'] : 0),
172
173 'images' => request_var('images', (bool) $user->optionget('viewimg')),
174 'flash' => request_var('flash', (bool) $user->optionget('viewflash')),
175 'smilies' => request_var('smilies', (bool) $user->optionget('viewsmilies')),
176 'sigs' => request_var('sigs', (bool) $user->optionget('viewsigs')),
177 'avatars' => request_var('avatars', (bool) $user->optionget('viewavatars')),
178 'wordcensor' => request_var('wordcensor', (bool) $user->optionget('viewcensors')),
179 );
180
181 if ($submit)
182 {
183 $error = validate_data($data, array(
184 'topic_sk' => array('string', false, 1, 1),
185 'topic_sd' => array('string', false, 1, 1),
186 'post_sk' => array('string', false, 1, 1),
187 'post_sd' => array('string', false, 1, 1),
188 ));
189
190 if (!check_form_key('ucp_prefs_view'))
191 {
192 $error[] = 'FORM_INVALID';
193 }
194
195 if (!sizeof($error))
196 {
197 $user->optionset('viewimg', $data['images']);
198 $user->optionset('viewflash', $data['flash']);
199 $user->optionset('viewsmilies', $data['smilies']);
200 $user->optionset('viewsigs', $data['sigs']);
201 $user->optionset('viewavatars', $data['avatars']);
202
203 if ($auth->acl_get('u_chgcensors'))
204 {
205 $user->optionset('viewcensors', $data['wordcensor']);
206 }
207
208 $sql_ary = array(
209 'user_options' => $user->data['user_options'],
210 'user_topic_sortby_type' => $data['topic_sk'],
211 'user_post_sortby_type' => $data['post_sk'],
212 'user_topic_sortby_dir' => $data['topic_sd'],
213 'user_post_sortby_dir' => $data['post_sd'],
214
215 'user_topic_show_days' => $data['topic_st'],
216 'user_post_show_days' => $data['post_st'],
217 );
218
219 $sql = 'UPDATE ' . USERS_TABLE . '
220 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
221 WHERE user_id = ' . $user->data['user_id'];
222 $db->sql_query($sql);
223
224 meta_refresh(3, $this->u_action);
225 $message = $user->lang['PREFERENCES_UPDATED'] . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
226 trigger_error($message);
227 }
228
229 // Replace "error" strings with their real, localised form
230 $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
231 }
232
233 $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
234
235 // Topic ordering options
236 $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']);
237
238 $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']);
239 $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');
240
241 // Post ordering options
242 $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']);
243
244 $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
245 $sort_by_post_sql = array('a' => 'u.username_clean', 't' => 'p.post_id', 's' => 'p.post_subject');
246
247 $_options = array('topic', 'post');
248 foreach ($_options as $sort_option)
249 {
250 ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
251 foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
252 {
253 $selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
254 ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
255 }
256 ${'s_limit_' . $sort_option . '_days'} .= '</select>';
257
258 ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
259 foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
260 {
261 $selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
262 ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
263 }
264 ${'s_sort_' . $sort_option . '_key'} .= '</select>';
265
266 ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
267 foreach ($sort_dir_text as $key => $value)
268 {
269 $selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
270 ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
271 }
272 ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
273 }
274
275 $template->assign_vars(array(
276 'ERROR' => (sizeof($error)) ? implode('<br />', $error) : '',
277
278 'S_IMAGES' => $data['images'],
279 'S_FLASH' => $data['flash'],
280 'S_SMILIES' => $data['smilies'],
281 'S_SIGS' => $data['sigs'],
282 'S_AVATARS' => $data['avatars'],
283 'S_DISABLE_CENSORS' => $data['wordcensor'],
284
285 'S_CHANGE_CENSORS' => ($auth->acl_get('u_chgcensors') && $config['allow_nocensors']) ? true : false,
286
287 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days,
288 'S_TOPIC_SORT_KEY' => $s_sort_topic_key,
289 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir,
290 'S_POST_SORT_DAYS' => $s_limit_post_days,
291 'S_POST_SORT_KEY' => $s_sort_post_key,
292 'S_POST_SORT_DIR' => $s_sort_post_dir)
293 );
294
295 break;
296
297 case 'post':
298
299 $data = array(
300 'bbcode' => request_var('bbcode', $user->optionget('bbcode')),
301 'smilies' => request_var('smilies', $user->optionget('smilies')),
302 'sig' => request_var('sig', $user->optionget('attachsig')),
303 'notify' => request_var('notify', (bool) $user->data['user_notify']),
304 );
305 add_form_key('ucp_prefs_post');
306
307 if ($submit)
308 {
309 if (check_form_key('ucp_prefs_post'))
310 {
311 $user->optionset('bbcode', $data['bbcode']);
312 $user->optionset('smilies', $data['smilies']);
313 $user->optionset('attachsig', $data['sig']);
314
315 $sql_ary = array(
316 'user_options' => $user->data['user_options'],
317 'user_notify' => $data['notify'],
318 );
319
320 $sql = 'UPDATE ' . USERS_TABLE . '
321 SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
322 WHERE user_id = ' . $user->data['user_id'];
323 $db->sql_query($sql);
324
325 $msg = $user->lang['PREFERENCES_UPDATED'];
326 }
327 else
328 {
329 $msg = $user->lang['FORM_INVALID'];
330 }
331 meta_refresh(3, $this->u_action);
332 $message = $msg . '<br /><br />' . sprintf($user->lang['RETURN_UCP'], '<a href="' . $this->u_action . '">', '</a>');
333 trigger_error($message);
334 }
335
336 $template->assign_vars(array(
337 'S_BBCODE' => $data['bbcode'],
338 'S_SMILIES' => $data['smilies'],
339 'S_SIG' => $data['sig'],
340 'S_NOTIFY' => $data['notify'])
341 );
342 break;
343 }
344
345 $template->assign_vars(array(
346 'L_TITLE' => $user->lang['UCP_PREFS_' . strtoupper($mode)],
347
348 'S_HIDDEN_FIELDS' => $s_hidden_fields,
349 'S_UCP_ACTION' => $this->u_action)
350 );
351
352 $this->tpl_name = 'ucp_prefs_' . $mode;
353 $this->page_title = 'UCP_PREFS_' . strtoupper($mode);
354 }
355}
356
357?>
Note: See TracBrowser for help on using the repository browser.