Blame Identity/Webenv/phpBB/3.0.4/includes/mcp/mcp_notes.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package mcp
ef5584
* @version $Id: mcp_notes.php 8598 2008-06-04 15:37:06Z naderman $
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
* mcp_notes
ef5584
* Displays notes about a user
ef5584
* @package mcp
ef5584
*/
ef5584
class mcp_notes
ef5584
{
ef5584
	var $p_master;
ef5584
	var $u_action;
ef5584
ef5584
	function mcp_notes(&$p_master)
ef5584
	{
ef5584
		$this->p_master = &$p_master;
ef5584
	}
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $auth, $db, $user, $template;
ef5584
		global $config, $phpbb_root_path, $phpEx;
ef5584
ef5584
		$action = request_var('action', array('' => ''));
ef5584
ef5584
		if (is_array($action))
ef5584
		{
ef5584
			list($action, ) = each($action);
ef5584
		}
ef5584
ef5584
		$this->page_title = 'MCP_NOTES';
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'front':
ef5584
				$template->assign_vars(array(
ef5584
					'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp&field=username&select_single=true'),
ef5584
					'U_POST_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes'),
ef5584
ef5584
					'L_TITLE'			=> $user->lang['MCP_NOTES'],
ef5584
				));
ef5584
ef5584
				$this->tpl_name = 'mcp_notes_front';
ef5584
			break;
ef5584
ef5584
			case 'user_notes':
ef5584
				$user->add_lang('acp/common');
ef5584
ef5584
				$this->mcp_notes_user_view($action);
ef5584
				$this->tpl_name = 'mcp_notes_user';
ef5584
			break;
ef5584
		}
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Display user notes
ef5584
	*/
ef5584
	function mcp_notes_user_view($action)
