<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: index.php');
}
if (isset($_GET['W9mvyDvFWE5']))
{
	$chaiz=addslashes($_GET['W9mvyDvFWE5']);
	$active=$chaiz;
	
	//require_once('active.php');
	include('tete.php');	
	if($developpeur==3)
	{
		$sql2='SELECT COUNT(*) as nbr FROM information,type WHERE type.id_type=information.id_type AND lib_type="'.$chaiz.'" AND id_user='.$_SESSION['celest'];
	}
	else
	{
		$sql2='SELECT COUNT(*) as nbr FROM information, type WHERE type.id_type=information.id_type AND lib_type="'.$chaiz.'"';
	}
	$reponse2=$bdd->query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
	$data2=$reponse2->fetch();
	?>
    <link rel="stylesheet" type="text/css" href="style/style_admin.css" />
</head>
<body>
    <div id="wrapper">
    	<?php include('menu_admin.php'); ?>
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12" id="administration">
                	<?php
                    if($developpeur==3)
					{
						?>
						<div class="alert alert-info" style="text-align:center; margin-top:15px;">Ce que vous ajouter est liés à <em><strong><?php echo $lib_categorie; ?></strong></em></div>
						<?php
					}
					?>
                	<div id="titro_admin">Gestionnaire : <?php echo stripslashes($chaiz); ?> <span>(<?php echo $data2[0] ?>)</span></div>
                    <table width="100%" class="table table-hover table-striped table-bordered" id="tableau">
					<div id="add_admin">
						<a class="btn btn-primary" href="ajouter-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>">
							<i class="fa fa-pencil"></i> Ajouter
						</a>
					</div>
                    <?php
					if($developpeur!=3)
					{
						/*if($chaiz=='Actualité')
						{*/
							?>
							<div id="classement">
								<a href="classement.php?W9mvyDvFWE5=<?php echo $chaiz; ?>">Faire le classement</a>
							</div>
							<?php
						//}
					}
					if($chaiz=='Actualité')
					{
						?>
                        <tr align="center"><td></td> <td></td> <td>visible</td> <?php if($developpeur!=3){ ?> <td>slider</td><?php } ?> <td></td> <td></td> <td></td></tr>
                        <?php
					}
					$i=0;
					if($developpeur==3)
					{
						$sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND lib_type="'.$chaiz.'" AND id_user='.$_SESSION['celest'].' ORDER BY id_information DESC';
					}
					else
					{
						$sql='SELECT * FROM information, type WHERE type.id_type=information.id_type AND lib_type="'.$chaiz.'" ORDER BY id_information DESC';
					}
					$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
					while($data=$reponse->fetch())
					{
						$i++;
						?>
						<tr align="center">
							<td align="left" id="td0">
								<?php echo $i ?>
							</td>
							<td align="left" id="td1">
                            	<?php
								$sql2= 'SELECT * FROM image WHERE id_information='.$data[0].'';
								$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
								$data2=$reponse2->fetch();
								if($chaiz=='Actualité')
								{
									if($developpeur!=3)
									{
										list($width, $height, $type, $attr) = getimagesize('../upload/'.$data2['lib_image']);
										//echo ($width/$height);
										if(($width/$height)<=1.7)
										{
											?>
											<div class="alert alert-info" id="slider">S'affichera correctement dans le slider</div>
											<?php
										}
										else
										{
											?>
											<div class="alert alert-danger" id="slider">Ne s'affichera pas correctement dans le slider</div>
											<?php
										}
									}
								}
								?>
                                <a href="afficher-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $data[0] ?>">
                                	<?php
                                    $sql3='SELECT * FROM information, langue WHERE langue.id_langue=information.id_langue AND id_information="'.$data[0].'"';
									$reponse3=$bdd-> query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
									while($data3=$reponse3->fetch())
									{
										if($data2[0]!=NULL)
										{
											?>
                                            <img src="../upload/<?php echo $data2['img_langue'] ?>" width="20">
                                            <?php
										}
									}
									if($data2[0]==NULL)
									{
										$sql11='SELECT * FROM selection_type, type, selection WHERE selection_type.id_selection=selection.id_selection AND type.id_type=selection_type.id_type AND lib_type="'.$chaiz.'"';
										$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
										while($data11=$reponse11->fetch())
										{
											if($data11['lib_selection']=='fa')
											{
												echo '<i class="fa '.$data['fa_information'].' fa-3x"></i>';
											}
										}
										if($chaiz!='Avantage')
										{
											?>
											<img src="img/noimage.png" id="img-table">	
											<?php
										}
									}
									else
									{
										?>
                                        <img src="../upload/<?php echo $data2['lib_image']; ?>" id="img-table">
                                        <?php
									}
									echo stripslashes($data['lib_information']);
                                    /*if($developpeur!=3)
									{
										$sql2='SELECT * FROM information, user WHERE user.id_user=information.id_user AND id_information="'.$data[0].'"';
										$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
										$data2=$reponse2->fetch();
										echo ' <span>['.$data2['lib_user'].']</span>';
									}*/
									if($chaiz=='Calendrier')
									{
										if(empty($data['score1_information']) and empty($data['score2_information']))
										{
											echo ' <span>[Match avenir]</span>';
										}
										else
										{
											echo ' <span>[Résultat de match]</span>';
										}
									}
									$sql2='SELECT * FROM information, typeinfo WHERE typeinfo.id_typeinfo=information.id_typeinfo AND id_information='.$data[0].'';
									$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
									while($data2=$reponse2->fetch())
									{
										if($data2[0]!=NULL)
										{
											?>
                                            <span>(<?php echo $data2['lib_typeinfo']; ?>)</span>
                                            <?php
										}
									}
									
									$sql2='SELECT * FROM information, typeinfo, categorie WHERE typeinfo.id_typeinfo=categorie.id_typeinfo AND categorie.id_categorie=information.id_categorie AND id_information='.$data[0].'';
									$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
									while($data2=$reponse2->fetch())
									{
										if($data2[0]!=NULL)
										{
											?>
                                            <span>(<?php echo $data2['lib_typeinfo']; ?>)</span>
                                            <?php
										}
									}
									?>
                                </a>
                            </td>
                            <td id="td2">
								<?php
                                if($data['visible_information']=='oui')
								{
									echo '<a href="?num='.$data[0].'&disponibilite=non&W9mvyDvFWE5='.$chaiz.'"><img src="img/valid.png" width="20"></a>';
								}
								else
								{
									echo '<a href="?num='.$data[0].'&disponibilite=oui&W9mvyDvFWE5='.$chaiz.'"><img src="img/attention.png" width="20"></a>';
								}
								if(isset($_GET['disponibilite']))
								{
									$disponibilite=addslashes(($_GET['disponibilite']));						
									$num=addslashes(($_GET['num']));						
									$req='UPDATE information SET visible_information="'.$disponibilite.'" WHERE id_information="'.$num.'"';
									$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
									?>
									<script type="text/javascript">window.setTimeout("location=('gestionnaire-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>');",0);</script>
									<?php
								}
								?>
							</td>
                            <?php
							if($developpeur!=3)
							{
								if($chaiz=='Actualité')
								{
									?>
									<td id="td2">
										<?php
										if($data['slider_information']=='oui')
										{
											echo '<a href="?num='.$data[0].'&slider=non&W9mvyDvFWE5='.$chaiz.'"><img src="img/valid.png" width="20"></a>';
										}
										else
										{
											echo '<a href="?num='.$data[0].'&slider=oui&W9mvyDvFWE5='.$chaiz.'"><img src="img/attention.png" width="20"></a>';
										}
										if(isset($_GET['slider']))
										{
											$disponibilite=addslashes(($_GET['slider']));						
											$num=addslashes(($_GET['num']));						
											$req='UPDATE information SET slider_information="'.$disponibilite.'" WHERE id_information="'.$num.'"';
											$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
											?>
											<script type="text/javascript">window.setTimeout("location=('gestionnaire-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>');",0);</script>
											<?php
										}
										?>
									</td>
									<?php
								}
							}
							?>
                            <td id="td2">
								<a href="modifier-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $data[0] ?>">
									<i class="fa fa-edit fa-2x"></i>
								</a>
							</td>
							<td id="td3">
								<a href="supprimer-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $data[0] ?>">
									<i class="fa fa-trash-o fa-2x"></i>
								</a>
							</td>
							<td id="td4">
								<?php echo date("d M Y H:i", strtotime($data['creation_information'])); ?>
							</td>
						</tr>
						<?php
					}
					if($i==0)
					{
						echo '<div class="alert alert-danger" id="alert"><i class="fa fa-warning"></i> Pas de '.stripslashes($chaiz).'</div>';
					}
					?>
                    </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<?php 
}
else
{
	header('Location: index.php');
}
?>