phpBB
Statistics
| Revision:

root / trunk / phpBB / ucp.php

History | View | Annotate | Download (9.8 kB)

1
<?php
2
/**
3
*
4
* @package ucp
5
* @copyright (c) 2005 phpBB Group
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
/**
11
* @ignore
12
*/
13
define('IN_PHPBB', true);
14
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
15
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16
require($phpbb_root_path . 'common.' . $phpEx);
17
require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
18
require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
19
20
// Basic parameter data
21
$id         = request_var('i', '');
22
$mode        = request_var('mode', '');
23
24
if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
25
{
26
        define('IN_LOGIN', true);
27
}
28
29
// Start session management
30
$user->session_begin();
31
$auth->acl($user->data);
32
$user->setup('ucp');
33
34
// Setting a variable to let the style designer know where he is...
35
$template->assign_var('S_IN_UCP', true);
36
37
$module = new p_master();
38
$default = false;
39
40
// Basic "global" modes
41
switch ($mode)
42
{
43
        case 'activate':
44
                $module->load('ucp', 'activate');
45
                $module->display($user->lang['UCP_ACTIVATE']);
46
47
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
48
        break;
49
50
        case 'resend_act':
51
                $module->load('ucp', 'resend');
52
                $module->display($user->lang['UCP_RESEND']);
53
        break;
54
55
        case 'sendpassword':
56
                $module->load('ucp', 'remind');
57
                $module->display($user->lang['UCP_REMIND']);
58
        break;
59
60
        case 'register':
61
                if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
62
                {
63
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
64
                }
65
66
                $module->load('ucp', 'register');
67
                $module->display($user->lang['REGISTER']);
68
        break;
69
70
        case 'confirm':
71
                $module->load('ucp', 'confirm');
72
        break;
73
74
        case 'login':
75
                if ($user->data['is_registered'])
76
                {
77
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
78
                }
79
80
                login_box(request_var('redirect', "index.$phpEx"));
81
        break;
82
83
        case 'logout':
84
                if ($user->data['user_id'] != ANONYMOUS && $request->is_set('sid') && $request->variable('sid', '') === $user->session_id)
85
                {
86
                        $user->session_kill();
87
                        $user->session_begin();
88
                        $message = $user->lang['LOGOUT_REDIRECT'];
89
                }
90
                else
91
                {
92
                        $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
93
                }
94
                meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
95
96
                $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
97
                trigger_error($message);
98
99
        break;
100
101
        case 'terms':
102
        case 'privacy':
103
104
                $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
105
                $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
106
107
                if (empty($user->lang[$message]))
108
                {
109
                        if ($user->data['is_registered'])
110
                        {
111
                                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
112
                        }
113
114
                        login_box();
115
                }
116
117
                $template->set_filenames(array(
118
                        'body'                => 'ucp_agreement.html')
119
                );
120
121
                // Disable online list
122
                page_header($user->lang[$title], false);
123
124
                $template->assign_vars(array(
125
                        'S_AGREEMENT'                        => true,
126
                        'AGREEMENT_TITLE'                => $user->lang[$title],
127
                        'AGREEMENT_TEXT'                => sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
128
                        'U_BACK'                                => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
129
                        'L_BACK'                                => $user->lang['BACK_TO_LOGIN'],
130
                ));
131
132
                page_footer();
133
134
        break;
135
136
        case 'delete_cookies':
137
138
                // Delete Cookies with dynamic names (do NOT delete poll cookies)
139
                if (confirm_box(true))
140
                {
141
                        $set_time = time() - 31536000;
142
143
                        foreach ($request->variable_names(phpbb_request_interface::COOKIE) as $cookie_name)
144
                        {
145
                                $cookie_data = $request->variable($cookie_name, '', true, phpbb_request_interface::COOKIE);
146
147
                                // Only delete board cookies, no other ones...
148
                                if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0)
149
                                {
150
                                        continue;
151
                                }
152
153
                                $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
154
155
                                // Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
156
                                if (strpos($cookie_name, 'poll_') !== 0)
157
                                {
158
                                        $user->set_cookie($cookie_name, '', $set_time);
159
                                }
160
                        }
161
162
                        $user->set_cookie('track', '', $set_time);
163
                        $user->set_cookie('u', '', $set_time);
164
                        $user->set_cookie('k', '', $set_time);
165
                        $user->set_cookie('sid', '', $set_time);
166
167
                        // We destroy the session here, the user will be logged out nevertheless
168
                        $user->session_kill();
169
                        $user->session_begin();
170
171
                        meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
172
173
                        $message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
174
                        trigger_error($message);
175
                }
176
                else
