PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/ucp.php

https://code.google.com/p/phpbbex/
PHP | 361 lines | 245 code | 82 blank | 34 comment | 47 complexity | 101c5c4bbffd7115557f5254b40d76ee MD5 | raw file
Possible License(s): AGPL-1.0
  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. * @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. // Basic parameter data
  20. $id = request_var('i', '');
  21. $mode = request_var('mode', '');
  22. if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
  23. {
  24. define('IN_LOGIN', true);
  25. }
  26. // Start session management
  27. $user->session_begin();
  28. $auth->acl($user->data);
  29. $user->setup('ucp');
  30. // Setting a variable to let the style designer know where he is...
  31. $template->assign_var('S_IN_UCP', true);
  32. $module = new p_master();
  33. $default = false;
  34. // Basic "global" modes
  35. switch ($mode)
  36. {
  37. case 'activate':
  38. $module->load('ucp', 'activate');
  39. $module->display($user->lang['UCP_ACTIVATE']);
  40. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  41. break;
  42. case 'resend_act':
  43. $module->load('ucp', 'resend');
  44. $module->display($user->lang['UCP_RESEND']);
  45. break;
  46. case 'sendpassword':
  47. $module->load('ucp', 'remind');
  48. $module->display($user->lang['UCP_REMIND']);
  49. break;
  50. case 'register':
  51. if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
  52. {
  53. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  54. }
  55. $module->load('ucp', 'register');
  56. $module->display($user->lang['REGISTER']);
  57. break;
  58. case 'confirm':
  59. $module->load('ucp', 'confirm');
  60. break;
  61. case 'login':
  62. if ($user->data['is_registered'])
  63. {
  64. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  65. }
  66. login_box(request_var('redirect', "index.$phpEx"));
  67. break;
  68. case 'logout':
  69. if ($user->data['user_id'] != ANONYMOUS && isset($_GET['sid']) && !is_array($_GET['sid']) && $_GET['sid'] === $user->session_id)
  70. {
  71. $user->session_kill();
  72. $user->session_begin();
  73. $message = $user->lang['LOGOUT_REDIRECT'];
  74. }
  75. else
  76. {
  77. $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
  78. }
  79. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  80. $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
  81. trigger_error($message);
  82. break;
  83. case 'terms':
  84. case 'privacy':
  85. $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
  86. $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
  87. if (empty($user->lang[$message]))
  88. {
  89. if ($user->data['is_registered'])
  90. {
  91. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  92. }
  93. login_box();
  94. }
  95. $template->set_filenames(array(
  96. 'body' => 'ucp_agreement.html')
  97. );
  98. // Disable online list
  99. page_header($user->lang[$title], false);
  100. $template->assign_vars(array(
  101. 'S_AGREEMENT' => true,
  102. 'AGREEMENT_TITLE' => $user->lang[$title],
  103. 'AGREEMENT_TEXT' => sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
  104. 'U_BACK' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
  105. 'L_BACK' => $user->lang['BACK_TO_LOGIN'],
  106. ));
  107. page_footer();
  108. break;
  109. case 'delete_cookies':
  110. // Delete Cookies with dynamic names (do NOT delete poll cookies)
  111. if (confirm_box(true))
  112. {
  113. $set_time = time() - 31536000;
  114. foreach ($_COOKIE as $cookie_name => $cookie_data)
  115. {
  116. // Only delete board cookies, no other ones...
  117. if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0 || $cookie_name == $config['cookie_name'] . '_bid')
  118. {
  119. continue;
  120. }
  121. $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
  122. // Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
  123. if (strpos($cookie_name, 'poll_') !== 0)
  124. {
  125. $user->set_cookie($cookie_name, '', $set_time);
  126. }
  127. }
  128. $user->set_cookie('track', '', $set_time);
  129. $user->set_cookie('u', '', $set_time);
  130. $user->set_cookie('k', '', $set_time);
  131. $user->set_cookie('sid', '', $set_time);
  132. // We destroy the session here, the user will be logged out nevertheless
  133. $user->session_kill();
  134. $user->session_begin();
  135. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  136. $message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  137. trigger_error($message);
  138. }
  139. else
  140. {
  141. confirm_box(false, 'DELETE_COOKIES', '');
  142. }
  143. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  144. break;
  145. case 'switch_perm':
  146. $user_id = request_var('u', 0);
  147. $sql = 'SELECT *
  148. FROM ' . USERS_TABLE . '
  149. WHERE user_id = ' . (int) $user_id;
  150. $result = $db->sql_query($sql);
  151. $user_row = $db->sql_fetchrow($result);
  152. $db->sql_freeresult($result);
  153. if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
  154. {
  155. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  156. }
  157. include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  158. $auth_admin = new auth_admin();
  159. if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
  160. {
  161. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  162. }
  163. add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
  164. $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>');
  165. trigger_error($message);
  166. break;
  167. case 'restore_perm':
  168. if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
  169. {
  170. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  171. }
  172. $auth->acl_cache($user->data);
  173. $sql = 'SELECT username
  174. FROM ' . USERS_TABLE . '
  175. WHERE user_id = ' . $user->data['user_perm_from'];
  176. $result = $db->sql_query($sql);
  177. $username = $db->sql_fetchfield('username');
  178. $db->sql_freeresult($result);
  179. add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
  180. $message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  181. trigger_error($message);
  182. break;
  183. default:
  184. $default = true;
  185. break;
  186. }
  187. // We use this approach because it does not impose large code changes
  188. if (!$default)
  189. {
  190. return true;
  191. }
  192. // Only registered users can go beyond this point
  193. if (!$user->data['is_registered'])
  194. {
  195. if ($user->data['is_bot'])
  196. {
  197. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  198. }
  199. if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
  200. {
  201. $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
  202. login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
  203. }
  204. login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
  205. }
  206. // Instantiate module system and generate list of available modules
  207. $module->list_modules('ucp');
  208. // Check if the zebra module is set
  209. if ($module->is_active('zebra', 'friends'))
  210. {
  211. // Output listing of friends online
  212. $update_time = $config['load_online_time'] * 60;
  213. $sql = $db->sql_build_query('SELECT_DISTINCT', array(
  214. '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',
  215. 'FROM' => array(
  216. USERS_TABLE => 'u',
  217. ZEBRA_TABLE => 'z'
  218. ),
  219. 'LEFT_JOIN' => array(
  220. array(
  221. 'FROM' => array(SESSIONS_TABLE => 's'),
  222. 'ON' => 's.session_user_id = z.zebra_id'
  223. )
  224. ),
  225. 'WHERE' => 'z.user_id = ' . $user->data['user_id'] . '
  226. AND z.friend = 1
  227. AND u.user_id = z.zebra_id',
  228. 'GROUP_BY' => 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
  229. 'ORDER_BY' => 'u.username_clean ASC',
  230. ));
  231. $result = $db->sql_query($sql);
  232. while ($row = $db->sql_fetchrow($result))
  233. {
  234. $which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
  235. $template->assign_block_vars("friends_{$which}", array(
  236. 'USER_ID' => $row['user_id'],
  237. 'U_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
  238. 'USER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
  239. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
  240. 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
  241. );
  242. }
  243. $db->sql_freeresult($result);
  244. }
  245. // Do not display subscribed topics/forums if not allowed
  246. if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
  247. {
  248. $module->set_display('main', 'subscribed', false);
  249. }
  250. // Do not display signature panel if not authed to do so
  251. if (!$auth->acl_get('u_sig'))
  252. {
  253. $module->set_display('profile', 'signature', false);
  254. }
  255. // Select the active module
  256. $module->set_active($id, $mode);
  257. // Load and execute the relevant module
  258. $module->load_active();
  259. // Assign data to the template engine for the list of modules
  260. $module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
  261. // Generate the page, do not display/query online list
  262. $module->display($module->get_page_title(), false);
  263. /**
  264. * Function for assigning a template var if the zebra module got included
  265. */
  266. function _module_zebra($mode, &$module_row)
  267. {
  268. global $template;
  269. $template->assign_var('S_ZEBRA_ENABLED', true);
  270. if ($mode == 'friends')
  271. {
  272. $template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
  273. }
  274. if ($mode == 'foes')
  275. {
  276. $template->assign_var('S_ZEBRA_FOES_ENABLED', true);
  277. }
  278. }
  279. ?>