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

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

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

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