<?php

require_once("connect.inc.php");
require_once ('../../common/scripts/persoGD.inc.php');

/* ------------------------------------------------------------------------------------
getOpponentCharInfos

Recupere les informations detaillees sur un mimichant ennemi d'id "cid"
------------------------------------------------------------------------------------ */

function getGroundCharInfos( $id )
{
global $connexion;

$req = '
SELECT cid, cname, sex, head, ears, corps, tail, skin, uid, login, emblem, master_id,
       user_guild_emblem as guild_emblem,
       user_guild_name   as guild_name
FROM (
      SELECT cid, cname, sex, head, ears, corps, tail, skin, uid,
             user_login           as login,
             user_guild_emblem    as emblem,
             user_guild_master_id as master_id 
      FROM (
            SELECT char_id        as cid,
                   char_name      as cname,
                   char_sex       as sex,
                   char_head      as head,
                   char_ears      as ears,
                   char_corps     as corps,
                   char_tail      as tail,
                   char_skincolor as skin,
                   user_id        as uid
            FROM characters 
            WHERE char_id='.$id.'
      ) AS c JOIN users
      ON users.user_id = c.uid
) AS cu JOIN users 
ON users.user_id = cu.master_id
';

$res = pg_query($connexion, $req) or die( pg_last_error().'<br />'.$req );
$c = pg_fetch_array($res);

if( $c['uid'] == $c['master_id'] ) $uname .= ' (ma&icirc;tre de guilde)';

/*$emblem = $c['guild_emblem'];
if($emblem!=null) 
	$imgemblem = '<img src="'.$emblem.'" alt="embl&ecirc;me" />';*/

if ( $c['sex']=='t' ) $sex='male'; else $sex='female';
$imgsex = '<img src="img/'.$sex.'.gif"/>';

// cree l'image du mimichant si elle n'existe pas deja
createMimichant($c['tail'], $c['corps'] , $c['head'] , $c['ears'], $c['skin']);

$imgchar = '<img src="../mimichants/t'.$c['head'].'o'.$c['ears'].'c'.$c['corps'].'q'.$c['tail'].'c'.$c['skin'].'.gif"/>';

$html .= $imgchar.$imgsex.'<br/>';
//$html .= $imgchar.$imgemblem.$imgsex.'<br/>';
$html .= 'N: '.$c['cname'].'<br/>';
$html .= 'P: '.$c['login'].'<br/>';
$html .= 'G: '.$c['guild_name'].'<br/>';

echo $html;
}
//getGroundCharInfos( 11 );
getGroundCharInfos( $_GET['id'] );
?>