<?php

require_once("connect.inc.php");

/* ------------------------------------------------------------------------------------
getCaseInfos

Recupere les informations detaillees sur une case (x,y) de proprietaire "uid"
------------------------------------------------------------------------------------ */

function getCaseInfos( $x, $y, $type, $uid )
{
	global $connexion;
	$req = 'SELECT * FROM getinfoscase('.$uid.');';
	$res = pg_query($connexion, $req) or die( pg_last_error().'<br />'.$req );
	$infos = pg_fetch_array($res);
	
	if(pg_num_rows($res)==0) {
		$x = 'x';
		$y = 'y';
		$type = 0;
		$emblem = '';
		$name = 'inconnu';
		$guild_name = 'inconnue';
	} else { 
		$name = $infos['login'];
		$masterId = $infos['masterId'];
		$guild_name = $infos['guildname'];
		$guild_emblem = $infos['guildemblem'];
		
		if( $masterId == $uid ) $name .= ' (ma&icirc;tre de guilde)';
		if($guild_emblem!=null) $emblem = ' <img src="'.$guild_emblem.'" alt="embl&ecirc;me" />';
	}
	
	$req2 = 'SELECT char_id, user_id, char_name, char_sex FROM characters WHERE char_pos~=point\'('.$x.','.$y.')\'';
	$res2 = pg_query($connexion, $req2) or die( pg_last_error().'<br />'.$req2 ); $select='';
	
	$select  = '<select id="opponentCharSelect" onChange="getOpponentCharInfos();" size="4">';
	$select .= '<option value="-1">-aucun-</option>';
	while( $c = pg_fetch_array($res2) ) {
		if ( $c['char_sex']=='t' ) $sex='male'; else $sex='female';
		$select .= '<option value="'.$c['char_id'].'" style="background-image:url(img/'.$sex.'.gif);">';
		$select .= $c['char_name'].'</option>';
	}
	$select .= '</select>';
	
	echo '<div id="infos_ground" class="t'.$type.'">'.$emblem.'</div></div>Case ('.$x.', '.$y.')<br/>P: '.$name.'<br/>G: '.$guild_name.'</div>'.$select;
}
/*
echo '<link href="carte.css" rel="stylesheet" type="text/css" />';
getCaseInfos( 2, 0, 3, 2 );
*/
getCaseInfos( $_GET['x'], $_GET['y'], $_GET['type'], $_GET['uid'] );
?>