<?php 
// ----------------------------------------------------------------------------------------------------
//			Mod Classement des Sites 
//
//      par Saint-pere  <saintpere5 AT hotmail POINT com> http://www.yep-yop.com
//
//     premiere distribution le Dimanche 26 Février 2006
//
// ----------------------------------------------------------------------------------------------------

define('IN_PHPBB', true); 

$phpbb_root_path = './'; 

include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 
include( $phpbb_root_path . 'includes/functions_classement.' . $phpEx);

if (isset($HTTP_GET_VARS['id']) AND (isset($HTTP_GET_VARS['visiter'])))
{
	$id = eregi_replace('[^0-9]', '',$HTTP_GET_VARS['id']);
	$sql = "UPDATE ".CLASS_SITES." SET clics=clics+1 WHERE id_site=".$id ;
	if( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not update classification information', '', __LINE__, __FILE__, $sql);
	}
	header("Location: ".$HTTP_GET_VARS['visiter']);
	exit;
}

$image = 'images/vote_classement.png'; 

$im = imagecreatefrompng($image); 
$bleu = ImageColorAllocate ($im, 12, 133, 215); 
$jaune  = ImageColorAllocate ($im, 249,173, 43); 
$rouge  = ImageColorAllocate ($im, 225,32, 11); 

$titre = $lang['class_site_defaut'];
$votes= 0 ;
$place = 0; 

if (isset($HTTP_GET_VARS['site']) AND ($HTTP_GET_VARS['site'] !== ""))
{
	// Quel est le site demandé .. 
	$sql = 'SELECT id_site,titre_site,votes FROM '. CLASS_SITES . ' ORDER BY votes DESC';
	if( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not query recent classification information', '', __LINE__, __FILE__, $sql);
	}
	$i = 0;
	while ($row = $db->sql_fetchrow($result))
	{	
		$i++;
		if ($row['id_site'] == $HTTP_GET_VARS['site'])
		{
			$titre = $row['titre_site'];
			$votes= $row['votes'];
			$place = $i; 
			break; 
		}
	}
	$message = 'Votez des maintenant';
/* // Fonction désactivée pour le moment
	// On place un compteur si on possede l'IP du votant
	if (isset($HTTP_GET_VARS['ip']) AND ($HTTP_GET_VARS['ip'] !== ''))
	{
		$sql = "SELECT * FROM " . CLASS_IP . " WHERE ip='".$HTTP_GET_VARS['ip']."' AND date > '".date("Y")."-".date("m")."-".(date("d")-1)." ".date("H").":".date("i").":".date("s")."' ORDER BY DATE DESC LIMIT 1";
		if( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not check classification information', '', __LINE__, __FILE__, $sql);
		}
		if (($db->sql_numrows($result)) >= 1) 
		{
			$row = $db->sql_fetchrow($result);
			$message = "Votez dans ". temps_restant($row['date'], date("Y-M-d H:m:s"));
		}
		else 
		{
			$message = 'Votez des maintenant';
		}
	}
	else
	{
		$message = 'Votez des maintenant';
	}
*/
}
if ($place == 1) 
{
	$place = "1er"; 
}
else 
{
	$place .= "eme";
}
	
ImageString($im, 4, 50, 2, $titre, $jaune); 
ImageString($im, 6, 165, 15, $place, $rouge); 
ImageString($im, 2, 55, 15, $votes." votes", $bleu); 
ImageString($im, 2, 45, 25, $message, $bleu); 

header("Content-Type: image/png"); 
Imagepng($im,'',100); 
ImageDestroy ($im); 

?>