From de3ece98a69da282a13349ea4395730ae15c434f Mon Sep 17 00:00:00 2001
From: nicrausaz <n.crausaz99@gmail.com>
Date: Tue, 5 Mar 2019 09:01:11 +0100
Subject: [PATCH] check post, filiere info ok

---
 canapEPFL/form.php                            | 12 ++---
 canapEPFL/helpers.php                         | 44 ++++++++++---------
 .../templates/formParts/edit/annexes.php      | 13 ++++++
 .../formParts/edit/filieresinfos.php          | 20 +++++++++
 .../templates/formParts/edit/maturity.php     |  5 ++-
 .../{ => formParts/new}/filieresinfos.php     |  6 +--
 .../templates/formParts/new/maturity.php      |  4 +-
 7 files changed, 71 insertions(+), 33 deletions(-)
 create mode 100644 canapEPFL/templates/formParts/edit/filieresinfos.php
 rename canapEPFL/templates/{ => formParts/new}/filieresinfos.php (71%)

diff --git a/canapEPFL/form.php b/canapEPFL/form.php
index 7cedc17..7180345 100644
--- a/canapEPFL/form.php
+++ b/canapEPFL/form.php
@@ -21,12 +21,14 @@
     <body>
     <?php
       include('templates/header.php');
+      require_once("helpers.php");
       if (isset($_GET['edit'])) {
-        // checker si y a pas de postulation selectionnée (session)
-        require_once("helpers.php");
-        echo "editing applicant" . $_SESSION['current_post']['applicant_id'];
-        $current_post = $_SESSION['current_post'];
-        echo $current_post['applicant_guest_sciper'];
+        // Check si une postulation a été selectionnée
+        if (!isset($_SESSION['current_post']['applicant_id'])) {
+          header('Location: index.php');
+        } else {
+          $current_post = $_SESSION['current_post'];
+        }
       }
     ?>
     <main id="main" role="main" class="content container-grid">
diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php
index 93515cd..61e30e8 100644
--- a/canapEPFL/helpers.php
+++ b/canapEPFL/helpers.php
@@ -316,11 +316,9 @@ function deletePostulation ($pdo, $id, $sciper, $rep1, $rep2) {
   header('Location: viewpostulation.php');
 }
 
