From 92c23fb9d0aaedf7c1691045b250a40f15a201c1 Mon Sep 17 00:00:00 2001
From: nicrausaz <n.crausaz99@gmail.com>
Date: Thu, 7 Mar 2019 10:55:43 +0100
Subject: [PATCH] show heaeder only if content

---
 canapEPFL/helpers.php        | 23 ++++++++++++++++++++++-
 canapEPFL/script.js          | 17 +++++++++++++++++
 canapEPFL/templates/head.php |  4 ++--
 3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/canapEPFL/helpers.php b/canapEPFL/helpers.php
index 33d5dc5..730d624 100644
--- a/canapEPFL/helpers.php
+++ b/canapEPFL/helpers.php
@@ -424,7 +424,28 @@ function updatePostulation ($pdo, $posted_data) {
     $query->bindParam(':responsible_phone', $sec_rep['telephone'], PDO::PARAM_STR);
     $query->execute();
   }
-  // TODO: si nouveau, insert
+
+  // Si majeur, delete les valeurs
+  // if ($posted_data->majeur == 1) {
+  //   echo $main_rep['id'];
+  //   if ($main_rep['id'] != '') {
+  //     $sqlreq = "DELETE FROM responsible WHERE responsible_id=:id";
+  //     $query = $pdo->prepare($sqlreq);
+  //     $query->bindParam(':id1', $main_rep['id'], PDO::PARAM_STR);
+  //     $query->execute();
+  //   }
+  //   if ($sec_rep['id'] != '') {
+  //     $sqlreq = "DELETE FROM responsible WHERE responsible_id=:id";
+  //     $query = $pdo->prepare($sqlreq);
+  //     $query->bindParam(':id', $sec_rep['id'], PDO::PARAM_STR);
+  //     $query->execute();
+  //   }
+  // }
+
+  // Si nouveau, insert
+  if ($main_rep['id'] == '' || $sec_rep['id'] == '') {
+    insertResponsibles($pdo, [$main_rep, $sec_rep], $posted_data->id);
+  }
 
   // update scolarities
   $to_add = [];
diff --git a/canapEPFL/script.js b/canapEPFL/script.js
index a32f45d..e187c37 100644
--- a/canapEPFL/script.js
+++ b/canapEPFL/script.js
@@ -8,6 +8,7 @@ $(document).ready(function () {
         initDateChecker();
         initDatepicker();
         checkRequired();
+        toggleTableHeaders();
     }
     else if (location.pathname.split("/").slice(-1)[0] == "form.php") {
         initJobChange();
@@ -61,6 +62,9 @@ function addChildren(parentId, maxItems, childTemplate, addButtonId) {
             $(addButtonId).hide();
         }
     }
+    if (location.search == "?edit") {
+        toggleTableHeaders();
+    }
 }
 
 function changeTitleFile(objFile) {
@@ -166,6 +170,19 @@ function initAddChildButtons() {
     });
 }
 
+function toggleTableHeaders() {
+    if ($('#activites')[0].rows.length == 1) {
+        $($('#activites')[0].rows[0]).hide();
+    } else {
+        $($('#activites')[0].rows[0]).show();
+    }
+    if ($('#stages')[0].rows.length == 1) {
+        $($('#stages')[0].rows[0]).hide();
+    } else {
+        $($('#stages')[0].rows[0]).show();
+    }
+}
+
 function setMajState() {
     $('#maj1')[0].checked ? $("#representants").show() : $("#representants").hide();
 }
diff --git a/canapEPFL/templates/head.php b/canapEPFL/templates/head.php
index 1169763..1639fee 100644
--- a/canapEPFL/templates/head.php
+++ b/canapEPFL/templates/head.php
@@ -23,8 +23,8 @@
 <?php
   ini_set("display_errors", 0);
   error_reporting(0);
-  ini_set("display_errors", 1);
-  error_reporting(E_ALL);
+  // ini_set("display_errors", 1);
+  // error_reporting(E_ALL);
   require_once('configs/config.php');
   require('configs/db.php');
   if (!isset($_SESSION)) { session_start(); }
-- 
GitLab