function main($id, $mode)
 {
     global $db, $user, $auth, $template, $cache;
     global $config, $phpbb_root_path, $phpEx;
     $user->add_lang(array('acp/board', 'mods/asacp', 'mods/acp_asacp', 'install', 'acp/common'));
     include $phpbb_root_path . 'antispam/acp_functions.' . $phpEx;
     $error = $notify = array();
     $submit = isset($_POST['submit']) ? true : false;
     $action = request_var('action', '');
     add_form_key('as_acp');
     if ($submit && !check_form_key('as_acp')) {
         trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
     }
     $error = $options = array();
     switch ($mode) {
         case 'ip_search':
             $this->tpl_name = 'antispam/mcp_asacp';
             $this->page_title = 'ASACP_IP_SEARCH';
             $ip = request_var('ip', '');
             $type = request_var('type', '');
             if ($ip) {
                 asacp_display_ip_search($type, $ip, $this->u_action . '&ip=' . $ip, request_var('start', 0));
             }
             $template->assign_vars(array('L_TITLE' => $user->lang['ASACP_IP_SEARCH'], 'L_TITLE_EXPLAIN' => $user->lang['ASACP_IP_SEARCH_EXPLAIN'], 'S_DATA_OUTPUT' => true, 'S_DISPLAY_IP_INPUT' => $ip ? false : true, 'U_BACK' => $type ? $this->u_action . '&ip=' . $ip : false, 'U_BACK_NONE' => $this->u_action));
             break;
             // case 'ip_search' :
         // case 'ip_search' :
         case 'log':
         case 'flag':
             $this->tpl_name = 'mcp_logs';
             if ($mode == 'log') {
                 $this->page_title = $user->lang['ASACP_SPAM_LOG'];
             } else {
                 $this->page_title = $user->lang['ASACP_FLAG_LOG'];
                 // Reset the user flag new notification
                 if ($user->data['user_flag_new']) {
                     $db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_flag_new = 0 WHERE user_id = ' . $user->data['user_id']);
                 }
             }
             $user->add_lang('mcp');
             // Set up general vars
             $start = request_var('start', 0);
             $action = request_var('action', array('' => ''));
             if (is_array($action)) {
                 list($action, ) = each($action);
             } else {
                 $action = request_var('action', '');
             }
             $deletemark = !empty($_POST['delmarked']) || $action == 'del_marked' ? true : false;
             $deleteall = !empty($_POST['delall']) || $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');
             $keywords = utf8_normalize_nfc(request_var('keywords', '', true));
             $keywords_param = !empty($keywords) ? '&keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';
             // Delete entries if requested and able
             if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs')) {
                 if (confirm_box(true)) {
                     clear_spam_log($mode, $deletemark ? false : $deleteall, $marked, $keywords);
                 } 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, 'keywords' => $keywords, 'i' => $id, 'mode' => $mode, 'action' => $this->u_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('t' => $user->lang['SORT_DATE'], 'u' => $user->lang['SORT_USERNAME'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
             $sort_by_sql = array('t' => 'l.log_time', 'u' => 'u.username_clean', '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_days = $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;
             if ($mode == 'log') {
                 view_spam_log('spam', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
             } else {
                 view_spam_log('flag', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
             }
             $template->assign_vars(array('L_TITLE' => $this->page_title, 'L_EXPLAIN' => '', 'S_ON_PAGE' => on_page($log_count, $config['topics_per_page'], $start), 'PAGE_NUMBER' => on_page($log_count, $config['topics_per_page'], $start), 'PAGINATION' => generate_pagination($this->u_action . "&{$u_sort_param}{$keywords_param}", $log_count, $config['topics_per_page'], $start), 'TOTAL' => $log_count == 1 ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count), 'S_LIMIT_DAYS' => $s_limit_days, 'S_SELECT_SORT_DAYS' => $s_limit_days, 'S_SORT_KEY' => $s_sort_key, 'S_SELECT_SORT_KEY' => $s_sort_key, 'S_SORT_DIR' => $s_sort_dir, 'S_SELECT_SORT_DIR' => $s_sort_dir, 'S_CLEARLOGS' => $auth->acl_get('a_clearlogs'), 'S_CLEAR_ALLOWED' => $auth->acl_get('a_clearlogs'), 'S_KEYWORDS' => $keywords, 'S_LOGS' => $log_count > 0 ? true : false));
             foreach ($log_data as $row) {
                 $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' => '<a href="' . append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode=ip_search&amp;ip={$row['ip']}") . '">' . $row['ip'] . '</a>', 'DATE' => $user->format_date($row['time']), 'ACTION' => $row['action'], 'DATA' => sizeof($row['data']) ? @vsprintf($user->lang[$row['operation'] . '_DATA'], $row['data']) : '', 'ID' => $row['id']));
             }
             break;
             //case 'log' :
             //case 'flag' :
         //case 'log' :
         //case 'flag' :
         case 'flag_list':
             $user->add_lang('memberlist');
             $this->tpl_name = 'antispam/mcp_asacp';
             $this->page_title = 'ASACP_FLAG_LIST';
             $start = request_var('start', 0);
             $limit = request_var('limit', 20);
             $db->sql_query('SELECT count(user_id) as cnt FROM ' . USERS_TABLE . ' WHERE user_flagged = 1');
             $total = $db->sql_fetchfield('cnt');
             $sql = 'SELECT user_id, username, user_colour, user_ip, user_posts FROM ' . USERS_TABLE . ' WHERE user_flagged = 1';
             $result = $db->sql_query_limit($sql, $limit, $start);
             $cnt = 0;
             $output = '';
             while ($row = $db->sql_fetchrow($result)) {
                 $row['username'] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
                 if ($auth->acl_get('m_asacp_ip_search')) {
                     $row['user_ip'] = '<a href="' . append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i={$id}&amp;mode=ip_search&amp;ip={$row['user_ip']}") . '">' . $row['user_ip'] . '</a>';
                 }
                 if ($auth->acl_get('a_user')) {
                     $row[$user->lang['ACTION']] = '<a href="' . append_sid("{$phpbb_root_path}adm/index.{$phpEx}", "i=users&amp;mode=overview&amp;u={$row['user_id']}", true, $user->session_id) . '">' . $user->lang['USER_ADMIN'] . '</a>';
                 }
                 unset($row['user_id'], $row['user_colour']);
                 $cnt++;
                 if ($cnt == 1) {
                     $output .= asacp_display_table_head($row);
                 }
                 $output .= asacp_display_table_row($row, $cnt);
             }
             $db->sql_freeresult($result);
             $template->assign_vars(array('L_TITLE' => $user->lang['ASACP_FLAG_LIST'], 'L_TITLE_EXPLAIN' => $user->lang['ASACP_FLAG_LIST_EXPLAIN'], 'S_DATA_OUTPUT' => true));
             $template->assign_block_vars('data_output', array('TITLE' => $user->lang['USERS'], 'DATA' => $output, 'PAGINATION' => $total ? generate_pagination($this->u_action . "&amp;limit={$limit}", $total, $limit, $start, false, 'data_output') : ''));
             break;
             //case 'flag_list' :
         //case 'flag_list' :
         default:
             trigger_error('NO_MODE');
             break;
     }
     // switch($mode)
     // Display the options if there are any (setup similar to acp_board)
     if (sizeof($options)) {
         asacp_display_options($options, $error, $this->u_action);
     }
     $template->assign_vars(array('ERROR' => implode('<br />', $error), 'U_ACTION' => $this->u_action, 'U_POST_ACTION' => $this->u_action));
 }
	function main($id, $mode)
	{
		global $db, $user, $auth, $template, $cache;
		global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;

		$user->add_lang(array('acp/board', 'mods/asacp', 'mods/acp_asacp', 'install'));
		include($phpbb_root_path . 'antispam/acp_functions.' . $phpEx);

		$error = $notify = array();
		$submit = (isset($_POST['submit'])) ? true : false;
		$action = request_var('action', '');

		add_form_key('as_acp');
		if ($submit && !check_form_key('as_acp'))
		{
			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
		}

		$error = $options = array();

		switch ($mode)
		{
			case 'spam_words' :
				$this->tpl_name = 'acp_asacp';
				$this->page_title = 'ASACP_SPAM_WORDS';

				$word_id = request_var('w', 0);
				$word_data = array(
					'word_text'			=> utf8_normalize_nfc(request_var('word_text', '', true)),
					'word_regex'		=> request_var('word_regex', 0),
					'word_regex_auto'	=> request_var('word_regex_auto', 0),
				);
				switch ($action)
				{
					case 'edit' :
						if (!$word_id)
						{
							trigger_error('NO_SPAM_WORD');
						}
						$result = $db->sql_query('SELECT * FROM ' . SPAM_WORDS_TABLE . ' WHERE word_id = ' . $word_id);
						$word = $db->sql_fetchrow($result);
						if (!$word)
						{
                            trigger_error('NO_SPAM_WORD');
						}

						if (!$submit)
						{
							$word_data = $word;
						}
					case 'add' :
						$template->assign_vars(array(
							'WORD_TEXT'			=> $word_data['word_text'],
							'WORD_REGEX'		=> ($word_data['word_regex']) ? true : false,
							'WORD_REGEX_AUTO'	=> ($word_data['word_regex_auto']) ? true : false,
							'S_ADD'				=> ($action == 'add') ? true : false,
							'U_WORD_ACTION'		=> $this->u_action . '&amp;action=' . $action . (($action == 'edit') ? '&amp;w=' . $word_id : ''),
						));

						if ($submit)
						{
							if ($word_data['word_regex'])
							{
								  $delim = substr($word_data['word_text'], 0, 1);
					              if (strrpos($word_data['word_text'], $delim) == 0)
					              {
					                  trigger_error('SPAM_WORD_TEXT_EXPLAIN');
					              }
							}

							if ($action == 'add')
							{
								$db->sql_query('INSERT INTO ' . SPAM_WORDS_TABLE . ' ' . $db->sql_build_array('INSERT', $word_data));
								$cache->destroy('_spam_words');
								trigger_error($user->lang['SPAM_WORD_ADD_SUCCESS'] . adm_back_link($this->u_action));
							}
							else
							{
								$db->sql_query('UPDATE ' . SPAM_WORDS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $word_data) . ' WHERE word_id = ' . $word_id);
								$cache->destroy('_spam_words');
								trigger_error($user->lang['SPAM_WORD_EDIT_SUCCESS'] . adm_back_link($this->u_action));
							}
						}
					break;

					case 'delete' :
						if (!$word_id)
						{
							trigger_error('NO_SPAM_WORD');
						}
						$result = $db->sql_query('SELECT * FROM ' . SPAM_WORDS_TABLE . ' WHERE word_id = ' . $word_id);
						$word = $db->sql_fetchrow($result);
						if (!$word)
						{
                            trigger_error('NO_SPAM_WORD');
						}

						if (confirm_box(true))
						{
							$db->sql_query('DELETE FROM ' . SPAM_WORDS_TABLE . ' WHERE word_id = ' . $word_id);
							$cache->destroy('_spam_words');
							trigger_error($user->lang['SPAM_WORD_DELETE_SUCCESS'] . adm_back_link($this->u_action));
						}
						else
						{
							confirm_box(false, 'DELETE_SPAM_WORD');
						}
					break;

					default :
						$sql = 'SELECT * FROM ' . SPAM_WORDS_TABLE . '
							ORDER BY word_text ASC';
						$result = $db->sql_query($sql);
						while ($row = $db->sql_fetchrow($result))
						{
							$template->assign_block_vars('spam_words', array(
								'TEXT'			=> $row['word_text'],
								'REGEX'			=> $row['word_regex'],
								'REGEX_AUTO'	=> $row['word_regex_auto'],
								'U_DELETE'		=> append_sid($this->u_action . '&amp;action=delete&amp;w=' . $row['word_id']),
								'U_EDIT'		=> append_sid($this->u_action . '&amp;action=edit&amp;w=' . $row['word_id']),
							));
						}
						$db->sql_freeresult($result);
						$template->assign_var('S_SPAM_WORD_LIST', true);
					break;
				}

				$template->assign_vars(array(
					'L_TITLE'			=> $user->lang['ASACP_SPAM_WORDS'],
					'L_TITLE_EXPLAIN'	=> $user->lang['ASACP_SPAM_WORDS_EXPLAIN'],

					'S_SPAM_WORDS'		=> true,
				));
			break;
			//case 'spam_words' :

			case 'ip_search' :
				$this->tpl_name = 'acp_asacp';
				$this->page_title = 'ASACP_IP_SEARCH';

				$ip = request_var('ip', '');
				$type = request_var('type', '');
				if ($ip)
				{
					asacp_display_ip_search($type, $ip, $this->u_action . '&amp;ip=' . $ip, request_var('start', 0));
				}

				$template->assign_vars(array(
					'L_TITLE'				=> $user->lang['ASACP_IP_SEARCH'],
					'L_TITLE_EXPLAIN'		=> $user->lang['ASACP_IP_SEARCH_EXPLAIN'],
					'S_DATA_OUTPUT'			=> true,
					'S_DISPLAY_IP_INPUT'	=> ($ip) ? false : true,

					'U_BACK'				=> ($type) ? $this->u_action . '&amp;ip=' . $ip : false,
					'U_BACK_NONE'			=> $this->u_action,
				));
			break;
			// case 'ip_search' :

			case 'log' :
			case 'flag' :
				$this->tpl_name = 'acp_logs';

				if ($mode == 'log')
				{
					$this->page_title = $user->lang['ASACP_SPAM_LOG'];
				}
				else
				{
					$this->page_title = $user->lang['ASACP_FLAG_LOG'];

					// Reset the user flag new notification
					if ($user->data['user_flag_new'])
					{
						$db->sql_query('UPDATE ' . USERS_TABLE . ' SET user_flag_new = 0 WHERE user_id = ' . $user->data['user_id']);
					}
				}

				$user->add_lang('mcp');

				// Set up general vars
				$start		= request_var('start', 0);
				$action = request_var('action', array('' => ''));
				if (is_array($action))
				{
					list($action, ) = each($action);
				}
				else
				{
					$action = request_var('action', '');
				}
				$deletemark = (!empty($_POST['delmarked']) || $action == 'del_marked') ? true : false;
				$deleteall	= (!empty($_POST['delall']) || $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');

				$keywords = utf8_normalize_nfc(request_var('keywords', '', true));
				$keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(htmlspecialchars_decode($keywords)) : '';

				// Delete entries if requested and able
				if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
				{
					if (confirm_box(true))
					{
						clear_spam_log($mode, (($deletemark) ? false : $deleteall), $marked, $keywords);
					}
					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,
							'keywords'	=> $keywords,
							'i'			=> $id,
							'mode'		=> $mode,
							'action'	=> $this->u_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('t' => $user->lang['SORT_DATE'], 'u' => $user->lang['SORT_USERNAME'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
				$sort_by_sql = array('t' => 'l.log_time', 'u' => 'u.username_clean', '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_days = ($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;

				if ($mode == 'log')
				{
					view_spam_log('spam', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
				}
				else
				{
					view_spam_log('flag', $log_data, $log_count, $config['topics_per_page'], $start, '', $sql_days, $sql_sort, $keywords);
				}

				$template->assign_vars(array(
					'L_TITLE'		=> $this->page_title,
					'L_EXPLAIN'		=> '',

					'S_ON_PAGE'		=> on_page($log_count, $config['topics_per_page'], $start),
					'PAGE_NUMBER'	=> on_page($log_count, $config['topics_per_page'], $start),
					'PAGINATION'	=> generate_pagination($this->u_action . "&amp;$u_sort_param$keywords_param", $log_count, $config['topics_per_page'], $start, true),
					'TOTAL'			=> ($log_count == 1) ? $user->lang['TOTAL_LOG'] : sprintf($user->lang['TOTAL_LOGS'], $log_count),

					'S_LIMIT_DAYS'			=> $s_limit_days, // Yes, these duplicates are shit, but the acp/mcp use different variables
					'S_SELECT_SORT_DAYS'	=> $s_limit_days,
					'S_SORT_KEY'			=> $s_sort_key,
					'S_SELECT_SORT_KEY'		=> $s_sort_key,
					'S_SORT_DIR'			=> $s_sort_dir,
					'S_SELECT_SORT_DIR'		=> $s_sort_dir,

					'S_CLEARLOGS'			=> $auth->acl_get('a_clearlogs'),
					'S_CLEAR_ALLOWED'	   	=> $auth->acl_get('a_clearlogs'),
					'S_KEYWORDS'			=> $keywords,
					'S_LOGS'				=> ($log_count > 0) ? true : false,
				));

				foreach ($log_data as $row)
				{
					$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'				=> '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}&amp;mode=ip_search&amp;ip={$row['ip']}") . '">' . $row['ip'] . '</a>',
						'DATE'				=> $user->format_date($row['time']),
						'ACTION'			=> $row['action'],
						'DATA'				=> (sizeof($row['data'])) ? @vsprintf($user->lang[$row['operation'] . '_DATA'], $row['data']) : '',
						'ID'				=> $row['id'],
					));
				}
			break;
			//case 'log' :
			//case 'flag' :

			case 'flag_list' :
				$user->add_lang('memberlist');
				$this->tpl_name = 'acp_asacp';
				$this->page_title = 'ASACP_FLAG_LIST';

				$start = request_var('start', 0);
				$limit = request_var('limit', 20);

				$db->sql_query('SELECT count(user_id) as cnt FROM ' . USERS_TABLE . ' WHERE user_flagged = 1');
				$total = $db->sql_fetchfield('cnt');

				$sql = 'SELECT user_id, username, user_colour, user_ip, user_posts FROM ' . USERS_TABLE . ' WHERE user_flagged = 1';
				$result = $db->sql_query_limit($sql, $limit, $start);

				$cnt = 0;
				$output = '';
				while ($row = $db->sql_fetchrow($result))
				{
					$row['username'] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);

					if ($auth->acl_get('m_asacp_ip_search'))
					{
						$row['user_ip'] = '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", "i={$id}&amp;mode=ip_search&amp;ip={$row['user_ip']}") . '">' . $row['user_ip'] . '</a>';
					}

					if ($auth->acl_get('a_user'))
					{
						$row[$user->lang['ACTION']] = '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;mode=overview&amp;u={$row['user_id']}") . '">' . $user->lang['USER_ADMIN'] . '</a>';
					}

					unset($row['user_id'], $row['user_colour']);

					$cnt++;
					if ($cnt == 1)
					{
						$output .= asacp_display_table_head($row);
					}

					$output .= asacp_display_table_row($row, $cnt);
				}
				$db->sql_freeresult($result);

				$template->assign_vars(array(
					'L_TITLE'			=> $user->lang['ASACP_FLAG_LIST'],
					'L_TITLE_EXPLAIN'	=> $user->lang['ASACP_FLAG_LIST_EXPLAIN'],

					'S_DATA_OUTPUT'		=> true,
				));

				$template->assign_block_vars('data_output', array(
					'TITLE'			=> $user->lang['USERS'],
					'DATA'			=> $output,
					'PAGINATION'	=> ($total) ? generate_pagination($this->u_action . "&amp;limit=$limit", $total, $limit, $start, true, 'data_output') : '',
				));
			break;
			//case 'flag_list' :

			case 'profile_fields' :
				$user->add_lang('ucp');
				$this->tpl_name = 'acp_asacp';
				$this->page_title = 'ASACP_PROFILE_FIELDS';

				$options = array(
					'legend1'				=> 'ASACP_PROFILE_FIELDS',
				);

				$cfg_array = (isset($_REQUEST['config'])) ? utf8_normalize_nfc(request_var('config', array('' => ''), true)) : $config;
				foreach (antispam::$profile_fields as $field => $ary)
				{
					if ($submit)
					{
						switch ($cfg_array['asacp_profile_' . $field])
						{
							case 1 :
								// Required
							break;

							case 2 :
								// Normal
							break;

							case 3 :
								// Never allowed
								$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array($ary['db'] => ''));
								$db->sql_query($sql);
							break;

							case 4 :
								// Post Count
								$sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', array($ary['db'] => '')) . '
									WHERE user_posts < ' . (int) $cfg_array['asacp_profile_' . $field . '_post_limit'];
								$db->sql_query($sql);
							break;
						}
					}

					$options['asacp_profile_' . $field] = array('lang' => $ary['lang'], 'validate' => 'int:1:4', 'type' => 'custom', 'method' => 'profile_fields_select', 'explain' => false);
					$options['asacp_profile_' . $field . '_post_limit'] = array('lang' => $ary['lang'] . '_POST_COUNT', 'validate' => 'int:1:99999', 'type' => 'text:40:255', 'explain' => true);
				}

				$template->assign_vars(array(
					'L_TITLE'			=> $user->lang['ASACP_PROFILE_FIELDS'],
					'L_TITLE_EXPLAIN'	=> $user->lang['ASACP_PROFILE_FIELDS_EXPLAIN'],
				));
			break;
			//case 'profile_fields' :

			default :
				$this->tpl_name = 'acp_asacp';
				$this->page_title = 'ASACP_SETTINGS';

				$options = array(
					'legend1'								=> 'ASACP_SETTINGS',
					'asacp_enable'							=> array('lang' => 'ASACP_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_log'								=> array('lang' => 'ASACP_LOG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_user_flag_enable'				=> array('lang' => 'ASACP_USER_FLAG_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_notify_new_flag'					=> array('lang' => 'ASACP_NOTIFY_NEW_FLAG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),

					'legend2'								=> 'ASACP_PROFILE_FIELDS',
					'asacp_profile_during_reg'				=> array('lang' => 'ASACP_PROFILE_DURING_REG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),

					'legend3'								=> 'ASACP_AKISMET',
					'asacp_akismet_enable'					=> array('lang' => 'ASACP_AKISMET_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false),
					'asacp_akismet_key'						=> array('lang' => 'ASACP_AKISMET_KEY', 'validate' => 'string', 'type' => 'text:14:14', 'explain' => true),
					'asacp_akismet_domain'					=> array('lang' => 'ASACP_AKISMET_DOMAIN', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true),
					'asacp_akismet_post_limit'				=> array('lang' => 'ASACP_AKISMET_POST_LIMIT', 'validate' => 'int', 'type' => 'text:14:14', 'explain' => true),
					'asacp_akismet_post_action'				=> array('lang' => 'ASACP_SPAM_WORDS_POSTING_ACTION', 'validate' => 'int:0:2', 'type' => 'custom', 'method' => 'spam_words_nothing_deny_approval_action', 'explain' => true),
					'asacp_akismet_pm_action' 				=> array('lang' => 'ASACP_SPAM_WORDS_PM_ACTION', 'validate' => 'int:0:1', 'type' => 'custom', 'method' => 'spam_words_nothing_deny_action', 'explain' => true),

					'legend4'								=> 'ASACP_SPAM_WORDS',
					'asacp_spam_words_enable'				=> array('lang' => 'ASACP_SPAM_WORDS_ENABLE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_spam_words_post_limit'			=> array('lang' => 'ASACP_SPAM_WORDS_POST_LIMIT', 'validate' => 'string', 'type' => 'text:40:255', 'explain' => true),
					'asacp_spam_words_flag_limit'			=> array('lang' => 'ASACP_SPAM_WORDS_FLAG_LIMIT', 'validate' => 'int:1', 'type' => 'text:40:255', 'explain' => true),
					'asacp_spam_words_posting_action'		=> array('lang' => 'ASACP_SPAM_WORDS_POSTING_ACTION', 'validate' => 'int:0:2', 'type' => 'custom', 'method' => 'spam_words_nothing_deny_approval_action', 'explain' => true),
					'asacp_spam_words_pm_action'			=> array('lang' => 'ASACP_SPAM_WORDS_PM_ACTION', 'validate' => 'int:0:1', 'type' => 'custom', 'method' => 'spam_words_nothing_deny_action', 'explain' => true),
					'asacp_spam_words_profile_action'		=> array('lang' => 'ASACP_SPAM_WORDS_PROFILE_ACTION', 'validate' => 'int:0:1', 'type' => 'custom', 'method' => 'spam_words_nothing_deny_action', 'explain' => true),

					'legend5'								=> 'ASACP_SFS_SETTINGS',
					'asacp_sfs_min_freq'					=> array('lang' => 'ASACP_SFS_MIN_FREQ', 'validate' => 'int:1', 'type' => 'text:6:10', 'explain' => true),
					'asacp_sfs_action'						=> array('lang' => 'ASACP_SFS_ACTION', 'validate' => 'int:0:5', 'type' => 'custom', 'method' => 'sfs_action', 'explain' => true),
					'asacp_sfs_key'							=> array('lang' => 'ASACP_SFS_KEY', 'validate' => 'string', 'type' => 'text:14:14', 'explain' => true),

					'legend6'								=> 'ASACP_BAN_SETTINGS',
					'asacp_ocban_username'					=> array('lang' => 'ASACP_BAN_USERNAME', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_deactivate'				=> array('lang' => 'ASACP_BAN_DEACTIVATE_USER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_move_to_group'				=> array('lang' => 'ASACP_BAN_MOVE_TO_GROUP', 'validate' => 'int:0', 'type' => 'custom', 'method' => 'group_list', 'explain' => true),
					'asacp_ocban_delete_posts'				=> array('lang' => 'ASACP_BAN_DELETE_POSTS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_clear_outbox'				=> array('lang' => 'ASACP_BAN_CLEAR_OUTBOX', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_delete_avatar'				=> array('lang' => 'ASACP_BAN_DELETE_AVATAR', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_delete_signature'			=> array('lang' => 'ASACP_BAN_DELETE_SIGNATURE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
					'asacp_ocban_delete_profile_fields'		=> array('lang' => 'ASACP_BAN_DELETE_PROFILE_FIELDS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
				);

				if (file_exists($phpbb_root_path . 'blog/includes/functions_admin.' . $phpEx))
				{
					$options['asacp_ocban_blog'] = array('lang' => 'ASACP_BAN_DELETE_BLOG', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
				}

				$template->assign_vars(array(
					'L_TITLE'			=> $user->lang['ASACP_SETTINGS'],
					'L_TITLE_EXPLAIN'	=> '',
					'S_SETTINGS'		=> true,

					'CURRENT_VERSION'	=> ASACP_VERSION,
					'LATEST_VERSION'	=> $this->asacp_latest_version(),
				));
			break;
		}
		// switch($mode)

		// Display the options if there are any (setup similar to acp_board)
		if (sizeof($options))
		{
			asacp_display_options($options, $error, $this->u_action);
		}

        $template->assign_vars(array(
			'ERROR'			=> implode('<br />', $error),
			'U_ACTION'		=> $this->u_action,
		));
	}
Ejemplo n.º 3
0
function asacp_display_ip_search($type, $ip, $url, $start = 0)
{
    global $auth, $db, $template, $user, $phpbb_admin_path, $phpbb_root_path, $phpEx;
    if (!$ip) {
        return;
    }
    $user->add_lang('memberlist');
    $sql_ip = $db->sql_escape($ip);
    $start = (int) $start;
    $limit = request_var('limit', 10);
    $cnt = $total = 0;
    $output = '';
    switch ($type) {
        case 'bot_check':
            $sql = 'SELECT * FROM ' . BOTS_TABLE . ' WHERE bot_ip = \'' . $sql_ip . '\'';
            $result = $db->sql_query($sql);
            while ($row = $db->sql_fetchrow($result)) {
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            // case 'bot_check' :
        // case 'bot_check' :
        case 'logs':
            // Those without admin log viewing permission can only see moderation logs
            $log_type_sql = '';
            if (!$auth->acl_get('a_viewlogs')) {
                $log_type_sql = ' AND log_type = ' . LOG_MOD;
            }
            $db->sql_query('SELECT count(log_id) AS total FROM ' . LOG_TABLE . '
				WHERE log_ip = \'' . $sql_ip . '\'' . $log_type_sql);
            $total = $db->sql_fetchfield('total');
            $sql = 'SELECT l.user_id, l.log_time, l.forum_id, l.topic_id, l.log_operation, l.log_data, u.username, u.user_colour
				FROM ' . LOG_TABLE . ' l,' . USERS_TABLE . " u\n\t\t\t\tWHERE log_ip = '{$sql_ip}'\n\t\t\t\tAND u.user_id = l.user_id\n\t\t\t\t{$log_type_sql}\n\t\t\t\tORDER BY log_time DESC";
            $result = $db->sql_query_limit($sql, $limit, $start);
            while ($row = $db->sql_fetchrow($result)) {
                $row['log_action'] = isset($user->lang[$row['log_operation']]) ? $user->lang[$row['log_operation']] : '{' . ucfirst(str_replace('_', ' ', $row['log_operation'])) . '}';
                if (!empty($row['log_data'])) {
                    // We supress the warning about inappropriate number of passed parameters here due to possible changes within LOG strings from one version to another.
                    $row['log_action'] = @vsprintf($row['log_action'], unserialize($row['log_data']));
                    $row['log_action'] = bbcode_nl2br($row['log_action']);
                }
                $row['username'] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
                unset($row['user_id'], $row['user_colour'], $row['reportee_id'], $row['reportee_username'], $row['reportee_user_colour'], $row['log_operation'], $row['log_data']);
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $row['log_time'] = $user->format_date($row['log_time']);
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            // case 'logs' :
        // case 'logs' :
        case 'spam_log':
            if (!$auth->acl_get('m_asacp_spam_log')) {
                return;
            }
            $db->sql_query('SELECT count(log_id) AS total FROM ' . SPAM_LOG_TABLE . '
				WHERE log_ip = \'' . $sql_ip . '\'
				AND log_type = 1');
            $total = $db->sql_fetchfield('total');
            $log_data = array();
            view_spam_log('spam', $log_data, $log_count, $limit, $start, $sql_ip);
            foreach ($log_data as $row) {
                $log = array($user->lang['USERNAME'] => $row['username_full'], $user->lang['TIME'] => $user->format_date($row['time']), $user->lang['ACTION'] => $row['action'] . (sizeof($row['data']) ? '<br />' . @vsprintf($user->lang[$row['operation'] . '_DATA'], $row['data']) : ''));
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($log);
                }
                $output .= asacp_display_table_row($log, $cnt);
            }
            break;
            //case 'spam_log' :
        //case 'spam_log' :
        case 'flag_log':
            if (!$auth->acl_get('m_asacp_user_flag')) {
                return;
            }
            $db->sql_query('SELECT count(log_id) AS total FROM ' . SPAM_LOG_TABLE . '
				WHERE log_ip = \'' . $sql_ip . '\'
				AND log_type = 2');
            $total = $db->sql_fetchfield('total');
            $log_data = array();
            view_spam_log('flag', $log_data, $log_count, $limit, $start, $sql_ip);
            foreach ($log_data as $row) {
                $log = array($user->lang['USERNAME'] => $row['username_full'], $user->lang['TIME'] => $user->format_date($row['time']), $user->lang['ACTION'] => $row['action'] . (sizeof($row['data']) ? '<br />' . @vsprintf($user->lang[$row['operation'] . '_DATA'], $row['data']) : ''));
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($log);
                }
                $output .= asacp_display_table_row($log, $cnt);
            }
            break;
            //case 'flag_log' :
        //case 'flag_log' :
        case 'poll_votes':
            $db->sql_query('SELECT count(vote_user_ip) AS total FROM ' . POLL_VOTES_TABLE . '
				WHERE vote_user_ip = \'' . $sql_ip . '\'');
            $total = $db->sql_fetchfield('total');
            $sql = 'SELECT * FROM ' . POLL_VOTES_TABLE . '
				WHERE vote_user_ip = \'' . $sql_ip . '\'
				ORDER BY topic_id DESC';
            $result = $db->sql_query_limit($sql, $limit, $start);
            while ($row = $db->sql_fetchrow($result)) {
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $row['topic_id'] = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", 't=' . $row['topic_id']) . '">' . $row['topic_id'] . '</a>';
                $row['vote_user_id'] = '<a href="' . append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=viewprofile&amp;u=' . $row['vote_user_id']) . '">' . $row['vote_user_id'] . '</a>';
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            // case 'poll_votes' :
        // case 'poll_votes' :
        case 'posts':
            $readable_forums = array_keys($auth->acl_getf('f_read', true));
            $db->sql_query('SELECT count(post_id) AS total FROM ' . POSTS_TABLE . '
				WHERE poster_ip = \'' . $sql_ip . '\'
				AND ' . $db->sql_in_set('forum_id', $readable_forums));
            $total = $db->sql_fetchfield('total');
            $sql = 'SELECT p.post_subject, p.topic_id, p.post_id, p.poster_id, u.username, u.user_colour, p.post_username, p.post_time FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . ' u
				WHERE poster_ip = \'' . $sql_ip . '\'
				AND u.user_id = p.poster_id
				AND ' . $db->sql_in_set('p.forum_id', $readable_forums) . '
				ORDER BY post_time DESC';
            $result = $db->sql_query_limit($sql, $limit, $start);
            while ($row = $db->sql_fetchrow($result)) {
                $row['post_subject'] = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.{$phpEx}", "t={$row['topic_id']}&amp;p={$row['post_id']}#p{$row['post_id']}") . '">' . $row['post_subject'] . '</a>';
                $row['username'] = get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']);
                unset($row['poster_id'], $row['post_id'], $row['topic_id'], $row['user_colour'], $row['post_username']);
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $row['post_time'] = $user->format_date($row['post_time']);
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            // case 'posts' :
        // case 'posts' :
        case 'privmsgs':
            $db->sql_query('SELECT count(msg_id) AS total FROM ' . PRIVMSGS_TABLE . '
				WHERE author_ip = \'' . $sql_ip . '\'');
            $total = $db->sql_fetchfield('total');
            $sql = 'SELECT p.msg_id, p.author_id, u.username, u.user_colour, p.message_time, message_subject, to_address, bcc_address FROM ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u
				WHERE author_ip = \'' . $sql_ip . '\'
				AND u.user_id = p.author_id
				ORDER BY message_time DESC';
            $result = $db->sql_query_limit($sql, $limit, $start);
            while ($row = $db->sql_fetchrow($result)) {
                $row['username'] = get_username_string('full', $row['author_id'], $row['username'], $row['user_colour']);
                unset($row['author_id'], $row['user_colour']);
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $row['message_time'] = $user->format_date($row['message_time']);
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            //case 'privmsgs' :
        //case 'privmsgs' :
        case 'users':
            $db->sql_query('SELECT count(user_id) AS total FROM ' . USERS_TABLE . '
				WHERE user_ip = \'' . $sql_ip . '\'');
            $total = $db->sql_fetchfield('total');
            $sql = 'SELECT user_id, username, user_regdate, user_email, user_colour  FROM ' . USERS_TABLE . '
				WHERE user_ip = \'' . $sql_ip . '\'
				ORDER BY user_regdate DESC';
            $result = $db->sql_query_limit($sql, $limit, $start);
            while ($row = $db->sql_fetchrow($result)) {
                $row['username'] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
                if ($auth->acl_get('a_user')) {
                    $row[$user->lang['ACTIONS']] = '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=users&amp;mode=overview&amp;u=' . $row['user_id']) . '">' . $user->lang['USER_ADMIN'] . '</a>';
                }
                unset($row['user_id'], $row['user_colour']);
                $cnt++;
                if ($cnt == 1) {
                    $output .= asacp_display_table_head($row);
                }
                $row['user_regdate'] = $user->format_date($row['user_regdate']);
                $output .= asacp_display_table_row($row, $cnt);
            }
            $db->sql_freeresult($result);
            break;
            // case 'users' :
        // case 'users' :
        default:
            asacp_display_ip_search('bot_check', $ip, $url);
            asacp_display_ip_search('logs', $ip, $url);
            asacp_display_ip_search('spam_log', $ip, $url);
            asacp_display_ip_search('flag_log', $ip, $url);
            //asacp_display_ip_search('poll_votes', $ip, $url);
            asacp_display_ip_search('posts', $ip, $url);
            asacp_display_ip_search('privmsgs', $ip, $url);
            asacp_display_ip_search('users', $ip, $url);
            return;
            break;
    }
    if ($output) {
        $template->assign_block_vars('data_output', array('TITLE' => isset($user->lang['ASACP_IP_SEARCH_' . strtoupper($type)]) ? $user->lang['ASACP_IP_SEARCH_' . strtoupper($type)] : 'ASACP_IP_SEARCH_' . strtoupper($type), 'DATA' => $output, 'PAGINATION' => $total ? generate_pagination($url . "&amp;type={$type}&amp;limit={$limit}", $total, $limit, $start, true, 'data_output') : ''));
    }
}