From cf2452a33a99df96e83b35385c2ccbc01c7cf456 Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle
 <Myriam Delaruelle@bdn-un-mdelarue.ad.univ-lorraine.fr>
Date: Tue, 14 Sep 2021 09:48:20 +0200
Subject: [PATCH] =?UTF-8?q?fix=20=C3=A0=20distance=20:=20pour=20le=20+=20d?=
 =?UTF-8?q?isabled=20checkbox=20for=20notifications?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib.php      | 27 ++++++++++++++++++++++++++-
 renderer.php |  4 ++--
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib.php b/lib.php
index 6ade008..7087588 100644
--- a/lib.php
+++ b/lib.php
@@ -174,6 +174,8 @@
 			//On montre le groupe si pas distance
 			$mform->hideIf('groupdate2', 'presence', 'eq', 2);
 
+
+
 			$daysarray=array();
 			$days=array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
 			$daysarray[] = $mform->createElement('select', 'daysnotif', "jours avant la séance", $days);
@@ -181,17 +183,35 @@
 			$daysarray[] = $mform->createElement('checkbox', 'selectdayscheck', 'Activer');
 			$mform->addGroup($daysarray, 'groupdays', 'Notification', array(' '), false);
 			$mform->disabledIf('groupdays', 'selectdayscheck');
-			$mform->disabledIf('groupdays', 'daterenducheck2');
+			$mform->disabledIf('groupdays', 'daterenducheck');
+			$mform->hideIf('groupdays', 'presence', 'neq', 2);
+
+
+			$daysarray=array();
+			
+			$daysarray[] = $mform->createElement('select', 'daysnotif2', "jours avant le rendu", $days);
+			$daysarray[]=$mform->createElement('html', ' <span id="days-text">jours avant le rendu</span>');
+			$daysarray[] = $mform->createElement('checkbox', 'selectdayscheck2', 'Activer');
+			$mform->addGroup($daysarray, 'groupdays2', 'Notification', array(' '), false);
+			$mform->disabledIf('groupdays2', 'selectdayscheck2');
+			$mform->disabledIf('groupdays2', 'daterenducheck2');
+			$mform->hideIf('groupdays2', 'presence', 'eq', 2);
+
+			//on ne peut pas activer des notifs s'il n'y a pas de date de rendu/date de cours
+			
 
           	if($section_config['presence']){
           		$mform->setDefault('presence', $section_config['presence']);
           	}
           	if($section_config['daterendu']){
+
           		if(isset($section_config['presence']) && $section_config['presence']==2){
+          			error_log("on passe là");
           			$mform->setDefault('daterendu', $section_config['daterendu']);
           			$mform->setDefault('daterenducheck', "1");
           		}
           		else if(isset($section_config['presence'])){
+          			error_log("non on passe là");
           			$mform->setDefault('daterendu2', $section_config['daterendu']);
           			$mform->setDefault('daterenducheck2', "1");
           		}
@@ -239,10 +259,15 @@
         }
         else if(isset($data['daterenducheck2'])){
         	$data['daterendu']=$data['daterendu2'];
+
         }
         if(!isset($data['selectdayscheck'])){
+        	if(isset($data['daysnotif2'])){
+    			$data['daysnotif']=$data["daysnotif2"];
+    		}
         	if(array_key_exists('daysnotif', $section_config) && $section_config['daysnotif']>-1){
         		$data['daysnotif']=-1;
+
         	}
         	else{
         		unset($data['daysnotif']);
diff --git a/renderer.php b/renderer.php
index a461b3b..5351435 100644
--- a/renderer.php
+++ b/renderer.php
@@ -182,10 +182,10 @@ class format_iena_renderer extends format_topics_renderer{
 				if (isset($param_section->presence)) {
 					if ($param_section->presence == 1) {
 						$section->presence = "En présence";
-						$string_date_presence="Pour le ";
+						$string_date_presence="Le ";
 					} else if ($param_section->presence == 2) {
 						$section->presence = "À distance";
-						$string_date_presence="Le ";
+						$string_date_presence="Pour le ";
 					}
 				}
 
-- 
GitLab