ef5584
	{
ef5584
		global $phpEx, $phpbb_root_path, $config;
ef5584
		global $template, $db, $user, $auth;
ef5584
ef5584
		$user_id = request_var('u', 0);
ef5584
		$username = request_var('username', '', true);
ef5584
		$start = request_var('start', 0);
ef5584
		$st	= request_var('st', 0);
ef5584
		$sk	= request_var('sk', 'b');
ef5584
		$sd	= request_var('sd', 'd');
ef5584
ef5584
		add_form_key('mcp_notes');
ef5584
ef5584
		$sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
ef5584
ef5584
		$sql = 'SELECT *
ef5584
			FROM ' . USERS_TABLE . "
ef5584
			WHERE $sql_where";
ef5584
		$result = $db->sql_query($sql);
ef5584
		$userrow = $db->sql_fetchrow($result);
ef5584
		$db->sql_freeresult($result);
ef5584
ef5584
		if (!$userrow)
ef5584
		{
ef5584
			trigger_error('NO_USER');
ef5584
		}
ef5584
ef5584
		$user_id = $userrow['user_id'];
ef5584
ef5584
		// Populate user id to the currently active module (this module)
ef5584
		// The following method is another way of adjusting module urls. It is the easy variant if we want
ef5584
		// to directly adjust the current module url based on data retrieved within the same module.
ef5584
		if (strpos($this->u_action, "&u=$user_id") === false)
ef5584
		{
ef5584
			$this->p_master->adjust_url('&u=' . $user_id);
ef5584
			$this->u_action .= "&u=$user_id";
ef5584
		}
ef5584
ef5584
		$deletemark = ($action == 'del_marked') ? true : false;
ef5584
		$deleteall	= ($action == 'del_all') ? true : false;
ef5584
		$marked		= request_var('marknote', array(0));
ef5584
		$usernote	= utf8_normalize_nfc(request_var('usernote', '', true));
ef5584
ef5584
		// Handle any actions
ef5584
		if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
ef5584
		{
ef5584
			$where_sql = '';
ef5584
			if ($deletemark && $marked)
ef5584
			{
ef5584
				$sql_in = array();
ef5584
				foreach ($marked as $mark)
ef5584
				{
ef5584
					$sql_in[] = $mark;
ef5584
				}
ef5584
				$where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
ef5584
				unset($sql_in);
ef5584
			}
ef5584
ef5584
			if ($where_sql || $deleteall)
ef5584
			{
ef5584
				if (check_form_key('mcp_notes'))
ef5584
				{
ef5584
					$sql = 'DELETE FROM ' . LOG_TABLE . '
ef5584
						WHERE log_type = ' . LOG_USERS . "
ef5584
							AND reportee_id = $user_id
ef5584
							$where_sql";
ef5584
					$db->sql_query($sql);
ef5584
ef5584
					add_log('admin', 'LOG_CLEAR_USER', $userrow['username']);
ef5584
ef5584
					$msg = ($deletemark) ? 'MARKED_NOTES_DELETED' : 'ALL_NOTES_DELETED';
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					$msg = 'FORM_INVALID';
ef5584
				}
ef5584
				$redirect = $this->u_action . '&u=' . $user_id;
ef5584
				meta_refresh(3, $redirect);
ef5584
				trigger_error($user->lang[$msg] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
			}
ef5584
		}
ef5584
ef5584
		if ($usernote && $action == 'add_feedback')
ef5584
		{
ef5584
			if (check_form_key('mcp_notes'))
ef5584
			{
ef5584
				add_log('admin', 'LOG_USER_FEEDBACK', $userrow['username']);
ef5584
				add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $userrow['username']);
ef5584
ef5584
				add_log('user', $user_id, 'LOG_USER_GENERAL', $usernote);
ef5584
				$msg = $user->lang['USER_FEEDBACK_ADDED'];
ef5584
			}
ef5584
			else
ef5584
			{
ef5584
				$msg = $user->lang['FORM_INVALID'];
ef5584
			}
ef5584
			$redirect = $this->u_action;
ef5584
			meta_refresh(3, $redirect);
ef5584
ef5584
			trigger_error($msg .  '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
		}
ef5584
ef5584
		// Generate the appropriate user information for the user we are looking at
ef5584
		if (!function_exists('get_user_avatar'))
ef5584
		{
ef5584
			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
ef5584
		}
ef5584
ef5584
		$rank_title = $rank_img = '';
ef5584
		$avatar_img = get_user_avatar($userrow['user_avatar'], $userrow['user_avatar_type'], $userrow['user_avatar_width'], $userrow['user_avatar_height']);
ef5584
ef5584
		$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']);
ef5584
		$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']);
ef5584
		$sort_by_sql = array('a' => 'u.username_clean', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation');
ef5584
ef5584
		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
ef5584
		gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
ef5584
ef5584
		// Define where and sort sql for use in displaying logs
ef5584
		$sql_where = ($st) ? (time() - ($st * 86400)) : 0;
ef5584
		$sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
ef5584
ef5584
		$log_data = array();
ef5584
		$log_count = 0;
ef5584
		view_log('user', $log_data, $log_count, $config['posts_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
ef5584
ef5584
		if ($log_count)
ef5584
		{
ef5584
			$template->assign_var('S_USER_NOTES', true);
ef5584
ef5584
			foreach ($log_data as $row)
ef5584
			{
ef5584
				$template->assign_block_vars('usernotes', array(
ef5584
					'REPORT_BY'		=> $row['username_full'],
ef5584
					'REPORT_AT'		=> $user->format_date($row['time']),
ef5584
					'ACTION'		=> $row['action'],
ef5584
					'IP'			=> $row['ip'],
ef5584
					'ID'			=> $row['id'])
ef5584
				);
ef5584
			}
ef5584
		}
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'U_POST_ACTION'			=> $this->u_action,
ef5584
			'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
ef5584
			'S_SELECT_SORT_DIR'		=> $s_sort_dir,
ef5584
			'S_SELECT_SORT_KEY'		=> $s_sort_key,
ef5584
			'S_SELECT_SORT_DAYS'	=> $s_limit_days,
ef5584
ef5584
			'L_TITLE'			=> $user->lang['MCP_NOTES_USER'],
ef5584
ef5584
			'PAGE_NUMBER'		=> on_page($log_count, $config['posts_per_page'], $start),
ef5584
			'PAGINATION'		=> generate_pagination($this->u_action . "&st=$st&sk=$sk&sd=$sd", $log_count, $config['posts_per_page'], $start),
ef5584
			'TOTAL_REPORTS'		=> ($log_count == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $log_count),
ef5584
ef5584
			'USERNAME'			=> $userrow['username'],
ef5584
			'USER_COLOR'		=> (!empty($userrow['user_colour'])) ? $userrow['user_colour'] : '',
ef5584
			'RANK_TITLE'		=> $rank_title,
ef5584
			'JOINED'			=> $user->format_date($userrow['user_regdate']),
ef5584
			'POSTS'				=> ($userrow['user_posts']) ? $userrow['user_posts'] : 0,
ef5584
			'WARNINGS'			=> ($userrow['user_warnings']) ? $userrow['user_warnings'] : 0,
ef5584
ef5584
			'AVATAR_IMG'		=> $avatar_img,
ef5584
			'RANK_IMG'			=> $rank_img,
ef5584
			)
ef5584
		);
ef5584
	}
ef5584
ef5584
}
ef5584
ef5584
?>