Blame Extras/phpBB/3.0.4/includes/mcp/mcp_logs.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package mcp
4c79b5
* @version $Id: mcp_logs.php 9029 2008-10-18 18:44:41Z toonarmy $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* mcp_logs
4c79b5
* Handling warning the users
4c79b5
* @package mcp
4c79b5
*/
4c79b5
class mcp_logs
4c79b5
{
4c79b5
	var $u_action;
4c79b5
	var $p_master;
4c79b5
4c79b5
	function mcp_logs(&$p_master)
4c79b5
	{
4c79b5
		$this->p_master = &$p_master;
4c79b5
	}
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $auth, $db, $user, $template;
4c79b5
		global $config, $phpbb_root_path, $phpEx;
4c79b5
4c79b5
		$user->add_lang('acp/common');
4c79b5
4c79b5
		$action = request_var('action', array('' => ''));
4c79b5
4c79b5
		if (is_array($action))
4c79b5
		{
4c79b5
			list($action, ) = each($action);
4c79b5
		}
4c79b5
		else
4c79b5
		{
4c79b5
			$action = request_var('action', '');
4c79b5
		}
4c79b5
4c79b5
		// Set up general vars
4c79b5
		$start		= request_var('start', 0);
4c79b5
		$deletemark = ($action == 'del_marked') ? true : false;
4c79b5
		$deleteall	= ($action == 'del_all') ? true : false;
4c79b5
		$marked		= request_var('mark', array(0));
4c79b5
4c79b5
		// Sort keys
4c79b5
		$sort_days	= request_var('st', 0);
4c79b5
		$sort_key	= request_var('sk', 't');
4c79b5
		$sort_dir	= request_var('sd', 'd');
4c79b5
4c79b5
		$this->tpl_name = 'mcp_logs';
4c79b5
		$this->page_title = 'MCP_LOGS';
4c79b5
4c79b5
		$forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
4c79b5
		$forum_list[] = 0;
4c79b5
4c79b5
		$forum_id = $topic_id = 0;
4c79b5
4c79b5
		switch ($mode)
4c79b5
		{
4c79b5
			case 'front':
4c79b5
			break;
4c79b5
4c79b5
			case 'forum_logs':
4c79b5
				$forum_id = request_var('f', 0);
4c79b5
4c79b5
				if (!in_array($forum_id, $forum_list))
4c79b5
				{
4c79b5
					trigger_error('NOT_AUTHORISED');
4c79b5
				}
4c79b5
4c79b5
				$forum_list = array($forum_id);
4c79b5
			break;
4c79b5
4c79b5
			case 'topic_logs':
4c79b5
				$topic_id = request_var('t', 0);
4c79b5
4c79b5
				$sql = 'SELECT forum_id
4c79b5
					FROM ' . TOPICS_TABLE . '
4c79b5
					WHERE topic_id = ' . $topic_id;
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$forum_id = (int) $db->sql_fetchfield('forum_id');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				if (!in_array($forum_id, $forum_list))
4c79b5
				{
4c79b5
					trigger_error('NOT_AUTHORISED');
4c79b5
				}
4c79b5
4c79b5
				$forum_list = array($forum_id);
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		// Delete entries if requested and able
4c79b5
		if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
4c79b5
		{
4c79b5
			if (confirm_box(true))
4c79b5
			{
4c79b5
				if ($deletemark && sizeof($marked))
4c79b5
				{
4c79b5
					$sql = 'DELETE FROM ' . LOG_TABLE . '
4c79b5
						WHERE log_type = ' . LOG_MOD . '
4c79b5
							AND ' . $db->sql_in_set('forum_id', $forum_list) . '
4c79b5
							AND ' . $db->sql_in_set('log_id', $marked);
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					add_log('admin', 'LOG_CLEAR_MOD');
4c79b5
				}
4c79b5
				else if ($deleteall)
4c79b5
				{
4c79b5
					$sql = 'DELETE FROM ' . LOG_TABLE . '
4c79b5
						WHERE log_type = ' . LOG_MOD . '
4c79b5
							AND ' . $db->sql_in_set('forum_id', $forum_list);
4c79b5
4c79b5
					if ($mode == 'topic_logs')
4c79b5
					{
4c79b5
						$sql .= ' AND topic_id = ' . $topic_id;
4c79b5
					}
4c79b5
					$db->sql_query($sql);
4c79b5
4c79b5
					add_log('admin', 'LOG_CLEAR_MOD');
4c79b5
				}
4c79b5
			}
4c79b5
			else
4c79b5
			{
4c79b5
				confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
					'f'			=> $forum_id,
4c79b5
					't'			=> $topic_id,
4c79b5
					'start'		=> $start,
4c79b5
					'delmarked'	=> $deletemark,
4c79b5
					'delall'	=> $deleteall,
4c79b5
					'mark'		=> $marked,
4c79b5
					'st'		=> $sort_days,
4c79b5
					'sk'		=> $sort_key,
4c79b5
					'sd'		=> $sort_dir,
4c79b5
					'i'			=> $id,
4c79b5
					'mode'		=> $mode,
4c79b5
					'action'	=> request_var('action', array('' => ''))))
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Sorting
4c79b5
		$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
4c79b5
		$sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
4c79b5
		$sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
4c79b5
4c79b5
		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
4c79b5
		gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
4c79b5
4c79b5
		// Define where and sort sql for use in displaying logs
4c79b5
		$sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
4c79b5
		$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
4c79b5
4c79b5
		// Grab log data
4c79b5
		$log_data = array();
4c79b5
		$log_count = 0;
4c79b5
		view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort);
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'PAGE_NUMBER'		=> on_page($log_count, $config['topics_per_page'], $start),
4c79b5
			'TOTAL'				=> ($log_count == 1) ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count),
4c79b5
			'PAGINATION'		=> generate_pagination($this->u_action . "&$u_sort_param", $log_count, $config['topics_per_page'], $start),
4c79b5
4c79b5
			'L_TITLE'			=> $user->lang['MCP_LOGS'],
4c79b5
4c79b5
			'U_POST_ACTION'			=> $this->u_action,
4c79b5
			'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
4c79b5
			'S_SELECT_SORT_DIR'		=> $s_sort_dir,
4c79b5
			'S_SELECT_SORT_KEY'		=> $s_sort_key,
4c79b5
			'S_SELECT_SORT_DAYS'	=> $s_limit_days,
4c79b5
			'S_LOGS'				=> ($log_count > 0),
4c79b5
			)
4c79b5
		);
4c79b5
4c79b5
		foreach ($log_data as $row)
4c79b5
		{
4c79b5
			$data = array();
4c79b5
				
4c79b5
			$checks = array('viewtopic', 'viewforum');
4c79b5
			foreach ($checks as $check)
4c79b5
			{
4c79b5
				if (isset($row[$check]) && $row[$check])
4c79b5
				{
4c79b5
					$data[] = '' . $user->lang['LOGVIEW_' . strtoupper($check)] . '';
4c79b5
				}
4c79b5
			}
4c79b5
4c79b5
			$template->assign_block_vars('log', array(
4c79b5
				'USERNAME'		=> $row['username_full'],
4c79b5
				'IP'			=> $row['ip'],
4c79b5
				'DATE'			=> $user->format_date($row['time']),
4c79b5
				'ACTION'		=> $row['action'],
4c79b5
				'DATA'			=> (sizeof($data)) ? implode(' | ', $data) : '',
4c79b5
				'ID'			=> $row['id'],
4c79b5
				)
4c79b5
			);
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>