<?php
session_start();	
error_reporting(E_ERROR);
$CONFIG_INI = parse_ini_file(REAL_PATH_ISHOP.'include/extern/config.ini', true);
define('GAME_MYSQL_HOST',$CONFIG_INI['game_mysql']['host']);
define('GAME_MYSQL_USER',$CONFIG_INI['game_mysql']['user']);
define('GAME_MYSQL_PASSWORD',$CONFIG_INI['game_mysql']['password']);
define('GAME_MYSQL_PORT',$CONFIG_INI['game_mysql']['port']);
define('GAME_MYSQL_ACCOUNT',$CONFIG_INI['game_mysql']['account_db']);
define('GAME_MYSQL_PLAYER',$CONFIG_INI['game_mysql']['player_db']);
define('GAME_MYSQL_ITEM_NAME',$CONFIG_INI['game_mysql']['item_name_field']);
define('ISHOP_MYSQL_HOST',$CONFIG_INI['ishop_mysql']['host']);
define('ISHOP_MYSQL_USER',$CONFIG_INI['ishop_mysql']['user']);
define('ISHOP_MYSQL_PASSWORD',$CONFIG_INI['ishop_mysql']['password']);
define('ISHOP_MYSQL_PORT',$CONFIG_INI['ishop_mysql']['port']);
define('ISHOP_MYSQL_DB',$CONFIG_INI['ishop_mysql']['ishop_db']);
define('ISHOP_ADMIN_NAME',$CONFIG_INI['admin_list']['player_name']);
define('ISHOP_LANG',$CONFIG_INI['ishop_config']['lang']);
define('ISHOP_MAINTENANCE',$CONFIG_INI['ishop_config']['maintenance']);
define('ISHOP_CRYPT_KEY',$CONFIG_INI['ishop_config']['game_ishop_key']);
define('ISHOP_SERVERNAME',$CONFIG_INI['ishop_config']['server_name']);
define('ISHOP_MONEYNAME',$CONFIG_INI['ishop_config']['money_name']);
define('ISHOP_SHORT_MONEY',$CONFIG_INI['ishop_config']['money_short_name']);
define('ISHOP_MONEY_FIELD',$CONFIG_INI['ishop_config']['money_account_field']);
define('ISHOP_SECOND_MONEY',$CONFIG_INI['ishop_config']['second_money_name']);
define('ISHOP_SECOND_SHORT_MONEY',$CONFIG_INI['ishop_config']['second_money_short_name']);
define('ISHOP_SECOND_MONEY_FIELD',$CONFIG_INI['ishop_config']['second_money_account_field']);
define('ISHOP_DEFAULT_CAT_ID',$CONFIG_INI['ishop_config']['default_cat_id']);
define('ISHOP_BUY_POINT_URL',$CONFIG_INI['ishop_config']['buy_point_url']);
define('ISHOP_ACCOUNT_BONUS_ENABLE',$CONFIG_INI['ishop_config']['account_bonus_enable']);
function is_admin(){
	$ADMIN_LIST = explode('-',ISHOP_ADMIN_NAME);
		if(count($ADMIN_LIST) == 0){
			if(GetPlayerInfo(GetPlayerSelectID(),'name') == ISHOP_ADMIN_NAME){
				return true;
			}else{
				return false;
			}
		}else{
			foreach($ADMIN_LIST as $admin){
				if($admin == GetPlayerInfo(GetPlayerSelectID(),'name')){
					
					return true;
					break;
				}
			}
			return false;
		}
	
}
$item_types = array( "ITEM_NONE", "ITEM_WEAPON", "ITEM_ARMOR", "ITEM_USE", "ITEM_AUTOUSE", "ITEM_MATERIAL", "ITEM_SPECIAL", "ITEM_TOOL",
						"ITEM_LOTTERY", "ITEM_ELK", "ITEM_METIN", "ITEM_CONTAINER", "ITEM_FISH", "ITEM_ROD", "ITEM_RESOURCE", "ITEM_CAMPFIRE",
						"ITEM_UNIQUE", "ITEM_SKILLBOOK", "ITEM_QUEST", "ITEM_POLYMORPH", "ITEM_TREASURE_BOX", "ITEM_TREASURE_KEY",
						"ITEM_SKILLFORGET", "ITEM_GIFTBOX", "ITEM_PICK", "ITEM_HAIR", "ITEM_TOTEM", "ITEM_BLEND", "ITEM_COSTUME") ;

$antiflag_types = array( "ANTI_FEMALE", "ANTI_MALE", "ANTI_MUSA", "ANTI_ASSASSIN", "ANTI_SURA", "ANTI_MUDANG",
							"ANTI_GET", "ANTI_DROP", "ANTI_SELL", "ANTI_EMPIRE_A", "ANTI_EMPIRE_B", "ANTI_EMPIRE_C",
							"ANTI_SAVE", "ANTI_GIVE", "ANTI_PKDROP", "ANTI_STACK", "ANTI_MYSHOP", "ANTI_SAFEBOX") ;

$item_subtype = array(  /*0*/0,
						/*1*/array( "WEAPON_SWORD", "WEAPON_DAGGER", "WEAPON_BOW", "WEAPON_TWO_HANDED",
									"WEAPON_BELL", "WEAPON_FAN", "WEAPON_ARROW", "WEAPON_MOUNT_SPEAR"),
						/*2*/array( "ARMOR_BODY", "ARMOR_HEAD", "ARMOR_SHIELD", "ARMOR_WRIST", "ARMOR_FOOTS",
									"ARMOR_NECK", "ARMOR_EAR", "ARMOR_NUM_TYPES"),
						/*3*/array( "USE_POTION", "USE_TALISMAN", "USE_TUNING", "USE_MOVE", "USE_TREASURE_BOX", "USE_MONEYBAG", "USE_BAIT",
									"USE_ABILITY_UP", "USE_AFFECT", "USE_CREATE_STONE", "USE_SPECIAL", "USE_POTION_NODELAY", "USE_CLEAR",
									"USE_INVISIBILITY", "USE_DETACHMENT", "USE_BUCKET", "USE_POTION_CONTINUE", "USE_CLEAN_SOCKET",
									"USE_CHANGE_ATTRIBUTE", "USE_ADD_ATTRIBUTE", "USE_ADD_ACCESSORY_SOCKET", "USE_PUT_INTO_ACCESSORY_SOCKET",
									"USE_ADD_ATTRIBUTE2", "USE_RECIPE", "USE_CHANGE_ATTRIBUTE2", "USE_BIND", "USE_UNBIND"),
						/*4*/array( "AUTOUSE_POTION", "AUTOUSE_ABILITY_UP", "AUTOUSE_BOMB", "AUTOUSE_GOLD", "AUTOUSE_MONEYBAG", "AUTOUSE_TREASURE_BOX"),
						/*5*/array( "MATERIAL_LEATHER", "MATERIAL_BLOOD", "MATERIAL_ROOT", "MATERIAL_NEEDLE", "MATERIAL_JEWEL"),
						/*6*/array( "SPECIAL_MAP", "SPECIAL_KEY", "SPECIAL_DOC", "SPECIAL_SPIRIT"),
						/*7*/array( "TOOL_FISHING_ROD" ),
						/*8*/array( "LOTTERY_TICKET", "LOTTERY_INSTANT" ),
						/*9*/0,
						/*10*/array( "METIN_NORMAL", "METIN_GOLD" ),
						/*11*/0,
						/*12*/array( "FISH_ALIVE", "FISH_DEAD"),
						/*13*/0,
						/*14*/array( "RESOURCE_FISHBONE", "RESOURCE_WATERSTONEPIECE", "RESOURCE_WATERSTONE", "RESOURCE_BLOOD_PEARL",
										"RESOURCE_BLUE_PEARL", "RESOURCE_WHITE_PEARL", "RESOURCE_BUCKET", "RESOURCE_CRYSTAL", "RESOURCE_GEM",
										"RESOURCE_STONE", "RESOURCE_METIN", "RESOURCE_ORE" ),
						/*15*/0,
						/*16*/array( "UNIQUE_NONE", "UNIQUE_BOOK", "UNIQUE_SPECIAL_RIDE" ),
						/*17*/0,
						/*18*/0,
						/*19*/0,
						/*20*/0,
						/*21*/0,
						/*22*/0,
						/*23*/0,
						/*24*/0,
						/*25*/0,
						/*26*/0,
						/*27*/0,
						/*28*/array( "COSTUME_BODY", "COSTUME_HAIR" )
					) ;

$flag_types = array( "ITEM_TUNABLE", "ITEM_SAVE", "ITEM_STACKABLE", "COUNT_PER_1GOLD", "ITEM_SLOW_QUERY", "ITEM_UNIQUE",
						"ITEM_MAKECOUNT", "ITEM_IRREMOVABLE", "CONFIRM_WHEN_USE", "QUEST_USE", "QUEST_USE_MULTIPLE",
						"QUEST_GIVE", "ITEM_QUEST", "LOG", "STACKABLE", "SLOW_QUERY", "REFINEABLE", "IRREMOVABLE", "ITEM_APPLICABLE") ;

$wearflag_types = array( "WEAR_BODY", "WEAR_HEAD", "WEAR_FOOTS", "WEAR_WRIST", "WEAR_WEAPON", "WEAR_NECK", "WEAR_EAR", "WEAR_SHIELD", "WEAR_UNIQUE",
							"WEAR_ARROW", "WEAR_HAIR", "WEAR_ABILITY") ;

$limit_types = array("LIMIT_NONE", "LEVEL", "STR", "DEX", "INT", "CON", "PC_BANG", "REAL_TIME") ;

