<?php
/***************************************************************************
 *                                 warn.php
 *                            -------------------
 *   begin                : Sunday, Aug 23, 2004
 *   copyright            : (C) 2004 roadway
 *   email                : roadway@interia.pl
 *
 *   $Id: warn.php,v 1.0.2 2004/08/27 18:42:20 $
 *
 ***************************************************************************/
// Begin PNphpBB2 Module
if (!defined("LOADED_AS_MODULE")) {
	 die ("You can't access this file directly...");
}
global $pnconfig;
$pntable = pnDBGetTables();
$ModName = basename( dirname( __FILE__ ) );
//End PNphpBB2 Module


define('IN_PHPBB', true);

$phpbb_root_path = './modules/' . $ModName . '/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

$userdata = session_pagestart($user_ip, PAGE_WARN);
init_userprefs($userdata);


$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
$uid = ( isset($HTTP_POST_VARS['uid']) ) ? $HTTP_POST_VARS['uid'] : $HTTP_GET_VARS['uid'];

$sql = "SELECT user_id, user_level FROM " . USERS_TABLE . " WHERE user_id='" . $userdata['session_user_id'] . "'";

	if ( !($result = $db->sql_query($sql)) ) {

	message_die(GENERAL_ERROR, 'Error in process userdata', '', __LINE__, __FILE__, $sql);

	}
	$row = $db->sql_fetchrow($result);


if( $row['user_level'] == ADMIN || $row['user_level'] == MOD ) {


	if( eregi("[0-9]", $uid) ) {


	$sql1 = "SELECT user_id, user_level, user_warn FROM " . USERS_TABLE . " WHERE user_id = $uid";
	$sql2 = "SELECT ban_userid FROM " . BANLIST_TABLE . " WHERE ban_userid = $uid";

		if ( !($result1 = $db->sql_query($sql1)) ) {

		message_die(GENERAL_ERROR, 'Error in process userdata', '', __LINE__, __FILE__, $sql1);

		}

		if ( !($result2 = $db->sql_query($sql2)) ) {

		message_die(GENERAL_ERROR, 'Error in process userdata', '', __LINE__, __FILE__, $sql2);

		}

		$row1 = $db->sql_fetchrow($result1);
		$row2 = $db->sql_fetchrow($result2);


	$user_level = $row1['user_level'];
	$user_warn = $row1['user_warn'];

	$ban_userid = $row2['ban_userid'];


	switch ( $mode ) {


	case "ban":

		if( $user_level == ADMIN ) {

		$message = $lang['is_admin'];

		}

		else {

			if( $ban_userid ) {

			$message = $lang['is_ban'];

			}

			else {

			$sql = "INSERT INTO " . BANLIST_TABLE . " SET ban_userid = $uid";

				if( !($result = $db->sql_query($sql)) ) {

				message_die(GENERAL_ERROR, 'Error in banned user', '', __LINE__, __FILE__, $sql);

				}

			$sql = "UPDATE " . USERS_TABLE . " SET user_warn = 0 WHERE user_id = $uid";

				if( !($result = $db->sql_query($sql)) ) {

				message_die(GENERAL_ERROR, 'Error in updating user warn', '', __LINE__, __FILE__, $sql);

				}

			$message = $lang['is_banned'];

			}

		}

	break;


	case "unban":

		if( !$ban_userid ) {

		$message = $lang['is_noban'];

		}

		else {

		$sql = "DELETE FROM " . BANLIST_TABLE . " WHERE ban_userid = $uid";

			if( !($result = $db->sql_query($sql)) ) {

			message_die(GENERAL_ERROR, 'Error in remove ban', '', __LINE__, __FILE__, $sql);

			}

		$message = $lang['is_unbanned'];

		}

	break;


	case "warn":

		if( $user_level == ADMIN ) {

		$message = $lang['is_admin'];

		}

		else {

		$user_warn++;

			if( $user_warn < $board_config['warn_limit'] ) {

				if( $ban_userid ) {

				$message = $lang['is_nowarned'];

				}

				else {

				$sql = "UPDATE " . USERS_TABLE . " SET user_warn = $user_warn WHERE user_id = $uid";

					if( !($result = $db->sql_query($sql)) ) {

					message_die(GENERAL_ERROR, 'Error in updating user warn', '', __LINE__, __FILE__, $sql);

					}

				$message = $lang['is_warned'];

				}

			}

			else {

			$sql = "INSERT INTO " . BANLIST_TABLE . " SET ban_userid = $uid";

				if( !($result = $db->sql_query($sql)) ) {

				message_die(GENERAL_ERROR, 'Error in banned user', '', __LINE__, __FILE__, $sql);

				}

			$sql = "UPDATE " . USERS_TABLE . " SET user_warn = 0 WHERE user_id = $uid";

				if( !($result = $db->sql_query($sql)) ) {

				message_die(GENERAL_ERROR, 'Error in updating user warn', '', __LINE__, __FILE__, $sql);

				}

			$message = $lang['is_banned'];

			}

		}

	break;


	default:

	$message = $lang['is_nomode'];

	break;

	}

	}

	else {

	$message = $lang['is_nouid'];

	}

}

else {

$message = $lang['is_noaccess'];

}

$message .= '<br /><br />' . sprintf($lang['Click_return_index'], '<a href="' . append_sid("index.$phpEx") . '">', '</a> ');

message_die(GENERAL_MESSAGE, $message);

include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
?>