<?

class weap{
	public $db;
		function __construct($db){
			$this->db=$db;
		}

	function view($id,$user,$param,$table){
		$weap=$this->db->fetch("SELECT * FROM `".$table."` WHERE `id`=?",array($id));
		if($param!="no"){
		$my_use=$this->db->rows("SELECT * FROM `weapons` WHERE `id`=?",array($user[$weap['type']]));	
		if($my_use==0){
				$use=array("def"=>0,"hp"=>0,"str"=>0);
			} else {
				$use=$this->db->fetch("SELECT * FROM `weapons` WHERE `id`=?",array($user[$weap['type']]));
			}
			$summa_stat=($weap['str']+$weap['def']+$weap['hp'])-($use['def']+$use['hp']+$use['str']);
				if($summa_stat>=0){
					$result="Лучше на: ";
					$color="#0f0";
				} else {
					$result="Хуже на: ";
					$color="#f00";
				}
			if($weap['lvl']>$user['level']){
				$color_lvl="#f00";
			} else {
				$color_lvl="#0f0";
			}
}
		echo "<table  style='width:0;'><tr><td rowspan='3'> 
<img width='60' src='/imgData/weapons/".$weap['image'].".jpg'></td><td style='  padding: 0px 0px 0px 10px;'><a href='/info_weap.php?id=".$weap['id']."'><font color='".$color_lvl."'>".$weap['name']."</a> <img src='/imgData/static/level.png'>".$weap['lvl']."</font> </td> </tr><tr><td style='  padding: 0px 0px 0px 10px;'><img class='icon' src='/imgData/static/str.png'>".$weap['str']."<img class='icon' src='/imgData/static/hp.png'>".$weap['hp']."<img class='icon' src='/imgData/static/def.png'>".$weap['def']."</td></tr><tr><td style='  padding: 0px 0px 0px 10px;'><font color='".$color."'>".$result." ".$summa_stat."</font></td></tr></table>";
	}

	


}