<?php
if($user_rg == 0 || $user_rg == '0'){
	echo "<div align='center'><h3>Vous n'avez le statut nécéssaire pour venir ici</h3></div>";
	exit;
}

if(isset($_POST['nombre_action'])){
	$limite_log=$_POST['nombre_action'];	
}else{
	$limite_log='25';
}
echo "<div align=\"center\"><h3>Logs des Modérateurs</h3>
<br/><br/>
<form action=\"\" method=\"post\">
	Nombre de message par page : <select name=\"nombre_action\" onchange=\"this.form.submit()\">
		<option value=\"25\" "; echo $limite_log=='25' ? "selected" : "" ;echo ">25</option>
		<option value=\"50\" "; echo $limite_log=='50' ? "selected" : "" ;echo ">50</option>
		<option value=\"100\" "; echo $limite_log=='100' ? "selected" : "" ;echo ">100</option>
		</select>
	</form>
</div><br/>";
if(isset($_GET['page'])){
	$page=$_GET['page'];
	$limit = (($limite_log*$page)-1) .",". (($limite_log*($page+'1'))-1);
}else{
	$page=0;
	$limit = "0,". ($limite_log-1);
}

echo "<table align=\"center\" border=\"1\">
	<tr align='center'>
		<td>Modérateur</td>
		<td>Date</td>
		<td>Action</td>
	</tr>";
$count_query="SELECT COUNT(id) FROM matgraph_logadmin";
$count_sql=db_mysql_Query($count_query);
$count=mysql_fetch_array($count_sql);
$query="SELECT * FROM matgraph_logadmin LIMIT ".$limit;
$sql=db_mysql_Query($query);
while($row = mysql_fetch_array($sql)){
	echo "<tr>
		<td>".$row['mdj']."</td>
		<td>".$row['date']."</td>
		<td>".$row['action']."</td>
	</tr>";
}
echo "</table><br/>";
$count=$count[0];
        if ($page > 1){
            $end2 = $page - 1;
            echo "<a href=\"index.php?action=log_modo&amp;page=" . $end2 . "\">&lt;</a>&nbsp;";
        } 

        $nb_page = intval($count / $limite_log);
        $nb_page2 = $count % $limite_log;
        if ($nb_page2 > 0) $nb_page++;
        $i = 1;

        while ($i <= $nb_page && $nb_page <> 1){
            if (($i == ($page-1)) || ($i == $page) || ($i == ($page + 1)) || ($i == 1) || ($i == 2) || ($i == 3) || ($i == $nb_page) || ($i == ($nb_page-1)) || ($i == ($nb_page-2)))
            {
                if ((($page + 1) <= ($nb_page - 4)) && ($i == ($nb_page - 2)) && $nb_page != 6)echo "...&nbsp;";
                if ($i <> $page){
                    echo "<a href=\"index.php?action=log_modo&amp;page=" . $i . "\">" . $i . "</a>";
                }else{
                    echo "<b>[" . $i . "]</b>";
                } 
                if ($nb_page != $i){
                    echo"&nbsp;";
                } 
                if ((($page - 1) >= 5) && ($i == 3) && $nb_page != 6){
                    echo "...&nbsp;";
                } 
            } 
            $i++;
        } 
        $end = $start + $limite_log;
        if (($count > $end) && $page < $nb_page){
            $end = $page + 1;
            echo"&nbsp;<a href=\"index.php?action=log_modo&amp;page=" . $end . "\">&gt;</a>";
        } 
        echo "<br />";
?>