<?php 
require_once '../../../../lib/configuration.inc';

// Vérification si l'accès est valide
if(!isset($_SESSION['SessionADMIN_compte_id'])){
	header('Location: ../../../auth.php');
	exit;
}

// Vérification si l'utilisateur a les droits d'accès
if($_SESSION['SessionADMIN_compte_type']=='utilisateur' AND (in_array(8, $_SESSION['SessionADMIN_compte_acces_modules'])==false OR in_array(13, $_SESSION['SessionADMIN_compte_acces_rubriques'])==false)){
	header('Location: ../../../');
	exit;
}


if(isset($action) AND $action=='positionner'){

	// Changement de la position (monter ou descendre)
	position_classement($connexion_mysql, 'sponsors', 'sponsor_id', 'sponsor_classement', '', $sponsor, $sponsor_position_actuelle, $direction);

	// Mise à jour du classement après ajout
	mise_a_jour_classement($connexion_mysql, 'sponsors', 'sponsor_id', 'sponsor_classement', '');

	header('Location: ./');

}

// Sélection des sponsors enregistrés
$requete_sponsors = mysqli_query($connexion_mysql, 'SELECT sponsor_id, sponsor_nom, sponsor_logo, sponsor_classement, sponsor_actif FROM sponsors ORDER BY sponsor_classement');
$nb_sponsors = mysqli_num_rows($requete_sponsors);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title><?=$admin_titre?></title>
	<link rel="shortcut icon" type="image/png" href="<?=$admin_domaine?>favicon.png">
	<link rel="stylesheet" type="text/css" href="<?=$admin_css_page?>">
	<script type="text/javascript" src="<?=$admin_js?>jquery/jquery.js"></script>
	<script type="text/javascript" src="<?=$admin_js?>commun.js"></script>
	<meta name="robots" content="none">
</head>

<body>

<script language="Javascript">
	<!-- 
	function supprimer(identifiant, nom, image){
		resultat = confirm("Désirez-vous réellement supprimer le sponsor ' " + nom + " ' ?");
		if(resultat == true){
			window.location = 'supprimer.php?sponsor_id=' + identifiant + '&sponsor_logo=' + image;
		}
	}
	//-->
</script>

<?php 
include $general_path_relatif.'sources/entete.inc';
include $general_path_relatif.'sources/menu.inc';
?>

<div id="contenu_1"<?=$correction_contenu_1?>><div id="contenu_2">

	<div id="contenu_3" align="left" style="width: 450px;">

		<div id="titres">
			<span class="titre_1">Sponsors</span>
			<span class="ajouter"><a href="./ajouter.php">Ajouter</a></span>
		</div>
		<br clear="all">

		<?php 
		if($nb_sponsors==1){
			echo '<div id="ligne_compteur"><b>1</b> sponsor sélectionné</div>';
		}elseif($nb_sponsors>1){
			echo '<div id="ligne_compteur"><b>'.$nb_sponsors.'</b> sponsors sélectionnés</div>';
		}
		?>

		<div id="bloc">

			<?php 
			if($nb_sponsors!=0){

				for($sponsor_boucle=0; $sponsor_boucle<$nb_sponsors; $sponsor_boucle++){
					$resultat_sponsor = mysqli_fetch_array($requete_sponsors);
					$sponsor_id = $resultat_sponsor[0];
					$sponsor_nom = $resultat_sponsor[1];
					$sponsor_logo = $resultat_sponsor[2];
					$sponsor_classement = $resultat_sponsor[3];
					$sponsor_actif = $resultat_sponsor[4];

					if($sponsor_actif==1){ $sponsor_ligne_css = 'ligne'; }else{ $sponsor_ligne_css = 'ligne_inactive'; }
			?>

					<div id="<?=$sponsor_ligne_css?>">
						<div style="float: left; width: 250px;" title="Nom du sponsor"><a href="./modifier.php?sponsor_id=<?=$sponsor_id?>"><?=$sponsor_nom?></a></div>
						<?php 
						if($sponsor_boucle==0){
							echo '<div id="ligne_icone" style="width: 50px; height: 18px; padding-left: 10px; border-left: 1px solid #CCCCCC;">&nbsp;</div>'."\n";
						}else{
							echo '<div id="ligne_icone" style="width: 50px; height: 18px; padding-left: 10px; border-left: 1px solid #CCCCCC;"><a href="Javascript: void(0);" onclick="window.location=\''.$PHP_SELF.'?action=positionner&sponsor='.$sponsor_id.'&sponsor_position_actuelle='.$sponsor_classement.'&direction=monter\'" title="Monter la position"><img src="'.$admin_img.'icone_monter.png" width="14" height="14"></a></div>'."\n";
						}
						if($sponsor_boucle==($nb_sponsors-1)){
							echo '<div id="ligne_icone" style="width: 50px; height: 18px; border-right: 1px solid #CCCCCC;">&nbsp;</div>'."\n";
						}else{
							echo '<div id="ligne_icone" style="width: 50px; height: 18px; border-right: 1px solid #CCCCCC;"><a href="Javascript: void(0);" onclick="window.location=\''.$PHP_SELF.'?action=positionner&sponsor='.$sponsor_id.'&sponsor_position_actuelle='.$sponsor_classement.'&direction=descendre\'" title="Descendre la position"><img src="'.$admin_img.'icone_descendre.png" width="14" height="14"></a></div>'."\n";
						}
						?>
						<div id="ligne_icone" style="margin-left: 15px;"><a href="./modifier.php?sponsor_id=<?=$sponsor_id?>" title="Modifier"><img src="<?=$admin_img?>picto_modifier.png" width="10" height="10"></a></div>
						<div id="ligne_icone"><a href="Javascript:void(0);" onclick="supprimer('<?=$sponsor_id?>', '<?=addslashes($sponsor_nom)?>', '<?=$sponsor_logo?>')" title="Supprimer"><img src="<?=$admin_img?>picto_supprimer.png" width="10" height="10"></a></div>
					</div>

			<?php 
				}
			}else{
				echo '<div id="ligne">aucun sponsor enregistré</div>'."\n";
			}
			?>

		</div>

	</div>
	<br clear="all">

</div></div>


<?php include $general_path_relatif.'sources/pied_page.inc'; ?>

</body>
</html>
