<?php session_start(); 
    if (!isset($_SESSION['profil'])) {
        header('Location: ../index.php');
    }
?>
<?php
require_once('../refactoring.php');
//pagination
//number de pages
$perPage = 5;
//fin 
$nombreTotal = pagination();
//numero de page
$noPage=1;
//fin
$pages = ceil($nombreTotal/$perPage);
if (isset($_GET['page'])) {
  $noPage = $_GET['page'];
}

// appele de fonction depuis le fichier refactoring.php pour la récuperation de tous les articles de ma BD
$posts = selectAll($noPage,$perPage);

?>
<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <!-- Custom Styling -->
        <link rel="stylesheet" href="../css/style.css">
        <!-- Admin Styling -->
        <link rel="stylesheet" href="../css/admin.css">
        <title>Section Admin - Gestions des articles</title>
    </head>
    <body>
     <!-- Debut header -->
     <header>
        <div class="logo">
            <h1 class="logo-text"><span>Blog</span>The News</h1>
        </div>
        <ul class="nav">
            <li><a href="deconnexion.php">Deconnexion</a></li>
        </ul>
    </header>
     <!-- Fin header -->
        <!-- Admin Page Wrapper -->
        <div class="admin-container">
            <!-- Admin Content -->
            <div class="admin-content">
                <div class="button-group">
                    <a href="create.php " class="btn btn-big">Ajouter un article</a>
                    <a href="index.php" class="btn btn-big">Gérer des articles</a>
                </div>
                <div class="container">
                    <h2 class="page-title">Gestion des articles</h2>
                    <table>
                        <thead>
                            <th>SN</th>
                            <th>TITRE</th>
                            <th>AUTEUR</th>
                        </thead>
                        <tbody>
                        <!-- debut effecutier les informations sur la page admin -->
                        <?php foreach($posts as $key=>$post):?>
                            <tr>
                                <td><?= $key+1;?></td>
                                <td><?=$post['title'];?></td>
                                <td><?=$post['author'];?></td>
                            </tr>
                        <?php endforeach; ?>
                        <!--fin-->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        
      <!-- Debut pagination -->
      <div class="pagination">
          <?php
            for ($i=1; $i<=$pages ; $i++) {             
          ?> 
          <a href="index.php?page=<?=$i;?>" class="page <?=($noPage == $i)?'active':''?>"><?= $i ;?></a>
          <?php
            }
          ?>
        </div>
  <!-- Fin pagination -->

    <!-- Debut footer -->
       <?php include('../inc/footer.php') ?>
     <!-- Fin footer -->
    </body>
</html>