<?php
if(!isset($_REQUEST['player']) || $_REQUEST['player']=='') {
	echo '';
} else {
	include('lib/conn.php');
	mysql_select_db(player);
	$player_name = $_REQUEST['player'];
	$sql = mysql_query("SELECT `id`, `gold` FROM `player`.`player` WHERE `name`='".$player_name."';");
	if(mysql_num_rows($sql)==0) {
		echo 'Aradiginiz <b>'.$player_name.'</b> Bulunamadi!';
	} else {
?>

<div id="inventar_wrap">
<div id="inventar">
	<div id="inv_top"></div>
	<div id="inv_page"></div>
	<div id="inv_con"></div>
	<div id="inv_bottom"></div>
</div>
<div id="inv_layer">
	<div id="inv_lay_1">
	<?php
	$res = mysql_fetch_array($sql);
	$user_id = $res['id'];
	$user_gold = $res['gold'];
	$user_gold_length = strlen($user_gold);
	
	if(($user_gold_length-3)>0) {
		$sub_st1 = $user_gold_length - 3;
		$substr1 = substr($user_gold, $sub_st1, 3);
		
		if(($user_gold_length-6)>0) {
			$sub_st2 = $user_gold_length - 6;
			$substr2 = substr($user_gold, $sub_st2, 3);
			
			if(($user_gold_length-9)>0) {
				$sub_st3 = $user_gold_length - 9;
				$substr3 = substr($user_gold, $sub_st3, 3);
				
				if(($user_gold_length-12)>0) {
					$sub_st4 = $user_gold_length - 12;
					$substr4 = substr($user_gold, $sub_st4, 3);
				} else {
					$substr4 = substr($user_gold, 0, -9);
				}
			} else {
				$substr3 = substr($user_gold, 0, -6);
			}
		} else {
			$substr2 = substr($user_gold, 0, -3);
		}	
	} else {
		$substr1 = $user_gold;
	}
	
	$equip = array();
	$equip_count = array();
	
	$inventar = array();
	$inventar_count = array();
	
	$sql2 = mysql_query("SELECT `pos`, `vnum`, `count`, `window` FROM `player`.`item` WHERE `owner_id`='".$user_id."' ORDER BY `pos`;");
	while($res2 = mysql_fetch_array($sql2)) {
		if($res2['window']=='EQUIPMENT') {
			$equip_length = strlen($res2['vnum']);
			switch($equip_length) {
				case '1':
					$res2['vnum'] = '0000'.$res2['vnum'];
				break;
				case '2':
					$res2['vnum'] = '000'.$res2['vnum'];
				break;
				case '3':
					$res2['vnum'] = '00'.$res2['vnum'];
				break;
				case '4':
					$res2['vnum'] = '0'.$res2['vnum'];
				break;
			}
			$equip[$res2['pos']] = substr($res2['vnum'], 0, -1);
			$equip_count[$res2['pos']] = $res2['count'];
		} elseif($res2['window']=='INVENTORY') {
			$inventar_length = strlen($res2['vnum']);
			switch($inventar_length) {
				case '1':
					$res2['vnum'] = '0000'.$res2['vnum'];
				break;
				case '2':
					$res2['vnum'] = '000'.$res2['vnum'];
				break;
				case '3':
					$res2['vnum'] = '00'.$res2['vnum'];
				break;
				case '4':
					$res2['vnum'] = '0'.$res2['vnum'];
				break;
			}
			if(!file_exists('img/item/'.$res2['vnum'].'.png')) {
				$inventar[$res2['pos']] = substr($res2['vnum'], 0, -1);
			} else {
				$inventar[$res2['pos']] = $res2['vnum'];
			}
			$inventar_count[$res2['pos']] = $res2['count'];
		}
	}
	echo '<div id="il1_4" class="il1_con">';
		if(isset($equip[4])) {echo '<img src="img/item/'.$equip[4].'0.png" alt="">';}
	echo '</div><div id="il1_1" class="il1_con">';
		if(isset($equip[1])) {echo '<img src="img/item/'.$equip[1].'0.png" alt="">';}
	echo '</div><div id="il1_0" class="il1_con">';
		if(isset($equip[0])) {echo '<img src="img/item/'.$equip[0].'0.png" alt="">';}
	echo '</div><div id="il1_2" class="il1_con">';
		if(isset($equip[2])) {echo '<img src="img/item/'.$equip[2].'0.png" alt="">';}
	echo '</div><div id="il1_10" class="il1_con">';
		if(isset($equip[10])) {echo '<img src="img/item/'.$equip[10].'0.png" alt="">';}
	echo '</div><div id="il1_3" class="il1_con">';
		if(isset($equip[3])) {echo '<img src="img/item/'.$equip[3].'0.png" alt="">';}
	echo '</div><div id="il1_6" class="il1_con">';
		if(isset($equip[6])) {echo '<img src="img/item/'.$equip[6].'0.png" alt="">';}
	echo '</div><div id="il1_5" class="il1_con">';
		if(isset($equip[5])) {echo '<img src="img/item/'.$equip[5].'0.png" alt="">';}
	echo '</div><div id="il1_9" class="il1_con">';
		if(isset($equip[9])) {echo '<img src="img/item/'.$equip[9].'0.png" alt=""><div class="item_count">'.$equip_count[9].'</div>';}
	echo '</div>';
	?>
	</div>
	<div id="inv_page2">
		<a href="?player=<?php echo $player_name; ?>&amp;ipa=1" class="page_link">
			<img src="<?php if($_REQUEST['ipa']==1) {echo 'img/inv_pag1_ac.png';} else {echo 'img/inv_pag1_in.png';} ?>" alt="">
		</a>
		<a href="?player=<?php echo $player_name; ?>&amp;ipa=2" class="page_link2">
			<img src="<?php if($_REQUEST['ipa']==2) {echo 'img/inv_pag2_ac.png';} else {echo 'img/inv_pag2_in.png';} ?>" alt="">
		</a>
		<div class="clear"></div>
	</div>
	<div id="inv_lay_2">
		<?php
		if(isset($_REQUEST['ipa']) && $_REQUEST['ipa']==2) {
		$start = 45; $end = 89;
		} else {
		$start = 0; $end = 44;
		}
		for($i=$start; $i<=$end; $i++) {
			echo '<div id="il2_'.$i.'" class="il2_con">';
			if(isset($inventar[$i])) {
				if(strlen($inventar[$i])==4) {
					echo '<img src="img/item/'.$inventar[$i].'0.png" alt="">';
				} else {
					echo '<img src="img/item/'.$inventar[$i].'.png" alt="">';
				}
				if($inventar_count[$i]>'1') {
					echo '<div class="item_count">'.$inventar_count[$i].'</div>';
				}
			}
			echo '</div>';
			if(($i+1)%5==0) {
				echo '<div class="clear"></div>';
			}
		}
		?>
	</div>
	<div id="inv_lay_3">
	<?php
		if(!isset($substr2) && !isset($substr3) && !isset($substr4)) {
			echo $substr1;
		} elseif(!isset($substr3) && !isset($substr4)) {
			echo $substr2.'.'.$substr1;
		} elseif(!isset($substr4)) {
			echo $substr3.'.'.$substr2.'.'.$substr1;
		} else {
			echo $substr4.'.'.$substr3.'.'.$substr2.'.'.$substr1;
		}?>
	Yang</div>
<input onclick="history.back();" type="button" value="GERI GEL">
</div>
</div>

<?php }} ?>
