root/my.php

Revision 316, 16.1 kB (checked in by Nafania, 2 years ago)

Апдейт добавляет возможность получать уведомление на мыло о новых комментариях, и небольшие изменения с уведомлениями в панели управления.
Мелкие фиксы.

Line 
1 <?php</span>
2 <span class="code-lang">$root_path = './';
3 require ($root_path . 'include/config.php');
4 require ($root_path . 'include/functions_check.php');
5
6 $userdata = session_pagestart($user_ip);
7 init_userprefs($userdata);
8 loggedinorreturn();
9
10 $action = request_var('action', '');
11 $type = request_var('type', '');
12
13 $template->assign_vars(array(</span>
14 <span class="code-lang">        'TYPE'           => $type,
15         'ALLOW_MY_BONUS' => ( $config['allow_my_bonus'] ? 1 : '' ),
16         'U_MY'           => append_sid('my.php'),          )
17 );
18
19 $files = array();</span>
20 <span class="code-lang">if ( $dir = opendir($root_path . 'include/ucp/') ) {
21     while ( false !== ($file = readdir($dir)) ) {
22         if ( $file != '.' && $file != '..' ) {
23             $file = substr($file, 0, strpos($file, '.php'));
24             $files[] = $file;
25             $template->assign_vars(array(
26                 'U_' . strtoupper($file) => append_sid('my.php?type=' . $file)
27             ));
28         }
29     }
30 }
31
32 if ( $type ) {
33     if ( in_array($type, $files) ) {
34         require_once($root_path . 'include/ucp/' . $type . '.php');
35     }
36     else {
37         trigger_error('invalid_action');
38     }
39 }
40 else {
41     if ( isset($_POST['submit']) ) {
42         $updateset = array();
43         $notifs = '';
44         $full_cats = $cache->obtain_cats();
45
46         $parked = request_var('parked', 0);
47         $updateset['parked'] = ( $parked ? 1 : 0 );
48
49         $user_limit_ary_allow_download = unserialize($config['user_limit_ary_allow_download']);
50         $can_leech = ( isset($user_limit_ary_allow_download[$userdata['class']]) ? 1 : 0 );
51
52         if ( $parked && $userdata['can_leech'] ) {
53             $updateset['can_leech'] = 0;
54         }
55         elseif ( !$parked && !$userdata['can_leech'] && $can_leech ) {
56             $updateset['can_leech'] = 1;
57         }
58
59         $accept_pms = request_var('acceptpms', 0);
60         $updateset['acceptpms'] = ( $accept_pms == 1 ? 1 : ( !$accept_pms ? 0 : 2 ) );
61
62         $updateset['deletepms'] = ( isset($_POST['deletepms']) ? 1 : 0 );
63
64         $updateset['savepms'] = ( isset($_POST['savepms']) ? 1 : 0 );
65
66         $user_notify = request_var('user_notify', array(''=>0));
67         foreach ( $user_notify AS $key => $val ) {
68             $notifs .= '[' . $key . ']';
69         }
70
71         $comment_pm = request_var('commentpm', 0);
72         $updateset['commentpm'] = ( $comment_pm ? 1 : 0 );
73
74         $expand_cats = request_var('expand_cats', 0);
75         $notifs .= ( $expand_cats ? '[ex]' : '' );
76
77         $cats = request_var('cats', array(0=>0));
78
79         if ( sizeof($cats) ) {
80             foreach ( $cats AS $cat_id => $_null ) {
81                 if ( $full_cats[$cat_id]['cat_parent'] ) {
82                     $notifs .= '[cat' . $cat_id . ']';
83                 }
84                 //no cat parent, try to get all child cats
85                 else {
86                     foreach ( $full_cats AS $_key => $_ary ) {
87                         if ( $_ary['cat_parent'] == $cat_id ) {
88                             $notifs .= '[cat' . $_key . ']';
89                         }
90                     }
91                     $notifs .= '[cat' . $cat_id . ']';
92                 }
93             }
94             $updateset['notifs'] = $notifs;
95         }
96         else {
97             $updateset['notifs'] = $notifs;
98         }
99
100         $language = request_var('language', $config['default_lang']);
101         if (!check_language($language)) {
102             $language = $config['default_lang'];
103         }
104         $updateset['language'] = $db->sql_escape($language);
105
106         $style = request_var('style', $config['default_style']);
107         if (!check_style_id($style)) {
108             $style = $config['default_style'];
109         }
110         $updateset['user_style'] = $style;
111
112         $download = request_var('download', '');
113         $upload = request_var('upload', '');
114         if ( !check_internet_speed($upload) || !check_internet_speed($download) ) {
115             trigger_error($lang['speed_invalid']);
116         }
117         $updateset['download'] = $download;
118         $updateset['upload'] = $upload;
119
120         $icq = request_var('icq', '');
121
122         $msn = request_var('msn', '');
123
124         $aim = request_var('aim', '');
125
126         $yim = request_var('yahoo', '');
127
128         $skype = request_var('skype', '');
129
130         $country = request_var('country', 0);
131
132         if ( !check_country_id($country) ) {
133             trigger_error($lang['invalid_country']);
134         }
135         $updateset['country'] = $country;
136
137         $tzoffset = (float) request_var('tzoffset', 0.0);
138         $updateset['tzoffset'] = $tzoffset;
139
140         $user_dst = request_var('dst', 0);
141         $updateset['user_dst'] = ( $user_dst ? 1 : 0 );
142
143         $gender = request_var('gender', 0);
144         $updateset['gender'] = ( $gender ? 1 : 0 );
145
146         $year = request_var('year', 0);
147         $month = request_var('month', 0);
148         $day = request_var('day', 0);
149         if ( !checkdate($month, $day, $year) ) {
150             trigger_error($lang['birthday_invalid']);
151         }
152         $birthday = $year . '-' . $month . '-' . $day;
153         $updateset['birthday'] = $birthday;
154
155         $avatar = request_var('avatar_link', '');
156         if ( $avatar && $avatar != $userdata['avatar'] && strpos($avatar, 'user_avatar_' . $userdata['uid']) === false && $config['allow_avatar_remote'] ) {
157             if ( $error = check_remote_avatar($avatar) ) {
158                 trigger_error($error);
159             }
160         }
161         if ( isset($_FILES['avatar_upload']) && !empty($_FILES['avatar_upload']['name']) && $config['allow_avatar_upload'] ) {
162             $avatar = check_upload_image($_FILES['avatar_upload'], $config['avatar_path'] . '/', $config['avatar_filesize'], $config['avatar_max_height'], $config['avatar_max_width'], 'user_avatar_' . $userdata['uid']);
163             $avatar = $avatar['filename'];
164         }
165         $updateset['avatar'] = $avatar;
166
167         $torrentperpage = request_var('torrentsperpage', 0);
168         $updateset['torrentsperpage'] = min(200, $torrentperpage);
169
170         $updateset['avatars'] = ( isset($_POST['avatars']) ? 1 : 0);
171
172         $privacy = request_var('privacy', PRIVACY_LEVEL_LOW);
173         $privacy = min($privacy, PRIVACY_LEVEL_HIGH);
174         $updateset['privacy'] = $privacy;
175
176         //start signature section
177         $signature = request_var('signature', '');
178
179         validate_optional_fields($icq, $aim, $msn, $yim, $skype, $signature);
180
181         $updateset['icq'] = $icq;
182         $updateset['msn'] = $msn;
183         $updateset['aim'] = $aim;
184         $updateset['yahoo'] = $yim;
185         $updateset['skype'] = $skype;
186
187         if ( $signature != '' ) {
188             define ('IN_PHPBB', true);
189             require($root_path . 'phpBB2/includes/bbcode.php');
190             require($root_path . 'phpBB2/includes/functions_post.php');
191
192             if ( strlen($signature) > $config['max_sig_chars'] ) {
193                 trigger_error( sprintf($lang['signature_too_long'], $config['max_sig_chars']) );
194             }
195
196             $signature = prepare_message($signature, $config['allow_html'], $config['allow_bbcode'], $config['allow_smilies']);
197             $updateset['user_sig'] = $signature;
198         }
199         else {
200             $updateset['user_sig'] = '';
201         }
202         //end signature section
203
204
205         // start email section
206         $urladd = '';
207         $changedemail = 0;
208         $email = request_var('email', '');
209         if ( $email != $userdata['email'] ) {
210             if ( $error = check_email($email) ) {
211                 trigger_error($error['error_msg']);
212             }
213             $changedemail = 1;
214         }
215         if ( $changedemail ) {
216             $sec = mksecret();
217             $hash = md5($sec . $email . $sec);
218             $obemail = urlencode($email);
219             $updateset['editsecret'] = $sec;
220
221             include_once($root_path . 'include/functions_messenger.php');
222             $messenger = new messenger(false);
223             $messenger->template('account_email_change', $userdata['language']);
224             $messenger->replyto($userdata['email']);
225             $messenger->to($userdata['email'], $userdata['name']);
226
227             $messenger->assign_vars(array(
228                 'USERNAME' => html_entity_decode($userdata['name']),
229                 'EMAIL' => $email,
230                 'IP' => $user_ip,
231                 'U_LINK' => generate_base_url() . '/signup.php?id=' . $userdata['uid'] . '&type=change_mail&hash=' . $hash . '&email=' . $obemail )
232             );
233             $messenger->send(NOTIFY_EMAIL);
234             $messenger->reset();
235             $urladd .= '&mailsent=1';
236         }
237         // end email section
238
239         if ( isset($_POST['resetpasskey']) ) {
240             $torrent_pass = md5($userdata['name'] . time() . $userdata['pass']);
241             $updateset['torrent_pass'] = $torrent_pass;
242         }
243
244         //start password section
245         $chpassword = request_var('chpassword', '');
246         $passagain = request_var('passagain', '');
247         if ($chpassword != '') {
248             if (strlen($chpassword) > 40) {
249                 trigger_error($lang['pass_too_long']);
250             }
251             if ($chpassword != $passagain) {
252                 trigger_error($lang['passwords_not_the_same']);
253             }
254             $sec = mksecret();
255             $passhash = md5($sec . $chpassword . $sec);
256             $updateset['secret'] = $sec;
257             $updateset['pass'] = $passhash;
258             session_reset_keys($userdata['uid'], $user_ip);
259         }
260         //end password section
261
262         $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $updateset) . ' WHERE uid = ' . $userdata['uid'];
263         $db->sql_query($sql);
264         redirect( append_sid('my.php?edited=1' . $urladd));
265     }
266     else {
267         require($root_path . 'include/functions_selects.php');
268
269         $template->assign_block_vars('main_part', array());
270
271         if ( isset($_GET['mailsent']) ) {
272             $message = $lang['mail_sent'];
273         }
274         elseif ( isset($_GET['edited']) ) {
275             $message = $lang['profile_edited'];
276         }
277         elseif ( isset($_GET['emailch']) ) {
278             $message = $lang['mail_edited'];
279         }
280         else {
281             $message = '';
282         }
283
284
285         $user_sig = $userdata['user_sig'];
286         $template->assign_vars(array(
287                 'U_USERBAR' => append_sid('my.php?type=get_userbar'),
288                 'L_MESSAGE' => $message,
289                 'L_AVATAR_DESCR' => sprintf($lang['avatar_url_descr'], $config['avatar_max_width'], $config['avatar_max_height'], mksize($config['avatar_filesize'])),
290                 'USER_ID' => $userdata['uid'],
291                 'USERNAME' => $userdata['name'],
292                 'ACCOUNT_PARKED_INPUT' => '<input type="radio" class="radio" name="parked"' . ($userdata['parked'] ? ' checked="checked"' : '') . ' value="1" /> ' . $lang['yes'] . ' <input type="radio" class="radio" id="parked" name="parked"' .  ( !$userdata['parked'] ? ' checked="checked"' : ''). ' value="0" /> ' . $lang['no'],
293                 'ACCEPT_PM_INPUT' => '<input type="radio" class="radio" id="acceptpms" name="acceptpms"' . ( $userdata['acceptpms'] ? ' checked="checked"' : '') . ' value="1" /> ' . $lang['all_except_block'] . '<br /><input type="radio" class="radio" name="acceptpms"' .  ($userdata['acceptpms'] == 2 ? ' checked="checked"' : '') . ' value="2" /> ' . $lang['only_friends'] . '<br /><input type="radio" class="radio" name="acceptpms"' .  ( !$userdata['acceptpms'] ? ' checked="checked"' : '') . ' value="0" /> ' . $lang['only_admins'],
294                 'DELETE_PM_INPUT' => '<input type="checkbox" id="deletepms" name="deletepms"' . ( $userdata['deletepms'] ? ' checked="checked"' : '') . ' />',
295                 'SAVE_PM_INPUT' => '<input type="checkbox" id="savepms" name="savepms"' . ( $userdata['savepms'] ? ' checked="checked"' : '') . ' />',
296                 'COMMENTPM_INPUT' => '<input type="radio" class="radio" id="commentpm" name="commentpm"' . ( $userdata['commentpm'] ? ' checked="checked"' : '') . ' value="1" /> ' . $lang['yes'] . ' <input type="radio" class="radio" name="commentpm"' .  ( !$userdata['commentpm'] ? ' checked="checked"' : '') . ' value="0" /> ' . $lang['no'],
297                 'USER_ICQ' => $userdata['icq'],
298                 'USER_SKYPE' => $userdata['skype'],
299                 'USER_AIM' => $userdata['aim'],
300                 'USER_MSN' => $userdata['msn'],
301                 'USER_YAHOO' => $userdata['yahoo'],
302                 'USER_SIGNATURE' => ( $config['allow_sig'] ? '<textarea rows="4" cols="40" id="signature" name="signature">' . $user_sig . '</textarea>' : '' ),
303                 'GENDER_INPUT' => '<input type="radio" class="radio" id="gender" name="gender"' . ( !$userdata['gender'] ? ' checked="checked"' : '') . ' value="0" />' . $lang['gender_male'] . ' <input type="radio" class="radio" name="gender"' .  ($userdata['gender'] ? ' checked="checked"' : '') . ' value="1" />' . $lang['gender_female'],
304                 'USER_AVATAR_LINK_INPUT' =>  ( $config['allow_avatar_remote'] ? '<input type="text" id="avatar" name="avatar_link" size="45" value="' . htmlspecialchars($userdata['avatar']) . '" />' : '' ),
305                 'USER_AVATAR_UPLOAD_INPUT' => ( $config['allow_avatar_upload'] ?  '<input type="file" id="avatar" name="avatar_upload" size="40" value="" />' : '' ),
306                 'TORRENTS_PER_PAGE_INPUT' => '<input type="text" size="10" maxlength="3" id="torrentsperpage" name="torrentsperpage" value="' . $userdata['torrentsperpage'] . '" />',
307                 'SHOW_AVATARS_INPUT' => '<input type="checkbox" id="avatars" name="avatars"' . ($userdata['avatars'] ? ' checked="checked"' : '') . ' />',
308                 'EMAIL_ADRESS_INPUT' =>  '<input type="text" id="email" name="email" size="45" value="' . $userdata['email'] . '" />',
309                 'EXPAND_CATS_INPUT' => '<input type="radio" name="expand_cats" value="1"' . ( strpos($userdata['notifs'], '[ex]') !== false ? ' checked="checked"' : '' ) . ' /> ' . $lang['yes'] . ' <input type="radio" name="expand_cats" value="0"' . ( strpos($userdata['notifs'], '[ex]') === false ? ' checked="checked"' : '' ) . ' /> ' . $lang['no']
310         ));
311
312         $countries = countries_select($userdata['country']);
313         $uploadspeed = generate_internet_speed($userdata['upload'], 'upload');
314         $downloadspeed = generate_internet_speed($userdata['download'], 'download');
315         $timezone = tz_select($userdata['tzoffset'], 'tzoffset');
316         $lang_select = language_select($userdata['language']);
317         $birthday_select = birthday_select(substr($userdata['birthday'], 0, 4), substr($userdata['birthday'], 5, 2), substr($userdata['birthday'], 8, 2));
318         $style_select = style_select($userdata['user_style']);
319
320         $dst = '<input type="radio" class="radio" id="dst" name="dst" value="1"' . ($userdata['user_dst']?' checked="checked"':'') . ' /> ' . $lang['yes'];
321         $dst .= ' <input type="radio" class="radio" id="dst" name="dst" value="0"' . (!$userdata['user_dst']?' checked="checked"':'') . ' /> ' . $lang['no'];
322
323         $privacy_input = '<input type="radio" name="privacy" id="privacy" value="' . PRIVACY_LEVEL_LOW . '"' . ( $userdata['privacy'] == PRIVACY_LEVEL_LOW ?' checked="checked"':'') . ' /> ' . $lang['low'];
324         $privacy_input .= ' <input type="radio" name="privacy" id="privacy" value="' . PRIVACY_LEVEL_NORMAL . '"' . ( $userdata['privacy'] == PRIVACY_LEVEL_NORMAL ?' checked="checked"':'') . ' /> ' . $lang['normal'];
325         $privacy_input .= ' <input type="radio" name="privacy" id="privacy" value="' . PRIVACY_LEVEL_HIGH . '"' . ( $userdata['privacy'] == PRIVACY_LEVEL_HIGH ?' checked="checked"':'') . ' /> ' . $lang['high'];
326
327         $catoptions = '';
328
329         $sql = 'SELECT * FROM ' . CATEGORIES_TABLE . ' ORDER BY cat_parent_id, name';
330         $result = $db->sql_query($sql, 30 * 60);
331
332         $cats = array();
333         while( $row = $db->sql_fetchrow($result) ){
334             $parent_cat_id = ( $row['cat_parent_id'] ? $row['cat_parent_id'] : $row['id'] );
335             $cats[$parent_cat_id][$row['id']] = $row;
336         }
337
338         if ( sizeof($cats) ) {
339             $catsperrow = 2;
340             $cats_split_row = $catsperrow - 1;
341             $row = 0;
342             $col = 0;
343
344             foreach ( $cats AS $cat_id => $ary ) {
345                 if (!$col) {
346                     $template->assign_block_vars('cats_row', array());
347                 }
348
349                  $template->assign_block_vars('cats_row.cats_col', array(
350                     'CAT_ID' => $cat_id,
351                     'CAT_NAME' => $ary[$cat_id]['name'],
352                     'CHECKED' => ( strpos($userdata['notifs'], '[cat' . $cat_id . ']') !== false ? ' checked="checked"' : "")
353                 ));
354
355                 if ($col == $cats_split_row) {
356                     $col = 0;
357                     $row++;
358                 }
359                 else {
360                     $col++;
361                 }
362
363                 unset($ary[$cat_id]);
364                 if ( $count = sizeof($ary) ) {
365                     $value = '';
366                     foreach( $ary AS $key => $sub_ary ) {
367                          $template->assign_block_vars('cats_row.cats_col.subcats_row', array(
368                             'CAT_ID' => $key,
369                             'CAT_NAME' => $sub_ary['name'],
370                             'CHECKED' => ( strpos($userdata['notifs'], '[cat' . $key . ']') !== false ? ' checked="checked"' : "")
371                         ));
372                     }
373                 }
374             }
375
376             if ($col) {
377                 $template->assign_block_vars('cats_row.colspan', array(
378                     'CATS_COLSPAN' => ( $catsperrow - $col )
379                 ));
380             }
381         }
382
383         $notifs = array('pm', 'forum', 'comments');
384
385         $notifs_options = '';
386         foreach ( $notifs AS $_null => $val ) {
387             $name = 'user_notify[' . $val . ']';
388             $notifs_options .= '<input type="checkbox" id="' . $name . '" name="' . $name . '"' . ( strpos($userdata['notifs'], '[' . $val . ']') !== false ? ' checked="checked"' : '' ) . ' value="1" /> ' . $lang['email_notifis_' . $val] . '<br />';
389         }
390
391         $template->assign_vars(array(
392                 'LANG_INPUT' => $lang_select,
393                 'UPLOAD_SPEED_OPTIONS' => $uploadspeed,
394                 'DOWNLOAD_SPEED_OPTIONS' => $downloadspeed,
395                 'COUNTRIES_OPTIONS' => $countries,
396                 'TIMEZONE' => $timezone,
397                 'STYLE_SELECT' => $style_select,
398                 'DST' => $dst,
399                 'BIRTHDAY_OPTIONS' => $birthday_select,
400                 'PRIVACY_INPUT' => $privacy_input,
401                 'EMAIL_NOTIFIS_INPUT' => $notifs_options
402         ));
403     }
404
405     $body = 'ucp_body.html';
406 }
407
408 stdhead(sprintf($lang['personal_page'], (!isset($_GET['id']) ? $userdata['name'] : '')));
409 $template->set_filenames(array(</span>
410 <span class="code-lang">        'body' => $body)
411 );
412 stdfoot();
413 ?>
414
Note: See TracBrowser for help on using the browser.