From 175c791fa360a20352a80c67409a52cbd9bac474 Mon Sep 17 00:00:00 2001
From: nicrausaz <n.crausaz99@gmail.com>
Date: Tue, 5 Mar 2019 13:43:02 +0100
Subject: [PATCH] update script to edit usage, form changes

---
 canapEPFL/form.php                            |  9 +++++--
 canapEPFL/script.js                           | 24 ++++++++++++-------
 canapEPFL/templates/errorText.php             |  1 +
 .../templates/formParts/edit/annexes.php      |  7 ++----
 .../templates/formParts/edit/jobselection.php |  4 ++--
 5 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/canapEPFL/form.php b/canapEPFL/form.php
index 7180345..71facd4 100644
--- a/canapEPFL/form.php
+++ b/canapEPFL/form.php
@@ -107,13 +107,18 @@
             </div>
           </div>
           <!-- / Conditions -->
-          <button type="submit" class="btn btn-primary btn-block" type="submit">Terminer</button>
+          <button class="btn btn-primary btn-block" type="submit">Terminer</button>
+          <button class="btn btn-secondary btn-block" id="cancelEditBtn" type="button">Annuler</button>
         </div>
         <!-- / div all -->
       </form>
     </main>
-    <script> lieu='<?php echo $_SESSION['postedForm']['lieu'] ;?>';</script>
+    <?php if (isset($_GET['edit'])) { ?>
+      <script> lieu='<?php echo $_SESSION['postedForm']['lieu'] ;?>';</script>
+    <?php } else { ?>
+      <script> lieu='<?php echo $_SESSION['current_post']['applicant_formation_location'] ;?>';</script>
     <?php
+      }
       if (isset($_SESSION['formError'])) {
         echo "<script>showOnFormReturn(lieu);</script>";
       }
diff --git a/canapEPFL/script.js b/canapEPFL/script.js
index ff00196..dca62d0 100644
--- a/canapEPFL/script.js
+++ b/canapEPFL/script.js
@@ -1,7 +1,6 @@
 $(document).ready(function () {
     initButtonsAction();
     if (location.search == "?edit") {
-        // showPolyAndInfoDivs();
         $("#all").show();
         initButtonsAction();
         initAddChildButtons();
@@ -114,6 +113,9 @@ function initButtonsAction() {
     $('#editPost').click(function () {
         document.location.href = "form.php?edit";
     });
+    $('#cancelEditBtn').click(function () {
+        document.location.href = "viewpostulation.php";
+    })
     $('#infoFilieres').click(function () {
         window.open("https://www.ict-berufsbildung.ch/fr/formation-professionnelle/formation-initiale-ict/", '_blank');
     });
@@ -236,14 +238,20 @@ function initJobChange() {
 }
 
 function showOnFormReturn(lieu) {
-    if (lieu == 'Lausanne') {
-        var selectedFormation = $("#jbLausanne option:selected")[0].value;
-    }
-    else if (lieu == 'Sion') {
-        var selectedFormation = $("#jbSion option:selected")[0].value;
+    if (location.search != "?edit") {
+        if (lieu == 'Lausanne') {
+            var selectedFormation = $("#jbLausanne option:selected")[0].value;
+        }
+        else if (lieu == 'Sion') {
+            var selectedFormation = $("#jbSion option:selected")[0].value;
+        }
+        showListJob(lieu);
+        showPolyAndInfoDivs(selectedFormation);
+
+    } else {
+        var selectedFormation = $('#job').val();
+        showPolyAndInfoDivs(selectedFormation);
     }
-    showListJob(lieu)
-    showPolyAndInfoDivs(selectedFormation);
 }
 function showListJob(lieu) {
     if (lieu == 'Lausanne') {
diff --git a/canapEPFL/templates/errorText.php b/canapEPFL/templates/errorText.php
index 7c45fa8..000100d 100644
--- a/canapEPFL/templates/errorText.php
+++ b/canapEPFL/templates/errorText.php
@@ -5,6 +5,7 @@
       if (!$_POST && !$_FILES) {
         echo "<li>Fichiers fournis trop volumineux ! <small>(Taille recommandée env. 2Mo)</small></li>";
       } else {
+        echo isset($_SESSION['edit_error']['files']) ? $_SESSION['edit_error']['files'] : '';
         foreach($validator->errors() as $error => $errorVal) {
           echo "<li>$errorVal</li>";
         }
diff --git a/canapEPFL/templates/formParts/edit/annexes.php b/canapEPFL/templates/formParts/edit/annexes.php
index 77fa211..1b1f92c 100644
--- a/canapEPFL/templates/formParts/edit/annexes.php
+++ b/canapEPFL/templates/formParts/edit/annexes.php
@@ -1,8 +1,5 @@
 <?php
   $files = getFilesById($pdo, $current_post['applicant_id']);
-  echo "<pre>";
-  print_r($files);
-  echo "</pre>";
 ?>
 <small>Remplacez ou ajouter des annexes (le fichier actuel est conservé si il n'est pas remplacé)</small>
 <br>
@@ -36,9 +33,9 @@
     </label>
     <br>
     <small class="error" class="form-text text-muted"></small>
-  </div>
+  </div> -->
 
-  <div class="form-group" id="griTest">
+  <!-- <div class="form-group" id="griTest">
     <label for="griTestInput">Attestation de tests d'aptitudes GRI (informaticien):</label>
     <input type="file" name="griTestInput" class="upload-input" id="griTestInput" onchange="changeTitleFile(this)"/>
     <br>
diff --git a/canapEPFL/templates/formParts/edit/jobselection.php b/canapEPFL/templates/formParts/edit/jobselection.php
index a617737..877ce70 100644
--- a/canapEPFL/templates/formParts/edit/jobselection.php
+++ b/canapEPFL/templates/formParts/edit/jobselection.php
@@ -1,4 +1,4 @@
 <p>Formation: <b><?= $LISTJOB[$current_post['applicant_formation_location']][$current_post['applicant_formation']]?></b></p>
 <p>Lieu: <b><?= $current_post['applicant_formation_location'] ?></b></p>
-<input type="text" hidden readonly name="job" value="<?= $current_post['applicant_formation']?>">
-<input type="text" hidden readonly name="lieu" value="<?= $current_post['applicant_formation_location'] ?>">
+<input type="text" hidden readonly name="job" id="job" value="<?= $current_post['applicant_formation']?>">
+<input type="text" hidden readonly name="lieu" id="lieu" value="<?= $current_post['applicant_formation_location'] ?>">
-- 
GitLab