<?php
    session_start();
    
      $connection=mysqli_connect("localhost","root","","bghbconsulting");

      if (isset($_POST['Inserer'])) {

      $Domaine=$_POST['Domaine'];
      $Titre=$_POST['Titre'];
      $P1=$_POST['Prgf1'];
      $P2=$_POST['Prgf2'];
      $P3=$_POST['Prgf3'];
      $P4=$_POST['Prgf4'];
      $P5=$_POST['Prgf5'];
      $P6=$_POST['Prgf6'];
      $Image=$_FILES['Image']['name'];

      if (file_exists("images/".$_FILES['Image']['name'])) 
      {
        $_Nom_image=$_FILES['Image']['name'];
        $_SESSION['statu']= "Echec d'insertion!!! L'image :".$_Nom_image."  existe déjà. Veuillez charger une autre image";
      }
      else
      {
        $sql="INSERT INTO activitebghb(DomaineAct,TitreAct,Paragraphe1Act,Paragraphe2Act,Paragraphe3Act,Paragraphe4Act,Paragraphe5Act,Paragraphe6Act,imageAct) VALUES ('$Domaine','$Titre','$P1','$P2','$P3','$P4','$P5','$P6','$Image')";
        $sql_run=mysqli_query($connection,$sql);

        if ($sql_run) 
        {
          move_uploaded_file($_FILES["Image"]["tmp_name"],"images/".$_FILES['Image']['name']);
          $_SESSION['status']="Articles inséré avec succès";
          //header('location: index.php');
        }
        else
        {
          $_SESSION['statu']="Echec d'insertion de l'article";
          //header('location: index.php');
        }
      }

      
 }

 if (isset($_POST['supprimer'])) 
 {
   $id=$_POST['id'];
   $image=$_POST['image'];

   $Supprimer_query="DELETE FROM activitebghb WHERE activitebghb.IdAct='$id'";
   $Supprimer_query_run=mysqli_query($connection,$Supprimer_query);

   if ($Supprimer_query_run) 
   {
    unlink("images/".$image);
     $_SESSION['status']="Article SUPPRIMER avec succès";
   }
   else
   {
    $_SESSION['statu']="ECHEC de SUPPRESSION de l'article";
   }

 }

 /* $file_basename= pathinfo($_FILES["Image"]["name"], PATHINFO_FILENAME);
      $file_extension= pathinfo($_FILES["Image"]["name"], PATHINFO_EXTENSION);
      $nouvelle_image= $file_basename.'_'.date("Ymd_His").'.'.$file_extension;


      $connection=mysqli_connect("localhost","root","","bghbconsulting");

      if ($connection->error) {
        die("La connexion à la base de donnée a échoué :" . $connection->connect_error);
      }

      $nouvelle_image=$connection->real_escape_string($nouvelle_image);

        
      
        $sql="INSERT INTO activitebghb(DomaineAct,TitreAct,Paragraphe1Act,Paragraphe2Act,Paragraphe3Act,Paragraphe4Act,Paragraphe5Act,Paragraphe6Act,imageAct) VALUES ('$Domaine','$Titre','$P1','$P2','$P3','$P4','$P5','$P6','$nouvelle_image')";

        if ($connection->query($sql) === TRUE) {
          $target_directory="images/";
          $target_path=$target_directory . $nouvelle_image;
          if (!move_uploaded_file($_FILES["Image"]["tmp_name"], $target_path)) {
            header("location:index.php?message=er");
          }
          header("lacation:index.php?message=ok");
          
        }else{
          header("lacation:index.php?message=ok");
        }

      }

      

        $connection->close();

    

    

*/

 ?>
      

   


