<?php
if ( !defined('IN_PHPBB') )
{
   die("Hacking attempt");
}
global $lang,$images,$board_config,$start,$sites_par_pages;

//chargement du template
$template->set_filenames(array(
   'listing' => 'areabb/mods/classement_sites/tpl/listing.tpl'
));

// On démarre notre liste de site par le début c'est mieux ... 
$start = (isset($HTTP_GET_VARS['start'])) ? intval($HTTP_GET_VARS['start']) : 0;

// On stocke tous les sites dans une variable
$liste_sites = array();
$sql = 'SELECT s.* , username,user_id,user_avatar_type,user_avatar
		FROM '. AREABB_CLASS_SITE .' as s
		LEFT JOIN '. USERS_TABLE .' as u 
		ON (s.id_user = u.user_id)
		ORDER BY '.$param_tri.' limit '.$start.','.$sites_par_pages;
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not query recent classification information', '', __LINE__, __FILE__, $sql);
}
if ($db->sql_numrows($result) < 1 )
{
	// Pas de site enregistré.
	$template->assign_block_vars('no_sites', array());
}else{
	// Des sites sont enregistrés.
	while( $row = $db->sql_fetchrow($result) )
	{
		// Avatar
		switch ( $row['user_avatar_type'] )
		{
			   case USER_AVATAR_GALLERY:
			      $avatar = $board_config['avatar_gallery_path']. '/' .$row['user_avatar'];
			      break;
			   case USER_AVATAR_UPLOAD:
			      $avatar = $board_config['avatar_path'] . '/' .$row['user_avatar'];
			      break;
			   case USER_AVATAR_REMOTE:
			      $avatar = $row['user_avatar'];
			      break;
			   default:
			      $avatar = 'areabb/images/guest_avatar.gif';      
		}
		$avatar = '<img src="'.$avatar.'" alt="Avatar de '.$row['username'].'" border="0" />';
		// On affiche les sites demandés ...
		$template->assign_block_vars('sites', array(
			'ID'			=> $row['id_site'],
			'TITRE' 		=> $row['titre_site'],
			'PROPRIO'		=> areabb_profile($row['user_id'],$row['username']),
			'AVATAR' 		=> $avatar,
			'URL' 			=> append_sid(NOM_CLASSEMENT.'.'.$phpEx.'?salle='.$id_squelette.'&id='.$row['id_site'].'&action=visiter&site='.$row['url_site']),
			'DESC' 			=> $row['description'],
			'BANNIERE' 		=> $repertoire_destination.$row['banniere'],
			'VOTES' 		=> $row['votes'],
			'CLICS' 		=> $row['clics']		
		));
		
		//On affiche les fichiers de modifs pour l'admin 
		// vive les privilèges !
		if (($userdata['user_level'] == ADMIN) || ($userdata['user_level'] == MOD))
		{
			$template->assign_block_vars('sites.admin', array(
				'EFFACER'	=> append_sid(NOM_CLASSEMENT.'.'.$phpEx.'?salle='.$id_squelette.'&id='.$row['id_site'].'&action=effacer'),
				'EDITER'	=> append_sid(NOM_CLASSEMENT.'.'.$phpEx.'?salle='.$id_squelette.'&id='.$row['id_site'].'&action=gestion&operation=EDIT_ADMIN')
			));	
		}
	}
}


// Variables générales
$template->assign_vars(array(
	'S_PAGINATION' 			=> $classite->pagination($action),
	'L_CLASSEMENT_SITES'	=> $lang['L_CLASSEMENT_SITES'],
	'L_DESCRIPTION'			=> $lang['L_DESCRIPTION'],
	'L_NO_SITES'			=> $lang['L_NO_SITES'],
	'L_VOTES'				=> $lang['votes'],
	'L_CLICS'				=> $lang['clics'],
	'L_PAGE'				=> $lang['L_PAGE'],
	'I_EDIT'				=> $images['icon_edit'],
	'I_DELETE'				=> $images['icon_delpost'],
	'I_DETAILS'				=> $images['icon_details'],
	'MESSAGE'				=> $message	
));

$template->assign_var_from_handle('CORPS', 'listing');

?>