<?php

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

	function avatar($id)
	{
		$us=$this->db->fetch("SELECT * FROM `users` WHERE `id`=? LIMIT 1",array($id));
		$types = array("w_head","w_shoulders","w_torso","w_mittens","w_weapon","w_pants","w_boots","w_shield");
			$i=0;
			foreach ($types as $type)
			{	
				if($us[$type]==0){
				$img_{$type}="no";					
			} else {
				$weap=$this->db->fetch("SELECT `image` FROM `weapons` WHERE `id`=?",array($us[$type]));
				$img_{$type}=$weap['image'];
				}
			}
			echo "<center>
				<table border='2' style='width:0;'>
					<tr><td><img width='45' src='/imgData/weapons/".$img_{$types['0']}.".jpg'></td>
					<td ROWSPAN='4'><img style='height:200px;' src ='/imgData/static/co/".$us['sex']."/4.jpg'/></td>
					<td><img width='45' src='/imgData/weapons/".$img_{$types['1']}.".jpg'></td> </tr>
					<tr><td><img width='45' src='/imgData/weapons/".$img_{$types['2']}.".jpg'></td>
					<td><img width='45' src='/imgData/weapons/".$img_{$types['3']}.".jpg'></td> </tr>
					<tr><td><img width='45' src='/imgData/weapons/".$img_{$types['4']}.".jpg'></td>
					<td><img width='45' src='/imgData/weapons/".$img_{$types['5']}.".jpg'></td> </tr>
					<tr><td><img width='45' src='/imgData/weapons/".$img_{$types['6']}.".jpg'></td>
					<td><img width='45' src='/imgData/weapons/".$img_{$types['7']}.".jpg'></td> </tr></table></center>";

}
}
/*
	public function user ($key)
	{
		$data = $this->db->fetch("SELECT `id`,`".$key."` FROM `users` WHERE `id`=?",
											array ($this->uid));
		return (array_key_exists($key, $data) ? $data[$key] : null);
	}
	public function showItemCase ($type)
	{
		$types = array("head","shoulders","torso","mittens","weapon","pants","boots","shield");
		if (!array_key_exists($type, $types))
		{
			return null;
		}

		$weaponID = $this->user($type);
		$weapon = $this->db->rows("SELECT `id`,`type`,`user` FROM `weapons` WHERE `user`=? and `id`=? and `type`=?",
																			array ($this->uid,$weaponID,$type));

		if ($weapon == 0)
		{
			return null;
		}
		$wp_data = $this->db->fetch("SELECT *  FROM `weapons` WHERE `user`=? and `id`=? and `type`=?",
																			array ($this->uid,$weaponID,$type));
		$item = $this->db->fecth("SELECT * FROM `items` WHERE `id`=? ",
											array($wp_data['id']));
		$ret = '<img src =\'/imgData/items/'.$item['id'].'.png\'/>';

		return $ret;
	}

}
*/

