Location: PHPKode > scripts > MetaBB > metabb/adr_character.php
<?php 
/***************************************************************************
 *					adr_character.php
 *				------------------------
 *	begin 			: 31/01/2004
 *	copyright			: Malicious Rabbit / Dr DLP
 *
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *
 ***************************************************************************/

define('IN_PHPBB', true); 
define('IN_ADR_CHARACTER', true);
define('IN_ADR_BATTLE', true);
define('IN_ADR_SHOPS', true);
define('IN_ADR_VAULT', true); 
$phpbb_root_path = './'; 
include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx);

$loc = 'character';
$sub_loc = 'adr_character';

//
// Start session management
$userdata = session_pagestart($user_ip, PAGE_INDEX); 
init_userprefs($userdata); 
// End session management
//

include($phpbb_root_path . 'adr/includes/adr_global.'.$phpEx);

// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
	$redirect = "adr_character.$phpEx";
	$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
	header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

// Includes the tpl and the header
adr_template_file('adr_character_body.tpl');

include($phpbb_root_path . 'includes/page_header.'.$phpEx);
//
//BEGIN zone Character weather
//
$zone_user = adr_get_user_infos($user_id);
$actual_weather = $zone_user['character_weather'];

( $board_config['adr_seasons'] == '4' ) ? $new_weather = rand(1,6) : $new_weather = rand(1,5);

//Update character weather
$sql = " UPDATE  " . ADR_CHARACTERS_TABLE . " 
	SET character_weather = $new_weather
	WHERE character_id = " .$userdata['user_id'];
if( !($result = $db->sql_query($sql)) )
	message_die(GENERAL_ERROR, 'Could not update character zone', '', __LINE__, __FILE__, $sql);
//
//END zone Character weather
//

// Who is looking at this page ?
$user_id = $userdata['user_id'];
if ( (!( isset($HTTP_POST_VARS[POST_USERS_URL]) || isset($HTTP_GET_VARS[POST_USERS_URL]))) || ( empty($HTTP_POST_VARS[POST_USERS_URL]) && empty($HTTP_GET_VARS[POST_USERS_URL])))
{ 
	$view_userdata = $userdata; 
} 
else 
{ 
	$view_userdata = get_userdata(intval($HTTP_GET_VARS[POST_USERS_URL])); 
} 
$searchid = $view_userdata['user_id'];
$points = $userdata['user_points'];
$posts = $userdata['user_posts'];

// Let's define some actions
$Level_up = isset($HTTP_POST_VARS['level_up']);
$carac_up = intval($HTTP_POST_VARS['carac_up']);
$Step2 = isset($HTTP_POST_VARS['Step2']);
$Step4 = isset($HTTP_POST_VARS['Step4']);
$bio_edit = isset($HTTP_POST_VARS['bio_edit']);
$upgrade_bio = isset($HTTP_POST_VARS['upgrade_bio']);
$delete = isset($HTTP_POST_VARS['delete']);
$monsters = isset($HTTP_POST_VARS['battle_monsters']);
$players = isset($HTTP_POST_VARS['battle_players']);
$delete_confirm = isset($HTTP_POST_VARS['delete_confirm']);

if ( intval($HTTP_GET_VARS['list']))
{
	if ( intval($HTTP_GET_VARS['list']) == '2' )
	{
		$players = TRUE;
	}
	else
	{
		$monsters = TRUE;
	}
}

// Get the general settings
$adr_general = adr_get_general_config();

adr_enable_check();
adr_ban_check($user_id);

// See if the user has ever created a character or no
$row = adr_get_user_infos($searchid);
$current_name = $row['character_name'];

// If someone is looking at a character's user that doesn't exist , let's display an error message
if (  !( $row['character_class'] ) && ($searchid != $user_id) ) 
{
	message_die(GENERAL_MESSAGE, $lang['Adr_character_lack']);
}

// Sounds strange , but this prevents characters without class if the user leaves the page while creating a character
if ( is_numeric($row['character_race']) && !$row['character_class'] && $searchid == $user_id )  
{
	$Step3 = TRUE;
}



