[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/includes/acp/ -> acp_main.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package acp
   5  * @version $Id: acp_main.php,v 1.36 2006/11/11 16:19:51 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * @package acp
  13  */
  14  class acp_main
  15  {
  16      var $u_action;
  17  
  18  	function main($id, $mode)
  19      {
  20          global $config, $db, $user, $auth, $template;
  21          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
  22  
  23          // Show restore permissions notice
  24          if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
  25          {
  26              $this->tpl_name = 'acp_main';
  27              $this->page_title = 'ACP_MAIN';
  28  
  29              $sql = 'SELECT user_id, username, user_colour
  30                  FROM ' . USERS_TABLE . '
  31                  WHERE user_id = ' . $user->data['user_perm_from'];
  32              $result = $db->sql_query($sql);
  33              $user_row = $db->sql_fetchrow($result);
  34              $db->sql_freeresult($result);
  35  
  36              $perm_from = '<strong' . (($user_row['user_colour']) ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
  37              $perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $user_row['user_id']) . '">' : '';
  38              $perm_from .= $user_row['username'];
  39              $perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '</a>' : '';
  40              $perm_from .= '</strong>';
  41  
  42              $template->assign_vars(array(
  43                  'S_RESTORE_PERMISSIONS'        => true,
  44                  'U_RESTORE_PERMISSIONS'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
  45                  'PERM_FROM'                    => $perm_from,
  46                  'L_PERMISSIONS_TRANSFERED_EXPLAIN'    => sprintf($user->lang['PERMISSIONS_TRANSFERED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
  47              ));
  48  
  49              return;
  50          }
  51  
  52          $action = request_var('action', '');
  53  
  54          switch ($action)
  55          {
  56              case 'online':
  57                  if (!$auth->acl_get('a_board'))
  58                  {
  59                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
  60                  }
  61  
  62                  set_config('record_online_users', 1, true);
  63                  set_config('record_online_date', time(), true);
  64                  add_log('admin', 'LOG_RESET_ONLINE');
  65              break;
  66  
  67              case 'stats':
  68                  if (!$auth->acl_get('a_board'))
  69                  {
  70                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
  71                  }
  72  
  73                  $sql = 'SELECT COUNT(post_id) AS stat 
  74                      FROM ' . POSTS_TABLE . '
  75                      WHERE post_approved = 1';
  76                  $result = $db->sql_query($sql);
  77                  $row = $db->sql_fetchrow($result);
  78                  $db->sql_freeresult($result);
  79  
  80                  set_config('num_posts', (int) $row['stat'], true);
  81  
  82                  $sql = 'SELECT COUNT(topic_id) AS stat
  83                      FROM ' . TOPICS_TABLE . '
  84                      WHERE topic_approved = 1';
  85                  $result = $db->sql_query($sql);
  86                  $row = $db->sql_fetchrow($result);
  87                  $db->sql_freeresult($result);
  88  
  89                  set_config('num_topics', (int) $row['stat'], true);
  90  
  91                  $sql = 'SELECT COUNT(user_id) AS stat
  92                      FROM ' . USERS_TABLE . '
  93                      WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
  94                  $result = $db->sql_query($sql);
  95                  $row = $db->sql_fetchrow($result);
  96                  $db->sql_freeresult($result);
  97  
  98                  set_config('num_users', (int) $row['stat'], true);
  99  
 100                  $sql = 'SELECT COUNT(attach_id) as stat
 101                      FROM ' . ATTACHMENTS_TABLE . '
 102                      WHERE is_orphan = 0';
 103                  $result = $db->sql_query($sql);
 104                  set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
 105                  $db->sql_freeresult($result);
 106  
 107                  $sql = 'SELECT SUM(filesize) as stat
 108                      FROM ' . ATTACHMENTS_TABLE . '
 109                      WHERE is_orphan = 0';
 110                  $result = $db->sql_query($sql);
 111                  set_config('upload_dir_size', (int) $db->sql_fetchfield('stat'), true);
 112                  $db->sql_freeresult($result);
 113  
 114                  add_log('admin', 'LOG_RESYNC_STATS');
 115              break;
 116  
 117              case 'user':
 118                  if (!$auth->acl_get('a_board'))
 119                  {
 120                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 121                  }
 122  
 123                  $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
 124                      FROM ' . POSTS_TABLE . '
 125                      WHERE post_postcount = 1
 126                      GROUP BY poster_id';
 127                  $result = $db->sql_query($sql);
 128  
 129                  while ($row = $db->sql_fetchrow($result))
 130                  {
 131                      $db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
 132                  }
 133                  $db->sql_freeresult($result);
 134  
 135                  add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
 136  
 137              break;
 138      
 139              case 'date':
 140                  if (!$auth->acl_get('a_board'))
 141                  {
 142                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 143                  }
 144  
 145                  set_config('board_startdate', time() - 1);
 146                  add_log('admin', 'LOG_RESET_DATE');
 147              break;
 148          
 149              case 'db_track':
 150                  $db->sql_query((($db->sql_layer != 'sqlite') ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . TOPICS_POSTED_TABLE);
 151  
 152                  // This can get really nasty... therefore we only do the last six months
 153                  $get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
 154  
 155                  // Select forum ids, do not include categories
 156                  $sql = 'SELECT forum_id
 157                      FROM ' . FORUMS_TABLE . '
 158                      WHERE forum_type <> ' . FORUM_CAT;
 159                  $result = $db->sql_query($sql);
 160          
 161                  $forum_ids = array();
 162                  while ($row = $db->sql_fetchrow($result))
 163                  {
 164                      $forum_ids[] = $row['forum_id'];
 165                  }
 166                  $db->sql_freeresult($result);
 167  
 168                  // Any global announcements? ;)
 169                  $forum_ids[] = 0;
 170  
 171                  // Now go through the forums and get us some topics...
 172                  foreach ($forum_ids as $forum_id)
 173                  {
 174                      $sql = 'SELECT p.poster_id, p.topic_id
 175                          FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
 176                          WHERE t.forum_id = ' . $forum_id . '
 177                              AND t.topic_moved_id = 0
 178                              AND t.topic_last_post_time > ' . $get_from_time . '
 179                              AND t.topic_id = p.topic_id
 180                              AND p.poster_id <> ' . ANONYMOUS . '
 181                          GROUP BY p.poster_id, p.topic_id';
 182                      $result = $db->sql_query($sql);
 183  
 184                      $posted = array();
 185                      while ($row = $db->sql_fetchrow($result))
 186                      {
 187                          $posted[$row['poster_id']][] = $row['topic_id'];
 188                      }
 189                      $db->sql_freeresult($result);
 190  
 191                      $sql_ary = array();
 192                      foreach ($posted as $user_id => $topic_row)
 193                      {
 194                          foreach ($topic_row as $topic_id)
 195                          {
 196                              $sql_ary[] = array(
 197                                  'user_id'        => $user_id,
 198                                  'topic_id'        => $topic_id,
 199                                  'topic_posted'    => 1,
 200                              );
 201                          }
 202                      }
 203                      unset($posted);
 204  
 205                      $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
 206                  }
 207      
 208                  add_log('admin', 'LOG_RESYNC_POST_MARKING');
 209              break;
 210          }
 211  
 212          // Get forum statistics
 213          $total_posts = $config['num_posts'];
 214          $total_topics = $config['num_topics'];
 215          $total_users = $config['num_users'];
 216          $total_files = $config['num_files'];
 217  
 218          $start_date = $user->format_date($config['board_startdate']);
 219  
 220          $boarddays = (time() - $config['board_startdate']) / 86400;
 221  
 222          $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
 223          $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
 224          $users_per_day = sprintf('%.2f', $total_users / $boarddays);
 225          $files_per_day = sprintf('%.2f', $total_files / $boarddays);
 226  
 227          $upload_dir_size = ($config['upload_dir_size'] >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($config['upload_dir_size'] / 1048576)) : (($config['upload_dir_size'] >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($config['upload_dir_size'] / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $config['upload_dir_size']));
 228  
 229          $avatar_dir_size = 0;
 230  
 231          if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
 232          {
 233              while (($file = readdir($avatar_dir)) !== false)
 234              {
 235                  if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
 236                  {
 237                      $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
 238                  }
 239              }
 240              @closedir($avatar_dir);
 241  
 242              // This bit of code translates the avatar directory size into human readable format
 243              // Borrowed the code from the PHP.net annoted manual, origanally written by:
 244              // Jesse (jesse@jess.on.ca)
 245              $avatar_dir_size = ($avatar_dir_size >= 1048576) ? sprintf('%.2f ' . $user->lang['MB'], ($avatar_dir_size / 1048576)) : (($avatar_dir_size >= 1024) ? sprintf('%.2f ' . $user->lang['KB'], ($avatar_dir_size / 1024)) : sprintf('%.2f ' . $user->lang['BYTES'], $avatar_dir_size));
 246          }
 247          else
 248          {
 249              // Couldn't open Avatar dir.
 250              $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
 251          }
 252  
 253          if ($posts_per_day > $total_posts)
 254          {
 255              $posts_per_day = $total_posts;
 256          }
 257  
 258          if ($topics_per_day > $total_topics)
 259          {
 260              $topics_per_day = $total_topics;
 261          }
 262  
 263          if ($users_per_day > $total_users)
 264          {
 265              $users_per_day = $total_users;
 266          }
 267  
 268          if ($files_per_day > $total_files)
 269          {
 270              $files_per_day = $total_files;
 271          }
 272  
 273          if ($config['allow_attachments'] || $config['allow_pm_attach'])
 274          {
 275              $sql = 'SELECT COUNT(attach_id) AS total_orphan
 276                  FROM ' . ATTACHMENTS_TABLE . '
 277                  WHERE is_orphan = 1
 278                      AND filetime < ' . (time() - 3*60*60);
 279              $result = $db->sql_query($sql);
 280              $total_orphan = (int) $db->sql_fetchfield('total_orphan');
 281              $db->sql_freeresult($result);
 282          }
 283          else
 284          {
 285              $total_orphan = false;
 286          }
 287  
 288          $dbsize = get_database_size();
 289          $s_action_options = build_select(array('online' => 'RESET_ONLINE', 'date' => 'RESET_DATE', 'stats' => 'RESYNC_STATS', 'user' => 'RESYNC_POSTCOUNTS', 'db_track' => 'RESYNC_POST_MARKING'));
 290  
 291          $template->assign_vars(array(
 292              'TOTAL_POSTS'        => $total_posts,
 293              'POSTS_PER_DAY'        => $posts_per_day,
 294              'TOTAL_TOPICS'        => $total_topics,
 295              'TOPICS_PER_DAY'    => $topics_per_day,
 296              'TOTAL_USERS'        => $total_users,
 297              'USERS_PER_DAY'        => $users_per_day,
 298              'TOTAL_FILES'        => $total_files,
 299              'FILES_PER_DAY'        => $files_per_day,
 300              'START_DATE'        => $start_date,
 301              'AVATAR_DIR_SIZE'    => $avatar_dir_size,
 302              'DBSIZE'            => $dbsize,
 303              'UPLOAD_DIR_SIZE'    => $upload_dir_size,
 304              'TOTAL_ORPHAN'        => $total_orphan,
 305              'S_TOTAL_ORPHAN'    => ($total_orphan === false) ? false : true,
 306              'GZIP_COMPRESSION'    => ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
 307              'DATABASE_INFO'        => $db->sql_server_info(),
 308  
 309              'U_ACTION'            => append_sid("{$phpbb_admin_path}index.$phpEx"),
 310              'U_ADMIN_LOG'        => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&amp;mode=admin'),
 311              'U_INACTIVE_USERS'    => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&amp;mode=list'),
 312  
 313              'S_ACTION_OPTIONS'    => ($auth->acl_get('a_board')) ? $s_action_options : '',
 314              )
 315          );
 316  
 317          $log_data = array();
 318          $log_count = 0;
 319  
 320          if ($auth->acl_get('a_viewlogs'))
 321          {
 322              view_log('admin', $log_data, $log_count, 5);
 323  
 324              foreach ($log_data as $row)
 325              {
 326                  $template->assign_block_vars('log', array(
 327                      'USERNAME'    => $row['username'],
 328                      'IP'        => $row['ip'],
 329                      'DATE'        => $user->format_date($row['time']),
 330                      'ACTION'    => $row['action'])
 331                  );
 332              }
 333          }
 334  
 335          if ($auth->acl_get('a_user'))
 336          {
 337              $inactive = array();
 338              $inactive_count = 0;
 339  
 340              view_inactive_users($inactive, $inactive_count, 10);
 341  
 342              foreach ($inactive as $row)
 343              {
 344                  $template->assign_block_vars('inactive', array(
 345                      'INACTIVE_DATE'    => $user->format_date($row['user_inactive_time']),
 346                      'JOINED'        => $user->format_date($row['user_regdate']),
 347                      'LAST_VISIT'    => (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
 348                      'REASON'        => $row['inactive_reason'],
 349                      'USER_ID'        => $row['user_id'],
 350                      'USERNAME'        => $row['username'],
 351                      'U_USER_ADMIN'    => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}"))
 352                  );
 353              }
 354  
 355              $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
 356              if ($config['email_enable'])
 357              {
 358                  $option_ary += array('remind' => 'REMIND');
 359              }
 360  
 361              $template->assign_vars(array(
 362                  'S_INACTIVE_USERS'        => true,
 363                  'S_INACTIVE_OPTIONS'    => build_select($option_ary))
 364              );
 365          }
 366  
 367          // Warn if install is still present
 368          if (file_exists($phpbb_root_path . 'install'))
 369          {
 370              $template->assign_var('S_REMOVE_INSTALL', true);
 371          }
 372  
 373          $this->tpl_name = 'acp_main';
 374          $this->page_title = 'ACP_MAIN';
 375      }
 376  }
 377  
 378  ?>


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