- do not allow setting the parent to currently assigned childs [Bug #6708]
[phpbb.git] / phpBB / ucp.php
blobd0163d9daff62634b4e4e26ea3c1229c6f25fffb
1 <?php
2 /**
4 * @package ucp
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 $phpbb_root_path = './';
16 $phpEx = substr(strrchr(__FILE__, '.'), 1);
17 require($phpbb_root_path . 'common.' . $phpEx);
18 require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
19 require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
21 // Basic parameter data
22 $id = request_var('i', '');
23 $mode = request_var('mode', '');
25 if ($mode == 'login' || $mode == 'logout')
27 define('IN_LOGIN', true);
30 // Start session management
31 $user->session_begin();
32 $auth->acl($user->data);
33 $user->setup('ucp');
35 // Setting a variable to let the style designer know where he is...
36 $template->assign_var('S_IN_UCP', true);
38 $module = new p_master();
40 // Basic "global" modes
41 switch ($mode)
43 case 'activate':
44 $module->load('ucp', 'activate');
45 $module->display($user->lang['UCP_ACTIVATE']);
47 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
48 break;
50 case 'resend_act':
51 $module->load('ucp', 'resend');
52 $module->display($user->lang['UCP_RESEND']);
53 break;
55 case 'sendpassword':
56 $module->load('ucp', 'remind');
57 $module->display($user->lang['UCP_REMIND']);
58 break;
60 case 'register':
61 if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
63 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
66 $module->load('ucp', 'register');
67 $module->display($user->lang['REGISTER']);
68 break;
70 case 'confirm':
71 $module->load('ucp', 'confirm');
72 exit;
73 break;
75 case 'login':
76 if ($user->data['is_registered'])
78 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
81 login_box("index.$phpEx");
82 break;
84 case 'logout':
85 if ($user->data['user_id'] != ANONYMOUS)
87 $user->session_kill();
88 $user->session_begin();
91 meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
93 $message = $user->lang['LOGOUT_REDIRECT'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
94 trigger_error($message);
95 break;
97 case 'terms':
98 case 'privacy':
100 $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
101 $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
103 if (empty($user->lang[$message]))
105 if ($user->data['is_registered'])
107 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
110 login_box();
113 $template->set_filenames(array(
114 'body' => 'ucp_agreement.html')
117 // Disable online list
118 page_header($user->lang[$title], false);
120 $template->assign_vars(array(
121 'S_AGREEMENT' => true,
122 'AGREEMENT_TITLE' => $user->lang[$title],
123 'AGREEMENT_TEXT' => sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
124 'U_BACK' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
125 'L_BACK' => $user->lang['BACK_TO_LOGIN'])
128 page_footer();
130 break;
132 case 'delete_cookies':
134 // Delete Cookies with dynamic names (do NOT delete poll cookies)
135 if (confirm_box(true))
137 $set_time = time() - 31536000;
139 foreach ($_COOKIE as $cookie_name => $cookie_data)
141 $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
142 if (strpos($cookie_name, '_poll') === false)
144 $user->set_cookie($cookie_name, '', $set_time);
148 $user->set_cookie('track', '', $set_time);
149 $user->set_cookie('u', '', $set_time);
150 $user->set_cookie('k', '', $set_time);
151 $user->set_cookie('sid', '', $set_time);
153 // We destroy the session here, the user will be logged out nevertheless
154 $user->session_kill();
155 $user->session_begin();
157 meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
159 $message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
160 trigger_error($message);
162 else
164 confirm_box(false, 'DELETE_COOKIES', '');
167 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
169 break;
171 case 'switch_perm':
173 $user_id = request_var('u', 0);
175 $sql = 'SELECT *
176 FROM ' . USERS_TABLE . '
177 WHERE user_id = ' . (int) $user_id;
178 $result = $db->sql_query($sql);
179 $user_row = $db->sql_fetchrow($result);
180 $db->sql_freeresult($result);
182 if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'])
184 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
187 include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
189 $auth_admin = new auth_admin();
190 if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
192 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
195 add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
197 $message = sprintf($user->lang['PERMISSIONS_TRANSFERED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
198 trigger_error($message);
200 break;
202 case 'restore_perm':
204 if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
206 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
209 $auth->acl_cache($user->data);
211 $sql = 'UPDATE ' . USERS_TABLE . "
212 SET user_perm_from = 0
213 WHERE user_id = " . $user->data['user_id'];
214 $db->sql_query($sql);
216 $sql = 'SELECT username
217 FROM ' . USERS_TABLE . '
218 WHERE user_id = ' . $user->data['user_perm_from'];
219 $result = $db->sql_query($sql);
220 $username = $db->sql_fetchfield('username');
221 $db->sql_freeresult($result);
223 add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
225 $message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
226 trigger_error($message);
228 break;
231 // Only registered users can go beyond this point
232 if (!$user->data['is_registered'])
234 if ($user->data['is_bot'])
236 redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
239 login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
243 // Output listing of friends online
244 $update_time = $config['load_online_time'] * 60;
246 $sql = $db->sql_build_query('SELECT_DISTINCT', array(
247 'SELECT' => 'u.user_id, u.username, u.username_clean, u.user_colour, u.user_allow_viewonline, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
249 'FROM' => array(
250 USERS_TABLE => 'u',
251 ZEBRA_TABLE => 'z'
254 'LEFT_JOIN' => array(
255 array(
256 'FROM' => array(SESSIONS_TABLE => 's'),
257 'ON' => 's.session_user_id = z.zebra_id'
261 'WHERE' => 'z.user_id = ' . $user->data['user_id'] . '
262 AND z.friend = 1
263 AND u.user_id = z.zebra_id',
265 'GROUP_BY' => 'z.zebra_id, u.user_id, u.username_clean, u.user_allow_viewonline, u.user_colour, u.username',
267 'ORDER_BY' => 'u.username_clean ASC',
270 $result = $db->sql_query($sql);
272 while ($row = $db->sql_fetchrow($result))
274 $which = (time() - $update_time < $row['online_time'] && $row['viewonline'] && $row['user_allow_viewonline']) ? 'online' : 'offline';
276 $template->assign_block_vars("friends_{$which}", array(
277 'USER_ID' => $row['user_id'],
279 'U_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
280 'USER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
281 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
282 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
285 $db->sql_freeresult($result);
287 // Instantiate module system and generate list of available modules
288 $module->list_modules('ucp');
290 // Select the active module
291 $module->set_active($id, $mode);
293 // Load and execute the relevant module
294 $module->load_active();
296 // Assign data to the template engine for the list of modules
297 $module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
299 // Generate the page, do not display/query online list
300 $module->display($module->get_page_title(), false);
303 * Function for assigning a template var if the zebra module got included
305 function _module_zebra($mode, &$module_row)
307 global $template;
309 $template->assign_var('S_ZEBRA_ENABLED', true);