<commit_before><?php
// ****************************************SUPPRIMER********************************************
$db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');
if(isset($_POST['delete'])){

  $sql = 'SELECT * FROM document';
  $result = $db->prepare($sql);
  $result->execute();
  $count = $result->rowCount($result);
  for($i=0;$i<$count;$i++)
  {

    $del_id = $_POST['checkbox'][$i];
    $sql = "DELETE FROM document WHERE id_doc = '$del_id' ";
    $result = $db->prepare($sql);
    $result->execute();

  }
  $fichier=$_POST['nom_fichier'];
  $dossier_traite = "bibliotheque";
  $repertoire = opendir($dossier_traite);
  while (false !== ($fichier = readdir($repertoire)))
  {
    $chemin = $dossier_traite."/".$fichier;
    // Si le fichier n'est pas un répertoire…
    if ($fichier != ".." AND $fichier != "." AND !is_dir($fichier))
    {if($fichier =basename($fichier,".pdf").PHP_EOL)
      {unlink($chemin);
      }
    }
  }
  closedir($repertoire);
  if($result){
    header('location:mes_documents.php');}
  }
  $sql = 'SELECT *  FROM document';
  $query = $db->prepare($sql);
  $query->execute();

  // ****************************************END SUPPRIMER********************************************
  ?>
    <?PHP
    include 'includes/header.php';
    include 'includes/side_bar.php';
    //*********************************** CREATION *******************************************************************
    if (isset($_POST['creer'])){
      $titre =$_POST['titre'];
      $projet =$_POST['projet'];
      $file_name=$_FILES['pdfDoc']['name'];
      $file_tmp = $_FILES['pdfDoc']['tmp_name'];
      $desc=$_POST['description'];

      if(!move_uploaded_file($file_tmp,"bibliotheque/".$file_name)){
        echo 'error';
      }

      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');
      if($titre!= "" && $desc !="" && $file_name != ""){
        $sql = 'INSERT INTO document VALUES (NULL,'.$projet.',"'.$titre.'","'.$_SESSION['username'].'",CURRENT_TIMESTAMP,"'.$desc.'","'.$file_name.'")';
        $query = $db->prepare($sql);
        $query->execute();


      } else
      {
        echo "error";
      }}


      ?>
      <?php
      //**************************************************modifier**********************************************************
      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');


      // Teste de l'envoie du fichier

      if (isset($_POST['modifier']))
      {
        $titre =$_POST['titred'];
        $desc= $_POST['descd'];


            $query = $db->prepare('UPDATE document
              SET titre = "'.$titre.'",
              description = "'.$desc.'"
              WHERE id_doc = '.$_POST['hiddenid']);
              $query->execute();


        }
        ?>

      <?php

      $user_session=$_SESSION["id_user"];
      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');

      if(isset($_GET['filtre'])){
        if($_GET['filtre'] == '1'){
          $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
          where d.id_projet=p.id_projet';
        }else{
          $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
          where d.id_projet=p.id_projet
          and
          proprietaire= (SELECT username from user
            where id_user='.$user_session.')';
        }
      }else{
        $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
        where d.id_projet=p.id_projet';
      }

        $query = $db->prepare($sql);
        $query->execute();
        ?>
        <div id="page-wrapper">
          <div class="row">
            <div class="col-md-12">
              <h1 class="page-header">Mes documents</h1>
              <button class="btn btn-primary col-md-2" data-toggle="modal" data-target="#ajoutDocument"><i class="fa fa-plus-circle"></i> Nouveau document</button>
              <div class="col-md-10">
                <form class="form-inline">
                  <div class="form-group pull-right">
                    <label for="filtre">Filtre par : </label>
                      <select id="filtre" class="form-control" onchange="reload();">
                        <option value="<?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? '1' : '2'; else echo '1'; ?>"><?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? 'Tous les documents' : 'Mes documents'; else echo 'Tous les documents'; ?></option>
                        <option value="<?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? '2' : '1'; else echo '1'; ?>"><?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? 'Mes documents' : 'Tous les documents'; else echo 'Mes documents'; ?> </option>
                      </select>
                  </div>
                </form>
              </div>
            </div>
            <!-- /.col-lg-12 -->
          </div>
          <br>
          <div class="row">
            <div class="col-lg-12">
              <div class="panel panel-default">
                <form class="form-horizontal" role="form" form method="post" action="mes_documents.php" enctype="multipart/form-data">

                  <div class="panel-body">
                    <div class="dataTable_wrapper">

                      <table class="table table-striped table-bordered table-hover" id="dataTables-example">

                        <thead>
                          <tr>
                            <th>#</th>
                            <th>titre du document</th>
                            <th>Projet concerné</th>
                            <th>date de création</th><commit_msg>small fix<commit_after><?php
// ****************************************SUPPRIMER********************************************
$db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');
if(isset($_POST['delete'])){

  $sql = 'SELECT * FROM document';
  $result = $db->prepare($sql);
  $result->execute();
  $count = $result->rowCount($result);
  for($i=0;$i<$count;$i++)
  {

    $del_id = $_POST['checkbox'][$i];
    $sql = "DELETE FROM document WHERE id_doc = '$del_id' ";
    $result = $db->prepare($sql);
    $result->execute();

  }
  $fichier=$_POST['nom_fichier'];
  $dossier_traite = "bibliotheque";
  $repertoire = opendir($dossier_traite);
  while (false !== ($fichier = readdir($repertoire)))
  {
    $chemin = $dossier_traite."/".$fichier;
    // Si le fichier n'est pas un répertoire…
    if ($fichier != ".." AND $fichier != "." AND !is_dir($fichier))
    {if($fichier =basename($fichier,".pdf").PHP_EOL)
      {unlink($chemin);
      }
    }
  }
  closedir($repertoire);
  if($result){
    header('location:mes_documents.php');}
  }
  $sql = 'SELECT *  FROM document';
  $query = $db->prepare($sql);
  $query->execute();

  // ****************************************END SUPPRIMER********************************************
  ?>
    <?PHP
    include 'includes/header.php';
    include 'includes/side_bar.php';
    //*********************************** CREATION *******************************************************************
    if (isset($_POST['creer'])){
      $titre =$_POST['titre'];
      $projet =$_POST['projet'];
      $file_name=$_FILES['pdfDoc']['name'];
      $file_tmp = $_FILES['pdfDoc']['tmp_name'];
      $desc=$_POST['description'];

      if(!move_uploaded_file($file_tmp,"bibliotheque/".$file_name)){
        echo 'error';
      }

      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');
      if($titre!= "" && $desc !="" && $file_name != ""){
        $sql = 'INSERT INTO document VALUES (NULL,'.$projet.',"'.$titre.'","'.$_SESSION['username'].'",CURRENT_TIMESTAMP,"'.$desc.'","'.$file_name.'")';
        $query = $db->prepare($sql);
        $query->execute();


      } else
      {
        echo "error";
      }}


      ?>
      <?php
      //**************************************************modifier**********************************************************
      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');


      // Teste de l'envoie du fichier

      if (isset($_POST['modifier']))
      {
        $titre =$_POST['titred'];
        $desc= $_POST['descd'];


            $query = $db->prepare('UPDATE document
              SET titre = "'.$titre.'",
              description = "'.$desc.'"
              WHERE id_doc = '.$_POST['hiddenid']);
              $query->execute();


        }
        ?>

      <?php

      $user_session=$_SESSION["id_user"];
      $db = new PDO('mysql:host=localhost;dbname=mgp_data;charset=utf8', 'root', '');

      if(isset($_GET['filtre'])){
        if($_GET['filtre'] == '1'){
          $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
          where d.id_projet=p.id_projet';
        }else{
          $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
          where d.id_projet=p.id_projet
          and
          proprietaire= (SELECT username from user
            where id_user='.$user_session.')';
        }
      }else{
        $sql = 'SELECT d.*,p.titre as nom_projet,p.id_projet from document d,projet p
        where d.id_projet=p.id_projet';
      }

        $query = $db->prepare($sql);
        $query->execute();
        ?>
        <div id="page-wrapper">
          <div class="row">
            <div class="col-md-12">
              <h1 class="page-header">Mes documents</h1>
              <button class="btn btn-primary col-md-2" data-toggle="modal" data-target="#ajoutDocument"><i class="fa fa-plus-circle"></i> Nouveau document</button>
              <div class="col-md-10">
                <form class="form-inline">
                  <div class="form-group pull-right">
                    <label for="filtre">Filtre par : </label>
                      <select id="filtre" class="form-control" onchange="reload();">
                        <option value="<?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? '1' : '2'; else echo '1'; ?>"><?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? 'Tous les documents' : 'Mes documents'; else echo 'Tous les documents'; ?></option>
                        <option value="<?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? '2' : '1'; else echo '2'; ?>"><?php if(isset($_GET['filtre'])) echo ($_GET['filtre'] == '1') ? 'Mes documents' : 'Tous les documents'; else echo 'Mes documents'; ?> </option>
                      </select>
                  </div>
                </form>
              </div>
            </div>
            <!-- /.col-lg-12 -->
          </div>
          <br>
          <div class="row">
            <div class="col-lg-12">
              <div class="panel panel-default">
                <form class="form-horizontal" role="form" form method="post" action="mes_documents.php" enctype="multipart/form-data">

                  <div class="panel-body">
                    <div class="dataTable_wrapper">

                      <table class="table table-striped table-bordered table-hover" id="dataTables-example">

                        <thead>
                          <tr>
                            <th>#</th>
                            <th>titre du document</th>
                            <th>Projet concerné</th>
                            <th>date de création</th>
{'fraction_non_alphanumeric': 0.2476439790575916, 'fraction_numerical': 0.004712041884816754, 'mean_word_length': 2.4069560047562426, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6789100', 'n_tokens_mistral': 3635, 'n_tokens_neox': 3548, 'n_words': 640}