$apply_types = array( "APPLY_NONE", "APPLY_MAX_HP", "APPLY_MAX_SP", "APPLY_CON", "APPLY_INT", "APPLY_STR", "APPLY_DEX", "APPLY_ATT_SPEED",
						"APPLY_MOV_SPEED", "APPLY_CAST_SPEED", "APPLY_HP_REGEN", "APPLY_SP_REGEN", "APPLY_POISON_PCT", "APPLY_STUN_PCT",
						"APPLY_SLOW_PCT", "APPLY_CRITICAL_PCT", "APPLY_PENETRATE_PCT", "APPLY_ATTBONUS_HUMAN", "APPLY_ATTBONUS_ANIMAL",
						"APPLY_ATTBONUS_ORC", "APPLY_ATTBONUS_MILGYO", "APPLY_ATTBONUS_UNDEAD", "APPLY_ATTBONUS_DEVIL", "APPLY_STEAL_HP",
						"APPLY_STEAL_SP", "APPLY_MANA_BURN_PCT", "APPLY_DAMAGE_SP_RECOVER", "APPLY_BLOCK", "APPLY_DODGE", "APPLY_RESIST_SWORD",
						"APPLY_RESIST_TWOHAND", "APPLY_RESIST_DAGGER", "APPLY_RESIST_BELL", "APPLY_RESIST_FAN", "APPLY_RESIST_BOW", "APPLY_RESIST_FIRE",
						"APPLY_RESIST_ELEC", "APPLY_RESIST_MAGIC", "APPLY_RESIST_WIND", "APPLY_REFLECT_MELEE", "APPLY_REFLECT_CURSE", "APPLY_POISON_REDUCE",
						"APPLY_KILL_SP_RECOVER", "APPLY_EXP_DOUBLE_BONUS", "APPLY_GOLD_DOUBLE_BONUS", "APPLY_ITEM_DROP_BONUS", "APPLY_POTION_BONUS",
						"APPLY_KILL_HP_RECOVER", "APPLY_IMMUNE_STUN", "APPLY_IMMUNE_SLOW", "APPLY_IMMUNE_FALL", "APPLY_SKILL", "APPLY_BOW_DISTANCE",
						"APPLY_ATT_GRADE_BONUS", "APPLY_DEF_GRADE_BONUS", "APPLY_MAGIC_ATT_GRADE", "APPLY_MAGIC_DEF_GRADE", "APPLY_CURSE_PCT",
						"APPLY_MAX_STAMINA", "APPLY_ATTBONUS_WARRIOR", "APPLY_ATTBONUS_ASSASSIN", "APPLY_ATTBONUS_SURA", "APPLY_ATTBONUS_SHAMAN",
						"APPLY_ATTBONUS_MONSTER", "APPLY_MALL_ATTBONUS", "APPLY_MALL_DEFBONUS", "APPLY_MALL_EXPBONUS", "APPLY_MALL_ITEMBONUS",
						"APPLY_MALL_GOLDBONUS", "APPLY_MAX_HP_PCT", "APPLY_MAX_SP_PCT", "APPLY_SKILL_DAMAGE_BONUS", "APPLY_NORMAL_HIT_DAMAGE_BONUS",
						"APPLY_SKILL_DEFEND_BONUS", "APPLY_NORMAL_HIT_DEFEND_BONUS", "APPLY_PC_BANG_EXP_BONUS", "APPLY_PC_BANG_DROP_BONUS",
						"APPLY_EXTRACT_HP_PCT", "APPLY_RESIST_WARRIOR", "APPLY_RESIST_ASSASSIN", "APPLY_RESIST_SURA", "APPLY_RESIST_SHAMAN") ;

$immune_types = array("PARA","CURSE","STUN","SLEEP","SLOW","POISON","TERROR") ;

$mob_ranks = array( "PAWN", "S_PAWN", "KNIGHT", "S_KNIGHT", "BOSS", "KING" );
$mob_battle_types = array( "MELEE", "RANGE", "MAGIC", "SPECIAL", "POWER", "TANKER", "SUPER_POWER", "SUPER_TANKER" );
$mob_types = array( "MONSTER", "NPC", "STONE", "WARP", "DOOR", "BUILDING", "PC", "POLYMORPH_PC", "HORSE", "GOTO" );
$mob_onclick_events = array( "NONE", "SHOP", "TALK" );

function get_bit_flag($val, $container)
{
	if (0 == $val)
		return "NONE";

	$pos = 0;
	$ret = "";

	while(true)
	{
		if ($val == 0)
			 break;

		if( ($val & 1) == 1 )
		{
			if( $ret == "" )
			{
				$ret .= $container[$pos];
			}
			else
			{
				$ret .= " | ";
				$ret .= $container[$pos];
			}
		}

		$pos++;
		$val >>= 1;
	}

	return $ret;
}

function get_bit_value($val, $container)
{
	$ret = 0 ;

	for( $i=0 ; $i < sizeof($val) ; $i++ )
	{
		if ("NONE" === $val[$i])
			continue;

		$idx = array_search($val[$i], $container) ;

		if( $idx === FALSE )
		{
			echo "ERROR ".$val[$i]." no matching flag\n";
			continue ;
		}

		$ret += ( 1 << $idx ) ;
	}

	return $ret ;
}


function get_limit_type($val)
{
	global $limit_types ;
	return $limit_types[$val] ;
}

function get_limit_type_value($val)
{
	if( $val[0] == "" ) return 0 ;

	global $limit_types ;
	$idx = array_search($val, $limit_types) ;

	if( $idx === FALSE )
	{
		echo "\n\n\n\nERROR ON get_limit_type_value ".$val."\n\n\n\n" ;
		exit ;
		return 0 ;
	}

	return $idx ;
}

function get_anti_flag($val)
{
	global $antiflag_types ;
	return get_bit_flag($val, $antiflag_types) ;
}

function get_anti_flag_value($val)
{
	if( $val[0] == "" ) return 0 ;

	$arg = split(" \| ", $val) ;

	global $antiflag_types ;
	return get_bit_value($arg, $antiflag_types) ;
}


function get_flag($val)
{
	global $flag_types ;

	return get_bit_flag($val, $flag_types) ;
}

function get_flag_value($val)
{
	if( $val[0] == "" ) return 0 ;

	$arg = split(" \| ", $val) ;

	global $flag_types ;
	return get_bit_value($arg, $flag_types) ;
}


function get_wear_flag($val)
{
	global $wearflag_types ;
	return get_bit_flag($val, $wearflag_types) ;
}

function get_wearflag_value($val)
{
	if( $val[0] == "" ) return 0 ;

	$arg = split(" \| ", $val) ;

	global $wearflag_types ;
	return get_bit_value($arg, $wearflag_types) ;
}


function get_item_type($val)
{
	global $item_types ;
	return $item_types[$val] ;
}

function get_item_type_value($val)
{
	global $item_types ;

	$idx = array_search( $val, $item_types) ;

	if( $idx === FALSE )
	{
		echo "\n\n\n\nERROR ON get_item_type_value ".$val."\n\n\n\n" ;
		exit ;
		return 0 ;
	}

	return $idx ;
}


function get_item_subtype($type, $val)
{
	global $item_subtype ;

	if( $item_subtype[$type] === 0 ) return 0 ;

	if( array_key_exists($val, $item_subtype[$type]) == FALSE )
	{
		if( $type == 16 && $val == 10 ) return "USE_SPECIAL" ;

		echo "\n\n\n\nERROR ON get_item_subtype ".$type." ".$val."\n\n\n\n" ;
		exit ;
		return 0 ;
	}

	return $item_subtype[$type][$val] ;
}

function get_item_subtype_value($type, $val)
{
	global $item_subtype ;

	if( $item_subtype[$type] === 0 ) return 0 ;

	$idx = array_search($val, $item_subtype[$type]) ;

	if( $idx === FALSE )
	{
		if( $type == 16 && $val == "USE_SPECIAL" ) return 10 ;

		echo "\n\n\n\nERROR ON get_item_subtype ".$type." ".$val."\n\n\n\n" ;
		exit ;
		return 0 ;
	}

	return $idx ;
}


function get_immune_flag($val)
{
	global $immune_types ;

	return get_bit_flag($val, $immune_types) ;
}

function get_immune_value($val)
{
	if( $val[0] == "" ) return 0 ;

	$arg = split(" \| ", $val) ;

	global $immune_types ;
	return get_bit_value($arg, $immune_types) ;
}


function get_apply_type($val)
{
	global $apply_types ;
	return $apply_types[$val] ;
}

function get_apply_value($val)
{
	global $apply_types ;
	$idx = array_search($val, $apply_types) ;

	if( $idx === FALSE )
	{
		echo "\n\n\n\nERROR ON get_apply_value ".$val."\n\n\n\n" ;
		exit ;
		return 0 ;
	}

	return $idx ;
}

function get_mob_types_val( $val )
{
    global $mob_types ;
    $idx = array_search($val, $mob_types) ;

    if( $idx === FALSE )
    {
        echo "\n\n\n\nERROR ON get_mob_types_val ".$val."\n\n\n\n" ;
        exit ;
    }

    return $idx ;
}

function get_mob_rank_val( $val )
{
    global $mob_ranks ;
    $idx = array_search($val, $mob_ranks) ;

    if( $idx === FALSE )
    {
        echo "\n\n\n\nERROR ON get_mob_rank_val ".$val."\n\n\n\n" ;
        exit ;
    }

    return $idx ;
}

function get_mob_battle_type_val( $val )
{
    global $mob_battle_types ;
    $idx = array_search($val, $mob_battle_types) ;

    if( $idx === FALSE )
    {
        echo "\n\n\n\nERROR ON get_mob_battle_type_val ".$val."\n\n\n\n" ;
        exit ;
    }

    return $idx ;
}

function get_mob_battle_type_str( $val )
{
    global $mob_battle_types ;
    return $mob_battle_types[ $val ] ;
}

function get_mob_type_str( $val )
{
    global $mob_types ;
    return $mob_types[ $val ] ;
}

function get_mob_rank_str( $val )
{
    global $mob_ranks ;
    return $mob_ranks[ $val ] ;
}
foreach($_POST as $key => $value) {
		$_POST[$key] = filter_array_post(utf8_decode($value));
	}
