<?php
	require_once('../common/scripts/connect.inc.php');
	require_once('../common/scripts/template.inc.php');

$template = new Template(".");

$template->set_file("info", "info.tpl");
$template->set_block("info", "INFO","Info");

$id=$_POST['id'];

//nom du mimichant
$name=pg_query($dbconn,"select char_name, char_head, char_ears, char_corps, char_tail,char_skincolor from characters where char_id = $id ");
$name=pg_fetch_row($name);

//informations sur le mimichant
$infos=pg_query($dbconn,"select char_infos from characters where char_id = $id ");
$infos=pg_fetch_row($infos);

//sexe
$sex=pg_query($dbconn,"select char_sex from characters where char_id = $id ");
$sex=pg_fetch_row($sex);
if($sex[0]==t)
$sex[0]="images/gif/sex_masc";
else
$sex[0]="images/gif/sex_fem";	
//argent
$money=pg_query($dbconn,"select char_money from characters where char_id = $id ");
$money=pg_fetch_row($money);
	
//points de vie
$pv=pg_query($dbconn,"select char_pv from characters where char_id = $id ");
$pv=pg_fetch_row($pv);
	
//points d'action
$pa=pg_query($dbconn,"select char_pa from characters where char_id = $id ");
$pa=pg_fetch_row($pa);
	
//points d'action par 60 minutes
$papm=pg_query($dbconn,"select char_papm from characters where char_id = $id ");
$papm=pg_fetch_row($papm);

//competence
$strength=pg_query($dbconn,"select char_strength from characters where char_id = $id ");
$strength=pg_fetch_row($strength);

$const=pg_query($dbconn,"select char_const from characters where char_id = $id ");
$const=pg_fetch_row($const);

$dext=pg_query($dbconn,"select char_dext from characters where char_id = $id ");
$dext=pg_fetch_row($dext);

$psy=pg_query($dbconn,"select char_psy from characters where char_id = $id ");
$psy=pg_fetch_row($psy);

//position
$pos=pg_query($dbconn,"select char_pos from characters where char_id = $id ");
$pos=pg_fetch_row($pos);

//equipement max
$equipmax=pg_query($dbconn,"select char_equipmax from characters where char_id = $id ");
$equipmax=pg_fetch_row($equipmax);

//case
//On selectionne le type de terrain ou est le mimi selectionné

$idcase=pg_query($dbconn,"select type_id from grounds where ground_pos ~= '$pos[0]' ");
$idcase=pg_fetch_row($idcase);
//On selectione l'id du terrain
$groundid=pg_query($dbconn,"select ground_id from grounds where ground_pos ~= '$pos[0]' ");
$groundid=pg_fetch_row($groundid);
//On selectionne le nom de la case en fct de son id
$typecase=pg_query($dbconn,"select type_name from ground_types where type_id = '$idcase[0]' ");
$typecase=pg_fetch_row($typecase);

/*
//On selectionne l'id du proprio du terrain
$userId=pg_query($dbconn,"select user_id from grounds where ground_id = '$groundid[0]' ");
$userId=pg_fetch_row($userId);
// Nom du proprio du terrain
$nameId=pg_query($dbconn,"select user_login from users where user_id = '$userId[0]' ");
$nameId=pg_fetch_row($nameId);
//Nom de la guilde du proprio
$Guildename=pg_query($dbconn,"select user_guild_name from users where user_id = '$userId[0]' ");
$Guildename=pg_fetch_row($Guildename);

//Nombre de personne sur la case
$nbuser=pg_query($dbconn,"select Count (char_id) from characters where char_pos ~= '$pos[0]' ");
$nbuser=pg_fetch_row($nbuser);

//Image de la case
$TerrainImage=pg_query($dbconn,"select ground_build from grounds where ground_id = '$groundid[0]' ");
$TerrainImage=pg_fetch_row($TerrainImage);
*/
$nameImage = '../mimichants/grost'.$name[1].'o'.$name[2].'c'.$name[3].'q'.$name[4].'c'.$name[5].'.gif';

$template->set_var("IMAGEMIMI",$nameImage);
$template->set_var("NAME",$name[0]);
$template->set_var("INFORMATION",$infos[0]);
$template->set_var("SEX",$sex[0]);
$template->set_var("MONEY",$money[0]);
$template->set_var("PV",$pv[0]);
$template->set_var("PA",$pa[0]);
$template->set_var("PAPM",$papm[0]);
$template->set_var("STRENGHT",$strength[0]);
$template->set_var("CONSTITUTION",$const[0]);
$template->set_var("DEXTERITY",$dext[0]);
$template->set_var("PSYCHISM",$psy[0]);
$template->set_var("POSITION",$pos[0]);
$template->set_var("EQUIPMAX",$equipmax[0]);
$template->set_var("TYPECASE",$typecase[0]);
$template->set_var("NAMEP",$nameId[0]);
$template->set_var("GUILDENAME",$Guildename[0]);
$template->set_var("NBUSER",$nbuser[0]);
$template->set_var("IMG",$TerrainImage[0]);

$template->parse("Info","INFO",true);
$template->parse("output","info");
$template->p("output");

// selection des identifiants des objets du mimichant
$objId=pg_query($dbconn,"select obj_id from equipements where char_id = $id and obj_equip= 'true'"); 

$nbId=pg_query($dbconn,"select count (obj_id) from equipements where char_id = $id and obj_equip= 'true'"); 
echo"<div class=\"Inventaire\">";
echo"<br />";
echo"<span class=\"info\">Arme(s) portée(s) par votre mimichant : </span>";
echo"<br /><br />";
while($ligneId=pg_fetch_array($objId)){
		$template2 = new Template(".");
		$template2->set_file("info", "arme.tpl");
		$template2->set_block("info", "ARME","Arme");
		$template2->set_var("IDARME",$ligneId[0]);
		foreach($ligneId as $valeurId){
				$objName=pg_query($dbconn,"select obj_name from objects where obj_id ='$ligneId[0]'"); 
				$name=pg_fetch_array($objName);
				$template2->set_var("NAMEARME",$name[0]);
				$image=$name[0];
				$template2->set_var("IMAGE",$image);
		}
		$template2->parse("Arme","ARME",true);
		$template2->parse("output","info");
		$template2->p("output");
}
echo"<br /></div>";
echo"<div class=\"PancarteInventaire\">";
	echo"<img style=\"cursor:pointer\" onclick='inventaire($id)' src=\"images/gif/inventaire.gif\" >";
echo"</div>";
?>