// The user has no character yet
if ( (!(is_numeric($row['character_race'])) &&  $searchid == $user_id )  || $Step3 ) 
{
	// Does character meet minimum post count for character creation
	if ( $adr_general['posts_enable'] && $posts < $adr_general['posts_min'] )
	{   
   		adr_previous ( Adr_posts , 'index' , '' );
	}

	if ($Step2)
	{
		$bio 				= trim($HTTP_POST_VARS['bio']);
		$name 			= $HTTP_POST_VARS['name'];
		$race 			= intval($HTTP_POST_VARS['race']);
		$element 			= intval($HTTP_POST_VARS['element']);
		$alignment 			= intval($HTTP_POST_VARS['alignment']);

		$reuse_char 		= unexploit_user_characteristics($userdata['user_id']);
		$details 			= explode('%SPLIT%', $reuse_char);		
		$power 			= $details[0];
		$agility 			= $details[1];
		$endurance 			= $details[2];
		$intelligence 		= $details[3];
		$willpower 			= $details[4];
		$charm 			= $details[5];
		$magic_attack 		= $details[6];
		$magic_resistance 	= $details[7];
		delete_unexploited_characteristics($userdata['user_id']);
		
		if ( !$name )
		{
			adr_previous( Fields_empty , adr_character , '' );
		}

		$sql = "SELECT * FROM " . ADR_RACES_TABLE ." r , " . ADR_ELEMENTS_TABLE ." e , " . ADR_ALIGNMENTS_TABLE ." a
			WHERE r.race_id = $race 
			AND e.element_id = $element
			AND a.alignment_id = $alignment ";
		if (!$result = $db->sql_query($sql)) 
		{
			message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
		}
		$infos = $db->sql_fetchrow($result);

		$power = $power + ( $infos['race_might_bonus'] - $infos['race_might_malus'] );
		$agility = $agility + ( $infos['race_dexterity_bonus'] - $infos['race_dexterity_malus'] );
		$endurance = $endurance + ( $infos['race_constitution_bonus'] - $infos['race_constitution_malus'] );
		$intelligence = $intelligence + ( $infos['race_intelligence_bonus'] - $infos['race_intelligence_malus'] );
		$willpower = $willpower + ( $infos['race_wisdom_bonus'] - $infos['race_wisdom_malus'] );
		$charm = $charm + ( $infos['race_charisma_bonus'] - $infos['race_charisma_malus'] );
		$magic_attack = $magic_attack + ( $infos['race_magic_attack_bonus'] - $infos['race_magic_attack_malus'] );
		$magic_resistance = $magic_resistance + ( $infos['race_magic_resistance_bonus'] - $infos['race_magic_resistance_malus'] );
		$mining = 1 + ( $infos['race_skill_mining_bonus'] + $infos['element_skill_mining_bonus'] );
		$stone = 1 + ( $infos['race_skill_stone_bonus'] + $infos['element_skill_stone_bonus'] );
		$forge = 1 + ( $infos['race_skill_forge_bonus'] + $infos['element_skill_forge_bonus'] );
		$enchantment = 1 + ( $infos['race_skill_enchantment_bonus'] + $infos['element_skill_enchantment_bonus'] );
		$trading = 1 + ( $infos['race_skill_trading_bonus'] + $infos['element_skill_trading_bonus'] );
		$thief = 1 + ( $infos['race_skill_thief_bonus'] + $infos['element_skill_thief_bonus'] );
		$zone = $infos['race_zone_begin'];
		$current_time = time();

		$sql = "INSERT INTO " . ADR_CHARACTERS_TABLE ."
			( character_id , character_name , character_desc , character_race , character_element , character_alignment , character_might , character_dexterity , character_constitution , character_intelligence , character_wisdom ,character_charisma , character_magic_attack , character_magic_resistance , character_skill_mining , character_skill_stone , character_skill_forge , character_skill_enchantment , character_skill_trading , character_skill_thief , character_birth, character_area, character_battle_limit, character_skill_limit, character_trading_limit, character_thief_limit )
			VALUES ( $user_id , '" . str_replace("\'", "''", $name ) . "' , '$bio' , $race , $element , $alignment , $power , $agility , $endurance , $intelligence , $willpower , $charm , $magic_attack , $magic_resistance , $mining , $stone , $forge , $enchantment , $trading , $thief , $current_time, $zone, ".$adr_general['Adr_character_battle_limit'].", ".$adr_general['Adr_character_skill_limit'].", ".$adr_general['Adr_character_trading_limit'].", ".$adr_general['Adr_character_thief_limit']." ) ";
		$result = $db->sql_query($sql);
		if( !$result )
		{
			adr_previous( Adr_character_twice , adr_character , '' );
		}
		adr_update_posters_infos();

		$Step3 = TRUE ;
	} 
	else if ($Step4)
	{
		$class_id = intval($HTTP_POST_VARS['class']);
		if ( !$class_id )
		{
			adr_previous( Adr_character_must_select_class , adr_character , '' );
		}

		$sql = "SELECT * FROM " . ADR_CLASSES_TABLE ."
				WHERE class_id = $class_id  ";
		if (!$result = $db->sql_query($sql)) 
		{
			message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
		}
		$class = $db->sql_fetchrow($result);

		$sql = "UPDATE " . ADR_CHARACTERS_TABLE ."
			SET character_class = $class_id ,
				character_hp = ".$class['class_base_hp'].",
				character_hp_max = ".$class['class_base_hp'].",
				character_mp = ".$class['class_base_mp'].",
				character_mp_max = ".$class['class_base_mp'].",
				character_ac = ".$class['class_base_ac']."
			WHERE character_id = $user_id ";
		if (!$result = $db->sql_query($sql)) 
		{
			message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
		}

		adr_update_posters_infos();
		adr_previous( Adr_character_success , adr_character , '' );

	}
	if ($Step3)
	{
		$template->assign_block_vars( 'nocharacterclass' , array());
		
		$race_id = intval($HTTP_POST_VARS['race']);

		if ( $userdata['user_level'] == ADMIN )
		{
			$sql_level = '';
		}
		else if ( $userdata['user_level'] == MOD )
		{
			$sql_level = ' AND c.class_level <> 1';
		}
		else
		{
			$sql_level = 'AND c.class_level = 0';
		}

		$sql = "SELECT c.* FROM " . ADR_CLASSES_TABLE ." c , " . ADR_CHARACTERS_TABLE ." u
				WHERE c.class_might_req < u.character_might
				$sql_level
				AND c.class_dexterity_req <= u.character_dexterity
				AND c.class_constitution_req <= u.character_constitution
				AND c.class_intelligence_req <= u.character_intelligence
				AND c.class_wisdom_req <= u.character_wisdom
				AND c.class_charisma_req <= u.character_charisma
				AND c.class_magic_attack_req <= u.character_magic_attack
				AND c.class_magic_resistance_req <= u.character_magic_resistance
				AND c.class_selectable = 1
				AND (c.class_race_id = 0 OR c.class_race_id = $race_id)
				AND u.character_id = $user_id ";
		if (!$result = $db->sql_query($sql)) 
		{
			message_die(CRITICAL_ERROR, 'Error Getting ADR Config!');
		}
		$class = $db->sql_fetchrowset($result);

		if ( !count($class) )
		{
			$sql = "DELETE FROM " . ADR_CHARACTERS_TABLE . " 
				WHERE character_id = $user_id"; 
			if( !$db->sql_query($sql) ) 
			{ 
				message_die(GENERAL_ERROR, 'Could not delete user from user pets table', '', __LINE__, __FILE__, $sql); 
			}
			adr_previous( Adr_character_impossible , adr_character , '' );
		}
		for ( $i = 0 ; $i < count($class) ; $i ++)
		{
			$template->assign_block_vars('nocharacterclass.classes' , array(
				"CLASS_NAME" => adr_get_lang($class[$i]['class_name']),
				"CLASS_DESC" => adr_get_lang($class[$i]['class_desc']),
				"CLASS_IMG" => $class[$i]['class_img'],
				"CLASS_ID" => $class[$i]['class_id'],
				"BASE_HP" => $class[$i]['class_base_hp'],
				"BASE_MP" => $class[$i]['class_base_mp'],
				"BASE_MIGHT" => $class[$i]['class_base_might'],
				"BASE_DEXTERITY" => $class[$i]['class_base_dexterity'],
				"BASE_CONSTITUTION" => $class[$i]['class_base_constitution'],
				"BASE_INTELLIGENCE" => $class[$i]['class_base_intelligence'],
				"BASE_WISDOM" => $class[$i]['class_base_wisdom'],
				"BASE_CHARISMA" => $class[$i]['class_base_charisma'],
				"BASE_MAGIC_ATTACK" => $class[$i]['class_base_magic_attack'],
				"BASE_MAGIC_RESISTANCE" => $class[$i]['class_base_magic_resistance'],					
				"BASE_AC" => $class[$i]['class_base_ac'],
				"UPDATE_XP_REQ" => $class[$i]['class_update_xp_req'],
				"UPDATE_HP" => $class[$i]['class_update_hp'],
				"UPDATE_MP" => $class[$i]['class_update_mp'],
				"UPDATE_MIGHT" => $class[$i]['class_update_might'],
				"UPDATE_DEXTERITY" => $class[$i]['class_update_dexterity'],
				"UPDATE_CONSTITUTION" => $class[$i]['class_update_constitution'],
				"UPDATE_INTELLIGENCE" => $class[$i]['class_update_intelligence'],
				"UPDATE_WISDOM" => $class[$i]['class_update_wisdom'],
				"UPDATE_CHARISMA" => $class[$i]['class_update_charisma'],
				"UPDATE_MAGIC_ATTACK" => $class[$i]['class_update_magic_attack'],
				"UPDATE_MAGIC_RESISTANCE" => $class[$i]['class_update_magic_resistance'],					
				"UPDATE_AC" => $class[$i]['class_update_ac'],
			));
		}

		$template->assign_vars(array(
			"L_BASE_HP" => $lang['Adr_classes_base_hp'],
			"L_BASE_MP" => $lang['Adr_classes_base_mp'],
			"L_BASE_MIGHT" => $lang['Adr_classes_base_might'],
			"L_BASE_DEXTERITY" => $lang['Adr_classes_base_dexterity'],
			"L_BASE_CONSTITUTION" => $lang['Adr_classes_base_constitution'],
			"L_BASE_INTELLIGENCE" => $lang['Adr_classes_base_intelligence'],
			"L_BASE_WISDOM" => $lang['Adr_classes_base_wisdom'],
			"L_BASE_CHARISMA" => $lang['Adr_classes_base_charisma'],
			"L_BASE_MAGIC_ATTACK" => $lang['Adr_classes_base_magic_attack'],
			"L_BASE_MAGIC_RESISTANCE" => $lang['Adr_classes_base_magic_resistance'],			
			"L_BASE_AC" => $lang['Adr_classes_base_ac'],
			"L_UPDATE_HP" => $lang['Adr_classes_update_hp'],
			"L_UPDATE_MP" => $lang['Adr_classes_update_mp'],
			"L_UPDATE_MIGHT" => $lang['Adr_classes_update_might'],
			"L_UPDATE_DEXTERITY" => $lang['Adr_classes_update_dexterity'],
			"L_UPDATE_CONSTITUTION" => $lang['Adr_classes_update_constitution'],
			"L_UPDATE_INTELLIGENCE" => $lang['Adr_classes_update_intelligence'],
			"L_UPDATE_WISDOM" => $lang['Adr_classes_update_wisdom'],
			"L_UPDATE_CHARISMA" => $lang['Adr_classes_update_charisma'],
			"L_UPDATE_MAGIC_ATTACK" => $lang['Adr_classes_update_magic_attack'],
			"L_UPDATE_MAGIC_RESISTANCE" => $lang['Adr_classes_update_magic_resistance'],			
			"L_UPDATE_AC" => $lang['Adr_classes_update_ac'],
			"L_NEW_CHARACTER_CLASS_DESC" => $lang['Adr_races_desc'],
			"L_NEW_CHARACTER_CLASS_CHOOSE" => $lang['Select'],
		));
	}
	else
	{
		$template->assign_block_vars( 'nocharacter' , array());

		if ( $adr_general['allow_reroll'] )
		{
			$template->assign_block_vars( 'nocharacter.reroll' , array());
		}

		// Prepare the level check for races , elements and alignments
		if ( $userdata['user_level'] == ADMIN )
		{
			$sql_race_level = '';
			$sql_element_level = '';
			$sql_alignment_level = '';
		}
		else if ( $userdata['user_level'] == MOD )
		{
			$sql_race_level = 'WHERE race_level <> 1';
			$sql_element_level = 'WHERE element_level  <> 1';
			$sql_alignment_level = 'WHERE alignment_level <> 1';
		}
		else
		{
			$sql_race_level = 'WHERE race_level = 0';
			$sql_element_level = 'WHERE element_level = 0';
			$sql_alignment_level = 'WHERE alignment_level = 0';
		}

		// Build the lists
		$sql = "SELECT *	FROM " . ADR_RACES_TABLE . "
			$sql_race_level ";
		$result = $db->sql_query($sql);
		if( !$result )
		{
			message_die(GENERAL_ERROR, 'Could not obtain races information', "", __LINE__, __FILE__, $sql);
		}
		$races = $db->sql_fetchrowset($result);
		$races_list = '<select name="race" tabindex="4">';
		for($i = 0; $i < count($races); $i++)
		{
			$races[$i]['race_name'] = adr_get_lang($races[$i]['race_name']);
			$previous_race = ( isset($HTTP_POST_VARS['race']) ) ? intval($HTTP_POST_VARS['race']) : 1;
			$race_selected = ( $previous_race == $races[$i]['race_id'] ) ? 'selected' : '';
			$races_list .= '<option value = "'.$races[$i]['race_id'].'" '.$race_selected.' >' . $races[$i]['race_name'] . '</option>';
		}
		$races_list .= '</select>';


		$sql = "SELECT *	FROM " . ADR_ELEMENTS_TABLE . "
			$sql_element_level ";
		$result = $db->sql_query($sql);
		if( !$result )
		{
			message_die(GENERAL_ERROR, 'Could not obtain elements information', "", __LINE__, __FILE__, $sql);
		}
		$elements = $db->sql_fetchrowset($result);
		$elements_list = '<select name="element" tabindex="5">';
		for($i = 0; $i < count($elements); $i++)
		{
			$elements[$i]['element_name'] = adr_get_lang($elements[$i]['element_name']);
			$previous_element = ( isset($HTTP_POST_VARS['element']) ) ? intval($HTTP_POST_VARS['element']) : 1;
			$element_selected = ( $previous_element == $elements[$i]['element_id'] ) ? 'selected' : '';
			$elements_list .= '<option value = "'.$elements[$i]['element_id'].'" '.$element_selected.' >' . $elements[$i]['element_name'] . '</option>';
		}
		$elements_list .= '</select>';
	
		$sql = "SELECT *	FROM " . ADR_ALIGNMENTS_TABLE . "
			$sql_alignment_level ";
		$result = $db->sql_query($sql);
		if( !$result )
		{
			message_die(GENERAL_ERROR, 'Could not obtain alignments information', "", __LINE__, __FILE__, $sql);
		}
		$alignments = $db->sql_fetchrowset($result);
		$alignments_list = '<select name="alignment" tabindex="6">';
		for($i = 0; $i < count($alignments); $i++)
		{
			$alignments[$i]['alignment_name'] = adr_get_lang($alignments[$i]['alignment_name']);
			$previous_alignment = ( isset($HTTP_POST_VARS['alignment']) ) ? intval($HTTP_POST_VARS['alignment']) : 1;
			$alignment_selected = ( $previous_alignment == $alignments[$i]['alignment_id'] ) ? 'selected' : '';
			$alignments_list .= '<option value = "'.$alignments[$i]['alignment_id'].'" '.$alignment_selected.' >' . $alignments[$i]['alignment_name'] . '</option>';
		}
		$alignments_list .= '</select>';
	
		if ( $HTTP_POST_VARS['power'] && !$adr_general['allow_reroll'] )
		{		
			$reuse_char 		= unexploit_user_characteristics($userdata['user_id']);
			$details 			= explode('%SPLIT%', $reuse_char);		
			$power 			= $details[0];
			$agility 			= $details[1];
			$endurance 			= $details[2];
			$intelligence 		= $details[3];
			$willpower 			= $details[4];
			$charm 			= $details[5];
			$magic_attack 		= $details[6];
			$magic_resistance 	= $details[7];
		}
		else
		{
			if ($adr_general['allow_reroll'])
			{
				$allow = 1;
			}
			else
			{
				$allow = '';
			}

			set_unexploited_characteristics($userdata['user_id'], $adr_general['min_characteristic'], $adr_general['max_characteristic'], $allow);
		
			$reuse_char 		= unexploit_user_characteristics($userdata['user_id']);
			$details 			= explode('%SPLIT%', $reuse_char);		
			$power 			= $details[0];
			$agility 			= $details[1];
			$endurance 			= $details[2];
			$intelligence 		= $details[3];
			$willpower 			= $details[4];
			$charm 			= $details[5];
			$magic_attack 		= $details[6];
			$magic_resistance 	= $details[7];				
		}

		$s_hidden_fields .= '<input type="hidden" name="race" value="' . $race . '" />';
		$s_hidden_fields .= '<input type="hidden" name="element" value="' . $element . '" />';
		$s_hidden_fields .= '<input type="hidden" name="alignment" value="' . $alignment . '" />';
		$s_hidden_fields .= '<input type="hidden" name="name" value="' . $name . '" />';
		$s_hidden_fields .= '<input type="hidden" name="bio" value="' . $bio . '" />';

		$template->assign_vars(array(
			'L_NEW_CHARACTER' => $lang['Adr_character_new'],
			'L_NEW_CHARACTER_NAME' => $lang['Adr_character_new_name'],
			'L_CHARACTERISTICS' => $lang['Adr_character_characteristics'],
			'L_POWER' => $lang['Adr_character_power'],
			'L_AGILITY' => $lang['Adr_character_agility'],
			'L_ENDURANCE' => $lang['Adr_character_endurance'],
			'L_INTELLIGENCE' => $lang['Adr_character_intelligence'],
			'L_WILLPOWER' => $lang['Adr_character_willpower'],
			'L_CHARM' => $lang['Adr_character_charm'],
			'L_MA' => $lang['Adr_character_ma'],
			'L_MD' => $lang['Adr_character_md'],
			'L_REROLL' => $lang['Adr_character_reroll'],
			'L_RACES_SELECT' => $lang['Adr_character_races_select'],
			'L_ELEMENTS_SELECT' => $lang['Adr_character_elements_select'],
			'L_ALIGNMENTS_SELECT' => $lang['Adr_character_alignments_select'],
			'L_RACES_MINI_FAQ' => $lang['Adr_character_races_mini_faq'],
			'L_ELEMENTS_MINI_FAQ' => $lang['Adr_character_elements_mini_faq'],
			'L_ALIGNMENTS_MINI_FAQ' => $lang['Adr_character_alignments_mini_faq'],
			'L_NEW_CHARACTER_BIOGRAPHY' => $lang['Adr_character_new_bio'],
			'L_NEW_CHARACTER_BIOGRAPHY_EXPLAIN' => $lang['Adr_character_new_bio_explain'],
			'BIO' => ( !empty($HTTP_POST_VARS['bio']) ) ? htmlspecialchars(stripslashes(trim(str_replace('<br />', "\n", $HTTP_POST_VARS['bio'] ) ))) : '',
			'NAME' => ( !empty($HTTP_POST_VARS['name']) ) ? htmlspecialchars(stripslashes($HTTP_POST_VARS['name'])) : '',
			'RACES_LIST' => $races_list,
			'ELEMENTS_LIST' => $elements_list,
			'ALIGNMENTS_LIST' => $alignments_list,
			
			'POWER' 		=> $power,
			'AGILITY' 		=> $agility,
			'ENDURANCE' 	=> $endurance,
			'INTELLIGENCE' 	=> $intelligence,
			'WILLPOWER' 	=> $willpower,
			'CHARM' 		=> $charm,
			'MA' 			=> $magic_attack,
			'MD' 			=> $magic_resistance,
						
			'MAX' => $adr_general['max_characteristic'],
			'S_HIDDEN_FIELDS' => $s_hidden_fields,
		));
	}

}

