Blame Identity/Webenv/phpBB/3.0.4/includes/acp/acp_main.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package acp
ef5584
* @version $Id: acp_main.php 9171 2008-12-04 14:53:04Z acydburn $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* @package acp
ef5584
*/
ef5584
class acp_main
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $config, $db, $user, $auth, $template;
ef5584
		global $phpbb_root_path, $phpbb_admin_path, $phpEx;
ef5584
ef5584
		// Show restore permissions notice
ef5584
		if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm'))
ef5584
		{
ef5584
			$this->tpl_name = 'acp_main';
ef5584
			$this->page_title = 'ACP_MAIN';
ef5584
ef5584
			$sql = 'SELECT user_id, username, user_colour
ef5584
				FROM ' . USERS_TABLE . '
ef5584
				WHERE user_id = ' . $user->data['user_perm_from'];
ef5584
			$result = $db->sql_query($sql);
ef5584
			$user_row = $db->sql_fetchrow($result);
ef5584
			$db->sql_freeresult($result);
ef5584
ef5584
			$perm_from = '<strong' . (($user_row['user_colour']) ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
ef5584
			$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '' : '';
ef5584
			$perm_from .= $user_row['username'];
ef5584
			$perm_from .= ($user_row['user_id'] != ANONYMOUS) ? '' : '';
ef5584
			$perm_from .= '';
ef5584
ef5584
			$template->assign_vars(array(
ef5584
				'S_RESTORE_PERMISSIONS'		=> true,
ef5584
				'U_RESTORE_PERMISSIONS'		=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm'),
ef5584
				'PERM_FROM'					=> $perm_from,
ef5584
				'L_PERMISSIONS_TRANSFERRED_EXPLAIN'	=> sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=restore_perm')),
ef5584
			));
ef5584
ef5584
			return;
ef5584
		}
ef5584
ef5584
		$action = request_var('action', '');
ef5584
ef5584
		if ($action)
ef5584
		{
ef5584
			if ($action === 'admlogout')
ef5584
			{
ef5584
				$user->unset_admin();
ef5584
				$redirect_url = append_sid("{$phpbb_root_path}index.$phpEx");
ef5584
				meta_refresh(3, $redirect_url);
ef5584
				trigger_error($user->lang['ADM_LOGGED_OUT'] . '

' . sprintf($user->lang['RETURN_INDEX'], '', ''));
ef5584
			}
ef5584
ef5584
			if (!confirm_box(true))
ef5584
			{
ef5584
				switch ($action)
ef5584
				{
ef5584
					case 'online':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'RESET_ONLINE_CONFIRM';
ef5584
					break;
ef5584
					case 'stats':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'RESYNC_STATS_CONFIRM';
ef5584
					break;
ef5584
					case 'user':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
ef5584
					break;
ef5584
					case 'date':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'RESET_DATE_CONFIRM';
ef5584
					break;
ef5584
					case 'db_track':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
ef5584
					break;
ef5584
					case 'purge_cache':
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'PURGE_CACHE_CONFIRM';
ef5584
					break;
ef5584
ef5584
					default:
ef5584
						$confirm = true;
ef5584
						$confirm_lang = 'CONFIRM_OPERATION';
ef5584
				}
ef5584
ef5584
				if ($confirm)
ef5584
				{
ef5584
					confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array(
ef5584
						'i'			=> $id,
ef5584
						'mode'		=> $mode,
ef5584
						'action'	=> $action,
ef5584
					)));
ef5584
				}
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				switch ($action)
ef5584
				{
ef5584
ef5584
					case 'online':
ef5584
						if (!$auth->acl_get('a_board'))
ef5584
						{
ef5584
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
ef5584
						set_config('record_online_users', 1, true);
ef5584
						set_config('record_online_date', time(), true);
ef5584
						add_log('admin', 'LOG_RESET_ONLINE');
ef5584
					break;
ef5584
ef5584
					case 'stats':
ef5584
						if (!$auth->acl_get('a_board'))
ef5584
						{
ef5584
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
ef5584
						$sql = 'SELECT COUNT(post_id) AS stat
ef5584
							FROM ' . POSTS_TABLE . '
ef5584
							WHERE post_approved = 1';
ef5584
						$result = $db->sql_query($sql);
ef5584
						set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$sql = 'SELECT COUNT(topic_id) AS stat
ef5584
							FROM ' . TOPICS_TABLE . '
ef5584
							WHERE topic_approved = 1';
ef5584
						$result = $db->sql_query($sql);
ef5584
						set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$sql = 'SELECT COUNT(user_id) AS stat
ef5584
							FROM ' . USERS_TABLE . '
ef5584
							WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
ef5584
						$result = $db->sql_query($sql);
ef5584
						set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$sql = 'SELECT COUNT(attach_id) as stat
ef5584
							FROM ' . ATTACHMENTS_TABLE . '
ef5584
							WHERE is_orphan = 0';
ef5584
						$result = $db->sql_query($sql);
ef5584
						set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$sql = 'SELECT SUM(filesize) as stat
ef5584
							FROM ' . ATTACHMENTS_TABLE . '
ef5584
							WHERE is_orphan = 0';
ef5584
						$result = $db->sql_query($sql);
ef5584
						set_config('upload_dir_size', (float) $db->sql_fetchfield('stat'), true);
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						if (!function_exists('update_last_username'))
ef5584
						{
ef5584
							include($phpbb_root_path . "includes/functions_user.$phpEx");
ef5584
						}
ef5584
						update_last_username();
ef5584
ef5584
						add_log('admin', 'LOG_RESYNC_STATS');
ef5584
					break;
ef5584
ef5584
					case 'user':
ef5584
						if (!$auth->acl_get('a_board'))
ef5584
						{
ef5584
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
ef5584
						// Resync post counts
ef5584
						$start = $max_post_id = 0;
ef5584
ef5584
						// Find the maximum post ID, we can only stop the cycle when we've reached it
ef5584
						$sql = 'SELECT MAX(forum_last_post_id) as max_post_id
ef5584
							FROM ' . FORUMS_TABLE;
ef5584
						$result = $db->sql_query($sql);
ef5584
						$max_post_id = (int) $db->sql_fetchfield('max_post_id');
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						// No maximum post id? :o
ef5584
						if (!$max_post_id)
ef5584
						{
ef5584
							$sql = 'SELECT MAX(post_id)
ef5584
								FROM ' . POSTS_TABLE;
ef5584
							$result = $db->sql_query($sql);
ef5584
							$max_post_id = (int) $db->sql_fetchfield('max_post_id');
ef5584
							$db->sql_freeresult($result);
ef5584
						}
ef5584
ef5584
						// Still no maximum post id? Then we are finished
ef5584
						if (!$max_post_id)
ef5584
						{
ef5584
							add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
ef5584
							break;
ef5584
						}
ef5584
ef5584
						$step = ($config['num_posts']) ? (max((int) ($config['num_posts'] / 5), 20000)) : 20000;
ef5584
						$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
ef5584
ef5584
						while ($start < $max_post_id)
ef5584
						{
ef5584
							$sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
ef5584
								FROM ' . POSTS_TABLE . '
ef5584
								WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
ef5584
									AND post_postcount = 1 AND post_approved = 1
ef5584
								GROUP BY poster_id';
ef5584
							$result = $db->sql_query($sql);
ef5584
ef5584
							if ($row = $db->sql_fetchrow($result))
ef5584
							{
ef5584
								do
ef5584
								{
ef5584
									$sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
ef5584
									$db->sql_query($sql);
ef5584
								}
ef5584
								while ($row = $db->sql_fetchrow($result));
ef5584
							}
ef5584
							$db->sql_freeresult($result);
ef5584
ef5584
							$start += $step;
ef5584
						}
ef5584
ef5584
						add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
ef5584
ef5584
					break;
ef5584
ef5584
					case 'date':
ef5584
						if (!$auth->acl_get('a_board'))
ef5584
						{
ef5584
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
ef5584
						set_config('board_startdate', time() - 1);
ef5584
						add_log('admin', 'LOG_RESET_DATE');
ef5584
					break;
ef5584
ef5584
					case 'db_track':
ef5584
						switch ($db->sql_layer)
ef5584
						{
ef5584
							case 'sqlite':
ef5584
							case 'firebird':
ef5584
								$db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
ef5584
							break;
ef5584
ef5584
							default:
ef5584
								$db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
ef5584
							break;
ef5584
						}
ef5584
ef5584
						// This can get really nasty... therefore we only do the last six months
ef5584
						$get_from_time = time() - (6 * 4 * 7 * 24 * 60 * 60);
ef5584
ef5584
						// Select forum ids, do not include categories
ef5584
						$sql = 'SELECT forum_id
ef5584
							FROM ' . FORUMS_TABLE . '
ef5584
							WHERE forum_type <> ' . FORUM_CAT;
ef5584
						$result = $db->sql_query($sql);
ef5584
ef5584
						$forum_ids = array();
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							$forum_ids[] = $row['forum_id'];
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						// Any global announcements? ;)
ef5584
						$forum_ids[] = 0;
ef5584
ef5584
						// Now go through the forums and get us some topics...
ef5584
						foreach ($forum_ids as $forum_id)
ef5584
						{
ef5584
							$sql = 'SELECT p.poster_id, p.topic_id
ef5584
								FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
ef5584
								WHERE t.forum_id = ' . $forum_id . '
ef5584
									AND t.topic_moved_id = 0
ef5584
									AND t.topic_last_post_time > ' . $get_from_time . '
ef5584
									AND t.topic_id = p.topic_id
ef5584
									AND p.poster_id <> ' . ANONYMOUS . '
ef5584
								GROUP BY p.poster_id, p.topic_id';
ef5584
							$result = $db->sql_query($sql);
ef5584
ef5584
							$posted = array();
ef5584
							while ($row = $db->sql_fetchrow($result))
ef5584
							{
ef5584
								$posted[$row['poster_id']][] = $row['topic_id'];
ef5584
							}
ef5584
							$db->sql_freeresult($result);
ef5584
ef5584
							$sql_ary = array();
ef5584
							foreach ($posted as $user_id => $topic_row)
ef5584
							{
ef5584
								foreach ($topic_row as $topic_id)
ef5584
								{
ef5584
									$sql_ary[] = array(
ef5584
										'user_id'		=> (int) $user_id,
ef5584
										'topic_id'		=> (int) $topic_id,
ef5584
										'topic_posted'	=> 1,
ef5584
									);
ef5584
								}
ef5584
							}
ef5584
							unset($posted);
ef5584
ef5584
							if (sizeof($sql_ary))
ef5584
							{
ef5584
								$db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
ef5584
							}
ef5584
						}
ef5584
ef5584
						add_log('admin', 'LOG_RESYNC_POST_MARKING');
ef5584
					break;
ef5584
ef5584
					case 'purge_cache':
ef5584
						if ((int) $user->data['user_type'] !== USER_FOUNDER)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
						}
ef5584
ef5584
						global $cache;
ef5584
						$cache->purge();
ef5584
ef5584
						// Clear permissions
ef5584
						$auth->acl_clear_prefetch();
ef5584
						cache_moderators();
ef5584
ef5584
						add_log('admin', 'LOG_PURGE_CACHE');
ef5584
					break;
ef5584
				}
ef5584
			}
ef5584
		}
ef5584
ef5584
		// Get forum statistics
ef5584
		$total_posts = $config['num_posts'];
ef5584
		$total_topics = $config['num_topics'];
ef5584
		$total_users = $config['num_users'];
ef5584
		$total_files = $config['num_files'];
ef5584
ef5584
		$start_date = $user->format_date($config['board_startdate']);
ef5584
ef5584
		$boarddays = (time() - $config['board_startdate']) / 86400;
ef5584
ef5584
		$posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
ef5584
		$topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
ef5584
		$users_per_day = sprintf('%.2f', $total_users / $boarddays);
ef5584
		$files_per_day = sprintf('%.2f', $total_files / $boarddays);
ef5584
ef5584
		$upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
ef5584
ef5584
		$avatar_dir_size = 0;
ef5584
ef5584
		if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path']))
ef5584
		{
ef5584
			while (($file = readdir($avatar_dir)) !== false)
ef5584
			{
ef5584
				if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false)
ef5584
				{
ef5584
					$avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
ef5584
				}
ef5584
			}
ef5584
			closedir($avatar_dir);
ef5584
ef5584
			$avatar_dir_size = get_formatted_filesize($avatar_dir_size);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			// Couldn't open Avatar dir.
ef5584
			$avatar_dir_size = $user->lang['NOT_AVAILABLE'];
ef5584
		}
ef5584
ef5584
		if ($posts_per_day > $total_posts)
ef5584
		{
ef5584
			$posts_per_day = $total_posts;
ef5584
		}
ef5584
ef5584
		if ($topics_per_day > $total_topics)
ef5584
		{
ef5584
			$topics_per_day = $total_topics;
ef5584
		}
ef5584
ef5584
		if ($users_per_day > $total_users)
ef5584
		{
ef5584
			$users_per_day = $total_users;
ef5584
		}
ef5584
ef5584
		if ($files_per_day > $total_files)
ef5584
		{
ef5584
			$files_per_day = $total_files;
ef5584
		}
ef5584
ef5584
		if ($config['allow_attachments'] || $config['allow_pm_attach'])
ef5584
		{
ef5584
			$sql = 'SELECT COUNT(attach_id) AS total_orphan
ef5584
				FROM ' . ATTACHMENTS_TABLE . '
ef5584
				WHERE is_orphan = 1
ef5584
					AND filetime < ' . (time() - 3*60*60);
ef5584
			$result = $db->sql_query($sql);
ef5584
			$total_orphan = (int) $db->sql_fetchfield('total_orphan');
ef5584
			$db->sql_freeresult($result);
ef5584
		}
ef5584
		else
ef5584
		{
ef5584
			$total_orphan = false;
ef5584
		}
ef5584
ef5584
		$dbsize = get_database_size();
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'TOTAL_POSTS'		=> $total_posts,
ef5584
			'POSTS_PER_DAY'		=> $posts_per_day,
ef5584
			'TOTAL_TOPICS'		=> $total_topics,
ef5584
			'TOPICS_PER_DAY'	=> $topics_per_day,
ef5584
			'TOTAL_USERS'		=> $total_users,
ef5584
			'USERS_PER_DAY'		=> $users_per_day,
ef5584
			'TOTAL_FILES'		=> $total_files,
ef5584
			'FILES_PER_DAY'		=> $files_per_day,
ef5584
			'START_DATE'		=> $start_date,
ef5584
			'AVATAR_DIR_SIZE'	=> $avatar_dir_size,
ef5584
			'DBSIZE'			=> $dbsize,
ef5584
			'UPLOAD_DIR_SIZE'	=> $upload_dir_size,
ef5584
			'TOTAL_ORPHAN'		=> $total_orphan,
ef5584
			'S_TOTAL_ORPHAN'	=> ($total_orphan === false) ? false : true,
ef5584
			'GZIP_COMPRESSION'	=> ($config['gzip_compress']) ? $user->lang['ON'] : $user->lang['OFF'],
ef5584
			'DATABASE_INFO'		=> $db->sql_server_info(),
ef5584
			'BOARD_VERSION'		=> $config['version'],
ef5584
ef5584
			'U_ACTION'			=> $this->u_action,
ef5584
			'U_ADMIN_LOG'		=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=logs&mode=admin'),
ef5584
			'U_INACTIVE_USERS'	=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=inactive&mode=list'),
ef5584
ef5584
			'S_ACTION_OPTIONS'	=> ($auth->acl_get('a_board')) ? true : false,
ef5584
			'S_FOUNDER'			=> ($user->data['user_type'] == USER_FOUNDER) ? true : false,
ef5584
			)
ef5584
		);