177
                {
178
                        confirm_box(false, 'DELETE_COOKIES', '');
179
                }
180
181
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
182
183
        break;
184
185
        case 'switch_perm':
186
187
                $user_id = request_var('u', 0);
188
189
                $sql = 'SELECT *
190
                        FROM ' . USERS_TABLE . '
191
                        WHERE user_id = ' . (int) $user_id;
192
                $result = $db->sql_query($sql);
193
                $user_row = $db->sql_fetchrow($result);
194
                $db->sql_freeresult($result);
195
196
                if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
197
                {
198
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
199
                }
200
201
                include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
202
203
                $auth_admin = new auth_admin();
204
                if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
205
                {
206
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
207
                }
208
209
                add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
210
211
                $message = sprintf($user->lang['PERMISSIONS_TRANSFERRED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
212
                trigger_error($message);
213
214
        break;
215
216
        case 'restore_perm':
217
218
                if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
219
                {
220
                        redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
221
                }
222
223
                $auth->acl_cache($user->data);
224
225
                $sql = 'SELECT username
226
                        FROM ' . USERS_TABLE . '
227
                        WHERE user_id = ' . $user->data['user_perm_from'];
228
                $result = $db->sql_query($sql);
229
                $username = $db->sql_fetchfield('username');
230
                $db->sql_freeresult($result);
231
232
                add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
233
234
                $message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
235
                trigger_error($message);
236
237
        break;
238
239
        default:
240
                $default = true;
241
        break;
242
}
243
244
// We use this approach because it does not impose large code changes
245
if (!$default)
246
{
247
        return true;
248
}
249
250
// Only registered users can go beyond this point
251
if (!$user->data['is_registered'])
252
{
253
        if ($user->data['is_bot'])
254
        {
255
                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
256
        }
257
258
        if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
259
        {
260
                $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
261
                login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
262
        }
263
264
        login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
265
}
266
267
// Instantiate module system and generate list of available modules
268
$module->list_modules('ucp');
269
270
// Check if the zebra module is set
271
if ($module->is_active('zebra', 'friends'))
272
{
273
        // Output listing of friends online
274
        $update_time = $config['load_online_time'] * 60;
275
276
        $sql_ary = array(
277
                'SELECT'        => 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
278
279
                'FROM'                => array(
280
                        USERS_TABLE                => 'u',
281
                        ZEBRA_TABLE                => 'z',
282
                ),
283
284
                'LEFT_JOIN'        => array(
285
                        array(
286
                                'FROM'        => array(SESSIONS_TABLE => 's'),
287
                                'ON'        => 's.session_user_id = z.zebra_id',
288
                        ),
289
                ),
290
291
                'WHERE'                => 'z.user_id = ' . $user->data['user_id'] . '
292
                        AND z.friend = 1
293
                        AND u.user_id = z.zebra_id',
294
295
                'GROUP_BY'        => 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
296
297
                'ORDER_BY'        => 'u.username_clean ASC',
298
        );
299
300
        $sql = $db->sql_build_query('SELECT_DISTINCT', $sql_ary);
301
        $result = $db->sql_query($sql);
302
303
        while ($row = $db->sql_fetchrow($result))
304
        {
305
                $which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
306
307
                $template->assign_block_vars("friends_{$which}", array(
308
                        'USER_ID'                => $row['user_id'],
309
310
                        'U_PROFILE'                => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
311
                        'USER_COLOUR'        => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
312
                        'USERNAME'                => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
313
                        'USERNAME_FULL'        => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
314
                );
315
        }
316
        $db->sql_freeresult($result);
317
}
318
319
// Do not display subscribed topics/forums if not allowed
320
if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
321
{
322
        $module->set_display('main', 'subscribed', false);
323
}
324
325
// Do not display signature panel if not authed to do so
326
if (!$auth->acl_get('u_sig'))
327
{
328
        $module->set_display('profile', 'signature', false);
329
}
330
331
// Select the active module
332
$module->set_active($id, $mode);
333
334
// Load and execute the relevant module
335
$module->load_active();
336
337
// Assign data to the template engine for the list of modules
338
$module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
339
340
// Generate the page, do not display/query online list
341
$module->display($module->get_page_title(), false);
342
343
/**
344
* Function for assigning a template var if the zebra module got included
345
*/
346
function _module_zebra($mode, &$module_row)
347
{
348
        global $template;
349
350
        $template->assign_var('S_ZEBRA_ENABLED', true);
351
352
        if ($mode == 'friends')
353
        {
354
                $template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
355
        }
356
357
        if ($mode == 'foes')
358
        {
359
                $template->assign_var('S_ZEBRA_FOES_ENABLED', true);
360
        }
361
}