From dd2fde610cc046472f7905ac9998225fbf964e83 Mon Sep 17 00:00:00 2001
From: nicrausaz <n.crausaz99@gmail.com>
Date: Wed, 10 Oct 2018 14:44:54 +0200
Subject: [PATCH] form, fix show errors

---
 canapEPFL/cible.php                         |  7 ++-----
 canapEPFL/configs/config.php                |  2 +-
 canapEPFL/form.php                          |  4 ++--
 canapEPFL/helpers.php                       |  9 ++-------
 canapEPFL/models/PersonnalData.php          |  2 +-
 canapEPFL/models/PersonnalDataValidator.php | 11 +++++------
 canapEPFL/templates/confirmationText.php    | 14 +++++++-------
 canapEPFL/templates/head.php                |  1 +
 8 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/canapEPFL/cible.php b/canapEPFL/cible.php
index fe20630..be2b3a2 100644
--- a/canapEPFL/cible.php
+++ b/canapEPFL/cible.php
@@ -16,13 +16,10 @@
             include('templates/header.php');
             //Init personnalData with postedData
             $candidateData = new PersonnalData($_POST);
-            debuglog("personnalData initiallised");
             //Init dataValidator
             $validator = new PersonnalDataValidator($candidateData);
-            debuglog("PersonnalDataValitor initiallised");
 
             if($validator->isValid()){
-                debuglog("validator->isValid");
                 //Create folders
                 createCandidateFolders($candidateData);
                 //Upload files
@@ -31,7 +28,8 @@
                 $encodedJson = (json_encode($candidateData,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT));
                 file_put_contents($candidateData->getPaths()["pathInfos"].'/informations.json', $encodedJson);
                 //Send mails
-                mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
+
+                // mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
                 mailToApprenti($candidateData->mailApprenti, $candidateData->formation);
                 // kill session
                 $_SESSION['formError'] = false;
@@ -41,7 +39,6 @@
                 $_SESSION['formError'] = true;
                 $_SESSION['postedForm'] = $_POST;
                 $_SESSION['files'] = $_FILES;
-                debuglog("!validator->isValid");
                 include("templates/errorText.php");
             }
         ?>