<!DOCTYPE html>
<html>
<head>
  <title>Accueil Admin</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="format-detection" content="telephone=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="author" content="">
  <meta name="keywords" content="">
  <meta name="description" content="">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-sRIl4kxILFvY47J16cr9ZwB07vP4J8+LH7qKQnuqkuIAvNWLzeN8tE5YBujZqJLB" crossorigin="anonymous">
  <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  <link rel="stylesheet" type="text/css" href="style.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css" />
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700;800;900&display=swap"
    rel="stylesheet">

  <!-- script
    ================================================== -->
  <script src="js/modernizr.js"></script>
</head>

<body data-bs-spy="scroll" data-bs-target="#header-nav" tabindex="0">
 
  <header id="header">
    <nav class="header-top pt-4 pb-5" style="background-color: aliceblue;">
      <div class="container">
        <div class="row justify-content-between align-items-center">
          <div class="col-lg-5 col-md-4 col-sm-6">
            <a class="navbar-brand" href="index.html">
              <img src="images/bghblogo.png" class="logo" width="200" height="80">
            </a>
          </div>
          <div class="col-lg-4 col-md-4 d-md-block d-sm-none">
            <h2>PAGE ADMIN BGHB</h2>
          </div>
          <div class="col-lg-3 col-md-4 col-sm-6">
            <div class="btn-book text-end">
              <a href="ContactezNous.html" class="btn btn-medium btn-outline-primary btn-pill text-uppercase">Admin</a>
            </div>
          </div>
        </div>
      </div>
    </nav>

    <nav id="primary-header" nav class="navbar navbar-expand-lg shadow-none" aria-label="navbar" height="30">
      <div class="container">
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar-primary"
          aria-controls="navbar-primary" aria-expanded="false" aria-label="Toggle navigation">
          <svg class="navbar-icon mt-3 primary-color-500 bg-light" width="50" height="50">
            <use xlink:href="#navbar-icon"></use>
          </svg>
        </button>
        <div class="header-bottom collapse navbar-collapse bg-light border-radius-10 py-2" id="navbar-primary">
          <ul class="navbar-nav me-auto mb-2 mb-lg-0">
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark active p-0 mt-3 mt-lg-0" aria-current="page" href="#intro">Accueil</a>
            </li>
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark p-0" href="AproposdeNous.html">A propos de nous</a>
            </li>
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark p-0" href="NosService.html">Nos services</a>
            </li>
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark p-0" href="NosActivite.html">Nos activités</a>
            </li>
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark p-0" href="NotreEquipe.html">Notre Equipe</a>
            </li>
            <li class="nav-item ps-4 pe-4 border-right">
              <a class="nav-link text-dark p-0" href="ContactezNous.html">Contactez-nous</a>
            </li>

            
          </ul>
        </div>
      </div>
    </nav>
  </header>


  


  <!-- iNSERT MODEL <div class="modal-dialog modal-lg">...</div> -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h1 class="modal-title fs-5" id="exampleModalLabel">VEUILLEZ ENTRER VOS DONNEES</h1>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
    <form action="" method="POST" enctype="multipart/form-data">
      <div class="modal-body">
        <div class="form.group mb-2 mt-3">
          <label for="">Domaine</label><br>
          <input type="text" name="Domaine" class="form form-control" placeholder="domaine activité">    
        </div>

        <div class="form.group mb-2">
          <label for="">Titre</label><br>
          <input type="text" name="Titre" class="form form-control" placeholder="Grand titre">    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 1</label><br>
          <textarea name="Prgf1" class="form form-control" placeholder="Premier paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 2</label><br>
          <textarea name="Prgf2" class="form form-control" placeholder="Deuxième paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 3</label><br>
          <textarea name="Prgf3" class="form form-control" placeholder="Troisième paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 4</label><br>
          <textarea name="Prgf4" class="form form-control" placeholder="Quatrième paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 5</label><br>
          <textarea name="Prgf5" class="form form-control" placeholder="Cinquième paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Paragraphe 6</label><br>
          <textarea name="Prgf6" class="form form-control" placeholder="Sixième paragraphe"></textarea>    
        </div>

        <div class="form.group mb-2">
          <label for="">Image</label><br>
          <input type="file" name="Image" class="form form-control" accept="image/">    
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">FERMER</button>
        <button type="submit" name="Inserer" class="btn btn-primary">INSERER</button>
      </div>
    </form>
    </div>
  </div>
