<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: index.php');
}
if (isset($_GET['W9mvyDvFWE5']))
{
	$chaiz=addslashes($_GET['W9mvyDvFWE5']);
	$id=addslashes($_GET['QYtgoGbhhd']);
	$active=$chaiz;
	
	$sql='SELECT * FROM information, type WHERE information.id_type=type.id_type AND id_information="'.$id.'"';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$id_table=$data[0];
	include('tete.php');
	if($developpeur==3 and $data['id_user']!=$_SESSION['celest'])
	{
		header('Location: gestionnaire-table.php?W9mvyDvFWE5='.$chaiz);
	}
	?>
    <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-2 col-md-1"></div>
                <div class="col-lg-8 col-md-10 col-sm-11 col-xs-12" id="administration">
                    <div id="titro_admin">
                    	Détails <?php echo $chaiz ?>
                    </div>
                    <div id="afficher_admin">
                        <a class="btn btn-primary" href="ajouter-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>">
                            <i class="fa fa-pencil"></i> Ajouter
                        </a>
                    </div>
                    <table width="100%" class="table table-hover" id="tableau">
                    	<div style="float:right; margin-top:30px;">
                            <a href="modifier-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $id ?>">
                                <i class="fa fa-edit fa-2x"></i>
                            </a>
                        </div>
                        <!--<tr>
                            <td id="td_right">Type</td>
                            <td>
							<?php 
							/*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>';
								}
							}*/
							?>
                            </td>
                        </tr>-->
                        <!--<tr>
                            <td id="td_right">Membre</td>
                            <td>
							<?php 
							/*$sql2='SELECT * FROM information, user WHERE user.id_user=information.id_user AND id_information="'.$id.'"';
							$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
							$data2=$reponse2->fetch();
							echo ' <span>['.$data2['lib_user'].']</span>';*/
							?>
                            </td>
                        </tr>-->
                        <?php
                        /*if($developpeur!=3)
						{
							?>
							<tr>
								<td id="td_right">Annonce</td>
								<td>
								<?php 
								$sql2='SELECT * FROM information, categorie WHERE categorie.id_categorie=information.id_categorie AND id_information="'.$id.'"';
								$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
								$data2=$reponse2->fetch();
								if($data2[0]==NULL)
								{
									echo '<div class="alert alert-danger">Cette information a été ajouté par l\'administrateur</div>';
								}
								else
								{
									echo ' <span>['.$data2['lib_categorie'].']</span>';
								}
								?>
								</td>
							</tr>
							<?php
						}*/
                        ?>
                        <tr>
                            <td id="td_right">Messages laissés</td>
                            <td>
                            <?php 
                            $m = 0;
                            $sql2='SELECT * FROM contact, information WHERE contact.id_information=information.id_information AND information.id_information='.$id;
                            $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                            while($data2=$reponse2->fetch())
                            {
                                $m++;
                                ?>
                                <div id="voir-profil"><a href="#" title="Détails" data-toggle="modal" data-target="#myModal<?= $m; ?>"><i class="fa fa-eye"></i> <?= stripslashes($data2['lib_contact']); ?></a></div>
                                <div class="modal fade" id="myModal<?= $m; ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header">
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                                <h4 class="modal-title" id="myModalLabel">Détails du message de <?= stripslashes($data2['lib_contact']) ?></h4>
                                            </div>
                                            <div class="modal-body" align="center">
                                                <table width="100%" class="table table-hover" id="tableau">
                                                    <tr>
                                                        <td id="td_right">Nom:</td>
                                                        <td>
                                                            <?= stripslashes($data2['lib_contact']) ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td id="td_right">Email</td>
                                                        <td>
                                                            <?php echo stripslashes($data2['mail_contact']) ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td id="td_right">N°Téléphone</td>
                                                        <td>
                                                            <?php echo stripslashes($data2['tel_contact']) ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td id="td_right">Sujet</td>
                                                        <td>
                                                            <?php echo stripslashes($data2['lib_information']) ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td id="td_right">Message</td>
                                                        <td>
                                                            <?php echo stripslashes($data2['msg_contact']) ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td id="td_right">Date de création</td>
                                                        <td>
                                                            <?php echo date("d/m/Y H:i", strtotime($data2['creation_contact']));?>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                            <div class="modal-footer">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            }
                            ?>
                            </td>
                        </tr>
                        <?php
						$z=0;
						$y=0;
						$sql11='SELECT * FROM selection, champ WHERE champ.id_champ=selection.id_champ ORDER BY id_selection ASC';
						$reponse11=$bdd-> query($sql11) or die('Erreur SQL !<br />'.$sql11.'<br />'.mysql_error());
						while($data11=$reponse11->fetch())
						{
							$z++;
							$nbr_blocage=0;
							$sql12='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.'"';
							$reponse12=$bdd-> query($sql12) or die('Erreur SQL !<br />'.$sql12.'<br />'.mysql_error());
							while($data12=$reponse12->fetch())
							{
								if($data12['lib_selection']==$data11['lib_selection'])
								{
									$nbr_blocage++;
								}
							}
							if($nbr_blocage==0)
							{
								$blocage=' id="blocage"';
							}
							else
							{
								$blocage='';
							}
							switch($data11['lib_champ'])
							{
								case 'int':
								case 'varchar':
								case 'text':
								?>
								<tr<?php echo $blocage ?>>
                                    <td id="td_right"><?php echo $data11['afficher_selection']; ?></td>
                                    <td><?php echo stripslashes($data[$data11['lib_selection'].'_information']) ?></td>
                                </tr>
                                <?php
								break;
								case 'date':
								?>
								<tr<?php echo $blocage ?>>
                                    <td id="td_right"><?php echo $data11['afficher_selection']; ?></td>
                                    <td><?php echo date("d M Y H:i", strtotime($data[$data11['lib_selection'].'_information'])) ?></td>
                                </tr>
                                <?php
								break;
								case 'select':
								if($data11['select_selection']=='classique')
								{
									?>
									<tr<?php echo $blocage ?>>
										<td id="td_right"><?php echo $data11['afficher_selection']; ?></td>
										<td><?php echo $data[$data11['lib_selection'].'_information']; ?></td>
									</tr>
									<?php
								}
								else
								{
									if($data11['lib_selection']!='categorie')
									{
										$sql2 = 'SELECT * FROM '.$data11['lib_selection'].', information WHERE '.$data11['lib_selection'].'.id_'.$data11['lib_selection'].'=information.id_'.$data11['lib_selection'].' AND id_information='.$id;
									}
									else
									{
										$sql2 = 'SELECT * FROM '.$data11['lib_selection'].', information, typeinfo WHERE typeinfo.id_typeinfo=categorie.id_typeinfo AND '.$data11['lib_selection'].'.id_'.$data11['lib_selection'].'=information.id_'.$data11['lib_selection'].' AND id_information='.$id;
									}
									$reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
									$data2=$reponse2->fetch();
									?>
									<tr<?php echo $blocage ?>>
										<td id="td_right"><?php echo $data11['afficher_selection']; ?></td>
										<td>
											<?php
											if($data11['lib_selection']=='categorie')
											{
												echo '<span>'.$data2['lib_typeinfo'].'</span> / ';
											}
                                            echo $data2['lib_'.$data11['lib_selection'].''];
                                            ?>
                                        </td>
									</tr>
                                    <?php
								}
								break;
								case 'video':
								?>
                                <tr<?php echo $blocage ?>>
                                   <td id="td_right">
                                   <font id="positionimg"> video</font>
                                    <?php
                                    if($data['nvideo_type']>1)
                                    {
                                        ?>
                                        <a href="ajouter-fichier.php?id=<?php echo $id ?>&W9mvyDvFWE5=video&retour=<?php echo $chaiz ?>"><i class="fa fa-plus-square"></i></a>
                                        <?php
                                    }
                                    ?>
                                    </td>
                                    <td>
                                    <?php
                                    $sql2= 'SELECT COUNT(*) FROM video WHERE id_information='.$data[0].'';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    $data2=$reponse2->fetch();
                                    $nbr_image=$data2[0];
                                    
                                    $sql2= 'SELECT * FROM video WHERE id_information='.$data[0].' ORDER BY id_video DESC';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    while($data2=$reponse2->fetch())
                                    {
                                        echo '<div id="video"><iframe width="200" height="100" src="'.$data2['lib_video'].'&amp;controls=0&amp;showinfo=0" frameborder="0" allowfullscreen></iframe></div>';
                                        if($nbr_image>1)
                                        {
                                            echo '
                                            <a href="supprimer-fichier.php?id='.$data2[0].'&W9mvyDvFWE5=video&retour='.$chaiz.'&num='.$id.'">
                                                <img src="img/delete.png" width="18"> 
                                            </a>';
                                        }
                                    }
                                    ?>
                                    </td>
                                </tr>
                                <?php
								break;
								
                                case 'checkbox':
                                ?>
                                <tr<?php echo $blocage ?>>
                                    <td id="td_right"><font id="positionimg"> Equipement</font></td>
                                    <td>
                                    <?php
                                    $sql2= 'SELECT * FROM information_equipement, equipement WHERE information_equipement.id_equipement=equipement.id_equipement AND id_information='.$data[0].' ORDER BY lib_equipement DESC';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    while($data2=$reponse2->fetch())
                                    {
                                        echo stripslashes($data2['lib_equipement']).' - ';
                                    }
                                    ?>
                                    </td>
                                </tr>
                                <?php
                                break;

								case 'image':
								?>
                                <tr<?php echo $blocage ?>>
                                    <td id="td_right">Image
                                        <?php
                                        $sql2= 'SELECT COUNT(*) FROM image WHERE id_information='.$data[0].'';
                                        $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                        $data2=$reponse2->fetch();
                                        $nbr_image=$data2[0];
                                        if(($data['nnombre_type']-$nbr_image)>0)
                                        {
                                            ?>
                                            <a href="ajouter-fichier.php?id=<?php echo $id ?>&W9mvyDvFWE5=image&retour=<?php echo $chaiz ?>"><i class="fa fa-plus-square"></i></a>
                                            <?php
                                        }
                                        ?>
                                    </td>
                                    <td>
                                    <?php
                                    if(isset($_GET['defaut']))
                                    {
                                        $defaut=addslashes(($_GET['defaut']));						
                                        $req='UPDATE image SET defaut_image=0 WHERE id_information="'.$id.'"';
                                        $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                        
                                        $req='UPDATE image SET defaut_image=1 WHERE id_image="'.$defaut.'"';
                                        $reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
                                        ?>
                                        <script type="text/javascript">window.setTimeout("location=('afficher-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $id ?>'#positionimg);",0);</script>
                                        <?php
                                    }
                                    $sql2= 'SELECT * FROM image WHERE id_information='.$data[0].' ORDER BY id_image DESC';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    while($data2=$reponse2->fetch())
                                    {
                                        ?>
                                        <div id="aff_img">
                                            <a href="?defaut=<?php echo $data2[0]?>&W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $id ?>#positionimg">
                                                <?php
                                                if($data2['defaut_image']==1)
                                                {
                                                    ?>
                                                    <i class="fa fa-flag-checkered"></i>
                                                    <?php
                                                }
                                                ?>
                                                <img src="../upload/<?php echo $data2['lib_image'] ?>" width="100">
                                            </a>
                                        </div>
                                        <?php
                                        /*if($data['nnombre_type']>1)
                                        {*/
                                            ?>
                                            <a href="supprimer-fichier.php?id=<?php echo $data2[0] ?>&W9mvyDvFWE5=image&retour=<?php echo $chaiz ?>&num=<?php echo $id ?>">
                                                <img src="img/delete.png" width="18"> 
                                            </a>
                                            <?php
                                        //}
                                    }
                                    ?>
                                    </td>
                                </tr>
                                <?php
								break;

								case 'fichier':
								?>
                                <tr<?php echo $blocage ?>>
                                    <td id="td_right">
                                    Fichier
                                    <?php
                                    $sql2= 'SELECT COUNT(*) FROM fichier WHERE id_information='.$data[0].'';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    $data2=$reponse2->fetch();
                                    $nbr_image=$data2[0];
                                    if(($data['nfichier_type']-$nbr_image)>0)
                                    {
                                        ?>
                                        <a href="ajouter-fichier.php?id=<?php echo $id ?>&W9mvyDvFWE5=fichier&retour=<?php echo $chaiz ?>"><i class="fa fa-plus-square"></i></a>
                                        <?php
                                    }
                                    ?>
                                    </td>
                                    <td>
                                    <?php
                                    $sql2= 'SELECT COUNT(*) FROM fichier WHERE id_information='.$data[0].'';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    $data2=$reponse2->fetch();
                                    $nbr_image=$data2[0];
                                    
                                    $sql2= 'SELECT * FROM fichier WHERE id_information='.$data[0].' ORDER BY id_fichier DESC';
                                    $reponse2=$bdd-> query($sql2) or die('Erreur SQL !<br />'.$sql2.'<br />'.mysql_error());
                                    while($data2=$reponse2->fetch())
                                    {
                                        echo '<a href="../upload/'.$data2['lib_fichier'].'" target="_blank"><i class="fa fa-film fa-2x"></i></a>';
                                        if($nbr_image>1)
                                        {
                                            echo '
                                            <a href="supprimer-fichier.php?id='.$data2[0].'&W9mvyDvFWE5=fichier&retour='.$chaiz.'&num='.$id.'">
                                                <img src="img/delete.png" width="18"> 
                                            </a>';
                                        }
                                    }
                                    ?>
                                    </td>
                                </tr>
                                <?php
								break;
							}
						}
						?>
                        <tr<?php echo $blocage ?>>
                        	<td id="td_right">Nombre de vue</td>
                            <td>
								<?php echo $data['vue_information'] ?>
                            </td>
                        </tr>
						
                        <tr<?php echo $blocage ?>>
                        	<td id="td_right">Visible</td>
                            <td id="positionimg">
								<?php
                                if($data['visible_information']=='oui')
								{
									echo '<a href="?num='.$data[0].'&disponibilite=non&W9mvyDvFWE5='.$chaiz.'&QYtgoGbhhd='.$id.'"><img src="img/valid.png" width="20"></a>';
								}
								else
								{
									echo '<a href="?num='.$data[0].'&disponibilite=oui&W9mvyDvFWE5='.$chaiz.'&QYtgoGbhhd='.$id.'"><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=('afficher-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>&QYtgoGbhhd=<?php echo $id ?>#positionimg');",0);</script>
									<?php
								}
								?>
                            </td>
                        </tr>
                        <tr>
                            <td id="td_right">Date de création</td>
                            <td>
                                <?php 
                                echo date("d M Y H:i", strtotime($data['creation_information']));
                                $sql3= 'SELECT * FROM user, information WHERE information.id_creation_user=user.id_user AND id_information='.$id;
                                $reponse3=$bdd->query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
                                $data3=$reponse3->fetch();
                                echo ' Par <a href="afficher-info.php?W9mvyDvFWE5=user&QYtgoGbhhd='.$data3[0].'"><span id="span_user">'.$data3['lib_user'].'</span></a>';
                                ?>
                            </td>
                        </tr>
                        <tr>
                            <td id="td_right">
                                Dates de modification
                                <?php
                                $sql3='SELECT COUNT(*) FROM modificateur WHERE id_information='.$id;
                                $reponse3=$bdd->query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
                                $data3=$reponse3->fetch();
                                echo '('.$data3[0].')';
                                ?>
                            </td>
                            <td>
                                <table class="table table-bordered">
                                <?php
                                $sql3='SELECT * FROM user, modificateur, information WHERE information.id_information=modificateur.id_information AND user.id_user=modificateur.id_modif_user AND information.id_information='.$id;
                                $reponse3=$bdd->query($sql3) or die('Erreur SQL !<br />'.$sql3.'<br />'.mysql_error());
                                while($data3=$reponse3->fetch())
                                {
                                    echo '<tr><td id="span_user"><a href="afficher-info.php?W9mvyDvFWE5=user&QYtgoGbhhd='.$data3[0].'">'.$data3['lib_user'].'</a></td><td>'.date("d M Y H:i:s", strtotime($data3['date_modificateur'])).'</td></tr>';
                                }
                                ?>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2" align="center">
                                <a class="btn btn-default" href="gestionnaire-table.php?W9mvyDvFWE5=<?php echo $chaiz ?>"><i class="fa fa-reply"></i> Retour</a>
                            </td>
                        </tr>
                      </table>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

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