foreach($_GET as $key => $value) {
		$_GET[$key] = filter_array_post(utf8_decode($value));
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function filter_array_post($value) {
    $newVal = mysqli_real_escape_string(ConnectiShopDb(),$value);
    return $newVal;
}
function ConnectGameDb(){
	return mysqli_connect(GAME_MYSQL_HOST,GAME_MYSQL_USER,GAME_MYSQL_PASSWORD,null,GAME_MYSQL_PORT);
}
function ConnectiShopDb(){
	return mysqli_connect(ISHOP_MYSQL_HOST,ISHOP_MYSQL_USER,ISHOP_MYSQL_PASSWORD,null,ISHOP_MYSQL_PORT);
}
function CheckConnectDb(){
	if(ConnectGameDb() && ConnectiShopDb()){
		return true;
	}else{
		return false;
	}
}
function IsConnect(){
	if($_SESSION['ISHOP_SESSION_ID']){
		return true;
	}else{
		return false;
	}
}
function GetCurrentCat(){
	if($_GET['cat'] && is_numeric($_GET['cat'])){
		$cat = $_GET['cat'];
	}else{
		$cat = ISHOP_DEFAULT_CAT_ID;
	}
		return $cat;
}
function includeFileContent($fileName)
{
    ob_start();
    ob_implicit_flush(false);
    include($fileName);
    return ob_get_clean();
}
function GetDescByVnum($vnum){
	$handle = fopen('include/extern/itemdesc.txt', 'r');
	$RETURN = $content;
	if ($handle)
	{
		while (!feof($handle))
		{
			$buffer = fgets($handle);
			$EXPLODE_RESULT = explode('	',$buffer);
			if($vnum == $EXPLODE_RESULT[0]){
				$RETURN = $EXPLODE_RESULT[2];
				break;
			}
			
		}
		fclose($handle);
	}
	return $RETURN;
}

function GetTotalItemLog(){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT count(*) as total from ".ISHOP_MYSQL_DB.".buy_log where date >= '".(time()-(3600*24*30))."' and date <= '".time()."' and account_id=('".$_SESSION['ISHOP_SESSION_ID']."')"));
	return $QUERY['total'];
}
function ReplaceHTMLCode($content){
	$handle = fopen('include/lang/'.ISHOP_LANG, 'r');
	$RETURN = $content;
	if ($handle)
	{
		while (!feof($handle))
		{
			$buffer = fgets($handle);
			$EXPLODE_RESULT = explode('	',$buffer);
			$RETURN = str_replace('{'.$EXPLODE_RESULT[0].'}',trim($EXPLODE_RESULT[1]),$RETURN);
			
		}
		fclose($handle);
	}
	return $RETURN;
	
}
function ReplaceHTMLCode_Database($content){
	$content = str_replace('{ISHOP_BUY_POINT_URL}',ISHOP_BUY_POINT_URL,$content);
	$content = str_replace('{SELECT_CHAR}',GetPlayerSelect(),$content);
	$content = str_replace('{CATEGORIE_LIST}',DisplayListCat(),$content);
	$content = str_replace('{ACTUAL_MONEY}',GetAccountInfo(ISHOP_MONEY_FIELD),$content);
	$content = str_replace('{ACTUAL_SECOND_MONEY}',GetAccountInfo(ISHOP_SECOND_MONEY_FIELD),$content);
	$content = str_replace('{DISPLAY_ITEMS}',DisplayItems(),$content);
	$content = str_replace('{DISPLAY_AJAX_ITEM}',DisplayAjaxItem(),$content);
	$content = str_replace('{DISPLAY_AJAX_ACCOUNT_BONUS}',DisplayAccountBonus(),$content);
	$content = str_replace('{CATEGORIE_NAME}',DisplayCatName(),$content);
	$content = str_replace('{SERVER_NAME}',ISHOP_SERVERNAME,$content);
	$content = str_replace('{MONEY_NAME}',ISHOP_MONEYNAME,$content);
	$content = str_replace('{MONEY_SHORT_NAME}',ISHOP_SHORT_MONEY,$content);
	$content = str_replace('{SECOND_MONEY_NAME}',ISHOP_SECOND_MONEY,$content);
	$content = str_replace('{SECOND_MONEY_SHORT_NAME}',ISHOP_SECOND_SHORT_MONEY,$content);
	return ReplaceHTMLCode($content);
}
function GetItemInfo($vnum,$type){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectGameDb(),"SELECT * from ".GAME_MYSQL_PLAYER.".item_proto where vnum=('".$vnum."') LIMIT 1"));
	return $QUERY[$type];

}
function GetPlayerSelect(){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".select_char where account_id=('".$_SESSION['ISHOP_SESSION_ID']."')"));
		if($QUERY['pid_id']){
			return GetPlayerInfo($QUERY['pid_id'],'name')." (".GetPlayerRaceByJob(GetPlayerInfo($QUERY['pid_id'],'job')).")";
		}else{
			return "{NO_CHARACTER_LABEL}";
		}
}
function GetPlayerSelectID(){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".select_char where account_id=('".$_SESSION['ISHOP_SESSION_ID']."')"));
		if($QUERY['pid_id']){
			return $QUERY['pid_id'];
		}else{
			return "";
		}
}
function UpdateSelectChar($pid){
	if(GetPlayerInfo($pid,'account_id') == $_SESSION['ISHOP_SESSION_ID']){
		mysqli_query(ConnectiShopDb(),"insert into ".ISHOP_MYSQL_DB.".select_char (account_id, pid_id) values('".$_SESSION['ISHOP_SESSION_ID']."', '".mysqli_real_escape_string(ConnectiShopDb(),$pid)."') on duplicate key update pid_id=('".$pid."')");
	}
}
function GetPlayerRaceByJob($job){
	if($job == 0){
		return "{WARRIOR_LABEL}";
	}elseif($job == 1){
		return "{ASSASSIN_LABEL}";
	}elseif($job == 2){
		return "{SURA_LABEL}";
	}elseif($job == 3){
		return "{SHAMANE_LABEL}";
	}elseif($job == 4){
		return "{WARRIOR_LABEL}";
	}elseif($job == 5){
		return "{ASSASSIN_LABEL}";
	}elseif($job == 6){
		return "{SURA_LABEL}";
	}elseif($job == 7){
		return "{SHAMANE_LABEL}";
	}

}
function GetPlayerSelectList(){
	$QUERY = mysqli_query(ConnectGameDb(),"SELECT * from ".GAME_MYSQL_PLAYER.".player where account_id=('".$_SESSION['ISHOP_SESSION_ID']."')");
		while($row = mysqli_fetch_array($QUERY)){
			$RETURN .= '<option value="'.$row['id'].'">'.utf8_encode($row['name']).' ('.GetPlayerRaceByJob($row['job']).')</option>';
		}
		return $RETURN;
	
}
function GetPlayerInfo($pid,$type){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectGameDb(),"SELECT * from ".GAME_MYSQL_PLAYER.".player where id=('".$pid."') LIMIT 1"));
	return $QUERY[$type];

}
function GetAccountInfo($type){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectGameDb(),"SELECT * from ".GAME_MYSQL_ACCOUNT.".account where id=('".$_SESSION['ISHOP_SESSION_ID']."') LIMIT 1"));
	return $QUERY[$type];

}
function DisplayListCat(){
	$QUERY = mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".categorie order by id_cat ASC");
		while($row = mysqli_fetch_array($QUERY)){
			$RETURN .= '<li><a href="./categorie/'.$row['id_cat'].'/">'.utf8_encode($row['name_cat']).'</a></li>';
		}
		return $RETURN;
}
function DisplayListSelectCat($id){
	$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
	$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
	
	$QUERY = mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".categorie order by id_cat ASC");
		while($row = mysqli_fetch_array($QUERY)){
			if($id == $row['id_cat']){
				$RETURN .= '<option value="'.$row['id_cat'].'" selected>'.utf8_encode($row['name_cat']).' (Type : '.$TEXT_REPLACE[$row['type_cat']].')</option>';
			}else{
				$RETURN .= '<option value="'.$row['id_cat'].'">'.utf8_encode($row['name_cat']).' (Type : '.$TEXT_REPLACE[$row['type_cat']].')</option>';
			}
		}
		return $RETURN;
}
function DisplayListItem(){
	$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
	$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
			
	$QUERY = mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".item_list order by item_id ASC");
		while($row = mysqli_fetch_array($QUERY)){
			$RETURN .= '<option value="'.$row['item_id'].'">'.utf8_encode($row['item_name']).' (Type : '.$TEXT_REPLACE[$row['item_type']].')</option>';
		}
		return $RETURN;
}