// He even has a character
else
{
	if ( $players )
	{
		adr_template_file('adr_character_battle_body.tpl');

		$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

		if ( isset($HTTP_GET_VARS['mode2']) || isset($HTTP_POST_VARS['mode2']) )
		{
			$mode2 = ( isset($HTTP_POST_VARS['mode2']) ) ? htmlspecialchars($HTTP_POST_VARS['mode2']) : htmlspecialchars($HTTP_GET_VARS['mode2']);
		}
		else
		{
			$mode2 = 'default';
		}

		if(isset($HTTP_POST_VARS['order']))
		{
			$sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
		}
		else if(isset($HTTP_GET_VARS['order']))
		{
			$sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
		}
		else
		{
			$sort_order = 'ASC';
		}

		$mode_types_text = array( $lang['Adr_pvp_result'] , $lang['Adr_pvp_player_name'] , $lang['Adr_pvp_player_level'] );
		$mode_types = array( 'result' , 'name', 'level' );
		
		$select_sort_mode = '<select name="mode2">';
		for($i = 0; $i < count($mode_types_text); $i++)
		{
			$selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
			$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
		}
		$select_sort_mode .= '</select>';

		$select_sort_order = '<select name="order">';
		if($sort_order == 'ASC')
		{
			$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
		}
		else
		{
			$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
		}
		$select_sort_order .= '</select>';

		switch( $mode2 )
		{
			case 'result':
				$order_by = "b.battle_result $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			case 'name':
				$order_by = "c.character_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			case 'level':
				$order_by = "c.character_level $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			default:
				$order_by = "b.battle_id $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
		}

		// Strange request isn't it ?
		$sql = "SELECT b.* , c.character_name , c.character_level FROM  " . ADR_BATTLE_PVP_TABLE . " b
			LEFT JOIN " . ADR_CHARACTERS_TABLE . " c ON ( ( b.battle_challenger_id = c.character_id AND b.battle_challenger_id <> $searchid ) OR ( b.battle_opponent_id = c.character_id AND b.battle_opponent_id <> $searchid ) )
			WHERE b.battle_result <> 0
			AND   b.battle_result <> 3
			AND ( b.battle_opponent_id = $searchid OR b.battle_challenger_id = $searchid )
			ORDER BY $order_by ";
		if ( !($result = $db->sql_query($sql)) ) 
		{ 
			message_die(CRITICAL_ERROR, 'Error Getting Adr Users!'); 
		}	

		if ( $row = $db->sql_fetchrow($result) )
		{
			$i = 0;
			do
			{
				$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
				
				if ( ( ($row['battle_result'] == 1) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 2) && ($row['battle_opponent_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_victory_current'] , $current_name);
				}
				else if ( ( ($row['battle_result'] == 1) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 2) && ($row['battle_challenger_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_victory_current'] , $row['character_name']);
				}
				else if ( ( ($row['battle_result'] == 5) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 6) && ($row['battle_opponent_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_stopped_current'] , $row['character_name']);
				}
				else if ( ( ($row['battle_result'] == 5) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 6) && ($row['battle_challenger_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_stopped_current'] , $current_name);
				}
				else if ( ( ($row['battle_result'] == 8) && ($row['battle_challenger_id'] == $searchid) ) || ( ($row['battle_result'] == 9) && ($row['battle_opponent_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_flee_current'] , $current_name);
				}
				else if ( ( ($row['battle_result'] == 8) && ($row['battle_opponent_id'] == $searchid) ) || ( ($row['battle_result'] == 9) && ($row['battle_challenger_id'] == $searchid) ) )
				{
					$battle_result = sprintf( $lang['Adr_pvp_flee_current'] , $row['character_name']);
				}

				$template->assign_block_vars('battle', array(
					"ROW_CLASS" => $row_class,
					"RESULT" => $battle_result ,
					"MONSTER_NAME" => adr_get_lang($row['character_name']),
					"MONSTER_LEVEL" => $row['character_level'],
				));

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

		$sql = "SELECT count(*) AS total FROM  " . ADR_BATTLE_PVP_TABLE . " 
			WHERE battle_result <> 0
			AND   battle_result <> 3
			AND ( battle_opponent_id = $searchid OR battle_challenger_id = $searchid )";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
		}
		if ( $total = $db->sql_fetchrow($result) )
		{
			$total_battle = $total['total'];
			$pagination = generate_pagination("adr_character.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;list=2", $total_battle , $board_config['topics_per_page'], $start). '&nbsp;';	
		}

		$template->assign_vars(array(
			'L_MONSTER_NAME' => $lang['Adr_pvp_player_name'],
			'L_MONSTER_LEVEL' => $lang['Adr_pvp_player_level'],
			'L_RESULT' => $lang['Adr_battle_result'],
			'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
			'L_ORDER' => $lang['Order'],
			'L_SORT' => $lang['Sort'],
			'L_SUBMIT' => $lang['Sort'],
			'S_MODE_SELECT' => $select_sort_mode,
			'S_ORDER_SELECT' => $select_sort_order,
			'PAGINATION' => $pagination,
			'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_battle  / $board_config['topics_per_page'] )), 
			'L_GOTO_PAGE' => $lang['Goto_page'],
			"S_BATTLE_ACTION" => append_sid("adr_character.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;list=2"),
		));
	}

	if ( $monsters )
	{
		adr_template_file('adr_character_battle_body.tpl');

		$start = ( isset($HTTP_GET_VARS['start']) ) ? intval($HTTP_GET_VARS['start']) : 0;

		if ( isset($HTTP_GET_VARS['mode2']) || isset($HTTP_POST_VARS['mode2']) )
		{
			$mode2 = ( isset($HTTP_POST_VARS['mode2']) ) ? htmlspecialchars($HTTP_POST_VARS['mode2']) : htmlspecialchars($HTTP_GET_VARS['mode2']);
		}
		else
		{
			$mode2 = 'default';
		}

		if(isset($HTTP_POST_VARS['order']))
		{
			$sort_order = ($HTTP_POST_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
		}
		else if(isset($HTTP_GET_VARS['order']))
		{
			$sort_order = ($HTTP_GET_VARS['order'] == 'ASC') ? 'ASC' : 'DESC';
		}
		else
		{
			$sort_order = 'ASC';
		}

		$mode_types_text = array( $lang['Adr_battle_result'] , $lang['Adr_battle_monster_name'] , $lang['Adr_battle_monster_level'] );
		$mode_types = array( 'result' , 'name', 'level' );
		
		$select_sort_mode = '<select name="mode2">';
		for($i = 0; $i < count($mode_types_text); $i++)
		{
			$selected = ( $mode2 == $mode_types[$i] ) ? ' selected="selected"' : '';
			$select_sort_mode .= '<option value="' . $mode_types[$i] . '"' . $selected . '>' . $mode_types_text[$i] . '</option>';
		}
		$select_sort_mode .= '</select>';

		$select_sort_order = '<select name="order">';
		if($sort_order == 'ASC')
		{
			$select_sort_order .= '<option value="ASC" selected="selected">' . $lang['Sort_Ascending'] . '</option><option value="DESC">' . $lang['Sort_Descending'] . '</option>';
		}
		else
		{
			$select_sort_order .= '<option value="ASC">' . $lang['Sort_Ascending'] . '</option><option value="DESC" selected="selected">' . $lang['Sort_Descending'] . '</option>';
		}
		$select_sort_order .= '</select>';

		switch( $mode2 )
		{
			case 'result':
				$order_by = "b.battle_result $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			case 'name':
				$order_by = "m.monster_name $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			case 'level':
				$order_by = "m.monster_level $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
			default:
				$order_by = "b.battle_id $sort_order LIMIT $start, " . $board_config['topics_per_page'];
				break;
		}

		$sql = "SELECT b.battle_result , m.monster_name , m.monster_level	FROM  " . ADR_BATTLE_LIST_TABLE . " b
			LEFT JOIN " . ADR_BATTLE_MONSTERS_TABLE . " m ON ( b.battle_opponent_id = m.monster_id )
			WHERE b.battle_type = 1 
			AND b.battle_challenger_id = $searchid 
			ORDER BY $order_by ";
		if ( !($result = $db->sql_query($sql)) ) 
		{ 
			message_die(CRITICAL_ERROR, 'Error Getting Adr Users!'); 
		}	

		if ( $row = $db->sql_fetchrow($result) )
		{
			$i = 0;
			do
			{
				$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
				
				if ( $row['battle_result'] == 1 )
				{
					$battle_result = $lang['Adr_battle_result_victory'];
				}
				else if ( $row['battle_result'] == 2 )
				{
					$battle_result = $lang['Adr_battle_result_defeat'];
				}
            		elseif  ( $row['battle_result'] == 3 )
            		{
               			$battle_result = $lang['Adr_battle_result_flee'];
            		}
            		else
            		{
               			$battle_result = $lang['Adr_battle_result_double_ko'];
            		} 

				$template->assign_block_vars('battle', array(
					"ROW_CLASS" => $row_class,
					"RESULT" => $battle_result ,
					"MONSTER_NAME" => adr_get_lang($row['monster_name']),
					"MONSTER_LEVEL" => $row['monster_level'],
				));

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


		$sql = "SELECT count(*) AS total FROM  " . ADR_BATTLE_LIST_TABLE . " 
			WHERE battle_challenger_id = $searchid 
			AND battle_type = 1 ";
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Error getting total users', '', __LINE__, __FILE__, $sql);
		}
		if ( $total = $db->sql_fetchrow($result) )
		{
			$total_battle = $total['total'];
			$pagination = generate_pagination("adr_character.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;list=1", $total_battle , $board_config['topics_per_page'], $start). '&nbsp;';	
		}

		$template->assign_vars(array(
			'L_MONSTER_NAME' => $lang['Adr_battle_monster_name'],
			'L_MONSTER_LEVEL' => $lang['Adr_battle_monster_level'],
			'L_RESULT' => $lang['Adr_battle_result'],
			'L_SELECT_SORT_METHOD' => $lang['Select_sort_method'],
			'L_ORDER' => $lang['Order'],
			'L_SORT' => $lang['Sort'],
			'L_SUBMIT' => $lang['Sort'],
			'S_MODE_SELECT' => $select_sort_mode,
			'S_ORDER_SELECT' => $select_sort_order,
			'PAGINATION' => $pagination,
			'PAGE_NUMBER' => sprintf($lang['Page_of'], ( floor( $start / $board_config['topics_per_page'] ) + 1 ), ceil( $total_battle  / $board_config['topics_per_page'] )), 
			'L_GOTO_PAGE' => $lang['Goto_page'],
			"S_BATTLE_ACTION" => append_sid("adr_character.$phpEx?".POST_USERS_URL."=$searchid&amp;mode2=$mode2&amp;order=$sort_order&amp;list=1"),
		));
	}

	$template->assign_block_vars( 'character' , array());

	if ( $user_id == $searchid )
	{
		$template->assign_block_vars( 'character.owner' , array());

	// START Cron check
		// The begining bit of code isn't pretty 
		// Had to revert to 3 seperate SELECT's because a combined one was coming out with weird results...
		// ...if you get a combined one to work ok please let me know. 

		// Character stats check
		$sql = " SELECT * FROM " . ADR_CHARACTERS_TABLE . "
			WHERE character_id = $user_id";
		if( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not query user stats page', '', __LINE__, __FILE__, $sql);
		}
		$character_check = $db->sql_fetchrow($result);

		// Vault account check
		$sql = " SELECT account_sum FROM " . ADR_VAULT_USERS_TABLE . "
			WHERE owner_id = $user_id";
		if( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not query user stats page', '', __LINE__, __FILE__, $sql);
		}
		$vault_check = $db->sql_fetchrow($result);

		// Shop stats check
		$sql = " SELECT shop_id FROM " . ADR_SHOPS_TABLE . "
			WHERE shop_owner_id = $user_id";
		if( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not query user stats page', '', __LINE__, __FILE__, $sql);
		}
		$shop_check = $db->sql_fetchrow($result);

		// Work out how many days have passed since character_creation
		$character_days = floor(( time() - $character_check['character_birth'] ) / 86400 );

		// START battle & skill regening
		if ( $adr_general['Adr_character_limit_enable'] != 0 && $character_days > ( $character_check['character_limit_update'] + ( $adr_general['Adr_limit_regen_duration'] - 1 ) ))
		{ 
			$new_battle_limit = $adr_general['Adr_character_battle_limit'];
			$new_skill_limit = $adr_general['Adr_character_skill_limit'];
			$new_trading_limit = $adr_general['Adr_character_trading_limit'];
			$new_thief_limit = $adr_general['Adr_character_thief_limit'];
			$new_event_limit = $adr_general['Adr_character_event_limit'];

			$sql = " UPDATE " . ADR_CHARACTERS_TABLE . " 
				SET character_battle_limit = $new_battle_limit ,
					character_event_limit = $new_event_limit , 
					character_skill_limit = $new_skill_limit , 
					character_trading_limit = $new_trading_limit , 
					character_thief_limit = $new_thief_limit , 
					character_limit_update = $character_days 
				WHERE character_id = $user_id ";
			if ( !($results = $db->sql_query($sql)) ) 
			{
				message_die(GENERAL_MESSAGE, 'Error regening user battle & skill limits');
			}
		}
		// END battle & skill regening

		// START warehouse tax check
		if ( $character_days > ( $character_check['character_warehouse_update'] + ( $board_config['Adr_warehouse_duration'] - 1 )) )
		{ 
			$warehouse_days = $character_days - ( $character_check['character_warehouse_update'] + ( $board_config['Adr_warehouse_duration'] - 1 ) );
			$warehouse_tax = $board_config['Adr_warehouse_tax'] * $warehouse_days;

			if ( $character_check['character_warehouse'] != 0 && $board_config['Adr_warehouse_tax'] > 0 )
			{
				if ( $points >= $warehouse_tax )
				{
					// Remove tax from user_points
					subtract_reward( $user_id, $warehouse_tax );
					
					$message = sprintf( $lang['Adr_character_warehouse_tax'] , $warehouse_tax , get_reward_name() );
				}
				elseif ( $points < $warehouse_tax && is_numeric($vault_check['account_sum']) && $vault_check['account_sum'] >= $warehouse_tax )
				{
					// Else remove from Vault
					$sql = "UPDATE " . ADR_VAULT_USERS_TABLE . "
							SET account_sum = account_sum - $warehouse_tax
							WHERE owner_id = $user_id ";
					if( !$db->sql_query($sql))
					{ 
						message_die(CRITICAL_ERROR, 'Error removing points for WH tax (vault)'); 
					}

					$message = sprintf( $lang['Adr_character_warehouse_tax'] , $warehouse_tax , get_reward_name() );
				}
				else
				{
					// Close warehouse
					$sql = " UPDATE " . ADR_CHARACTERS_TABLE . " 
						SET character_warehouse = 0 
							WHERE character_id = $user_id ";
					if( !$db->sql_query($sql)) 
					{
						message_die(GENERAL_MESSAGE, 'Error closing warehouse');
					}

					// Remove warehouse status from itemsif rent not paid
					$sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
						SET item_in_warehouse = 0
						WHERE item_owner_id = $user_id ";
					if( !$db->sql_query($sql) )
					{
						message_die(GENERAL_ERROR, 'Could not remove WH status for items', "", __LINE__, __FILE__, $sql);
					}

					$message = sprintf( $lang['Adr_character_warehouse_closed'] , $warehouse_tax , get_reward_name() );
				}
			}

			// Update user warehouse update time
			$sql = " UPDATE " . ADR_CHARACTERS_TABLE . " 
				SET character_warehouse_update = $character_days  
					WHERE character_id = $user_id ";
			if ( !($results = $db->sql_query($sql)) ) 
			{
				message_die(GENERAL_MESSAGE, 'Error updating warehouse');
			}

			if ( $character_check['character_warehouse'] != 0 && $board_config['Adr_warehouse_tax'] > 0 )
			{
				$direction = append_sid("adr_character.$phpEx");
				$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
				message_die ( GENERAL_MESSAGE , $message );
			}
		}
		// END warehouse tax check

		// START open shop tax check
		if (( $character_days > ( $character_check['character_shop_update'] + ( $board_config['Adr_shop_duration'] - 1 ) ) ))
		{ 
			$shop_days = $character_days - ( $character_check['character_shop_update'] + ( $board_config['Adr_shop_duration'] - 1 ));
			$shop_tax = $board_config['Adr_shop_tax'] * $shop_days;

			// see if user has a shop open
			if ( is_numeric($shop_check['shop_id']) && $board_config['Adr_shop_tax'] > 0 )
			{
				if ( $points >= $shop_tax )
				{
					// Remove tax from user_points
					subtract_reward( $user_id, $shop_tax );
					
					if ( $board_config['Adr_warehouse_tax'] > 0 )
					{
						$message .= sprintf( $lang['Adr_character_shop_tax'] , $shop_tax , get_reward_name() );
					}
					else
					{
						$message = sprintf( $lang['Adr_character_shop_tax'] , $shop_tax , get_reward_name() );		
					}
				}
				elseif ( $points < $shop_tax && is_numeric($vault_check['account_sum']) && $vault_check['account_sum'] >= $shop_tax )
				{
					$sql = "UPDATE " . ADR_VAULT_USERS_TABLE . "
							SET account_sum = account_sum - $shop_tax
							WHERE owner_id = $user_id ";
					if( !$db->sql_query($sql))
					{ 
						message_die(CRITICAL_ERROR, 'Error removing points for shop (vault)'); 
					}

					if ( $board_config['Adr_warehouse_tax'] > 0 )
					{
						$message .= sprintf( $lang['Adr_character_shop_tax'] , $shop_tax , get_reward_name() );
					}
					else
					{
						$message = sprintf( $lang['Adr_character_shop_tax'] , $shop_tax , get_reward_name() );		
					}
				}
				else
				{
					// Remove shop status from items & close shop if rent not paid
					$sql = "UPDATE " . ADR_SHOPS_ITEMS_TABLE ."
						SET item_in_shop = 0
						WHERE item_owner_id = $user_id ";
					if( !$db->sql_query($sql) )
					{
						message_die(GENERAL_ERROR, 'Could not remove shop status for items', "", __LINE__, __FILE__, $sql);
					}

					$sql = "DELETE FROM " . ADR_SHOPS_TABLE ."
						WHERE shop_owner_id = $user_id ";
					if( !$db->sql_query($sql) )
					{
						message_die(GENERAL_ERROR, 'Could not delete shop', "", __LINE__, __FILE__, $sql);
					}

					$message = sprintf( $lang['Adr_character_shop_closed'] , $shop_tax , get_reward_name() );						
				}
			}

			// Last shop update
			$sql = " UPDATE " . ADR_CHARACTERS_TABLE . " 
				SET character_shop_update = $character_days  
					WHERE character_id = $user_id ";
			if ( !($results = $db->sql_query($sql)) ) 
			{
				message_die(GENERAL_MESSAGE, 'Error updating warehouse');
			}

			if ( is_numeric($shop_check['shop_id']) && $board_config['Adr_shop_tax'] > 0 )
			{
				$direction = append_sid("adr_character.$phpEx");
				$message .= '<br /><br />'.sprintf($lang['Adr_return'],"<a href=\"" . $direction . "\">", "</a>") ;
				message_die ( GENERAL_MESSAGE , $message );
			}
		}
		// END open shop tax check
	// END Cron check


		// Check if the user can gain a level
		if ( adr_seek_levelup($user_id) )
		{
			$template->assign_block_vars( 'character_level_up' , array());

			if ( $Level_up )
			{
				$carac[1]='character_might';
				$carac[2]='character_dexterity';
				$carac[3]='character_constitution';
				$carac[4]='character_intelligence';
				$carac[5]='character_wisdom';
				$carac[6]='character_charisma';
				$carac[7]='character_magic_attack';
				$carac[8]='character_magic_resistance';

				$sql = "UPDATE " . ADR_CHARACTERS_TABLE . "
					SET $carac[$carac_up] = $carac[$carac_up] + 1 
				WHERE character_id = $user_id ";
				if (!($result = $db->sql_query($sql) ))
				{
					message_die(GENERAL_ERROR, 'Could not update user experience',"", __LINE__, __FILE__, $sql);
				}
				adr_level_up($user_id , character_page );
			}
		}

		// Check if the user can delete his character
		if ( $adr_general['allow_character_delete'] )
		{
			$template->assign_block_vars( 'character.owner.delete' , array());
		}

		if ( $delete )
		{
			adr_template_file('adr_confirm_body.tpl');
			$template->assign_block_vars('delete_character' , array());

			$template->assign_vars(array(
				'MESSAGE_TITLE' => $lang['Adr_items_sell_confirm'],
				'MESSAGE_TEXT' => $lang['Adr_character_delete_confirm'],
				'L_YES' => $lang['Yes'],
				'L_NO' => $lang['No'],
			));

		}

		else if ( $delete_confirm )
		{
			// Active loan check
			$sql = "SELECT loan_time FROM " . ADR_VAULT_USERS_TABLE . "
				WHERE owner_id = $user_id ";
			if ( !($result = $db->sql_query($sql)) ) 
			{ 
				message_die(CRITICAL_ERROR, 'Error Getting Vault Users!'); 
			}
			$loan_check = $db->sql_fetchrow($result);

			if ( $loan_check['loan_time'] <= 0 )			
			{
				$sql = " DELETE FROM " . ADR_CHARACTERS_TABLE . "
					WHERE character_id = $user_id ";
				if (!$db->sql_query($sql))
				{
					message_die(GENERAL_ERROR, 'Cannot delete this user', '', __LINE__, __FILE__, $sql);
				}

				$sql = " DELETE FROM " . ADR_BATTLE_LIST_TABLE . "
					WHERE battle_challenger_id = $user_id 
					AND battle_type = 1 ";
				if (!$db->sql_query($sql))
				{
					message_die(GENERAL_ERROR, 'Cannot delete this user', '', __LINE__, __FILE__, $sql);
				}

            		$sql = "DELETE FROM " . ADR_SHOPS_TABLE ."
               			WHERE shop_owner_id = $user_id ";
            		if( !$db->sql_query($sql) )
            		{
               			message_die(GENERAL_ERROR, 'Could not delete shop', "", __LINE__, __FILE__, $sql);
            		} 

				adr_update_posters_infos();
				adr_previous( Adr_character_successful_deleted , adr_character , '' );
			}

			else
			{
				adr_previous( Adr_character_active_loan , adr_character , '' );				
			}
		}

		else if ( $bio_edit )
		{
			adr_template_file('adr_character_edit_body.tpl');

			$message = $row['character_desc'];
			$message = str_replace('<', '&lt;', $message);
			$message = str_replace('>', '&gt;', $message);
			$message = str_replace('<br />', "\n", $message);

			$template->assign_vars(array(
				'L_SUBMIT' => $lang['Submit'],
				'L_NEW_CHARACTER_BIOGRAPHY' => $lang['Adr_character_new_bio'],
				'L_NEW_CHARACTER_BIOGRAPHY_EXPLAIN' => $lang['Adr_character_new_bio_explain'],
				'NEW_BIO' => $message,
			));
		}
		else if ( $upgrade_bio )
		{
			$bio = $HTTP_POST_VARS['new_bio'];

			$sql = "UPDATE " . ADR_CHARACTERS_TABLE . "
				SET character_desc = '$bio'
				WHERE character_id = $user_id ";
			if ( !($result = $db->sql_query($sql)) ) 
			{ 
				message_die(CRITICAL_ERROR, 'Error updating bio informations !'); 
			}

			adr_previous( Adr_character_bio_updated , adr_character , '' );
		}

		// Check if quota limits are enabled
		if ( $adr_general['Adr_character_limit_enable'] == 1 )
		{
			$template->assign_block_vars( 'character.limit' , array());
		}
	}

	$avatar_img = '';
	if ( $view_userdata['user_avatar_type'] && $view_userdata['user_allowavatar'] )
	{
		switch( $view_userdata['user_avatar_type'] )
		{
			case USER_AVATAR_UPLOAD:
				$avatar_img = ( $board_config['allow_avatar_upload'] ) ? '<img src="' . $board_config['avatar_path'] . '/' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
				break;
			case USER_AVATAR_REMOTE:
				$avatar_img = ( $board_config['allow_avatar_remote'] ) ? '<img src="' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
				break;
			case USER_AVATAR_GALLERY:
				$avatar_img = ( $board_config['allow_avatar_local'] ) ? '<img src="' . $board_config['avatar_gallery_path'] . '/' . $view_userdata['user_avatar'] . '" alt="" border="0" />' : '';
				break;
		}
	}

	$sql = "SELECT c.* , r.race_name , r.race_weight , r.race_weight_per_level , r.race_img , e.element_name , e.element_img , a.alignment_name , a.alignment_img , cl.class_name , cl.class_img , cl.class_update_xp_req
		FROM  " . ADR_CHARACTERS_TABLE . " c , " . ADR_RACES_TABLE . " r , " . ADR_ELEMENTS_TABLE . " e , " . ADR_ALIGNMENTS_TABLE . " a , " . ADR_CLASSES_TABLE . " cl
		WHERE c.character_id= $searchid
		AND cl.class_id = c.character_class
		AND r.race_id = c.character_race
		AND e.element_id = c.character_element
		AND a.alignment_id = c.character_alignment ";
	if ( !($result = $db->sql_query($sql)) ) 
	{ 
		message_die(CRITICAL_ERROR, 'Error Getting Adr Users!'); 
	}	
	$row = $db->sql_fetchrow($result);

	if ( $row['character_desc'] )
	{
		$template->assign_block_vars( 'character.bio' , array());
	}

	$class = adr_get_lang($row['class_name']);
	$race = adr_get_lang($row['race_name']);
	$element = adr_get_lang($row['element_name']);
	$alignment = adr_get_lang($row['alignment_name']);

	// Work out weight stats
	$max_weight = adr_weight_stats($row['character_level'], $row['race_weight'], $row['race_weight_per_level'], $row['character_might']);

	// Count up characters current weight
	$sql = "SELECT SUM(item_weight) AS total FROM  " . ADR_SHOPS_ITEMS_TABLE . "
		WHERE item_owner_id = $searchid 
		AND item_in_warehouse = 0 
		AND item_duration > 0
		AND item_in_shop = 0";
	if ( !($result = $db->sql_query($sql)) ) 
	{ 
		message_die(CRITICAL_ERROR, 'Error Getting Adr Users!'); 
	}	
	$weight = $db->sql_fetchrow($result);
	if ( $weight[total] != '' )
	{
		$current_weight = $weight[total];
	}
	else
	{
		$current_weight = 0;
	}

	//changed from max_hp to max_xp
   	$max_xp = $row['class_update_xp_req'];
   	for ( $p = 1 ; $p < $row['character_level'] ; $p ++ )
  	{
      	$max_xp = floor($max_xp * (( $adr_general['next_level_penalty'] + 100 ) / 100 ));
   	}

	##=== Create bar widths ===##
		list($hp_percent_width, $hp_percent_empty) = adr_make_bars($row['character_hp'], $row['character_hp_max'], '318');
		list($mp_percent_width, $mp_percent_empty) = adr_make_bars($row['character_mp'], $row['character_mp_max'], '318');
		list($exp_percent_width, $exp_percent_empty) = adr_make_bars($row['character_xp'], $max_xp, '318');
		list($weight_percent_width, $weight_percent_empty) = adr_make_bars($current_weight, $max_weight, '318');
	##=== Create bar widths ===##

	$template->assign_vars(array(
		'LEVEL' => $row['character_level'],
		'POWER' => $row['character_might'],
		'AGILITY' => $row['character_dexterity'],
		'CONSTIT' => $row['character_constitution'],
		'INT' => $row['character_intelligence'],
		'WIS' => $row['character_wisdom'],
		'CHA' => $row['character_charisma'],
		'MA' => $row['character_magic_attack'],
		'MD' => $row['character_magic_resistance'],
		'POINTS' => number_format($view_userdata['user_points']),
		'HP' => $row['character_hp'],
		'MP' => $row['character_mp'],
		'EXP' => $row['character_xp'],
		'HP_MAX' => $row['character_hp_max'],
		'MP_MAX' => $row['character_mp_max'],
		'SP' => number_format($row['character_sp']),
		'EXP_MAX' => $max_xp,
		'WEIGHT' => $current_weight,
		'WEIGHT_MAX' => $max_weight,
		'WEIGHT_PERCENT_WIDTH' => $weight_percent_width,
		'BATTLE_VICTORIES' => $row['character_victories'],
		'BATTLE_DEFEATS' => $row['character_defeats'],
		'BATTLE_FLEES' => $row['character_flees'],
		'BATTLE_DOUBLE_KO' => $row['character_double_ko'],
		'BATTLE_LIMIT' => $row['character_battle_limit'],
		'SKILL_LIMIT' => $row['character_skill_limit'],
		'TRADING_LIMIT' => $row['character_trading_limit'],
		'THIEF_LIMIT' => $row['character_thief_limit'],
		'EVENT_LIMIT' => $row['character_event_limit'],
		'AC' => $row['character_ac'],
		'NAME' => $row['character_name'],
		'BIO' => str_replace("\n", "\n<br />\n", $row['character_desc']),
		'AVATAR_IMG' => $avatar_img, 
		'CLASS' => $class,
		'RACE' => $race,
		'ELEMENT' => $element,
		'ALIGNMENT' => $alignment,
		'CLASS_IMG' => $row['class_img'],
		'RACE_IMG' => $row['race_img'],
		'ELEMENT_IMG' => $row['element_img'],
		'ALIGNMENT_IMG' => $row['alignment_img'],
		'HP_PERCENT_WIDTH' => $hp_percent_width,
		'MP_PERCENT_WIDTH' => $mp_percent_width,
		'EXP_PERCENT_WIDTH' => $exp_percent_width,
		'ADR_YEAR' => $adr_years,
		'ADR_MONTH' => $adr_months,
		'ADR_WEEK' => $adr_weeks,
		'ADR_DAY' => $adr_days,
		'ADR_HOUR' => $adr_hours,
		'CHAR_YEAR' => adr_character_age($user_id, '0'),
		'HP_PERCENT_EMPTY' => $hp_percent_empty,
		'MP_PERCENT_EMPTY' => $mp_percent_empty,
		'EXP_PERCENT_EMPTY' => $exp_percent_empty,
		'WEIGHT_PERCENT_EMPTY' => $weight_percent_empty,
		'L_YEAR' => $lang['year'],
		'L_MONTH' => $lang['month'],
		'L_WEEK' => $lang['week'],
		'L_DAY' => $lang['day'],
		'L_HOUR' => $lang['hour'],
		'L_AGE' => $lang['Adr_character_age'],
		'L_CHARACTER_AGE' => $lang_age,
		'L_MA' => $lang['Adr_character_ma'],
		'L_MD' => $lang['Adr_character_md'],
		'L_BIO' => $lang['Adr_character_new_bio'],
		'L_CLASS' => $lang['Adr_character_class'],
		'L_RACE' => $lang['Adr_character_race'],
		'L_ELEMENT' => $lang['Adr_character_element'],
		'L_ALIGNMENT' => $lang['Adr_character_alignment'],
		'L_HEALTH'=> $lang['Adr_character_health'],
		'L_MAGIC' => $lang['Adr_character_magic'],
		'L_EXPERIENCE' => $lang['Adr_character_experience'],	
		'L_SP' => $lang['Adr_character_sp'],	
		'L_WEIGHT' => $lang['Adr_character_weight'],	
		'L_AC' => $lang['Adr_character_ac'],
		'L_POWER' => $lang['Adr_character_power'],
		'L_AGILITY' => $lang['Adr_character_agility'],
		'L_CONSTIT' => $lang['Adr_character_endurance'],
		'L_INT' => $lang['Adr_character_intelligence'],
		'L_WIS' => $lang['Adr_character_willpower'],
		'L_CHA' => $lang['Adr_character_charm'],
		'L_POINTS' => get_reward_name(),
		'L_BATTLE_STATISTICS' => $lang['Adr_character_battle_statistics'],
		'L_BATTLE_VICTORIES' => $lang['Adr_character_victories'],
		'L_BATTLE_DEFEATS' => $lang['Adr_character_defeats'],
		'L_BATTLE_SKILLS' => $lang['Adr_character_battle_skills'],
		'L_BATTLE_LIMIT' => $lang['Adr_character_battle_limit'],
		'L_SKILL_LIMIT' => $lang['Adr_character_skill_limit'],
		'L_TRADING_LIMIT' => $lang['Adr_character_trading_limit'],
		'L_THIEF_LIMIT' => $lang['Adr_character_thief_limit'],
		'L_BATTLE_FLEES' => $lang['Adr_character_flees'],
		'L_BATTLE_DOUBLE_KO' => $lang['Adr_character_double_ko'], 
		'L_BATTLE_SEE_MONSTERS' => $lang['Adr_character_battle_history_monsters'],
		'L_BATTLE_SEE_PLAYERS' => $lang['Adr_character_battle_history_players'],
		'L_CHARACTER_LEVEL_UP' => $lang['Adr_level_up'],
		'L_CHARACTER_LEVEL_UP_SELECT' => $lang['Adr_level_up_select'],
		'L_LEVEL_UP' => $lang['Adr_level_up_perform'],
		'L_DELETE_CHARACTER' => $lang['Adr_character_delete'],
		'L_EDIT_CHARACTER' => $lang['Adr_character_edit'],
	));

	include($phpbb_root_path . 'adr/includes/adr_header.'.$phpEx);
}

$template->assign_vars(array(
	'L_NAME' => $lang['Adr_races_name'],
	'L_DESC' => $lang['Adr_races_desc'],
	'L_IMG' => $lang['Adr_races_image'],
	'L_LEVEL' => $lang['Adr_character_level'],
	'L_PROGRESS' => $lang['Adr_character_progress'],
	'L_SKILLS' => $lang['Adr_character_skills'],
	'L_CHARACTER_OF' => sprintf ( $lang['Adr_character_of'], $view_userdata['username'] ),
	'L_STEP2' => $lang['Adr_character_new_step2'],
	'L_STEP4' => $lang['Adr_character_new_step4'],
	'L_NEW_CHARACTER_CLASS' => $lang['Adr_character_new_class'],
	'S_CHARACTER_ACTION'     => append_sid("adr_character.$phpEx?".POST_USERS_URL."=".$searchid),
));

$template->pparse('body');
#==== Start Copyright ======================== |
?>
	<SCRIPT language="JavaScript">
	function copyright()
		{
		var popurl 	= "adr/includes/adr_copy.php" 
		var winpops = window.open(popurl, "", "width=400, height=350,")
		}
	</SCRIPT>
	
	<?PHP
echo "<table width='100%' border='0'>
		<tr>
			<td align='center' valign='top' colspan='1'>
				<span class='genmed'>
					<a style='TEXT-DECORATION:NONE;' href='javascript:copyright();'><span class='gensmall'>&copy; ADR</a></span>
				</span>
			</td>
		</tr>
	  </table>";
#==== End Copyright ========================== |
include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
 
?> 
Return current item: MetaBB