diff --git a/canapEPFL/configs/config.php b/canapEPFL/configs/config.php
index 102d2ca..0a145ae 100644
--- a/canapEPFL/configs/config.php
+++ b/canapEPFL/configs/config.php
@@ -4,7 +4,7 @@
     // by default, labo can't apply by this formular, in case, add some of these these values in the array:
 
     /*
-    -- PLEASE DO NOT DELETE --
+    -- DO NOT DELETE --
 
         "laborantinBiologie" => "Laborantin-e CFC; option biologie",
         "laborantinChimie" => "Laborantin-e CFC; option chimie",
diff --git a/canapEPFL/form.php b/canapEPFL/form.php
index 709c962..9d4d61b 100644
--- a/canapEPFL/form.php
+++ b/canapEPFL/form.php
@@ -258,7 +258,7 @@
           <div class="form-group mt-3">
             <label for="anneeFin">Année de fin de scolarité*</label>
             <input type="text" name="anneeFin" id="anneeFin" class="form-control" placeholder="Année de fin de scolarité" value="<?php echo $_SESSION['postedForm']['anneeFin'] != '' ? $_SESSION['postedForm']['anneeFin'] : ''; ?>" maxlength="4" data-required/>
-            <small id="anneeFinError" class="form-text text-muted"></small>
+            <small id="anneeFinError" class="error form-text text-muted"></small>
           </div>
           <h5>3.2 Activités professionnelles</h5>
           <small>Formations / apprentissages après la scolarité.</small>
@@ -337,7 +337,7 @@
           <div class="form-group" id="dejaCandAnnee" style="display: none;">
             <label for="dejaCandAnneeInput">Année de candidature *</label>
             <input type="text" name="dejaCandAnnee" id="dejaCandAnneeInput" class="form-control" placeholder="Année de candidature" value="<?php echo $_SESSION['postedForm']['dejaCandAnnee'] != '' ? $_SESSION['postedForm']['dejaCandAnnee'] : ''; ?>" maxlength="4"/>
-            <small id="dejaCandError" class="form-text text-muted"></small>
+            <small id="dejaCandError" class="form-text text-muted error"></small>
           </div>
           <!-- / Activités pro -->
           <hr>
diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php
index a62fb3f..a22c93a 100644
--- a/canapEPFL/helpers.php
+++ b/canapEPFL/helpers.php
@@ -22,12 +22,11 @@ function uploadFile(&$candidateData, $pathAnnexes, $file, $name){
     $extension = strtolower(strrchr($file['name'], '.'));
     $validExt = ['.pdf', '.jpeg', '.png', '.jpg'];
     $filename = $name . $extension;
-    
-    //-> dataValidator
+
     if(!in_array($extension, $validExt)){
         $erreur = "uploadError";
     }
-    
+
     if(!isset($erreur)){
         $filename = checkChars($filename);
         move_uploaded_file($file['tmp_name'], $pathAnnexes . $filename);
@@ -68,8 +67,4 @@ function uploadAllFiles($pathAnnexes, $postedFiles, $candidateData){
     }
     return $candidateData;
 }
-
-function debuglog($message){
-    //echo $message;
-}
 ?>
\ No newline at end of file
diff --git a/canapEPFL/models/PersonnalData.php b/canapEPFL/models/PersonnalData.php
index a0cd16b..6e0872f 100644
--- a/canapEPFL/models/PersonnalData.php
+++ b/canapEPFL/models/PersonnalData.php
@@ -17,7 +17,7 @@ class PersonnalData {
     "interactiveMediaDesigner" => "InteractiveMediaDesigners"
     );
     private $dateNow;
-    private $rootpath = '\\\\scxdata\\apprentis$\\candidatures\\nouvelles\\';
+    private $rootpath = 'D:/Formdata/'; // \\\\scxdata\\apprentis$\\candidatures\\nouvelles\\
     public $formation = "";
     public $lieu = "";
     public $filiere = "";
diff --git a/canapEPFL/models/PersonnalDataValidator.php b/canapEPFL/models/PersonnalDataValidator.php
index 89ef8c2..e41648b 100644
--- a/canapEPFL/models/PersonnalDataValidator.php
+++ b/canapEPFL/models/PersonnalDataValidator.php
@@ -15,7 +15,6 @@ class PersonnalDataValidator {
     }
 
     public function isValid(){
-
         $this->filiereValid();
         $this->dataRequiredIsValid();
         $this->representantValid();
@@ -57,8 +56,8 @@ class PersonnalDataValidator {
 
         $this->isBirthDateValid(date($this->personnalData->dateNaissanceApprenti));
 
-        foreach ($toValid as $valid) {
-            $this->isRequired($valid);
+        foreach ($toValid as $key => $valid) {
+            $this->isRequired($key, $valid);
         }
     }
 
@@ -73,9 +72,9 @@ class PersonnalDataValidator {
         }
     }
 
-    private function isRequired ($dataToCheck) {
-        if (is_null($dataToCheck) || $dataToCheck=="") {
-            $this->errors[$dataNameToCheck] = $dataNameToCheck . " manquant(e)";
+    private function isRequired ($key, $dataToCheck) {
+        if (is_null($dataToCheck) || $dataToCheck == "") {
+            $this->errors[$key] = $key . " manquant(e)";
         }
     }
 
diff --git a/canapEPFL/templates/confirmationText.php b/canapEPFL/templates/confirmationText.php
index 7af7da2..20ce404 100644
--- a/canapEPFL/templates/confirmationText.php
+++ b/canapEPFL/templates/confirmationText.php
@@ -1,7 +1,7 @@
-<h1><?php echo $candidateData->prenomApprenti," ", $candidateData->nomApprenti,"," ?></h1>
-<h4>Votre demande à bien été enregistrée, vous allez bientôt recevoir un e-mail confirmant votre postulation.</h4>
-<footer>
-  <button type="button" id="retourHome" class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent">
-    Retour à l'accueil
-  </button>
-</footer>
\ No newline at end of file
+
+
+
+<main id="main" role="main" class="content container-grid">
+  <p>Votre demande à bien été enregistrée, vous allez bientôt recevoir un e-mail confirmant votre postulation.</p>
+  <button type="button" class="btn btn-primary btn-sm mt-3 mb-2" id="retourHome">Retour à l'acceuil</button>
+</main>
\ No newline at end of file
diff --git a/canapEPFL/templates/head.php b/canapEPFL/templates/head.php
index 5214b95..29a7aab 100644
--- a/canapEPFL/templates/head.php
+++ b/canapEPFL/templates/head.php
@@ -8,6 +8,7 @@
 <script src="./style/epfl2018/js/vendors.min.js"></script>
 <script src="./style/epfl2018/js/vendors.bundle.js"></script>
 <script src="./script.js"></script>
+<style>.error { color: red!important; }</style>
 <noscript>Veuillez Activer JavaScript pour utiliser le service de postulation</noscript>
 <?php
   ini_set("display_errors",0);
-- 
GitLab