<?php
session_start();
include('../connexion.php');
if (!isset($_SESSION['celest']))
{
	header ('Location: administration.php');
}
if (isset($_GET['W9mvyDvFWE5']))
{
	$chaiz=addslashes($_GET['W9mvyDvFWE5']);
	$active=$chaiz;
	
	$sql='SELECT * FROM type WHERE lib_type="'.$chaiz.'"';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$id_table=$data['id_type'];
	
	$sql='SELECT COUNT(*) FROM information WHERE id_type="'.$id_table.'"';
	$reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
	$data=$reponse->fetch();
	$nombre_entrep=$data[0];
	include('tete.php');
	?>
	<link rel="stylesheet" type="text/css" href="style/style_admin.css" />
</head>
<body>
    <div id="wrapper">
    	<?php
        include('menu_admin.php');
		if($developpeur==3)
		{
			header('Location: gestionnaire-table.php?W9mvyDvFWE5=Actualité');
		}
		?>
        <div id="page-wrapper">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" id="administration">
                    <div id="titro_admin">
                    	Classement <?php echo $chaiz; ?>
                    </div>
                    <?php
                    if (isset($_POST['valider']))
                    {
						$i=0;
						for ($n=1; $n<=$nombre_entrep; $n++)
						{
							$entreprise=(addslashes($_POST['entreprise'.$n.'']));
							$numero=(addslashes($_POST['numero'.$n.'']));
							if(is_numeric($entreprise))
							{
								$i++;
								$req='UPDATE information SET rang_information="'.$entreprise.'" WHERE id_information='.$numero.'';
								$reponse=$bdd-> query($req) or die('Erreur SQL !<br />'.$req.'<br />'.mysql_error());
							}
						}
						echo '<div class="alert alert-success">Classement modifié avec succès avec '.$i.' occurence(s)</div>';
						?> 
						<script type="text/javascript">
                        window.setTimeout("location=('classement.php?W9mvyDvFWE5=<?php echo $chaiz; ?>');",2500);
                        </script>
                        <?php
					}
					?>
                    <form action="" method="post">
                        <table width="100%" class="table table-hover" id="tableau">
                            <tr>
							<?php
                            $i=0;
							$z=0;
                            $sql='SELECT * FROM information WHERE id_type='.$id_table.' ORDER BY id_information DESC';
                            $reponse=$bdd-> query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());
                            while ($data=$reponse->fetch())
                            {
								$z++;
                                $i++;
                                ?>
                                <td id="td_right"><?php echo $data['lib_information'] ?>:</td>
                                <td>
                                    <input type="text" class="form-control" name="entreprise<?php echo $i ?>" style="width:60px;" value="<?php echo $data['rang_information'] ?>">
                                    <input type="text" name="numero<?php echo $i ?>" value="<?php echo $data[0] ?>" style="display:none;">
                                </td>
                                <?php
								if($z==3)
								{
									echo '</tr><tr>';
									$z=0;
								}
                            }
                            ?>
                            </tr>
                        </table>
                        
                        <div align="center" colspan="2">
                            <input type="submit" class="btn btn-primary" value="Valider" name="valider">
                            <a class="btn btn-default" href="gestionnaire-table.php?W9mvyDvFWE5=<?php echo $chaiz; ?>"><i class="fa fa-reply"></i> Retour</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<?php 
}
else
{
	header('Location: index.php');
}
?>