function AutoLoginiShop($PID,$SAS){
	if(!is_numeric($PID)){
		return false;
	}
	$RETURN = mysqli_fetch_array(mysqli_query(ConnectGameDb(),"SELECT account_id from ".GAME_MYSQL_PLAYER.".player where id=(".$PID.") LIMIT 1"));
	$hash_generate = md5($PID.$RETURN['account_id'].ISHOP_CRYPT_KEY);
		if(is_numeric($PID) && $SAS){
			if($hash_generate == $SAS){
				setcookie(session_name(), session_id(), time() + 7200, "/");
				$_SESSION['ISHOP_SESSION_ID'] = $RETURN['account_id'];
				UpdateSelectChar($PID);
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
}
function GetRandomItem(){
	$QUERY = mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".item_list ORDER by RAND() LIMIT 6");
		while($row = mysqli_fetch_array($QUERY)){
			if((($row['item_level_restrict'] == null) or ($row['item_level_restrict'] <= GetPlayerInfo(GetPlayerSelectID(),'level'))) AND 
			( ($row['item_sexe_restrict'] == null) or ($row['item_sexe_restrict'] == GetSexeById(GetPlayerSelectID()))) AND 
			( ($row['item_race_restrict'] == null) or ($row['item_race_restrict'] == GetRaceById(GetPlayerSelectID())))){		
				$RETURN .= '
					<li class="thumbnailBgSmall">
									<a id="suggestion2500" class="suggestion" href="./ajax/display_item_infos/'.$row['item_id'].'/" title="'.utf8_encode($row['item_name']).'">
										<img src="'.$row['item_img'].'" width="63" height="63" alt="'.utf8_encode($row['item_name']).'"/>
									</a>
								</li>
				
				';
			
			}
		
		}
	return $RETURN;
}
function DisplayBonusAccount(){
	$QUERY = "SELECT * from ".ISHOP_MYSQL_DB.".account_bonus where visible=('1') order by id DESC";
	$QUERY_EXEC = mysqli_query(ConnectiShopDb(),$QUERY);
		while($row = mysqli_fetch_array($QUERY_EXEC)){
			$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
			$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
			$RETURN .= '
				
						<div class="item">
								<div class="itemDesc">
									<div class="thumbnailBgSmall">
										<a href="./ajax/display_account_bonus_infos/'.$row['id'].'/" title="{MORE_INFORMATION_LABEL}" class="openinformation">
											<img src="'.$row['img_url'].'" width="63px" height="63px" alt="{MORE_INFORMATION_LABEL}"/>
										</a>
									</div>
									<p>
										<a href="./ajax/display_account_bonus_infos/'.$row['id'].'/" title="{MORE_INFORMATION_LABEL}" class="openinformation">
											<span class="itemTitle">'.utf8_encode($row['name']).'</span>
										</a>
										<span class="line">
										</span>
										'.utf8_encode(nl2br($row['description'])).'
										<br class="clearfloat" />
									</p>
								</div>
								<div class="purchaseOptionsWrapper">
									<div class="itemPrice">
										<div class="priceValue">1 {FOR_LABEL} :<span class="price">&nbsp;'.$row['price'].' '.$TEXT_REPLACE[$row['type']].'</span></div>
									</div>
									<a href="./ajax/display_account_bonus_infos/'.$row['id'].'/" title="{MORE_INFORMATION_LABEL}" class="purchaseInfo openinformation">{DETAIL_LABEL}</a>
									
								</div>
								<br class="clearfloat" />
							</div>
				
				
				
				';
		}
	return $RETURN;
}
function DisplayItems(){
	if($_POST['searchString']){
		$QUERY = "SELECT * from ".ISHOP_MYSQL_DB.".item_list where CONVERT(item_name USING latin1) like ('%".mysqli_real_escape_string(ConnectiShopDb(),utf8_decode($_POST['searchString']))."%') and item_visible=('1') ORDER by item_id DESC";;
	}elseif($_GET['cat'] == "new"){
		$QUERY = "SELECT * from ".ISHOP_MYSQL_DB.".item_list where item_visible=('1') ORDER by item_id DESC LIMIT 25";
	}elseif($_GET['cat'] == "bonus" && ISHOP_ACCOUNT_BONUS_ENABLE){
		return DisplayBonusAccount();
	}else{
		$QUERY = "SELECT * from ".ISHOP_MYSQL_DB.".item_list where item_cat=('".GetCurrentCat()."') AND item_type=('".GetTypeCat(GetCurrentCat())."') and item_visible=('1')  ORDER by item_id DESC";
	}
	$QUERY_EXEC = mysqli_query(ConnectiShopDb(),$QUERY);
		while($row = mysqli_fetch_array($QUERY_EXEC)){
			$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
			$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
			if((($row['item_level_restrict'] == null) or ($row['item_level_restrict'] <= GetPlayerInfo(GetPlayerSelectID(),'level'))) AND ( ($row['item_sexe_restrict'] == null) or ($row['item_sexe_restrict'] == GetSexeById(GetPlayerSelectID()))) AND ( ($row['item_race_restrict'] == null) or ($row['item_race_restrict'] == GetRaceById(GetPlayerSelectID())))){		
				$RETURN .= '
				
						<div class="item">
								<div class="itemDesc">
									<div class="thumbnailBgSmall">
										<a href="./ajax/display_item_infos/'.$row['item_id'].'/" title="{MORE_INFORMATION_LABEL}" class="openinformation">
											<img src="'.$row['item_img'].'" width="63px" height="63px" alt="{MORE_INFORMATION_LABEL}"/>
										</a>
									</div>
									<p>
										<a href="./ajax/display_item_infos/'.$row['item_id'].'/" title="{MORE_INFORMATION_LABEL}" class="openinformation">
											<span class="itemTitle">'.utf8_encode($row['item_name']).'</span>
										</a>
										<span class="line">
										</span>
										'.utf8_encode(nl2br($row['item_desc'])).'
										<br class="clearfloat" />
									</p>
								</div>
								<div class="purchaseOptionsWrapper">
									<div class="itemPrice">
										<div class="priceValue">'.$row['item_count'].' {FOR_LABEL} :<span class="price">&nbsp;'.$row['item_price'].' '.$TEXT_REPLACE[$row['item_type']].'</span></div>
									</div>
									<a href="./ajax/display_item_infos/'.$row['item_id'].'/" title="{MORE_INFORMATION_LABEL}" class="purchaseInfo openinformation">{DETAIL_LABEL}</a>
									
								</div>
								<br class="clearfloat" />
							</div>
				
				
				
				';
			}
		}
		return $RETURN;	
}
function GetTypeCat($id){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT type_cat from ".ISHOP_MYSQL_DB.".categorie where id_cat=('".$id."') LIMIT 1"));
	return $QUERY['type_cat'];
}
function DisplayCatName(){
	if($_POST['searchString']){
		return "{KEYWORD_SEARCH_LABEL} : ".utf8_decode($_POST['searchString']);
	}elseif($_GET['cat'] == "new"){
		return "{NEW_ITEMS_LABEL}";
	}elseif($_GET['cat'] == "bonus" && ISHOP_ACCOUNT_BONUS_ENABLE){
		return "{ACCOUNT_BONUS_LABEL}";
	}else{
		$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".categorie where id_cat=('".GetCurrentCat()."') LIMIT 1"));
		return utf8_encode($QUERY['name_cat']);
	}
}
function GetSexeById($pid){
	$JOB = GetPlayerInfo($pid,'job');
		if($JOB == 0 or $JOB == 2 or $JOB == 5 or $JOB == 7){
			return "MALE";
		}else{
			return "FEMALE";
		}
}
function GetRaceById($pid){
	$JOB = GetPlayerInfo($pid,'job');
		if($JOB == 0 or $JOB == 4){
			return "WARRIOR";
		}elseif($JOB == 1 or $JOB == 5){
			return "ASSASSIN";
		}elseif($JOB == 2 or $JOB == 6){
			return "SURA";
		}elseif($JOB == 3 or $JOB == 7){
			return "SHAMANE";
		}
}
function DisplayAccountBonus(){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".account_bonus where id=('".$_GET['id']."') and visible=('1') LIMIT 1"));
	$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
	$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
	$RETURN = '
			<h1 class="mainHeadline">'.utf8_encode($QUERY['name']).'</h1>
	<div class="dynContent detail">
		<div class="box boxLeft visual">
			<img src="'.$QUERY['img_url_big'].'" alt="'.utf8_encode($QUERY['name']).'" />
		</div>
		<div class="box desc descOnlyItem">
			<div class="detailBadge">
				<div class="detailBadgeInner">
				</div>
			</div>
			<h2>'.utf8_encode($QUERY['name']).'</h2>
			<div class="scrollpane scrollpaneOnlyItem">
				<p>'.utf8_encode(nl2br($QUERY['big_description'])).'</p>
			</div>
		</div>
		<div class="box boxRight buy onlyItem">
			<div class="priceSelect" style="display:none;">
				<div id="selectItemContainer" class="big">
					<table id="selectItem" cellspacing="0">
						<tbody>
							<tr class="bgSelected" value="1:'.$QUERY['price'].':'.$QUERY['price'].':'.$QUERY['price'].':0:1">
								<td>1 {COUNT_LABEL}</td>
								<td class="price">'.$QUERY['price'].'&nbsp;'.$TEXT_REPLACE[$QUERY['type']].'</td>
							</tr>
							';
							
							
							$RETURN .= '
							
						</tbody>
					</table>
				</div>
			</div>
			<div id="idItemSelectAjax" style="display:none;">'.$QUERY['id'].'</div>
			<div id="priceRight">
				<div class="sprice">
					{PRICE_LABEL} : <del><span id="oldPriceAmount"></span></del> <span id="priceAmount">'.$QUERY['price'].'</span> '.$TEXT_REPLACE[$QUERY['type']].'</div>
					<a id="buyItemLink" href="./ajax/buy_account_bonus/'.$QUERY['id'].'/">{BUY_LABEL} !</a>
					';
					if($QUERY['type'] == "DC"){ $RETURN .= '<div class="buyInfo">{SECOND_MONEY_GIVE_LABEL} <span id="mileageAmount">'.$QUERY['price'].'</span> '.ISHOP_SECOND_MONEY.' </div>'; }
					else{ $RETURN .= '<div class="buyInfo" style="display:none;"><span id="mileageAmount"></span></div>'; }
					$RETURN .= '</div>
				</div>
				<div id="volumeDiscount">
					<h3>{DISCOUNT_LABEL}:</h3>
					<p>{SAVE_MONEY_LABEL} <br><strong><span>0</span> '.$TEXT_REPLACE[$QUERY['type']].' !</strong></p>
				</div>
				<div class="box suggestions">
					<h2>{BUY_SUGGESTION_LABEL} :</h2>
					<ol id="suggestions">
						'.GetRandomItem().'
					</ol>
				</div>
			</div>';
	
		return $RETURN;
}
function DisplayAjaxItem(){
	$QUERY = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".item_list where item_id=('".$_GET['id']."') and item_visible=('1') LIMIT 1"));
	$TEXT_REPLACE['DC'] = "{MONEY_SHORT_NAME}";
	$TEXT_REPLACE['MD'] = "{SECOND_MONEY_SHORT_NAME}";
	if((($QUERY['item_level_restrict'] == null) or ($QUERY['item_level_restrict'] <= GetPlayerInfo(GetPlayerSelectID(),'level'))) AND ( ($QUERY['item_sexe_restrict'] == null) or ($QUERY['item_sexe_restrict'] == GetSexeById(GetPlayerSelectID()))) AND ( ($QUERY['item_race_restrict'] == null) or ($QUERY['item_race_restrict'] == GetRaceById(GetPlayerSelectID())))){		
		$RETURN = '
			<h1 class="mainHeadline">'.utf8_encode($QUERY['item_name']).'</h1>
	<div class="dynContent detail">
		<div class="box boxLeft visual">
			<img src="'.$QUERY['item_img_big'].'" alt="'.utf8_encode($QUERY['item_name']).'" />
		</div>
		<div class="box desc descOnlyItem">
			<div class="detailBadge">
				<div class="detailBadgeInner">
				</div>
			</div>
			<h2>'.utf8_encode($QUERY['item_name']).'</h2>
			<div class="scrollpane scrollpaneOnlyItem">
				<p>'.utf8_encode(nl2br($QUERY['item_desc_big'])).'</p>
			</div>
		</div>
		<div class="box boxRight buy onlyItem">
			<div class="priceSelect">
				<div id="selectItemContainer" class="big">
					<table id="selectItem" cellspacing="0">
						<tbody>
							<tr class="bgSelected" value="'.$QUERY['item_count'].':'.$QUERY['item_price'].':'.$QUERY['item_price'].':'.$QUERY['item_price'].':0:'.$QUERY['item_count'].'">
								<td>'.$QUERY['item_count'].' {COUNT_LABEL}</td>
								<td class="price">'.$QUERY['item_price'].'&nbsp;'.$TEXT_REPLACE[$QUERY['item_type']].'</td>
							</tr>
							';
							if($QUERY['item_price2'] && $QUERY['item_count2']){
								$RETURN .= '
								<tr value="'.($QUERY['item_price2']).':'.($QUERY['item_price2']).':'.(($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count2']).':'.($QUERY['item_price2']).':'.((($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count2'])-(($QUERY['item_price2']))).':'.$QUERY['item_count2'].'">
								<td>'.($QUERY['item_count2']).' {COUNT_LABEL}</td>
								<td class="price">'.($QUERY['item_price2']).'&nbsp;'.$TEXT_REPLACE[$QUERY['item_type']].'</td>
							</tr>
								';
							}
							if($QUERY['item_price3'] && $QUERY['item_count3']){
								$RETURN .= '
								<tr value="'.($QUERY['item_price3']).':'.($QUERY['item_price3']).':'.(($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count3']).':'.($QUERY['item_price3']).':'.((($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count3'])-(($QUERY['item_price3']))).':'.$QUERY['item_count3'].'">
								<td>'.($QUERY['item_count3']).' {COUNT_LABEL}</td>
								<td class="price">'.($QUERY['item_price3']).'&nbsp;'.$TEXT_REPLACE[$QUERY['item_type']].'</td>
							</tr>
								';
							}
							if($QUERY['item_price4'] && $QUERY['item_count4']){
								$RETURN .= '
								<tr value="'.($QUERY['item_price4']).':'.($QUERY['item_price4']).':'.(($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count4']).':'.($QUERY['item_price4']).':'.((($QUERY['item_price']/$QUERY['item_count'])*$QUERY['item_count4'])-(($QUERY['item_price4']))).':'.$QUERY['item_count4'].'">
								<td>'.($QUERY['item_count4']).' {COUNT_LABEL}</td>
								<td class="price">'.($QUERY['item_price4']).'&nbsp;'.$TEXT_REPLACE[$QUERY['item_type']].'</td>
							</tr>
								';
							}
							
							$RETURN .= '
							
						</tbody>
					</table>
				</div>
			</div>
			<div id="idItemSelectAjax" style="display:none;">'.$QUERY['item_id'].'</div>
			<div id="priceRight">
				<div class="sprice">
					{PRICE_LABEL} : <del><span id="oldPriceAmount"></span></del> <span id="priceAmount">'.$QUERY['item_price'].'</span> '.$TEXT_REPLACE[$QUERY['item_type']].'</div>
					<a id="buyItemLink" href="./ajax/buy_item/'.$QUERY['item_id'].'/">{BUY_LABEL} !</a>
					';
					if($QUERY['item_type'] == "DC"){ $RETURN .= '<div class="buyInfo">{SECOND_MONEY_GIVE_LABEL} <span id="mileageAmount">'.$QUERY['item_price'].'</span> '.ISHOP_SECOND_MONEY.' </div>'; }
					else{ $RETURN .= '<div class="buyInfo" style="display:none;"><span id="mileageAmount"></span></div>'; }
					$RETURN .= '</div>
				</div>
				<div id="volumeDiscount">
					<h3>{DISCOUNT_LABEL}:</h3>
					<p>{SAVE_MONEY_LABEL} <br><strong><span>0</span> '.$TEXT_REPLACE[$QUERY['item_type']].' !</strong></p>
				</div>
				<div class="box suggestions">
					<h2>{BUY_SUGGESTION_LABEL} :</h2>
					<ol id="suggestions">
						'.GetRandomItem().'
					</ol>
				</div>
			</div>';
		}
	
		return $RETURN;
}
function GetRamdomBonusCostume(){
	$chance_bonus = rand(1,100);
	$GET_BONUS_COSTUME = mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".bonus_costume order by RAND() LIMIT 2");
		$i_bonus = 0;
			while($row_bonus_costume = mysqli_fetch_array($GET_BONUS_COSTUME)){
				if($i_bonus == 0){
					$FIRST_BONUS = $row_bonus_costume['bonus_id'];
					$FIRST_VALUE = $row_bonus_costume['value_bonus'];
					$i_bonus = $i_bonus +1;
				}
				if($i_bonus == 1){
					$SECOND_BONUS = $row_bonus_costume['bonus_id'];
					$SECOND_VALUE = $row_bonus_costume['value_bonus'];
				}
						
			}
			if($chance_bonus <= 25){
				return $FIRST_BONUS."-".$FIRST_VALUE."-".$SECOND_BONUS."-".$SECOND_VALUE;
			}else{
				return $FIRST_BONUS."-".$FIRST_VALUE."-0-0";
			}

}
function SendBuyAccountBonusByAjax($id){
	$BONUS_INFOS = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".account_bonus where id=('".$id."') and visible=('1') LIMIT 1"));
	if($BONUS_INFOS['id'] == ""){
		return false;
	}
	if($BONUS_INFOS['type'] == "DC"){
		$ITEM_TYPE = ISHOP_MONEY_FIELD;
		$QUERY = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."-".$BONUS_INFOS['price']."), ".ISHOP_SECOND_MONEY_FIELD."=(".ISHOP_SECOND_MONEY_FIELD."+".$BONUS_INFOS['price'].") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
		$QUERY_BACK = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."+".$BONUS_INFOS['price']."), ".ISHOP_SECOND_MONEY_FIELD."=(".ISHOP_SECOND_MONEY_FIELD."-".$BONUS_INFOS['price'].") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
	}else{
		$ITEM_TYPE = ISHOP_SECOND_MONEY_FIELD;
		$QUERY = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."-".$BONUS_INFOS['price'].") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
		$QUERY_BACK = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."+".$BONUS_INFOS['price'].") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
	}
	if($BONUS_INFOS['price'] <= GetAccountInfo($ITEM_TYPE)){
		if(date('Y-m-d H:i:s') < GetAccountInfo($BONUS_INFOS['bonus_type'])){
			$BONUS_TIME = date('Y-m-d H:i:s',strtotime(GetAccountInfo($BONUS_INFOS['bonus_type'])." +".$BONUS_INFOS['time']." second"));
		}else{
			$BONUS_TIME = date('Y-m-d H:i:s',(time()+$BONUS_INFOS['time']));
		}
		if(mysqli_query(ConnectGameDb(),$QUERY)){
			$QUERY_BONUS = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$BONUS_INFOS['bonus_type']."=('".$BONUS_TIME."') WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
				if(mysqli_query(ConnectGameDb(),$QUERY_BONUS)){
					return true;
				}else{
					mysqli_query(ConnectGameDb(),$QUERY_BACK);
					return false;
				}
		}else{
			return false;
		}
		
	}else{
		return false;
	}
}
function SendBuyItemByAjax($id,$price){
	$ITEM_INFOS = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".item_list where item_id=('".$id."') and item_visible=('1') LIMIT 1"));
	if($ITEM_INFOS['item_id'] == ""){
		return false;
	}
	if($price == null){
		$PRICE = "item_price";
		$REAL_PRICE = $ITEM_INFOS['item_price'];
		$REAL_COUNT = $ITEM_INFOS['item_count'];
	}else{
		if($price == $ITEM_INFOS['item_price']){
			$PRICE = "item_price";
			$REAL_PRICE = $ITEM_INFOS['item_price'];
			$REAL_COUNT = $ITEM_INFOS['item_count'];
		}elseif($price == $ITEM_INFOS['item_price2']){
			$PRICE = "item_price2";
			$REAL_PRICE = $ITEM_INFOS['item_price2'];
			$REAL_COUNT = $ITEM_INFOS['item_count2'];
		}elseif($price == $ITEM_INFOS['item_price3']){
			$PRICE = "item_price3";
			$REAL_PRICE = $ITEM_INFOS['item_price3'];
			$REAL_COUNT = $ITEM_INFOS['item_count3'];
		}elseif($price == $ITEM_INFOS['item_price4']){
			$PRICE = "item_price4";
			$REAL_PRICE = $ITEM_INFOS['item_price4'];
			$REAL_COUNT = $ITEM_INFOS['item_count4'];
		}else{
			$PRICE = "item_price";
			$REAL_PRICE = $ITEM_INFOS['item_price'];
			$REAL_COUNT = $ITEM_INFOS['item_count'];
		}
	}
	if($ITEM_INFOS['item_type'] == "DC"){
		$ITEM_TYPE = ISHOP_MONEY_FIELD;
		$QUERY = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."-".$REAL_PRICE."), ".ISHOP_SECOND_MONEY_FIELD."=(".ISHOP_SECOND_MONEY_FIELD."+".$REAL_PRICE.") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
		$QUERY_BACK = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."+".$REAL_PRICE."), ".ISHOP_SECOND_MONEY_FIELD."=(".ISHOP_SECOND_MONEY_FIELD."-".$REAL_PRICE.") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
	}else{
		$ITEM_TYPE = ISHOP_SECOND_MONEY_FIELD;
		$QUERY = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."-".$REAL_PRICE.") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
		$QUERY_BACK = "UPDATE ".GAME_MYSQL_ACCOUNT.".account set ".$ITEM_TYPE."=(".$ITEM_TYPE."+".$REAL_PRICE.") WHERE id=('".$_SESSION['ISHOP_SESSION_ID']."')";
	}
	if($ITEM_INFOS['item_stack'] == 0){
		$POS_NEED = $REAL_COUNT;
	}else{
		if($REAL_COUNT > 200){
			$POS_NEED = ceil($REAL_COUNT/200);
		}else{
			$POS_NEED = 1;
		}
	}
	if(GetTotalFreePos() < $POS_NEED){
		return false;
	}elseif($ITEM_INFOS[$PRICE] > GetAccountInfo($ITEM_TYPE)){
		return false;
	}else{
		$REMOVE_GOLD = mysqli_query(ConnectGameDb(),$QUERY);
			if($REMOVE_GOLD){
				if($ITEM_INFOS['item_time'] == "" or $ITEM_INFOS['item_time'] == null or $ITEM_INFOS['item_time'] == 0){
					$TIME_FIX = GetItemInfo($ITEM_INFOS['item_vnum'],'value0');
					$SOCKET_TIME = "socket2";
				}else{
					$TIME_FIX = time()+$ITEM_INFOS['item_time'];
					if($ITEM_INFOS['item_time_socket'] == "" or $ITEM_INFOS['item_time_socket'] == null){
						$SOCKET_TIME = "socket2";
					}else{
						$SOCKET_TIME = $ITEM_INFOS['item_time_socket'];
					}
				}
				if($ITEM_INFOS['item_costume_bonus'] == 1 && GetItemInfo($ITEM_INFOS['item_vnum'],'type') == 28){
					for($i_q=0; $i_q<$POS_NEED; $i_q++){
						$BONUS_STAT = explode('-',GetRamdomBonusCostume());
						$QUERY_END .= "INSERT INTO ".GAME_MYSQL_PLAYER.".item (`owner_id` ,`vnum` ,`count`,`".$SOCKET_TIME."`, `window`, `pos`,`attrtype0`,`attrvalue0`,`attrtype1`,`attrvalue1`) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."', '".$ITEM_INFOS['item_vnum']."', '1', '".$TIME_FIX."', 'mall','".(GetFreePos()+$i_q)."','".$BONUS_STAT[0]."','".$BONUS_STAT[1]."','".$BONUS_STAT[2]."','".$BONUS_STAT[3]."'); ";
					}
				}elseif($ITEM_INFOS['item_stack'] == 0){
					for($i_q=0; $i_q<$POS_NEED; $i_q++){
						$QUERY_END .= "INSERT INTO ".GAME_MYSQL_PLAYER.".item (`owner_id` ,`vnum` ,`count`,`".$SOCKET_TIME."`, `window`, `pos`) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."', '".$ITEM_INFOS['item_vnum']."', '1', '".$TIME_FIX."', 'mall','".(GetFreePos()+$i_q)."'); ";
					}
				}else{
					if($REAL_COUNT > 200){
						$TOTAL_ITEM = $REAL_COUNT;
							for($i_q=0; $i_q<$POS_NEED; $i_q++){
								if($TOTAL_ITEM > 200){
									$QUERY_END .= "INSERT INTO ".GAME_MYSQL_PLAYER.".item (`owner_id` ,`vnum` ,`count`,`".$SOCKET_TIME."`, `window`, `pos`) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."', '".$ITEM_INFOS['item_vnum']."', '200', '".$TIME_FIX."', 'mall','".(GetFreePos()+$i_q)."');";
								}else{
									$QUERY_END .= "INSERT INTO ".GAME_MYSQL_PLAYER.".item (`owner_id` ,`vnum` ,`count`,`".$SOCKET_TIME."`, `window`, `pos`) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."', '".$ITEM_INFOS['item_vnum']."', '".$TOTAL_ITEM."', '".$TIME_FIX."', 'mall','".(GetFreePos()+$i_q)."');";
								}
								$TOTAL_ITEM = $TOTAL_ITEM - 200;
							}
					}else{
						$QUERY_END = "INSERT INTO ".GAME_MYSQL_PLAYER.".item (`owner_id` ,`vnum` ,`count`,`".$SOCKET_TIME."`, `window`, `pos`) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."', '".$ITEM_INFOS['item_vnum']."', '".$REAL_COUNT."', '".$TIME_FIX."', 'mall','".GetFreePos()."')";
					}
				}
				$QUERY_END_EXEC = mysqli_multi_query(ConnectGameDb(),$QUERY_END);
				mysqli_query(ConnectiShopDb(),"INSERT INTO ".ISHOP_MYSQL_DB.".buy_log(account_id,item_id,item_count,date,ip) VALUES ('".$_SESSION['ISHOP_SESSION_ID']."','".$ITEM_INFOS['item_id']."','".$REAL_COUNT."','".time()."','".$_SERVER['REMOTE_ADDR']."')");
				if($QUERY_END_EXEC){
					return true;
				}else{
					mysqli_query(ConnectGameDb(),$QUERY_BACK);
					return false;
				}
			}else{
				return false;
			}
	}
	
}
function GetFreePos(){
	$SELECT_FREE_POS = mysqli_query(ConnectGameDb(),"SELECT pos from ".GAME_MYSQL_PLAYER.".item where owner_id=('".$_SESSION['ISHOP_SESSION_ID']."') and window=('MALL') ORDER by pos ASC");
		$USED_POS = array();
			while($row = mysqli_fetch_array($SELECT_FREE_POS)){
				$USED_POS[] = $row['pos'];
			}
			$USED_POS = array_unique($USED_POS);
			for($i=0; $i<45; $i++){
				if(!in_array($i,$USED_POS)){
					$FREE_POS = $i;
					break;
				}
			}
			return $FREE_POS;
			
			//return print_r($USED_POS);
}
function GetTotalFreePos(){
	$SELECT_FREE_POS = mysqli_fetch_array(mysqli_query(ConnectGameDb(),"SELECT count(*) as result from ".GAME_MYSQL_PLAYER.".item where owner_id=('".$_SESSION['ISHOP_SESSION_ID']."') and window=('MALL')"));
	return (45-$SELECT_FREE_POS['result']);
}
function SendAdminAction($action){
	if($_POST['admin_type_post'] == $action) 
	{ 
		if($action == "create_cat"){
			if(($_POST['type_cat'] == "DC" or $_POST['type_cat'] == "DC") && isset($_POST['name_cat'])){
				$QUERY = mysqli_query(ConnectiShopDb(),"INSERT INTO ".ISHOP_MYSQL_DB.".categorie(id_cat,name_cat,type_cat) VALUES ('','".$_POST['name_cat']."','".$_POST['type_cat']."')");
					if($QUERY){
						return "{ADD_CAT_SUCCESS_LABEL}";
					}else{
						return "{ADD_CAT_FAIL_LABEL}";
					}
			}else{
				return "{ADD_CAT_FAIL_LABEL}";
			}
			 
		}elseif($action == "create_item"){
			return AddNewiShopItem();
		}elseif($action == "modify_item"){
			return ModifyiShopItem();
		}
		elseif($action == "modify_cat"){
			return ModifyCat();
		}
		
	}
	
}
function ModifyCat(){
	$QUERY = mysqli_query(ConnectiShopDb(),"UPDATE ".ISHOP_MYSQL_DB.".categorie set name_cat=('".$_POST['name_cat']."'),type_cat=('".$_POST['type_cat']."') WHERE id_cat=('".$_POST['id_cat']."')");
		if($QUERY){
			return "{MODIFY_CAT_SUCCESS_LABEL}";
		}else{
			return "{MODIFY_CAT_FAIL_LABEL}";
		}
}
function DisplayModifyCatForm($id){
	$GET_CAT_INFO = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".categorie where id_cat=('".$id."') LIMIT 1"));
		if($GET_CAT_INFO['type_cat'] == "MD"){
			$TYPE_CAT = "selected";
		}
	return '
		<form action="" method="POST">
					<table>
						<tbody>
							<tr>
								<th>{CAT_NAME_LABEL} :</th>
								<th><input type="text" name="name_cat" value="'.utf8_encode($GET_CAT_INFO['name_cat']).'" /></th>
							</tr>
							<tr>
								<th>{CAT_TYPE_LABEL} :</th>
								<th>
									<select name="type_cat">
										<option value="DC">{MONEY_NAME}</option>
										<option value="MD" '.$TYPE_CAT.'>{SECOND_MONEY_NAME}</option>
									</select>
								</th>
							</tr>
							<tr>
							  <th><input type="submit" value="{MODIFY_LABEL}" /></th>
							  <th>&nbsp;</th>
							</tr>
						</tbody>
					</table>
		<input type="hidden" name="admin_type_post" value="modify_cat" />
		<input type="hidden" name="id_cat" value="'.$id.'" />
		</form>
	';
}
function DisplayCreateItemForm($vnum){
	if($vnum == null or $vnum == "" or GetItemInfo($vnum,'vnum') == ""){
		return "{VERIFY_VNUM_LABEL}";
	}else{
		if(strpos(get_flag(GetItemInfo($vnum,'flag')),'ITEM_STACKABLE') === false){
			$STACKABLE = "";
		}else{
			$STACKABLE = "selected";
		}
		
		$RETURN .= '
			
			<form action="" method="POST">
			 <input type="hidden" name="item_vnum" id="item_vnum" value="'.$vnum.'">
				<table>
				  
				 
				  <tbody>
				  <tr>
					<th>{NAME_LABEL}  :</th>
					 <th><input type="text" name="item_name" id="item_name" value="'.utf8_encode(GetItemInfo($vnum,GAME_MYSQL_ITEM_NAME)).'" /></th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{STACK_ITEM_LABEL} :</th>
					  <th>
					    <select name="stack_item">
							<option value="0">{NO_LABEL}</option>
							'.(GetItemInfo($vnum,"type") != 28 ? "<option value=\"1\" ".$STACKABLE.">{YES_LABEL}</option>" : null).'
						</select>
					  </th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{CATEGORIE_LABEL} :</th>
					  <th>
					   <select name="cat_item">
						'.DisplayListSelectCat().'
						</select>
					  </th>
				  </tr>
				  <tr>
					  <th>{TYPE_LABEL} :</th>
					  <th>
					   <select name="type_item">
						<option value="DC">{MONEY_NAME}</option>
						<option value="MD">{SECOND_MONEY_NAME}</option>
					</select>
					  </th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{SEXE_RESTRICTION_LABEL} :</th>
					  <th>
					   <select name="sexe_item">
						<option value="">{NO_LABEL}</option>
						<option value="MALE">{MALE_LABEL}</option>
						<option value="FEMALE">{FEMALE_LABEL}</option>
					   </select>
					  </th>
				  </tr>
				  <tr>
					  <th>{RACE_RESTRICTION_LABEL} :</th>
					  <th>
					   <select name="race_item">
						<option value="">{NO_LABEL}</option>
						<option value="WARRIOR">{WARRIOR_LABEL}</option>
						<option value="ASSASSIN">{ASSASSIN_LABEL}</option>
						<option value="SURA">{SURA_LABEL}</option>
						<option value="SHAMANE">{SHAMANE_LABEL}</option>
					   </select>
					  </th>
				  </tr>	
				  <tr>
					  <th>{LEVEL_RESTRICTION_LABEL} :</th>
					  <th>
					   <input type="text" name="level_item" id="level_item" />
					  </th>
				  </tr>	
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (1/4) :</th>
					  <th>
					   <input type="text" name="price1_item" id="price1_item" /> / <input type="text" name="count1_item" id="count1_item" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (2/4) :</th>
					  <th>
					   <input type="text" name="price2_item" id="price2_item" /> / <input type="text" name="count2_item" id="count2_item" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (3/4) :</th>
					  <th>
					   <input type="text" name="price3_item" id="price3_item" /> / <input type="text" name="count3_item" id="count3_item" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (4/4) :</th>
					  <th>
					   <input type="text" name="price4_item" id="price4_item" /> / <input type="text" name="count4_item" id="count4_item" />
					  </th>
				  </tr>		
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{IMAGE_URL_LABEL} (63px / 63px) :</th>
					  <th>
					   <input type="text" name="img_item" id="img_item" />
					  </th>
				  </tr>		
				  <tr>
					  <th>{IMAGE_URL_LABEL} (119px / 119px) :</th>
					  <th>
					   <input type="text" name="img_big_item" id="img_big_item" />
					  </th>
				  </tr>	
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  
					';
					if(GetItemInfo($vnum,'type') == 28){
						$RETURN .= '
							<tr>
					  <th>{COSTUME_BONUS_LABEL} :</th>
					  <th>
					  <select name="costume_bonus_item">
					   <option value="">{NO_LABEL}</option>
						<option value="1">{YES_LABEL}</option>
						</select>
					  </th>
				  </tr>	
						
						';
					}else{
						$RETURN .= '
						<tr>
					  <th>{ITEM_TIME_LABEL} :</th>
					  <th>
					   <select name="time_item">
						<option value="">{NO_LABEL}</option>
						<option value="1">{YES_LABEL}</option>
					</select>
					  </th>
				  </tr>	
				  <tr>	
					  <th>{ITEM_TIME_INPUT_LABEL} : </th>
					  <th>
					   <input type="text" name="time_count_item" id="time_count_item" />
					<select name="time_type_item">
						<option value="1">{SECOND_LABEL}</option>
						<option value="60">{MINUTE_LABEL}</option>
						<option value="3600">{HOUR_LABEL}</option>
						<option value="86400">{DAY_LABEL}</option>
					</select>
					  </th>
				  </tr>
					
				  <tr>
					  <th>{SOCKET_TIME_LABEL} :</th>
					  <th>
					   <input type="text" name="socket_item" id="socket_item" value="socket2" />
					  </th>
				  </tr>
						
						
						';
					
					}
					$RETURN .= '
					<tr>
					  <th>{ITEM_VISIBLE_LABEL} :</th>
					  <th>
					  <select name="visible_item">
					   <option value="1">{YES_LABEL}</option>
						<option value="0">{NO_LABEL}</option>
						</select>
					  </th>
				  </tr>	
				  </tbody>
				</table>
				
				
				
				<br />
				<label>{DESCRIPTION_LABEL}: </label>
					<br />
					<textarea name="desc_item" id="desc_item" cols="60" rows="5">'.utf8_encode(GetDescByVnum($vnum)).'</textarea>
					<br />
					<br />
				<label>{DESCRIPTION_BIG_LABEL}: </label>
					<br />
					<textarea name="desc_item_big" id="desc_item_big" cols="60" rows="5">'.utf8_encode(GetDescByVnum($vnum)).'</textarea>
					<br />
					<br />
					<input type="hidden" name="admin_type_post" value="create_item" />
					<input type="submit" value="{ADD_ITEM_LABEL}" />
			</form>
		';
		return $RETURN;
	}
}
function DisplayModifyItemForm($id){
	if($id == null or $id == ""){
		return "{VERIFY_VNUM_LABEL}";
	}else{
		$GET_ITEM_INFO = mysqli_fetch_array(mysqli_query(ConnectiShopDb(),"SELECT * from ".ISHOP_MYSQL_DB.".item_list where item_id=('".$id."') LIMIT 1"));
			if($GET_ITEM_INFO['item_stack'] == 1){
				$STACKABLE = "selected";
			}
			if($GET_ITEM_INFO['item_type'] == "MD"){
				$TYPE = "selected";
			}
			if($GET_ITEM_INFO['item_sexe_restrict'] == "MALE"){
				$MALE_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_sexe_restrict'] == "FEMALE"){
				$FEMALE_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_race_restrict'] == "WARRIOR"){
				$WARRIOR_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_race_restrict'] == "ASSASSIN"){
				$ASSASSIN_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_race_restrict'] == "SURA"){
				$SURA_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_race_restrict'] == "SHAMANE"){
				$SHAMANE_RESTRICT = "selected";
			}
			if($GET_ITEM_INFO['item_time'] > 0){
				$ITEM_TIME = "selected";
			}
			if($GET_ITEM_INFO['item_visible'] == 0){
				$ITEM_VISIBLE = "selected";
			}
		$RETURN .= ' 
			
			<form action="" method="POST">
			 <input type="hidden" name="item_id" id="item_id" value="'.$GET_ITEM_INFO['item_id'].'">
			 <input type="hidden" name="item_vnum" id="item_vnum" value="'.$GET_ITEM_INFO['item_vnum'].'">
			
				<table>
				  
				 
				  <tbody>
				  <tr>
					<th>{NAME_LABEL} :</th>
					 <th><input type="text" name="item_name" id="item_name" value="'.utf8_encode($GET_ITEM_INFO['item_name']).'" /></th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{STACK_ITEM_LABEL} :</th>
					  <th>
					    <select name="stack_item">
							<option value="0">{NO_LABEL}</option>
							'.(GetItemInfo($GET_ITEM_INFO['item_vnum'],"type") != 28 ? "<option value=\"1\" ".$STACKABLE.">{YES_LABEL}</option>" : null).'
						</select>
					  </th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{CATEGORIE_LABEL} :</th>
					  <th>
					   <select name="cat_item">
						'.DisplayListSelectCat($GET_ITEM_INFO['item_cat']).'
						</select>
					  </th>
				  </tr>
				  <tr>
					  <th>{TYPE_LABEL} :</th>
					  <th>
					   <select name="type_item">
						<option value="DC">{MONEY_NAME}</option>
						<option value="MD" '.$TYPE.'>{SECOND_MONEY_NAME}</option>
					</select>
					  </th>
				  </tr>
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{SEXE_RESTRICTION_LABEL} :</th>
					  <th>
					   <select name="sexe_item">
						<option value="">{NO_LABEL}</option>
						<option value="MALE" '.$MALE_RESTRICT.'>{MALE_LABEL}</option>
						<option value="FEMALE" '.$FEMALE_RESTRICT.'>{FEMALE_LABEL}</option>
					   </select>
					  </th>
				  </tr>
				  <tr>
					  <th>{RACE_RESTRICTION_LABEL} :</th>
					  <th>
					   <select name="race_item">
						<option value="">{NO_LABEL}</option>
						<option value="WARRIOR" '.$WARRIOR_RESTRICT.'>{WARRIOR_LABEL}</option>
						<option value="ASSASSIN" '.$ASSASSIN_RESTRICT.'>{ASSASSIN_LABEL}</option>
						<option value="SURA" '.$SURA_RESTRICT.'>{SURA_LABEL}</option>
						<option value="SHAMANE" '.$SHAMANE_RESTRICT.'>{SHAMANE_LABEL}</option>
					   </select>
					  </th>
				  </tr>	
				  <tr>
					  <th>{LEVEL_RESTRICTION_LABEL} :</th>
					  <th>
					   <input type="text" name="level_item" id="level_item" value="'.$GET_ITEM_INFO['item_level_restrict'].'" />
					  </th>
				  </tr>	
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (1/4) :</th>
					  <th>
					   <input type="text" name="price1_item" id="price1_item" value="'.$GET_ITEM_INFO['item_price'].'" /> / <input type="text" name="count1_item" id="count1_item" value="'.$GET_ITEM_INFO['item_count'].'" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (2/4) :</th>
					  <th>
					   <input type="text" name="price2_item" id="price2_item" value="'.$GET_ITEM_INFO['item_price2'].'" /> / <input type="text" name="count2_item" value="'.$GET_ITEM_INFO['item_count2'].'" id="count2_item" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (3/4) :</th>
					  <th>
					   <input type="text" name="price3_item" id="price3_item" value="'.$GET_ITEM_INFO['item_price3'].'" /> / <input type="text" name="count3_item" id="count3_item" value="'.$GET_ITEM_INFO['item_count3'].'" />
					  </th>
				  </tr>
				  <tr>
					  <th>{PRICE_COUNT_LABEL} (4/4) :</th>
					  <th>
					   <input type="text" name="price4_item" id="price4_item" value="'.$GET_ITEM_INFO['item_price4'].'" /> / <input type="text" name="count4_item" id="count4_item" value="'.$GET_ITEM_INFO['item_count4'].'" />
					  </th>
				  </tr>		
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>
				  <tr>
					  <th>{IMAGE_URL_LABEL} (63px / 63px) :</th>
					  <th>
					   <input type="text" name="img_item" id="img_item" value="'.$GET_ITEM_INFO['item_img'].'" />
					  </th>
				  </tr>		
				  <tr>
					  <th>{IMAGE_URL_LABEL} (119px / 119px) :</th>
					  <th>
					   <input type="text" name="img_big_item" id="img_big_item" value="'.$GET_ITEM_INFO['item_img_big'].'" />
					  </th>
				  </tr>	
				  <tr>
					  <th>&nbsp;</th>
					  <th>&nbsp;</th>
				  </tr>';
				  if(GetItemInfo($GET_ITEM_INFO['item_vnum'],'type') != 28){
						
						$RETURN .= '
				  <tr>
					  <th>{ITEM_TIME_LABEL} :</th>
					  <th>
					   <select name="time_item">
						<option value="">{NO_LABEL}</option>
						<option value="1" '.$ITEM_TIME.'>{YES_LABEL}</option>
					</select>
					  </th>
				  </tr>	
				  <tr>	
					  <th>{ITEM_TIME_INPUT_LABEL} : </th>
					  <th>
					   <input type="text" name="time_count_item" id="time_count_item" value="'.$GET_ITEM_INFO['item_time'].'" />
					<select name="time_type_item">
						<option value="1">{SECOND_LABEL}</option>
						<option value="60">{MINUTE_LABEL}</option>
						<option value="3600">{HOUR_LABEL}</option>
						<option value="86400">{DAY_LABEL}</option>
					</select>
					  </th>
				  </tr>	
				  <tr>
					  <th>{SOCKET_TIME_LABEL} :</th>
					  <th>
					   <input type="text" name="socket_item" id="socket_item" value="'.$GET_ITEM_INFO['item_time_socket'].'" />
					  </th>
				  </tr>
					';
					}else{
					$RETURN .= '
					
					<tr>
					  <th>{COSTUME_BONUS_LABEL} :</th>
					  <th>
					  <select name="costume_bonus_item">
					   <option value="">{NO_LABEL}</option>
						<option value="1" '.$COSTUME_BONUS_ENABLE.'>{YES_LABEL}</option>
						</select>
					  </th>
				  </tr>	
						
						';
					}
					
					$RETURN .= '
					<tr>
					  <th>{ITEM_VISIBLE_LABEL} :</th>
					  <th>
					  <select name="visible_item">
					   <option value="1">{YES_LABEL}</option>
						<option value="0" '.$ITEM_VISIBLE.'>{NO_LABEL}</option>
						</select>
					  </th>
				  </tr>	
				  </tbody>
				</table>
				
				
				
				<br />
				<label>{DESCRIPTION_LABEL}: </label>
					<br />
					<textarea name="desc_item" id="desc_item" cols="60" rows="5">'.utf8_encode($GET_ITEM_INFO['item_desc']).'</textarea>
					<br />
					<br />
				<label>{DESCRIPTION_BIG_LABEL}: </label>
					<br />
					<textarea name="desc_item_big" id="desc_item_big" cols="60" rows="5">'.utf8_encode($GET_ITEM_INFO['item_desc_big']).'</textarea>
					<br />
					<br />
					<input type="hidden" name="admin_type_post" value="modify_item" />
					<input type="submit" value="{MODIFY_LABEL}" />
			</form>
		';
		return $RETURN;

	}
}
function AddNewiShopItem(){
	$VNUM = isset($_POST['item_vnum']) ? $_POST['item_vnum'] : 0;
	$NAME = isset($_POST['item_name']) ? $_POST['item_name'] : NULL;
	$STACK = $_POST['stack_item'] > 0 ? $_POST['stack_item'] : 0;
	$CATEGORIE = isset($_POST['cat_item']) ? $_POST['cat_item'] : 0;
	$TYPE = isset($_POST['type_item']) ? $_POST['type_item'] : NULL;
	$SEXE_RESTRICT = $_POST['sexe_item'] != "" ? $_POST['sexe_item'] : NULL;
	$RACE_RESTRICT = $_POST['race_item'] != "" ? $_POST['race_item'] : NULL;
	$LEVEL_RESTRICT = $_POST['level_item'] > 0  ? $_POST['level_item'] : 0;
	$PRICE1 = $_POST['price1_item'] > 0  ? $_POST['price1_item'] : 0;
	$COUNT1 = $_POST['count1_item'] > 0  ? $_POST['count1_item'] : 0;
	$PRICE2 = $_POST['price2_item'] > 0  ? $_POST['price2_item'] : 0;
	$COUNT2 = $_POST['count2_item'] > 0  ? $_POST['count2_item'] : 0;
	$PRICE3 = $_POST['price3_item'] > 0  ? $_POST['price3_item'] : 0;
	$COUNT3 = $_POST['count3_item'] > 0  ? $_POST['count3_item'] : 0;
	$PRICE4 = $_POST['price4_item'] > 0 ? $_POST['price4_item'] : 0;
	$COUNT4 = $_POST['count4_item'] > 0  ? $_POST['count4_item'] : 0;
	$IMG_URL = $_POST['img_item'] != "" ? $_POST['img_item'] : NULL;
	$IMG_BIG_URL = $_POST['img_big_item'] != "" ? $_POST['img_big_item'] : NULL;
	$TIME_ITEM = $_POST['time_item'];
	$TIME_TIME_ITEM = ($_POST['time_count_item']*$_POST['time_type_item']) > 0 ? ($_POST['time_count_item']*$_POST['time_type_item']) : 0;
	$SOCKET = $_POST['socket_item'];
	$DESCRIPTION = $_POST['desc_item'];
	$DESCRIPTION_BIG = $_POST['desc_item_big'];
	$ITEM_VISIBLE = $_POST['visible_item'];
	$COSTUME_BONUS = $_POST['costume_bonus_item'] > 0 ? $_POST['costume_bonus_item'] : 0;
	$QUERY = mysqli_query(ConnectiShopDb(),"INSERT INTO ".ISHOP_MYSQL_DB.".item_list(item_vnum,item_name,item_count,item_count2,item_count3,item_count4,item_desc,item_desc_big,item_type,item_img,item_img_big,item_cat,item_price,item_price2,item_price3,item_price4,item_stack,item_sexe_restrict,item_race_restrict,item_level_restrict,item_time,item_time_socket,item_costume_bonus,item_visible) VALUES
		('".$VNUM."','".$NAME."',".$COUNT1.",".$COUNT2.",".$COUNT3.",".$COUNT4.",'".$DESCRIPTION."','".$DESCRIPTION_BIG."','".$TYPE."',
		 '".$IMG_URL."','".$IMG_BIG_URL."','".$CATEGORIE."',".$PRICE1.",".$PRICE2.",".$PRICE3.",".$PRICE4.",
		 '".$STACK."',".($SEXE_RESTRICT != "" ? "'".$SEXE_RESTRICT."'" : "null").",".($RACE_RESTRICT != "" ? "'".$RACE_RESTRICT."'" : "null").",'".$LEVEL_RESTRICT."',".$TIME_TIME_ITEM.",'".$SOCKET."','".$COSTUME_BONUS."',".$ITEM_VISIBLE.")
	");
		if($QUERY){
			return "{ITEM_ADD_SUCCESS_LABEL}";
		}else{
			return "{ITEM_ADD_FAIL_LABEL}";
		}
}
function ModifyiShopItem(){
	$ID = $_POST['item_id'];
	$VNUM = isset($_POST['item_vnum']) ? $_POST['item_vnum'] : 0;
	$NAME = isset($_POST['item_name']) ? $_POST['item_name'] : NULL;
	$STACK = $_POST['stack_item'] > 0 ? $_POST['stack_item'] : 0;
	$CATEGORIE = isset($_POST['cat_item']) ? $_POST['cat_item'] : 0;
	$TYPE = isset($_POST['type_item']) ? $_POST['type_item'] : NULL;
	$SEXE_RESTRICT = $_POST['sexe_item'] != "" ? $_POST['sexe_item'] : NULL;
	$RACE_RESTRICT = $_POST['race_item'] != "" ? $_POST['race_item'] : NULL;
	$LEVEL_RESTRICT = $_POST['level_item'] > 0  ? $_POST['level_item'] : 0;
	$PRICE1 = $_POST['price1_item'] > 0  ? $_POST['price1_item'] : 0;
	$COUNT1 = $_POST['count1_item'] > 0  ? $_POST['count1_item'] : 0;
	$PRICE2 = $_POST['price2_item'] > 0  ? $_POST['price2_item'] : 0;
	$COUNT2 = $_POST['count2_item'] > 0  ? $_POST['count2_item'] : 0;
	$PRICE3 = $_POST['price3_item'] > 0  ? $_POST['price3_item'] : 0;
	$COUNT3 = $_POST['count3_item'] > 0  ? $_POST['count3_item'] : 0;
	$PRICE4 = $_POST['price4_item'] > 0 ? $_POST['price4_item'] : 0;
	$COUNT4 = $_POST['count4_item'] > 0  ? $_POST['count4_item'] : 0;
	$IMG_URL = $_POST['img_item'] != "" ? $_POST['img_item'] : NULL;
	$IMG_BIG_URL = $_POST['img_big_item'] != "" ? $_POST['img_big_item'] : NULL;
	$TIME_ITEM = $_POST['time_item'];
	$TIME_TIME_ITEM = ($_POST['time_count_item']*$_POST['time_type_item']) > 0 ? ($_POST['time_count_item']*$_POST['time_type_item']) : 0;
	$SOCKET = $_POST['socket_item'];
	$DESCRIPTION = $_POST['desc_item'];
	$DESCRIPTION_BIG = $_POST['desc_item_big'];
	$ITEM_VISIBLE = $_POST['visible_item'];	
	$COSTUME_BONUS = $_POST['costume_bonus_item'] > 0 ? $_POST['costume_bonus_item'] : 0;
	$QUERY = mysqli_query(ConnectiShopDb(),"REPLACE INTO ".ISHOP_MYSQL_DB.".item_list(item_id,item_vnum,item_name,item_count,item_count2,item_count3,item_count4,item_desc,item_desc_big,item_type,item_img,item_img_big,item_cat,item_price,item_price2,item_price3,item_price4,item_stack,item_sexe_restrict,item_race_restrict,item_level_restrict,item_time,item_time_socket,item_costume_bonus,item_visible) VALUES
		('".$ID."','".$VNUM."','".$NAME."',".$COUNT1.",".$COUNT2.",".$COUNT3.",".$COUNT4.",'".$DESCRIPTION."','".$DESCRIPTION_BIG."','".$TYPE."',
		 '".$IMG_URL."','".$IMG_BIG_URL."','".$CATEGORIE."',".$PRICE1.",".$PRICE2.",".$PRICE3.",".$PRICE4.",
		 '".$STACK."',".($SEXE_RESTRICT != "" ? "'".$SEXE_RESTRICT."'" : "null").",".($RACE_RESTRICT != "" ? "'".$RACE_RESTRICT."'" : "null").",'".$LEVEL_RESTRICT."',".$TIME_TIME_ITEM.",'".$SOCKET."','".$COSTUME_BONUS."',".$ITEM_VISIBLE.")
	");
		if($QUERY){
			return "{ITEM_MODIFY_SUCCESS_LABEL}";
		}else{
			return "{ITEM_MODIFY_FAIL_LABEL}";
		}
}