ef5584
ef5584
		$log_data = array();
ef5584
		$log_count = 0;
ef5584
ef5584
		if ($auth->acl_get('a_viewlogs'))
ef5584
		{
ef5584
			view_log('admin', $log_data, $log_count, 5);
ef5584
ef5584
			foreach ($log_data as $row)
ef5584
			{
ef5584
				$template->assign_block_vars('log', array(
ef5584
					'USERNAME'	=> $row['username_full'],
ef5584
					'IP'		=> $row['ip'],
ef5584
					'DATE'		=> $user->format_date($row['time']),
ef5584
					'ACTION'	=> $row['action'])
ef5584
				);
ef5584
			}
ef5584
		}
ef5584
ef5584
		if ($auth->acl_get('a_user'))
ef5584
		{
ef5584
			$inactive = array();
ef5584
			$inactive_count = 0;
ef5584
ef5584
			view_inactive_users($inactive, $inactive_count, 10);
ef5584
ef5584
			foreach ($inactive as $row)
ef5584
			{
ef5584
				$template->assign_block_vars('inactive', array(
ef5584
					'INACTIVE_DATE'	=> $user->format_date($row['user_inactive_time']),
ef5584
					'JOINED'		=> $user->format_date($row['user_regdate']),
ef5584
					'LAST_VISIT'	=> (!$row['user_lastvisit']) ? ' - ' : $user->format_date($row['user_lastvisit']),
ef5584
					'REASON'		=> $row['inactive_reason'],
ef5584
					'USER_ID'		=> $row['user_id'],
ef5584
					'USERNAME'		=> $row['username'],
ef5584
					'U_USER_ADMIN'	=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&mode=overview&u={$row['user_id']}"))
ef5584
				);
ef5584
			}
ef5584
ef5584
			$option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
ef5584
			if ($config['email_enable'])
ef5584
			{
ef5584
				$option_ary += array('remind' => 'REMIND');
ef5584
			}
ef5584
ef5584
			$template->assign_vars(array(
ef5584
				'S_INACTIVE_USERS'		=> true,
ef5584
				'S_INACTIVE_OPTIONS'	=> build_select($option_ary))
ef5584
			);
ef5584
		}
ef5584
ef5584
		// Warn if install is still present
ef5584
		if (file_exists($phpbb_root_path . 'install'))
ef5584
		{
ef5584
			$template->assign_var('S_REMOVE_INSTALL', true);
ef5584
		}
ef5584
ef5584
		if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && is_writable($phpbb_root_path . 'config.' . $phpEx))
ef5584
		{
ef5584
			// World-Writable? (000x)
ef5584
			$template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x0002));
ef5584
		}
ef5584
ef5584
		$this->tpl_name = 'acp_main';
ef5584
		$this->page_title = 'ACP_MAIN';
ef5584
	}
ef5584
}
ef5584
ef5584
?>