[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/ -> ucp.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package ucp
   5  * @version $Id: ucp.php,v 1.73 2006/10/21 15:46:23 grahamje Exp $
   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  */
  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);
  20  
  21  // Basic parameter data
  22  $id     = request_var('i', '');
  23  $mode    = request_var('mode', '');
  24  
  25  if ($mode == 'login' || $mode == 'logout')
  26  {
  27      define('IN_LOGIN', true);
  28  }
  29  
  30  // Start session management
  31  $user->session_begin();
  32  $auth->acl($user->data);
  33  $user->setup('ucp');
  34  
  35  // Setting a variable to let the style designer know where he is...
  36  $template->assign_var('S_IN_UCP', true);
  37  
  38  $module = new p_master();
  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          exit;
  73      break;
  74  
  75      case 'login':
  76          if ($user->data['is_registered'])
  77          {
  78              redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  79          }
  80  
  81          login_box("index.$phpEx");
  82      break;
  83  
  84      case 'logout':
  85          if ($user->data['user_id'] != ANONYMOUS)
  86          {
  87              $user->session_kill();
  88              $user->session_begin();
  89          }
  90  
  91          meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  92  
  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;
  96  
  97      case 'terms':
  98      case 'privacy':
  99  
 100          $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
 101          $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
 102  
 103          if (empty($user->lang[$message]))
 104          {
 105              if ($user->data['is_registered'])
 106              {
 107                  redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 108              }
 109  
 110              login_box();
 111          }
 112  
 113          $template->set_filenames(array(
 114              'body'        => 'ucp_agreement.html')
 115          );
 116  
 117          // Disable online list
 118          page_header($user->lang[$title], false);
 119  
 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'])
 126          );
 127  
 128          page_footer();
 129  
 130      break;
 131  
 132      case 'delete_cookies':
 133          
 134          // Delete Cookies with dynamic names (do NOT delete poll cookies)
 135          if (confirm_box(true))
 136          {
 137              $set_time = time() - 31536000;
 138  
 139              foreach ($_COOKIE as $cookie_name => $cookie_data)
 140              {
 141                  $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
 142                  if (strpos($cookie_name, '_poll') === false)
 143                  {
 144                      $user->set_cookie($cookie_name, '', $set_time);
 145                  }
 146              }
 147  
 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);
 152  
 153              // We destroy the session here, the user will be logged out nevertheless
 154              $user->session_kill();
 155              $user->session_begin();
 156  
 157              meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
 158  
 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);
 161          }
 162          else
 163          {
 164              confirm_box(false, 'DELETE_COOKIES', '');
 165          }
 166  
 167          redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 168  
 169      break;
 170  
 171      case 'switch_perm':
 172  
 173          $user_id = request_var('u', 0);
 174  
 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);
 181  
 182          if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'])
 183          {
 184              redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 185          }
 186  
 187          include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
 188  
 189          $auth_admin = new auth_admin();
 190          if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
 191          {
 192              redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 193          }
 194  
 195          add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
 196  
 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);
 199  
 200      break;
 201  
 202      case 'restore_perm':
 203  
 204          if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
 205          {
 206              redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 207          }
 208  
 209          $auth->acl_cache($user->data);
 210  
 211          $sql = 'UPDATE ' . USERS_TABLE . "
 212              SET user_perm_from = 0
 213              WHERE user_id = " . $user->data['user_id'];
 214          $db->sql_query($sql);
 215  
 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);
 222  
 223          add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
 224  
 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);
 227  
 228      break;
 229  }
 230  
 231  // Only registered users can go beyond this point
 232  if (!$user->data['is_registered'])
 233  {
 234      if ($user->data['is_bot'])
 235      {
 236          redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 237      }
 238  
 239      login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
 240  }
 241  
 242  
 243  // Output listing of friends online
 244  $update_time = $config['load_online_time'] * 60;
 245  
 246  $sql = $db->sql_build_query('SELECT_DISTINCT', array(
 247      'SELECT'    => 'u.user_id, u.username, u.user_colour, u.user_allow_viewonline, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
 248  
 249      'FROM'        => array(
 250          USERS_TABLE        => 'u',
 251          ZEBRA_TABLE        => 'z'
 252      ),
 253  
 254      'LEFT_JOIN'    => array(
 255          array(
 256              'FROM'    => array(SESSIONS_TABLE => 's'),
 257              'ON'    => 's.session_user_id = z.zebra_id'
 258          )
 259      ),
 260  
 261      'WHERE'        => 'z.user_id = ' . $user->data['user_id'] . '
 262          AND z.friend = 1
 263          AND u.user_id = z.zebra_id',
 264  
 265      'GROUP_BY'    => 'z.zebra_id, u.user_id, u.username, u.user_allow_viewonline, u.user_colour',
 266  
 267      'ORDER_BY'    => 'u.username ASC',
 268  ));
 269  
 270  $result = $db->sql_query($sql);
 271  
 272  while ($row = $db->sql_fetchrow($result))
 273  {
 274      $which = (time() - $update_time < $row['online_time'] && $row['viewonline'] && $row['user_allow_viewonline']) ? 'online' : 'offline';
 275  
 276      $template->assign_block_vars("friends_{$which}", array(
 277          'U_PROFILE'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
 278  
 279          'USER_ID'        => $row['user_id'],
 280          'USER_COLOUR'    => ($row['user_colour']) ? '#' . $row['user_colour'] : '',
 281          'USERNAME'        => $row['username'])
 282      );
 283  }
 284  $db->sql_freeresult($result);
 285  
 286  // Instantiate module system and generate list of available modules
 287  $module->list_modules('ucp');
 288  
 289  // Select the active module
 290  $module->set_active($id, $mode);
 291  
 292  // Load and execute the relevant module
 293  $module->load_active();
 294  
 295  // Assign data to the template engine for the list of modules
 296  $module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
 297  
 298  // Generate the page, do not display/query online list
 299  $module->display($module->get_page_title(), false);
 300  
 301  /**
 302  * Function for assigning a template var if the zebra module got included
 303  */
 304  function _module_zebra($mode, &$module_row)
 305  {
 306      global $template;
 307  
 308      $template->assign_var('S_ZEBRA_ENABLED', true);
 309  }
 310  
 311  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6