예제 #1
0
파일: admin.php 프로젝트: eaglstun/dbug
function route()
{
    switch (TRUE) {
        case isset($_GET['log_file']):
            view_log($_GET['log_file']);
            break;
        default:
            menu();
    }
}
예제 #2
0
 /**
  * @dataProvider view_log_function_data
  */
 public function test_view_log_function($expected, $expected_returned, $mode, $log_count, $limit = 5, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $limit_days = 0, $sort_by = 'l.log_id ASC', $keywords = '')
 {
     global $cache, $db, $user, $auth, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx;
     $db = $this->new_dbal();
     $cache = new phpbb_mock_cache();
     $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
     // Create auth mock
     $auth = $this->getMock('\\phpbb\\auth\\auth');
     $acl_get_map = array(array('f_read', 23, true), array('m_', 23, true));
     $acl_gets_map = array(array('a_', 'm_', 23, true));
     $auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap($acl_get_map));
     $auth->expects($this->any())->method('acl_gets')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap($acl_gets_map));
     $user = new phpbb_mock_user();
     $user->optionset('viewcensors', false);
     // Test sprintf() of the data into the action
     $user->lang = array('LOG_INSTALL_INSTALLED' => 'installed: %s', 'LOG_USER' => 'User<br /> %s', 'LOG_MOD2' => 'Mod2', 'LOG_MOD3' => 'Mod3: %1$s, %2$s', 'LOG_SINGULAR_PLURAL' => array(1 => 'singular', 2 => 'plural (%d)'));
     $phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
     $log = array();
     $this->assertEquals($expected_returned, view_log($mode, $log, $log_count, $limit, $offset, $forum_id, $topic_id, $user_id, $limit_days, $sort_by, $keywords));
     $this->assertEquals($expected, $log);
 }
예제 #3
0
	function main($id, $mode)
	{
		global $config, $db, $user, $auth, $template, $cache;
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;

		$user->add_lang(array('posting', 'ucp', 'acp/users'));
		$this->tpl_name = 'acp_users';
		$this->page_title = 'ACP_USER_' . strtoupper($mode);

		$error		= array();
		$username	= utf8_normalize_nfc(request_var('username', '', true));
		$user_id	= request_var('u', 0);
		$action		= request_var('action', '');

		$submit		= (isset($_POST['update']) && !isset($_POST['cancel'])) ? true : false;

		$form_name = 'acp_users';
		add_form_key($form_name);

		// Whois (special case)
		if ($action == 'whois')
		{
			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

			$this->page_title = 'WHOIS';
			$this->tpl_name = 'simple_body';

			$user_ip = request_var('user_ip', '');
			$domain = gethostbyaddr($user_ip);
			$ipwhois = user_ipwhois($user_ip);

			$template->assign_vars(array(
				'MESSAGE_TITLE'		=> sprintf($user->lang['IP_WHOIS_FOR'], $domain),
				'MESSAGE_TEXT'		=> nl2br($ipwhois))
			);

			return;
		}

		// Show user selection mask
		if (!$username && !$user_id)
		{
			$this->page_title = 'SELECT_USER';

			$template->assign_vars(array(
				'U_ACTION'			=> $this->u_action,
				'ANONYMOUS_USER_ID'	=> ANONYMOUS,

				'S_SELECT_USER'		=> true,
				'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true'),
			));

			return;
		}

		if (!$user_id)
		{
			$sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "
				WHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
			$result = $db->sql_query($sql);
			$user_id = (int) $db->sql_fetchfield('user_id');
			$db->sql_freeresult($result);

			if (!$user_id)
			{
				trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
			}
		}

		// Generate content for all modes
		$sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
		$result = $db->sql_query($sql);
		$user_row = $db->sql_fetchrow($result);
		$db->sql_freeresult($result);

		if (!$user_row)
		{
			trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
		}

		// Generate overall "header" for user admin
		$s_form_options = '';

		// Build modes dropdown list
		$sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "
			WHERE module_basename = 'users'
				AND module_enabled = 1
				AND module_class = 'acp'
			ORDER BY left_id, module_mode";
		$result = $db->sql_query($sql);

		$dropdown_modes = array();
		while ($row = $db->sql_fetchrow($result))
		{
			if (!$this->p_master->module_auth($row['module_auth']))
			{
				continue;
			}

			$dropdown_modes[$row['module_mode']] = true;
		}
		$db->sql_freeresult($result);

		foreach ($dropdown_modes as $module_mode => $null)
		{
			$selected = ($mode == $module_mode) ? ' selected="selected"' : '';
			$s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
		}

		$template->assign_vars(array(
			'U_BACK'			=> $this->u_action,
			'U_MODE_SELECT'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=$id&amp;u=$user_id"),
			'U_ACTION'			=> $this->u_action . '&amp;u=' . $user_id,
			'S_FORM_OPTIONS'	=> $s_form_options,
			'MANAGED_USERNAME'	=> $user_row['username'])
		);

		// Prevent normal users/admins change/view founders if they are not a founder by themselves
		if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER)
		{
			trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
		}

		switch ($mode)
		{
			case 'overview':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$user->add_lang('acp/ban');

				$delete			= request_var('delete', 0);
				$delete_type	= request_var('delete_type', '');
				$ip				= request_var('ip', 'ip');

				if ($submit)
				{
					// You can't delete the founder
					if ($delete && $user_row['user_type'] != USER_FOUNDER)
					{
						if (!$auth->acl_get('a_userdel'))
						{
							trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}

						// Check if the user wants to remove himself or the guest user account
						if ($user_id == ANONYMOUS)
						{
							trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}

						if ($user_id == $user->data['user_id'])
						{
							trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}

						if (confirm_box(true))
						{
							user_delete($delete_type, $user_id, $user_row['username']);

							add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
							trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
						}
						else
						{
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
								'u'				=> $user_id,
								'i'				=> $id,
								'mode'			=> $mode,
								'action'		=> $action,
								'update'		=> true,
								'delete'		=> 1,
								'delete_type'	=> $delete_type))
							);
						}
					}

					// Handle quicktool actions
					switch ($action)
					{
						case 'banuser':
						case 'banemail':
						case 'banip':

							if ($user_id == $user->data['user_id'])
							{
								trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$ban = array();

							switch ($action)
							{
								case 'banuser':
									$ban[] = $user_row['username'];
									$reason = 'USER_ADMIN_BAN_NAME_REASON';
									$log = 'LOG_USER_BAN_USER';
								break;

								case 'banemail':
									$ban[] = $user_row['user_email'];
									$reason = 'USER_ADMIN_BAN_EMAIL_REASON';
									$log = 'LOG_USER_BAN_EMAIL';
								break;

								case 'banip':
									$ban[] = $user_row['user_ip'];

									$sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "
										WHERE poster_id = $user_id";
									$result = $db->sql_query($sql);

									while ($row = $db->sql_fetchrow($result))
									{
										$ban[] = $row['poster_ip'];
									}
									$db->sql_freeresult($result);

									$reason = 'USER_ADMIN_BAN_IP_REASON';
									$log = 'LOG_USER_BAN_IP';
								break;
							}

							$ban_reason = utf8_normalize_nfc(request_var('ban_reason', $user->lang[$reason], true));
							$ban_give_reason = utf8_normalize_nfc(request_var('ban_give_reason', '', true));

							// Log not used at the moment, we simply utilize the ban function.
							$result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);

							trigger_error((($result === false) ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;

						case 'reactivate':

							if ($user_id == $user->data['user_id'])
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_IGNORE)
							{
								trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($config['email_enable'])
							{
								include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);

								$server_url = generate_board_url();

								$user_actkey = gen_rand_string(10);
								$key_len = 54 - (strlen($server_url));
								$key_len = ($key_len > 6) ? $key_len : 6;
								$user_actkey = substr($user_actkey, 0, $key_len);
								$email_template = ($user_row['user_type'] == USER_NORMAL) ? 'user_reactivate_account' : 'user_resend_inactive';

								if ($user_row['user_type'] == USER_NORMAL)
								{
									user_active_flip('deactivate', $user_id, INACTIVE_REMIND);

									$sql = 'UPDATE ' . USERS_TABLE . "
										SET user_actkey = '" . $db->sql_escape($user_actkey) . "'
										WHERE user_id = $user_id";
									$db->sql_query($sql);
								}
								else
								{
									// Grabbing the last confirm key - we only send a reminder
									$sql = 'SELECT user_actkey
										FROM ' . USERS_TABLE . '
										WHERE user_id = ' . $user_id;
									$result = $db->sql_query($sql);
									$user_actkey = (string) $db->sql_fetchfield('user_actkey');
									$db->sql_freeresult($result);
								}

								$messenger = new messenger(false);

								$messenger->template($email_template, $user_row['user_lang']);

								$messenger->to($user_row['user_email'], $user_row['username']);

								$messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
								$messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
								$messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
								$messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);

								$messenger->assign_vars(array(
									'WELCOME_MSG'	=> htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])),
									'USERNAME'		=> htmlspecialchars_decode($user_row['username']),
									'U_ACTIVATE'	=> "$server_url/ucp.$phpEx?mode=activate&u={$user_row['user_id']}&k=$user_actkey")
								);

								$messenger->send(NOTIFY_EMAIL);

								add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
								add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');

								trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
							}

						break;

						case 'active':

							if ($user_id == $user->data['user_id'])
							{
								// It is only deactivation since the user is already activated (else he would not have reached this page)
								trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_FOUNDER)
							{
								trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($user_row['user_type'] == USER_IGNORE)
							{
								trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							user_active_flip('flip', $user_id);

							$message = ($user_row['user_type'] == USER_INACTIVE) ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
							$log = ($user_row['user_type'] == USER_INACTIVE) ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';

							add_log('admin', $log, $user_row['username']);
							add_log('user', $user_id, $log . '_USER');

							trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;

						case 'delsig':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$sql_ary = array(
								'user_sig'					=> '',
								'user_sig_bbcode_uid'		=> '',
								'user_sig_bbcode_bitfield'	=> ''
							);

							$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
								WHERE user_id = $user_id";
							$db->sql_query($sql);
						
							add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
							add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');

							trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;

						case 'delavatar':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$sql_ary = array(
								'user_avatar'			=> '',
								'user_avatar_type'		=> 0,
								'user_avatar_width'		=> 0,
								'user_avatar_height'	=> 0,
							);

							$sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
								WHERE user_id = $user_id";
							$db->sql_query($sql);

							// Delete old avatar if present
							if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY)
							{
								avatar_delete('user', $user_row);
							}

							add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
							add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');

							trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
						break;

						case 'delposts':

							if (confirm_box(true))
							{
								// Delete posts, attachments, etc.
								delete_posts('poster_id', $user_id);

								add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
								trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
							}
							else
							{
								confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
									'u'				=> $user_id,
									'i'				=> $id,
									'mode'			=> $mode,
									'action'		=> $action,
									'update'		=> true))
								);
							}

						break;

						case 'delattach':

							if (confirm_box(true))
							{
								delete_attachments('user', $user_id);

								add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
								trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
							}
							else
							{
								confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
									'u'				=> $user_id,
									'i'				=> $id,
									'mode'			=> $mode,
									'action'		=> $action,
									'update'		=> true))
								);
							}
						
						break;
						
						case 'moveposts':

							if (!check_form_key($form_name))
							{
								trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							$user->add_lang('acp/forums');

							$new_forum_id = request_var('new_f', 0);

							if (!$new_forum_id)
							{
								$this->page_title = 'USER_ADMIN_MOVE_POSTS';

								$template->assign_vars(array(
									'S_SELECT_FORUM'		=> true,
									'U_ACTION'				=> $this->u_action . "&amp;action=$action&amp;u=$user_id",
									'U_BACK'				=> $this->u_action . "&amp;u=$user_id",
									'S_FORUM_OPTIONS'		=> make_forum_select(false, false, false, true))
								);

								return;
							}

							// Is the new forum postable to?
							$sql = 'SELECT forum_name, forum_type
								FROM ' . FORUMS_TABLE . "
								WHERE forum_id = $new_forum_id";
							$result = $db->sql_query($sql);
							$forum_info = $db->sql_fetchrow($result);
							$db->sql_freeresult($result);

							if (!$forum_info)
							{
								trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($forum_info['forum_type'] != FORUM_POST)
							{
								trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							// Two stage?
							// Move topics comprising only posts from this user
							$topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
							$forum_id_ary = array($new_forum_id);

							$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "
								WHERE poster_id = $user_id
									AND forum_id <> $new_forum_id
								GROUP BY topic_id";
							$result = $db->sql_query($sql);

							while ($row = $db->sql_fetchrow($result))
							{
								$topic_id_ary[$row['topic_id']] = $row['total_posts'];
							}
							$db->sql_freeresult($result);

							if (sizeof($topic_id_ary))
							{
								$sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real, topic_attachment
									FROM ' . TOPICS_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
								$result = $db->sql_query($sql);

								while ($row = $db->sql_fetchrow($result))
								{
									if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
									{
										$move_topic_ary[] = $row['topic_id'];
									}
									else
									{
										$move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
										$move_post_ary[$row['topic_id']]['attach'] = ($row['topic_attachment']) ? 1 : 0;
									}

									$forum_id_ary[] = $row['forum_id'];
								}
								$db->sql_freeresult($result);
							}

							// Entire topic comprises posts by this user, move these topics
							if (sizeof($move_topic_ary))
							{
								move_topics($move_topic_ary, $new_forum_id, false);
							}

							if (sizeof($move_post_ary))
							{
								// Create new topic
								// Update post_ids, report_ids, attachment_ids
								foreach ($move_post_ary as $topic_id => $post_ary)
								{
									// Create new topic
									$sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
										'topic_poster'				=> $user_id,
										'topic_time'				=> time(),
										'forum_id' 					=> $new_forum_id,
										'icon_id'					=> 0,
										'topic_approved'			=> 1,
										'topic_title' 				=> $post_ary['title'],
										'topic_first_poster_name'	=> $user_row['username'],
										'topic_type'				=> POST_NORMAL,
										'topic_time_limit'			=> 0,
										'topic_attachment'			=> $post_ary['attach'])
									);
									$db->sql_query($sql);

									$new_topic_id = $db->sql_nextid();

									// Move posts
									$sql = 'UPDATE ' . POSTS_TABLE . "
										SET forum_id = $new_forum_id, topic_id = $new_topic_id
										WHERE topic_id = $topic_id
											AND poster_id = $user_id";
									$db->sql_query($sql);

									if ($post_ary['attach'])
									{
										$sql = 'UPDATE ' . ATTACHMENTS_TABLE . "
											SET topic_id = $new_topic_id
											WHERE topic_id = $topic_id
												AND poster_id = $user_id";
										$db->sql_query($sql);
									}

									$new_topic_id_ary[] = $new_topic_id;
								}
							}

							$forum_id_ary = array_unique($forum_id_ary);
							$topic_id_ary = array_unique(array_merge($topic_id_ary, $new_topic_id_ary));

							if (sizeof($topic_id_ary))
							{
								sync('reported', 'topic_id', $topic_id_ary);
								sync('topic', 'topic_id', $topic_id_ary);
							}

							if (sizeof($forum_id_ary))
							{
								sync('forum', 'forum_id', $forum_id_ary, false, true);
							}


							add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
							add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);

							trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));

						break;
					}

					// Handle registration info updates
					$data = array(
						'username'			=> utf8_normalize_nfc(request_var('user', $user_row['username'], true)),
						'user_founder'		=> request_var('user_founder', ($user_row['user_type'] == USER_FOUNDER) ? 1 : 0),
						'email'				=> strtolower(request_var('user_email', $user_row['user_email'])),
						'email_confirm'		=> strtolower(request_var('email_confirm', '')),
						'new_password'		=> request_var('new_password', '', true),
						'password_confirm'	=> request_var('password_confirm', '', true),
					);

					// Validation data - we do not check the password complexity setting here
					$check_ary = array(
						'new_password'		=> array(
							array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
							array('password')),
						'password_confirm'	=> array('string', true, $config['min_pass_chars'], $config['max_pass_chars']),
					);

					// Check username if altered
					if ($data['username'] != $user_row['username'])
					{
						$check_ary += array(
							'username'			=> array(
								array('string', false, $config['min_name_chars'], $config['max_name_chars']),
								array('username', $user_row['username'])
							),
						);
					}

					// Check email if altered
					if ($data['email'] != $user_row['user_email'])
					{
						$check_ary += array(
							'email'				=> array(
								array('string', false, 6, 60),
								array('email', $user_row['user_email'])
							),
							'email_confirm'		=> array('string', true, 6, 60)
						);
					}

					$error = validate_data($data, $check_ary);

					if ($data['new_password'] && $data['password_confirm'] != $data['new_password'])
					{
						$error[] = 'NEW_PASSWORD_ERROR';
					}

					if ($data['email'] != $user_row['user_email'] && $data['email_confirm'] != $data['email'])
					{
						$error[] = 'NEW_EMAIL_ERROR';
					}

					if (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					// Which updates do we need to do?
					$update_username = ($user_row['username'] != $data['username']) ? $data['username'] : false;
					$update_password = ($data['new_password'] && !phpbb_check_hash($user_row['user_password'], $data['new_password'])) ? true : false;
					$update_email = ($data['email'] != $user_row['user_email']) ? $data['email'] : false;

					if (!sizeof($error))
					{
						$sql_ary = array();

						if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER)
						{
							// Only allow founders updating the founder status...
							if ($user->data['user_type'] == USER_FOUNDER)
							{
								// Setting a normal member to be a founder
								if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER)
								{
									// Make sure the user is not setting an Inactive or ignored user to be a founder
									if ($user_row['user_type'] == USER_IGNORE)
									{
										trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}

									if ($user_row['user_type'] == USER_INACTIVE)
									{
										trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}

									$sql_ary['user_type'] = USER_FOUNDER;
								}
								else if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER)
								{
									// Check if at least one founder is present
									$sql = 'SELECT user_id
										FROM ' . USERS_TABLE . '
										WHERE user_type = ' . USER_FOUNDER . '
											AND user_id <> ' . $user_id;
									$result = $db->sql_query_limit($sql, 1);
									$row = $db->sql_fetchrow($result);
									$db->sql_freeresult($result);

									if ($row)
									{
										$sql_ary['user_type'] = USER_NORMAL;
									}
									else
									{
										trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
									}
								}
							}
						}

						if ($update_username !== false)
						{
							$sql_ary['username'] = $update_username;
							$sql_ary['username_clean'] = utf8_clean_string($update_username);

							add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
						}

						if ($update_email !== false)
						{
							$sql_ary += array(
								'user_email'		=> $update_email,
								'user_email_hash'	=> crc32($update_email) . strlen($update_email)
							);

							add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
						}

						if ($update_password)
						{
							$sql_ary += array(
								'user_password'		=> phpbb_hash($data['new_password']),
								'user_passchg'		=> time(),
								'user_pass_convert'	=> 0,
							);

							$user->reset_login_keys($user_id);
							add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
						}

						if (sizeof($sql_ary))
						{
							$sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
							$db->sql_query($sql);
						}

						if ($update_username)
						{
							user_update_name($user_row['username'], $update_username);
						}

						// Let the users permissions being updated
						$auth->acl_clear_prefetch($user_id);

						add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);

						trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				if ($user_id == $user->data['user_id'])
				{
					$quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
				}
				else
				{
					$quick_tool_ary = array();

					if ($user_row['user_type'] != USER_FOUNDER)
					{
						$quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
					}

					if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE)
					{
						$quick_tool_ary += array('active' => (($user_row['user_type'] == USER_INACTIVE) ? 'ACTIVATE' : 'DEACTIVATE'));
					}
					
					$quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
					
					if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE))
					{
						$quick_tool_ary['reactivate'] = 'FORCE';
					}
				}

				$s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
				foreach ($quick_tool_ary as $value => $lang)
				{
					$s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
				}

				if ($config['load_onlinetrack'])
				{
					$sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
						FROM ' . SESSIONS_TABLE . "
						WHERE session_user_id = $user_id";
					$result = $db->sql_query($sql);
					$row = $db->sql_fetchrow($result);
					$db->sql_freeresult($result);

					$user_row['session_time'] = (isset($row['session_time'])) ? $row['session_time'] : 0;
					$user_row['session_viewonline'] = (isset($row['session_viewonline'])) ? $row['session_viewonline'] : 0;
					unset($row);
				}

				$last_visit = (!empty($user_row['session_time'])) ? $user_row['session_time'] : $user_row['user_lastvisit'];

				$inactive_reason = '';
				if ($user_row['user_type'] == USER_INACTIVE)
				{
					$inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];

					switch ($user_row['user_inactive_reason'])
					{
						case INACTIVE_REGISTER:
							$inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
						break;

						case INACTIVE_PROFILE:
							$inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
						break;

						case INACTIVE_MANUAL:
							$inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
						break;

						case INACTIVE_REMIND:
							$inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
						break;
					}
				}

				$template->assign_vars(array(
					'L_NAME_CHARS_EXPLAIN'		=> sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']),
					'L_CHANGE_PASSWORD_EXPLAIN'	=> sprintf($user->lang[$config['pass_complex'] . '_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']),
					'S_FOUNDER'					=> ($user->data['user_type'] == USER_FOUNDER) ? true : false,

					'S_OVERVIEW'		=> true,
					'S_USER_IP'			=> ($user_row['user_ip']) ? true : false,
					'S_USER_FOUNDER'	=> ($user_row['user_type'] == USER_FOUNDER) ? true : false,
					'S_ACTION_OPTIONS'	=> $s_action_options,
					'S_OWN_ACCOUNT'		=> ($user_id == $user->data['user_id']) ? true : false,
					'S_USER_INACTIVE'	=> ($user_row['user_type'] == USER_INACTIVE) ? true : false,

					'U_SHOW_IP'		=> $this->u_action . "&amp;u=$user_id&amp;ip=" . (($ip == 'ip') ? 'hostname' : 'ip'),
					'U_WHOIS'		=> $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}",

					'U_SWITCH_PERMISSIONS'	=> ($auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", "mode=switch_perm&amp;u={$user_row['user_id']}") : '',

					'USER'				=> $user_row['username'],
					'USER_REGISTERED'	=> $user->format_date($user_row['user_regdate']),
					'REGISTERED_IP'		=> ($ip == 'hostname') ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'],
					'USER_LASTACTIVE'	=> ($last_visit) ? $user->format_date($last_visit) : ' - ',
					'USER_EMAIL'		=> $user_row['user_email'],
					'USER_WARNINGS'		=> $user_row['user_warnings'],
					'USER_POSTS'		=> $user_row['user_posts'],
					'USER_INACTIVE_REASON'	=> $inactive_reason,
				));

			break;

			case 'feedback':

				$user->add_lang('mcp');
				
				// Set up general vars
				$start		= request_var('start', 0);
				$deletemark = (isset($_POST['delmarked'])) ? true : false;
				$deleteall	= (isset($_POST['delall'])) ? true : false;
				$marked		= request_var('mark', array(0));
				$message	= utf8_normalize_nfc(request_var('message', '', true));

				// Sort keys
				$sort_days	= request_var('st', 0);
				$sort_key	= request_var('sk', 't');
				$sort_dir	= request_var('sd', 'd');

				// Delete entries if requested and able
				if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					$where_sql = '';
					if ($deletemark && $marked)
					{
						$sql_in = array();
						foreach ($marked as $mark)
						{
							$sql_in[] = $mark;
						}
						$where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
						unset($sql_in);
					}

					if ($where_sql || $deleteall)
					{
						$sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "
							$where_sql";
						$db->sql_query($sql);

						add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
					}
				}

				if ($submit && $message)
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
					add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $user_row['username']);
					add_log('user', $user_id, 'LOG_USER_GENERAL', $message);

					trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
				}
				
				// Sorting
				$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']);
				$sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
				$sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');

				$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
				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);

				// Define where and sort sql for use in displaying logs
				$sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
				$sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');

				// Grab log data
				$log_data = array();
				$log_count = 0;
				view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);

				$template->assign_vars(array(
					'S_FEEDBACK'	=> true,
					'S_ON_PAGE'		=> on_page($log_count, $config['topics_per_page'], $start),
					'PAGINATION'	=> generate_pagination($this->u_action . "&amp;u=$user_id&amp;$u_sort_param", $log_count, $config['topics_per_page'], $start, true),

					'S_LIMIT_DAYS'	=> $s_limit_days,
					'S_SORT_KEY'	=> $s_sort_key,
					'S_SORT_DIR'	=> $s_sort_dir,
					'S_CLEARLOGS'	=> $auth->acl_get('a_clearlogs'))
				);

				foreach ($log_data as $row)
				{
					$template->assign_block_vars('log', array(
						'USERNAME'		=> $row['username_full'],
						'IP'			=> $row['ip'],
						'DATE'			=> $user->format_date($row['time']),
						'ACTION'		=> nl2br($row['action']),
						'ID'			=> $row['id'])
					);
				}

			break;

			case 'profile':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);

				$cp = new custom_profile();

				$cp_data = $cp_error = array();

				$sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "
					WHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
				$result = $db->sql_query($sql);
				$row = $db->sql_fetchrow($result);
				$db->sql_freeresult($result);

				$user_row['iso_lang_id'] = $row['lang_id'];

				$data = array(
					'icq'			=> request_var('icq', $user_row['user_icq']),
					'aim'			=> request_var('aim', $user_row['user_aim']),
					'msn'			=> request_var('msn', $user_row['user_msnm']),
					'yim'			=> request_var('yim', $user_row['user_yim']),
					'jabber'		=> utf8_normalize_nfc(request_var('jabber', $user_row['user_jabber'], true)),
					'website'		=> request_var('website', $user_row['user_website']),
					'location'		=> utf8_normalize_nfc(request_var('location', $user_row['user_from'], true)),
					'occupation'	=> utf8_normalize_nfc(request_var('occupation', $user_row['user_occ'], true)),
					'interests'		=> utf8_normalize_nfc(request_var('interests', $user_row['user_interests'], true)),
					'bday_day'		=> 0,
					'bday_month'	=> 0,
					'bday_year'		=> 0,
				);

				if ($user_row['user_birthday'])
				{
					list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
				}

				$data['bday_day'] = request_var('bday_day', $data['bday_day']);
				$data['bday_month'] = request_var('bday_month', $data['bday_month']);
				$data['bday_year'] = request_var('bday_year', $data['bday_year']);

				if ($submit)
				{
					$error = validate_data($data, array(
						'icq'			=> array(
							array('string', true, 3, 15),
							array('match', true, '#^[0-9]+$#i')),
						'aim'			=> array('string', true, 3, 255),
						'msn'			=> array('string', true, 5, 255),
						'jabber'		=> array(
							array('string', true, 5, 255),
							array('jabber')),
						'yim'			=> array('string', true, 5, 255),
						'website'		=> array(
							array('string', true, 12, 255),
							array('match', true, '#^http[s]?://(.*?\.)*?[a-z0-9\-]+\.[a-z]{2,4}#i')),
						'location'		=> array('string', true, 2, 255),
						'occupation'	=> array('string', true, 2, 500),
						'interests'		=> array('string', true, 2, 500),
						'bday_day'		=> array('num', true, 1, 31),
						'bday_month'	=> array('num', true, 1, 12),
						'bday_year'		=> array('num', true, 1901, gmdate('Y', time())),
					));

					// validate custom profile fields
					$cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);

					if (sizeof($cp_error))
					{
						$error = array_merge($error, $cp_error);
					}
					if (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					if (!sizeof($error))
					{
						$sql_ary = array(
							'user_icq'		=> $data['icq'],
							'user_aim'		=> $data['aim'],
							'user_msnm'		=> $data['msn'],
							'user_yim'		=> $data['yim'],
							'user_jabber'	=> $data['jabber'],
							'user_website'	=> $data['website'],
							'user_from'		=> $data['location'],
							'user_occ'		=> $data['occupation'],
							'user_interests'=> $data['interests'],
							'user_birthday'	=> sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']),
						);

						$sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
							WHERE user_id = $user_id";
						$db->sql_query($sql);

						// Update Custom Fields
						if (sizeof($cp_data))
						{
							switch ($db->sql_layer)
							{
								case 'oracle':
								case 'firebird':
								case 'postgres':
									$right_delim = $left_delim = '"';
								break;

								case 'sqlite':
								case 'mssql':
								case 'mssql_odbc':
									$right_delim = ']';
									$left_delim = '[';
								break;

								case 'mysql':
								case 'mysql4':
								case 'mysqli':
									$right_delim = $left_delim = '`';
								break;
							}

							foreach ($cp_data as $key => $value)
							{
								$cp_data[$left_delim . $key . $right_delim] = $value;
								unset($cp_data[$key]);
							}

							$sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "
								WHERE user_id = $user_id";
							$db->sql_query($sql);

							if (!$db->sql_affectedrows())
							{
								$cp_data['user_id'] = (int) $user_id;

								$db->sql_return_on_error(true);

								$sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
								$db->sql_query($sql);

								$db->sql_return_on_error(false);
							}
						}

						trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				$s_birthday_day_options = '<option value="0"' . ((!$data['bday_day']) ? ' selected="selected"' : '') . '>--</option>';
				for ($i = 1; $i < 32; $i++)
				{
					$selected = ($i == $data['bday_day']) ? ' selected="selected"' : '';
					$s_birthday_day_options .= "<option value=\"$i\"$selected>$i</option>";
				}

				$s_birthday_month_options = '<option value="0"' . ((!$data['bday_month']) ? ' selected="selected"' : '') . '>--</option>';
				for ($i = 1; $i < 13; $i++)
				{
					$selected = ($i == $data['bday_month']) ? ' selected="selected"' : '';
					$s_birthday_month_options .= "<option value=\"$i\"$selected>$i</option>";
				}
				$s_birthday_year_options = '';

				$now = getdate();
				$s_birthday_year_options = '<option value="0"' . ((!$data['bday_year']) ? ' selected="selected"' : '') . '>--</option>';
				for ($i = $now['year'] - 100; $i < $now['year']; $i++)
				{
					$selected = ($i == $data['bday_year']) ? ' selected="selected"' : '';
					$s_birthday_year_options .= "<option value=\"$i\"$selected>$i</option>";
				}
				unset($now);

				$template->assign_vars(array(
					'ICQ'			=> $data['icq'],
					'YIM'			=> $data['yim'],
					'AIM'			=> $data['aim'],
					'MSN'			=> $data['msn'],
					'JABBER'		=> $data['jabber'],
					'WEBSITE'		=> $data['website'],
					'LOCATION'		=> $data['location'],
					'OCCUPATION'	=> $data['occupation'],
					'INTERESTS'		=> $data['interests'],

					'S_BIRTHDAY_DAY_OPTIONS'	=> $s_birthday_day_options,
					'S_BIRTHDAY_MONTH_OPTIONS'	=> $s_birthday_month_options,
					'S_BIRTHDAY_YEAR_OPTIONS'	=> $s_birthday_year_options,
						
					'S_PROFILE'		=> true)
				);

				// Get additional profile fields and assign them to the template block var 'profile_fields'
				$user->get_profile_fields($user_id);

				$cp->generate_profile_fields('profile', $user_row['iso_lang_id']);

			break;

			case 'prefs':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$data = array(
					'dateformat'		=> utf8_normalize_nfc(request_var('dateformat', $user_row['user_dateformat'], true)),
					'lang'				=> basename(request_var('lang', $user_row['user_lang'])),
					'tz'				=> request_var('tz', (float) $user_row['user_timezone']),
					'style'				=> request_var('style', $user_row['user_style']),
					'dst'				=> request_var('dst', $user_row['user_dst']),
					'viewemail'			=> request_var('viewemail', $user_row['user_allow_viewemail']),
					'massemail'			=> request_var('massemail', $user_row['user_allow_massemail']),
					'hideonline'		=> request_var('hideonline', !$user_row['user_allow_viewonline']),
					'notifymethod'		=> request_var('notifymethod', $user_row['user_notify_type']),
					'notifypm'			=> request_var('notifypm', $user_row['user_notify_pm']),
					'popuppm'			=> request_var('popuppm', $this->optionget($user_row, 'popuppm')),
					'allowpm'			=> request_var('allowpm', $user_row['user_allow_pm']),

					'topic_sk'			=> request_var('topic_sk', ($user_row['user_topic_sortby_type']) ? $user_row['user_topic_sortby_type'] : 't'),
					'topic_sd'			=> request_var('topic_sd', ($user_row['user_topic_sortby_dir']) ? $user_row['user_topic_sortby_dir'] : 'd'),
					'topic_st'			=> request_var('topic_st', ($user_row['user_topic_show_days']) ? $user_row['user_topic_show_days'] : 0),

					'post_sk'			=> request_var('post_sk', ($user_row['user_post_sortby_type']) ? $user_row['user_post_sortby_type'] : 't'),
					'post_sd'			=> request_var('post_sd', ($user_row['user_post_sortby_dir']) ? $user_row['user_post_sortby_dir'] : 'a'),
					'post_st'			=> request_var('post_st', ($user_row['user_post_show_days']) ? $user_row['user_post_show_days'] : 0),

					'view_images'		=> request_var('view_images', $this->optionget($user_row, 'viewimg')),
					'view_flash'		=> request_var('view_flash', $this->optionget($user_row, 'viewflash')),
					'view_smilies'		=> request_var('view_smilies', $this->optionget($user_row, 'viewsmilies')),
					'view_sigs'			=> request_var('view_sigs', $this->optionget($user_row, 'viewsigs')),
					'view_avatars'		=> request_var('view_avatars', $this->optionget($user_row, 'viewavatars')),
					'view_wordcensor'	=> request_var('view_wordcensor', $this->optionget($user_row, 'viewcensors')),

					'bbcode'	=> request_var('bbcode', $this->optionget($user_row, 'bbcode')),
					'smilies'	=> request_var('smilies', $this->optionget($user_row, 'smilies')),
					'sig'		=> request_var('sig', $this->optionget($user_row, 'attachsig')),
					'notify'	=> request_var('notify', $user_row['user_notify']),
				);

				if ($submit)
				{
					$error = validate_data($data, array(
						'dateformat'	=> array('string', false, 1, 30),
						'lang'			=> array('match', false, '#^[a-z_\-]{2,}$#i'),
						'tz'			=> array('num', false, -14, 14),

						'topic_sk'		=> array('string', false, 1, 1),
						'topic_sd'		=> array('string', false, 1, 1),
						'post_sk'		=> array('string', false, 1, 1),
						'post_sd'		=> array('string', false, 1, 1),
					));

					if (!check_form_key($form_name))
					{
						$error[] = 'FORM_INVALID';
					}

					if (!sizeof($error))
					{
						$this->optionset($user_row, 'popuppm', $data['popuppm']);
						$this->optionset($user_row, 'viewimg', $data['view_images']);
						$this->optionset($user_row, 'viewflash', $data['view_flash']);
						$this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
						$this->optionset($user_row, 'viewsigs', $data['view_sigs']);
						$this->optionset($user_row, 'viewavatars', $data['view_avatars']);
						$this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
						$this->optionset($user_row, 'bbcode', $data['bbcode']);
						$this->optionset($user_row, 'smilies', $data['smilies']);
						$this->optionset($user_row, 'attachsig', $data['sig']);

						$sql_ary = array(
							'user_options'			=> $user_row['user_options'],

							'user_allow_pm'			=> $data['allowpm'],
							'user_allow_viewemail'	=> $data['viewemail'],
							'user_allow_massemail'	=> $data['massemail'],
							'user_allow_viewonline'	=> !$data['hideonline'],
							'user_notify_type'		=> $data['notifymethod'],
							'user_notify_pm'		=> $data['notifypm'],

							'user_dst'				=> $data['dst'],
							'user_dateformat'		=> $data['dateformat'],
							'user_lang'				=> $data['lang'],
							'user_timezone'			=> $data['tz'],
							'user_style'			=> $data['style'],

							'user_topic_sortby_type'	=> $data['topic_sk'],
							'user_post_sortby_type'		=> $data['post_sk'],
							'user_topic_sortby_dir'		=> $data['topic_sd'],
							'user_post_sortby_dir'		=> $data['post_sd'],

							'user_topic_show_days'	=> $data['topic_st'],
							'user_post_show_days'	=> $data['post_st'],

							'user_notify'	=> $data['notify'],
						);

						$sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
							WHERE user_id = $user_id";
						$db->sql_query($sql);

						trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				$dateformat_options = '';
				foreach ($user->lang['dateformats'] as $format => $null)
				{
					$dateformat_options .= '<option value="' . $format . '"' . (($format == $data['dateformat']) ? ' selected="selected"' : '') . '>';
					$dateformat_options .= $user->format_date(time(), $format, false) . ((strpos($format, '|') !== false) ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
					$dateformat_options .= '</option>';
				}

				$s_custom = false;

				$dateformat_options .= '<option value="custom"';
				if (!in_array($data['dateformat'], array_keys($user->lang['dateformats'])))
				{
					$dateformat_options .= ' selected="selected"';
					$s_custom = true;
				}
				$dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';

				$sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);

				// Topic ordering options
				$limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 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']);
				$sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);

				// Post ordering options
				$limit_post_days = array(0 => $user->lang['ALL_POSTS'], 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']);
				$sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);

				$_options = array('topic', 'post');
				foreach ($_options as $sort_option)
				{
					${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
					foreach (${'limit_' . $sort_option . '_days'} as $day => $text)
					{
						$selected = ($data[$sort_option . '_st'] == $day) ? ' selected="selected"' : '';
						${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
					}
					${'s_limit_' . $sort_option . '_days'} .= '</select>';

					${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
					foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text)
					{
						$selected = ($data[$sort_option . '_sk'] == $key) ? ' selected="selected"' : '';
						${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
					}
					${'s_sort_' . $sort_option . '_key'} .= '</select>';

					${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
					foreach ($sort_dir_text as $key => $value)
					{
						$selected = ($data[$sort_option . '_sd'] == $key) ? ' selected="selected"' : '';
						${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
					}
					${'s_sort_' . $sort_option . '_dir'} .= '</select>';
				}

				$template->assign_vars(array(
					'S_PREFS'			=> true,
					'S_JABBER_DISABLED'	=> ($config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml')) ? false : true,
					
					'VIEW_EMAIL'		=> $data['viewemail'],
					'MASS_EMAIL'		=> $data['massemail'],
					'ALLOW_PM'			=> $data['allowpm'],
					'HIDE_ONLINE'		=> $data['hideonline'],
					'NOTIFY_EMAIL'		=> ($data['notifymethod'] == NOTIFY_EMAIL) ? true : false,
					'NOTIFY_IM'			=> ($data['notifymethod'] == NOTIFY_IM) ? true : false,
					'NOTIFY_BOTH'		=> ($data['notifymethod'] == NOTIFY_BOTH) ? true : false,
					'NOTIFY_PM'			=> $data['notifypm'],
					'POPUP_PM'			=> $data['popuppm'],
					'DST'				=> $data['dst'],
					'BBCODE'			=> $data['bbcode'],
					'SMILIES'			=> $data['smilies'],
					'ATTACH_SIG'		=> $data['sig'],
					'NOTIFY'			=> $data['notify'],
					'VIEW_IMAGES'		=> $data['view_images'],
					'VIEW_FLASH'		=> $data['view_flash'],
					'VIEW_SMILIES'		=> $data['view_smilies'],
					'VIEW_SIGS'			=> $data['view_sigs'],
					'VIEW_AVATARS'		=> $data['view_avatars'],
					'VIEW_WORDCENSOR'	=> $data['view_wordcensor'],
					
					'S_TOPIC_SORT_DAYS'		=> $s_limit_topic_days,
					'S_TOPIC_SORT_KEY'		=> $s_sort_topic_key,
					'S_TOPIC_SORT_DIR'		=> $s_sort_topic_dir,
					'S_POST_SORT_DAYS'		=> $s_limit_post_days,
					'S_POST_SORT_KEY'		=> $s_sort_post_key,
					'S_POST_SORT_DIR'		=> $s_sort_post_dir,

					'DATE_FORMAT'			=> $data['dateformat'],
					'S_DATEFORMAT_OPTIONS'	=> $dateformat_options,
					'S_CUSTOM_DATEFORMAT'	=> $s_custom,
					'DEFAULT_DATEFORMAT'	=> $config['default_dateformat'],
					'A_DEFAULT_DATEFORMAT'	=> addslashes($config['default_dateformat']),

					'S_LANG_OPTIONS'	=> language_select($data['lang']),
					'S_STYLE_OPTIONS'	=> style_select($data['style']),
					'S_TZ_OPTIONS'		=> tz_select($data['tz'], true),
					)
				);

			break;

			case 'avatar':

				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;

				if ($submit)
				{

					if (!check_form_key($form_name))
					{
							trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					if (avatar_process_user($error, $user_row))
					{
						trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_row['user_id']));
					}

					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}

				// Generate users avatar
				$avatar_img = ($user_row['user_avatar']) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';

				$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
				$avatar_select = basename(request_var('avatar_select', ''));
				$category = basename(request_var('category', ''));

				if ($config['allow_avatar_local'] && $display_gallery)
				{
					avatar_gallery($category, $avatar_select, 4);
				}

				$template->assign_vars(array(
					'S_AVATAR'			=> true,
					'S_CAN_UPLOAD'		=> ($can_upload && $config['allow_avatar_upload']) ? true : false,
					'S_ALLOW_REMOTE'	=> ($config['allow_avatar_remote']) ? true : false,
					'S_DISPLAY_GALLERY'	=> ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
					'S_IN_GALLERY'		=> ($config['allow_avatar_local'] && $display_gallery) ? true : false,

					'AVATAR_IMAGE'			=> $avatar_img,
					'AVATAR_MAX_FILESIZE'	=> $config['avatar_filesize'],
					'USER_AVATAR_WIDTH'		=> $user_row['user_avatar_width'],
					'USER_AVATAR_HEIGHT'	=> $user_row['user_avatar_height'],

					'L_AVATAR_EXPLAIN'	=> sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)))
				);

			break;

			case 'rank':

				if ($submit)
				{
					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					$rank_id = request_var('user_rank', 0);

					$sql = 'UPDATE ' . USERS_TABLE . "
						SET user_rank = $rank_id
						WHERE user_id = $user_id";
					$db->sql_query($sql);

					trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
				}
				
				$sql = 'SELECT *
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
				$result = $db->sql_query($sql);

				$s_rank_options = '<option value="0"' . ((!$user_row['user_rank']) ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';

				while ($row = $db->sql_fetchrow($result))
				{
					$selected = ($user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank']) ? ' selected="selected"' : '';
					$s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
				}
				$db->sql_freeresult($result);

				$template->assign_vars(array(
					'S_RANK'			=> true,
					'S_RANK_OPTIONS'	=> $s_rank_options)
				);

			break;
			
			case 'sig':
			
				include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
				include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);

				$enable_bbcode	= ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', !$user->optionget('bbcode'))) ? false : true) : false;
				$enable_smilies	= ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', !$user->optionget('smilies'))) ? false : true) : false;
				$enable_urls	= ($config['allow_sig_links']) ? ((request_var('disable_magic_url', false)) ? false : true) : false;
				$signature		= utf8_normalize_nfc(request_var('signature', (string) $user_row['user_sig'], true));

				$preview		= (isset($_POST['preview'])) ? true : false;

				if ($submit || $preview)
				{
					include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);

					$message_parser = new parse_message($signature);

					// Allowing Quote BBCode
					$message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], true, 'sig');
						
					if (sizeof($message_parser->warn_msg))
					{
						$error[] = implode('<br />', $message_parser->warn_msg);
					}

					if (!check_form_key($form_name))
					{
						$error = 'FORM_INVALID';
					}

					if (!sizeof($error) && $submit)
					{
						$sql_ary = array(
							'user_sig'					=> (string) $message_parser->message,
							'user_sig_bbcode_uid'		=> (string) $message_parser->bbcode_uid,
							'user_sig_bbcode_bitfield'	=> (string) $message_parser->bbcode_bitfield
						);

						$sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user_id;
						$db->sql_query($sql);

						trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
					}
	
					// Replace "error" strings with their real, localised form
					$error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
				}
				
				$signature_preview = '';
				
				if ($preview)
				{
					// Now parse it for displaying
					$signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
					unset($message_parser);
				}

				decode_message($signature, $user_row['user_sig_bbcode_uid']);

				$template->assign_vars(array(
					'S_SIGNATURE'		=> true,

					'SIGNATURE'			=> $signature,
					'SIGNATURE_PREVIEW'	=> $signature_preview,

					'S_BBCODE_CHECKED'		=> (!$enable_bbcode) ? ' checked="checked"' : '',
					'S_SMILIES_CHECKED'		=> (!$enable_smilies) ? ' checked="checked"' : '',
					'S_MAGIC_URL_CHECKED'	=> (!$enable_urls) ? ' checked="checked"' : '',

					'BBCODE_STATUS'			=> ($config['allow_sig_bbcode']) ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.$phpEx", 'mode=bbcode') . '">', '</a>'),
					'SMILIES_STATUS'		=> ($config['allow_sig_smilies']) ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'],
					'IMG_STATUS'			=> ($config['allow_sig_img']) ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'],
					'FLASH_STATUS'			=> ($config['allow_sig_flash']) ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'],
					'URL_STATUS'			=> ($config['allow_sig_links']) ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'],

					'L_SIGNATURE_EXPLAIN'	=> sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']),

					'S_BBCODE_ALLOWED'		=> $config['allow_sig_bbcode'],
					'S_SMILIES_ALLOWED'		=> $config['allow_sig_smilies'],
					'S_BBCODE_IMG'			=> ($config['allow_sig_img']) ? true : false,
					'S_BBCODE_FLASH'		=> ($config['allow_sig_flash']) ? true : false,
					'S_LINKS_ALLOWED'		=> ($config['allow_sig_links']) ? true : false)
				);

				// Assigning custom bbcodes
				display_custom_bbcodes();

			break;

			case 'attach':

				$start		= request_var('start', 0);
				$deletemark = (isset($_POST['delmarked'])) ? true : false;
				$marked		= request_var('mark', array(0));

				// Sort keys
				$sort_key	= request_var('sk', 'a');
				$sort_dir	= request_var('sd', 'd');

				if ($deletemark && sizeof($marked))
				{
					$sql = 'SELECT attach_id
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE poster_id = ' . $user_id . '
							AND is_orphan = 0
							AND ' . $db->sql_in_set('attach_id', $marked);
					$result = $db->sql_query($sql);

					$marked = array();
					while ($row = $db->sql_fetchrow($result))
					{
						$marked[] = $row['attach_id'];
					}
					$db->sql_freeresult($result);
				}

				if ($deletemark && sizeof($marked))
				{
					if (confirm_box(true))
					{
						$sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $marked);
						$result = $db->sql_query($sql);

						$log_attachments = array();
						while ($row = $db->sql_fetchrow($result))
						{
							$log_attachments[] = $row['real_filename'];
						}
						$db->sql_freeresult($result);

						delete_attachments('attach', $marked);

						$message = (sizeof($log_attachments) == 1) ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];

						add_log('admin', 'LOG_ATTACHMENTS_DELETED', implode(', ', $log_attachments));
						trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
					}
					else
					{
						confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
							'u'				=> $user_id,
							'i'				=> $id,
							'mode'			=> $mode,
							'action'		=> $action,
							'delmarked'		=> true,
							'mark'			=> $marked))
						);
					}
				}

				$sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
				$sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');

				$sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);

				$s_sort_key = '';
				foreach ($sk_text as $key => $value)
				{
					$selected = ($sort_key == $key) ? ' selected="selected"' : '';
					$s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
				}

				$s_sort_dir = '';
				foreach ($sd_text as $key => $value)
				{
					$selected = ($sort_dir == $key) ? ' selected="selected"' : '';
					$s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
				}

				if (!isset($sk_sql[$sort_key]))
				{
					$sort_key = 'a';
				}

				$order_by = $sk_sql[$sort_key] . ' ' . (($sort_dir == 'a') ? 'ASC' : 'DESC');

				$sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "
					WHERE poster_id = $user_id
						AND is_orphan = 0";
				$result = $db->sql_query_limit($sql, 1);
				$num_attachments = (int) $db->sql_fetchfield('num_attachments');
				$db->sql_freeresult($result);

				$sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "
						AND a.is_orphan = 0
					ORDER BY $order_by";
				$result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);

				while ($row = $db->sql_fetchrow($result))
				{
					if ($row['in_message'])
					{
						$view_topic = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&amp;p={$row['post_msg_id']}");
					}
					else
					{
						$view_topic = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
					}

					$template->assign_block_vars('attach', array(
						'REAL_FILENAME'		=> $row['real_filename'],
						'COMMENT'			=> nl2br($row['attach_comment']),
						'EXTENSION'			=> $row['extension'],
						'SIZE'				=> ($row['filesize'] >= 1048576) ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : (($row['filesize'] >= 1024) ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']),
						'DOWNLOAD_COUNT'	=> $row['download_count'],
						'POST_TIME'			=> $user->format_date($row['filetime']),
						'TOPIC_TITLE'		=> ($row['in_message']) ? $row['message_title'] : $row['topic_title'],

						'ATTACH_ID'			=> $row['attach_id'],
						'POST_ID'			=> $row['post_msg_id'],
						'TOPIC_ID'			=> $row['topic_id'],
				
						'S_IN_MESSAGE'		=> $row['in_message'],

						'U_DOWNLOAD'		=> append_sid("{$phpbb_root_path}download/file.$phpEx", 'mode=view&amp;id=' . $row['attach_id']),
						'U_VIEW_TOPIC'		=> $view_topic)
					);
				}
				$db->sql_freeresult($result);
		
				$template->assign_vars(array(
					'S_ATTACHMENTS'		=> true,
					'S_ON_PAGE'			=> on_page($num_attachments, $config['topics_per_page'], $start),
					'S_SORT_KEY'		=> $s_sort_key,
					'S_SORT_DIR'		=> $s_sort_dir,

					'PAGINATION'		=> generate_pagination($this->u_action . "&amp;u=$user_id&amp;sk=$sort_key&amp;sd=$sort_dir", $num_attachments, $config['topics_per_page'], $start, true))
				);

			break;
		
			case 'groups':

				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

				$user->add_lang(array('groups', 'acp/groups'));
				$group_id = request_var('g', 0);
				
				if ($group_id)
				{
					// Check the founder only entry for this group to make sure everything is well
					$sql = 'SELECT group_founder_manage
						FROM ' . GROUPS_TABLE . '
						WHERE group_id = ' . $group_id;
					$result = $db->sql_query($sql);
					$founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
					$db->sql_freeresult($result);
					
					if ($user->data['user_type'] != USER_FOUNDER && $founder_manage)
					{
						trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}
				}
				else
				{
					$founder_manage = 0;
				}
				
				switch ($action)
				{
					case 'demote':
					case 'promote':
					case 'default':
						if (!$group_id)
						{
							trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
						}
						group_user_attributes($action, $group_id, $user_id);

						if ($action == 'default')
						{
							$user_row['group_id'] = $group_id;
						}
					break;

					case 'delete':

						if (confirm_box(true))
						{
							if (!$group_id)
							{
								trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}

							if ($error = group_user_del($group_id, $user_id))
							{
								trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
							}
						
							$error = array();
						}
						else
						{
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
								'u'				=> $user_id,
								'i'				=> $id,
								'mode'			=> $mode,
								'action'		=> $action,
								'g'				=> $group_id))
							);
						}
	
					break;
				}

				// Add user to group?
				if ($submit)
				{

					if (!check_form_key($form_name))
					{
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					if (!$group_id)
					{
						trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					// Add user/s to group
					if ($error = group_user_add($group_id, $user_id))
					{
						trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
					}

					$error = array();
				}


				$sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug
					WHERE ug.user_id = $user_id
						AND g.group_id = ug.group_id
					ORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
				$result = $db->sql_query($sql);

				$i = 0;
				$group_data = $id_ary = array();
				while ($row = $db->sql_fetchrow($result))
				{
					$type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : (($row['user_pending']) ? 'pending' : 'normal');

					$group_data[$type][$i]['group_id']		= $row['group_id'];
					$group_data[$type][$i]['group_name']	= $row['group_name'];
					$group_data[$type][$i]['group_leader']	= ($row['group_leader']) ? 1 : 0;

					$id_ary[] = $row['group_id'];

					$i++;
				}
				$db->sql_freeresult($result);

				// Select box for other groups
				$sql = 'SELECT group_id, group_name, group_type, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					' . ((sizeof($id_ary)) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
					ORDER BY group_type DESC, group_name ASC';
				$result = $db->sql_query($sql);

				$s_group_options = '';
				while ($row = $db->sql_fetchrow($result))
				{
					if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA')
					{
						continue;
					}

					// Do not display those groups not allowed to be managed
					if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage'])
					{
						continue;
					}

					$s_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
				}
				$db->sql_freeresult($result);

				$current_type = '';
				foreach ($group_data as $group_type => $data_ary)
				{
					if ($current_type != $group_type)
					{
						$template->assign_block_vars('group', array(
							'S_NEW_GROUP_TYPE'		=> true,
							'GROUP_TYPE'			=> $user->lang['USER_GROUP_' . strtoupper($group_type)])
						);
					}

					foreach ($data_ary as $data)
					{
						$template->assign_block_vars('group', array(
							'U_EDIT_GROUP'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=groups&amp;mode=manage&amp;action=edit&amp;u=$user_id&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"),
							'U_DEFAULT'			=> $this->u_action . "&amp;action=default&amp;u=$user_id&amp;g=" . $data['group_id'],
							'U_DEMOTE_PROMOTE'	=> $this->u_action . '&amp;action=' . (($data['group_leader']) ? 'demote' : 'promote') . "&amp;u=$user_id&amp;g=" . $data['group_id'],
							'U_DELETE'			=> $this->u_action . "&amp;action=delete&amp;u=$user_id&amp;g=" . $data['group_id'],

							'GROUP_NAME'		=> ($group_type == 'special') ? $user->lang['G_' . $data['group_name']] : $data['group_name'],
							'L_DEMOTE_PROMOTE'	=> ($data['group_leader']) ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'],

							'S_NO_DEFAULT'		=> ($user_row['group_id'] != $data['group_id']) ? true : false,
							'S_SPECIAL_GROUP'	=> ($group_type == 'special') ? true : false,
							)
						);
					}
				}

				$template->assign_vars(array(
					'S_GROUPS'			=> true,
					'S_GROUP_OPTIONS'	=> $s_group_options)
				);

			break;

			case 'perm':

				include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);

				$auth_admin = new auth_admin();

				$user->add_lang('acp/permissions');
				add_permission_language();

				$forum_id = request_var('f', 0);

				// Global Permissions
				if (!$forum_id)
				{
					// Select auth options
					$sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . '
						WHERE auth_option ' . $db->sql_like_expression($db->any_char . '_') . '
							AND is_global = 1
						ORDER BY auth_option';
					$result = $db->sql_query($sql);

					$hold_ary = array();
					
					while ($row = $db->sql_fetchrow($result))
					{
						$hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
					}
					$db->sql_freeresult($result);

					unset($hold_ary);
				}
				else
				{
					$sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . "
						WHERE auth_option " . $db->sql_like_expression($db->any_char . '_') . "
							AND is_local = 1
						ORDER BY is_global DESC, auth_option";
					$result = $db->sql_query($sql);

					while ($row = $db->sql_fetchrow($result))
					{
						$hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
						$auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
					}
					$db->sql_freeresult($result);
				}

				$s_forum_options = '<option value="0"' . ((!$forum_id) ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
				$s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);

				$template->assign_vars(array(
					'S_PERMISSIONS'				=> true,

					'S_GLOBAL'					=> (!$forum_id) ? true : false,
					'S_FORUM_OPTIONS'			=> $s_forum_options,

					'U_ACTION'					=> $this->u_action . '&amp;u=' . $user_id,
					'U_USER_PERMISSIONS'		=> append_sid("{$phpbb_admin_path}index.$phpEx" ,'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id),
					'U_USER_FORUM_PERMISSIONS'	=> append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id))
				);
			
			break;

		}

		// Assign general variables
		$template->assign_vars(array(
			'S_ERROR'			=> (sizeof($error)) ? true : false,
			'ERROR_MSG'			=> (sizeof($error)) ? implode('<br />', $error) : '')
		);
	}
예제 #4
0
파일: logs.php 프로젝트: skdong/nfs-ovd
    echo '<input type="checkbox" name="warn" value="1" checked="checked" /> ' . _('Show alerts') . ' ';
} else {
    echo '<input type="checkbox" name="warn" value="1" /> ' . _('Show alerts') . ' ';
}
if ($info) {
    echo '<input type="checkbox" name="info" value="1" checked="checked" /> ' . _('Show information') . ' ';
} else {
    echo '<input type="checkbox" name="info" value="1" /> ' . _('Show informations') . ' ';
}
echo '<input type="submit" value="reload" /> ';
echo '</form></td><td>';
echo '<form name="mod_ha_logs" action="logs.php" method="post">';
echo '<input type="hidden" name="action" value="cleanup_logs" />';
echo '<input type="submit" value="' . _('Cleanup logs') . '" />';
echo '</form></td></tr></table>';
echo '<div><span class="mod_ha_log_gravity mod_ha_host"> ' . sprintf(_('%s logs'), count($res)) . '</span></div><br />';
if (count($res)) {
    foreach ($res as $line) {
        $tmp = explode(' ', $line);
        $log = array();
        for ($i = 0; $i < 6; $i++) {
            $log[$i] = $tmp[0];
            array_shift($tmp);
        }
        $log[6] = implode(" ", $tmp);
        unset($tmp);
        view_log($log);
    }
}
echo '</div>';
page_footer();
예제 #5
0
/**
* Display user notes
*/
function mcp_notes_user_view($action)
{
    global $_CLASS, $_CORE_CONFIG, $config;
    $user_id = request_var('u', 0);
    $username = request_var('username', '');
    $start = request_var('start', 0);
    $st = request_var('st', 0);
    $sk = request_var('sk', 'b');
    $sd = request_var('sd', 'd');
    $url = 'forums&amp;file=mcp&amp;i=notes&mode=user_notes';
    $sql_where = $user_id ? "user_id = {$user_id}" : "username = '******'";
    $sql = 'SELECT *
		FROM ' . CORE_USERS_TABLE . "\n\t\tWHERE {$sql_where}";
    $result = $_CLASS['core_db']->query($sql);
    $userrow = $_CLASS['core_db']->fetch_row_assoc($result);
    $_CLASS['core_db']->free_result($result);
    if (!$userrow) {
        trigger_error('NO_USER');
    }
    $user_id = $userrow['user_id'];
    $deletemark = $action === 'del_marked';
    $deleteall = $action === 'del_all';
    $marked = get_variable('marknote', 'REQUEST', false, 'array:int');
    $usernote = request_var('usernote', '', true);
    // Handle any actions
    if (($deletemark || $deleteall) && $_CLASS['forums_auth']->acl_get('a_clearlogs')) {
        $where_sql = '';
        if ($deletemark && !empty($marked)) {
            $where_sql = ' AND log_id IN (' . implode(', ', $marked) . ')';
        }
        if ($where_sql || $deleteall) {
            $sql = 'DELETE FROM ' . FORUMS_LOG_TABLE . '
				WHERE log_type = ' . LOG_USERS . " \n\t\t\t\t\tAND reportee_id = {$user_id}\n\t\t\t\t\t{$where_sql}";
            $_CLASS['core_db']->query($sql);
            add_log('admin', 'LOG_CLEAR_USER', $userrow['username']);
            $msg = $deletemark ? 'MARKED_NOTES_DELETED' : 'ALL_NOTES_DELETED';
            $redirect = generate_link($url . '&amp;u=' . $user_id);
            $_CLASS['core_display']->meta_refresh(3, $redirect);
            trigger_error($_CLASS['core_user']->lang[$msg] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
        }
    }
    if ($usernote && $action === 'add_feedback') {
        add_log('admin', 'LOG_USER_FEEDBACK', $userrow['username']);
        add_log('user', $user_id, 'LOG_USER_GENERAL', $usernote);
        $redirect = generate_link($url . '&amp;u=' . $user_id);
        $_CLASS['core_display']->meta_refresh(3, $redirect);
        trigger_error($_CLASS['core_user']->lang['USER_FEEDBACK_ADDED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
    }
    // Generate the appropriate user information for the user we are looking at
    $rank_title = $rank_img = '';
    //get_user_rank($userrow['user_rank'], $userrow['user_posts'], $rank_title, $rank_img);
    $avatar_img = '';
    if (!empty($userrow['user_avatar'])) {
        switch ($userrow['user_avatar_type']) {
            case AVATAR_UPLOAD:
                $avatar_img = $_CORE_CONFIG['global']['path_avatar_upload'] . '/';
                break;
            case AVATAR_GALLERY:
                $avatar_img = $_CORE_CONFIG['global']['path_avatar_gallery'] . '/';
                break;
        }
        $avatar_img .= $userrow['user_avatar'];
        $avatar_img = '<img src="' . $avatar_img . '" width="' . $userrow['user_avatar_width'] . '" height="' . $userrow['user_avatar_height'] . '" alt="" />';
    }
    $limit_days = array(0 => $_CLASS['core_user']->lang['ALL_ENTRIES'], 1 => $_CLASS['core_user']->lang['1_DAY'], 7 => $_CLASS['core_user']->lang['7_DAYS'], 14 => $_CLASS['core_user']->lang['2_WEEKS'], 30 => $_CLASS['core_user']->lang['1_MONTH'], 90 => $_CLASS['core_user']->lang['3_MONTHS'], 180 => $_CLASS['core_user']->lang['6_MONTHS'], 365 => $_CLASS['core_user']->lang['1_YEAR']);
    $sort_by_text = array('a' => $_CLASS['core_user']->lang['SORT_USERNAME'], 'b' => $_CLASS['core_user']->lang['SORT_DATE'], 'c' => $_CLASS['core_user']->lang['SORT_IP'], 'd' => $_CLASS['core_user']->lang['SORT_ACTION']);
    $sort_by_sql = array('a' => 'l.username', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation');
    $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
    gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
    // Define where and sort sql for use in displaying logs
    $sql_where = $st ? $_CLASS['core_user']->time - $st * 86400 : 0;
    $sql_sort = $sort_by_sql[$sk] . ' ' . ($sd == 'd' ? 'DESC' : 'ASC');
    $log_data = array();
    $log_count = 0;
    view_log('user', $log_data, $log_count, $config['posts_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
    $_CLASS['core_template']->assign('S_USER_NOTES', false);
    if ($log_count) {
        $_CLASS['core_template']->assign('S_USER_NOTES', true);
        foreach ($log_data as $row) {
            $_CLASS['core_template']->assign_vars_array('usernotes', array('REPORT_BY' => $row['username'], 'REPORT_AT' => $_CLASS['core_user']->format_date($row['time']), 'ACTION' => $row['action'], 'IP' => $row['ip'], 'ID' => $row['id']));
        }
    }
    $pagination = generate_pagination($url . "&amp;u={$user_id}&amp;st={$st}&amp;sk={$sk}&amp;sd={$sd}", $log_count, $config['posts_per_page'], $start);
    $_CLASS['core_template']->assign_array(array('U_POST_ACTION' => generate_link($url . '&amp;u=' . $user_id), 'S_CLEAR_ALLOWED' => $_CLASS['forums_auth']->acl_get('a_clearlogs'), 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'L_TITLE' => $_CLASS['core_user']->get_lang('MCP_NOTES_USER'), 'PAGE_NUMBER' => on_page($log_count, $config['posts_per_page'], $start), 'PAGINATION' => $pagination['formated'], 'PAGINATION_ARRAY' => $pagination['array'], 'TOTAL_REPORTS' => $log_count == 1 ? $_CLASS['core_user']->get_lang('LIST_REPORT') : sprintf($_CLASS['core_user']->get_lang('LIST_REPORTS'), $log_count), 'USERNAME' => $userrow['username'], 'USER_COLOR' => !empty($userrow['user_colour']) ? $userrow['user_colour'] : '', 'RANK_TITLE' => $rank_title, 'JOINED' => $_CLASS['core_user']->format_date($userrow['user_reg_date']), 'POSTS' => $userrow['user_posts'] ? $userrow['user_posts'] : 0, 'WARNINGS' => @$userrow['user_warnings'] ? $userrow['user_warnings'] : 0, 'AVATAR_IMG' => $avatar_img, 'RANK_IMG' => $rank_img));
}
예제 #6
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template, $cache;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $this->page_title = 'ACP_USER_' . strtoupper($mode);
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx;
        $error = array();
        $username = request_var('username', '', true);
        $user_id = request_var('u', 0);
        $action = request_var('action', '');
        $submit = isset($_POST['update']) ? true : false;
        // Whois (special case)
        if ($action == 'whois') {
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = request_var('user_ip', '');
            $domain = gethostbyaddr($user_ip);
            $ipwhois = '';
            if ($ipwhois = user_ipwhois($user_ip)) {
                $ipwhois = preg_replace('#(\\s)([\\w\\-\\._\\+]+@[\\w\\-\\.]+)(\\s)#', '\\1<a href="mailto:\\2">\\2</a>\\3', $ipwhois);
                $ipwhois = preg_replace('#(\\s)(http:/{2}[^\\s]*)(\\s)#', '\\1<a href="\\2" target="_blank">\\2</a>\\3', $ipwhois);
            }
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=select_user&amp;field=username')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username = '******'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query($sql);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action));
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Include info file...
        include_once $phpbb_root_path . 'includes/acp/info/acp_users.' . $phpEx;
        $forms_ary = acp_users_info::module();
        foreach ($forms_ary['modes'] as $value => $ary) {
            if (!$this->is_authed($ary['auth'])) {
                continue;
            }
            $selected = $mode == $value ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $value . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($value)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action));
        }
        switch ($mode) {
            case 'overview':
                $delete = request_var('delete', 0);
                $delete_type = request_var('delete_type', '');
                $ip = request_var('ip', 'ip');
                if ($submit) {
                    // You can't delete the founder
                    if ($delete && $user_row['user_type'] != USER_FOUNDER) {
                        if (!$auth->acl_get('a_userdel')) {
                            trigger_error($user->lang['NO_ADMIN'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        // Check if the user wants to remove himself or the guest user account
                        if ($user_id == ANONYMOUS) {
                            trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                        if (confirm_box(true)) {
                            user_delete($delete_type, $user_id);
                            add_log('admin', 'LOG_USER_DELETED', $user_row['username']);
                            trigger_error($user->lang['USER_DELETED'] . adm_back_link($this->u_action));
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type)));
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    $log = 'LOG_USER_BAN_USER';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    $log = 'LOG_USER_BAN_EMAIL';
                                    break;
                                case 'banip':
                                    $ban[] = $user_row['user_ip'];
                                    $sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}";
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $ban[] = $row['poster_ip'];
                                    }
                                    $db->sql_freeresult($result);
                                    $reason = 'USER_ADMIN_BAN_IP_REASON';
                                    $log = 'LOG_USER_BAN_IP';
                                    break;
                            }
                            user_ban(substr($action, 3), $ban, 0, 0, 0, $user->lang[$reason]);
                            add_log('admin', $log, $user->lang[$reason]);
                            add_log('user', $user_id, $log, $user->lang[$reason]);
                            trigger_error($user->lang['BAN_SUCCESSFUL'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($config['email_enable']) {
                                include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(10);
                                $key_len = 54 - strlen($server_url);
                                $key_len = $key_len > 6 ? $key_len : 6;
                                $user_actkey = substr($user_actkey, 0, $key_len);
                                if ($user_row['user_type'] != USER_INACTIVE) {
                                    user_active_flip($user_id, $user_row['user_type'], $user_actkey, $user_row['username']);
                                }
                                $messenger = new messenger(false);
                                $messenger->template('user_resend_inactive', $user_row['user_lang']);
                                $messenger->replyto($config['board_contact']);
                                $messenger->to($user_row['user_email'], $user_row['username']);
                                $messenger->headers('X-AntiAbuse: Board servername - ' . $config['server_name']);
                                $messenger->headers('X-AntiAbuse: User_id - ' . $user->data['user_id']);
                                $messenger->headers('X-AntiAbuse: Username - ' . $user->data['username']);
                                $messenger->headers('X-AntiAbuse: User IP - ' . $user->ip);
                                $messenger->assign_vars(array('SITENAME' => $config['sitename'], 'WELCOME_MSG' => sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), 'USERNAME' => html_entity_decode($user_row['username']), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                add_log('admin', 'LOG_USER_REACTIVATE', $user_row['username']);
                                add_log('user', $user_id, 'LOG_USER_REACTIVATE_USER');
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            user_active_flip($user_id, $user_row['user_type'], false, $user_row['username']);
                            $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
                            $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
                            add_log('user', $user_id, $log . '_USER');
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                set_config('num_users', $config['num_users'] + 1, true);
                            } else {
                                set_config('num_users', $config['num_users'] - 1, true);
                            }
                            // Update latest username
                            update_last_username();
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_USER_DEL_SIG', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_SIG_USER');
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            $sql_ary = array('user_avatar' => '', 'user_avatar_type' => 0, 'user_avatar_width' => 0, 'user_avatar_height' => 0);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                            add_log('admin', 'LOG_USER_DEL_AVATAR', $user_row['username']);
                            add_log('user', $user_id, 'LOG_USER_DEL_AVATAR_USER');
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
									FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tGROUP BY topic_id";
                                $result = $db->sql_query($sql);
                                $topic_id_ary = array();
                                while ($row = $db->sql_fetchrow($result)) {
                                    $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                                }
                                $db->sql_freeresult($result);
                                if (sizeof($topic_id_ary)) {
                                    $sql = 'SELECT topic_id, topic_replies, topic_replies_real
										FROM ' . TOPICS_TABLE . '
										WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                    $result = $db->sql_query($sql);
                                    $del_topic_ary = array();
                                    while ($row = $db->sql_fetchrow($result)) {
                                        if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                            $del_topic_ary[] = $row['topic_id'];
                                        }
                                    }
                                    $db->sql_freeresult($result);
                                    if (sizeof($del_topic_ary)) {
                                        $sql = 'DELETE FROM ' . TOPICS_TABLE . '
											WHERE topic_id IN (' . implode(', ', $del_topic_ary) . ')';
                                        $db->sql_query($sql);
                                    }
                                }
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                add_log('admin', 'LOG_USER_DEL_POSTS', $user_row['username']);
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'delattach':
                            if (confirm_box(true)) {
                                delete_attachments('user', $user_id);
                                add_log('admin', 'LOG_USER_DEL_ATTACH', $user_row['username']);
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'moveposts':
                            $new_forum_id = request_var('new_f', 0);
                            if (!$new_forum_id) {
                                $this->page_title = 'USER_ADMIN_MOVE_POSTS';
                                $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)));
                                return;
                            }
                            // Two stage?
                            // Move topics comprising only posts from this user
                            $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
                            $forum_id_ary = array($new_forum_id);
                            $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_replies, topic_replies_real
									FROM ' . TOPICS_TABLE . '
									WHERE topic_id IN (' . implode(', ', array_keys($topic_id_ary)) . ')';
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) {
                                        $move_topic_ary[] = $row['topic_id'];
                                    } else {
                                        $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
                                        $move_post_ary[$row['topic_id']]['attach'] = $row['attach'] ? 1 : 0;
                                    }
                                    $forum_id_ary[] = $row['forum_id'];
                                }
                                $db->sql_freeresult($result);
                            }
                            // Entire topic comprises posts by this user, move these topics
                            if (sizeof($move_topic_ary)) {
                                move_topics($move_topic_ary, $new_forum_id, false);
                            }
                            if (sizeof($move_post_ary)) {
                                // Create new topic
                                // Update post_ids, report_ids, attachment_ids
                                foreach ($move_post_ary as $topic_id => $post_ary) {
                                    // Create new topic
                                    $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_approved' => 1, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach']));
                                    $db->sql_query($sql);
                                    $new_topic_id = $db->sql_nextid();
                                    // Move posts
                                    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                    $db->sql_query($sql);
                                    if ($post_ary['attach']) {
                                        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                        $db->sql_query($sql);
                                    }
                                    $new_topic_id_ary[] = $new_topic_id;
                                }
                            }
                            $forum_id_ary = array_unique($forum_id_ary);
                            $topic_id_ary = array_unique(array_merge($topic_id_ary, $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('reported', 'topic_id', $topic_id_ary);
                                sync('topic', 'topic_id', $topic_id_ary);
                            }
                            if (sizeof($forum_id_ary)) {
                                sync('forum', 'forum_id', $forum_id_ary);
                            }
                            $sql = 'SELECT forum_name
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql, 3600);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            add_log('admin', 'LOG_USER_MOVE_POSTS', $user_row['username'], $forum_info['forum_name']);
                            add_log('user', $user_id, 'LOG_USER_MOVE_POSTS_USER', $forum_info['forum_name']);
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                    }
                    $data = array();
                    // Handle registration info updates
                    $var_ary = array('user' => (string) $user_row['username'], 'user_founder' => (int) ($user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'user_email' => (string) $user_row['user_email'], 'email_confirm' => (string) '', 'user_password' => (string) '', 'password_confirm' => (string) '', 'warnings' => (int) $user_row['user_warnings']);
                    // Get the data from the form. Use data from the database if no info is provided
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    // We use user within the form to circumvent auto filling
                    $data['username'] = $data['user'];
                    unset($data['user']);
                    // Validation data
                    $var_ary = array('password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'user_password' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), 'warnings' => array('num'));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $var_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username'])));
                    }
                    // Check email if altered
                    if ($data['user_email'] != $user_row['user_email']) {
                        $var_ary += array('user_email' => array(array('string', false, 6, 60), array('email', $user_row['user_email'])), 'email_confirm' => array('string', true, 6, 60));
                    }
                    $error = validate_data($data, $var_ary);
                    if ($data['user_password'] && $data['password_confirm'] != $data['user_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if ($data['user_email'] != $user_row['user_email'] && $data['email_confirm'] != $data['user_email']) {
                        $error[] = 'NEW_EMAIL_ERROR';
                    }
                    // Which updates do we need to do?
                    $update_warning = $user_row['user_warnings'] != $data['warnings'] ? true : false;
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['user_password'] && $user_row['user_password'] != md5($data['user_password']) ? true : false;
                    $update_email = $data['user_email'] != $user_row['user_email'] ? $data['user_email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            if ($update_warning) {
                                $sql_ary['user_warnings'] = $data['warnings'];
                            }
                            if ($user_row['user_type'] == USER_FOUNDER && !$data['user_founder'] || $user_row['user_type'] != USER_FOUNDER && $data['user_founder']) {
                                $sql_ary['user_type'] = $data['user_founder'] ? USER_FOUNDER : USER_NORMAL;
                            }
                        }
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            add_log('user', $user_id, 'LOG_USER_UPDATE_NAME', $user_row['username'], $update_username);
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => crc32(strtolower($update_email)) . strlen($update_email));
                            add_log('user', $user_id, 'LOG_USER_UPDATE_EMAIL', $user_row['username'], $user_row['user_email'], $update_email);
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => md5($data['user_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            add_log('user', $user_id, 'LOG_USER_NEW_PASSWORD', $user_row['username']);
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                        }
                        /**
                         * @todo adjust every data based in the number of user warnings
                         */
                        if ($update_warning) {
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']);
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $user_char_ary = array('.*' => 'USERNAME_CHARS_ANY', '[\\w]+' => 'USERNAME_ALPHA_ONLY', '[\\w_\\+\\. \\-\\[\\]]+' => 'USERNAME_ALPHA_SPACERS');
                $quick_tool_ary = array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP', 'active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE', 'delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH');
                if ($config['email_enable']) {
                    $quick_tool_ary['reactivate'] = 'FORCE';
                }
                $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
                foreach ($quick_tool_ary as $value => $lang) {
                    $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
                }
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => sprintf($user->lang[$user_char_ary[$config['allow_name_chars']] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_CHANGE_PASSWORD_EXPLAIN' => sprintf($user->lang['CHANGE_PASSWORD_EXPLAIN'], $config['min_pass_chars'], $config['max_pass_chars']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'U_SHOW_IP' => $this->u_action . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}", 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&amp;u={$user_row['user_id']}") : '', 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $user_row['user_lastvisit'] ? $user->format_date($user_row['user_lastvisit']) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings']));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = request_var('mark', array(0));
                $message = request_var('message', '', true);
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND log_id IN (' . implode(', ', $sql_in) . ')';
                        unset($sql_in);
                    }
                    if ($where_sql || $deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_CLEAR_USER', $user_row['username']);
                    }
                }
                if ($submit && $message) {
                    add_log('admin', 'LOG_USER_FEEDBACK', $user_row['username']);
                    add_log('user', $user_id, 'LOG_USER_GENERAL', $message);
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                // Sorting
                $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']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                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);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $template->assign_vars(array('S_FEEDBACK' => true, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
                foreach ($log_data as $row) {
                    $template->assign_block_vars('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'profile':
                $cp = new custom_profile();
                $cp_data = $cp_error = array();
                $data = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user_row['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                if ($submit) {
                    $var_ary = array('icq' => (string) '', 'aim' => (string) '', 'msn' => (string) '', 'yim' => (string) '', 'jabber' => (string) '', 'website' => (string) '', 'location' => (string) '', 'occupation' => (string) '', 'interests' => (string) '', 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = in_array($var, array('location', 'occupation', 'interests')) ? request_var($var, $default, true) : ($data[$var] = request_var($var, $default));
                    }
                    $var_ary = array('icq' => array(array('string', true, 3, 15), array('match', true, '#^[0-9]+$#i')), 'aim' => array('string', true, 3, 17), 'msn' => array('string', true, 5, 255), 'jabber' => array(array('string', true, 5, 255), array('match', true, '#^[a-z0-9\\.\\-_\\+]+?@(.*?\\.)*?[a-z0-9\\-_]+?\\.[a-z]{2,4}(/.*)?$#i')), 'yim' => array('string', true, 5, 255), 'website' => array(array('string', true, 12, 255), array('match', true, '#^http[s]?://(.*?\\.)*?[a-z0-9\\-]+\\.[a-z]{2,4}#i')), 'location' => array('string', true, 2, 255), 'occupation' => array('string', true, 2, 500), 'interests' => array('string', true, 2, 500), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())));
                    $error = validate_data($data, $var_ary);
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!sizeof($error)) {
                        $sql_ary = array('user_icq' => $data['icq'], 'user_aim' => $data['aim'], 'user_msnm' => $data['msn'], 'user_yim' => $data['yim'], 'user_jabber' => $data['jabber'], 'user_website' => $data['website'], 'user_from' => $data['location'], 'user_occ' => $data['occupation'], 'user_interests' => $data['interests'], 'user_birthday' => sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']));
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Update Custom Fields
                        if (sizeof($cp_data)) {
                            $sql = 'UPDATE ' . PROFILE_FIELDS_DATA_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $cp_data) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            if (!$db->sql_affectedrows()) {
                                $cp_data['user_id'] = (int) $user_id;
                                $db->return_on_error = true;
                                $sql = 'INSERT INTO ' . PROFILE_FIELDS_DATA_TABLE . ' ' . $db->sql_build_array('INSERT', $cp_data);
                                $db->sql_query($sql);
                                $db->return_on_error = false;
                            }
                        }
                        trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                if (!isset($data['bday_day'])) {
                    if ($user_row['user_birthday']) {
                        list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                    } else {
                        $data['bday_day'] = $data['bday_month'] = $data['bday_year'] = 0;
                    }
                }
                $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_year_options = '';
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i < $now['year']; $i++) {
                    $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('ICQ' => isset($data['icq']) ? $data['icq'] : $user_row['user_icq'], 'YIM' => isset($data['yim']) ? $data['yim'] : $user_row['user_yim'], 'AIM' => isset($data['aim']) ? $data['aim'] : $user_row['user_aim'], 'MSN' => isset($data['msn']) ? $data['msn'] : $user_row['user_msnm'], 'JABBER' => isset($data['jabber']) ? $data['jabber'] : $user_row['user_jabber'], 'WEBSITE' => isset($data['website']) ? $data['website'] : $user_row['user_website'], 'LOCATION' => isset($data['location']) ? $data['location'] : $user_row['user_from'], 'OCCUPATION' => isset($data['occupation']) ? $data['occupation'] : $user_row['user_occ'], 'INTERESTS' => isset($data['interests']) ? $data['interests'] : $user_row['user_interests'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_PROFILE' => true));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user_id);
                $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
                break;
            case 'prefs':
                $data = array();
                if ($submit) {
                    $var_ary = array('dateformat' => (string) $config['default_dateformat'], 'lang' => (string) $config['default_lang'], 'tz' => (double) $config['board_timezone'], 'style' => (int) $config['default_style'], 'dst' => (bool) $config['board_dst'], 'viewemail' => false, 'massemail' => true, 'hideonline' => false, 'notifymethod' => 0, 'notifypm' => true, 'popuppm' => false, 'allowpm' => true, 'topic_sk' => (string) 't', 'topic_sd' => (string) 'd', 'topic_st' => 0, 'post_sk' => (string) 't', 'post_sd' => (string) 'a', 'post_st' => 0, 'view_images' => true, 'view_flash' => false, 'view_smilies' => true, 'view_sigs' => true, 'view_avatars' => true, 'view_wordcensor' => false, 'bbcode' => true, 'smilies' => true, 'sig' => true, 'notify' => false);
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('dateformat' => array('string', false, 3, 30), 'lang' => array('match', false, '#^[a-z_]{2,}$#i'), 'tz' => array('num', false, -14, 14), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'popuppm', $data['popuppm']);
                        $this->optionset($user_row, 'viewimg', $data['view_images']);
                        $this->optionset($user_row, 'viewflash', $data['view_flash']);
                        $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
                        $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
                        $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
                        $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
                        $this->optionset($user_row, 'bbcode', $data['bbcode']);
                        $this->optionset($user_row, 'smilies', $data['smilies']);
                        $this->optionset($user_row, 'attachsig', $data['sig']);
                        $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dst' => $data['dst'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $notify_method = isset($data['notifymethod']) ? $data['notifymethod'] : $user_row['user_notify_type'];
                $dateformat = isset($data['dateformat']) ? $data['dateformat'] : $user_row['user_dateformat'];
                $lang = isset($data['lang']) ? $data['lang'] : $user_row['user_lang'];
                $style = isset($data['style']) ? $data['style'] : $user_row['user_style'];
                $tz = isset($data['tz']) ? $data['tz'] : $user_row['user_timezone'];
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $dateformat ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, true) . (strpos($format, '|') !== false ? ' [' . $user->lang['RELATIVE_DAYS'] . ']' : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!in_array($dateformat, array_keys($user->lang['dateformats']))) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $topic_sk = isset($data['topic_sk']) ? $data['topic_sk'] : ($user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't');
                $post_sk = isset($data['post_sk']) ? $data['post_sk'] : ($user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't');
                $topic_sd = isset($data['topic_sd']) ? $data['topic_sd'] : ($user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd');
                $post_sd = isset($data['post_sd']) ? $data['post_sd'] : ($user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'd');
                $topic_st = isset($data['topic_st']) ? $data['topic_st'] : ($user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0);
                $post_st = isset($data['post_st']) ? $data['post_st'] : ($user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0);
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                // Topic ordering options
                $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 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']);
                $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
                // Post ordering options
                $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 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']);
                $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
                $_options = array('topic', 'post');
                foreach ($_options as $sort_option) {
                    ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
                    foreach (${'limit_' . $sort_option . '_days'} as $day => $text) {
                        $selected = ${$sort_option . '_st'} == $day ? ' selected="selected"' : '';
                        ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_limit_' . $sort_option . '_days'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
                    foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) {
                        $selected = ${$sort_option . '_sk'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_key'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
                    foreach ($sort_dir_text as $key => $value) {
                        $selected = ${$sort_option . '_sd'} == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                $template->assign_vars(array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user->data['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => isset($data['viewemail']) ? $data['viewemail'] : $user_row['user_allow_viewemail'], 'MASS_EMAIL' => isset($data['massemail']) ? $data['massemail'] : $user_row['user_allow_massemail'], 'ALLOW_PM' => isset($data['allowpm']) ? $data['allowpm'] : $user_row['user_allow_pm'], 'HIDE_ONLINE' => isset($data['hideonline']) ? $data['hideonline'] : !$user_row['user_allow_viewonline'], 'NOTIFY_EMAIL' => $notify_method == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $notify_method == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $notify_method == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => isset($data['notifypm']) ? $data['notifypm'] : $user_row['user_notify_pm'], 'POPUP_PM' => isset($data['popuppm']) ? $data['popuppm'] : $this->optionget($user_row, 'popuppm'), 'DST' => isset($data['dst']) ? $data['dst'] : $user_row['user_dst'], 'BBCODE' => isset($data['bbcode']) ? $data['bbcode'] : $this->optionget($user_row, 'bbcode'), 'SMILIES' => isset($data['smilies']) ? $data['smilies'] : $this->optionget($user_row, 'smilies'), 'ATTACH_SIG' => isset($data['sig']) ? $data['sig'] : $this->optionget($user_row, 'attachsig'), 'NOTIFY' => isset($data['notify']) ? $data['notify'] : $user_row['user_notify'], 'VIEW_IMAGES' => isset($data['view_images']) ? $data['view_images'] : $this->optionget($user_row, 'viewimg'), 'VIEW_FLASH' => isset($data['view_flash']) ? $data['view_flash'] : $this->optionget($user_row, 'viewflash'), 'VIEW_SMILIES' => isset($data['view_smilies']) ? $data['view_smilies'] : $this->optionget($user_row, 'viewsmilies'), 'VIEW_SIGS' => isset($data['view_sigs']) ? $data['view_sigs'] : $this->optionget($user_row, 'viewsigs'), 'VIEW_AVATARS' => isset($data['view_avatars']) ? $data['view_avatars'] : $this->optionget($user_row, 'viewavatars'), 'VIEW_WORDCENSOR' => isset($data['view_wordcensor']) ? $data['view_wordcensor'] : $this->optionget($user_row, 'viewcensors'), 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $dateformat, 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($lang), 'S_STYLE_OPTIONS' => style_select($style), 'S_TZ_OPTIONS' => tz_select($tz)));
                break;
            case 'avatar':
                $avatar_select = basename(request_var('avatar_select', ''));
                $category = basename(request_var('category', ''));
                $can_upload = file_exists($phpbb_root_path . $config['avatar_path']) && is_writeable($phpbb_root_path . $config['avatar_path']) && $file_uploads ? true : false;
                $data = array();
                if ($submit) {
                    $delete = request_var('delete', '');
                    $var_ary = array('uploadurl' => (string) '', 'remotelink' => (string) '', 'width' => (string) '', 'height' => (string) '');
                    foreach ($var_ary as $var => $default) {
                        $data[$var] = request_var($var, $default);
                    }
                    $var_ary = array('uploadurl' => array('string', true, 5, 255), 'remotelink' => array('string', true, 5, 255), 'width' => array('string', true, 1, 3), 'height' => array('string', true, 1, 3));
                    $error = validate_data($data, $var_ary);
                    if (!sizeof($error)) {
                        $data['user_id'] = $user_id;
                        if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload && $config['allow_avatar_upload']) {
                            list($type, $filename, $width, $height) = avatar_upload($data, $error);
                        } else {
                            if ($data['remotelink'] && $config['allow_avatar_remote']) {
                                list($type, $filename, $width, $height) = avatar_remote($data, $error);
                            } else {
                                if ($avatar_select && $config['allow_avatar_local']) {
                                    $type = AVATAR_GALLERY;
                                    $filename = $avatar_select;
                                    // check avatar gallery
                                    if (!is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category)) {
                                        $type = $width = $height = 0;
                                        $filename = '';
                                    } else {
                                        list($width, $height) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $filename);
                                        $filename = $category . '/' . $filename;
                                    }
                                } else {
                                    if ($delete) {
                                        $filename = '';
                                        $type = $width = $height = 0;
                                    } else {
                                        $data = array();
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($error)) {
                        // Do we actually have any data to update?
                        if (sizeof($data)) {
                            $sql_ary = array('user_avatar' => $filename, 'user_avatar_type' => $type, 'user_avatar_width' => $width, 'user_avatar_height' => $height);
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                            // Delete old avatar if present
                            if ($user_row['user_avatar'] && $filename != $user_row['user_avatar'] && $user_row['user_avatar_type'] != AVATAR_GALLERY) {
                                avatar_delete($user_row['user_avatar']);
                            }
                        }
                        trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                // Generate users avatar
                if ($user_row['user_avatar']) {
                    $avatar_img = '';
                    switch ($user_row['user_avatar_type']) {
                        case AVATAR_UPLOAD:
                            $avatar_img = $phpbb_root_path . $config['avatar_path'] . '/';
                            break;
                        case AVATAR_GALLERY:
                            $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
                            break;
                    }
                    $avatar_img .= $user_row['user_avatar'];
                    $avatar_img = '<img src="' . $avatar_img . '" width="' . $user_row['user_avatar_width'] . '" height="' . $user_row['user_avatar_height'] . '" alt="" />';
                } else {
                    $avatar_img = '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
                }
                $display_gallery = isset($_POST['display_gallery']) ? true : false;
                if ($config['allow_avatar_local'] && $display_gallery) {
                    avatar_gallery($category, $avatar_select, 4);
                }
                $template->assign_vars(array('S_AVATAR' => true, 'S_CAN_UPLOAD' => $can_upload && $config['allow_avatar_upload'] ? true : false, 'S_ALLOW_REMOTE' => $config['allow_avatar_remote'] ? true : false, 'S_DISPLAY_GALLERY' => $config['allow_avatar_local'] && !$display_gallery ? true : false, 'S_IN_GALLERY' => $config['allow_avatar_local'] && $display_gallery ? true : false, 'AVATAR_IMAGE' => $avatar_img, 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], 'USER_AVATAR_WIDTH' => $user_row['user_avatar_width'], 'USER_AVATAR_HEIGHT' => $user_row['user_avatar_height'], 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024))));
                break;
            case 'rank':
                if ($submit) {
                    $rank_id = request_var('user_rank', 0);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                    $db->sql_query($sql);
                    trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                $sql = 'SELECT * 
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : '';
                    $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options));
                break;
            case 'sig':
                include_once $phpbb_root_path . 'includes/functions_posting.' . $phpEx;
                $enable_bbcode = $config['allow_sig_bbcode'] ? request_var('enable_bbcode', $this->optionget($user_row, 'bbcode')) : false;
                $enable_smilies = $config['allow_sig_smilies'] ? request_var('enable_smilies', $this->optionget($user_row, 'smilies')) : false;
                $enable_urls = request_var('enable_urls', true);
                $signature = request_var('signature', $user_row['user_sig'], true);
                $preview = isset($_POST['preview']) ? true : false;
                if ($submit || $preview) {
                    include_once $phpbb_root_path . 'includes/message_parser.' . $phpEx;
                    $message_parser = new parse_message($signature);
                    // Allowing Quote BBCode
                    $message_parser->parse($enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, true, 'sig');
                    if (sizeof($message_parser->warn_msg)) {
                        $error[] = implode('<br />', $message_parser->warn_msg);
                    }
                    if (!sizeof($error) && $submit) {
                        $sql_ary = array('user_sig' => (string) $message_parser->message, 'user_sig_bbcode_uid' => (string) $message_parser->bbcode_uid, 'user_sig_bbcode_bitfield' => (int) $message_parser->bbcode_bitfield);
                        $sql = 'UPDATE ' . USERS_TABLE . ' 
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' 
							WHERE user_id = ' . $user_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                $signature_preview = '';
                if ($preview) {
                    // Now parse it for displaying
                    $signature_preview = $message_parser->format_display($enable_bbcode, $enable_urls, $enable_smilies, false);
                    unset($message_parser);
                }
                decode_message($signature, $user_row['user_sig_bbcode_uid']);
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $signature, 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? 'checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? 'checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? 'checked="checked"' : '', 'BBCODE_STATUS' => $config['allow_sig_bbcode'] ? sprintf($user->lang['BBCODE_IS_ON'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>') : sprintf($user->lang['BBCODE_IS_OFF'], '<a href="' . append_sid("{$phpbb_root_path}faq.{$phpEx}", 'mode=bbcode') . '" onclick="target=\'_phpbbcode\';">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => sprintf($user->lang['SIGNATURE_EXPLAIN'], $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies']));
                break;
            case 'attach':
                $start = request_var('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = request_var('mark', array(0));
                // Sort keys
                $sort_key = request_var('sk', 'a');
                $sort_dir = request_var('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE attach_id IN (' . implode(', ', $marked) . ')';
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        delete_attachments('attach', $marked);
                        $log = sizeof($log_attachments) == 1 ? 'ATTACHMENT_DELETED' : 'ATTACHMENTS_DELETED';
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        add_log('admin', $log, implode(', ', $log_attachments));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'deletemark' => true, 'mark' => $marked)));
                    }
                }
                $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
                $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
                $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                $s_sort_key = '';
                foreach ($sk_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sd_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $order_by = $sk_sql[$sort_key] . '  ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                $sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}";
                $result = $db->sql_query_limit($sql, 1);
                $num_attachments = (int) $db->sql_fetchfield('num_attachments');
                $db->sql_freeresult($result);
                $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a 
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['posts_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}#{$row['post_msg_id']}");
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['comment']), 'EXTENSION' => $row['extension'], 'SIZE' => $row['filesize'] >= 1048576 ? ($row['filesize'] >> 20) . ' ' . $user->lang['MB'] : ($row['filesize'] >= 1024 ? ($row['filesize'] >> 10) . ' ' . $user->lang['KB'] : $row['filesize'] . ' ' . $user->lang['BYTES']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download.{$phpEx}", 'id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_ON_PAGE' => on_page($num_attachments, $config['topics_per_page'], $start), 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'PAGINATION' => generate_pagination($this->u_action . "&amp;sk={$sort_key}&amp;sd={$sort_dir}", $num_attachments, $config['topics_per_page'], $start, true)));
                break;
            case 'groups':
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = request_var('g', 0);
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        group_user_attributes($action, $group_id, $user_id);
                        if ($action == 'default') {
                            $user_row['group_id'] = $group_id;
                        }
                        break;
                    case 'delete':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            $error = array();
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                }
                // Add user to group?
                if ($submit) {
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Add user/s to group
                    if ($error = group_user_add($group_id, $user_id)) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    $error = array();
                }
                $sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
                $result = $db->sql_query($sql);
                $i = 0;
                $group_data = $id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal');
                    $group_data[$type][$i]['group_id'] = $row['group_id'];
                    $group_data[$type][$i]['group_name'] = $row['group_name'];
                    $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0;
                    $id_ary[] = $row['group_id'];
                    $i++;
                }
                $db->sql_freeresult($result);
                // Select box for other groups
                $sql = 'SELECT group_id, group_name, group_type
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE group_id NOT IN (' . implode(', ', $id_ary) . ')' : '') . '
					ORDER BY group_type DESC, group_name ASC';
                $result = $db->sql_query($sql);
                $s_group_options = '';
                while ($row = $db->sql_fetchrow($result)) {
                    if ($config['coppa_hide_groups'] && in_array($row['group_name'], array('INACTIVE_COPPA', 'REGISTERED_COPPA'))) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
                }
                $db->sql_freeresult($result);
                $current_type = '';
                foreach ($group_data as $group_type => $data_ary) {
                    if ($current_type != $group_type) {
                        $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]));
                    }
                    foreach ($data_ary as $data) {
                        $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false));
                    }
                }
                $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options));
                break;
            case 'perm':
                include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                $user->add_lang('acp/permissions_phpbb');
                // Select auth options
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_global = 1\n\t\t\t\t\tORDER BY auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT auth_option, is_local, is_global
					FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\tWHERE auth_option LIKE '%\\_'\n\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\tORDER BY is_global DESC, auth_option";
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'local', ACL_NO);
                    $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id)));
                break;
        }
        // Assign general variables
        $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
    }
예제 #7
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
        $action = request_var('action', '');
        $mark = isset($_REQUEST['mark']) ? implode(', ', request_var('mark', array(0))) : '';
        if ($mark) {
            switch ($action) {
                case 'activate':
                case 'delete':
                    if (!$auth->acl_get('a_user')) {
                        trigger_error($user->lang['NO_ADMIN']);
                    }
                    $sql = 'SELECT username 
						FROM ' . USERS_TABLE . "\n\t\t\t\t\t\tWHERE user_id IN ({$mark})";
                    $result = $db->sql_query($sql);
                    $user_affected = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $user_affected[] = $row['username'];
                    }
                    $db->sql_freeresult($result);
                    if ($action == 'activate') {
                        include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                        $mark_ary = explode(', ', $mark);
                        foreach ($mark_ary as $user_id) {
                            user_active_flip($user_id, USER_INACTIVE);
                        }
                        set_config('num_users', $config['num_users'] + sizeof($mark_ary), true);
                        // Update latest username
                        update_last_username();
                    } else {
                        if ($action == 'delete') {
                            if (!$auth->acl_get('a_userdel')) {
                                trigger_error($user->lang['NO_ADMIN']);
                            }
                            $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE user_id IN ({$mark})";
                            $db->sql_query($sql);
                            $sql = 'DELETE FROM ' . USERS_TABLE . " WHERE user_id IN ({$mark})";
                            $db->sql_query($sql);
                            add_log('admin', 'LOG_INDEX_' . strtoupper($action), implode(', ', $user_affected));
                        }
                    }
                    break;
                case 'remind':
                    if (!$auth->acl_get('a_user')) {
                        trigger_error($user->lang['NO_ADMIN']);
                    }
                    if (empty($config['email_enable'])) {
                        trigger_error($user->lang['EMAIL_DISABLED']);
                    }
                    $sql = 'SELECT user_id, username, user_email, user_lang, user_jabber, user_notify_type, user_regdate, user_actkey 
						FROM ' . USERS_TABLE . " \n\t\t\t\t\t\tWHERE user_id IN ({$mark})";
                    $result = $db->sql_query($sql);
                    if ($row = $db->sql_fetchrow($result)) {
                        // Send the messages
                        include_once $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                        $messenger = new messenger();
                        $board_url = generate_board_url() . "/ucp.{$phpEx}?mode=activate";
                        $sig = str_replace('<br />', "\n", "-- \n" . $config['board_email_sig']);
                        $usernames = array();
                        do {
                            $messenger->template('user_remind_inactive', $row['user_lang']);
                            $messenger->replyto($config['board_email']);
                            $messenger->to($row['user_email'], $row['username']);
                            $messenger->im($row['user_jabber'], $row['username']);
                            $messenger->assign_vars(array('EMAIL_SIG' => $sig, 'USERNAME' => html_entity_decode($row['username']), 'SITENAME' => $config['sitename'], 'REGISTER_DATE' => $user->format_date($row['user_regdate']), 'U_ACTIVATE' => "{$board_url}&mode=activate&u=" . $row['user_id'] . '&k=' . $row['user_actkey']));
                            $messenger->send($row['user_notify_type']);
                            $usernames[] = $row['username'];
                        } while ($row = $db->sql_fetchrow($result));
                        $messenger->save_queue();
                        add_log('admin', 'LOG_INDEX_REMIND', implode(', ', $usernames));
                        unset($usernames);
                    }
                    $db->sql_freeresult($result);
                    break;
            }
        }
        switch ($action) {
            case 'online':
                if (!$auth->acl_get('a_board')) {
                    trigger_error($user->lang['NO_ADMIN']);
                }
                set_config('record_online_users', 1, true);
                set_config('record_online_date', time(), true);
                add_log('admin', 'LOG_RESET_ONLINE');
                break;
            case 'stats':
                if (!$auth->acl_get('a_board')) {
                    trigger_error($user->lang['NO_ADMIN']);
                }
                $sql = 'SELECT COUNT(post_id) AS stat 
					FROM ' . POSTS_TABLE . '
					WHERE post_approved = 1';
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                set_config('num_posts', (int) $row['stat'], true);
                $sql = 'SELECT COUNT(topic_id) AS stat
					FROM ' . TOPICS_TABLE . '
					WHERE topic_approved = 1';
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                set_config('num_topics', (int) $row['stat'], true);
                $sql = 'SELECT COUNT(user_id) AS stat
					FROM ' . USERS_TABLE . '
					WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                set_config('num_users', (int) $row['stat'], true);
                $sql = 'SELECT COUNT(attach_id) as stat
					FROM ' . ATTACHMENTS_TABLE;
                $result = $db->sql_query($sql);
                set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
                $db->sql_freeresult($result);
                $sql = 'SELECT SUM(filesize) as stat
					FROM ' . ATTACHMENTS_TABLE;
                $result = $db->sql_query($sql);
                set_config('upload_dir_size', (int) $db->sql_fetchfield('stat'), true);
                $db->sql_freeresult($result);
                add_log('admin', 'LOG_RESYNC_STATS');
                break;
            case 'user':
                if (!$auth->acl_get('a_board')) {
                    trigger_error($user->lang['NO_ADMIN']);
                }
                $post_count_ary = $auth->acl_getf('f_postcount');
                $forum_read_ary = $auth->acl_getf('f_read');
                $forum_ary = array();
                foreach ($post_count_ary as $forum_id => $allowed) {
                    if ($allowed['f_postcount'] && $forum_read_ary[$forum_id]['f_read']) {
                        $forum_ary[] = $forum_id;
                    }
                }
                if (!sizeof($forum_ary)) {
                    $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
                } else {
                    $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
						FROM ' . POSTS_TABLE . '
						WHERE poster_id <> ' . ANONYMOUS . '
							AND forum_id IN (' . implode(', ', $forum_ary) . ')
						GROUP BY poster_id';
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $db->sql_query('UPDATE ' . USERS_TABLE . " SET user_posts = {$row['num_posts']} WHERE user_id = {$row['poster_id']}");
                    }
                    $db->sql_freeresult($result);
                }
                add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
                break;
            case 'date':
                if (!$auth->acl_get('a_board')) {
                    trigger_error($user->lang['NO_ADMIN']);
                }
                set_config('board_startdate', time() - 1);
                add_log('admin', 'LOG_RESET_DATE');
                break;
            case 'db_track':
                $db->sql_query((SQL_LAYER != 'sqlite' ? 'TRUNCATE TABLE ' : 'DELETE FROM ') . TOPICS_POSTED_TABLE);
                // This can get really nasty... therefore we only do the last six months
                $get_from_time = time() - 6 * 4 * 7 * 24 * 60 * 60;
                // Select forum ids, do not include categories
                $sql = 'SELECT forum_id
					FROM ' . FORUMS_TABLE . '
					WHERE forum_type <> ' . FORUM_CAT;
                $result = $db->sql_query($sql);
                $forum_ids = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $forum_ids[] = $row['forum_id'];
                }
                $db->sql_freeresult($result);
                // Any global announcements? ;)
                $forum_ids[] = 0;
                // Now go through the forums and get us some topics...
                foreach ($forum_ids as $forum_id) {
                    $sql = 'SELECT p.poster_id, p.topic_id
						FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
						WHERE t.forum_id = ' . $forum_id . '
							AND t.topic_moved_id = 0
							AND t.topic_last_post_time > ' . $get_from_time . '
							AND t.topic_id = p.topic_id
							AND p.poster_id <> ' . ANONYMOUS . '
						GROUP BY p.poster_id, p.topic_id';
                    $result = $db->sql_query($sql);
                    $posted = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $posted[$row['poster_id']][] = $row['topic_id'];
                    }
                    $db->sql_freeresult($result);
                    $sql_ary = array();
                    foreach ($posted as $user_id => $topic_row) {
                        foreach ($topic_row as $topic_id) {
                            $sql_ary[] = array('user_id' => $user_id, 'topic_id' => $topic_id, 'topic_posted' => 1);
                        }
                    }
                    unset($posted);
                    if (sizeof($sql_ary)) {
                        switch (SQL_LAYER) {
                            case 'mysql':
                            case 'mysql4':
                            case 'mysqli':
                                $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('MULTI_INSERT', $sql_ary));
                                break;
                            default:
                                foreach ($sql_ary as $ary) {
                                    $db->sql_query('INSERT INTO ' . TOPICS_POSTED_TABLE . ' ' . $db->sql_build_array('INSERT', $ary));
                                }
                                break;
                        }
                    }
                }
                add_log('admin', 'LOG_RESYNC_POST_MARKING');
                break;
        }
        // Get forum statistics
        $total_posts = $config['num_posts'];
        $total_topics = $config['num_topics'];
        $total_users = $config['num_users'];
        $total_files = $config['num_files'];
        $start_date = $user->format_date($config['board_startdate']);
        $boarddays = (time() - $config['board_startdate']) / 86400;
        $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
        $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
        $users_per_day = sprintf('%.2f', $total_users / $boarddays);
        $files_per_day = sprintf('%.2f', $total_files / $boarddays);
        $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']));
        $avatar_dir_size = 0;
        if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) {
            while (($file = readdir($avatar_dir)) !== false) {
                if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) {
                    $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
                }
            }
            @closedir($avatar_dir);
            // This bit of code translates the avatar directory size into human readable format
            // Borrowed the code from the PHP.net annoted manual, origanally written by:
            // Jesse (jesse@jess.on.ca)
            $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));
        } else {
            // Couldn't open Avatar dir.
            $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
        }
        if ($posts_per_day > $total_posts) {
            $posts_per_day = $total_posts;
        }
        if ($topics_per_day > $total_topics) {
            $topics_per_day = $total_topics;
        }
        if ($users_per_day > $total_users) {
            $users_per_day = $total_users;
        }
        if ($files_per_day > $total_files) {
            $files_per_day = $total_files;
        }
        $dbsize = get_database_size();
        $s_action_options = build_select(array('online' => 'RESET_ONLINE', 'date' => 'RESET_DATE', 'stats' => 'RESYNC_STATS', 'user' => 'RESYNC_POSTCOUNTS', 'db_track' => 'RESYNC_POST_MARKING'));
        $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'POSTS_PER_DAY' => $posts_per_day, 'TOTAL_TOPICS' => $total_topics, 'TOPICS_PER_DAY' => $topics_per_day, 'TOTAL_USERS' => $total_users, 'USERS_PER_DAY' => $users_per_day, 'TOTAL_FILES' => $total_files, 'FILES_PER_DAY' => $files_per_day, 'START_DATE' => $start_date, 'AVATAR_DIR_SIZE' => $avatar_dir_size, 'DBSIZE' => $dbsize, 'UPLOAD_DIR_SIZE' => $upload_dir_size, 'GZIP_COMPRESSION' => $config['gzip_compress'] ? $user->lang['ON'] : $user->lang['OFF'], 'U_ACTION' => append_sid("{$phpbb_admin_path}index.{$phpEx}"), 'S_ACTION_OPTIONS' => $auth->acl_get('a_board') ? $s_action_options : ''));
        $log_data = array();
        $log_count = 0;
        if ($auth->acl_get('a_viewlogs')) {
            view_log('admin', $log_data, $log_count, 5);
            foreach ($log_data as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action']));
            }
        }
        if ($auth->acl_get('a_user')) {
            $sql = 'SELECT user_id, username, user_regdate
				FROM ' . USERS_TABLE . ' 
				WHERE user_type = ' . USER_INACTIVE . ' 
				ORDER BY user_regdate ASC';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $template->assign_block_vars('inactive', array('DATE' => $user->format_date($row['user_regdate']), 'USER_ID' => $row['user_id'], 'USERNAME' => $row['username'], 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}")));
            }
            $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
            if ($config['email_enable']) {
                $option_ary += array('remind' => 'REMIND');
            }
            $template->assign_vars(array('S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary)));
        }
        // Display debug_extra notice
        if (defined('DEBUG_EXTRA')) {
            $template->assign_var('S_DEBUG_EXTRA', true);
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
예제 #8
0
/**
* Handling actions in post details screen
*/
function mcp_post_details($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth, $cache;
    $user->add_lang('posting');
    $post_id = request_var('p', 0);
    $start = request_var('start', 0);
    // Get post data
    $post_info = get_post_data(array($post_id), false, true);
    add_form_key('mcp_post_details');
    if (!sizeof($post_info)) {
        trigger_error('POST_NOT_EXIST');
    }
    $post_info = $post_info[$post_id];
    $url = append_sid("{$phpbb_root_path}mcp.{$phpEx}?" . extra_url());
    switch ($action) {
        case 'whois':
            if ($auth->acl_get('m_info', $post_info['forum_id'])) {
                $ip = request_var('ip', '');
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                $template->assign_vars(array('RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;p={$post_id}") . '">', '</a>'), 'U_RETURN_POST' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;p={$post_id}"), 'L_RETURN_POST' => sprintf($user->lang['RETURN_POST'], '', ''), 'WHOIS' => user_ipwhois($ip)));
            }
            // We're done with the whois page so return
            return;
            break;
        case 'chgposter':
        case 'chgposter_ip':
            if ($action == 'chgposter') {
                $username = request_var('username', '', true);
                $sql_where = "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
            } else {
                $new_user_id = request_var('u', 0);
                $sql_where = 'user_id = ' . $new_user_id;
            }
            $sql = 'SELECT *
				FROM ' . USERS_TABLE . '
				WHERE ' . $sql_where;
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row) {
                trigger_error('NO_USER');
            }
            if ($auth->acl_get('m_chgposter', $post_info['forum_id'])) {
                if (check_form_key('mcp_post_details')) {
                    change_poster($post_info, $row);
                } else {
                    trigger_error('FORM_INVALID');
                }
            }
            break;
    }
    // Set some vars
    $users_ary = $usernames_ary = array();
    $attachments = $extensions = array();
    $post_id = $post_info['post_id'];
    $topic_tracking_info = array();
    // Get topic tracking info
    if ($config['load_db_lastread']) {
        $tmp_topic_data = array($post_info['topic_id'] => $post_info);
        $topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
        unset($tmp_topic_data);
    } else {
        $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
    }
    $post_unread = isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']] ? true : false;
    // Process message, leave it uncensored
    $message = $post_info['post_text'];
    if ($post_info['bbcode_bitfield']) {
        include_once $phpbb_root_path . 'includes/bbcode.' . $phpEx;
        $bbcode = new bbcode($post_info['bbcode_bitfield']);
        $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
    }
    $message = bbcode_nl2br($message);
    $message = smiley_text($message);
    if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id'])) {
        $extensions = $cache->obtain_attach_extensions($post_info['forum_id']);
        $sql = 'SELECT *
			FROM ' . ATTACHMENTS_TABLE . '
			WHERE post_msg_id = ' . $post_id . '
				AND in_message = 0
			ORDER BY filetime DESC, post_msg_id ASC';
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $attachments[] = $row;
        }
        $db->sql_freeresult($result);
        if (sizeof($attachments)) {
            $update_count = array();
            parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
        }
        // Display not already displayed Attachments for this post, we already parsed them. ;)
        if (!empty($attachments)) {
            $template->assign_var('S_HAS_ATTACHMENTS', true);
            foreach ($attachments as $attachment) {
                $template->assign_block_vars('attachment', array('DISPLAY_ATTACHMENT' => $attachment));
            }
        }
    }
    $template->assign_vars(array('U_MCP_ACTION' => "{$url}&amp;i=main&amp;quickmod=1&amp;mode=post_details", 'U_POST_ACTION' => "{$url}&amp;i={$id}&amp;mode=post_details", 'U_APPROVE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue&amp;p={$post_id}&amp;f={$post_info['forum_id']}"), 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_CAN_CHGPOSTER' => $auth->acl_get('m_chgposter', $post_info['forum_id']), 'S_CAN_LOCK_POST' => $auth->acl_get('m_lock', $post_info['forum_id']), 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'] ? true : false, 'S_POST_UNAPPROVED' => !$post_info['post_approved'] ? true : false, 'S_POST_LOCKED' => $post_info['post_edit_locked'] ? true : false, 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'U_EDIT' => $auth->acl_get('m_edit', $post_info['forum_id']) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '', 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=mcp_chgposter&amp;field=username&amp;select_single=true'), 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id), 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id), 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']), 'U_MCP_WARN_USER' => $auth->acl_get('m_warn') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '', 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']), 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']), 'MINI_POST_IMG' => $post_unread ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'), 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$post_info['forum_id']}&amp;p={$post_id}") . "#p{$post_id}\">", '</a>'), 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'), 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']), 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']), 'SEARCH_IMG' => $user->img('icon_user_search', $user->lang['SEARCH']), 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']), 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], 'POST_IPADDR' => $auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '') ? @gethostbyaddr($post_info['poster_ip']) : '', 'POST_ID' => $post_info['post_id'], 'U_LOOKUP_IP' => $auth->acl_get('m_info', $post_info['forum_id']) ? "{$url}&amp;i={$id}&amp;mode={$mode}&amp;lookup={$post_info['poster_ip']}#ip" : '', 'U_WHOIS' => $auth->acl_get('m_info', $post_info['forum_id']) ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;action=whois&amp;p={$post_id}&amp;ip={$post_info['poster_ip']}") : ''));
    // Get User Notes
    $log_data = array();
    $log_count = false;
    view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
    if (!empty($log_data)) {
        $template->assign_var('S_USER_NOTES', true);
        foreach ($log_data as $row) {
            $template->assign_block_vars('usernotes', array('REPORT_BY' => $row['username_full'], 'REPORT_AT' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'ID' => $row['id']));
        }
    }
    // Get Reports
    if ($auth->acl_get('m_report', $post_info['forum_id'])) {
        $sql = 'SELECT r.*, re.*, u.user_id, u.username
			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re\n\t\t\tWHERE r.post_id = {$post_id}\n\t\t\t\tAND r.reason_id = re.reason_id\n\t\t\t\tAND u.user_id = r.user_id\n\t\t\tORDER BY r.report_time DESC";
        $result = $db->sql_query($sql);
        if ($row = $db->sql_fetchrow($result)) {
            $template->assign_var('S_SHOW_REPORTS', true);
            do {
                // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
                if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) {
                    $row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
                    $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
                }
                $template->assign_block_vars('reports', array('REPORT_ID' => $row['report_id'], 'REASON_TITLE' => $row['reason_title'], 'REASON_DESC' => $row['reason_description'], 'REPORTER' => $row['user_id'] != ANONYMOUS ? $row['username'] : $user->lang['GUEST'], 'U_REPORTER' => $row['user_id'] != ANONYMOUS ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'USER_NOTIFY' => $row['user_notify'] ? true : false, 'REPORT_TIME' => $user->format_date($row['report_time']), 'REPORT_TEXT' => bbcode_nl2br(trim($row['report_text']))));
            } while ($row = $db->sql_fetchrow($result));
        }
        $db->sql_freeresult($result);
    }
    // Get IP
    if ($auth->acl_get('m_info', $post_info['forum_id'])) {
        $rdns_ip_num = request_var('rdns', '');
        if ($rdns_ip_num != 'all') {
            $template->assign_vars(array('U_LOOKUP_ALL' => "{$url}&amp;i=main&amp;mode=post_details&amp;rdns=all"));
        }
        // Get other users who've posted under this IP
        $sql = 'SELECT poster_id, COUNT(poster_id) as postings
			FROM ' . POSTS_TABLE . "\n\t\t\tWHERE poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'\n\t\t\tGROUP BY poster_id\n\t\t\tORDER BY postings DESC";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            // Fill the user select list with users who have posted under this IP
            if ($row['poster_id'] != $post_info['poster_id']) {
                $users_ary[$row['poster_id']] = $row;
            }
        }
        $db->sql_freeresult($result);
        if (sizeof($users_ary)) {
            // Get the usernames
            $sql = 'SELECT user_id, username
				FROM ' . USERS_TABLE . '
				WHERE ' . $db->sql_in_set('user_id', array_keys($users_ary));
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $users_ary[$row['user_id']]['username'] = $row['username'];
                $usernames_ary[utf8_clean_string($row['username'])] = $users_ary[$row['user_id']];
            }
            $db->sql_freeresult($result);
            foreach ($users_ary as $user_id => $user_row) {
                $template->assign_block_vars('userrow', array('USERNAME' => $user_id == ANONYMOUS ? $user->lang['GUEST'] : $user_row['username'], 'NUM_POSTS' => $user_row['postings'], 'L_POST_S' => $user_row['postings'] == 1 ? $user->lang['POST'] : $user->lang['POSTS'], 'U_PROFILE' => $user_id == ANONYMOUS ? '' : append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $user_id), 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.{$phpEx}", 'author_id=' . $user_id . '&amp;sr=topics')));
            }
        }
        // Get other IP's this user has posted under
        // A compound index on poster_id, poster_ip (posts table) would help speed up this query a lot,
        // but the extra size is only valuable if there are persons having more than a thousands posts.
        // This is better left to the really really big forums.
        $sql = 'SELECT poster_ip, COUNT(poster_ip) AS postings
			FROM ' . POSTS_TABLE . '
			WHERE poster_id = ' . $post_info['poster_id'] . "\n\t\t\tGROUP BY poster_ip\n\t\t\tORDER BY postings DESC";
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $hostname = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip'] ? @gethostbyaddr($row['poster_ip']) : '';
            $template->assign_block_vars('iprow', array('IP' => $row['poster_ip'], 'HOSTNAME' => $hostname, 'NUM_POSTS' => $row['postings'], 'L_POST_S' => $row['postings'] == 1 ? $user->lang['POST'] : $user->lang['POSTS'], 'U_LOOKUP_IP' => $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all' ? '' : "{$url}&amp;i={$id}&amp;mode=post_details&amp;rdns={$row['poster_ip']}#ip", 'U_WHOIS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;action=whois&amp;p={$post_id}&amp;ip={$row['poster_ip']}")));
        }
        $db->sql_freeresult($result);
        $user_select = '';
        if (sizeof($usernames_ary)) {
            ksort($usernames_ary);
            foreach ($usernames_ary as $row) {
                $user_select .= '<option value="' . $row['poster_id'] . '">' . $row['username'] . "</option>\n";
            }
        }
        $template->assign_var('S_USER_SELECT', $user_select);
    }
}
예제 #9
0
 function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     $user->add_lang('mcp');
     // Set up general vars
     $action = request_var('action', '');
     $forum_id = request_var('f', 0);
     $start = request_var('start', 0);
     $deletemark = !empty($_POST['delmarked']) ? true : false;
     $deleteall = !empty($_POST['delall']) ? true : false;
     $marked = request_var('mark', array(0));
     // Sort keys
     $sort_days = request_var('st', 0);
     $sort_key = request_var('sk', 't');
     $sort_dir = request_var('sd', 'd');
     $this->tpl_name = 'acp_logs';
     $this->log_type = constant('LOG_' . strtoupper($mode));
     // Delete entries if requested and able
     if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
         if (confirm_box(true)) {
             $where_sql = '';
             if ($deletemark && sizeof($marked)) {
                 $sql_in = array();
                 foreach ($marked as $mark) {
                     $sql_in[] = $mark;
                 }
                 $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
                 unset($sql_in);
             }
             if ($where_sql || $deleteall) {
                 $sql = 'DELETE FROM ' . LOG_TABLE . "\n\t\t\t\t\t\tWHERE log_type = {$this->log_type}\n\t\t\t\t\t\t{$where_sql}";
                 $db->sql_query($sql);
                 add_log('admin', 'LOG_CLEAR_' . strtoupper($mode));
             }
         } else {
             confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('f' => $forum_id, 'start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => $action)));
         }
     }
     // Sorting
     $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']);
     $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
     $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
     $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
     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);
     // Define where and sort sql for use in displaying logs
     $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
     $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
     $l_title = $user->lang['ACP_' . strtoupper($mode) . '_LOGS'];
     $l_title_explain = $user->lang['ACP_' . strtoupper($mode) . '_LOGS_EXPLAIN'];
     $this->page_title = $l_title;
     // Define forum list if we're looking @ mod logs
     if ($mode == 'mod') {
         $forum_box = '<option value="0">' . $user->lang['ALL_FORUMS'] . '</option>' . make_forum_select($forum_id);
         $template->assign_vars(array('S_SHOW_FORUMS' => true, 'S_FORUM_BOX' => $forum_box));
     }
     // Grab log data
     $log_data = array();
     $log_count = 0;
     view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort);
     $template->assign_vars(array('L_TITLE' => $l_title, 'L_EXPLAIN' => $l_title_explain, 'U_ACTION' => $this->u_action, 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
     foreach ($log_data as $row) {
         $data = array();
         $checks = array('viewtopic', 'viewlogs', 'viewforum');
         foreach ($checks as $check) {
             if (isset($row[$check]) && $row[$check]) {
                 $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
             }
         }
         $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'REPORTEE_USERNAME' => $row['reportee_username'] && $row['user_id'] != $row['reportee_id'] ? $row['reportee_username_full'] : '', 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
     }
 }
예제 #10
0
                                            </div>
                                            <div class="help-block" style="margin:0px;"></div></div></div>







                                </div>
                            </div>

                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile"><?php 
            view_log($tid);
            ?>
</div>
                </div>
            </div>
            </div>


            <div class="col-md-4">
                <div class="panel panel-info">
                    <?php 
            echo get_client_info_ticket($cid);
            ?>
                </div>
            </div>
예제 #11
0
/**
* Handling actions in post details screen
*/
function mcp_post_details($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth;
    $user->add_lang('posting');
    $post_id = request_var('p', 0);
    $start = request_var('start', 0);
    // Get post data
    $post_info = get_post_data(array($post_id));
    if (!sizeof($post_info)) {
        trigger_error($user->lang['POST_NOT_EXIST']);
    }
    $post_info = $post_info[$post_id];
    $url = append_sid("{$phpbb_root_path}mcp.{$phpEx}?" . extra_url());
    switch ($action) {
        case 'whois':
            $ip = request_var('ip', '');
            include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            $whois = user_ipwhois($ip);
            $whois = preg_replace('#(\\s)([\\w\\-\\._\\+]+@[\\w\\-\\.]+)(\\s)#', '\\1<a href="mailto:\\2">\\2</a>\\3', $whois);
            $whois = preg_replace('#(\\s)(http:/{2}[^\\s]*)(\\s)#', '\\1<a href="\\2" target="_blank">\\2</a>\\3', $whois);
            $template->assign_vars(array('RETURN_POST' => sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;p={$post_id}") . '">', '</a>'), 'WHOIS' => trim($whois)));
            // We're done with the whois page so return
            return;
            break;
        case 'chgposter':
        case 'chgposter_ip':
            if ($action == 'chgposter') {
                $username = request_var('username', '', true);
                $sql_where = "username = '******'";
            } else {
                $new_user_id = request_var('u', 0);
                $sql_where = 'user_id = ' . $new_user_id;
            }
            $sql = 'SELECT *
				FROM ' . USERS_TABLE . '
				WHERE ' . $sql_where;
            $result = $db->sql_query($sql);
            $row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            if (!$row) {
                trigger_error($user->lang['NO_USER']);
            }
            if ($auth->acl_get('m_chgposter', $post_info['forum_id'])) {
                change_poster($post_info, $row);
            }
            break;
    }
    // Set some vars
    $users_ary = array();
    $post_id = $post_info['post_id'];
    $poster = $post_info['user_colour'] ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
    // Process message, leave it uncensored
    $message = $post_info['post_text'];
    if ($post_info['bbcode_bitfield']) {
        include_once $phpbb_root_path . 'includes/bbcode.' . $phpEx;
        $bbcode = new bbcode($post_info['bbcode_bitfield']);
        $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
    }
    $message = smiley_text($message);
    $message = str_replace("\n", '<br />', $message);
    $template->assign_vars(array('U_MCP_ACTION' => "{$url}&amp;i=main&amp;quickmod=1", 'U_POST_ACTION' => "{$url}&amp;i={$id}&amp;mode=post_details", 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']), 'S_CAN_CHGPOSTER' => $auth->acl_get('m_chgposter', $post_info['forum_id']), 'S_CAN_LOCK_POST' => $auth->acl_get('m_lock', $post_info['forum_id']), 'S_CAN_DELETE_POST' => $auth->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'] ? true : false, 'S_POST_UNAPPROVED' => !$post_info['post_approved'] ? true : false, 'S_POST_LOCKED' => $post_info['post_edit_locked'] ? true : false, 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'U_EDIT' => $auth->acl_get('m_edit', $post_info['forum_id']) ? append_sid("{$phpbb_root_path}posting.{$phpEx}", "mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '', 'U_FIND_MEMBER' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=mcp_chgposter&amp;field=username'), 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id), 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id), 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']), 'U_MCP_WARN_USER' => $auth->acl_getf_global('m_warn') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '', 'U_VIEW_PROFILE' => $post_info['user_id'] != ANONYMOUS ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $post_info['user_id']) : '', 'RETURN_TOPIC' => sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "f={$post_info['forum_id']}&amp;p={$post_id}") . "#p{$post_id}\">", '</a>'), 'RETURN_FORUM' => sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.{$phpEx}", "f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'), 'REPORTED_IMG' => $user->img('icon_reported', $user->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $user->img('icon_unapproved', $user->lang['POST_UNAPPROVED']), 'EDIT_IMG' => $user->img('btn_edit', $user->lang['EDIT_POST']), 'POSTER_NAME' => $poster, 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $user->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip']), 'POST_ID' => $post_info['post_id']));
    // Get User Notes
    $log_data = array();
    $log_count = 0;
    view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
    if ($log_count) {
        $template->assign_var('S_USER_NOTES', true);
        foreach ($log_data as $row) {
            $template->assign_block_vars('usernotes', array('REPORT_BY' => $row['username'], 'REPORT_AT' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'ID' => $row['id']));
        }
    }
    // Get Reports
    if ($auth->acl_get('m_', $post_info['forum_id'])) {
        $sql = 'SELECT r.*, re.*, u.user_id, u.username
			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REPORTS_REASONS_TABLE . " re\n\t\t\tWHERE r.post_id = {$post_id}\n\t\t\t\tAND r.reason_id = re.reason_id\n\t\t\t\tAND u.user_id = r.user_id\n\t\t\tORDER BY r.report_time DESC";
        $result = $db->sql_query($sql);
        if ($row = $db->sql_fetchrow($result)) {
            $template->assign_var('S_SHOW_REPORTS', true);
            do {
                // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
                if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) {
                    $row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
                    $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
                }
                $template->assign_block_vars('reports', array('REPORT_ID' => $row['report_id'], 'REASON_TITLE' => $row['reason_title'], 'REASON_DESC' => $row['reason_description'], 'REPORTER' => $row['user_id'] != ANONYMOUS ? $row['username'] : $user->lang['GUEST'], 'U_REPORTER' => $row['user_id'] != ANONYMOUS ? append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']) : '', 'USER_NOTIFY' => $row['user_notify'] ? true : false, 'REPORT_TIME' => $user->format_date($row['report_time']), 'REPORT_TEXT' => str_replace("\n", '<br />', trim($row['report_text']))));
            } while ($row = $db->sql_fetchrow($result));
        }
        $db->sql_freeresult($result);
    }
    // Get IP
    if ($auth->acl_get('m_info', $post_info['forum_id'])) {
        $rdns_ip_num = request_var('rdns', '');
        if ($rdns_ip_num != 'all') {
            $template->assign_vars(array('U_LOOKUP_ALL' => "{$url}&amp;i=main&amp;mode=post_details&amp;rdns=all"));
        }
        // Get other users who've posted under this IP
        // Firebird does not support ORDER BY on aliased columns
        // MySQL does not support ORDER BY on functions
        switch (SQL_LAYER) {
            case 'firebird':
                $sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
					FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p\n\t\t\t\t\tWHERE p.poster_id = u.user_id\n\t\t\t\t\t\tAND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'\n\t\t\t\t\t\tAND p.poster_id <> {$post_info['user_id']}\n\t\t\t\t\tGROUP BY u.user_id, u.username\n\t\t\t\t\tORDER BY COUNT(*) DESC";
                break;
            default:
                $sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
					FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p\n\t\t\t\t\tWHERE p.poster_id = u.user_id\n\t\t\t\t\t\tAND p.poster_ip = '" . $db->sql_escape($post_info['poster_ip']) . "'\n\t\t\t\t\t\tAND p.poster_id <> {$post_info['user_id']}\n\t\t\t\t\tGROUP BY u.user_id, u.username\n\t\t\t\t\tORDER BY postings DESC";
                break;
        }
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            // Fill the user select list with users who have posted
            // under this IP
            if ($row['user_id'] != $post_info['poster_id']) {
                $users_ary[strtolower($row['username'])] = $row;
            }
            $template->assign_block_vars('userrow', array('USERNAME' => $row['user_id'] == ANONYMOUS ? $user->lang['GUEST'] : $row['username'], 'NUM_POSTS' => $row['postings'], 'L_POST_S' => $row['postings'] == 1 ? $user->lang['POST'] : $user->lang['POSTS'], 'U_PROFILE' => $row['user_id'] == ANONYMOUS ? '' : append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $row['user_id']), 'U_SEARCHPOSTS' => append_sid("{$phpbb_root_path}search.{$phpEx}", 'author=' . urlencode($row['username']) . '&amp;sr=topics')));
        }
        $db->sql_freeresult($result);
        // Get other IP's this user has posted under
        // Firebird does not support ORDER BY on aliased columns
        // MySQL does not support ORDER BY on functions
        switch (SQL_LAYER) {
            case 'firebird':
                $sql = 'SELECT poster_ip, COUNT(*) AS postings
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $post_info['poster_id'] . '
					GROUP BY poster_ip
					ORDER BY COUNT(*) DESC';
                break;
            default:
                $sql = 'SELECT poster_ip, COUNT(*) AS postings
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $post_info['poster_id'] . '
					GROUP BY poster_ip
					ORDER BY postings DESC';
                break;
        }
        $result = $db->sql_query($sql);
        while ($row = $db->sql_fetchrow($result)) {
            $hostname = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip'] ? @gethostbyaddr($row['poster_ip']) : '';
            $template->assign_block_vars('iprow', array('IP' => $row['poster_ip'], 'HOSTNAME' => $hostname, 'NUM_POSTS' => $row['postings'], 'L_POST_S' => $row['postings'] == 1 ? $user->lang['POST'] : $user->lang['POSTS'], 'U_LOOKUP_IP' => $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all' ? '' : "{$url}&amp;i={$id}&amp;mode=post_details&amp;rdns={$row['poster_ip']}#ip", 'U_WHOIS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode={$mode}&amp;action=whois&amp;p={$post_id}&amp;ip={$row['poster_ip']}")));
        }
        $db->sql_freeresult($result);
        $user_select = '';
        ksort($users_ary);
        foreach ($users_ary as $row) {
            $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n";
        }
        $template->assign_var('S_USER_SELECT', $user_select);
    }
}
예제 #12
0
</th>
		<th width="15%"><?php 
echo $_CLASS['core_user']->lang['IP'];
?>
</th>
		<th width="20%"><?php 
echo $_CLASS['core_user']->lang['TIME'];
?>
</th>
		<th width="45%" nowrap="nowrap"><?php 
echo $_CLASS['core_user']->lang['ACTION'];
?>
</th>
	</tr>
<?php 
view_log('admin', $log_data, $log_count, 10);
$row_class = 'row2';
for ($i = 0; $i < sizeof($log_data); $i++) {
    $row_class = $row_class == 'row1' ? 'row2' : 'row1';
    ?>
	<tr>
		<td class="<?php 
    echo $row_class;
    ?>
"><?php 
    echo $log_data[$i]['username'];
    ?>
</td>
		<td class="<?php 
    echo $row_class;
    ?>
예제 #13
0
    function main($id, $mode)
    {
        global $db, $user, $auth, $template, $cache, $phpEx;
        global $config, $phpbb_root_path, $phpbb_admin_path;
        include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
        include $phpbb_root_path . 'includes/functions_invite.' . $phpEx;
        $user->add_lang(array('ucp', 'mods/info_acp_invite', 'acp/board', 'acp/email'));
        $invite = new invite();
        $action = request_var('action', '');
        $submit = isset($_POST['submit']) ? true : false;
        $error = array();
        foreach ($invite->config as $k => $v) {
            $new_config[$k] = utf8_normalize_nfc(request_var($k, $v, true));
        }
        $form_key = 'acp_invite';
        add_form_key($form_key);
        if (request_var('version_check', false)) {
            $mode = 'version';
        }
        if (!$invite->config['enable']) {
            $error[] = $user->lang['ACP_IAF_DISABLED'];
        }
        if ($invite->config['enable'] && !$config['email_enable']) {
            $error[] = sprintf($user->lang['ERROR_EMAIL_DISABLED'], append_sid("{$phpbb_admin_path}index.{$phpEx}?i=board&amp;mode=email"));
        }
        switch ($mode) {
            case 'overview':
                $this->page_title = 'ACP_INVITE_OVERVIEW';
                $this->tpl_name = 'acp_invite_overview';
                // Calculate stats
                $days_installed = (time() - $invite->config['tracking_time']) / 86400;
                $invitations_per_day = sprintf('%.2f', $invite->config['num_invitations'] / $days_installed);
                $registrations_per_day = sprintf('%.2f', $invite->config['num_registrations'] / $days_installed);
                $referrals_per_day = sprintf('%.2f', $invite->config['num_referrals'] / $days_installed);
                $install_date = $user->format_date($invite->config['tracking_time']);
                // Version check
                $latest_version_info = $update_to_date = false;
                if (($latest_version_info = $this->latest_version_info(request_var('versioncheck_force', false))) === false) {
                    $template->assign_var('S_VERSIONCHECK_FAIL', true);
                } else {
                    $latest_version_info = explode("\n", $latest_version_info);
                    $up_to_date = phpbb_version_compare($invite->config['version'], trim($latest_version_info[0]), '<') ? false : true;
                }
                if ($action) {
                    if (!confirm_box(true)) {
                        switch ($action) {
                            case 'sync_referral_data':
                                $confirm = true;
                                $confirm_lang = 'ACP_INVITE_CONFIRM_SYNC_REFERRAL_DATA';
                                break;
                            default:
                                $confirm = false;
                                break;
                        }
                        if ($confirm) {
                            confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                        }
                    } else {
                        switch ($action) {
                            case 'sync_referral_data':
                                // Get an idea of which users need to be updated
                                $sql = 'SELECT invite_user_id, register_user_id, invite_time
										FROM ' . INVITE_LOG_TABLE . '
										WHERE register_key_used = 1';
                                $result = $db->sql_query($sql);
                                $uid_array = $db->sql_fetchrowset($result);
                                $db->sql_freeresult($result);
                                for ($i = 0; $i < sizeof($uid_array); $i++) {
                                    if ($invite->config['referral_invitation_bridge']) {
                                        $sql = 'SELECT COUNT(referrer_id) AS is_existent
											FROM ' . INVITE_REFERRALS_TABLE . '
											WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'] . '
												AND referral_id = ' . (int) $uid_array[$i]['register_user_id'];
                                        $result = $db->sql_query($sql);
                                        $exists = $db->sql_fetchfield('is_existent');
                                        $db->sql_freeresult($result);
                                        if (!$exists) {
                                            $sql_ary = array('user_referrer_id' => $uid_array[$i]['invite_user_id'], 'user_referrer_name' => $invite->user_return_data($uid_array[$i]['invite_user_id'], 'user_id', 'username_clean'));
                                            $sql = 'UPDATE ' . USERS_TABLE . '
													SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
													WHERE user_id = ' . (int) $uid_array[$i]['register_user_id'];
                                            $result = $db->sql_query($sql);
                                            $db->sql_freeresult($result);
                                            $sql_ary = array('referrer_id' => $uid_array[$i]['invite_user_id'], 'referral_id' => $uid_array[$i]['register_user_id'], 'time' => $uid_array[$i]['invite_time']);
                                            $sql = 'INSERT INTO ' . INVITE_REFERRALS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
                                            $db->sql_query($sql);
                                        }
                                    } else {
                                        $sql_ary = array('user_referrer_id' => 0, 'user_referrer_name' => '');
                                        $sql = 'UPDATE ' . USERS_TABLE . '
												SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
												WHERE user_id = ' . (int) $uid_array[$i]['register_user_id'];
                                        $result = $db->sql_query($sql);
                                        $db->sql_freeresult($result);
                                        $sql = 'DELETE FROM ' . INVITE_REFERRALS_TABLE . '
												WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'] . '
												AND referral_id = ' . (int) $uid_array[$i]['register_user_id'];
                                        $db->sql_query($sql);
                                        $sql = 'SELECT COUNT(referrer_id) AS total_referrals
											FROM ' . INVITE_REFERRALS_TABLE;
                                        $result = $db->sql_query($sql);
                                        $total_referrals = $db->sql_fetchfield('total_referrals');
                                        $db->sql_freeresult($result);
                                        $sql = 'UPDATE ' . INVITE_CONFIG_TABLE . ' SET config_value = ' . (int) $total_referrals . ' WHERE config_name = "num_referrals"';
                                        $result = $db->sql_query($sql);
                                        $db->sql_freeresult($result);
                                        $sql = 'SELECT COUNT(referrer_id) AS user_referrals
											FROM ' . INVITE_REFERRALS_TABLE . '
											WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'];
                                        $result = $db->sql_query($sql);
                                        $user_referrals = $db->sql_fetchfield('user_referrals');
                                        $db->sql_freeresult($result);
                                        $sql = 'UPDATE ' . USERS_TABLE . '
												SET user_referrals = ' . $user_referrals . '
												WHERE user_id = ' . (int) $uid_array[$i]['invite_user_id'];
                                        $result = $db->sql_query($sql);
                                        $db->sql_freeresult($result);
                                    }
                                    // Synch stats
                                    $sql = 'SELECT COUNT(referrer_id) AS total_referrals
										FROM ' . INVITE_REFERRALS_TABLE;
                                    $result = $db->sql_query($sql);
                                    $total_referrals = $db->sql_fetchfield('total_referrals');
                                    $db->sql_freeresult($result);
                                    $sql = 'UPDATE ' . INVITE_CONFIG_TABLE . ' SET config_value = ' . (int) $total_referrals . ' WHERE config_name = "num_referrals"';
                                    $result = $db->sql_query($sql);
                                    $sql = 'SELECT COUNT(referrer_id) AS user_referrals
										FROM ' . INVITE_REFERRALS_TABLE . '
										WHERE referrer_id = ' . (int) $uid_array[$i]['invite_user_id'];
                                    $result = $db->sql_query($sql);
                                    $user_referrals = $db->sql_fetchfield('user_referrals');
                                    $db->sql_freeresult($result);
                                    $sql = 'UPDATE ' . USERS_TABLE . '
											SET user_referrals = ' . $user_referrals . '
											WHERE user_id = ' . (int) $uid_array[$i]['invite_user_id'];
                                    $result = $db->sql_query($sql);
                                }
                                break;
                            default:
                                trigger_error('NO_MODE', E_USER_ERROR);
                                break;
                        }
                        add_log('admin', 'LOG_INVITE_' . strtoupper($action));
                        trigger_error($user->lang['ACP_INVITE_' . strtoupper($action) . '_SUCCESS'] . adm_back_link($this->u_action));
                    }
                }
                if ($submit) {
                    if (!check_form_key($form_key)) {
                        $error[] = $user->lang['FORM_INVALID'];
                    }
                    foreach ($new_config as $k => $v) {
                        $invite->set_config($k, $v);
                    }
                    add_log('admin', 'LOG_INVITE_SETTINGS_UPDATED');
                    trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                foreach ($new_config as $k => $v) {
                    $template->assign_vars(array('S_' . strtoupper($k) => $v));
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'TOTAL_INVITATIONS' => $invite->config['num_invitations'], 'INVITATIONS_PER_DAY' => $invitations_per_day, 'TOTAL_SUCCESSFUL_INVITATIONS' => $invite->config['num_registrations'], 'SUCCESSFUL_INVITATIONS_PER_DAY' => $registrations_per_day, 'TOTAL_REFERRALS' => $invite->config['num_referrals'], 'REFERRALS_PER_DAY' => $referrals_per_day, 'INSTALL_DATE' => $install_date, 'INVITE_VERSION' => $invite->config['version'], 'U_ACTION' => $this->u_action, 'U_VERSIONCHECK' => $this->u_action . '&amp;version_check=1', 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;versioncheck_force=1', 'S_VERSION_UP_TO_DATE' => $up_to_date, 'S_SETTINGS_AUTH' => $auth->acl_get('acl_a_invite_settings') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
                break;
            case 'version':
                $this->page_title = 'ACP_INVITE_OVERVIEW';
                $this->tpl_name = 'acp_invite_overview';
                $user->add_lang('install');
                $errstr = '';
                $errno = 0;
                $info = $this->latest_version_info(request_var('versioncheck_force', false), true);
                if ($info === false) {
                    trigger_error('VERSIONCHECK_FAIL', E_USER_WARNING);
                }
                $info = explode("\n", $info);
                $latest_version = trim($info[0]);
                $announcement_url = trim($info[1]);
                $announcement_url = strpos($announcement_url, '&amp;') === false ? str_replace('&', '&amp;', $announcement_url) : $announcement_url;
                $update_link = append_sid($phpbb_root_path . 'install/index.' . $phpEx);
                $next_feature_version = $next_feature_announcement_url = false;
                if (isset($info[2]) && trim($info[2]) !== '') {
                    $next_feature_version = trim($info[2]);
                    $next_feature_announcement_url = trim($info[3]);
                }
                $up_to_date = phpbb_version_compare($invite->config['version'], $latest_version, '<') ? false : true;
                $template->assign_vars(array('S_VERSION_CHECK' => true, 'S_UP_TO_DATE' => $up_to_date, 'U_VERSIONCHECK_FORCE' => $this->u_action . '&amp;version_check=1&amp;versioncheck_force=1', 'LATEST_VERSION' => '<strong style="color:#228822">' . $latest_version . '</strong>', 'CURRENT_VERSION' => '<strong style="color:#' . ($up_to_date ? '228822' : 'BC2A4D') . '">' . $invite->config['version'] . '</strong>', 'NEXT_FEATURE_VERSION' => $next_feature_version, 'UPDATE_INSTRUCTIONS' => sprintf($user->lang['ACP_INVITE_UPDATE_INSTRUCTIONS'], $announcement_url, $update_link), 'UPGRADE_INSTRUCTIONS' => $next_feature_version ? $user->lang('INVITE_UPGRADE_INSTRUCTIONS', $next_feature_version, $next_feature_announcement_url) : false));
                break;
            case 'settings':
            case 'referral_settings':
                $this->page_title = $mode == 'referral_settings' ? 'ACP_REFERRAL_SETTINGS' : 'ACP_INVITE_SETTINGS';
                $this->tpl_name = $mode == 'referral_settings' ? 'acp_invite_referral' : 'acp_invite';
                $queue_time_m = request_var('queue_time_m', floor($invite->config['queue_time'] / 60));
                $queue_time_s = request_var('queue_time_s', $invite->config['queue_time'] % 60);
                if (!$invite->config['enable_invitation'] && $mode == 'settings') {
                    $error[] = $user->lang['ACP_INVITATION_DISABLED'];
                }
                if (!$invite->config['enable_referral'] && $mode == 'referral_settings') {
                    $error[] = $user->lang['ACP_REFERRAL_DISABLED'];
                }
                if ($submit) {
                    $new_config['queue_time'] = $queue_time_s + $queue_time_m * 60;
                    $check_ary = array('queue_time' => array('num', true, 1, 9999999999), 'message_min_chars' => array('num', true, 1, 9999), 'message_max_chars' => array('num', false, 1, 9999), 'subject_min_chars' => array('num', false, 1, 999), 'subject_max_chars' => array('num', false, 1, 999));
                    $error = validate_data($new_config, $check_ary);
                    if (!check_form_key($form_key)) {
                        $error[] = $user->lang['FORM_INVALID'];
                    }
                    // No errors.. continue!
                    if (!sizeof($error)) {
                        foreach ($new_config as $k => $v) {
                            $invite->set_config($k, $v);
                        }
                        add_log('admin', 'LOG_INVITE_SETTINGS_UPDATED');
                        trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = preg_replace('#^([A-Z_]+)$#e', "(!empty(\$user->lang['\\1'])) ? \$user->lang['\\1'] : '\\1'", $error);
                }
                foreach ($new_config as $k => $v) {
                    $template->assign_vars(array('S_' . strtoupper($k) => $v));
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'S_VALUE_EMAIL' => EMAIL, 'S_VALUE_PM' => PM, 'S_VALUE_OPTIONAL' => OPTIONAL, 'S_GROUP_SELECT' => group_select_options($new_config['key_group'], false, 0), 'S_EMAIL_ENABLE' => $config['email_enable'] ? true : false, 'S_SELECT_LANGUAGE' => $this->build_select('language', '', $new_config['invite_language_select']), 'S_SELECT_PROFILE_LOCATION' => $this->build_select('profile_location'), 'S_SELECT_PROFILE_TYPE' => $this->build_select('profile_type'), 'S_SELECT_REFERRAL_PROFILE_LOCATION' => $this->build_select('referral_profile_location'), 'S_SELECT_REFERRAL_PROFILE_TYPE' => $this->build_select('referral_profile_type'), 'S_PRIORITY_OPTIONS' => $this->build_select('priority', '', $new_config['invite_priority_flag']), 'S_QUEUE_TIME_M' => $queue_time_m, 'S_QUEUE_TIME_S' => $queue_time_s, 'U_ACTION' => $this->u_action));
                if ($invite->ultimate_points_installed()) {
                    $template->assign_vars(array('S_ULTIMATE_POINTS_INSTALLED' => true));
                }
                if ($invite->cash_installed()) {
                    global $cash;
                    $template->assign_vars(array('S_CASH_INSTALLED' => true, 'S_CASH_CURRENCY_INVITE' => $cash->get_currencies($invite->config['cash_id_invite'], true), 'S_CASH_CURRENCY_REGISTER' => $cash->get_currencies($invite->config['cash_id_register'], true)));
                }
                break;
            case 'templates':
                $this->page_title = 'ACP_INVITE_TEMPLATES';
                $this->tpl_name = 'acp_invite_templates';
                $select = isset($_POST['select']) ? true : false;
                $tpl_type = request_var('template_type', '', true);
                $tpl_lang = request_var('template_language', $user->data['user_lang'], true);
                $tpl_subject = $select ? $invite->get_template("{$tpl_type}_subject.txt", $tpl_lang) : '';
                $tpl_message = $select ? $invite->get_template("{$tpl_type}_message.txt", $tpl_lang) : '';
                if ($submit) {
                    $tpl_subject = request_var('template_subject', $invite->get_template("{$tpl_type}_subject.txt", $tpl_lang), true);
                    $tpl_message = request_var('template_message', $invite->get_template("{$tpl_type}_message.txt", $tpl_lang), true);
                    if (!check_form_key($form_key)) {
                        $error[] = $user->lang['FORM_INVALID'];
                    }
                    // No errors.. continue!
                    if (!sizeof($error)) {
                        $invite->set_template($tpl_subject, "{$tpl_type}_subject.txt", $tpl_lang);
                        $invite->set_template($tpl_message, "{$tpl_type}_message.txt", $tpl_lang);
                        add_log('admin', 'LOG_INVITE_TEMPLATES_UPDATED');
                        trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
                    }
                }
                // Output wildcard tables
                $wildcards['general'] = $this->print_wildcard_array($invite, 'general');
                $wildcards['user'] = $this->print_wildcard_array($invite, 'user');
                foreach ($wildcards as $type => $data) {
                    foreach ($data as $wildcard => $example_value) {
                        $template->assign_block_vars($type . '_wildcards', array('WILDCARD' => $wildcard, 'EXAMPLE_VALUE' => $example_value));
                    }
                }
                $template->assign_vars(array('ERROR' => sizeof($error) ? array_pop($error) : '', 'TEMPLATE_SUBJECT' => $tpl_subject, 'TEMPLATE_MESSAGE' => $tpl_message, 'S_EDIT_TEMPLATE' => $select ? true : false, 'S_TEMPLATE_TYPE_SELECT' => $this->build_select('message', $invite->INVITE_MESSAGE_TYPE, $tpl_type), 'S_TEMPLATE_LANGUAGE_SELECT' => language_select($tpl_lang)));
                break;
            case 'log':
                $this->page_title = 'ACP_INVITE_LOG';
                $this->tpl_name = 'acp_invite_log';
                $this->log_type = LOG_INVITE;
                $start = request_var('start', 0);
                $show_info = request_var('info', 0);
                $marked = request_var('mark', array(0));
                $filter = request_var('filter', 'all');
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $entries_per_page = 25;
                // Sort keys
                $sort_days = request_var('st', 0);
                $sort_key = request_var('sk', 't');
                $sort_dir = request_var('sd', 'd');
                $sort_user = request_var('ui', '', true);
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    if (confirm_box(true)) {
                        $where_sql = '';
                        if ($deletemark && sizeof($marked)) {
                            $sql_in = array();
                            foreach ($marked as $mark) {
                                $sql_in[] = $mark;
                            }
                            $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
                            unset($sql_in);
                        }
                        if ($where_sql || $deleteall) {
                            $sql = 'DELETE FROM ' . LOG_TABLE . "\n\t\t\t\t\t\t\t\tWHERE log_type = {$this->log_type}\n\t\t\t\t\t\t\t\t{$where_sql}";
                            $db->sql_query($sql);
                        }
                        add_log('admin', 'LOG_INVITE_LOG_CLEARED');
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => $action)));
                    }
                }
                // Sorting
                $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']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                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);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                $sql_user = $invite->user_return_data($db->sql_escape(utf8_clean_string($sort_user)), 'username_clean', 'user_id');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                view_log('invite', $log_data, $log_count, $entries_per_page, $start, $sql_user, $filter, $sql_user, $sql_where, $sql_sort);
                $u_sort_param .= $sql_user ? "&amp;ui={$sort_user}" : '';
                $log_count = $sql_user ? $log_count : ($sort_user ? 0 : $log_count);
                $template->assign_vars(array('U_ACTION' => $this->u_action, 'S_FILTER' => $this->build_select('filter', '', $filter), 'S_ON_PAGE' => on_page($log_count, $entries_per_page, $start), 'PAGINATION' => generate_pagination($this->u_action . "&amp;{$u_sort_param}", $log_count, $entries_per_page, $start, true), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_SORT_USER' => $sort_user ? $sort_user : '', 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'), 'S_USER_ENTRY' => empty($sort_user) ? true : $sql_user));
                foreach ($log_data as $row) {
                    // Remove info to fix the bug 'Invitation log - Details'
                    $u_sort_param = $show_info ? str_replace("&amp;info={$show_info}", '', $u_sort_param) : $u_sort_param;
                    $data = array();
                    $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'REPORTEE_USERNAME' => $row['reportee_username'] && $row['user_id'] != $row['reportee_id'] ? $row['reportee_username_full'] : '', 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
                }
                break;
        }
    }
예제 #14
0
function mcp_post_details($id, $mode, $action, $url)
{
    global $config, $_CLASS;
    $_CLASS['core_user']->add_lang('posting');
    $_CLASS['core_template']->assign(array('L_POST_DETAILS' => $_CLASS['core_user']->lang['POST_DETAILS'], 'L_POST_SUBJECT' => $_CLASS['core_user']->lang['POST_SUBJECT'], 'L_POSTER' => $_CLASS['core_user']->lang['POSTER'], 'L_READ_PROFILE' => $_CLASS['core_user']->lang['READ_PROFILE'], 'L_READ_USERNOTES' => $_CLASS['core_user']->lang['READ_USERNOTES'], 'L_READ_WARNINGS' => $_CLASS['core_user']->lang['READ_WARNINGS'], 'L_THIS_POST_IP' => $_CLASS['core_user']->lang['THIS_POST_IP'], 'L_POSTED' => $_CLASS['core_user']->lang['POSTED'], 'L_PREVIEW' => $_CLASS['core_user']->lang['PREVIEW'], 'L_APPROVE' => $_CLASS['core_user']->lang['APPROVE'], 'L_DISAPPROVE' => $_CLASS['core_user']->lang['DISAPPROVE'], 'L_REPORTS' => $_CLASS['core_user']->lang['REPORTS'], 'L_ADD_FEEDBACK' => $_CLASS['core_user']->lang['ADD_FEEDBACK'], 'L_FEEDBACK' => $_CLASS['core_user']->lang['FEEDBACK'], 'L_DELETE_MARKED' => $_CLASS['core_user']->lang['DELETE_MARKED'], 'L_DELETE_ALL' => $_CLASS['core_user']->lang['DELETE_ALL'], 'L_REPORTER' => $_CLASS['core_user']->lang['REPORTER'], 'L_MORE_INFO' => $_CLASS['core_user']->lang['MORE_INFO'], 'L_MOD_OPTIONS' => $_CLASS['core_user']->lang['MOD_OPTIONS'], 'L_CHANGE_POSTER' => $_CLASS['core_user']->lang['CHANGE_POSTER'], 'L_CONFIRM' => $_CLASS['core_user']->lang['CONFIRM'], 'L_SEARCH' => $_CLASS['core_user']->lang['SEARCH'], 'L_MOD_OPTIONS' => $_CLASS['core_user']->lang['MOD_OPTIONS'], 'L_UNLOCK_POST' => $_CLASS['core_user']->lang['UNLOCK_POST'], 'L_UNLOCK_POST_EXPLAIN' => $_CLASS['core_user']->lang['UNLOCK_POST_EXPLAIN'], 'L_LOCK_POST' => $_CLASS['core_user']->lang['LOCK_POST'], 'L_LOCK_POST_EXPLAIN' => $_CLASS['core_user']->lang['LOCK_POST_EXPLAIN'], 'L_DELETE_POST' => $_CLASS['core_user']->lang['DELETE_POST'], 'L_SUBMIT' => $_CLASS['core_user']->lang['SUBMIT'], 'L_IP_INFO' => $_CLASS['core_user']->lang['IP_INFO'], 'L_OTHER_USERS' => $_CLASS['core_user']->lang['OTHER_USERS'], 'L_NO_MATCHES_FOUND' => $_CLASS['core_user']->lang['NO_MATCHES_FOUND'], 'L_OTHER_IPS' => $_CLASS['core_user']->lang['OTHER_IPS'], 'L_LOOKUP_ALL' => $_CLASS['core_user']->lang['LOOKUP_ALL'], 'L_JUMP_TO' => $_CLASS['core_user']->lang['JUMP_TO'], 'L_GO' => $_CLASS['core_user']->lang['GO'], 'L_LOOKUP_IP' => $_CLASS['core_user']->lang['LOOKUP_IP']));
    $post_id = request_var('p', 0);
    $start = request_var('start', 0);
    // Get post data
    $post_info = get_post_data(array($post_id));
    if (!sizeof($post_info)) {
        trigger_error($_CLASS['core_user']->lang['POST_NOT_EXIST']);
    }
    $post_info = $post_info[$post_id];
    switch ($action) {
        case 'chgposter_search':
            $username = request_var('username', '');
            if ($username) {
                $users_ary = array();
                if (strpos($username, '*') === false) {
                    $username = "******";
                }
                $username = str_replace('*', '%', str_replace('%', '\\%', $username));
                $sql = 'SELECT user_id, username
					FROM ' . USERS_TABLE . "\r\n\t\t\t\t\tWHERE username LIKE '" . $_CLASS['core_db']->sql_escape($username) . "'\r\n\t\t\t\t\t\tAND user_type NOT IN (" . USER_INACTIVE . ', ' . USER_IGNORE . ')
						AND user_id <> ' . $post_info['user_id'];
                $result = $_CLASS['core_db']->sql_query($sql);
                while ($row = $_CLASS['core_db']->sql_fetchrow($result)) {
                    $users_ary[strtolower($row['username'])] = $row;
                }
                $user_select = '';
                ksort($users_ary);
                foreach ($users_ary as $row) {
                    $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n";
                }
            }
            if (!$user_select) {
                $_CLASS['core_template']->assign('MESSAGE', $_CLASS['core_user']->lang['NO_MATCHES_FOUND']);
            }
            $_CLASS['core_template']->assign(array('S_USER_SELECT' => $user_select, 'SEARCH_USERNAME' => request_var('username', '')));
            break;
        case 'chgposter':
            $new_user = request_var('u', 0);
            if ($new_user && $_CLASS['auth']->acl_get('m_', $post_info['forum_id']) && $new_user != $post_info['user_id']) {
                $sql = 'UPDATE ' . POSTS_TABLE . "\r\n\t\t\t\t\tSET poster_id = {$new_user}\r\n\t\t\t\t\tWHERE post_id = {$post_id}";
                $_CLASS['core_db']->sql_query($sql);
                if ($post_info['topic_last_post_id'] == $post_info['post_id'] || $post_info['forum_last_post_id'] == $post_info['post_id']) {
                    sync('topic', 'topic_id', $post_info['topic_id'], false, false);
                    sync('forum', 'forum_id', $post_info['forum_id'], false, false);
                }
                // Renew post info
                $post_info = get_post_data(array($post_id));
                if (!sizeof($post_info)) {
                    trigger_error($_CLASS['core_user']->lang['POST_NOT_EXIST']);
                }
                $post_info = $post_info[$post_id];
            }
            break;
        case 'del_marked':
        case 'del_all':
        case 'add_feedback':
            $deletemark = $action == 'del_marked' ? true : false;
            $deleteall = $action == 'del_all' ? true : false;
            $marked = request_var('marknote', 0);
            $usernote = request_var('usernote', '');
            if (($deletemark || $deleteall) && $_CLASS['auth']->acl_get('a_clearlogs')) {
                $where_sql = '';
                if ($deletemark && $marked) {
                    $sql_in = array();
                    foreach ($marked as $mark) {
                        $sql_in[] = $mark;
                    }
                    $where_sql = ' AND log_id IN (' . implode(', ', $sql_in) . ')';
                    unset($sql_in);
                }
                $sql = 'DELETE FROM ' . LOG_TABLE . '
					WHERE log_type = ' . LOG_USERS . " \r\n\t\t\t\t\t\t{$where_sql}";
                $_CLASS['core_db']->sql_query($sql);
                add_log('admin', 'LOG_USERS_CLEAR');
                $msg = $deletemark ? 'MARKED_DELETED' : 'ALL_DELETED';
                $redirect = generate_link("{$url}&amp;i={$id}&amp;mode=post_details");
                $_CLASS['core_display']->meta_refresh(2, $redirect);
                trigger_error($_CLASS['core_user']->lang[$msg] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
            }
            if ($usernote && $action == 'add_feedback') {
                add_log('admin', 'LOG_USER_FEEDBACK', $post_info['username']);
                add_log('user', $post_info['user_id'], 'LOG_USER_GENERAL', $usernote);
                $redirect = generate_link("{$url}&amp;i={$id}&amp;mode=post_details");
                $_CLASS['core_display']->meta_refresh(2, $redirect);
                trigger_error($_CLASS['core_user']->lang['USER_FEEDBACK_ADDED'] . '<br /><br />' . sprintf($_CLASS['core_user']->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
            }
            break;
        default:
    }
    // Set some vars
    $users_ary = array();
    $poster = $post_info['user_colour'] ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
    // Process message, leave it uncensored
    $message = $post_info['post_text'];
    if ($post_info['bbcode_bitfield']) {
        global $site_file_root;
        require_once $site_file_root . 'includes/forums/bbcode.php';
        $bbcode = new bbcode($post_info['bbcode_bitfield']);
        $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
    }
    $message = smiley_text($message);
    $_CLASS['core_template']->assign(array('U_MCP_ACTION' => generate_link($url . '&amp;i=main&amp;quickmod=1'), 'U_POST_ACTION' => generate_link("{$url}&amp;i={$id}&amp;mode=post_details"), 'U_APPROVE_ACTION' => generate_link('Forums&amp;file=mcp&amp;i=queue&amp;p=' . $post_id), 'S_CAN_VIEWIP' => $_CLASS['auth']->acl_get('m_ip', $post_info['forum_id']), 'S_CAN_CHGPOSTER' => $_CLASS['auth']->acl_get('m_', $post_info['forum_id']), 'S_CAN_LOCK_POST' => $_CLASS['auth']->acl_get('m_lock', $post_info['forum_id']), 'S_CAN_DELETE_POST' => $_CLASS['auth']->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], 'S_POST_UNAPPROVED' => !$post_info['post_approved'], 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_WARNINGS' => $post_info['user_warnings'] ? true : false, 'S_SHOW_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => $_CLASS['auth']->acl_get('a_clearlogs') ? true : false, 'U_VIEW_PROFILE' => generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $post_info['user_id']), 'U_EDIT' => $_CLASS['auth']->acl_get('m_edit', $post_info['forum_id']) ? generate_link("Forums&amp;file=posting&amp;mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '', 'RETURN_TOPIC' => sprintf($_CLASS['core_user']->lang['RETURN_TOPIC'], '<a href="' . generate_link("Forums&amp;file=viewtopic&amp;p={$post_id}#{$post_id}") . '">', '</a>'), 'RETURN_FORUM' => sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link("Forums&amp;file=viewforum&amp;f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'), 'REPORTED_IMG' => $_CLASS['core_user']->img('icon_reported', $_CLASS['core_user']->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $_CLASS['core_user']->img('icon_unapproved', $_CLASS['core_user']->lang['POST_UNAPPROVED']), 'EDIT_IMG' => $_CLASS['core_user']->img('btn_edit', $_CLASS['core_user']->lang['EDIT_POST']), 'POSTER_NAME' => $poster, 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $_CLASS['core_user']->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip']), 'POST_ID' => $post_info['post_id']));
    // Get User Notes
    $log_data = array();
    $log_count = 0;
    view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
    if ($log_count) {
        $_CLASS['core_template']->assign('S_USER_NOTES', true);
        foreach ($log_data as $row) {
            $_CLASS['core_template']->assign_vars_array('usernotes', array('REPORT_BY' => $row['username'], 'REPORT_AT' => $_CLASS['core_user']->format_date($row['time']), 'ACTION' => $row['action'], 'ID' => $row['id']));
        }
    }
    // Get Reports
    if ($_CLASS['auth']->acl_get('m_', $post_info['forum_id'])) {
        $sql = 'SELECT r.*, re.*, u.user_id, u.username 
			FROM ' . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u, ' . REASONS_TABLE . " re\r\n\t\t\tWHERE r.post_id = {$post_id}\r\n\t\t\t\tAND r.reason_id = re.reason_id\r\n\t\t\t\tAND u.user_id = r.user_id\r\n\t\t\tORDER BY r.report_time DESC";
        $result = $_CLASS['core_db']->sql_query($sql);
        if ($row = $_CLASS['core_db']->sql_fetchrow($result)) {
            $_CLASS['core_template']->assign('S_SHOW_REPORTS', true);
            do {
                $_CLASS['core_template']->assign_vars_array('reports', array('REPORT_ID' => $row['report_id'], 'REASON_TITLE' => $_CLASS['core_user']->lang['report_reasons']['TITLE'][strtoupper($row['reason_name'])], 'REASON_DESC' => $_CLASS['core_user']->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_name'])], 'REPORTER' => $row['user_id'] != ANONYMOUS ? $row['username'] : $_CLASS['core_user']->lang['GUEST'], 'U_REPORTER' => $row['user_id'] != ANONYMOUS ? generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $row['user_id']) : '', 'USER_NOTIFY' => $row['user_notify'] ? true : false, 'REPORT_TIME' => $_CLASS['core_user']->format_date($row['report_time']), 'REPORT_TEXT' => str_replace("\n", '<br />', trim($row['report_text']))));
            } while ($row = $_CLASS['core_db']->sql_fetchrow($result));
        }
        $_CLASS['core_db']->sql_freeresult($result);
    }
    // Get IP
    if ($_CLASS['auth']->acl_get('m_ip', $post_info['forum_id'])) {
        $rdns_ip_num = request_var('rdns', '');
        if ($rdns_ip_num != 'all') {
            $_CLASS['core_template']->assign(array('U_LOOKUP_ALL' => generate_link($url . '&amp;i=main&amp;mode=post_details&amp;rdns=all')));
        }
        // Get other users who've posted under this IP
        $sql = 'SELECT u.user_id, u.username, COUNT(*) as postings
			FROM ' . USERS_TABLE . ' u, ' . POSTS_TABLE . " p\r\n\t\t\tWHERE p.poster_id = u.user_id\r\n\t\t\t\tAND p.poster_ip = '{$post_info['poster_ip']}'\r\n\t\t\t\tAND p.poster_id <> {$post_info['user_id']}\r\n\t\t\tGROUP BY u.user_id\r\n\t\t\tORDER BY postings DESC";
        $result = $_CLASS['core_db']->sql_query($sql);
        while ($row = $_CLASS['core_db']->sql_fetchrow($result)) {
            // Fill the user select list with users who have posted
            // under this IP
            if ($row['user_id'] != $post_info['poster_id']) {
                $users_ary[strtolower($row['username'])] = $row;
            }
            $_CLASS['core_template']->assign_vars_array('userrow', array('USERNAME' => $row['user_id'] == ANONYMOUS ? $_CLASS['core_user']->lang['GUEST'] : $row['username'], 'NUM_POSTS' => $row['postings'], 'L_POST_S' => $row['postings'] == 1 ? $_CLASS['core_user']->lang['POST'] : $_CLASS['core_user']->lang['POSTS'], 'U_PROFILE' => $row['user_id'] == ANONYMOUS ? '' : generate_link('Members_List&amp;mode=viewprofile&amp;u=' . $row['user_id']), 'U_SEARCHPOSTS' => generate_link('Forums&amp;file=search&amp;search_author=' . urlencode($row['username']) . '&amp;showresults=topics')));
        }
        $_CLASS['core_db']->sql_freeresult($result);
        // Get other IP's this user has posted under
        $sql = 'SELECT poster_ip, COUNT(*) AS postings
			FROM ' . POSTS_TABLE . '
			WHERE poster_id = ' . $post_info['poster_id'] . '
			GROUP BY poster_ip
			ORDER BY postings DESC';
        $result = $_CLASS['core_db']->sql_query($sql);
        while ($row = $_CLASS['core_db']->sql_fetchrow($result)) {
            $hostname = ($rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all') && $row['poster_ip'] ? @gethostbyaddr($row['poster_ip']) : '';
            $_CLASS['core_template']->assign_vars_array('iprow', array('IP' => $row['poster_ip'], 'HOSTNAME' => $hostname, 'NUM_POSTS' => $row['postings'], 'L_POST_S' => $row['postings'] == 1 ? $_CLASS['core_user']->lang['POST'] : $_CLASS['core_user']->lang['POSTS'], 'U_LOOKUP_IP' => $rdns_ip_num == $row['poster_ip'] || $rdns_ip_num == 'all' ? '' : generate_link("{$url}&amp;i={$id}&amp;mode=post_details&amp;rdns={$row['poster_ip']}#ip"), 'U_WHOIS' => generate_link("Forums&amp;file=mcp&amp;i={$id}&amp;mode=whois&amp;ip={$row['poster_ip']}")));
        }
        $_CLASS['core_db']->sql_freeresult($result);
        // If we were not searching for a specific username fill
        // the user_select box with users who have posted under
        // the same IP
        if ($action != 'chgposter_search') {
            $user_select = '';
            ksort($users_ary);
            foreach ($users_ary as $row) {
                $user_select .= '<option value="' . $row['user_id'] . '">' . $row['username'] . "</option>\n";
            }
            $_CLASS['core_template']->assign('S_USER_SELECT', $user_select);
        }
    }
}
예제 #15
0
    function main($id, $mode)
    {
        global $auth, $db, $user, $template;
        global $config, $phpbb_root_path, $phpEx;
        $user->add_lang('acp/common');
        $action = request_var('action', array('' => ''));
        if (is_array($action)) {
            list($action, ) = each($action);
        } else {
            $action = request_var('action', '');
        }
        // Set up general vars
        $start = request_var('start', 0);
        $deletemark = isset($_POST['del_marked']) ? true : false;
        $deleteall = isset($_POST['del_all']) ? true : false;
        $marked = request_var('mark', array(0));
        // Sort keys
        $sort_days = request_var('st', 0);
        $sort_key = request_var('sk', 't');
        $sort_dir = request_var('sd', 'd');
        $this->tpl_name = 'mcp_logs';
        $this->page_title = 'MCP_LOGS';
        $forum_id = $topic_id = 0;
        switch ($mode) {
            case 'front':
                $where_sql = '';
                break;
            case 'forum_logs':
                $forum_id = request_var('f', 0);
                $where_sql = " AND forum_id = {$forum_id}";
                break;
            case 'topic_logs':
                $topic_id = request_var('t', 0);
                $where_sql = " AND topic_id = {$topic_id}";
                break;
        }
        // Delete entries if requested and able
        if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
            if ($deletemark && $marked) {
                $sql_in = array();
                foreach ($marked as $mark) {
                    $sql_in[] = $mark;
                }
                $where_sql = ' AND log_id IN (' . implode(', ', $sql_in) . ')';
                unset($sql_in);
            }
            if ($where_sql || $deleteall) {
                $sql = 'DELETE FROM ' . LOG_TABLE . '
					WHERE log_type = ' . LOD_MOD . "\n\t\t\t\t\t{$where_sql}";
                $db->sql_query($sql);
                add_log('admin', 'LOG_CLEAR_MOD');
            }
        }
        // Sorting
        $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']);
        $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
        $sort_by_sql = array('u' => 'l.user_id', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        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);
        // Define where and sort sql for use in displaying logs
        $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
        $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        // Grab log data
        $log_data = array();
        $log_count = 0;
        view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, $topic_id, 0, $sql_where, $sql_sort);
        $template->assign_vars(array('PAGE_NUMBER' => on_page($log_count, $config['topics_per_page'], $start), 'TOTAL' => $log_count == 1 ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count), 'PAGINATION' => generate_pagination($this->u_action . "&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start), 'U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_LOGS' => $log_count > 0));
        foreach ($log_data as $row) {
            $data = array();
            $checks = array('viewtopic', 'viewforum');
            foreach ($checks as $check) {
                if (isset($row[$check]) && $row[$check]) {
                    $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
                }
            }
            $template->assign_block_vars('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
        }
    }
예제 #16
0
    /**
     * Display user notes
     */
    function mcp_notes_user_view($action)
    {
        global $phpEx, $src_root_path, $config;
        global $template, $db, $user, $auth, $src_container;
        $user_id = request_var('u', 0);
        $username = request_var('username', '', true);
        $start = request_var('start', 0);
        $st = request_var('st', 0);
        $sk = request_var('sk', 'b');
        $sd = request_var('sd', 'd');
        $pagination = $src_container->get('pagination');
        add_form_key('mcp_notes');
        $sql_where = $user_id ? "user_id = {$user_id}" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
        $sql = 'SELECT *
			FROM ' . USERS_TABLE . "\n\t\t\tWHERE {$sql_where}";
        $result = $db->sql_query($sql);
        $userrow = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$userrow) {
            trigger_error('NO_USER');
        }
        $user_id = $userrow['user_id'];
        // Populate user id to the currently active module (this module)
        // The following method is another way of adjusting module urls. It is the easy variant if we want
        // to directly adjust the current module url based on data retrieved within the same module.
        if (strpos($this->u_action, "&amp;u={$user_id}") === false) {
            $this->p_master->adjust_url('&amp;u=' . $user_id);
            $this->u_action .= "&amp;u={$user_id}";
        }
        $deletemark = $action == 'del_marked' ? true : false;
        $deleteall = $action == 'del_all' ? true : false;
        $marked = request_var('marknote', array(0));
        $usernote = utf8_normalize_nfc(request_var('usernote', '', true));
        // Handle any actions
        if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
            $where_sql = '';
            if ($deletemark && $marked) {
                $sql_in = array();
                foreach ($marked as $mark) {
                    $sql_in[] = $mark;
                }
                $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
                unset($sql_in);
            }
            if ($where_sql || $deleteall) {
                if (check_form_key('mcp_notes')) {
                    $sql = 'DELETE FROM ' . LOG_TABLE . '
						WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\tAND reportee_id = {$user_id}\n\t\t\t\t\t\t\t{$where_sql}";
                    $db->sql_query($sql);
                    add_log('admin', 'LOG_CLEAR_USER', $userrow['username']);
                    $msg = $deletemark ? 'MARKED_NOTES_DELETED' : 'ALL_NOTES_DELETED';
                } else {
                    $msg = 'FORM_INVALID';
                }
                $redirect = $this->u_action . '&amp;u=' . $user_id;
                meta_refresh(3, $redirect);
                trigger_error($user->lang[$msg] . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
            }
        }
        if ($usernote && $action == 'add_feedback') {
            if (check_form_key('mcp_notes')) {
                add_log('admin', 'LOG_USER_FEEDBACK', $userrow['username']);
                add_log('mod', 0, 0, 'LOG_USER_FEEDBACK', $userrow['username']);
                add_log('user', $user_id, 'LOG_USER_GENERAL', $usernote);
                $msg = $user->lang['USER_FEEDBACK_ADDED'];
            } else {
                $msg = $user->lang['FORM_INVALID'];
            }
            $redirect = $this->u_action;
            meta_refresh(3, $redirect);
            trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
        }
        // Generate the appropriate user information for the user we are looking at
        $rank_title = $rank_img = '';
        $avatar_img = src_get_user_avatar($userrow);
        $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']);
        $sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']);
        $sort_by_sql = array('a' => 'u.username_clean', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation');
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
        // Define where and sort sql for use in displaying logs
        $sql_where = $st ? time() - $st * 86400 : 0;
        $sql_sort = $sort_by_sql[$sk] . ' ' . ($sd == 'd' ? 'DESC' : 'ASC');
        $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
        $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
        $log_data = array();
        $log_count = 0;
        $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort, $keywords);
        if ($log_count) {
            $template->assign_var('S_USER_NOTES', true);
            foreach ($log_data as $row) {
                $template->assign_block_vars('usernotes', array('REPORT_BY' => $row['username_full'], 'REPORT_AT' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'IP' => $row['ip'], 'ID' => $row['id']));
            }
        }
        $base_url = $this->u_action . "&amp;{$u_sort_param}{$keywords_param}";
        $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
        $template->assign_vars(array('U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_KEYWORDS' => $keywords, 'L_TITLE' => $user->lang['MCP_NOTES_USER'], 'TOTAL_REPORTS' => $user->lang('LIST_REPORTS', (int) $log_count), 'RANK_TITLE' => $rank_title, 'JOINED' => $user->format_date($userrow['user_regdate']), 'POSTS' => $userrow['user_posts'] ? $userrow['user_posts'] : 0, 'WARNINGS' => $userrow['user_warnings'] ? $userrow['user_warnings'] : 0, 'USERNAME_FULL' => get_username_string('full', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), 'USERNAME_COLOUR' => get_username_string('colour', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), 'USERNAME' => get_username_string('username', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), 'U_PROFILE' => get_username_string('profile', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), 'AVATAR_IMG' => $avatar_img, 'RANK_IMG' => $rank_img));
    }
예제 #17
0
파일: mcp_front.php 프로젝트: jvinhit/php
/**
* MCP Front Panel
*/
function mcp_front_view($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth, $module;
    // Latest 5 unapproved
    if ($module->loaded('queue')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
        $post_list = array();
        $forum_names = array();
        $forum_id = request_var('f', 0);
        $template->assign_var('S_SHOW_UNAPPROVED', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(post_id) AS total
				FROM ' . POSTS_TABLE . '
				WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
					AND post_approved = 0';
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $global_id = $forum_list[0];
                $sql = 'SELECT forum_id, forum_name
					FROM ' . FORUMS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list);
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $forum_names[$row['forum_id']] = $row['forum_name'];
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE forum_id IN (0, ' . implode(', ', $forum_list) . ')
						AND post_approved = 0
					ORDER BY post_time DESC';
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $post_list[] = $row['post_id'];
                }
                $db->sql_freeresult($result);
                if (empty($post_list)) {
                    $total = 0;
                }
            }
            if ($total) {
                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
					WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
						AND t.topic_id = p.topic_id
						AND p.poster_id = u.user_id
					ORDER BY p.post_time DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $global_topic = $row['forum_id'] ? false : true;
                    if ($global_topic) {
                        $row['forum_id'] = $global_id;
                    }
                    $template->assign_block_vars('unapproved', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']), 'U_MCP_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']) : '', 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=topic_view&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'U_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']) : '', 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']), 'U_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']), 'FORUM_NAME' => !$global_topic ? $forum_names[$row['forum_id']] : $user->lang['GLOBAL_ANNOUNCEMENT'], 'POST_ID' => $row['post_id'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_TIME' => $user->format_date($row['post_time'])));
                }
                $db->sql_freeresult($result);
            }
            $template->assign_vars(array('S_MCP_QUEUE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue")));
            if ($total == 0) {
                $template->assign_vars(array('L_UNAPPROVED_TOTAL' => $user->lang['UNAPPROVED_POSTS_ZERO_TOTAL'], 'S_HAS_UNAPPROVED_POSTS' => false));
            } else {
                $template->assign_vars(array('L_UNAPPROVED_TOTAL' => $total == 1 ? $user->lang['UNAPPROVED_POST_TOTAL'] : sprintf($user->lang['UNAPPROVED_POSTS_TOTAL'], $total), 'S_HAS_UNAPPROVED_POSTS' => true));
            }
        }
    }
    // Latest 5 reported
    if ($module->loaded('reports')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
        $template->assign_var('S_SHOW_REPORTS', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(r.report_id) AS total
				FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
				WHERE r.post_id = p.post_id
					AND r.report_closed = 0
					AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')';
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $global_id = $forum_list[0];
                $sql = $db->sql_build_query('SELECT', array('SELECT' => 'r.report_time, p.post_id, p.post_subject, p.post_time, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', TOPICS_TABLE => 't', USERS_TABLE => array('u', 'u2'), POSTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = p.forum_id')), 'WHERE' => 'r.post_id = p.post_id
						AND r.report_closed = 0
						AND r.reason_id = rr.reason_id
						AND p.topic_id = t.topic_id
						AND r.user_id = u.user_id
						AND p.poster_id = u2.user_id
						AND p.forum_id IN (0, ' . implode(', ', $forum_list) . ')', 'ORDER_BY' => 'p.post_time DESC'));
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $global_topic = $row['forum_id'] ? false : true;
                    if ($global_topic) {
                        $row['forum_id'] = $global_id;
                    }
                    $template->assign_block_vars('report', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"), 'U_MCP_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . "&amp;i={$id}&amp;mode=forum_view") : '', 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . "&amp;i={$id}&amp;mode=topic_view"), 'U_FORUM' => !$global_topic ? append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']) : '', 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'FORUM_NAME' => !$global_topic ? $row['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'POST_TIME' => $user->format_date($row['post_time'])));
                }
            }
            if ($total == 0) {
                $template->assign_vars(array('L_REPORTS_TOTAL' => $user->lang['REPORTS_ZERO_TOTAL'], 'S_HAS_REPORTS' => false));
            } else {
                $template->assign_vars(array('L_REPORTS_TOTAL' => $total == 1 ? $user->lang['REPORT_TOTAL'] : sprintf($user->lang['REPORTS_TOTAL'], $total), 'S_HAS_REPORTS' => true));
            }
        }
    }
    // Latest 5 logs
    if ($module->loaded('logs')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        if (!empty($forum_list)) {
            // Add forum_id 0 for global announcements
            $forum_list[] = 0;
            $log_count = 0;
            $log = array();
            view_log('mod', $log, $log_count, 5, 0, $forum_list);
            foreach ($log as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'TIME' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'U_VIEW_TOPIC' => !empty($row['viewtopic']) ? $row['viewtopic'] : '', 'U_VIEWLOGS' => !empty($row['viewlogs']) ? $row['viewlogs'] : ''));
            }
        }
        $template->assign_vars(array('S_SHOW_LOGS' => !empty($forum_list) ? true : false, 'S_HAS_LOGS' => !empty($log) ? true : false));
    }
    $template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.{$phpEx}"));
    make_jumpbox(append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view'), 0, false, 'm_', true);
}
예제 #18
0
파일: mcp_logs.php 프로젝트: phpbb/phpbb
    function main($id, $mode)
    {
        global $auth, $db, $user, $template, $request;
        global $config, $phpbb_container, $phpbb_log;
        $user->add_lang('acp/common');
        $action = $request->variable('action', array('' => ''));
        if (is_array($action)) {
            list($action, ) = each($action);
        } else {
            $action = $request->variable('action', '');
        }
        // Set up general vars
        $start = $request->variable('start', 0);
        $deletemark = $action == 'del_marked' ? true : false;
        $deleteall = $action == 'del_all' ? true : false;
        $marked = $request->variable('mark', array(0));
        // Sort keys
        $sort_days = $request->variable('st', 0);
        $sort_key = $request->variable('sk', 't');
        $sort_dir = $request->variable('sd', 'd');
        $this->tpl_name = 'mcp_logs';
        $this->page_title = 'MCP_LOGS';
        /* @var $pagination \phpbb\pagination */
        $pagination = $phpbb_container->get('pagination');
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        $forum_list[] = 0;
        $forum_id = $topic_id = 0;
        switch ($mode) {
            case 'front':
                break;
            case 'forum_logs':
                $forum_id = $request->variable('f', 0);
                if (!in_array($forum_id, $forum_list)) {
                    send_status_line(403, 'Forbidden');
                    trigger_error('NOT_AUTHORISED');
                }
                $forum_list = array($forum_id);
                break;
            case 'topic_logs':
                $topic_id = $request->variable('t', 0);
                $sql = 'SELECT forum_id
					FROM ' . TOPICS_TABLE . '
					WHERE topic_id = ' . $topic_id;
                $result = $db->sql_query($sql);
                $forum_id = (int) $db->sql_fetchfield('forum_id');
                $db->sql_freeresult($result);
                if (!in_array($forum_id, $forum_list)) {
                    send_status_line(403, 'Forbidden');
                    trigger_error('NOT_AUTHORISED');
                }
                $forum_list = array($forum_id);
                break;
        }
        // Delete entries if requested and able
        if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
            if (confirm_box(true)) {
                if ($deletemark && sizeof($marked)) {
                    $conditions = array('forum_id' => array('IN' => $forum_list), 'log_id' => array('IN' => $marked));
                    $phpbb_log->delete('mod', $conditions);
                } else {
                    if ($deleteall) {
                        $keywords = $request->variable('keywords', '', true);
                        $conditions = array('forum_id' => array('IN' => $forum_list), 'keywords' => $keywords);
                        if ($sort_days) {
                            $conditions['log_time'] = array('>=', time() - $sort_days * 86400);
                        }
                        if ($mode == 'topic_logs') {
                            $conditions['topic_id'] = $topic_id;
                        }
                        $phpbb_log->delete('mod', $conditions);
                    }
                }
            } else {
                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('f' => $forum_id, 't' => $topic_id, 'start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => $request->variable('action', array('' => '')))));
            }
        }
        // Sorting
        $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']);
        $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
        $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        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);
        // Define where and sort sql for use in displaying logs
        $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
        $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        $keywords = $request->variable('keywords', '', true);
        $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
        // Grab log data
        $log_data = array();
        $log_count = 0;
        $start = view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort, $keywords);
        $base_url = $this->u_action . "&amp;{$u_sort_param}{$keywords_param}";
        $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
        $template->assign_vars(array('TOTAL' => $user->lang('TOTAL_LOGS', (int) $log_count), 'L_TITLE' => $user->lang['MCP_LOGS'], 'U_POST_ACTION' => $this->u_action . "&amp;{$u_sort_param}{$keywords_param}&amp;start={$start}", 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_LOGS' => $log_count > 0, 'S_KEYWORDS' => $keywords));
        foreach ($log_data as $row) {
            $data = array();
            $checks = array('viewpost', 'viewtopic', 'viewforum');
            foreach ($checks as $check) {
                if (isset($row[$check]) && $row[$check]) {
                    $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
                }
            }
            $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
        }
    }
예제 #19
0
    function main($id, $mode)
    {
        global $auth, $db, $user, $template;
        global $config, $phpbb_root_path, $phpEx;
        $user->add_lang('acp/common');
        //-- mod start : Garage ----------------------------------------------------------------------------------------------------
        //-- add
        $user->add_lang('acp/garage');
        //-- mod finish : Garage ---------------------------------------------------------------------------------------------------
        $action = request_var('action', array('' => ''));
        if (is_array($action)) {
            list($action, ) = each($action);
        } else {
            $action = request_var('action', '');
        }
        // Set up general vars
        $start = request_var('start', 0);
        $deletemark = $action == 'del_marked' ? true : false;
        $deleteall = $action == 'del_all' ? true : false;
        $marked = request_var('mark', array(0));
        // Sort keys
        $sort_days = request_var('st', 0);
        $sort_key = request_var('sk', 't');
        $sort_dir = request_var('sd', 'd');
        $this->tpl_name = 'mcp_logs';
        $this->page_title = 'MCP_LOGS';
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        $forum_list[] = 0;
        $forum_id = $topic_id = 0;
        switch ($mode) {
            case 'front':
                break;
            case 'forum_logs':
                $forum_id = request_var('f', 0);
                if (!in_array($forum_id, $forum_list)) {
                    trigger_error('NOT_AUTHORISED');
                }
                $forum_list = array($forum_id);
                break;
            case 'topic_logs':
                $topic_id = request_var('t', 0);
                $sql = 'SELECT forum_id
					FROM ' . TOPICS_TABLE . '
					WHERE topic_id = ' . $topic_id;
                $result = $db->sql_query($sql);
                $forum_id = (int) $db->sql_fetchfield('forum_id');
                $db->sql_freeresult($result);
                if (!in_array($forum_id, $forum_list)) {
                    trigger_error('NOT_AUTHORISED');
                }
                $forum_list = array($forum_id);
                break;
        }
        // Delete entries if requested and able
        if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
            if (confirm_box(true)) {
                if ($deletemark && sizeof($marked)) {
                    $sql = 'DELETE FROM ' . LOG_TABLE . '
						WHERE log_type = ' . LOG_MOD . '
							AND ' . $db->sql_in_set('forum_id', $forum_list) . '
							AND ' . $db->sql_in_set('log_id', $marked);
                    $db->sql_query($sql);
                    add_log('admin', 'LOG_CLEAR_MOD');
                } else {
                    if ($deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
						WHERE log_type = ' . LOG_MOD . '
							AND ' . $db->sql_in_set('forum_id', $forum_list);
                        if ($mode == 'topic_logs') {
                            $sql .= ' AND topic_id = ' . $topic_id;
                        }
                        $db->sql_query($sql);
                        add_log('admin', 'LOG_CLEAR_MOD');
                    }
                }
            } else {
                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('f' => $forum_id, 't' => $topic_id, 'start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => request_var('action', array('' => '')))));
            }
        }
        // Sorting
        $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']);
        $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
        $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
        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);
        // Define where and sort sql for use in displaying logs
        $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
        $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
        // Grab log data
        $log_data = array();
        $log_count = 0;
        view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort);
        $template->assign_vars(array('PAGE_NUMBER' => on_page($log_count, $config['topics_per_page'], $start), 'TOTAL' => $log_count == 1 ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count), 'PAGINATION' => generate_pagination($this->u_action . "&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start), 'L_TITLE' => $user->lang['MCP_LOGS'], 'U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs') ? true : false, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_LOGS' => $log_count > 0));
        foreach ($log_data as $row) {
            $data = array();
            $checks = array('viewtopic', 'viewforum');
            foreach ($checks as $check) {
                if (isset($row[$check]) && $row[$check]) {
                    $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
                }
            }
            $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
        }
    }
 function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache, $phpbb_container;
     global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
     global $request;
     $user->add_lang('mcp');
     // Set up general vars
     $action = request_var('action', '');
     $forum_id = request_var('f', 0);
     $topic_id = request_var('t', 0);
     $start = request_var('start', 0);
     $deletemark = $request->variable('delmarked', false, false, \phpbb\request\request_interface::POST);
     $deleteall = $request->variable('delall', false, false, \phpbb\request\request_interface::POST);
     $marked = request_var('mark', array(0));
     // Sort keys
     $sort_days = request_var('st', 0);
     $sort_key = request_var('sk', 't');
     $sort_dir = request_var('sd', 'd');
     $this->tpl_name = 'acp_logs';
     $this->log_type = constant('LOG_' . strtoupper($mode));
     $pagination = $phpbb_container->get('pagination');
     // Delete entries if requested and able
     if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
         if (confirm_box(true)) {
             $conditions = array();
             if ($deletemark && sizeof($marked)) {
                 $conditions['log_id'] = array('IN' => $marked);
             }
             if ($deleteall) {
                 if ($sort_days) {
                     $conditions['log_time'] = array('>=', time() - $sort_days * 86400);
                 }
                 $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
                 $conditions['keywords'] = $keywords;
             }
             $phpbb_log = $phpbb_container->get('log');
             $phpbb_log->delete($mode, $conditions);
         } else {
             confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('f' => $forum_id, 'start' => $start, 'delmarked' => $deletemark, 'delall' => $deleteall, 'mark' => $marked, 'st' => $sort_days, 'sk' => $sort_key, 'sd' => $sort_dir, 'i' => $id, 'mode' => $mode, 'action' => $action)));
         }
     }
     // Sorting
     $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']);
     $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
     $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
     $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
     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);
     // Define where and sort sql for use in displaying logs
     $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
     $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
     $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
     $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
     $l_title = $user->lang['ACP_' . strtoupper($mode) . '_LOGS'];
     $l_title_explain = $user->lang['ACP_' . strtoupper($mode) . '_LOGS_EXPLAIN'];
     $this->page_title = $l_title;
     // Define forum list if we're looking @ mod logs
     if ($mode == 'mod') {
         $forum_box = '<option value="0">' . $user->lang['ALL_FORUMS'] . '</option>' . make_forum_select($forum_id);
         $template->assign_vars(array('S_SHOW_FORUMS' => true, 'S_FORUM_BOX' => $forum_box));
     }
     // Grab log data
     $log_data = array();
     $log_count = 0;
     $start = view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort, $keywords);
     $base_url = $this->u_action . "&amp;{$u_sort_param}{$keywords_param}";
     $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
     $template->assign_vars(array('L_TITLE' => $l_title, 'L_EXPLAIN' => $l_title_explain, 'U_ACTION' => $this->u_action . "&amp;{$u_sort_param}{$keywords_param}&amp;start={$start}", 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'), 'S_KEYWORDS' => $keywords));
     foreach ($log_data as $row) {
         $data = array();
         $checks = array('viewtopic', 'viewlogs', 'viewforum');
         foreach ($checks as $check) {
             if (isset($row[$check]) && $row[$check]) {
                 $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
             }
         }
         $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'REPORTEE_USERNAME' => $row['reportee_username'] && $row['user_id'] != $row['reportee_id'] ? $row['reportee_username_full'] : '', 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($data) ? implode(' | ', $data) : '', 'ID' => $row['id']));
     }
 }
예제 #21
0
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        // Show restore permissions notice
        if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) {
            $this->tpl_name = 'acp_main';
            $this->page_title = 'ACP_MAIN';
            $sql = 'SELECT user_id, username, user_colour
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $user->data['user_perm_from'];
            $result = $db->sql_query($sql);
            $user_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $perm_from = '<strong' . ($user_row['user_colour'] ? ' style="color: #' . $user_row['user_colour'] . '">' : '>');
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $user_row['user_id']) . '">' : '';
            $perm_from .= $user_row['username'];
            $perm_from .= $user_row['user_id'] != ANONYMOUS ? '</a>' : '';
            $perm_from .= '</strong>';
            $template->assign_vars(array('S_RESTORE_PERMISSIONS' => true, 'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'), 'PERM_FROM' => $perm_from, 'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'))));
            return;
        }
        $action = request_var('action', '');
        if ($action) {
            if ($action === 'admlogout') {
                $user->unset_admin();
                $redirect_url = append_sid("{$phpbb_root_path}index.{$phpEx}");
                meta_refresh(3, $redirect_url);
                trigger_error($user->lang['ADM_LOGGED_OUT'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect_url . '">', '</a>'));
            }
            if (!confirm_box(true)) {
                switch ($action) {
                    case 'online':
                        $confirm = true;
                        $confirm_lang = 'RESET_ONLINE_CONFIRM';
                        break;
                    case 'stats':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_STATS_CONFIRM';
                        break;
                    case 'user':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
                        break;
                    case 'date':
                        $confirm = true;
                        $confirm_lang = 'RESET_DATE_CONFIRM';
                        break;
                    case 'db_track':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
                        break;
                    case 'purge_cache':
                        $confirm = true;
                        $confirm_lang = 'PURGE_CACHE_CONFIRM';
                        break;
                    default:
                        $confirm = true;
                        $confirm_lang = 'CONFIRM_OPERATION';
                }
                if ($confirm) {
                    confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                }
            } else {
                switch ($action) {
                    case 'online':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        set_config('record_online_users', 1, true);
                        set_config('record_online_date', time(), true);
                        add_log('admin', 'LOG_RESET_ONLINE');
                        break;
                    case 'stats':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT COUNT(post_id) AS stat
							FROM ' . POSTS_TABLE . '
							WHERE post_approved = 1';
                        $result = $db->sql_query($sql);
                        set_config('num_posts', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(topic_id) AS stat
							FROM ' . TOPICS_TABLE . '
							WHERE topic_approved = 1';
                        $result = $db->sql_query($sql);
                        set_config('num_topics', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(user_id) AS stat
							FROM ' . USERS_TABLE . '
							WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
                        $result = $db->sql_query($sql);
                        set_config('num_users', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(attach_id) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        set_config('num_files', (int) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT SUM(filesize) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        set_config('upload_dir_size', (double) $db->sql_fetchfield('stat'), true);
                        $db->sql_freeresult($result);
                        if (!function_exists('update_last_username')) {
                            include $phpbb_root_path . "includes/functions_user.{$phpEx}";
                        }
                        update_last_username();
                        add_log('admin', 'LOG_RESYNC_STATS');
                        break;
                    case 'user':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        // Resync post counts
                        $start = $max_post_id = 0;
                        // Find the maximum post ID, we can only stop the cycle when we've reached it
                        $sql = 'SELECT MAX(forum_last_post_id) as max_post_id
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                        $db->sql_freeresult($result);
                        // No maximum post id? :o
                        if (!$max_post_id) {
                            $sql = 'SELECT MAX(post_id)
								FROM ' . POSTS_TABLE;
                            $result = $db->sql_query($sql);
                            $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                            $db->sql_freeresult($result);
                        }
                        // Still no maximum post id? Then we are finished
                        if (!$max_post_id) {
                            add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
                            break;
                        }
                        $step = $config['num_posts'] ? max((int) ($config['num_posts'] / 5), 20000) : 20000;
                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
                        while ($start < $max_post_id) {
                            $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
								FROM ' . POSTS_TABLE . '
								WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
									AND post_postcount = 1 AND post_approved = 1
								GROUP BY poster_id';
                            $result = $db->sql_query($sql);
                            if ($row = $db->sql_fetchrow($result)) {
                                do {
                                    $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
                                    $db->sql_query($sql);
                                } while ($row = $db->sql_fetchrow($result));
                            }
                            $db->sql_freeresult($result);
                            $start += $step;
                        }
                        add_log('admin', 'LOG_RESYNC_POSTCOUNTS');
                        break;
                    case 'date':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        set_config('board_startdate', time() - 1);
                        add_log('admin', 'LOG_RESET_DATE');
                        break;
                    case 'db_track':
                        switch ($db->sql_layer) {
                            case 'sqlite':
                            case 'firebird':
                                $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
                                break;
                            default:
                                $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
                                break;
                        }
                        // This can get really nasty... therefore we only do the last six months
                        $get_from_time = time() - 6 * 4 * 7 * 24 * 60 * 60;
                        // Select forum ids, do not include categories
                        $sql = 'SELECT forum_id
							FROM ' . FORUMS_TABLE . '
							WHERE forum_type <> ' . FORUM_CAT;
                        $result = $db->sql_query($sql);
                        $forum_ids = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_ids[] = $row['forum_id'];
                        }
                        $db->sql_freeresult($result);
                        // Any global announcements? ;)
                        $forum_ids[] = 0;
                        // Now go through the forums and get us some topics...
                        foreach ($forum_ids as $forum_id) {
                            $sql = 'SELECT p.poster_id, p.topic_id
								FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
								WHERE t.forum_id = ' . $forum_id . '
									AND t.topic_moved_id = 0
									AND t.topic_last_post_time > ' . $get_from_time . '
									AND t.topic_id = p.topic_id
									AND p.poster_id <> ' . ANONYMOUS . '
								GROUP BY p.poster_id, p.topic_id';
                            $result = $db->sql_query($sql);
                            $posted = array();
                            while ($row = $db->sql_fetchrow($result)) {
                                $posted[$row['poster_id']][] = $row['topic_id'];
                            }
                            $db->sql_freeresult($result);
                            $sql_ary = array();
                            foreach ($posted as $user_id => $topic_row) {
                                foreach ($topic_row as $topic_id) {
                                    $sql_ary[] = array('user_id' => (int) $user_id, 'topic_id' => (int) $topic_id, 'topic_posted' => 1);
                                }
                            }
                            unset($posted);
                            if (sizeof($sql_ary)) {
                                $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
                            }
                        }
                        add_log('admin', 'LOG_RESYNC_POST_MARKING');
                        break;
                    case 'purge_cache':
                        if ((int) $user->data['user_type'] !== USER_FOUNDER) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        global $cache;
                        $cache->purge();
                        // Clear permissions
                        $auth->acl_clear_prefetch();
                        cache_moderators();
                        add_log('admin', 'LOG_PURGE_CACHE');
                        break;
                }
            }
        }
        // Get forum statistics
        $total_posts = $config['num_posts'];
        $total_topics = $config['num_topics'];
        $total_users = $config['num_users'];
        $total_files = $config['num_files'];
        $start_date = $user->format_date($config['board_startdate']);
        $boarddays = (time() - $config['board_startdate']) / 86400;
        $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
        $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
        $users_per_day = sprintf('%.2f', $total_users / $boarddays);
        $files_per_day = sprintf('%.2f', $total_files / $boarddays);
        $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
        $avatar_dir_size = 0;
        if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) {
            while (($file = readdir($avatar_dir)) !== false) {
                if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) {
                    $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
                }
            }
            closedir($avatar_dir);
            $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
        } else {
            // Couldn't open Avatar dir.
            $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
        }
        if ($posts_per_day > $total_posts) {
            $posts_per_day = $total_posts;
        }
        if ($topics_per_day > $total_topics) {
            $topics_per_day = $total_topics;
        }
        if ($users_per_day > $total_users) {
            $users_per_day = $total_users;
        }
        if ($files_per_day > $total_files) {
            $files_per_day = $total_files;
        }
        if ($config['allow_attachments'] || $config['allow_pm_attach']) {
            $sql = 'SELECT COUNT(attach_id) AS total_orphan
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE is_orphan = 1
					AND filetime < ' . (time() - 3 * 60 * 60);
            $result = $db->sql_query($sql);
            $total_orphan = (int) $db->sql_fetchfield('total_orphan');
            $db->sql_freeresult($result);
        } else {
            $total_orphan = false;
        }
        $dbsize = get_database_size();
        $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'POSTS_PER_DAY' => $posts_per_day, 'TOTAL_TOPICS' => $total_topics, 'TOPICS_PER_DAY' => $topics_per_day, 'TOTAL_USERS' => $total_users, 'USERS_PER_DAY' => $users_per_day, 'TOTAL_FILES' => $total_files, 'FILES_PER_DAY' => $files_per_day, 'START_DATE' => $start_date, 'AVATAR_DIR_SIZE' => $avatar_dir_size, 'DBSIZE' => $dbsize, 'UPLOAD_DIR_SIZE' => $upload_dir_size, 'TOTAL_ORPHAN' => $total_orphan, 'S_TOTAL_ORPHAN' => $total_orphan === false ? false : true, 'GZIP_COMPRESSION' => $config['gzip_compress'] ? $user->lang['ON'] : $user->lang['OFF'], 'DATABASE_INFO' => $db->sql_server_info(), 'BOARD_VERSION' => $config['version'], 'U_ACTION' => $this->u_action, 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&amp;mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&amp;mode=list'), 'S_ACTION_OPTIONS' => $auth->acl_get('a_board') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
        $log_data = array();
        $log_count = 0;
        if ($auth->acl_get('a_viewlogs')) {
            view_log('admin', $log_data, $log_count, 5);
            foreach ($log_data as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action']));
            }
        }
        if ($auth->acl_get('a_user')) {
            $inactive = array();
            $inactive_count = 0;
            view_inactive_users($inactive, $inactive_count, 10);
            foreach ($inactive as $row) {
                $template->assign_block_vars('inactive', array('INACTIVE_DATE' => $user->format_date($row['user_inactive_time']), 'JOINED' => $user->format_date($row['user_regdate']), 'LAST_VISIT' => !$row['user_lastvisit'] ? ' - ' : $user->format_date($row['user_lastvisit']), 'REASON' => $row['inactive_reason'], 'USER_ID' => $row['user_id'], 'USERNAME' => $row['username'], 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}")));
            }
            $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
            if ($config['email_enable']) {
                $option_ary += array('remind' => 'REMIND');
            }
            $template->assign_vars(array('S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary)));
        }
        // Warn if install is still present
        if (file_exists($phpbb_root_path . 'install')) {
            $template->assign_var('S_REMOVE_INSTALL', true);
        }
        if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && is_writable($phpbb_root_path . 'config.' . $phpEx)) {
            // World-Writable? (000x)
            $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x2));
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
예제 #22
0
	if ($total == 0)
	{
		$_CLASS['core_template']->assign_array(array(
			'L_REPORTS_TOTAL'	=>	$_CLASS['core_user']->lang['REPORTS_ZERO_TOTAL'],
			'S_HAS_REPORTS'		=>	false)
		);
	}
	else
	{
		$_CLASS['core_template']->assign_array(array(
			'L_REPORTS_TOTAL'	=> ($total == 1) ? $_CLASS['core_user']->lang['REPORT_TOTAL'] : sprintf($_CLASS['core_user']->lang['REPORTS_TOTAL'], $total),
			'S_HAS_REPORTS'		=> true)
		);
	}
}
*/
$forum_list_log = get_forum_list(array('m_', 'a_general'));
// Add forum_id 0 for global announcements
$forum_list_log[] = 0;
$log_count = 0;
$log = array();
view_log('mod', $log, $log_count, 5, 0, $forum_list_log);
foreach ($log as $row) {
    $_CLASS['core_template']->assign_vars_array('log', array('USERNAME' => $row['username'], 'IP' => $row['ip'], 'TIME' => $_CLASS['core_user']->format_date($row['time']), 'ACTION' => $row['action'], 'U_VIEWTOPIC' => $row['viewtopic'], 'U_VIEWLOGS' => $row['viewlogs']));
}
$_CLASS['core_template']->assign_array(array('S_SHOW_LOGS' => true, 'S_HAS_LOGS' => !empty($log)));
$_CLASS['core_template']->assign('S_MCP_ACTION', generate_link($url));
make_jumpbox(generate_link($url . '&amp;mode=forum_view'), 0, false, 'm_');
page_header();
$_CLASS['core_display']->display($_CLASS['core_user']->get_lang('MCP'), 'modules/Forums/mcp_front.html');
예제 #23
0
파일: acp_main.php 프로젝트: MrAdder/phpbb
    function main($id, $mode)
    {
        global $config, $db, $cache, $user, $auth, $template, $request, $phpbb_log;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx, $phpbb_container, $phpbb_dispatcher, $phpbb_filesystem;
        // Show restore permissions notice
        if ($user->data['user_perm_from'] && $auth->acl_get('a_switchperm')) {
            $this->tpl_name = 'acp_main';
            $this->page_title = 'ACP_MAIN';
            $sql = 'SELECT user_id, username, user_colour
				FROM ' . USERS_TABLE . '
				WHERE user_id = ' . $user->data['user_perm_from'];
            $result = $db->sql_query($sql);
            $user_row = $db->sql_fetchrow($result);
            $db->sql_freeresult($result);
            $perm_from = get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']);
            $template->assign_vars(array('S_RESTORE_PERMISSIONS' => true, 'U_RESTORE_PERMISSIONS' => append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'), 'PERM_FROM' => $perm_from, 'L_PERMISSIONS_TRANSFERRED_EXPLAIN' => sprintf($user->lang['PERMISSIONS_TRANSFERRED_EXPLAIN'], $perm_from, append_sid("{$phpbb_root_path}ucp.{$phpEx}", 'mode=restore_perm'))));
            return;
        }
        $action = $request->variable('action', '');
        if ($action) {
            if ($action === 'admlogout') {
                $user->unset_admin();
                redirect(append_sid("{$phpbb_root_path}index.{$phpEx}"));
            }
            if (!confirm_box(true)) {
                switch ($action) {
                    case 'online':
                        $confirm = true;
                        $confirm_lang = 'RESET_ONLINE_CONFIRM';
                        break;
                    case 'stats':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_STATS_CONFIRM';
                        break;
                    case 'user':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POSTCOUNTS_CONFIRM';
                        break;
                    case 'date':
                        $confirm = true;
                        $confirm_lang = 'RESET_DATE_CONFIRM';
                        break;
                    case 'db_track':
                        $confirm = true;
                        $confirm_lang = 'RESYNC_POST_MARKING_CONFIRM';
                        break;
                    case 'purge_cache':
                        $confirm = true;
                        $confirm_lang = 'PURGE_CACHE_CONFIRM';
                        break;
                    case 'purge_sessions':
                        $confirm = true;
                        $confirm_lang = 'PURGE_SESSIONS_CONFIRM';
                        break;
                    default:
                        $confirm = true;
                        $confirm_lang = 'CONFIRM_OPERATION';
                }
                if ($confirm) {
                    confirm_box(false, $user->lang[$confirm_lang], build_hidden_fields(array('i' => $id, 'mode' => $mode, 'action' => $action)));
                }
            } else {
                switch ($action) {
                    case 'online':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $config->set('record_online_users', 1, false);
                        $config->set('record_online_date', time(), false);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_ONLINE');
                        if ($request->is_ajax()) {
                            trigger_error('RESET_ONLINE_SUCCESS');
                        }
                        break;
                    case 'stats':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $sql = 'SELECT COUNT(post_id) AS stat
							FROM ' . POSTS_TABLE . '
							WHERE post_visibility = ' . ITEM_APPROVED;
                        $result = $db->sql_query($sql);
                        $config->set('num_posts', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(topic_id) AS stat
							FROM ' . TOPICS_TABLE . '
							WHERE topic_visibility = ' . ITEM_APPROVED;
                        $result = $db->sql_query($sql);
                        $config->set('num_topics', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(user_id) AS stat
							FROM ' . USERS_TABLE . '
							WHERE user_type IN (' . USER_NORMAL . ',' . USER_FOUNDER . ')';
                        $result = $db->sql_query($sql);
                        $config->set('num_users', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT COUNT(attach_id) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        $config->set('num_files', (int) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        $sql = 'SELECT SUM(filesize) as stat
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE is_orphan = 0';
                        $result = $db->sql_query($sql);
                        $config->set('upload_dir_size', (double) $db->sql_fetchfield('stat'), false);
                        $db->sql_freeresult($result);
                        if (!function_exists('update_last_username')) {
                            include $phpbb_root_path . "includes/functions_user.{$phpEx}";
                        }
                        update_last_username();
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_STATS');
                        if ($request->is_ajax()) {
                            trigger_error('RESYNC_STATS_SUCCESS');
                        }
                        break;
                    case 'user':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        // Resync post counts
                        $start = $max_post_id = 0;
                        // Find the maximum post ID, we can only stop the cycle when we've reached it
                        $sql = 'SELECT MAX(forum_last_post_id) as max_post_id
							FROM ' . FORUMS_TABLE;
                        $result = $db->sql_query($sql);
                        $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                        $db->sql_freeresult($result);
                        // No maximum post id? :o
                        if (!$max_post_id) {
                            $sql = 'SELECT MAX(post_id) as max_post_id
								FROM ' . POSTS_TABLE;
                            $result = $db->sql_query($sql);
                            $max_post_id = (int) $db->sql_fetchfield('max_post_id');
                            $db->sql_freeresult($result);
                        }
                        // Still no maximum post id? Then we are finished
                        if (!$max_post_id) {
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
                            break;
                        }
                        $step = $config['num_posts'] ? max((int) ($config['num_posts'] / 5), 20000) : 20000;
                        $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_posts = 0');
                        while ($start < $max_post_id) {
                            $sql = 'SELECT COUNT(post_id) AS num_posts, poster_id
								FROM ' . POSTS_TABLE . '
								WHERE post_id BETWEEN ' . ($start + 1) . ' AND ' . ($start + $step) . '
									AND post_postcount = 1 AND post_visibility = ' . ITEM_APPROVED . '
								GROUP BY poster_id';
                            $result = $db->sql_query($sql);
                            if ($row = $db->sql_fetchrow($result)) {
                                do {
                                    $sql = 'UPDATE ' . USERS_TABLE . " SET user_posts = user_posts + {$row['num_posts']} WHERE user_id = {$row['poster_id']}";
                                    $db->sql_query($sql);
                                } while ($row = $db->sql_fetchrow($result));
                            }
                            $db->sql_freeresult($result);
                            $start += $step;
                        }
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POSTCOUNTS');
                        if ($request->is_ajax()) {
                            trigger_error('RESYNC_POSTCOUNTS_SUCCESS');
                        }
                        break;
                    case 'date':
                        if (!$auth->acl_get('a_board')) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $config->set('board_startdate', time() - 1);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESET_DATE');
                        if ($request->is_ajax()) {
                            trigger_error('RESET_DATE_SUCCESS');
                        }
                        break;
                    case 'db_track':
                        switch ($db->get_sql_layer()) {
                            case 'sqlite':
                            case 'sqlite3':
                                $db->sql_query('DELETE FROM ' . TOPICS_POSTED_TABLE);
                                break;
                            default:
                                $db->sql_query('TRUNCATE TABLE ' . TOPICS_POSTED_TABLE);
                                break;
                        }
                        // This can get really nasty... therefore we only do the last six months
                        $get_from_time = time() - 6 * 4 * 7 * 24 * 60 * 60;
                        // Select forum ids, do not include categories
                        $sql = 'SELECT forum_id
							FROM ' . FORUMS_TABLE . '
							WHERE forum_type <> ' . FORUM_CAT;
                        $result = $db->sql_query($sql);
                        $forum_ids = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $forum_ids[] = $row['forum_id'];
                        }
                        $db->sql_freeresult($result);
                        // Any global announcements? ;)
                        $forum_ids[] = 0;
                        // Now go through the forums and get us some topics...
                        foreach ($forum_ids as $forum_id) {
                            $sql = 'SELECT p.poster_id, p.topic_id
								FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t
								WHERE t.forum_id = ' . $forum_id . '
									AND t.topic_moved_id = 0
									AND t.topic_last_post_time > ' . $get_from_time . '
									AND t.topic_id = p.topic_id
									AND p.poster_id <> ' . ANONYMOUS . '
								GROUP BY p.poster_id, p.topic_id';
                            $result = $db->sql_query($sql);
                            $posted = array();
                            while ($row = $db->sql_fetchrow($result)) {
                                $posted[$row['poster_id']][] = $row['topic_id'];
                            }
                            $db->sql_freeresult($result);
                            $sql_ary = array();
                            foreach ($posted as $user_id => $topic_row) {
                                foreach ($topic_row as $topic_id) {
                                    $sql_ary[] = array('user_id' => (int) $user_id, 'topic_id' => (int) $topic_id, 'topic_posted' => 1);
                                }
                            }
                            unset($posted);
                            if (sizeof($sql_ary)) {
                                $db->sql_multi_insert(TOPICS_POSTED_TABLE, $sql_ary);
                            }
                        }
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_RESYNC_POST_MARKING');
                        if ($request->is_ajax()) {
                            trigger_error('RESYNC_POST_MARKING_SUCCESS');
                        }
                        break;
                    case 'purge_cache':
                        $config->increment('assets_version', 1);
                        $cache->purge();
                        // Remove old renderers from the text_formatter service. Since this
                        // operation is performed after the cache is purged, there is not "current"
                        // renderer and in effect all renderers will be purged
                        $phpbb_container->get('text_formatter.cache')->tidy();
                        // Clear permissions
                        $auth->acl_clear_prefetch();
                        phpbb_cache_moderators($db, $cache, $auth);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_CACHE');
                        if ($request->is_ajax()) {
                            trigger_error('PURGE_CACHE_SUCCESS');
                        }
                        break;
                    case 'purge_sessions':
                        if ((int) $user->data['user_type'] !== USER_FOUNDER) {
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
                        }
                        $tables = array(CONFIRM_TABLE, SESSIONS_TABLE);
                        foreach ($tables as $table) {
                            switch ($db->get_sql_layer()) {
                                case 'sqlite':
                                case 'sqlite3':
                                    $db->sql_query("DELETE FROM {$table}");
                                    break;
                                default:
                                    $db->sql_query("TRUNCATE TABLE {$table}");
                                    break;
                            }
                        }
                        // let's restore the admin session
                        $reinsert_ary = array('session_id' => (string) $user->session_id, 'session_page' => (string) substr($user->page['page'], 0, 199), 'session_forum_id' => $user->page['forum'], 'session_user_id' => (int) $user->data['user_id'], 'session_start' => (int) $user->data['session_start'], 'session_last_visit' => (int) $user->data['session_last_visit'], 'session_time' => (int) $user->time_now, 'session_browser' => (string) trim(substr($user->browser, 0, 149)), 'session_forwarded_for' => (string) $user->forwarded_for, 'session_ip' => (string) $user->ip, 'session_autologin' => (int) $user->data['session_autologin'], 'session_admin' => 1, 'session_viewonline' => (int) $user->data['session_viewonline']);
                        $sql = 'INSERT INTO ' . SESSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $reinsert_ary);
                        $db->sql_query($sql);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_PURGE_SESSIONS');
                        if ($request->is_ajax()) {
                            trigger_error('PURGE_SESSIONS_SUCCESS');
                        }
                        break;
                }
            }
        }
        // Version check
        $user->add_lang('install');
        if ($auth->acl_get('a_server') && version_compare(PHP_VERSION, '5.4', '<')) {
            $template->assign_vars(array('S_PHP_VERSION_OLD' => true, 'L_PHP_VERSION_OLD' => sprintf($user->lang['PHP_VERSION_OLD'], '<a href="https://www.phpbb.com/community/viewtopic.php?f=14&amp;t=2152375">', '</a>')));
        }
        if ($auth->acl_get('a_board')) {
            /* @var $version_helper \phpbb\version_helper */
            $version_helper = $phpbb_container->get('version_helper');
            try {
                $recheck = $request->variable('versioncheck_force', false);
                $updates_available = $version_helper->get_suggested_updates($recheck);
                $template->assign_var('S_VERSION_UP_TO_DATE', empty($updates_available));
            } catch (\RuntimeException $e) {
                $template->assign_vars(array('S_VERSIONCHECK_FAIL' => true, 'VERSIONCHECK_FAIL_REASON' => $e->getMessage() !== $user->lang('VERSIONCHECK_FAIL') ? $e->getMessage() : ''));
            }
        } else {
            // We set this template var to true, to not display an outdated version notice.
            $template->assign_var('S_VERSION_UP_TO_DATE', true);
        }
        /**
         * Notice admin
         *
         * @event core.acp_main_notice
         * @since 3.1.0-RC3
         */
        $phpbb_dispatcher->dispatch('core.acp_main_notice');
        // Get forum statistics
        $total_posts = $config['num_posts'];
        $total_topics = $config['num_topics'];
        $total_users = $config['num_users'];
        $total_files = $config['num_files'];
        $start_date = $user->format_date($config['board_startdate']);
        $boarddays = (time() - $config['board_startdate']) / 86400;
        $posts_per_day = sprintf('%.2f', $total_posts / $boarddays);
        $topics_per_day = sprintf('%.2f', $total_topics / $boarddays);
        $users_per_day = sprintf('%.2f', $total_users / $boarddays);
        $files_per_day = sprintf('%.2f', $total_files / $boarddays);
        $upload_dir_size = get_formatted_filesize($config['upload_dir_size']);
        $avatar_dir_size = 0;
        if ($avatar_dir = @opendir($phpbb_root_path . $config['avatar_path'])) {
            while (($file = readdir($avatar_dir)) !== false) {
                if ($file[0] != '.' && $file != 'CVS' && strpos($file, 'index.') === false) {
                    $avatar_dir_size += filesize($phpbb_root_path . $config['avatar_path'] . '/' . $file);
                }
            }
            closedir($avatar_dir);
            $avatar_dir_size = get_formatted_filesize($avatar_dir_size);
        } else {
            // Couldn't open Avatar dir.
            $avatar_dir_size = $user->lang['NOT_AVAILABLE'];
        }
        if ($posts_per_day > $total_posts) {
            $posts_per_day = $total_posts;
        }
        if ($topics_per_day > $total_topics) {
            $topics_per_day = $total_topics;
        }
        if ($users_per_day > $total_users) {
            $users_per_day = $total_users;
        }
        if ($files_per_day > $total_files) {
            $files_per_day = $total_files;
        }
        if ($config['allow_attachments'] || $config['allow_pm_attach']) {
            $sql = 'SELECT COUNT(attach_id) AS total_orphan
				FROM ' . ATTACHMENTS_TABLE . '
				WHERE is_orphan = 1
					AND filetime < ' . (time() - 3 * 60 * 60);
            $result = $db->sql_query($sql);
            $total_orphan = (int) $db->sql_fetchfield('total_orphan');
            $db->sql_freeresult($result);
        } else {
            $total_orphan = false;
        }
        $dbsize = get_database_size();
        $template->assign_vars(array('TOTAL_POSTS' => $total_posts, 'POSTS_PER_DAY' => $posts_per_day, 'TOTAL_TOPICS' => $total_topics, 'TOPICS_PER_DAY' => $topics_per_day, 'TOTAL_USERS' => $total_users, 'USERS_PER_DAY' => $users_per_day, 'TOTAL_FILES' => $total_files, 'FILES_PER_DAY' => $files_per_day, 'START_DATE' => $start_date, 'AVATAR_DIR_SIZE' => $avatar_dir_size, 'DBSIZE' => $dbsize, 'UPLOAD_DIR_SIZE' => $upload_dir_size, 'TOTAL_ORPHAN' => $total_orphan, 'S_TOTAL_ORPHAN' => $total_orphan === false ? false : true, 'GZIP_COMPRESSION' => $config['gzip_compress'] && @extension_loaded('zlib') ? $user->lang['ON'] : $user->lang['OFF'], 'DATABASE_INFO' => $db->sql_server_info(), 'BOARD_VERSION' => $config['version'], 'U_ACTION' => $this->u_action, 'U_ADMIN_LOG' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=logs&amp;mode=admin'), 'U_INACTIVE_USERS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=inactive&amp;mode=list'), 'U_VERSIONCHECK' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=update&amp;mode=version_check'), 'U_VERSIONCHECK_FORCE' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'versioncheck_force=1'), 'S_VERSIONCHECK' => $auth->acl_get('a_board') ? true : false, 'S_ACTION_OPTIONS' => $auth->acl_get('a_board') ? true : false, 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false));
        $log_data = array();
        $log_count = false;
        if ($auth->acl_get('a_viewlogs')) {
            view_log('admin', $log_data, $log_count, 5);
            foreach ($log_data as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action']));
            }
        }
        if ($auth->acl_get('a_user')) {
            $user->add_lang('memberlist');
            $inactive = array();
            $inactive_count = 0;
            view_inactive_users($inactive, $inactive_count, 10);
            foreach ($inactive as $row) {
                $template->assign_block_vars('inactive', array('INACTIVE_DATE' => $user->format_date($row['user_inactive_time']), 'REMINDED_DATE' => $user->format_date($row['user_reminded_time']), 'JOINED' => $user->format_date($row['user_regdate']), 'LAST_VISIT' => !$row['user_lastvisit'] ? ' - ' : $user->format_date($row['user_lastvisit']), 'REASON' => $row['inactive_reason'], 'USER_ID' => $row['user_id'], 'POSTS' => $row['user_posts'] ? $row['user_posts'] : 0, 'REMINDED' => $row['user_reminded'], 'REMINDED_EXPLAIN' => $user->lang('USER_LAST_REMINDED', (int) $row['user_reminded'], $user->format_date($row['user_reminded_time'])), 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&amp;mode=overview')), 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'USER_COLOR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_USER_ADMIN' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}"), 'U_SEARCH_USER' => $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$row['user_id']}&amp;sr=posts") : ''));
            }
            $option_ary = array('activate' => 'ACTIVATE', 'delete' => 'DELETE');
            if ($config['email_enable']) {
                $option_ary += array('remind' => 'REMIND');
            }
            $template->assign_vars(array('S_INACTIVE_USERS' => true, 'S_INACTIVE_OPTIONS' => build_select($option_ary)));
        }
        // Warn if install is still present
        if (file_exists($phpbb_root_path . 'install') && !is_file($phpbb_root_path . 'install')) {
            $template->assign_var('S_REMOVE_INSTALL', true);
        }
        // Warn if no search index is created
        if ($config['num_posts'] && class_exists($config['search_type'])) {
            $error = false;
            $search_type = $config['search_type'];
            $search = new $search_type($error, $phpbb_root_path, $phpEx, $auth, $config, $db, $user, $phpbb_dispatcher);
            if (!$search->index_created()) {
                $template->assign_vars(array('S_SEARCH_INDEX_MISSING' => true, 'L_NO_SEARCH_INDEX' => $user->lang('NO_SEARCH_INDEX', $search->get_name(), '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=acp_search&amp;mode=index') . '">', '</a>')));
            }
        }
        if (!defined('PHPBB_DISABLE_CONFIG_CHECK') && file_exists($phpbb_root_path . 'config.' . $phpEx) && $phpbb_filesystem->is_writable($phpbb_root_path . 'config.' . $phpEx)) {
            // World-Writable? (000x)
            $template->assign_var('S_WRITABLE_CONFIG', (bool) (@fileperms($phpbb_root_path . 'config.' . $phpEx) & 0x2));
        }
        if (extension_loaded('mbstring')) {
            $template->assign_vars(array('S_MBSTRING_LOADED' => true, 'S_MBSTRING_FUNC_OVERLOAD_FAIL' => intval(@ini_get('mbstring.func_overload')) & (MB_OVERLOAD_MAIL | MB_OVERLOAD_STRING), 'S_MBSTRING_ENCODING_TRANSLATION_FAIL' => @ini_get('mbstring.encoding_translation') != 0, 'S_MBSTRING_HTTP_INPUT_FAIL' => !in_array(@ini_get('mbstring.http_input'), array('pass', '')), 'S_MBSTRING_HTTP_OUTPUT_FAIL' => !in_array(@ini_get('mbstring.http_output'), array('pass', ''))));
        }
        // Fill dbms version if not yet filled
        if (empty($config['dbms_version'])) {
            $config->set('dbms_version', $db->sql_server_info(true));
        }
        $this->tpl_name = 'acp_main';
        $this->page_title = 'ACP_MAIN';
    }
예제 #24
0
<?php

/**
 * Contains the Pivot debug functions.
 *
 * @package pivot
 * @subpackage modules
 */
$logfile = dirname(dirname(__FILE__)) . "/db/logfile.txt";
/**
 * If called directly, display the debug log.
 */
if (basename($_SERVER['PHP_SELF']) == "module_debug.php") {
    view_log();
}
/**
 * Displays the debug log
 *
 */
function view_log()
{
    global $logfile;
    if (isset($_GET['clear']) && file_exists($logfile)) {
        $fp = fopen($logfile, "w");
        fclose($fp);
        header("location: module_debug.php");
        die;
    }
    echo <<<EOM
\t<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
예제 #25
0
/**
* MCP Front Panel
*/
function mcp_front_view($id, $mode, $action)
{
    global $phpEx, $phpbb_root_path, $config;
    global $template, $db, $user, $auth, $module;
    global $phpbb_dispatcher;
    // Latest 5 unapproved
    if ($module->loaded('queue')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_approve')));
        $post_list = array();
        $forum_names = array();
        $forum_id = request_var('f', 0);
        $template->assign_var('S_SHOW_UNAPPROVED', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql_ary = array('SELECT' => 'COUNT(post_id) AS total', 'FROM' => array(POSTS_TABLE => 'p'), 'WHERE' => $db->sql_in_set('p.forum_id', $forum_list) . '
					AND ' . $db->sql_in_set('p.post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)));
            /**
             * Allow altering the query to get the number of unapproved posts
             *
             * @event core.mcp_front_queue_unapproved_total_before
             * @var	int		sql_ary						Query to get the total number of unapproved posts
             * @var	array	forum_list					List of forums to look for unapproved posts
             * @since 3.1.5-RC1
             */
            $vars = array('sql_ary', 'forum_list');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_queue_unapproved_total_before', compact($vars)));
            $sql = $db->sql_build_query('SELECT', $sql_ary);
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $sql = 'SELECT forum_id, forum_name
					FROM ' . FORUMS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list);
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $forum_names[$row['forum_id']] = $row['forum_name'];
                }
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE ' . $db->sql_in_set('forum_id', $forum_list) . '
						AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE)) . '
					ORDER BY post_time DESC, post_id DESC';
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $post_list[] = $row['post_id'];
                }
                $db->sql_freeresult($result);
                if (empty($post_list)) {
                    $total = 0;
                }
            }
            /**
             * Alter list of posts and total as required
             *
             * @event core.mcp_front_view_queue_postid_list_after
             * @var	int		total						Number of unapproved posts
             * @var	array	post_list					List of unapproved posts
             * @var	array	forum_list					List of forums that contain the posts
             * @var	array	forum_names					Associative array with forum_id as key and it's corresponding forum_name as value
             * @since 3.1.0-RC3
             */
            $vars = array('total', 'post_list', 'forum_list', 'forum_names');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_view_queue_postid_list_after', compact($vars)));
            if ($total) {
                $sql = 'SELECT p.post_id, p.post_subject, p.post_time, p.post_attachment, p.poster_id, p.post_username, u.username, u.username_clean, u.user_colour, t.topic_id, t.topic_title, t.topic_first_post_id, p.forum_id
					FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u
					WHERE ' . $db->sql_in_set('p.post_id', $post_list) . '
						AND t.topic_id = p.topic_id
						AND p.poster_id = u.user_id
					ORDER BY p.post_time DESC, p.post_id DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('unapproved', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue&amp;mode=approve_details&amp;f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']), 'U_MCP_FORUM' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view&amp;f=' . $row['forum_id']), 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=topic_view&amp;f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'U_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']), 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour']), 'U_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour']), 'FORUM_NAME' => $forum_names[$row['forum_id']], 'POST_ID' => $row['post_id'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'POST_TIME' => $user->format_date($row['post_time']), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
                }
                $db->sql_freeresult($result);
            }
            $s_hidden_fields = build_hidden_fields(array('redirect' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main' . ($forum_id ? '&amp;f=' . $forum_id : ''))));
            $template->assign_vars(array('S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_MCP_QUEUE_ACTION' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=queue"), 'L_UNAPPROVED_TOTAL' => $user->lang('UNAPPROVED_POSTS_TOTAL', (int) $total), 'S_HAS_UNAPPROVED_POSTS' => $total != 0));
        }
    }
    // Latest 5 reported
    if ($module->loaded('reports')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_report')));
        $template->assign_var('S_SHOW_REPORTS', !empty($forum_list) ? true : false);
        if (!empty($forum_list)) {
            $sql = 'SELECT COUNT(r.report_id) AS total
				FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
				WHERE r.post_id = p.post_id
					AND r.pm_id = 0
					AND r.report_closed = 0
					AND ' . $db->sql_in_set('p.forum_id', $forum_list);
            /**
             * Alter sql query to count the number of reported posts
             *
             * @event core.mcp_front_reports_count_query_before
             * @var	int		sql				The query string used to get the number of reports that exist
             * @var	array	forum_list		List of forums that contain the posts
             * @since 3.1.5-RC1
             */
            $vars = array('sql', 'forum_list');
            extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_count_query_before', compact($vars)));
            $result = $db->sql_query($sql);
            $total = (int) $db->sql_fetchfield('total');
            $db->sql_freeresult($result);
            if ($total) {
                $sql_ary = array('SELECT' => 'r.report_time, p.post_id, p.post_subject, p.post_time, p.post_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id, t.topic_id, t.topic_title, f.forum_id, f.forum_name', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', TOPICS_TABLE => 't', USERS_TABLE => array('u', 'u2'), POSTS_TABLE => 'p'), 'LEFT_JOIN' => array(array('FROM' => array(FORUMS_TABLE => 'f'), 'ON' => 'f.forum_id = p.forum_id')), 'WHERE' => 'r.post_id = p.post_id
						AND r.pm_id = 0
						AND r.report_closed = 0
						AND r.reason_id = rr.reason_id
						AND p.topic_id = t.topic_id
						AND r.user_id = u.user_id
						AND p.poster_id = u2.user_id
						AND ' . $db->sql_in_set('p.forum_id', $forum_list), 'ORDER_BY' => 'p.post_time DESC, p.post_id DESC');
                /**
                 * Alter sql query to get latest reported posts
                 *
                 * @event core.mcp_front_reports_listing_query_before
                 * @var	int		sql_ary						Associative array with the query to be executed
                 * @var	array	forum_list					List of forums that contain the posts
                 * @since 3.1.0-RC3
                 */
                $vars = array('sql_ary', 'forum_list');
                extract($phpbb_dispatcher->trigger_event('core.mcp_front_reports_listing_query_before', compact($vars)));
                $sql = $db->sql_build_query('SELECT', $sql_ary);
                $result = $db->sql_query_limit($sql, 5);
                while ($row = $db->sql_fetchrow($result)) {
                    $template->assign_block_vars('report', array('U_POST_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id'] . "&amp;i=reports&amp;mode=report_details"), 'U_MCP_FORUM' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . "&amp;i={$id}&amp;mode=forum_view"), 'U_MCP_TOPIC' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id'] . "&amp;i={$id}&amp;mode=topic_view"), 'U_FORUM' => append_sid("{$phpbb_root_path}viewforum.{$phpEx}", 'f=' . $row['forum_id']), 'U_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 'f=' . $row['forum_id'] . '&amp;t=' . $row['topic_id']), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'FORUM_NAME' => $row['forum_name'], 'TOPIC_TITLE' => $row['topic_title'], 'SUBJECT' => $row['post_subject'] ? $row['post_subject'] : $user->lang['NO_SUBJECT'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'POST_TIME' => $user->format_date($row['post_time']), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $auth->acl_get('f_download', $row['forum_id']) && $row['post_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
                }
                $db->sql_freeresult($result);
            }
            $template->assign_vars(array('L_REPORTS_TOTAL' => $user->lang('REPORTS_TOTAL', (int) $total), 'S_HAS_REPORTS' => $total != 0));
        }
    }
    // Latest 5 reported PMs
    if ($module->loaded('pm_reports') && $auth->acl_get('m_pm_report')) {
        $template->assign_var('S_SHOW_PM_REPORTS', true);
        $user->add_lang(array('ucp'));
        $sql = 'SELECT COUNT(r.report_id) AS total
			FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p
			WHERE r.post_id = 0
				AND r.pm_id = p.msg_id
				AND r.report_closed = 0';
        $result = $db->sql_query($sql);
        $total = (int) $db->sql_fetchfield('total');
        $db->sql_freeresult($result);
        if ($total) {
            include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
            $sql_ary = array('SELECT' => 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, p.message_attachment, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id', 'FROM' => array(REPORTS_TABLE => 'r', REPORTS_REASONS_TABLE => 'rr', USERS_TABLE => array('u', 'u2'), PRIVMSGS_TABLE => 'p'), 'WHERE' => 'r.pm_id = p.msg_id
					AND r.post_id = 0
					AND r.report_closed = 0
					AND r.reason_id = rr.reason_id
					AND r.user_id = u.user_id
					AND p.author_id = u2.user_id', 'ORDER_BY' => 'p.message_time DESC');
            $sql = $db->sql_build_query('SELECT', $sql_ary);
            $result = $db->sql_query_limit($sql, 5);
            $pm_by_id = $pm_list = array();
            while ($row = $db->sql_fetchrow($result)) {
                $pm_by_id[(int) $row['msg_id']] = $row;
                $pm_list[] = (int) $row['msg_id'];
            }
            $db->sql_freeresult($result);
            $address_list = get_recipient_strings($pm_by_id);
            foreach ($pm_list as $message_id) {
                $row = $pm_by_id[$message_id];
                $template->assign_block_vars('pm_report', array('U_PM_DETAILS' => append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'r=' . $row['report_id'] . "&amp;i=pm_reports&amp;mode=pm_report_details"), 'REPORTER_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']), 'REPORTER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']), 'U_REPORTER' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']), 'PM_AUTHOR_FULL' => get_username_string('full', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR' => get_username_string('username', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_AUTHOR_COLOUR' => get_username_string('colour', $row['author_id'], $row['author_name'], $row['author_colour']), 'U_PM_AUTHOR' => get_username_string('profile', $row['author_id'], $row['author_name'], $row['author_colour']), 'PM_SUBJECT' => $row['message_subject'], 'REPORT_TIME' => $user->format_date($row['report_time']), 'PM_TIME' => $user->format_date($row['message_time']), 'RECIPIENTS' => implode(', ', $address_list[$row['msg_id']]), 'ATTACH_ICON_IMG' => $auth->acl_get('u_download') && $row['message_attachment'] ? $user->img('icon_topic_attach', $user->lang['TOTAL_ATTACHMENTS']) : ''));
            }
        }
        $template->assign_vars(array('L_PM_REPORTS_TOTAL' => $user->lang('PM_REPORTS_TOTAL', (int) $total), 'S_HAS_PM_REPORTS' => $total != 0));
    }
    // Latest 5 logs
    if ($module->loaded('logs')) {
        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
        if (!empty($forum_list)) {
            $log_count = false;
            $log = array();
            view_log('mod', $log, $log_count, 5, 0, $forum_list);
            foreach ($log as $row) {
                $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'TIME' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'U_VIEW_TOPIC' => !empty($row['viewtopic']) ? $row['viewtopic'] : '', 'U_VIEWLOGS' => !empty($row['viewlogs']) ? $row['viewlogs'] : ''));
            }
        }
        $template->assign_vars(array('S_SHOW_LOGS' => !empty($forum_list) ? true : false, 'S_HAS_LOGS' => !empty($log) ? true : false));
    }
    $template->assign_var('S_MCP_ACTION', append_sid("{$phpbb_root_path}mcp.{$phpEx}"));
    make_jumpbox(append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=main&amp;mode=forum_view'), 0, false, 'm_', true);
}
    echo $forum_box;
    ?>
</select> <input class="btnlite" type="submit" value="<?php 
    echo $_CLASS['core_user']->lang['GO'];
    ?>
" /></td>
	</tr>
</table>
<?php 
}
//
// Grab log data
//
$log_data = array();
$log_count = 0;
view_log($mode, $log_data, $log_count, $config['topics_per_page'], $start, $forum_id, 0, 0, $sql_where, $sql_sort);
?>
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
<tr>
	<td align="left" valign="top">&nbsp;<span class="nav"><?php 
echo on_page($log_count, $config['topics_per_page'], $start);
?>
</span></td>
	<td align="right" valign="top" nowrap="nowrap">
		<span class="nav"><?php 
echo generate_pagination("admin_viewlogs&amp;mode={$mode}&amp;{$u_sort_param}", $log_count, $config['topics_per_page'], $start, true);
?>
</span>
	</td>
</tr>
</table>
예제 #27
0
파일: acp_users.php 프로젝트: bantu/phpbb
    function main($id, $mode)
    {
        global $config, $db, $user, $auth, $template;
        global $phpbb_root_path, $phpbb_admin_path, $phpEx;
        global $phpbb_dispatcher, $request;
        global $phpbb_container, $phpbb_log;
        $user->add_lang(array('posting', 'ucp', 'acp/users'));
        $this->tpl_name = 'acp_users';
        $error = array();
        $username = $request->variable('username', '', true);
        $user_id = $request->variable('u', 0);
        $action = $request->variable('action', '');
        // Get referer to redirect user to the appropriate page after delete action
        $redirect = $request->variable('redirect', '');
        $redirect_tag = "redirect={$redirect}";
        $redirect_url = append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$redirect}");
        $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false;
        $form_name = 'acp_users';
        add_form_key($form_name);
        // Whois (special case)
        if ($action == 'whois') {
            if (!function_exists('user_get_id_name')) {
                include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
            }
            $this->page_title = 'WHOIS';
            $this->tpl_name = 'simple_body';
            $user_ip = phpbb_ip_normalise($request->variable('user_ip', ''));
            $domain = gethostbyaddr($user_ip);
            $ipwhois = user_ipwhois($user_ip);
            $template->assign_vars(array('MESSAGE_TITLE' => sprintf($user->lang['IP_WHOIS_FOR'], $domain), 'MESSAGE_TEXT' => nl2br($ipwhois)));
            return;
        }
        // Show user selection mask
        if (!$username && !$user_id) {
            $this->page_title = 'SELECT_USER';
            $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&amp;form=select_user&amp;field=username&amp;select_single=true')));
            return;
        }
        if (!$user_id) {
            $sql = 'SELECT user_id
				FROM ' . USERS_TABLE . "\n\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
            $result = $db->sql_query($sql);
            $user_id = (int) $db->sql_fetchfield('user_id');
            $db->sql_freeresult($result);
            if (!$user_id) {
                trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
            }
        }
        // Generate content for all modes
        $sql = 'SELECT u.*, s.*
			FROM ' . USERS_TABLE . ' u
				LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
			WHERE u.user_id = ' . $user_id . '
			ORDER BY s.session_time DESC';
        $result = $db->sql_query_limit($sql, 1);
        $user_row = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);
        if (!$user_row) {
            trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        // Generate overall "header" for user admin
        $s_form_options = '';
        // Build modes dropdown list
        $sql = 'SELECT module_mode, module_auth
			FROM ' . MODULES_TABLE . "\n\t\t\tWHERE module_basename = 'acp_users'\n\t\t\t\tAND module_enabled = 1\n\t\t\t\tAND module_class = 'acp'\n\t\t\tORDER BY left_id, module_mode";
        $result = $db->sql_query($sql);
        $dropdown_modes = array();
        while ($row = $db->sql_fetchrow($result)) {
            if (!$this->p_master->module_auth_self($row['module_auth'])) {
                continue;
            }
            $dropdown_modes[$row['module_mode']] = true;
        }
        $db->sql_freeresult($result);
        foreach ($dropdown_modes as $module_mode => $null) {
            $selected = $mode == $module_mode ? ' selected="selected"' : '';
            $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>';
        }
        $template->assign_vars(array('U_BACK' => empty($redirect) ? $this->u_action : $redirect_url, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&amp;u={$user_id}"), 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id . (empty($redirect) ? '' : '&amp;' . $redirect_tag), 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username']));
        // Prevent normal users/admins change/view founders if they are not a founder by themselves
        if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) {
            trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING);
        }
        $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode));
        switch ($mode) {
            case 'overview':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang('acp/ban');
                $delete = $request->variable('delete', 0);
                $delete_type = $request->variable('delete_type', '');
                $ip = $request->variable('ip', 'ip');
                /**
                 * Run code at beginning of ACP users overview
                 *
                 * @event core.acp_users_overview_before
                 * @var	array   user_row    Current user data
                 * @var	string  mode        Active module
                 * @var	string  action      Module that should be run
                 * @var	bool    submit      Do we display the form only
                 *                          or did the user press submit
                 * @var	array   error       Array holding error messages
                 * @since 3.1.3-RC1
                 */
                $vars = array('user_row', 'mode', 'action', 'submit', 'error');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_before', compact($vars)));
                if ($submit) {
                    if ($delete) {
                        if (!$auth->acl_get('a_userdel')) {
                            send_status_line(403, 'Forbidden');
                            trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        // Check if the user wants to remove himself or the guest user account
                        if ($user_id == ANONYMOUS) {
                            trigger_error($user->lang['CANNOT_REMOVE_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        // Founders can not be deleted.
                        if ($user_row['user_type'] == USER_FOUNDER) {
                            trigger_error($user->lang['CANNOT_REMOVE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($user_id == $user->data['user_id']) {
                            trigger_error($user->lang['CANNOT_REMOVE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        if ($delete_type) {
                            if (confirm_box(true)) {
                                user_delete($delete_type, $user_id, $user_row['username']);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DELETED', false, array($user_row['username']));
                                trigger_error($user->lang['USER_DELETED'] . adm_back_link(empty($redirect) ? $this->u_action : $redirect_url));
                            } else {
                                $delete_confirm_hidden_fields = array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true, 'delete' => 1, 'delete_type' => $delete_type);
                                // Checks if the redirection page is specified
                                if (!empty($redirect)) {
                                    $delete_confirm_hidden_fields['redirect'] = $redirect;
                                }
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($delete_confirm_hidden_fields));
                            }
                        } else {
                            trigger_error($user->lang['NO_MODE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle quicktool actions
                    switch ($action) {
                        case 'banuser':
                        case 'banemail':
                        case 'banip':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_BAN_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_id == ANONYMOUS) {
                                trigger_error($user->lang['CANNOT_BAN_ANONYMOUS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_BAN_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $ban = array();
                            switch ($action) {
                                case 'banuser':
                                    $ban[] = $user_row['username'];
                                    $reason = 'USER_ADMIN_BAN_NAME_REASON';
                                    break;
                                case 'banemail':
                                    $ban[] = $user_row['user_email'];
                                    $reason = 'USER_ADMIN_BAN_EMAIL_REASON';
                                    break;
                                case 'banip':
                                    $ban[] = $user_row['user_ip'];
                                    $sql = 'SELECT DISTINCT poster_ip
										FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}";
                                    $result = $db->sql_query($sql);
                                    while ($row = $db->sql_fetchrow($result)) {
                                        $ban[] = $row['poster_ip'];
                                    }
                                    $db->sql_freeresult($result);
                                    $reason = 'USER_ADMIN_BAN_IP_REASON';
                                    break;
                            }
                            $ban_reason = $request->variable('ban_reason', $user->lang[$reason], true);
                            $ban_give_reason = $request->variable('ban_give_reason', '', true);
                            // Log not used at the moment, we simply utilize the ban function.
                            $result = user_ban(substr($action, 3), $ban, 0, 0, 0, $ban_reason, $ban_give_reason);
                            trigger_error(($result === false ? $user->lang['BAN_ALREADY_ENTERED'] : $user->lang['BAN_SUCCESSFUL']) . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'reactivate':
                            if ($user_id == $user->data['user_id']) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_FORCE_REACT_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($config['email_enable']) {
                                if (!class_exists('messenger')) {
                                    include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                }
                                $server_url = generate_board_url();
                                $user_actkey = gen_rand_string(mt_rand(6, 10));
                                $email_template = $user_row['user_type'] == USER_NORMAL ? 'user_reactivate_account' : 'user_resend_inactive';
                                if ($user_row['user_type'] == USER_NORMAL) {
                                    user_active_flip('deactivate', $user_id, INACTIVE_REMIND);
                                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET user_actkey = '" . $db->sql_escape($user_actkey) . "'\n\t\t\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                                    $db->sql_query($sql);
                                } else {
                                    // Grabbing the last confirm key - we only send a reminder
                                    $sql = 'SELECT user_actkey
										FROM ' . USERS_TABLE . '
										WHERE user_id = ' . $user_id;
                                    $result = $db->sql_query($sql);
                                    $user_actkey = (string) $db->sql_fetchfield('user_actkey');
                                    $db->sql_freeresult($result);
                                }
                                $messenger = new messenger(false);
                                $messenger->template($email_template, $user_row['user_lang']);
                                $messenger->set_addresses($user_row);
                                $messenger->anti_abuse_headers($config, $user);
                                $messenger->assign_vars(array('WELCOME_MSG' => htmlspecialchars_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename'])), 'USERNAME' => htmlspecialchars_decode($user_row['username']), 'U_ACTIVATE' => "{$server_url}/ucp.{$phpEx}?mode=activate&u={$user_row['user_id']}&k={$user_actkey}"));
                                $messenger->send(NOTIFY_EMAIL);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE', false, array($user_row['username']));
                                $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_REACTIVATE_USER', false, array('reportee_id' => $user_id));
                                trigger_error($user->lang['FORCE_REACTIVATION_SUCCESS'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            }
                            break;
                        case 'active':
                            if ($user_id == $user->data['user_id']) {
                                // It is only deactivation since the user is already activated (else he would not have reached this page)
                                trigger_error($user->lang['CANNOT_DEACTIVATE_YOURSELF'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_FOUNDER) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($user_row['user_type'] == USER_IGNORE) {
                                trigger_error($user->lang['CANNOT_DEACTIVATE_BOT'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            user_active_flip('flip', $user_id);
                            if ($user_row['user_type'] == USER_INACTIVE) {
                                if ($config['require_activation'] == USER_ACTIVATION_ADMIN) {
                                    /* @var $phpbb_notifications \phpbb\notification\manager */
                                    $phpbb_notifications = $phpbb_container->get('notification_manager');
                                    $phpbb_notifications->delete_notifications('notification.type.admin_activate_user', $user_row['user_id']);
                                    if (!class_exists('messenger')) {
                                        include $phpbb_root_path . 'includes/functions_messenger.' . $phpEx;
                                    }
                                    $messenger = new messenger(false);
                                    $messenger->template('admin_welcome_activated', $user_row['user_lang']);
                                    $messenger->set_addresses($user_row);
                                    $messenger->anti_abuse_headers($config, $user);
                                    $messenger->assign_vars(array('USERNAME' => htmlspecialchars_decode($user_row['username'])));
                                    $messenger->send(NOTIFY_EMAIL);
                                }
                            }
                            $message = $user_row['user_type'] == USER_INACTIVE ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED';
                            $log = $user_row['user_type'] == USER_INACTIVE ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE';
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, $log, false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, $log . '_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delsig':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $sql_ary = array('user_sig' => '', 'user_sig_bbcode_uid' => '', 'user_sig_bbcode_bitfield' => '');
                            $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_SIG_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang['USER_ADMIN_SIG_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delavatar':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // Delete old avatar if present
                            /* @var $phpbb_avatar_manager \phpbb\avatar\manager */
                            $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $phpbb_avatar_manager->clean_row($user_row, 'user'), USERS_TABLE, 'user_');
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR', false, array($user_row['username']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_AVATAR_USER', false, array('reportee_id' => $user_id));
                            trigger_error($user->lang['USER_ADMIN_AVATAR_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'delposts':
                            if (confirm_box(true)) {
                                // Delete posts, attachments, etc.
                                delete_posts('poster_id', $user_id);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_POSTS', false, array($user_row['username']));
                                trigger_error($user->lang['USER_POSTS_DELETED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'delattach':
                            if (confirm_box(true)) {
                                /** @var \phpbb\attachment\manager $attachment_manager */
                                $attachment_manager = $phpbb_container->get('attachment.manager');
                                $attachment_manager->delete('user', $user_id);
                                unset($attachment_manager);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_ATTACH', false, array($user_row['username']));
                                trigger_error($user->lang['USER_ATTACHMENTS_REMOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'deloutbox':
                            if (confirm_box(true)) {
                                $msg_ids = array();
                                $lang = 'EMPTY';
                                $sql = 'SELECT msg_id
									FROM ' . PRIVMSGS_TO_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE author_id = {$user_id}\n\t\t\t\t\t\t\t\t\t\tAND folder_id = " . PRIVMSGS_OUTBOX;
                                $result = $db->sql_query($sql);
                                if ($row = $db->sql_fetchrow($result)) {
                                    if (!function_exists('delete_pm')) {
                                        include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx;
                                    }
                                    do {
                                        $msg_ids[] = (int) $row['msg_id'];
                                    } while ($row = $db->sql_fetchrow($result));
                                    $db->sql_freeresult($result);
                                    delete_pm($user_id, $msg_ids, PRIVMSGS_OUTBOX);
                                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_DEL_OUTBOX', false, array($user_row['username']));
                                    $lang = 'EMPTIED';
                                }
                                $db->sql_freeresult($result);
                                trigger_error($user->lang['USER_OUTBOX_' . $lang] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        case 'moveposts':
                            if (!check_form_key($form_name)) {
                                trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $user->add_lang('acp/forums');
                            $new_forum_id = $request->variable('new_f', 0);
                            if (!$new_forum_id) {
                                $this->page_title = 'USER_ADMIN_MOVE_POSTS';
                                $template->assign_vars(array('S_SELECT_FORUM' => true, 'U_ACTION' => $this->u_action . "&amp;action={$action}&amp;u={$user_id}", 'U_BACK' => $this->u_action . "&amp;u={$user_id}", 'S_FORUM_OPTIONS' => make_forum_select(false, false, false, true)));
                                return;
                            }
                            // Is the new forum postable to?
                            $sql = 'SELECT forum_name, forum_type
								FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE forum_id = {$new_forum_id}";
                            $result = $db->sql_query($sql);
                            $forum_info = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                            if (!$forum_info) {
                                trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($forum_info['forum_type'] != FORUM_POST) {
                                trigger_error($user->lang['MOVE_POSTS_NO_POSTABLE_FORUM'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            // Two stage?
                            // Move topics comprising only posts from this user
                            $topic_id_ary = $move_topic_ary = $move_post_ary = $new_topic_id_ary = array();
                            $forum_id_ary = array($new_forum_id);
                            $sql = 'SELECT topic_id, post_visibility, COUNT(post_id) AS total_posts
								FROM ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\t\t\t\tAND forum_id <> {$new_forum_id}\n\t\t\t\t\t\t\t\tGROUP BY topic_id, post_visibility";
                            $result = $db->sql_query($sql);
                            while ($row = $db->sql_fetchrow($result)) {
                                $topic_id_ary[$row['topic_id']][$row['post_visibility']] = $row['total_posts'];
                            }
                            $db->sql_freeresult($result);
                            if (sizeof($topic_id_ary)) {
                                $sql = 'SELECT topic_id, forum_id, topic_title, topic_posts_approved, topic_posts_unapproved, topic_posts_softdeleted, topic_attachment
									FROM ' . TOPICS_TABLE . '
									WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
                                $result = $db->sql_query($sql);
                                while ($row = $db->sql_fetchrow($result)) {
                                    if ($topic_id_ary[$row['topic_id']][ITEM_APPROVED] == $row['topic_posts_approved'] && $topic_id_ary[$row['topic_id']][ITEM_UNAPPROVED] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_REAPPROVE] == $row['topic_posts_unapproved'] && $topic_id_ary[$row['topic_id']][ITEM_DELETED] == $row['topic_posts_softdeleted']) {
                                        $move_topic_ary[] = $row['topic_id'];
                                    } else {
                                        $move_post_ary[$row['topic_id']]['title'] = $row['topic_title'];
                                        $move_post_ary[$row['topic_id']]['attach'] = $row['topic_attachment'] ? 1 : 0;
                                    }
                                    $forum_id_ary[] = $row['forum_id'];
                                }
                                $db->sql_freeresult($result);
                            }
                            // Entire topic comprises posts by this user, move these topics
                            if (sizeof($move_topic_ary)) {
                                move_topics($move_topic_ary, $new_forum_id, false);
                            }
                            if (sizeof($move_post_ary)) {
                                // Create new topic
                                // Update post_ids, report_ids, attachment_ids
                                foreach ($move_post_ary as $topic_id => $post_ary) {
                                    // Create new topic
                                    $sql = 'INSERT INTO ' . TOPICS_TABLE . ' ' . $db->sql_build_array('INSERT', array('topic_poster' => $user_id, 'topic_time' => time(), 'forum_id' => $new_forum_id, 'icon_id' => 0, 'topic_visibility' => ITEM_APPROVED, 'topic_title' => $post_ary['title'], 'topic_first_poster_name' => $user_row['username'], 'topic_type' => POST_NORMAL, 'topic_time_limit' => 0, 'topic_attachment' => $post_ary['attach']));
                                    $db->sql_query($sql);
                                    $new_topic_id = $db->sql_nextid();
                                    // Move posts
                                    $sql = 'UPDATE ' . POSTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tSET forum_id = {$new_forum_id}, topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                    $db->sql_query($sql);
                                    if ($post_ary['attach']) {
                                        $sql = 'UPDATE ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\tSET topic_id = {$new_topic_id}\n\t\t\t\t\t\t\t\t\t\t\tWHERE topic_id = {$topic_id}\n\t\t\t\t\t\t\t\t\t\t\t\tAND poster_id = {$user_id}";
                                        $db->sql_query($sql);
                                    }
                                    $new_topic_id_ary[] = $new_topic_id;
                                }
                            }
                            $forum_id_ary = array_unique($forum_id_ary);
                            $topic_id_ary = array_unique(array_merge(array_keys($topic_id_ary), $new_topic_id_ary));
                            if (sizeof($topic_id_ary)) {
                                sync('topic_reported', 'topic_id', $topic_id_ary);
                                sync('topic', 'topic_id', $topic_id_ary);
                            }
                            if (sizeof($forum_id_ary)) {
                                sync('forum', 'forum_id', $forum_id_ary, false, true);
                            }
                            $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS', false, array($user_row['username'], $forum_info['forum_name']));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_MOVE_POSTS_USER', false, array('reportee_id' => $user_id, $forum_info['forum_name']));
                            trigger_error($user->lang['USER_POSTS_MOVED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            break;
                        case 'leave_nr':
                            if (confirm_box(true)) {
                                remove_newly_registered($user_id, $user_row);
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_REMOVED_NR', false, array($user_row['username']));
                                trigger_error($user->lang['USER_LIFTED_NR'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                            } else {
                                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'update' => true)));
                            }
                            break;
                        default:
                            /**
                             * Run custom quicktool code
                             *
                             * @event core.acp_users_overview_run_quicktool
                             * @var	array	user_row	Current user data
                             * @var	string	action		Quick tool that should be run
                             * @since 3.1.0-a1
                             */
                            $vars = array('action', 'user_row');
                            extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_run_quicktool', compact($vars)));
                            break;
                    }
                    // Handle registration info updates
                    $data = array('username' => $request->variable('user', $user_row['username'], true), 'user_founder' => $request->variable('user_founder', $user_row['user_type'] == USER_FOUNDER ? 1 : 0), 'email' => strtolower($request->variable('user_email', $user_row['user_email'])), 'new_password' => $request->variable('new_password', '', true), 'password_confirm' => $request->variable('password_confirm', '', true));
                    // Validation data - we do not check the password complexity setting here
                    $check_ary = array('new_password' => array(array('string', true, $config['min_pass_chars'], $config['max_pass_chars']), array('password')), 'password_confirm' => array('string', true, $config['min_pass_chars'], $config['max_pass_chars']));
                    // Check username if altered
                    if ($data['username'] != $user_row['username']) {
                        $check_ary += array('username' => array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username', $user_row['username'])));
                    }
                    // Check email if altered
                    if ($data['email'] != $user_row['user_email']) {
                        $check_ary += array('email' => array(array('string', false, 6, 60), array('user_email', $user_row['user_email'])));
                    }
                    $error = validate_data($data, $check_ary);
                    if ($data['new_password'] && $data['password_confirm'] != $data['new_password']) {
                        $error[] = 'NEW_PASSWORD_ERROR';
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    // Instantiate passwords manager
                    /* @var $passwords_manager \phpbb\passwords\manager */
                    $passwords_manager = $phpbb_container->get('passwords.manager');
                    // Which updates do we need to do?
                    $update_username = $user_row['username'] != $data['username'] ? $data['username'] : false;
                    $update_password = $data['new_password'] && !$passwords_manager->check($data['new_password'], $user_row['user_password']);
                    $update_email = $data['email'] != $user_row['user_email'] ? $data['email'] : false;
                    if (!sizeof($error)) {
                        $sql_ary = array();
                        if ($user_row['user_type'] != USER_FOUNDER || $user->data['user_type'] == USER_FOUNDER) {
                            // Only allow founders updating the founder status...
                            if ($user->data['user_type'] == USER_FOUNDER) {
                                // Setting a normal member to be a founder
                                if ($data['user_founder'] && $user_row['user_type'] != USER_FOUNDER) {
                                    // Make sure the user is not setting an Inactive or ignored user to be a founder
                                    if ($user_row['user_type'] == USER_IGNORE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_IGNORED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    if ($user_row['user_type'] == USER_INACTIVE) {
                                        trigger_error($user->lang['CANNOT_SET_FOUNDER_INACTIVE'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                    }
                                    $sql_ary['user_type'] = USER_FOUNDER;
                                } else {
                                    if (!$data['user_founder'] && $user_row['user_type'] == USER_FOUNDER) {
                                        // Check if at least one founder is present
                                        $sql = 'SELECT user_id
										FROM ' . USERS_TABLE . '
										WHERE user_type = ' . USER_FOUNDER . '
											AND user_id <> ' . $user_id;
                                        $result = $db->sql_query_limit($sql, 1);
                                        $row = $db->sql_fetchrow($result);
                                        $db->sql_freeresult($result);
                                        if ($row) {
                                            $sql_ary['user_type'] = USER_NORMAL;
                                        } else {
                                            trigger_error($user->lang['AT_LEAST_ONE_FOUNDER'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                                        }
                                    }
                                }
                            }
                        }
                        /**
                         * Modify user data before we update it
                         *
                         * @event core.acp_users_overview_modify_data
                         * @var	array	user_row	Current user data
                         * @var	array	data		Submitted user data
                         * @var	array	sql_ary		User data we udpate
                         * @since 3.1.0-a1
                         */
                        $vars = array('user_row', 'data', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_overview_modify_data', compact($vars)));
                        if ($update_username !== false) {
                            $sql_ary['username'] = $update_username;
                            $sql_ary['username_clean'] = utf8_clean_string($update_username);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_NAME', false, array('reportee_id' => $user_id, $user_row['username'], $update_username));
                        }
                        if ($update_email !== false) {
                            $sql_ary += array('user_email' => $update_email, 'user_email_hash' => phpbb_email_hash($update_email));
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_UPDATE_EMAIL', false, array('reportee_id' => $user_id, $user_row['username'], $user_row['user_email'], $update_email));
                        }
                        if ($update_password) {
                            $sql_ary += array('user_password' => $passwords_manager->hash($data['new_password']), 'user_passchg' => time());
                            $user->reset_login_keys($user_id);
                            $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_NEW_PASSWORD', false, array('reportee_id' => $user_id, $user_row['username']));
                        }
                        if (sizeof($sql_ary)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
								WHERE user_id = ' . $user_id;
                            $db->sql_query($sql);
                        }
                        if ($update_username) {
                            user_update_name($user_row['username'], $update_username);
                        }
                        // Let the users permissions being updated
                        $auth->acl_clear_prefetch($user_id);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_USER_UPDATE', false, array($data['username']));
                        trigger_error($user->lang['USER_OVERVIEW_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $error);
                }
                if ($user_id == $user->data['user_id']) {
                    $quick_tool_ary = array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                } else {
                    $quick_tool_ary = array();
                    if ($user_row['user_type'] != USER_FOUNDER) {
                        $quick_tool_ary += array('banuser' => 'BAN_USER', 'banemail' => 'BAN_EMAIL', 'banip' => 'BAN_IP');
                    }
                    if ($user_row['user_type'] != USER_FOUNDER && $user_row['user_type'] != USER_IGNORE) {
                        $quick_tool_ary += array('active' => $user_row['user_type'] == USER_INACTIVE ? 'ACTIVATE' : 'DEACTIVATE');
                    }
                    $quick_tool_ary += array('delsig' => 'DEL_SIG', 'delavatar' => 'DEL_AVATAR', 'moveposts' => 'MOVE_POSTS', 'delposts' => 'DEL_POSTS', 'delattach' => 'DEL_ATTACH', 'deloutbox' => 'DEL_OUTBOX');
                    if ($config['email_enable'] && ($user_row['user_type'] == USER_NORMAL || $user_row['user_type'] == USER_INACTIVE)) {
                        $quick_tool_ary['reactivate'] = 'FORCE';
                    }
                    if ($user_row['user_new']) {
                        $quick_tool_ary['leave_nr'] = 'LEAVE_NR';
                    }
                }
                if ($config['load_onlinetrack']) {
                    $sql = 'SELECT MAX(session_time) AS session_time, MIN(session_viewonline) AS session_viewonline
						FROM ' . SESSIONS_TABLE . "\n\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                    $result = $db->sql_query($sql);
                    $row = $db->sql_fetchrow($result);
                    $db->sql_freeresult($result);
                    $user_row['session_time'] = isset($row['session_time']) ? $row['session_time'] : 0;
                    $user_row['session_viewonline'] = isset($row['session_viewonline']) ? $row['session_viewonline'] : 0;
                    unset($row);
                }
                /**
                 * Add additional quick tool options and overwrite user data
                 *
                 * @event core.acp_users_display_overview
                 * @var	array	user_row			Array with user data
                 * @var	array	quick_tool_ary		Ouick tool options
                 * @since 3.1.0-a1
                 */
                $vars = array('user_row', 'quick_tool_ary');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_display_overview', compact($vars)));
                $s_action_options = '<option class="sep" value="">' . $user->lang['SELECT_OPTION'] . '</option>';
                foreach ($quick_tool_ary as $value => $lang) {
                    $s_action_options .= '<option value="' . $value . '">' . $user->lang['USER_ADMIN_' . $lang] . '</option>';
                }
                $last_active = !empty($user_row['session_time']) ? $user_row['session_time'] : $user_row['user_lastvisit'];
                $inactive_reason = '';
                if ($user_row['user_type'] == USER_INACTIVE) {
                    $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN'];
                    switch ($user_row['user_inactive_reason']) {
                        case INACTIVE_REGISTER:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER'];
                            break;
                        case INACTIVE_PROFILE:
                            $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE'];
                            break;
                        case INACTIVE_MANUAL:
                            $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL'];
                            break;
                        case INACTIVE_REMIND:
                            $inactive_reason = $user->lang['INACTIVE_REASON_REMIND'];
                            break;
                    }
                }
                // Posts in Queue
                $sql = 'SELECT COUNT(post_id) as posts_in_queue
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id . '
						AND ' . $db->sql_in_set('post_visibility', array(ITEM_UNAPPROVED, ITEM_REAPPROVE));
                $result = $db->sql_query($sql);
                $user_row['posts_in_queue'] = (int) $db->sql_fetchfield('posts_in_queue');
                $db->sql_freeresult($result);
                $sql = 'SELECT post_id
					FROM ' . POSTS_TABLE . '
					WHERE poster_id = ' . $user_id;
                $result = $db->sql_query_limit($sql, 1);
                $user_row['user_has_posts'] = (bool) $db->sql_fetchfield('post_id');
                $db->sql_freeresult($result);
                $template->assign_vars(array('L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_CHANGE_PASSWORD_EXPLAIN' => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_pass_chars']), $user->lang('CHARACTERS', (int) $config['max_pass_chars'])), 'L_POSTS_IN_QUEUE' => $user->lang('NUM_POSTS_IN_QUEUE', $user_row['posts_in_queue']), 'S_FOUNDER' => $user->data['user_type'] == USER_FOUNDER ? true : false, 'S_OVERVIEW' => true, 'S_USER_IP' => $user_row['user_ip'] ? true : false, 'S_USER_FOUNDER' => $user_row['user_type'] == USER_FOUNDER ? true : false, 'S_ACTION_OPTIONS' => $s_action_options, 'S_OWN_ACCOUNT' => $user_id == $user->data['user_id'] ? true : false, 'S_USER_INACTIVE' => $user_row['user_type'] == USER_INACTIVE ? true : false, 'U_SHOW_IP' => $this->u_action . "&amp;u={$user_id}&amp;ip=" . ($ip == 'ip' ? 'hostname' : 'ip'), 'U_WHOIS' => $this->u_action . "&amp;action=whois&amp;user_ip={$user_row['user_ip']}", 'U_MCP_QUEUE' => $auth->acl_getf_global('m_approve') ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", 'i=queue', true, $user->session_id) : '', 'U_SEARCH_USER' => $config['load_search'] && $auth->acl_get('u_search') ? append_sid("{$phpbb_root_path}search.{$phpEx}", "author_id={$user_row['user_id']}&amp;sr=posts") : '', 'U_SWITCH_PERMISSIONS' => $auth->acl_get('a_switchperm') && $user->data['user_id'] != $user_row['user_id'] ? append_sid("{$phpbb_root_path}ucp.{$phpEx}", "mode=switch_perm&amp;u={$user_row['user_id']}&amp;hash=" . generate_link_hash('switchperm')) : '', 'POSTS_IN_QUEUE' => $user_row['posts_in_queue'], 'USER' => $user_row['username'], 'USER_REGISTERED' => $user->format_date($user_row['user_regdate']), 'REGISTERED_IP' => $ip == 'hostname' ? gethostbyaddr($user_row['user_ip']) : $user_row['user_ip'], 'USER_LASTACTIVE' => $last_active ? $user->format_date($last_active) : ' - ', 'USER_EMAIL' => $user_row['user_email'], 'USER_WARNINGS' => $user_row['user_warnings'], 'USER_POSTS' => $user_row['user_posts'], 'USER_HAS_POSTS' => $user_row['user_has_posts'], 'USER_INACTIVE_REASON' => $inactive_reason));
                break;
            case 'feedback':
                $user->add_lang('mcp');
                // Set up general vars
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $marked = $request->variable('mark', array(0));
                $message = $request->variable('message', '', true);
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                // Sort keys
                $sort_days = $request->variable('st', 0);
                $sort_key = $request->variable('sk', 't');
                $sort_dir = $request->variable('sd', 'd');
                // Delete entries if requested and able
                if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $where_sql = '';
                    if ($deletemark && $marked) {
                        $sql_in = array();
                        foreach ($marked as $mark) {
                            $sql_in[] = $mark;
                        }
                        $where_sql = ' AND ' . $db->sql_in_set('log_id', $sql_in);
                        unset($sql_in);
                    }
                    if ($where_sql || $deleteall) {
                        $sql = 'DELETE FROM ' . LOG_TABLE . '
							WHERE log_type = ' . LOG_USERS . "\n\t\t\t\t\t\t\tAND reportee_id = {$user_id}\n\t\t\t\t\t\t\t{$where_sql}";
                        $db->sql_query($sql);
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_CLEAR_USER', false, array($user_row['username']));
                    }
                }
                if ($submit && $message) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array($user_row['username']));
                    $phpbb_log->add('mod', $user->data['user_id'], $user->ip, 'LOG_USER_FEEDBACK', false, array('forum_id' => 0, 'topic_id' => 0, $user_row['username']));
                    $phpbb_log->add('user', $user->data['user_id'], $user->ip, 'LOG_USER_GENERAL', false, array('reportee_id' => $user_id, $message));
                    trigger_error($user->lang['USER_FEEDBACK_ADDED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                // Sorting
                $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']);
                $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
                $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
                $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
                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);
                // Define where and sort sql for use in displaying logs
                $sql_where = $sort_days ? time() - $sort_days * 86400 : 0;
                $sql_sort = $sort_by_sql[$sort_key] . ' ' . ($sort_dir == 'd' ? 'DESC' : 'ASC');
                // Grab log data
                $log_data = array();
                $log_count = 0;
                $start = view_log('user', $log_data, $log_count, $config['topics_per_page'], $start, 0, 0, $user_id, $sql_where, $sql_sort);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;{$u_sort_param}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_FEEDBACK' => true, 'S_LIMIT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs')));
                foreach ($log_data as $row) {
                    $template->assign_block_vars('log', array('USERNAME' => $row['username_full'], 'IP' => $row['ip'], 'DATE' => $user->format_date($row['time']), 'ACTION' => nl2br($row['action']), 'ID' => $row['id']));
                }
                break;
            case 'warnings':
                $user->add_lang('mcp');
                // Set up general vars
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $deleteall = isset($_POST['delall']) ? true : false;
                $confirm = isset($_POST['confirm']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Delete entries if requested and able
                if ($deletemark || $deleteall || $confirm) {
                    if (confirm_box(true)) {
                        $where_sql = '';
                        $deletemark = $request->variable('delmarked', 0);
                        $deleteall = $request->variable('delall', 0);
                        if ($deletemark && $marked) {
                            $where_sql = ' AND ' . $db->sql_in_set('warning_id', array_values($marked));
                        }
                        if ($where_sql || $deleteall) {
                            $sql = 'DELETE FROM ' . WARNINGS_TABLE . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}\n\t\t\t\t\t\t\t\t\t{$where_sql}";
                            $db->sql_query($sql);
                            if ($deleteall) {
                                $log_warnings = $deleted_warnings = 0;
                            } else {
                                $num_warnings = (int) $db->sql_affectedrows();
                                $deleted_warnings = ' user_warnings - ' . $num_warnings;
                                $log_warnings = $num_warnings > 2 ? 2 : $num_warnings;
                            }
                            $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\tSET user_warnings = {$deleted_warnings}\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            if ($log_warnings) {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED', false, array($user_row['username'], $num_warnings));
                            } else {
                                $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_WARNINGS_DELETED_ALL', false, array($user_row['username']));
                            }
                        }
                    } else {
                        $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'u' => $user_id, 'mark' => $marked);
                        if (isset($_POST['delmarked'])) {
                            $s_hidden_fields['delmarked'] = 1;
                        }
                        if (isset($_POST['delall'])) {
                            $s_hidden_fields['delall'] = 1;
                        }
                        if (isset($_POST['delall']) || isset($_POST['delmarked']) && sizeof($marked)) {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields));
                        }
                    }
                }
                $sql = 'SELECT w.warning_id, w.warning_time, w.post_id, l.log_operation, l.log_data, l.user_id AS mod_user_id, m.username AS mod_username, m.user_colour AS mod_user_colour
					FROM ' . WARNINGS_TABLE . ' w
					LEFT JOIN ' . LOG_TABLE . ' l
						ON (w.log_id = l.log_id)
					LEFT JOIN ' . USERS_TABLE . ' m
						ON (l.user_id = m.user_id)
					WHERE w.user_id = ' . $user_id . '
					ORDER BY w.warning_time DESC';
                $result = $db->sql_query($sql);
                while ($row = $db->sql_fetchrow($result)) {
                    if (!$row['log_operation']) {
                        // We do not have a log-entry anymore, so there is no data available
                        $row['action'] = $user->lang['USER_WARNING_LOG_DELETED'];
                    } else {
                        $row['action'] = isset($user->lang[$row['log_operation']]) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
                        if (!empty($row['log_data'])) {
                            $log_data_ary = @unserialize($row['log_data']);
                            $log_data_ary = $log_data_ary === false ? array() : $log_data_ary;
                            if (isset($user->lang[$row['log_operation']])) {
                                // Check if there are more occurrences of % than arguments, if there are we fill out the arguments array
                                // It doesn't matter if we add more arguments than placeholders
                                if (substr_count($row['action'], '%') - sizeof($log_data_ary) > 0) {
                                    $log_data_ary = array_merge($log_data_ary, array_fill(0, substr_count($row['action'], '%') - sizeof($log_data_ary), ''));
                                }
                                $row['action'] = vsprintf($row['action'], $log_data_ary);
                                $row['action'] = bbcode_nl2br(censor_text($row['action']));
                            } else {
                                if (!empty($log_data_ary)) {
                                    $row['action'] .= '<br />' . implode('', $log_data_ary);
                                }
                            }
                        }
                    }
                    $template->assign_block_vars('warn', array('ID' => $row['warning_id'], 'USERNAME' => $row['log_operation'] ? get_username_string('full', $row['mod_user_id'], $row['mod_username'], $row['mod_user_colour']) : '-', 'ACTION' => make_clickable($row['action']), 'DATE' => $user->format_date($row['warning_time'])));
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_WARNINGS' => true));
                break;
            case 'profile':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                /* @var $cp \phpbb\profilefields\manager */
                $cp = $phpbb_container->get('profilefields.manager');
                $cp_data = $cp_error = array();
                $sql = 'SELECT lang_id
					FROM ' . LANG_TABLE . "\n\t\t\t\t\tWHERE lang_iso = '" . $db->sql_escape($user->data['user_lang']) . "'";
                $result = $db->sql_query($sql);
                $row = $db->sql_fetchrow($result);
                $db->sql_freeresult($result);
                $user_row['iso_lang_id'] = $row['lang_id'];
                $data = array('jabber' => $request->variable('jabber', $user_row['user_jabber'], true), 'bday_day' => 0, 'bday_month' => 0, 'bday_year' => 0);
                if ($user_row['user_birthday']) {
                    list($data['bday_day'], $data['bday_month'], $data['bday_year']) = explode('-', $user_row['user_birthday']);
                }
                $data['bday_day'] = $request->variable('bday_day', $data['bday_day']);
                $data['bday_month'] = $request->variable('bday_month', $data['bday_month']);
                $data['bday_year'] = $request->variable('bday_year', $data['bday_year']);
                $data['user_birthday'] = sprintf('%2d-%2d-%4d', $data['bday_day'], $data['bday_month'], $data['bday_year']);
                /**
                 * Modify user data on editing profile in ACP
                 *
                 * @event core.acp_users_modify_profile
                 * @var	array	data		Array with user profile data
                 * @var	bool	submit		Flag indicating if submit button has been pressed
                 * @var	int		user_id		The user id
                 * @var	array	user_row	Array with the full user data
                 * @since 3.1.4-RC1
                 */
                $vars = array('data', 'submit', 'user_id', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_modify_profile', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('jabber' => array(array('string', true, 5, 255), array('jabber')), 'bday_day' => array('num', true, 1, 31), 'bday_month' => array('num', true, 1, 12), 'bday_year' => array('num', true, 1901, gmdate('Y', time())), 'user_birthday' => array('date', true)));
                    // validate custom profile fields
                    $cp->submit_cp_field('profile', $user_row['iso_lang_id'], $cp_data, $cp_error);
                    if (sizeof($cp_error)) {
                        $error = array_merge($error, $cp_error);
                    }
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    /**
                     * Validate profile data in ACP before submitting to the database
                     *
                     * @event core.acp_users_profile_validate
                     * @var	bool	submit		Flag indicating if submit button has been pressed
                     * @var	array	data		Array with user profile data
                     * @var	array	error		Array with the form errors
                     * @since 3.1.4-RC1
                     */
                    $vars = array('submit', 'data', 'error');
                    extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_validate', compact($vars)));
                    if (!sizeof($error)) {
                        $sql_ary = array('user_jabber' => $data['jabber'], 'user_birthday' => $data['user_birthday']);
                        /**
                         * Modify profile data in ACP before submitting to the database
                         *
                         * @event core.acp_users_profile_modify_sql_ary
                         * @var	array	cp_data		Array with the user custom profile fields data
                         * @var	array	data		Array with user profile data
                         * @var	int		user_id		The user id
                         * @var	array	user_row	Array with the full user data
                         * @var	array	sql_ary		Array with sql data
                         * @since 3.1.4-RC1
                         */
                        $vars = array('cp_data', 'data', 'user_id', 'user_row', 'sql_ary');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_profile_modify_sql_ary', compact($vars)));
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                        $db->sql_query($sql);
                        // Update Custom Fields
                        $cp->update_profile_field_data($user_id, $cp_data);
                        trigger_error($user->lang['USER_PROFILE_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $error);
                }
                $s_birthday_day_options = '<option value="0"' . (!$data['bday_day'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 32; $i++) {
                    $selected = $i == $data['bday_day'] ? ' selected="selected"' : '';
                    $s_birthday_day_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $s_birthday_month_options = '<option value="0"' . (!$data['bday_month'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = 1; $i < 13; $i++) {
                    $selected = $i == $data['bday_month'] ? ' selected="selected"' : '';
                    $s_birthday_month_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                $now = getdate();
                $s_birthday_year_options = '<option value="0"' . (!$data['bday_year'] ? ' selected="selected"' : '') . '>--</option>';
                for ($i = $now['year'] - 100; $i <= $now['year']; $i++) {
                    $selected = $i == $data['bday_year'] ? ' selected="selected"' : '';
                    $s_birthday_year_options .= "<option value=\"{$i}\"{$selected}>{$i}</option>";
                }
                unset($now);
                $template->assign_vars(array('JABBER' => $data['jabber'], 'S_BIRTHDAY_DAY_OPTIONS' => $s_birthday_day_options, 'S_BIRTHDAY_MONTH_OPTIONS' => $s_birthday_month_options, 'S_BIRTHDAY_YEAR_OPTIONS' => $s_birthday_year_options, 'S_PROFILE' => true));
                // Get additional profile fields and assign them to the template block var 'profile_fields'
                $user->get_profile_fields($user_id);
                $cp->generate_profile_fields('profile', $user_row['iso_lang_id']);
                break;
            case 'prefs':
                if (!function_exists('user_get_id_name')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $data = array('dateformat' => $request->variable('dateformat', $user_row['user_dateformat'], true), 'lang' => basename($request->variable('lang', $user_row['user_lang'])), 'tz' => $request->variable('tz', $user_row['user_timezone']), 'style' => $request->variable('style', $user_row['user_style']), 'viewemail' => $request->variable('viewemail', $user_row['user_allow_viewemail']), 'massemail' => $request->variable('massemail', $user_row['user_allow_massemail']), 'hideonline' => $request->variable('hideonline', !$user_row['user_allow_viewonline']), 'notifymethod' => $request->variable('notifymethod', $user_row['user_notify_type']), 'notifypm' => $request->variable('notifypm', $user_row['user_notify_pm']), 'allowpm' => $request->variable('allowpm', $user_row['user_allow_pm']), 'topic_sk' => $request->variable('topic_sk', $user_row['user_topic_sortby_type'] ? $user_row['user_topic_sortby_type'] : 't'), 'topic_sd' => $request->variable('topic_sd', $user_row['user_topic_sortby_dir'] ? $user_row['user_topic_sortby_dir'] : 'd'), 'topic_st' => $request->variable('topic_st', $user_row['user_topic_show_days'] ? $user_row['user_topic_show_days'] : 0), 'post_sk' => $request->variable('post_sk', $user_row['user_post_sortby_type'] ? $user_row['user_post_sortby_type'] : 't'), 'post_sd' => $request->variable('post_sd', $user_row['user_post_sortby_dir'] ? $user_row['user_post_sortby_dir'] : 'a'), 'post_st' => $request->variable('post_st', $user_row['user_post_show_days'] ? $user_row['user_post_show_days'] : 0), 'view_images' => $request->variable('view_images', $this->optionget($user_row, 'viewimg')), 'view_flash' => $request->variable('view_flash', $this->optionget($user_row, 'viewflash')), 'view_smilies' => $request->variable('view_smilies', $this->optionget($user_row, 'viewsmilies')), 'view_sigs' => $request->variable('view_sigs', $this->optionget($user_row, 'viewsigs')), 'view_avatars' => $request->variable('view_avatars', $this->optionget($user_row, 'viewavatars')), 'view_wordcensor' => $request->variable('view_wordcensor', $this->optionget($user_row, 'viewcensors')), 'bbcode' => $request->variable('bbcode', $this->optionget($user_row, 'bbcode')), 'smilies' => $request->variable('smilies', $this->optionget($user_row, 'smilies')), 'sig' => $request->variable('sig', $this->optionget($user_row, 'attachsig')), 'notify' => $request->variable('notify', $user_row['user_notify']));
                /**
                 * Modify users preferences data
                 *
                 * @event core.acp_users_prefs_modify_data
                 * @var	array	data			Array with users preferences data
                 * @var	array	user_row		Array with user data
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_data', compact($vars)));
                if ($submit) {
                    $error = validate_data($data, array('dateformat' => array('string', false, 1, 64), 'lang' => array('match', false, '#^[a-z_\\-]{2,}$#i'), 'tz' => array('timezone'), 'topic_sk' => array('string', false, 1, 1), 'topic_sd' => array('string', false, 1, 1), 'post_sk' => array('string', false, 1, 1), 'post_sd' => array('string', false, 1, 1)));
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'viewimg', $data['view_images']);
                        $this->optionset($user_row, 'viewflash', $data['view_flash']);
                        $this->optionset($user_row, 'viewsmilies', $data['view_smilies']);
                        $this->optionset($user_row, 'viewsigs', $data['view_sigs']);
                        $this->optionset($user_row, 'viewavatars', $data['view_avatars']);
                        $this->optionset($user_row, 'viewcensors', $data['view_wordcensor']);
                        $this->optionset($user_row, 'bbcode', $data['bbcode']);
                        $this->optionset($user_row, 'smilies', $data['smilies']);
                        $this->optionset($user_row, 'attachsig', $data['sig']);
                        $sql_ary = array('user_options' => $user_row['user_options'], 'user_allow_pm' => $data['allowpm'], 'user_allow_viewemail' => $data['viewemail'], 'user_allow_massemail' => $data['massemail'], 'user_allow_viewonline' => !$data['hideonline'], 'user_notify_type' => $data['notifymethod'], 'user_notify_pm' => $data['notifypm'], 'user_dateformat' => $data['dateformat'], 'user_lang' => $data['lang'], 'user_timezone' => $data['tz'], 'user_style' => $data['style'], 'user_topic_sortby_type' => $data['topic_sk'], 'user_post_sortby_type' => $data['post_sk'], 'user_topic_sortby_dir' => $data['topic_sd'], 'user_post_sortby_dir' => $data['post_sd'], 'user_topic_show_days' => $data['topic_st'], 'user_post_show_days' => $data['post_st'], 'user_notify' => $data['notify']);
                        /**
                         * Modify SQL query before users preferences are updated
                         *
                         * @event core.acp_users_prefs_modify_sql
                         * @var	array	data			Array with users preferences data
                         * @var	array	user_row		Array with user data
                         * @var	array	sql_ary			SQL array with users preferences data to update
                         * @var	array	error			Array with errors data
                         * @since 3.1.0-b3
                         */
                        $vars = array('data', 'user_row', 'sql_ary', 'error');
                        extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_sql', compact($vars)));
                        if (!sizeof($error)) {
                            $sql = 'UPDATE ' . USERS_TABLE . '
								SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "\n\t\t\t\t\t\t\t\tWHERE user_id = {$user_id}";
                            $db->sql_query($sql);
                            // Check if user has an active session
                            if ($user_row['session_id']) {
                                // We'll update the session if user_allow_viewonline has changed and the user is a bot
                                // Or if it's a regular user and the admin set it to hide the session
                                if ($user_row['user_allow_viewonline'] != $sql_ary['user_allow_viewonline'] && $user_row['user_type'] == USER_IGNORE || $user_row['user_allow_viewonline'] && !$sql_ary['user_allow_viewonline']) {
                                    // We also need to check if the user has the permission to cloak.
                                    $user_auth = new \phpbb\auth\auth();
                                    $user_auth->acl($user_row);
                                    $session_sql_ary = array('session_viewonline' => $user_auth->acl_get('u_hideonline') ? $sql_ary['user_allow_viewonline'] : true);
                                    $sql = 'UPDATE ' . SESSIONS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $session_sql_ary) . "\n\t\t\t\t\t\t\t\t\t\tWHERE session_user_id = {$user_id}";
                                    $db->sql_query($sql);
                                    unset($user_auth);
                                }
                            }
                            trigger_error($user->lang['USER_PREFS_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                    }
                    // Replace "error" strings with their real, localised form
                    $error = array_map(array($user, 'lang'), $error);
                }
                $dateformat_options = '';
                foreach ($user->lang['dateformats'] as $format => $null) {
                    $dateformat_options .= '<option value="' . $format . '"' . ($format == $data['dateformat'] ? ' selected="selected"' : '') . '>';
                    $dateformat_options .= $user->format_date(time(), $format, false) . (strpos($format, '|') !== false ? $user->lang['VARIANT_DATE_SEPARATOR'] . $user->format_date(time(), $format, true) : '');
                    $dateformat_options .= '</option>';
                }
                $s_custom = false;
                $dateformat_options .= '<option value="custom"';
                if (!isset($user->lang['dateformats'][$data['dateformat']])) {
                    $dateformat_options .= ' selected="selected"';
                    $s_custom = true;
                }
                $dateformat_options .= '>' . $user->lang['CUSTOM_DATEFORMAT'] . '</option>';
                $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                // Topic ordering options
                $limit_topic_days = array(0 => $user->lang['ALL_TOPICS'], 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']);
                $sort_by_topic_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
                // Post ordering options
                $limit_post_days = array(0 => $user->lang['ALL_POSTS'], 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']);
                $sort_by_post_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
                $_options = array('topic', 'post');
                foreach ($_options as $sort_option) {
                    ${'s_limit_' . $sort_option . '_days'} = '<select name="' . $sort_option . '_st">';
                    foreach (${'limit_' . $sort_option . '_days'} as $day => $text) {
                        $selected = $data[$sort_option . '_st'] == $day ? ' selected="selected"' : '';
                        ${'s_limit_' . $sort_option . '_days'} .= '<option value="' . $day . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_limit_' . $sort_option . '_days'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_key'} = '<select name="' . $sort_option . '_sk">';
                    foreach (${'sort_by_' . $sort_option . '_text'} as $key => $text) {
                        $selected = $data[$sort_option . '_sk'] == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_key'} .= '<option value="' . $key . '"' . $selected . '>' . $text . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_key'} .= '</select>';
                    ${'s_sort_' . $sort_option . '_dir'} = '<select name="' . $sort_option . '_sd">';
                    foreach ($sort_dir_text as $key => $value) {
                        $selected = $data[$sort_option . '_sd'] == $key ? ' selected="selected"' : '';
                        ${'s_sort_' . $sort_option . '_dir'} .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                    }
                    ${'s_sort_' . $sort_option . '_dir'} .= '</select>';
                }
                phpbb_timezone_select($template, $user, $data['tz'], true);
                $user_prefs_data = array('S_PREFS' => true, 'S_JABBER_DISABLED' => $config['jab_enable'] && $user_row['user_jabber'] && @extension_loaded('xml') ? false : true, 'VIEW_EMAIL' => $data['viewemail'], 'MASS_EMAIL' => $data['massemail'], 'ALLOW_PM' => $data['allowpm'], 'HIDE_ONLINE' => $data['hideonline'], 'NOTIFY_EMAIL' => $data['notifymethod'] == NOTIFY_EMAIL ? true : false, 'NOTIFY_IM' => $data['notifymethod'] == NOTIFY_IM ? true : false, 'NOTIFY_BOTH' => $data['notifymethod'] == NOTIFY_BOTH ? true : false, 'NOTIFY_PM' => $data['notifypm'], 'BBCODE' => $data['bbcode'], 'SMILIES' => $data['smilies'], 'ATTACH_SIG' => $data['sig'], 'NOTIFY' => $data['notify'], 'VIEW_IMAGES' => $data['view_images'], 'VIEW_FLASH' => $data['view_flash'], 'VIEW_SMILIES' => $data['view_smilies'], 'VIEW_SIGS' => $data['view_sigs'], 'VIEW_AVATARS' => $data['view_avatars'], 'VIEW_WORDCENSOR' => $data['view_wordcensor'], 'S_TOPIC_SORT_DAYS' => $s_limit_topic_days, 'S_TOPIC_SORT_KEY' => $s_sort_topic_key, 'S_TOPIC_SORT_DIR' => $s_sort_topic_dir, 'S_POST_SORT_DAYS' => $s_limit_post_days, 'S_POST_SORT_KEY' => $s_sort_post_key, 'S_POST_SORT_DIR' => $s_sort_post_dir, 'DATE_FORMAT' => $data['dateformat'], 'S_DATEFORMAT_OPTIONS' => $dateformat_options, 'S_CUSTOM_DATEFORMAT' => $s_custom, 'DEFAULT_DATEFORMAT' => $config['default_dateformat'], 'A_DEFAULT_DATEFORMAT' => addslashes($config['default_dateformat']), 'S_LANG_OPTIONS' => language_select($data['lang']), 'S_STYLE_OPTIONS' => style_select($data['style']));
                /**
                 * Modify users preferences data before assigning it to the template
                 *
                 * @event core.acp_users_prefs_modify_template_data
                 * @var	array	data				Array with users preferences data
                 * @var	array	user_row			Array with user data
                 * @var	array	user_prefs_data		Array with users preferences data to be assigned to the template
                 * @since 3.1.0-b3
                 */
                $vars = array('data', 'user_row', 'user_prefs_data');
                extract($phpbb_dispatcher->trigger_event('core.acp_users_prefs_modify_template_data', compact($vars)));
                $template->assign_vars($user_prefs_data);
                break;
            case 'avatar':
                $avatars_enabled = false;
                /** @var \phpbb\avatar\manager $phpbb_avatar_manager */
                $phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
                if ($config['allow_avatar']) {
                    $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers();
                    // This is normalised data, without the user_ prefix
                    $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user');
                    if ($submit) {
                        if (check_form_key($form_name)) {
                            $driver_name = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', ''));
                            if (in_array($driver_name, $avatar_drivers) && !$request->is_set_post('avatar_delete')) {
                                $driver = $phpbb_avatar_manager->get_driver($driver_name);
                                $result = $driver->process_form($request, $template, $user, $avatar_data, $error);
                                if ($result && empty($error)) {
                                    // Success! Lets save the result in the database
                                    $result = array('user_avatar_type' => $driver_name, 'user_avatar' => $result['avatar'], 'user_avatar_width' => $result['avatar_width'], 'user_avatar_height' => $result['avatar_height']);
                                    $sql = 'UPDATE ' . USERS_TABLE . '
										SET ' . $db->sql_build_array('UPDATE', $result) . '
										WHERE user_id = ' . (int) $user_id;
                                    $db->sql_query($sql);
                                    trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                                }
                            }
                        } else {
                            trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                    }
                    // Handle deletion of avatars
                    if ($request->is_set_post('avatar_delete')) {
                        if (!confirm_box(true)) {
                            confirm_box(false, $user->lang('CONFIRM_AVATAR_DELETE'), build_hidden_fields(array('avatar_delete' => true)));
                        } else {
                            $phpbb_avatar_manager->handle_avatar_delete($db, $user, $avatar_data, USERS_TABLE, 'user_');
                            trigger_error($user->lang['USER_AVATAR_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                        }
                    }
                    $selected_driver = $phpbb_avatar_manager->clean_driver_name($request->variable('avatar_driver', $user_row['user_avatar_type']));
                    // Assign min and max values before generating avatar driver html
                    $template->assign_vars(array('AVATAR_MIN_WIDTH' => $config['avatar_min_width'], 'AVATAR_MAX_WIDTH' => $config['avatar_max_width'], 'AVATAR_MIN_HEIGHT' => $config['avatar_min_height'], 'AVATAR_MAX_HEIGHT' => $config['avatar_max_height']));
                    foreach ($avatar_drivers as $current_driver) {
                        $driver = $phpbb_avatar_manager->get_driver($current_driver);
                        $avatars_enabled = true;
                        $template->set_filenames(array('avatar' => $driver->get_acp_template_name()));
                        if ($driver->prepare_form($request, $template, $user, $avatar_data, $error)) {
                            $driver_name = $phpbb_avatar_manager->prepare_driver_name($current_driver);
                            $driver_upper = strtoupper($driver_name);
                            $template->assign_block_vars('avatar_drivers', array('L_TITLE' => $user->lang($driver_upper . '_TITLE'), 'L_EXPLAIN' => $user->lang($driver_upper . '_EXPLAIN'), 'DRIVER' => $driver_name, 'SELECTED' => $current_driver == $selected_driver, 'OUTPUT' => $template->assign_display('avatar')));
                        }
                    }
                }
                // Avatar manager is not initialized if avatars are disabled
                if (isset($phpbb_avatar_manager)) {
                    // Replace "error" strings with their real, localised form
                    $error = $phpbb_avatar_manager->localize_errors($user, $error);
                }
                $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true);
                $template->assign_vars(array('S_AVATAR' => true, 'ERROR' => !empty($error) ? implode('<br />', $error) : '', 'AVATAR' => empty($avatar) ? '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />' : $avatar, 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), 'S_AVATARS_ENABLED' => $config['allow_avatar'] && $avatars_enabled));
                break;
            case 'rank':
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $rank_id = $request->variable('user_rank', 0);
                    $sql = 'UPDATE ' . USERS_TABLE . "\n\t\t\t\t\t\tSET user_rank = {$rank_id}\n\t\t\t\t\t\tWHERE user_id = {$user_id}";
                    $db->sql_query($sql);
                    trigger_error($user->lang['USER_RANK_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                }
                $sql = 'SELECT *
					FROM ' . RANKS_TABLE . '
					WHERE rank_special = 1
					ORDER BY rank_title';
                $result = $db->sql_query($sql);
                $s_rank_options = '<option value="0"' . (!$user_row['user_rank'] ? ' selected="selected"' : '') . '>' . $user->lang['NO_SPECIAL_RANK'] . '</option>';
                while ($row = $db->sql_fetchrow($result)) {
                    $selected = $user_row['user_rank'] && $row['rank_id'] == $user_row['user_rank'] ? ' selected="selected"' : '';
                    $s_rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
                }
                $db->sql_freeresult($result);
                $template->assign_vars(array('S_RANK' => true, 'S_RANK_OPTIONS' => $s_rank_options));
                break;
            case 'sig':
                if (!function_exists('display_custom_bbcodes')) {
                    include $phpbb_root_path . 'includes/functions_display.' . $phpEx;
                }
                $enable_bbcode = $config['allow_sig_bbcode'] ? $this->optionget($user_row, 'sig_bbcode') : false;
                $enable_smilies = $config['allow_sig_smilies'] ? $this->optionget($user_row, 'sig_smilies') : false;
                $enable_urls = $config['allow_sig_links'] ? $this->optionget($user_row, 'sig_links') : false;
                $decoded_message = generate_text_for_edit($user_row['user_sig'], $user_row['user_sig_bbcode_uid'], $user_row['user_sig_bbcode_bitfield']);
                $signature = $request->variable('signature', $decoded_message['text'], true);
                $signature_preview = '';
                if ($submit || $request->is_set_post('preview')) {
                    $enable_bbcode = $config['allow_sig_bbcode'] ? !$request->variable('disable_bbcode', false) : false;
                    $enable_smilies = $config['allow_sig_smilies'] ? !$request->variable('disable_smilies', false) : false;
                    $enable_urls = $config['allow_sig_links'] ? !$request->variable('disable_magic_url', false) : false;
                    if (!check_form_key($form_name)) {
                        $error[] = 'FORM_INVALID';
                    }
                }
                $bbcode_uid = $bbcode_bitfield = $bbcode_flags = '';
                $warn_msg = generate_text_for_storage($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags, $enable_bbcode, $enable_urls, $enable_smilies, $config['allow_sig_img'], $config['allow_sig_flash'], true, $config['allow_sig_links'], 'sig');
                if (sizeof($warn_msg)) {
                    $error += $warn_msg;
                }
                if (!$submit) {
                    // Parse it for displaying
                    $signature_preview = generate_text_for_display($signature, $bbcode_uid, $bbcode_bitfield, $bbcode_flags);
                } else {
                    if (!sizeof($error)) {
                        $this->optionset($user_row, 'sig_bbcode', $enable_bbcode);
                        $this->optionset($user_row, 'sig_smilies', $enable_smilies);
                        $this->optionset($user_row, 'sig_links', $enable_urls);
                        $sql_ary = array('user_sig' => $signature, 'user_options' => $user_row['user_options'], 'user_sig_bbcode_uid' => $bbcode_uid, 'user_sig_bbcode_bitfield' => $bbcode_bitfield);
                        $sql = 'UPDATE ' . USERS_TABLE . '
							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
							WHERE user_id = ' . $user_id;
                        $db->sql_query($sql);
                        trigger_error($user->lang['USER_SIG_UPDATED'] . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    }
                }
                // Replace "error" strings with their real, localised form
                $error = array_map(array($user, 'lang'), $error);
                if ($request->is_set_post('preview')) {
                    $decoded_message = generate_text_for_edit($signature, $bbcode_uid, $bbcode_bitfield);
                }
                /** @var \phpbb\controller\helper $controller_helper */
                $controller_helper = $phpbb_container->get('controller.helper');
                $template->assign_vars(array('S_SIGNATURE' => true, 'SIGNATURE' => $decoded_message['text'], 'SIGNATURE_PREVIEW' => $signature_preview, 'S_BBCODE_CHECKED' => !$enable_bbcode ? ' checked="checked"' : '', 'S_SMILIES_CHECKED' => !$enable_smilies ? ' checked="checked"' : '', 'S_MAGIC_URL_CHECKED' => !$enable_urls ? ' checked="checked"' : '', 'BBCODE_STATUS' => $user->lang($config['allow_sig_bbcode'] ? 'BBCODE_IS_ON' : 'BBCODE_IS_OFF', '<a href="' . $controller_helper->route('phpbb_help_bbcode_controller') . '">', '</a>'), 'SMILIES_STATUS' => $config['allow_sig_smilies'] ? $user->lang['SMILIES_ARE_ON'] : $user->lang['SMILIES_ARE_OFF'], 'IMG_STATUS' => $config['allow_sig_img'] ? $user->lang['IMAGES_ARE_ON'] : $user->lang['IMAGES_ARE_OFF'], 'FLASH_STATUS' => $config['allow_sig_flash'] ? $user->lang['FLASH_IS_ON'] : $user->lang['FLASH_IS_OFF'], 'URL_STATUS' => $config['allow_sig_links'] ? $user->lang['URL_IS_ON'] : $user->lang['URL_IS_OFF'], 'L_SIGNATURE_EXPLAIN' => $user->lang('SIGNATURE_EXPLAIN', (int) $config['max_sig_chars']), 'S_BBCODE_ALLOWED' => $config['allow_sig_bbcode'], 'S_SMILIES_ALLOWED' => $config['allow_sig_smilies'], 'S_BBCODE_IMG' => $config['allow_sig_img'] ? true : false, 'S_BBCODE_FLASH' => $config['allow_sig_flash'] ? true : false, 'S_LINKS_ALLOWED' => $config['allow_sig_links'] ? true : false));
                // Assigning custom bbcodes
                display_custom_bbcodes();
                break;
            case 'attach':
                /* @var $pagination \phpbb\pagination */
                $pagination = $phpbb_container->get('pagination');
                $start = $request->variable('start', 0);
                $deletemark = isset($_POST['delmarked']) ? true : false;
                $marked = $request->variable('mark', array(0));
                // Sort keys
                $sort_key = $request->variable('sk', 'a');
                $sort_dir = $request->variable('sd', 'd');
                if ($deletemark && sizeof($marked)) {
                    $sql = 'SELECT attach_id
						FROM ' . ATTACHMENTS_TABLE . '
						WHERE poster_id = ' . $user_id . '
							AND is_orphan = 0
							AND ' . $db->sql_in_set('attach_id', $marked);
                    $result = $db->sql_query($sql);
                    $marked = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $marked[] = $row['attach_id'];
                    }
                    $db->sql_freeresult($result);
                }
                if ($deletemark && sizeof($marked)) {
                    if (confirm_box(true)) {
                        $sql = 'SELECT real_filename
							FROM ' . ATTACHMENTS_TABLE . '
							WHERE ' . $db->sql_in_set('attach_id', $marked);
                        $result = $db->sql_query($sql);
                        $log_attachments = array();
                        while ($row = $db->sql_fetchrow($result)) {
                            $log_attachments[] = $row['real_filename'];
                        }
                        $db->sql_freeresult($result);
                        /** @var \phpbb\attachment\manager $attachment_manager */
                        $attachment_manager = $phpbb_container->get('attachment.manager');
                        $attachment_manager->delete('attach', $marked);
                        unset($attachment_manager);
                        $message = sizeof($log_attachments) == 1 ? $user->lang['ATTACHMENT_DELETED'] : $user->lang['ATTACHMENTS_DELETED'];
                        $phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'LOG_ATTACHMENTS_DELETED', false, array(implode($user->lang['COMMA_SEPARATOR'], $log_attachments)));
                        trigger_error($message . adm_back_link($this->u_action . '&amp;u=' . $user_id));
                    } else {
                        confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'delmarked' => true, 'mark' => $marked)));
                    }
                }
                $sk_text = array('a' => $user->lang['SORT_FILENAME'], 'c' => $user->lang['SORT_EXTENSION'], 'd' => $user->lang['SORT_SIZE'], 'e' => $user->lang['SORT_DOWNLOADS'], 'f' => $user->lang['SORT_POST_TIME'], 'g' => $user->lang['SORT_TOPIC_TITLE']);
                $sk_sql = array('a' => 'a.real_filename', 'c' => 'a.extension', 'd' => 'a.filesize', 'e' => 'a.download_count', 'f' => 'a.filetime', 'g' => 't.topic_title');
                $sd_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
                $s_sort_key = '';
                foreach ($sk_text as $key => $value) {
                    $selected = $sort_key == $key ? ' selected="selected"' : '';
                    $s_sort_key .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                $s_sort_dir = '';
                foreach ($sd_text as $key => $value) {
                    $selected = $sort_dir == $key ? ' selected="selected"' : '';
                    $s_sort_dir .= '<option value="' . $key . '"' . $selected . '>' . $value . '</option>';
                }
                if (!isset($sk_sql[$sort_key])) {
                    $sort_key = 'a';
                }
                $order_by = $sk_sql[$sort_key] . ' ' . ($sort_dir == 'a' ? 'ASC' : 'DESC');
                $sql = 'SELECT COUNT(attach_id) as num_attachments
					FROM ' . ATTACHMENTS_TABLE . "\n\t\t\t\t\tWHERE poster_id = {$user_id}\n\t\t\t\t\t\tAND is_orphan = 0";
                $result = $db->sql_query_limit($sql, 1);
                $num_attachments = (int) $db->sql_fetchfield('num_attachments');
                $db->sql_freeresult($result);
                $sql = 'SELECT a.*, t.topic_title, p.message_subject as message_title
					FROM ' . ATTACHMENTS_TABLE . ' a
						LEFT JOIN ' . TOPICS_TABLE . ' t ON (a.topic_id = t.topic_id
							AND a.in_message = 0)
						LEFT JOIN ' . PRIVMSGS_TABLE . ' p ON (a.post_msg_id = p.msg_id
							AND a.in_message = 1)
					WHERE a.poster_id = ' . $user_id . "\n\t\t\t\t\t\tAND a.is_orphan = 0\n\t\t\t\t\tORDER BY {$order_by}";
                $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
                while ($row = $db->sql_fetchrow($result)) {
                    if ($row['in_message']) {
                        $view_topic = append_sid("{$phpbb_root_path}ucp.{$phpEx}", "i=pm&amp;p={$row['post_msg_id']}");
                    } else {
                        $view_topic = append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_msg_id']}") . '#p' . $row['post_msg_id'];
                    }
                    $template->assign_block_vars('attach', array('REAL_FILENAME' => $row['real_filename'], 'COMMENT' => nl2br($row['attach_comment']), 'EXTENSION' => $row['extension'], 'SIZE' => get_formatted_filesize($row['filesize']), 'DOWNLOAD_COUNT' => $row['download_count'], 'POST_TIME' => $user->format_date($row['filetime']), 'TOPIC_TITLE' => $row['in_message'] ? $row['message_title'] : $row['topic_title'], 'ATTACH_ID' => $row['attach_id'], 'POST_ID' => $row['post_msg_id'], 'TOPIC_ID' => $row['topic_id'], 'S_IN_MESSAGE' => $row['in_message'], 'U_DOWNLOAD' => append_sid("{$phpbb_root_path}download/file.{$phpEx}", 'mode=view&amp;id=' . $row['attach_id']), 'U_VIEW_TOPIC' => $view_topic));
                }
                $db->sql_freeresult($result);
                $base_url = $this->u_action . "&amp;u={$user_id}&amp;sk={$sort_key}&amp;sd={$sort_dir}";
                $pagination->generate_template_pagination($base_url, 'pagination', 'start', $num_attachments, $config['topics_per_page'], $start);
                $template->assign_vars(array('S_ATTACHMENTS' => true, 'S_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir));
                break;
            case 'groups':
                if (!function_exists('group_user_attributes')) {
                    include $phpbb_root_path . 'includes/functions_user.' . $phpEx;
                }
                $user->add_lang(array('groups', 'acp/groups'));
                $group_id = $request->variable('g', 0);
                if ($group_id) {
                    // Check the founder only entry for this group to make sure everything is well
                    $sql = 'SELECT group_founder_manage
						FROM ' . GROUPS_TABLE . '
						WHERE group_id = ' . $group_id;
                    $result = $db->sql_query($sql);
                    $founder_manage = (int) $db->sql_fetchfield('group_founder_manage');
                    $db->sql_freeresult($result);
                    if ($user->data['user_type'] != USER_FOUNDER && $founder_manage) {
                        trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                }
                switch ($action) {
                    case 'demote':
                    case 'promote':
                    case 'default':
                        if (!$group_id) {
                            trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                        }
                        group_user_attributes($action, $group_id, $user_id);
                        if ($action == 'default') {
                            $user_row['group_id'] = $group_id;
                        }
                        break;
                    case 'delete':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            if ($error = group_user_del($group_id, $user_id)) {
                                trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            $error = array();
                            // The delete action was successful - therefore update the user row...
                            $sql = 'SELECT u.*, s.*
								FROM ' . USERS_TABLE . ' u
									LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id)
								WHERE u.user_id = ' . $user_id . '
								ORDER BY s.session_time DESC';
                            $result = $db->sql_query_limit($sql, 1);
                            $user_row = $db->sql_fetchrow($result);
                            $db->sql_freeresult($result);
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                    case 'approve':
                        if (confirm_box(true)) {
                            if (!$group_id) {
                                trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                            }
                            group_user_attributes($action, $group_id, $user_id);
                        } else {
                            confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('u' => $user_id, 'i' => $id, 'mode' => $mode, 'action' => $action, 'g' => $group_id)));
                        }
                        break;
                }
                // Add user to group?
                if ($submit) {
                    if (!check_form_key($form_name)) {
                        trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    if (!$group_id) {
                        trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    // Add user/s to group
                    if ($error = group_user_add($group_id, $user_id)) {
                        trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;u=' . $user_id), E_USER_WARNING);
                    }
                    $error = array();
                }
                /** @var \phpbb\group\helper $group_helper */
                $group_helper = $phpbb_container->get('group_helper');
                $sql = 'SELECT ug.*, g.*
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . " ug\n\t\t\t\t\tWHERE ug.user_id = {$user_id}\n\t\t\t\t\t\tAND g.group_id = ug.group_id\n\t\t\t\t\tORDER BY g.group_type DESC, ug.user_pending ASC, g.group_name";
                $result = $db->sql_query($sql);
                $i = 0;
                $group_data = $id_ary = array();
                while ($row = $db->sql_fetchrow($result)) {
                    $type = $row['group_type'] == GROUP_SPECIAL ? 'special' : ($row['user_pending'] ? 'pending' : 'normal');
                    $group_data[$type][$i]['group_id'] = $row['group_id'];
                    $group_data[$type][$i]['group_name'] = $row['group_name'];
                    $group_data[$type][$i]['group_leader'] = $row['group_leader'] ? 1 : 0;
                    $id_ary[] = $row['group_id'];
                    $i++;
                }
                $db->sql_freeresult($result);
                // Select box for other groups
                $sql = 'SELECT group_id, group_name, group_type, group_founder_manage
					FROM ' . GROUPS_TABLE . '
					' . (sizeof($id_ary) ? 'WHERE ' . $db->sql_in_set('group_id', $id_ary, true) : '') . '
					ORDER BY group_type DESC, group_name ASC';
                $result = $db->sql_query($sql);
                $s_group_options = '';
                while ($row = $db->sql_fetchrow($result)) {
                    if (!$config['coppa_enable'] && $row['group_name'] == 'REGISTERED_COPPA') {
                        continue;
                    }
                    // Do not display those groups not allowed to be managed
                    if ($user->data['user_type'] != USER_FOUNDER && $row['group_founder_manage']) {
                        continue;
                    }
                    $s_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . $group_helper->get_name($row['group_name']) . '</option>';
                }
                $db->sql_freeresult($result);
                $current_type = '';
                foreach ($group_data as $group_type => $data_ary) {
                    if ($current_type != $group_type) {
                        $template->assign_block_vars('group', array('S_NEW_GROUP_TYPE' => true, 'GROUP_TYPE' => $user->lang['USER_GROUP_' . strtoupper($group_type)]));
                    }
                    foreach ($data_ary as $data) {
                        $template->assign_block_vars('group', array('U_EDIT_GROUP' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i=groups&amp;mode=manage&amp;action=edit&amp;u={$user_id}&amp;g={$data['group_id']}&amp;back_link=acp_users_groups"), 'U_DEFAULT' => $this->u_action . "&amp;action=default&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DEMOTE_PROMOTE' => $this->u_action . '&amp;action=' . ($data['group_leader'] ? 'demote' : 'promote') . "&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_DELETE' => $this->u_action . "&amp;action=delete&amp;u={$user_id}&amp;g=" . $data['group_id'], 'U_APPROVE' => $group_type == 'pending' ? $this->u_action . "&amp;action=approve&amp;u={$user_id}&amp;g=" . $data['group_id'] : '', 'GROUP_NAME' => $group_type == 'special' ? $user->lang['G_' . $data['group_name']] : $data['group_name'], 'L_DEMOTE_PROMOTE' => $data['group_leader'] ? $user->lang['GROUP_DEMOTE'] : $user->lang['GROUP_PROMOTE'], 'S_IS_MEMBER' => $group_type != 'pending' ? true : false, 'S_NO_DEFAULT' => $user_row['group_id'] != $data['group_id'] ? true : false, 'S_SPECIAL_GROUP' => $group_type == 'special' ? true : false));
                    }
                }
                $template->assign_vars(array('S_GROUPS' => true, 'S_GROUP_OPTIONS' => $s_group_options));
                break;
            case 'perm':
                if (!class_exists('auth_admin')) {
                    include $phpbb_root_path . 'includes/acp/auth.' . $phpEx;
                }
                $auth_admin = new auth_admin();
                $user->add_lang('acp/permissions');
                add_permission_language();
                $forum_id = $request->variable('f', 0);
                // Global Permissions
                if (!$forum_id) {
                    // Select auth options
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . '
						WHERE auth_option ' . $db->sql_like_expression($db->get_any_char() . '_') . '
							AND is_global = 1
						ORDER BY auth_option';
                    $result = $db->sql_query($sql);
                    $hold_ary = array();
                    while ($row = $db->sql_fetchrow($result)) {
                        $hold_ary = $auth_admin->get_mask('view', $user_id, false, false, $row['auth_option'], 'global', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', false, false);
                    }
                    $db->sql_freeresult($result);
                    unset($hold_ary);
                } else {
                    $sql = 'SELECT auth_option, is_local, is_global
						FROM ' . ACL_OPTIONS_TABLE . "\n\t\t\t\t\t\tWHERE auth_option " . $db->sql_like_expression($db->get_any_char() . '_') . "\n\t\t\t\t\t\t\tAND is_local = 1\n\t\t\t\t\t\tORDER BY is_global DESC, auth_option";
                    $result = $db->sql_query($sql);
                    while ($row = $db->sql_fetchrow($result)) {
                        $hold_ary = $auth_admin->get_mask('view', $user_id, false, $forum_id, $row['auth_option'], 'local', ACL_NEVER);
                        $auth_admin->display_mask('view', $row['auth_option'], $hold_ary, 'user', true, false);
                    }
                    $db->sql_freeresult($result);
                }
                $s_forum_options = '<option value="0"' . (!$forum_id ? ' selected="selected"' : '') . '>' . $user->lang['VIEW_GLOBAL_PERMS'] . '</option>';
                $s_forum_options .= make_forum_select($forum_id, false, true, false, false, false);
                $template->assign_vars(array('S_PERMISSIONS' => true, 'S_GLOBAL' => !$forum_id ? true : false, 'S_FORUM_OPTIONS' => $s_forum_options, 'U_ACTION' => $this->u_action . '&amp;u=' . $user_id, 'U_USER_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_global&amp;user_id[]=' . $user_id), 'U_USER_FORUM_PERMISSIONS' => append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions&amp;mode=setting_user_local&amp;user_id[]=' . $user_id)));
                break;
        }
        // Assign general variables
        $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : ''));
    }
예제 #28
0
$users_ary = array();
$poster = $post_info['user_colour'] ? '<span style="color:#' . $post_info['user_colour'] . '">' . $post_info['username'] . '</span>' : $post_info['username'];
// Process message, leave it uncensored
$message = $post_info['post_text'];
if ($post_info['bbcode_bitfield']) {
    require_once SITE_FILE_ROOT . 'includes/forums/bbcode.php';
    $bbcode = new bbcode($post_info['bbcode_bitfield']);
    $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
}
$message = smiley_text($message);
$message = str_replace("\n", '<br />', $message);
$_CLASS['core_template']->assign_array(array('U_MCP_ACTION' => generate_link($url . '&amp;quickmod=1'), 'U_POST_ACTION' => generate_link("{$url}&amp;mode=post_details"), 'U_APPROVE_ACTION' => generate_link('forums&amp;file=mcp&amp;i=queue&amp;p=' . $post_info['post_id']), 'S_CAN_VIEWIP' => $_CLASS['forums_auth']->acl_get('m_ip', $post_info['forum_id']), 'S_CAN_CHGPOSTER' => $_CLASS['forums_auth']->acl_get('m_', $post_info['forum_id']), 'S_CAN_LOCK_POST' => $_CLASS['forums_auth']->acl_get('m_lock', $post_info['forum_id']), 'S_CAN_DELETE_POST' => $_CLASS['forums_auth']->acl_get('m_delete', $post_info['forum_id']), 'S_POST_REPORTED' => $post_info['post_reported'], 'S_POST_UNAPPROVED' => !$post_info['post_approved'], 'S_POST_LOCKED' => $post_info['post_edit_locked'], 'S_USER_NOTES' => true, 'S_CLEAR_ALLOWED' => $_CLASS['forums_auth']->acl_get('a_clearlogs'), 'U_EDIT' => $_CLASS['forums_auth']->acl_get('m_edit', $post_info['forum_id']) ? generate_link("forums&amp;file=posting&amp;mode=edit&amp;p={$post_info['post_id']}") : '', 'U_FIND_MEMBER' => generate_link('members_list&amp;mode=search_user&amp;form=mcp_chgposter&amp;field=username'), 'U_MCP_APPROVE' => generate_link('forums&amp;file=mcp&amp;i=queue&amp;mode=approve_details&amp;p=' . $post_info['post_id']), 'U_MCP_REPORT' => generate_link('forums&amp;file=mcp&amp;i=reports&amp;mode=report_details&amp;p=' . $post_info['post_id']), 'U_MCP_USER_NOTES' => generate_link('forums&amp;file=mcp&amp;i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']), 'U_MCP_WARN_USER' => $_CLASS['forums_auth']->acl_get('m_warn') ? generate_link('forums&amp;file=mcp&amp;i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '', 'U_VIEW_POST' => generate_link('forums&amp;file=viewtopic&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']), 'U_VIEW_PROFILE' => generate_link('members_list&amp;mode=viewprofile&amp;u=' . $post_info['user_id']), 'U_VIEW_TOPIC' => generate_link('forums&amp;file=viewtopic&amp;t=' . $post_info['topic_id']), 'RETURN_TOPIC' => sprintf($_CLASS['core_user']->lang['RETURN_TOPIC'], '<a href="' . generate_link("forums&amp;file=viewtopic&amp;p={$post_info['post_id']}#{$post_info['post_id']}") . '">', '</a>'), 'RETURN_FORUM' => sprintf($_CLASS['core_user']->lang['RETURN_FORUM'], '<a href="' . generate_link("forums&amp;file=viewforum&amp;f={$post_info['forum_id']}&amp;start={$start}") . '">', '</a>'), 'REPORTED_IMG' => $_CLASS['core_user']->img('icon_reported', $_CLASS['core_user']->lang['POST_REPORTED']), 'UNAPPROVED_IMG' => $_CLASS['core_user']->img('icon_unapproved', $_CLASS['core_user']->lang['POST_UNAPPROVED']), 'EDIT_IMG' => $_CLASS['core_user']->img('btn_edit', $_CLASS['core_user']->lang['EDIT_POST']), 'SEARCH_IMG' => $_CLASS['core_user']->img('btn_search', 'SEARCH_USER_POSTS'), 'POSTER_NAME' => $poster, 'POST_PREVIEW' => $message, 'POST_SUBJECT' => $post_info['post_subject'], 'POST_DATE' => $_CLASS['core_user']->format_date($post_info['post_time']), 'POST_IP' => $post_info['poster_ip'], 'POST_IPADDR' => @gethostbyaddr($post_info['poster_ip']), 'POST_ID' => $post_info['post_id']));
// Get User Notes
$log_data = array();
$log_count = 0;
view_log('user', $log_data, $log_count, $config['posts_per_page'], 0, 0, 0, $post_info['user_id']);
if ($log_count) {
    $_CLASS['core_template']->assign('S_USER_NOTES', true);
    foreach ($log_data as $row) {
        $_CLASS['core_template']->assign_vars_array('usernotes', array('REPORT_BY' => $row['username'], 'REPORT_AT' => $_CLASS['core_user']->format_date($row['time']), 'ACTION' => $row['action'], 'ID' => $row['id']));
    }
}
// Get Reports
/*
if ($_CLASS['forums_auth']->acl_get('m_', $post_info['forum_id']))
{
	$sql = 'SELECT r.*, re.*, u.user_id, u.username 
		FROM ' . FORUMS_REPORTS_TABLE . ' r, ' . CORE_USERS_TABLE . ' u, ' . DORUMS_REPORTS_REASONS_TABLE . " re
		WHERE r.post_id = $post_id
			AND r.reason_id = re.reason_id
			AND u.user_id = r.user_id