<?php
require_once("connect.inc.php");

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

function getGroundChars( $x, $y )
{
global $connexion;

$req = '
SELECT cid, name, sex, uid, emblem, master_id,
       user_guild_emblem as guild_emblem,
       user_guild_name   as guild_name
FROM (
      SELECT cid, name, sex, uid,
             user_guild_emblem    as emblem,
             user_guild_master_id as master_id 
      FROM (
            SELECT char_id       as cid,
                   char_name     as name,
                   char_sex      as sex,
                   user_id       as uid
            FROM characters 
            WHERE char_pos ~= point ('.$x.','.$y.')
      ) AS c LEFT JOIN users
      ON users.user_id = c.uid
) AS cu LEFT JOIN users 
ON users.user_id = cu.master_id
';

$res = pg_query($connexion, $req) or die( pg_last_error().'<br />'.$req );
$select  = '
<select id="groundCharsSelect" onChange="getGroundCharInfos();" size="4">
<option value="-1">-aucun-</option>';

while( $c = pg_fetch_array($res) ) {
	
	if ( $c['sex']=='t' ) $color='#a4c6ff'; else $color='#ffc5f2';
	$select .= '<option value="'.$c['cid'].'" style="background-image:url('.$c['guild_emblem'].');
	       background-color:'.$color.';">'.$c['name'].'</option>';
}
$select .= '</select>';
echo $select;
}
//getGroundChars( $_GET['x'], $_GET['y'] );
?>