-function updatePostulation ($pdo, $posted_data, $posted_files) {
-
-  // echo "<pre>";
-  // print_r($posted_data);
+function updatePostulation ($pdo, $posted_data) {
 
+  $posted_files = $posted_data->fichiers;
   // update applicant infos
 
   $sqlreq = "UPDATE applicant
@@ -460,25 +458,29 @@ foreach ($posted_data->stages as $training) {
   $query->execute();
 }
 
-die;
-
+echo "<pre>";
 // TODO: files
-  print_r($posted_files);
-  $i = 1;
-  while (isset($posted_data['file_id'.$i])) {
-    // remplace le fichier sur le serveur
-    if ($_FILES['file'.$i]['name']) {
-      $file_data = getOneFile($pdo, $posted_data['file_id'.$i], $id);
-      if (move_uploaded_file($_FILES['file'.$i]['tmp_name'], $file_data['file_path'])) {
-
-      } else {
-        // Le fichier est ouvert
-        $_SESSION['edit_error']['files'] = "Erreur lors du remplacement du fichier" . $_FILES['file'.$i]['name'] . ", réessayez plus tard.";
-      }
-    }
-    $i++;
+
+foreach ($posted_files as $key => $file) {
+  if ($file['name'] != '') {
+    print_r($file);
   }
-  // header('Location: viewpostulation.php');
+}
+// $i = 1;
+// while (isset($posted_data['file_id'.$i])) {
+//   // remplace le fichier sur le serveur
+//   if ($_FILES['file'.$i]['name']) {
+//     $file_data = getOneFile($pdo, $posted_data['file_id'.$i], $id);
+//     if (move_uploaded_file($_FILES['file'.$i]['tmp_name'], $file_data['file_path'])) {
+      
+//     } else {
+//       // Le fichier est ouvert
+//       $_SESSION['edit_error']['files'] = "Erreur lors du remplacement du fichier" . $_FILES['file'.$i]['name'] . ", réessayez plus tard.";
+//     }
+//   }
+//   $i++;
+// }
+// header('Location: viewpostulation.php');
 }
 #endregion
 ?>
\ No newline at end of file
diff --git a/canapEPFL/templates/formParts/edit/annexes.php b/canapEPFL/templates/formParts/edit/annexes.php
index d6af62c..2d60fee 100644
--- a/canapEPFL/templates/formParts/edit/annexes.php
+++ b/canapEPFL/templates/formParts/edit/annexes.php
@@ -9,6 +9,19 @@
 <small>Formats autorisés: <b>PDF, JPG, JPEG, PNG</b></small>
 <!-- Annexes obligatoires -->
 <div class="form-group mt-3" id="files">
+
+  <!-- <?php foreach ($files as $key => $file) { ?>
+    <div class="form-group">
+      <label for="photo"></label>
+      <input type="file" name="photo" class="upload-input" id="photo" onchange="changeTitleFile(this)"/>
+      <br>
+      <label for="photo" class="btn btn-secondary btn-sm icon-right">
+        Remplacer: <?= $file['file_name'] ?>
+      </label>
+      <br>
+      <small class="error" class="form-text text-muted"></small>
+    </div>
+  <?php } ?> -->
   <div class="form-group">
     <label for="photo">Photo passeport <strong>couleur: *</strong></label>
     <input type="file" name="photo" class="upload-input" id="photo" onchange="changeTitleFile(this)"/>
diff --git a/canapEPFL/templates/formParts/edit/filieresinfos.php b/canapEPFL/templates/formParts/edit/filieresinfos.php
new file mode 100644
index 0000000..4d3781a
--- /dev/null
+++ b/canapEPFL/templates/formParts/edit/filieresinfos.php
@@ -0,0 +1,20 @@
+<div class="form-group">
+  <label>Filières informatiques:*</label>
+  <div class="custom-control custom-radio">
+    <input type="radio" name="filInfo" id="fill1" class="custom-control-input" value="developpementApplications" <?php echo ($current_post['applicant_it_section'] == "developpementApplications") ? "checked=\"checked\"" : ''; ?>>
+    <label class="custom-control-label" for="fill1">Développement d'application</label>
+  </div>
+  <div class="custom-control custom-radio">
+    <input type="radio" name="filInfo" id="fill2" class="custom-control-input" value="entreprise" <?php echo ($current_post['applicant_it_section'] == "entreprise") ? "checked=\"checked\"" : ''; ?>>
+    <label class="custom-control-label" for="fill2">Informatique d'entreprise</label>
+  </div>
+  <div class="custom-control custom-radio">
+    <input type="radio" name="filInfo" id="fill3" class="custom-control-input" value="techniqueSysteme" <?php echo ($current_post['applicant_it_section'] == "techniqueSysteme") ? "checked=\"checked\"" : ''; ?>>
+    <label class="custom-control-label" for="fill3">Technique des systèmes</label>
+  </div>
+  <div class="custom-control custom-radio">
+    <input type="radio" name="filInfo" id="fill4" class="custom-control-input" value="neSaisPas" <?php echo ($current_post['applicant_it_section'] == '' || $current_post['applicant_it_section'] == "neSaisPas") ? "checked=\"checked\"" : ''; ?>>
+    <label class="custom-control-label" for="fill4">Je ne sais pas</label>
+  </div>
+</div>
+<button type="button" class="btn btn-primary btn-sm mb-3" id="infoFilieres">Infos sur les filières</button>
\ No newline at end of file
diff --git a/canapEPFL/templates/formParts/edit/maturity.php b/canapEPFL/templates/formParts/edit/maturity.php
index e9c601d..a297bae 100644
--- a/canapEPFL/templates/formParts/edit/maturity.php
+++ b/canapEPFL/templates/formParts/edit/maturity.php
@@ -1,5 +1,5 @@
 <div id="infoOnly">
-  <?php include('templates/filieresinfos.php') ?>
+  <?php include('filieresinfos.php') ?>
 </div>
 
 <label>Je désire m'inscire en maturité professionnelle intégrée:</label>
@@ -10,4 +10,5 @@
 <div class="custom-control custom-radio">
   <input type="radio" name="mpt" id="mpt2" class="custom-control-input" value="true"  <?php echo ($current_post['applicant_maturity'] == 1) ? "checked=\"checked\"" : ''; ?>>
   <label class="custom-control-label" for="mpt2">Oui</label>
-</div>
\ No newline at end of file
+</div>
+<button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="infoMpt">Infos sur la maturité professionnelle</button>
\ No newline at end of file
diff --git a/canapEPFL/templates/filieresinfos.php b/canapEPFL/templates/formParts/new/filieresinfos.php
similarity index 71%
rename from canapEPFL/templates/filieresinfos.php
rename to canapEPFL/templates/formParts/new/filieresinfos.php
index 2fc7aab..0b40fc8 100644
--- a/canapEPFL/templates/filieresinfos.php
+++ b/canapEPFL/templates/formParts/new/filieresinfos.php
@@ -5,15 +5,15 @@
     <label class="custom-control-label" for="fill1">Développement d'application</label>
   </div>
   <div class="custom-control custom-radio">
-    <input type="radio" name="filInfo" id="fill2" class="custom-control-input" value="entreprise"  <?php echo ($_SESSION['postedForm']['filInfo'] == "entreprise") ? "checked=\"checked\"" : ''; ?>>
+    <input type="radio" name="filInfo" id="fill2" class="custom-control-input" value="entreprise" <?php echo ($_SESSION['postedForm']['filInfo'] == "entreprise") ? "checked=\"checked\"" : ''; ?>>
     <label class="custom-control-label" for="fill2">Informatique d'entreprise</label>
   </div>
   <div class="custom-control custom-radio">
-    <input type="radio" name="filInfo" id="fill3" class="custom-control-input" value="techniqueSysteme"  <?php echo ($_SESSION['postedForm']['filInfo'] == "techniqueSysteme") ? "checked=\"checked\"" : ''; ?>>
+    <input type="radio" name="filInfo" id="fill3" class="custom-control-input" value="techniqueSysteme" <?php echo ($_SESSION['postedForm']['filInfo'] == "techniqueSysteme") ? "checked=\"checked\"" : ''; ?>>
     <label class="custom-control-label" for="fill3">Technique des systèmes</label>
   </div>
   <div class="custom-control custom-radio">
-    <input type="radio" name="filInfo" id="fill4" class="custom-control-input" value="neSaisPas"  <?php echo (!isset($_SESSION['postedForm']['filInfo']) || $_SESSION['postedForm']['mpt'] == "neSaisPas") ? "checked=\"checked\"" : ''; ?>>
+    <input type="radio" name="filInfo" id="fill4" class="custom-control-input" value="neSaisPas" <?php echo (!isset($_SESSION['postedForm']['filInfo']) || $_SESSION['postedForm']['mpt'] == "neSaisPas") ? "checked=\"checked\"" : ''; ?>>
     <label class="custom-control-label" for="fill4">Je ne sais pas</label>
   </div>
 </div>
diff --git a/canapEPFL/templates/formParts/new/maturity.php b/canapEPFL/templates/formParts/new/maturity.php
index 2c4d86c..49f1dc7 100644
--- a/canapEPFL/templates/formParts/new/maturity.php
+++ b/canapEPFL/templates/formParts/new/maturity.php
@@ -1,5 +1,5 @@
 <div id="infoOnly">
-  <?php include('templates/filieresinfos.php') ?>
+  <?php include('filieresinfos.php') ?>
 </div>
 
 <label>Je désire m'inscire en maturité professionnelle intégrée*:</label>
@@ -8,7 +8,7 @@
   <label class="custom-control-label" for="mpt1">Non</label>
 </div>
 <div class="custom-control custom-radio">
-  <input type="radio" name="mpt" id="mpt2" class="custom-control-input" value="true"  <?php echo ($_SESSION['postedForm']['mpt'] == "true") ? "checked=\"checked\"" : ''; ?>>
+  <input type="radio" name="mpt" id="mpt2" class="custom-control-input" value="true" <?php echo ($_SESSION['postedForm']['mpt'] == "true") ? "checked=\"checked\"" : ''; ?>>
   <label class="custom-control-label" for="mpt2">Oui</label>
 </div>
 <button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="infoMpt">Infos sur la maturité professionnelle</button>
\ No newline at end of file
-- 
GitLab