From 55b3db0b3e2a7035aa56e294164aad66d045ce57 Mon Sep 17 00:00:00 2001
From: nicrausaz <n.crausaz99@gmail.com>
Date: Tue, 4 Jun 2019 16:24:38 +0200
Subject: [PATCH] Close if no positions, mails

---
 canapEPFL/cible.php                                   | 4 ++--
 canapEPFL/configs/config.php                          | 3 +--
 canapEPFL/helpers.php                                 | 4 ++--
 canapEPFL/templates/head.php                          | 6 +++---
 canapEPFL/templates/mails/apprenticeMailTemplate.html | 2 +-
 canapEPFL/templates/mails/mailToResp.php              | 3 +--
 6 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/canapEPFL/cible.php b/canapEPFL/cible.php
index f9a51c0..b2dac26 100644
--- a/canapEPFL/cible.php
+++ b/canapEPFL/cible.php
@@ -35,8 +35,8 @@
           insertFiles($pdo, $candidateData->fichiers, $candidateId, $candidateData->rootpath);
 
           if ($SENDEMAILS) {
-            mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti, $candidateData->formation);
-            mailToApprenti($candidateData->mailApprenti, $candidateData->formation);
+            mailToResp($candidateData->prenomApprenti, $candidateData->nomApprenti);
+            mailToApprenti($candidateData->mailApprenti);
           }
           // kill session
           $_SESSION['formError'] = false;
diff --git a/canapEPFL/configs/config.php b/canapEPFL/configs/config.php
index 7e77fd3..877a65c 100644
--- a/canapEPFL/configs/config.php
+++ b/canapEPFL/configs/config.php
@@ -7,8 +7,7 @@
     // Mettre a false pour pas spammer pendant le dev
     $SENDEMAILS = false;
 
-    // TODO: If 0 postitions => closed
-    $POSTULATION_OPEN = true; // close/open postulation
+    $POSTULATION_OPEN = count($DBController->getOpenPositions()) > 0; // close/open postulation
 
     if (!$POSTULATION_OPEN && $_SERVER['PHP_SELF'] != '/denied.php') { header("Location: ./denied.php"); }
 ?>
\ No newline at end of file
diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php
index 2550607..f7e2559 100644
--- a/canapEPFL/helpers.php
+++ b/canapEPFL/helpers.php
@@ -1,11 +1,11 @@
 <?php
 #region [Mail Sendings]
-function mailToResp($surname, $name, $job){
+function mailToResp($surname, $name){
   require_once("templates/mails/mailToResp.php");
   mail($to, $subject, $message, $headers);
 }
 
-function mailToApprenti($to, $job){
+function mailToApprenti($to){
   require_once("templates/mails/mailToApp.php");
   mail($to, $subject, $message, $headers);
 }
diff --git a/canapEPFL/templates/head.php b/canapEPFL/templates/head.php
index 1277585..8ca154b 100644
--- a/canapEPFL/templates/head.php
+++ b/canapEPFL/templates/head.php
@@ -21,13 +21,13 @@
   gtag('config', 'UA-130041798-1', { 'anonymize_ip': true });
 </script>
 <?php
-  // ini_set("display_errors", 0);
-  // error_reporting(0);
+  ini_set("display_errors", 0);
+  error_reporting(0);
   // ini_set("display_errors", 1);
   // error_reporting(E_ALL);
-  require_once('configs/config.php');
   require('configs/db.php');
   include('models/DBController.php');
   $DBController = new DBController($pdo);
+  require_once('configs/config.php');
   if (!isset($_SESSION)) { session_start(); }
 ?>
\ No newline at end of file
diff --git a/canapEPFL/templates/mails/apprenticeMailTemplate.html b/canapEPFL/templates/mails/apprenticeMailTemplate.html
index 7502521..d21eafc 100644
--- a/canapEPFL/templates/mails/apprenticeMailTemplate.html
+++ b/canapEPFL/templates/mails/apprenticeMailTemplate.html
@@ -219,7 +219,7 @@
                         <table border="0" cellspacing="0" cellpadding="0" class="responsive-table">
                           <tr>
                             <td align="center">
-                              <a href="http://canap-dev.epfl.ch/viewpostulation.php" target="_blank"
+                              <a href="https://canap.epfl.ch/viewpostulation.php" target="_blank"
                                 style="font-size: 16px; font-family: Helvetica, Arial, sans-serif; font-weight: normal; color: #ffffff; text-decoration: none; background-color: #e30713; border-top: 15px solid #e30713; border-bottom: 15px solid #e30713; border-left: 25px solid #e30713; border-right: 25px solid #e30713; border-radius: 3px; -webkit-border-radius: 3px; -moz-border-radius: 3px; display: inline-block;"
                                 class="mobile-button">Consulter votre postulation</a>
                             </td>
diff --git a/canapEPFL/templates/mails/mailToResp.php b/canapEPFL/templates/mails/mailToResp.php
index c7b37d3..eb02e40 100644
--- a/canapEPFL/templates/mails/mailToResp.php
+++ b/canapEPFL/templates/mails/mailToResp.php
@@ -3,8 +3,7 @@ $to = 'formation.apprentis@epfl.ch';
 $subject = 'Nouvelle Candidature';
 
 $message = "Candidat: ".$surname." ".$name."\n\n".
-"Apprentissage: ".$job."\n\n".
-"Consulter la candidature sur: "."\\\\scxdata\\apprentis$\\candidatures\\nouvelles";
+"Consulter la candidature sur: https://canap-gest.epfl.ch/";
 
 $headers = 'From: noreply+formulaireApprentis@epfl.ch' . "\r\n" .
 'Reply-To: formation.apprentis@epfl.ch' . "\r\n" .
-- 
GitLab