</div>

  <div class="container mt-4">
    <div class="row justify-content-center">
      <div class="col-md-10">
        <div class="card">
        <?php

        if (isset($_SESSION['status']) && $_SESSION !='') 
        {
          
          ?>
          <div class="alert alert-success alert-dismissible fade show" role ="alert">
            <strong>Info: </strong><?php echo $_SESSION['status']; ?>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>

          <?php
          unset($_SESSION['status']);
        }

        ?>
        <?php

        if (isset($_SESSION['statu']) && $_SESSION !='') 
        {
          
          ?>
          <div class="alert alert-danger alert-dismissible fade show" role ="alert">
            <strong>Info: </strong><?php echo $_SESSION['statu']; ?>
            <button type="button" class="btn-close" data_bs_dismiss="alert" arial-lable="close"></button>
          </div>

          <?php
          unset($_SESSION['statu']);
        }

        ?>

          <div class="card header">
            <h4>PAGE DE GESTION D'ARTICLES (ACTIVITES)</h4>
            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
              INSERER ARTICLE
            </button>  
          </div>
          <div class="card.body">
            <table class="table table-striped table-bodered table-light table-wraped" style="border: 2px solid;">
              <thead>
                <tr>
                  <th scope="col">Id Art</th>
                  <th scope="col">Domaine</th>
                  <th scope="col">Titre</th>
                  <th scope="col">Image</th>
                  <th scope="col">Afficher</th>
                  <th scope="col">Modifier</th>
                  <th scope="col">Supprimer</th>
                </tr>
              </thead>
              <tbody>


                <?php

                  $connection=mysqli_connect("localhost","root","","bghbconsulting");
                  $fetch_query="SELECT * FROM activitebghb";
                  $fetch_query_run=mysqli_query($connection, $fetch_query);

                  if (mysqli_num_rows($fetch_query_run,) > 0) 
                    {
                    
                    while ($row = mysqli_fetch_array($fetch_query_run)) 
                    {
                      ?>
                        <tr>
                          <td><?php echo $row["IdAct"]; ?></td>
                          <td><?php echo $row["DomaineAct"]; ?></td>
                          <td><?php echo $row["TitreAct"]; ?></td>
                          <td>
                            <img src="<?php echo "images/".$row["imageAct"];?>" width="40" height="50" alt="Image" >
                          </td>
                          <td>
                            <a href="" class="btn btn-info btn-sm">Afficher</a>
                          </td>
                          <td>
                            <a href="" class="btn btn-success btn-sm">Modifier</a>
                          </td>
                          <td>
                            <form action="index.php" method="POST">
                              <input type="hidden" name="id" value="<?php echo $row["IdAct"]; ?>">
                              <input type="hidden" name="image" value="<?php echo $row["imageAct"];?>">
                              <button type="submit" name="supprimer" class="btn btn-danger btn-sm">Supprimer</button>
                            </form>
                            
                          </td>
                        </tr>


                      <?php

                    }

                  }
                  else
                  {
                    ?>

                    <?php

                  }


                ?>

                
              </tbody>  
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
   
  <script src="js/jquery-1.11.0.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.js"></script>
  <script type="text/javascript" src="js/bootstrap.bundle.min.js"></script>
  <script type="text/javascript" src="js/plugins.js"></script>
  <script type="text/javascript" src="js/script.js"></script>
  <script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js" integrity="sha384-FKyoEForCGlyvwx9Hj09JcYn3nv7wiPVlz7YYwJrWVcXK/BmnVDxM+D2scQbITxI" crossorigin="anonymous"></script>
</body>

</html>