diff --git a/classes/task/sync_task_iena_message.php b/classes/task/sync_task_iena_message.php
index 078e16697a3a21da56eb1a79b4a72d7e9a9ab8fa..d5363835860600ba35c147a486ac20cc42538ad5 100644
--- a/classes/task/sync_task_iena_message.php
+++ b/classes/task/sync_task_iena_message.php
@@ -1,64 +1,46 @@
-<?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 15/03/18
-	 * Time: 16:22
-	 */
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * sync_task_iena_message lunch cron_message()
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	namespace format_iena\task;
-	
-	class sync_task_iena_message extends \core\task\scheduled_task
-	{
-		/**
-		 * Get a descriptive name for this task (shown to admins).
-		 *
-		 * @return string
-		 */
-		
-		public function get_name()
-		{
-			return "task_iena_message";
-		}
-		
-		
-		public function execute()
-		{
-			global $CFG;
-			mtrace("IENA notifications task started");
-
-			require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_cron_action.php');
-			$cron_test = new \course_format_iena_cron_action();
-			// echo 'send message start';
-			$cron_test->cron_message();
-			mtrace("IENA notifications task completed");
-			// echo 'send message stop';
-		}
-		
-	}
\ No newline at end of file
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * sync_task_iena_message lunch cron_message()
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace format_iena\task;
+
+class sync_task_iena_message extends \core\task\scheduled_task {
+    /**
+     * Get a descriptive name for this task (shown to admins).
+     *
+     * @return string
+     */
+    public function get_name() {
+        return "task_iena_message";
+    }
+
+    public function execute() {
+        global $CFG;
+        mtrace("IENA notifications task started");
+
+        require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_cron_action.php');
+        $cron = new \course_format_iena_cron_action();
+        $cron->cron_message();
+        mtrace("IENA notifications task completed");
+    }
+}
diff --git a/db/access.php b/db/access.php
index da3f58ea7548df5a38f4eb5689eb89721e716f65..7f4beb1913d0b1968932376be10fcb6c0108f269 100644
--- a/db/access.php
+++ b/db/access.php
@@ -1,22 +1,45 @@
-<?php
-$capabilities = array(
-	'course/iena:suivi' => array(
-		'captype' => 'read',
-		'contextlevel' => CONTEXT_COURSE,
-		'archetypes' => array(
-			'teacher' => CAP_ALLOW,
-			'editingteacher' => CAP_ALLOW,
-			'manager' => CAP_ALLOW
-		)
-	),
-	'course/iena:suivi_edit' => array(
-		'captype' => 'write',
-		'contextlevel' => CONTEXT_COURSE,
-		'archetypes' => array(
-			'teacher' => CAP_PREVENT,
-			'editingteacher' => CAP_ALLOW,
-			'manager' => CAP_ALLOW
-		)
-	),
-	
-);
\ No newline at end of file
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * Plugin capabilities
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+defined('MOODLE_INTERNAL') || die();
+
+$capabilities = array(
+    'course/iena:suivi' => array(
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_COURSE,
+        'archetypes' => array(
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'manager' => CAP_ALLOW
+        )
+    ),
+    'course/iena:suivi_edit' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'archetypes' => array(
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'manager' => CAP_ALLOW
+        )
+    ),
+);
diff --git a/db/tasks.php b/db/tasks.php
index 5d9bca3eb01e8fd77754d0d159033f1924bee1a5..9a26a1fb0469211225ab4f33c6a9c5334bfe7b8e 100644
--- a/db/tasks.php
+++ b/db/tasks.php
@@ -1,51 +1,38 @@
-<?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 15/03/18
-	 * Time: 16:34
-	 */
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * Set setting for cron
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	defined('MOODLE_INTERNAL') || die();
-	
-	
-	$tasks = array(
-		
-
-		array(
-			'classname' => 'format_iena\task\sync_task_iena_message',
-			'blocking' => 0,
-			'minute' => '0',
-			'hour' => '22',
-			'day' => '*',
-			'month' => '*',
-			'dayofweek' => '*'
-		)
-	
-	);
\ No newline at end of file
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * Set setting for cron
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$tasks = array(
+    array(
+        'classname' => 'format_iena\task\sync_task_iena_message',
+        'blocking' => 0,
+        'minute' => '0',
+        'hour' => '22',
+        'day' => '*',
+        'month' => '*',
+        'dayofweek' => '*'
+    )
+);
diff --git a/db/upgrade.php b/db/upgrade.php
index 8616fe3696a4c8015ca53375842c64540f3ec375..4aceccdc28e07c7816651160f2a729b09117dd64 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -1,73 +1,97 @@
 <?php
-
-	
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * Set setting for cron
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
 
 function xmldb_format_iena_upgrade($oldversion) {
     global $CFG, $DB;
- 	$dbman = $DB->get_manager();
-    $result = TRUE;
- 
-      if ($oldversion < 2021220900) {
-
-       
+    $dbman = $DB->get_manager();
+    $result = true;
 
-        //Support for old versions: we copy format options to the course_format_options table
+    if ($oldversion < 2021220900) {
+        // Support for old versions: we copy format options to the course_format_options table.
         try {
-            $sections= $DB->get_records_sql('select * FROM {format_iena}');
-        } 
-        catch (dml_exception $e) {
+            $sections = $DB->get_records_sql('select * FROM {format_iena}');
+        } catch (dml_exception $e) {
             echo "Aucun cours avec le format hybride dans la base";
         }
-        if(count($sections) > 0){
+        if (count($sections) > 0) {
             foreach ($sections as $section) {
                 try {
+                    $courseid = $DB->get_record_sql('SELECT course
+                        FROM {course_sections}
+                        WHERE id=?',
+                        array($section->id_section));
+
+                    $sectiondata = new stdClass();
+                    $sectiondata->courseid = $courseid->course;
+                    $sectiondata->format = "iena";
+                    $sectiondata->sectionid = $section->id_section;
+                    // On va faire pour présence, daterendu et daysnotif.
+                    $sectiondata->name = "presence";
+                    $sectiondata->value = $section->presence;
+
+                    $exists = $DB->get_record_sql('SELECT *
+                        FROM {course_format_options}
+                        WHERE sectionid=?
+                        AND name="presence"',
+                        array($section->id_section));
 
-                    $courseid = $DB->get_record_sql('select course FROM {course_sections} WHERE id=?', array($section->id_section));
-                    
-                    $section_data = new stdClass();
-                    $section_data->courseid = $courseid->course;
-                    $section_data->format = "iena";
-                    $section_data->sectionid = $section->id_section;
-                    //On va faire pour présence, daterendu et daysnotif
-                    $section_data->name = "presence";
-                    $section_data->value = $section->presence;
-                    
-                    $exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="presence"', array($section->id_section));
-                    
-                    if(!$exists){
-                       
-                        $resultat = $DB->insert_record('course_format_options', $section_data, true);
+                    if (!$exists) {
+                        $resultat = $DB->insert_record('course_format_options', $sectiondata, true);
                     }
-                    $exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="daterendu"', array($section->id_section));
-                    if(!$exists){
-                       
-                        if(isset($section->date_rendu)){
-                            $section_data->name = "daterendu";
-                            $section_data->value = strtotime($section->date_rendu);
-                            $resultat = $DB->insert_record('course_format_options', $section_data, true);
+                    $exists = $DB->get_record_sql('SELECT *
+                        FROM {course_format_options}
+                        WHERE sectionid=?
+                        AND name="daterendu"',
+                        array($section->id_section));
+
+                    if (!$exists) {
+                        if (isset($section->date_rendu)) {
+                            $sectiondata->name = "daterendu";
+                            $sectiondata->value = strtotime($section->date_rendu);
+                            $resultat = $DB->insert_record('course_format_options', $sectiondata, true);
                         }
                     }
-                    $exists = $DB->get_record_sql('select * FROM {course_format_options} WHERE sectionid=? AND name="daysnotif"', array($section->id_section));
-                    if(!$exists){
-                        
-                        if(!empty($section->day_before)){
-                            $section_data->name = "daysnotif";
-                          
-                            $section_data->value = $section->nb_days_before;
-                            $resultat = $DB->insert_record('course_format_options', $section_data, true);
+                    $exists = $DB->get_record_sql('SELECT *
+                        FROM {course_format_options}
+                        WHERE sectionid=?
+                        AND name="daysnotif"',
+                        array($section->id_section));
+
+                    if (!$exists) {
+                        if (!empty($section->day_before)) {
+                            $sectiondata->name = "daysnotif";
+                            $sectiondata->value = $section->nb_days_before;
+                            $resultat = $DB->insert_record('course_format_options', $sectiondata, true);
                         }
                     }
-                } 
-                catch (dml_exception $e) {
+                } catch (dml_exception $e) {
                 }
             }
         }
-
         // Format_iena savepoint reached.
-        upgrade_plugin_savepoint(true, 2021070600,'format', 'iena');
+        upgrade_plugin_savepoint(true, 2021070600, 'format', 'iena');
     }
- 
     return $result;
 }
-
-?>
\ No newline at end of file
diff --git a/entity/course_format_iena_attendance.php b/entity/course_format_iena_attendance.php
index 938314efd64db50ba7d36cfbb2ae2f489c4bbb03..fc8c79db1adfd308958175035aaca49bce07796d 100644
--- a/entity/course_format_iena_attendance.php
+++ b/entity/course_format_iena_attendance.php
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -14,53 +13,31 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
 /**
  *
  * course_format_iena_sections
  *
  * @package    format_iena
- * @category   format
  * @copyright  2018 Softia/Université lorraine
  * @author     Thomas Fradet
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
-class course_format_iena_attendance
-{
-
-	/**
-	 * @param $id_course
-	 * @return array
-	 * @throws dml_exception
-	 */
-	public function get_attendance_sessions($course_id) {
-
-
-		global $DB;
-			// -- FROM {attendance_sessions} 
-		// $DB->set_debug(true);
-		$res = $DB->get_records_sql('SELECT sessdate, att_sess.id, duration, groupid 
-			FROM {attendance_sessions} as att_sess
-			INNER JOIN {attendance} as att on att_sess.attendanceid = att.id
-			WHERE att.course = ?'
-			, array($course_id));
-
-		return $res;
-		// $groups = array();
-		// $i = 0;
-		// foreach ($requete as $value) {
-		// 	$group = new course_format_iena_groups();
-		// 	$group->get_group_by_id_group($value->id);
-		// 	$groups[$i] = $group;
-		// 	$i++;
-		// }
-
-		// return $groups;
-
-
-	}
-
-
-
-
+class course_format_iena_attendance {
+
+    /**
+     * @param $idcourse
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_attendance_sessions($courseid) {
+        global $DB;
+
+        $res = $DB->get_records_sql('SELECT sessdate, att_sess.id, duration, groupid
+            FROM {attendance_sessions} att_sess
+            INNER JOIN {attendance} att ON att_sess.attendanceid = att.id
+            WHERE att.course = ?',
+            array($courseid));
+
+        return $res;
+    }
 }
diff --git a/entity/course_format_iena_completion.php b/entity/course_format_iena_completion.php
index 9df796923646327bcbe58a85304cc918d12db3da..b25a7fd287b09c8c8bfef9d070ae160f4e14e9f5 100644
--- a/entity/course_format_iena_completion.php
+++ b/entity/course_format_iena_completion.php
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -17,153 +16,147 @@
 
 /**
  *
- * This file give completion datas to get and display completion infos. 
+ * This file give completion datas to get and display completion infos.
  *
  * @package    format_iena
- * @category   format
  * @copyright  2018 Softia/Université lorraine
  * @author     Thomas Fradet
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 class course_format_iena_completion {
 
-	/**
-	 * Get completion by sections
-	 * @param array $section_names 
-	 * @param array $idSection 
-	 * @return type
-	 */
-	public static function get_completion_by_section($section_names, $idSection) {
-	
-		global $COURSE, $USER, $DB, $CFG;
-
-		$completion = new \completion_info($COURSE);
-		if ( $completion->is_enabled_for_site() == false || $completion->has_activities() == false || $completion->is_enabled() == 0 ) {
-			return false;
-		}
-
-
-		$sections = [];
-
-		$fast_modinfo = get_fast_modinfo($COURSE->id);
-		$modinfos_cms = $fast_modinfo->get_cms();
-
-		$modules = [];
-		//Il récupère les modules qui ne sont pas en cours de suppression, qui ont l'achèvement d'activité, et qui sont visibles pour l'user
-		foreach ($modinfos_cms as $cm) {
-			$module = $completion->get_data($cm, true, $USER->id, $fast_modinfo);
-			$module->url = "$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id";
-			$module->section = $cm->section;
-			if ( $cm->deletioninprogress == 0 && $cm->completion != 0 && $cm->uservisible) {
-				$module->name = $cm->name;
-				$module->url = "$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id";
-				$modules[] = $module;
-			}
-		}
-
-
-
-		$total_completed = 0;
-		$total_modules = 0;
-		foreach ($idSection as $i => $section_id) {
-			$section = new StdClass();
-			$section->id = $i;
-			$section->name = $section_names[$i];
-			$inner_modules = [];
-			$inner_completed = 0;
-			foreach ($modules as $module) {
-				if ( $module->section == $section_id) {
-					$mod = new StdClass();
-					$mod->coursemoduleid = $module->coursemoduleid;
-					$mod->completion = $module->completionstate;
-					$mod->name = $module->name;
-					$mod->url = $module->url;
-					if ( $mod->completion == 1 || $mod->completion == 2 ) {
-						$inner_completed++;
-					}
-					$inner_modules[] = $mod;
-				}
-			}
-			$section->modules = $inner_modules;
-			if ( count($inner_modules) == 0 ) {
-				$section->completion = 0;
-			} else {
-				$section->completion = number_format( 100 * $inner_completed / count($inner_modules), 0 );
-			}
-			$total_completed += $inner_completed;
-			$total_modules += count($inner_modules);
-			array_push($sections, $section);
-		}
-		if($total_modules==0){
-			return false;
-		}
-		$progress = new StdClass();
-		$progress->total = number_format( 100 * $total_completed / $total_modules, 0);
-		$progress->sections = $sections;
-		return $progress;
-
-	}
-
-	public static function get_completion_by_section_old() {
-
-		global $COURSE, $DB, $USER;
-
-		$completion = new \completion_info($COURSE);
-		if ( $completion->is_enabled_for_site() == false || $completion->has_activities() == false || $completion->is_enabled() == 0 ) {
-			return false;
-		}
-
-		$modinfo = get_fast_modinfo($COURSE->id);
-
-		$sections_infos = $modinfo->get_section_info_all();
-		$section_ids = [];
-		foreach ($sections_infos as $section) {
-			array_push($section_ids, $section->__get('id') );
-		}
-
-		$modules = $DB->get_records_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate, cm.section
-			FROM  {course_modules_completion} as cmc
-			inner join {course_modules} as cm on cm.id = cmc.coursemoduleid
-			inner join {user} as u on u.id = cmc.userid
-			inner join {modules} as m on m.id = cm.module
-			where cm.course = ? and cm.deletioninprogress = 0
-			and cmc.userid = ?
-			order by section, coursemoduleid asc', array($COURSE->id, $USER->id));
-
-		$sections = [];
-
-		foreach ($section_ids as $i => $section_id) {
-			$section = new StdClass();
-			$section->id = $i;
-			$inner_modules = [];
-			$inner_completed = 0;
-			foreach ($modules as $module) {
-				if ( $module->section == $section_id ) {
-					$mod = new StdClass();
-					$mod->coursemoduleid = $module->coursemoduleid;
-					$mod->completion = $module->completionstate;
-					if ( $mod->completion == 1 || $mod->completion == 2 ) {
-						$inner_completed++;
-					}
-					$inner_modules[] = $mod;
-				}
-			}
-			$section->modules = $inner_modules;
-			if ( count($inner_modules) == 0 ) {
-				$section->completion = false;
-			} else {
-				$section->completion = number_format( 100 * $inner_completed / count($inner_modules), 0 );
-			}
-			array_push($sections, $section);
-		}
-
-		// echo '<pre>';
-		// var_dump($sections);
-		// echo '</pre>';
-
-		return $sections;
-
-
-	}
-
-}
\ No newline at end of file
+    /**
+     * Get completion by sections
+     * @param array $sectionnames
+     * @param array $idsection
+     * @return type
+     */
+    public static function get_completion_by_section($sectionnames, $idsection) {
+
+        global $COURSE, $USER, $DB, $CFG;
+
+        $completion = new \completion_info($COURSE);
+        if ($completion->is_enabled_for_site() == false
+            || $completion->has_activities() == false || $completion->is_enabled() == 0) {
+            return false;
+        }
+
+        $sections = [];
+
+        $fastmodinfo = get_fast_modinfo($COURSE->id);
+        $modinfoscms = $fastmodinfo->get_cms();
+
+        $modules = [];
+        // Il récupère les modules qui ne sont pas en cours de suppression, qui ont l'achèvement d'activité,
+        // et qui sont visibles pour l'user.
+        foreach ($modinfoscms as $cm) {
+            $module = $completion->get_data($cm, true, $USER->id, $fastmodinfo);
+            $module->url = "$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id";
+            $module->section = $cm->section;
+            if ($cm->deletioninprogress == 0 && $cm->completion != 0 && $cm->uservisible) {
+                $module->name = $cm->name;
+                $module->url = "$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id";
+                $modules[] = $module;
+            }
+        }
+
+        $totalcompleted = 0;
+        $totalmodules = 0;
+        foreach ($idsection as $i => $sectionid) {
+            $section = new StdClass();
+            $section->id = $i;
+            $section->name = $sectionnames[$i];
+            $innermodules = [];
+            $innercompleted = 0;
+            foreach ($modules as $module) {
+                if ($module->section == $sectionid) {
+                    $mod = new StdClass();
+                    $mod->coursemoduleid = $module->coursemoduleid;
+                    $mod->completion = $module->completionstate;
+                    $mod->name = $module->name;
+                    $mod->url = $module->url;
+                    if ($mod->completion == 1 || $mod->completion == 2) {
+                        $innercompleted++;
+                    }
+                    $innermodules[] = $mod;
+                }
+            }
+            $section->modules = $innermodules;
+            if (count($innermodules) == 0) {
+                $section->completion = 0;
+            } else {
+                $section->completion = number_format(100 * $innercompleted / count($innermodules), 0);
+            }
+            $totalcompleted += $innercompleted;
+            $totalmodules += count($innermodules);
+            array_push($sections, $section);
+        }
+        if ($totalmodules == 0) {
+            return false;
+        }
+        $progress = new StdClass();
+        $progress->total = number_format(100 * $totalcompleted / $totalmodules, 0);
+        $progress->sections = $sections;
+        return $progress;
+    }
+
+    public static function get_completion_by_section_old() {
+
+        global $COURSE, $DB, $USER;
+
+        $completion = new \completion_info($COURSE);
+        if ($completion->is_enabled_for_site() == false
+            || $completion->has_activities() == false
+            || $completion->is_enabled() == 0) {
+            return false;
+        }
+
+        $modinfo = get_fast_modinfo($COURSE->id);
+
+        $sectionsinfos = $modinfo->get_section_info_all();
+        $sectionids = [];
+        foreach ($sectionsinfos as $section) {
+            array_push($sectionids, $section->__get('id') );
+        }
+
+        $modules = $DB->get_records_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate, cm.section
+            FROM  {course_modules_completion} cmc
+            INNER JOIN {course_modules} cm ON cm.id = cmc.coursemoduleid
+            INNER JOIN {user} u ON u.id = cmc.userid
+            INNER JOIN {modules} m ON m.id = cm.module
+            WHERE cm.course = ? AND cm.deletioninprogress = 0
+            AND cmc.userid = ?
+            ORDER BY section, coursemoduleid ASC',
+            array($COURSE->id, $USER->id));
+
+        $sections = [];
+
+        foreach ($sectionids as $i => $sectionid) {
+            $section = new StdClass();
+            $section->id = $i;
+            $innermodules = [];
+            $innercompleted = 0;
+            foreach ($modules as $module) {
+                if ($module->section == $sectionid) {
+                    $mod = new StdClass();
+                    $mod->coursemoduleid = $module->coursemoduleid;
+                    $mod->completion = $module->completionstate;
+                    if ($mod->completion == 1 || $mod->completion == 2) {
+                        $innercompleted++;
+                    }
+                    $innermodules[] = $mod;
+                }
+            }
+            $section->modules = $innermodules;
+            if (count($innermodules) == 0) {
+                $section->completion = false;
+            } else {
+                $section->completion = number_format(100 * $innercompleted / count($innermodules), 0);
+            }
+            array_push($sections, $section);
+        }
+
+        return $sections;
+    }
+
+}
diff --git a/entity/course_format_iena_cron_action.php b/entity/course_format_iena_cron_action.php
index b6bd6f4bf03fc5a7b0fb38c0041841998b66ac91..d046585d1ea35f7f2c3a4cb3e9b221e634be7b3f 100644
--- a/entity/course_format_iena_cron_action.php
+++ b/entity/course_format_iena_cron_action.php
@@ -1,149 +1,141 @@
-<?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 15/03/18
-	 * Time: 11:33
-	 */
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * Class course_format_iena_cron_action
-	 * This class hide and show section with setting present in table format_iena
-	 * This class send message with setting present in table format_iena
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille / Michaël Lebeau
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	// include('../../lib.php');
-	// include('../../../../config.php');
-	
-	
-	class course_format_iena_cron_action
-	{
-		
-		
-
-		/**
-		 * Récupère le nombre de jours avant le rendu/présence pour envoyer une notification
-		 * @return type
-		 */
-		public function cron_message()
-		{
-			global $DB, $USER, $CFG;
-
-			$sections = $DB->get_records_sql("SELECT fo1.sectionid, fo1.value daysnotif, fo2.value daterendu, fo3.value presence, fo4.value msg FROM {course_format_options} fo1 LEFT JOIN {course_format_options} fo2 ON fo1.sectionid = fo2.sectionid LEFT JOIN {course_format_options} fo3 ON fo1.sectionid = fo3.sectionid LEFT JOIN {course_format_options} fo4 ON fo1.sectionid = fo4.sectionid WHERE fo1.format='iena' AND fo1.name ='daysnotif' AND (fo1.value IS NOT NULL) AND fo1.value != -1 AND fo2.name='daterendu' AND fo3.name='presence' AND fo4.name='msg'");
-			foreach ($sections as $section) {
-				$requete = $DB->get_record('course_sections', array('id' => $section->sectionid));
-				$date_notif = $this->is_notif($section);
-				if ($date_notif == false) {
-					continue;
-				}
-				$this->iena_send_message($requete, $section, $section->msg);
-	
-			}
-		}
-		
-		/**
-		 * Check if it's time to send a notif by comparing the date withe the numbers of days before sending one in the db
-		 * @param $section
-		 * @return bool true if it's time to send a notif
-		 */
-		private function is_notif($section)
-		{
-			//On compare la date d'aujourd'hui avec le timestamp - daysnotifs
-			$date_now=date('Ymd');
-			$timenotif=strtotime('-'.$section->daysnotif.' days', $section->daterendu);
-			$date_notif=date('Ymd', $timenotif);
-			if($date_notif==$date_now){
-				return true;
-			}
-			return false;
-		}
-		
-		/**
-		 * @param $requete
-		 * @param $section
-		 * @throws coding_exception
-		 * @throws dml_exception
-		 */
-		private function iena_send_message($requete, $section, $message)
-		{
-			global $DB, $CFG, $USER;
-			$course_ctx = context_course::instance($requete->course);
-
-			//À vérifier : on récupère tous les utilisateurs, même les invités
-			//2. $students = get_role_users(5 , $context) (the 5 represents the role-id with role.shortname = 'student')
-			//
-			$students = get_enrolled_users($course_ctx);
-			$course = $DB->get_record('course', array('id' => $requete->course), '*', MUST_EXIST);
-
-			$messageContent = false;
-
-			$messageContent .= "<h1>Rappel</h1>";
-			$messageContent .= "<h2>$course->fullname</h2>";
-
-			$date_jour = date('d/m', $section->daterendu);
-			$date_heure = date('H:i', $section->daterendu);
-
-			// 0 : NC
-			// 1 : work in the classroom
-			// 2 : online work
-			if ( $section->presence < 2 ) {
-				//$messageContent .= "<p>La séance de cours <strong>$requete->name</strong> aura lieu le $date_jour à $date_heure.</p>";
-				$messageContent .= "$message";
-			} else if ( $section->presence == 2 ) {
-				//$messageContent .= "<p>Le travail de la séance de cours à distance <strong>$requete->name</strong> est à finir pour le $date_jour à $date_heure.</p>";
-				$messageContent .= "$message";
-			}
-
-			$messageContent .= "<p>Lien vers le cours : <a href='" . $CFG->wwwroot . "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a></p>";
-
-			//Create message
-			$message = new \core\message\message();
-			$message->component = 'moodle';
-			$message->name = 'instantmessage';
-			$message->userfrom = $USER;
-			$message->courseid = $course->id;
-			$message->notification = '1';
-			$message->contexturl = $CFG->wwwroot . "/course/view.php?id=" . $course->id . "#section-" . $requete->section;
-			$message->contexturlname = $course->fullname;
-			$message->fullmessageformat = FORMAT_HTML;
-			$log = "Messages sent for section $requete->name of course $course->fullname (id $course->id) to ";
-			$studs_counter = 0;
-			foreach ($students as $student) {
-				$studs_counter++;
-				$message->userto = $student;
-				$studs[] = 
-				$message->smallmessage = $messageContent;
-				$message->fullmessage = $messageContent;
-				$message->fullmessagehtml = $messageContent;
-				$message->subject = "Rappel : " . $course->fullname . " — " . $requete->name;
-				// $message->subject = $messageContent;
-				message_send($message);
-			}
-			$log .= $studs_counter . " students.";
-			echo $log;
-		}
-		
-		
-	}
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * Class course_format_iena_cron_action
+ * This class hide and show section with setting present in table format_iena
+ * This class send message with setting present in table format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille / Michaël Lebeau
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class course_format_iena_cron_action {
+    /**
+     * Récupère le nombre de jours avant le rendu/présence pour envoyer une notification
+     * @return type
+     */
+    public function cron_message() {
+        global $DB, $USER, $CFG;
+
+        $sections = $DB->get_records_sql("SELECT fo1.sectionid, fo1.value daysnotif,
+            fo2.value daterendu, fo3.value presence, fo4.value msg
+            FROM {course_format_options} fo1
+            LEFT JOIN {course_format_options} fo2 ON fo1.sectionid = fo2.sectionid
+            LEFT JOIN {course_format_options} fo3 ON fo1.sectionid = fo3.sectionid
+            LEFT JOIN {course_format_options} fo4 ON fo1.sectionid = fo4.sectionid
+            WHERE fo1.format='iena'
+            AND fo1.name ='daysnotif'
+            AND (fo1.value IS NOT NULL)
+            AND fo1.value != -1
+            AND fo2.name='daterendu'
+            AND fo3.name='presence'
+            AND fo4.name='msg'");
+        foreach ($sections as $section) {
+            $requete = $DB->get_record('course_sections', array('id' => $section->sectionid));
+            $datenotif = $this->is_notif($section);
+            if ($datenotif == false) {
+                continue;
+            }
+            if ((empty($section->msg)) && ($section->presence == 2)) {
+                $this->iena_send_message($requete, $section, get_config('format_iena', 'msg_dist'));
+            } else if ((empty($section->msg)) && ($section->presence == 1)) {
+                $this->iena_send_message($requete, $section, get_config('format_iena', 'msg_pres'));
+            } else {
+                $this->iena_send_message($requete, $section, $section->msg);
+            }
+        }
+    }
+
+    /**
+     * Check if it's time to send a notif by comparing the date withe the numbers of days before sending one in the db
+     * @param $section
+     * @return bool true if it's time to send a notif
+     */
+    private function is_notif($section) {
+        // On compare la date d'aujourd'hui avec le timestamp - daysnotifs.
+        $datenow = date('Ymd');
+        $timenotif = strtotime('-'.$section->daysnotif.' days', $section->daterendu);
+        $datenotif = date('Ymd', $timenotif);
+        if ($datenotif == $datenow) {
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * @param $requete
+     * @param $section
+     * @throws coding_exception
+     * @throws dml_exception
+     */
+    private function iena_send_message($requete, $section, $message) {
+        global $DB, $CFG, $USER;
+        $coursectx = context_course::instance($requete->course);
+
+        // A vérifier : on récupère tous les utilisateurs, même les invités.
+        // 2. $students = get_role_users(5 , $context) (the 5 represents the role-id with role.shortname = 'student').
+        $students = get_enrolled_users($coursectx);
+        $course = $DB->get_record('course', array('id' => $requete->course), '*', MUST_EXIST);
+
+        $messagecontent = false;
+
+        $messagecontent .= "<h1>Rappel</h1>";
+        $messagecontent .= "<h2>$course->fullname</h2>";
+
+        $datejour = date('d/m', $section->daterendu);
+        $dateheure = date('H:i', $section->daterendu);
+
+        // 0 : NC
+        // 1 : work in the classroom
+        // 2 : online work
+        if ( $section->presence < 2 ) {
+            $messagecontent .= "$message";
+        } else if ( $section->presence == 2 ) {
+            $messagecontent .= "$message";
+        }
+
+        $messagecontent .= "<p>Lien vers le cours : <a href='" . $CFG->wwwroot .
+            "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a></p>";
+
+        // Create message.
+        $message = new \core\message\message();
+        $message->component = 'moodle';
+        $message->name = 'instantmessage';
+        $message->userfrom = $USER;
+        $message->courseid = $course->id;
+        $message->notification = '1';
+        $message->contexturl = $CFG->wwwroot . "/course/view.php?id=" . $course->id . "#section-" . $requete->section;
+        $message->contexturlname = $course->fullname;
+        $message->fullmessageformat = FORMAT_HTML;
+        $log = "Messages sent for section $requete->name of course $course->fullname (id $course->id) to ";
+        $studscounter = 0;
+        foreach ($students as $student) {
+            $studscounter++;
+            $message->userto = $student;
+            $studs[] =
+            $message->smallmessage = $messagecontent;
+            $message->fullmessage = $messagecontent;
+            $message->fullmessagehtml = $messagecontent;
+            $message->subject = "Rappel : " . $course->fullname . " — " . $requete->name;
+            message_send($message);
+        }
+        $log .= $studscounter . " students.";
+        echo $log;
+    }
+}
diff --git a/entity/course_format_iena_groups.php b/entity/course_format_iena_groups.php
index 466a39477d870394a7c1da0e9ec2131fab570d1f..2a4ef2bb26cac6787720da75e375875d66fe9768 100644
--- a/entity/course_format_iena_groups.php
+++ b/entity/course_format_iena_groups.php
@@ -1,98 +1,99 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-	/**
-	 *
-	 * course_format_iena_sections
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille / Michaël Lebeau
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	class course_format_iena_groups
-	{
-		/** @var int id of group */
-		public $id;
-		/** @var int id of course */
-		public $id_course;
-		/** @var string idnumber of group */
-		public $idnumber;
-		/** @var string name of group */
-		public $name;
-		/** @var string description of group */
-		public $description;
-
-		/** @var array<userid>  */
-		public $list_userid;
-		
-		
-		/**
-		 * @param $id_course
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_groups_by_id_course($id_course)
-		{
-			global $DB;
-			$requete = $DB->get_records_sql('SELECT id FROM {groups} WHERE courseid = ?', array($id_course));
-			$groups = array();
-			$i = 0;
-			foreach ($requete as $value) {
-				$group = new course_format_iena_groups();
-				$group->get_group_by_id_group($value->id);
-				$groups[$i] = $group;
-				$i++;
-			}
-			
-			return $groups;
-		}
-		
-		
-		/**
-		 * @param $id_section
-		 * @throws dml_exception
-		 */
-		public function get_group_by_id_group($id_group)
-		{
-			global $DB;
-			$requete = $DB->get_record_sql('SELECT * FROM {groups} WHERE id = ?', array($id_group));
-			$this->id = $requete->id;
-			$this->id_course = $requete->courseid;
-			$this->idnumber = "id_groupe".$requete->id;
-			$this->name = $requete->name;
-			$this->description = $requete->description;
-			$this->list_userid = $DB->get_records_sql('SELECT userid FROM {groups_members} WHERE groupid = ?', array($id_group));
-			
-		}
-		
-		/**
-		 * 
-		 * @gparam $id_course
-		 * @return array
-		 */
-		public function get_students_group($id_course)
-		{
-			global $DB;
-			$students_group = $DB->get_records_sql('SELECT gm.userid, gm.groupid FROM {groups} as g 
-				inner join {groups_members} as gm on gm.groupid=g.id 
-				WHERE g.courseid = ?', array($id_course));
-			return $students_group;
-		}
-		
-	}
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * course_format_iena_sections
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille / Michaël Lebeau
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class course_format_iena_groups {
+    /** @var int id of group */
+    public $id;
+    /** @var int id of course */
+    public $idcourse;
+    /** @var string idnumber of group */
+    public $idnumber;
+    /** @var string name of group */
+    public $name;
+    /** @var string description of group */
+    public $description;
+
+    /** @var array<userid>  */
+    public $listuserid;
+
+    /**
+     * @param $id_course
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_groups_by_id_course($idcourse) {
+        global $DB;
+        $requete = $DB->get_records_sql('SELECT id
+            FROM {groups}
+            WHERE courseid = ?',
+            array($idcourse));
+        $groups = array();
+        $i = 0;
+        foreach ($requete as $value) {
+            $group = new course_format_iena_groups();
+            $group->get_group_by_id_group($value->id);
+            $groups[$i] = $group;
+            $i++;
+        }
+
+        return $groups;
+    }
+
+    /**
+     * @param $id_section
+     * @throws dml_exception
+     */
+    public function get_group_by_id_group($idgroup) {
+        global $DB;
+        $requete = $DB->get_record_sql('SELECT *
+            FROM {groups}
+            WHERE id = ?',
+            array($idgroup));
+        $this->id = $requete->id;
+        $this->idcourse = $requete->courseid;
+        $this->idnumber = "id_groupe".$requete->id;
+        $this->name = $requete->name;
+        $this->description = $requete->description;
+        $this->listuserid = $DB->get_records_sql('SELECT userid
+            FROM {groups_members}
+            WHERE groupid = ?',
+            array($idgroup));
+    }
+
+    /**
+     *
+     * @gparam $id_course
+     * @return array
+     */
+    public function get_students_group($idcourse) {
+        global $DB;
+        $studentsgroup = $DB->get_records_sql('SELECT gm.userid, gm.groupid
+            FROM {groups} g
+            INNER JOIN {groups_members} gm ON gm.groupid=g.id
+            WHERE g.courseid = ?',
+            array($idcourse));
+        return $studentsgroup;
+    }
+}
diff --git a/entity/course_format_iena_message.php b/entity/course_format_iena_message.php
index c673ae56dd946d2cbf5479c499463dcfe6c12375..c90c969069313df9e4edd16c58ec5a06334f11e8 100644
--- a/entity/course_format_iena_message.php
+++ b/entity/course_format_iena_message.php
@@ -1,11 +1,4 @@
 <?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 13/03/18
-	 * Time: 11:26
-	 */
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -20,45 +13,36 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * course_format_iena_sections
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2021 Softia/Université lorraine
-	 * @author     Delaruelle Myriam
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
+/**
+ *
+ * course_format_iena_sections
+ *
+ * @package    format_iena
+ * @copyright  2021 Softia/Université lorraine
+ * @author     Delaruelle Myriam
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
 
-	require_once("{$CFG->libdir}/formslib.php");
+require_once("{$CFG->libdir}/formslib.php");
 
+class course_format_iena_message extends moodleform {
+    public function definition() {
+        // TODO: Implement definition() method.
 
-	class course_format_iena_message extends moodleform
-	{
-		public function definition()
-		{
-			// TODO: Implement definition() method.
-		
-			$mform = $this->_form; // Don't forget the underscore!
+        $mform = $this->_form;
+        $description = "";
 
-			$description = "";
-			
-			$mform->addElement('editor', 'summary', get_string('summary', 'format_iena'));
-			$mform->setType('summary', PARAM_RAW);
-			$mform->addRule('summary', get_string('error'), 'required', null, null, false, false);
-			$mform->setDefault('summary', array('text' => $description));
-			$mform->addElement('hidden', 'back_url', '');
-			$mform->setType('back_url', PARAM_TEXT);
-			$mform->setDefault('back_url', $this->_customdata['back_url']);
-			$mform->addElement('hidden', 'students', '');
-			$mform->setType('students', PARAM_TEXT);
-			$mform->setDefault('students', $this->_customdata['students']);
+        $mform->addElement('editor', 'summary', get_string('summary', 'format_iena'));
+        $mform->setType('summary', PARAM_RAW);
+        $mform->addRule('summary', get_string('error'), 'required', null, null, false, false);
+        $mform->setDefault('summary', array('text' => $description));
+        $mform->addElement('hidden', 'back_url', '');
+        $mform->setType('back_url', PARAM_TEXT);
+        $mform->setDefault('back_url', $this->_customdata['back_url']);
+        $mform->addElement('hidden', 'students', '');
+        $mform->setType('students', PARAM_TEXT);
+        $mform->setDefault('students', $this->_customdata['students']);
 
-			$this->add_action_buttons(true, "Envoyer");
-			
-			
-		}
-		
-	}
\ No newline at end of file
+        $this->add_action_buttons(true, "Envoyer");
+    }
+}
diff --git a/entity/course_format_iena_section_ressources.php b/entity/course_format_iena_section_ressources.php
index 30e4fcd0cd550d354f832434428342ebeb0556fa..f1a4cd9b220f3fc9cb6bb053f71f86274cb8b76f 100644
--- a/entity/course_format_iena_section_ressources.php
+++ b/entity/course_format_iena_section_ressources.php
@@ -1,221 +1,234 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-	/**
-	 *
-	 * course_format_iena_section_ressources
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille/Thomas Fradet
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	class course_format_iena_section_ressources
-	{
-		/** @var int Id of ressource */
-		public $id;
-		/** @var string name of ressource */
-		public $name;
-		/** @var string type of ressource */
-		public $type;
-		/** @var int module id of ressource */
-		public $module;
-		/** @var string intro of ressource */
-		public $descrition;
-		/** @var course_format_iena_section_ressources section */
-		public $section;
-		/** @var module hide indicator (from table format_iena_settings) */
-		public $ressource_hide_indic;
-		
-		
-		/**
-		 * @param $id_module
-		 * @return mixed
-		 * @throws dml_exception
-		 */
-		public function get_ressource_hide_indicator($id_module)
-		{
-			global $DB;
-			$module_state = $DB->get_record_sql('SELECT hide from {format_iena_settings} where cmid = ?', array($id_module));
-			return $module_state->hide;
-		}
-
-		/**
-		 * @param $id_module
-		 * @return mixed
-		 * @throws dml_exception
-		 */
-		public function is_followed_ressources($cm_ids)
-		{
-			global $DB;
-			$module_state = $DB->get_records_sql('SELECT hide from {format_iena_settings} where cmid = ?', $cm_ids);
-			// echo "<pre>";
-			// var_dump($module_state);
-			// echo "</pre>";
-			return $module_state;
-		}
-		
-		/**
-		 * @param $id_section
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_ressources_by_id_section($id_section)
-		{
-			global $DB;
-			
-			$requete = $DB->get_records_sql('SELECT id FROM {course_modules} WHERE section = ? AND deletioninprogress = 0', array($id_section));
-			$ressources = array();
-			$i = 0;
-			foreach ($requete as $value) {
-				$ressource = new course_format_iena_section_ressources();
-				$ressource->get_ressource_by_id($value->id);
-				$ressources[$i] = $ressource;
-				$i++;
-			}
-			
-			return $ressources;
-		}
-		
-		/**
-		 * @param $id_section
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_ressources_completion_on_by_id_section($id_section)
-		{
-			global $COURSE, $DB;
-
-			// !!! format_iena_settings.hide stands for this module is followed by teacher in a section following indicator — this course module is NOT hidden
-
-			// visible : disponibility for studient (right to access), visibleoncoursepage : visibility for student (display on course page) ; 1 : true, 0 : false. 
-
-			$course = course_get_format($COURSE)->get_course();
-
-
-			// search only modules by general course format parameters
-			// count only if it is follewed by teacher
-			// $if_followed = $course->restrictedbreadcrum == 1;
-			// count even if it is "hidden on course page but available"
-			$even_if_hidden_but_available = $course->allmodulesbreadcrum == 1;
-
-			if ( $even_if_hidden_but_available ) {
-				$requete = $DB->get_records_sql('SELECT id FROM {course_modules} WHERE section = ? AND deletioninprogress = 0
-					AND visible = 1
-					AND completion != 0', array($id_section));
-			} else {
-				$requete = $DB->get_records_sql('SELECT id FROM {course_modules} WHERE section = ? AND deletioninprogress = 0
-					AND visible = 1
-					AND visibleoncoursepage = 1
-					AND completion != 0', array($id_section));
-			}
-			
-			$ressources = array();
-			$i = 0;
-			foreach ($requete as $value) {
-				$ressource = new course_format_iena_section_ressources();
-				$ressource->get_ressource_by_id($value->id);
-				$ressources[$i] = $ressource;
-				$i++;
-			}
-			
-			return $ressources;
-		}
-		
-		
-		/**
-		 * @param $id_course_modules
-		 * @throws dml_exception
-		 */
-		public function get_ressource_by_id($id_course_modules)
-		{
-			
-			global $DB;
-			if ($id_course_modules) {
-				$this->id = $id_course_modules;
-				$requete = $DB->get_record_sql('SELECT * FROM {course_modules} WHERE id = ? AND deletioninprogress = 0', array($id_course_modules));
-				$id_instance = $requete->instance;
-				$id_module = $requete->module;
-				if ($id_module) {
-					$modules = $DB->get_record_sql('SELECT * FROM {modules} WHERE id = ?', array($id_module));
-				}
-				if ($modules->name) {
-					$instance = $DB->get_record_sql('SELECT * FROM {' . $modules->name . '} WHERE id = ?', array($id_instance));
-				}
-				if ($instance->name) {
-					$this->name = $instance->name;
-				}
-				$this->descrition = $instance->intro;
-				$this->type = $modules->name;
-				$this->module = $modules->id;
-				// $this->section = new course_format_iena_section_ressources();
-				$this->section = new course_format_iena_sections();
-				$this->section->get_section_by_id_section($requete->section);
-			}
-		}
-		
-		/**
-		 * @param $userId
-		 * @param $courseID
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_completions_by_userid($userId, $courseID)
-		{
-			global $DB;
-			$modules_completion_infos = $DB->get_records_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate
-				FROM  {course_modules_completion} as cmc
-				inner join {course_modules} as cm on cm.id = cmc.coursemoduleid
-				inner join {user} as u on u.id = cmc.userid
-				inner join {modules} as m on m.id = cm.module
-				where cm.course = ? and cm.deletioninprogress = 0
-				and cmc.userid = ?
-				order by section, coursemoduleid asc', array($courseID, $userId));
-			
-			return $modules_completion_infos;
-		}
-		
-		/**
-		 * @param $userId
-		 * @param $courseID
-		 * @param $moduleID
-		 * @return mixed
-		 * @throws dml_exception
-		 */
-		public function get_completions_by_module($userId, $courseID, $moduleID)
-		{
-			global $DB, $COURSE;
-
-			$course = course_get_format($COURSE)->get_course();
-			
-			$modules_completion_infos = $DB->get_record_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate
-				FROM  {course_modules_completion} as cmc
-				inner join {course_modules} as cm on cm.id = cmc.coursemoduleid
-				inner join {user} as u on u.id = cmc.userid
-				inner join {modules} as m on m.id = cm.module
-				where cm.course = ? and cm.deletioninprogress = 0
-				and cmc.userid = ?
-				and cmc.coursemoduleid = ?
-				order by section, coursemoduleid asc', array($courseID, $userId, $moduleID));
-
-			return $modules_completion_infos;
-		}
-		
-	}
-
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * course_format_iena_section_ressources
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille/Thomas Fradet
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class course_format_iena_section_ressources {
+    /** @var int Id of ressource */
+    public $id;
+    /** @var string name of ressource */
+    public $name;
+    /** @var string type of ressource */
+    public $type;
+    /** @var int module id of ressource */
+    public $module;
+    /** @var string intro of ressource */
+    public $description;
+    /** @var course_format_iena_section_ressources section */
+    public $section;
+    /** @var module hide indicator (from table format_iena_settings) */
+    public $ressourcehideindic;
+
+    /**
+     * @param $idmodule
+     * @return mixed
+     * @throws dml_exception
+     */
+    public function get_ressource_hide_indicator($idmodule) {
+        global $DB;
+        $modulestate = $DB->get_record_sql('SELECT hide
+            FROM {format_iena_settings}
+            WHERE cmid = ?',
+            array($idmodule));
+        return $modulestate->hide;
+    }
+
+    /**
+     * @param $idmodule
+     * @return mixed
+     * @throws dml_exception
+     */
+    public function is_followed_ressources($cmids) {
+        global $DB;
+        $modulestate = $DB->get_records_sql('SELECT hide
+            FROM {format_iena_settings}
+            WHERE cmid = ?',
+            $cmids);
+        return $modulestate;
+    }
+
+    /**
+     * @param $idsection
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_ressources_by_id_section($idsection) {
+        global $DB;
+
+        $requete = $DB->get_records_sql('SELECT id
+            FROM {course_modules}
+            WHERE section = ?
+            AND deletioninprogress = 0',
+            array($idsection));
+        $ressources = array();
+        $i = 0;
+        foreach ($requete as $value) {
+            $ressource = new course_format_iena_section_ressources();
+            $ressource->get_ressource_by_id($value->id);
+            $ressources[$i] = $ressource;
+            $i++;
+        }
+
+        return $ressources;
+    }
+
+    /**
+     * @param $idsection
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_ressources_completion_on_by_id_section($idsection) {
+        global $COURSE, $DB;
+
+        // Format_iena_settings.hide stands for this module is followed by teacher in a section following indicator —
+        // this course module is NOT hidden.
+
+        // Visible : disponibility for studient (right to access), visibleoncoursepage : visibility for student
+        // (display on course page) ; 1 : true, 0 : false.
+
+        $course = course_get_format($COURSE)->get_course();
+
+        // Search only modules by general course format parameters
+        // count only if it is follewed by teacher
+        // count even if it is "hidden on course page but available".
+        $evenifhiddenbutavailable = $course->allmodulesbreadcrum == 1;
+
+        if ($evenifhiddenbutavailable) {
+            $requete = $DB->get_records_sql('SELECT id
+                FROM {course_modules}
+                WHERE section = ?
+                AND deletioninprogress = 0
+                AND visible = 1
+                AND completion != 0',
+                array($idsection));
+        } else {
+            $requete = $DB->get_records_sql('SELECT id
+                FROM {course_modules}
+                WHERE section = ?
+                AND deletioninprogress = 0
+                AND visible = 1
+                AND visibleoncoursepage = 1
+                AND completion != 0',
+                array($idsection));
+        }
+
+        $ressources = array();
+        $i = 0;
+        foreach ($requete as $value) {
+            $ressource = new course_format_iena_section_ressources();
+            $ressource->get_ressource_by_id($value->id);
+            $ressources[$i] = $ressource;
+            $i++;
+        }
+
+        return $ressources;
+    }
+
+    /**
+     * @param $idcoursemodules
+     * @throws dml_exception
+     */
+    public function get_ressource_by_id($idcoursemodules) {
+
+        global $DB;
+        if ($idcoursemodules) {
+            $this->id = $idcoursemodules;
+            $requete = $DB->get_record_sql('SELECT *
+                FROM {course_modules}
+                WHERE id = ?
+                AND deletioninprogress = 0',
+                array($idcoursemodules));
+            $idinstance = $requete->instance;
+            $idmodule = $requete->module;
+            if ($idmodule) {
+                $modules = $DB->get_record_sql('SELECT *
+                    FROM {modules}
+                    WHERE id = ?',
+                    array($idmodule));
+            }
+            if ($modules->name) {
+                $instance = $DB->get_record_sql('SELECT *
+                    FROM {' . $modules->name . '}
+                    WHERE id = ?',
+                    array($idinstance));
+            }
+            if ($instance->name) {
+                $this->name = $instance->name;
+            }
+            $this->descrition = $instance->intro;
+            $this->type = $modules->name;
+            $this->module = $modules->id;
+            $this->section = new course_format_iena_sections();
+            $this->section->get_section_by_id_section($requete->section);
+        }
+    }
+
+    /**
+     * @param $userid
+     * @param $courseid
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_completions_by_userid($userid, $courseid) {
+        global $DB;
+        $modulescompletioninfos = $DB->get_records_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate
+            FROM  {course_modules_completion} cmc
+            INNER JOIN {course_modules} cm ON cm.id = cmc.coursemoduleid
+            INNER JOIN {user} u ON u.id = cmc.userid
+            INNER JOIN {modules} m ON m.id = cm.module
+            WHERE cm.course = ?
+            AND cm.deletioninprogress = 0
+            AND cmc.userid = ?
+            ORDER BY section, coursemoduleid ASC',
+            array($courseid, $userid));
+
+        return $modulescompletioninfos;
+    }
+
+    /**
+     * @param $userid
+     * @param $courseid
+     * @param $moduleid
+     * @return mixed
+     * @throws dml_exception
+     */
+    public function get_completions_by_module($userid, $courseid, $moduleid) {
+        global $DB, $COURSE;
+
+        $course = course_get_format($COURSE)->get_course();
+
+        $modulescompletioninfos = $DB->get_record_sql('SELECT cmc.id, cmc.coursemoduleid, cmc.userid, cmc.completionstate
+            FROM  {course_modules_completion} cmc
+            INNER JOIN {course_modules} cm ON cm.id = cmc.coursemoduleid
+            INNER JOIN {user} u ON u.id = cmc.userid
+            INNER JOIN {modules} m ON m.id = cm.module
+            WHERE cm.course = ?
+            AND cm.deletioninprogress = 0
+            AND cmc.userid = ?
+            AND cmc.coursemoduleid = ?
+            ORDER BY section, coursemoduleid ASC',
+            array($courseid, $userid, $moduleid));
+
+        return $modulescompletioninfos;
+    }
+}
diff --git a/entity/course_format_iena_sections.php b/entity/course_format_iena_sections.php
index 16432599bae9f5f190003a89510eade6947e02e8..2a7f5e6d0d4e8c06f582124bb745602114223f01 100644
--- a/entity/course_format_iena_sections.php
+++ b/entity/course_format_iena_sections.php
@@ -1,285 +1,264 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * course_format_iena_sections
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille / Michaël Lebeau
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	class course_format_iena_sections
-	{
-		/** @var int id of section */
-		public $id;
-		/** @var string name of section */
-		public $name;
-		/** @var int id of course */
-		public $id_course;
-		/** @var block_career_resources array<Ressource> resources */
-		public $resources;
-		/** @var date */
-		public $date;
-		/** @var string availability */
-		public $availability;
-		public $visibility;
-		
-		
-		/**
-		 * @param $id_course
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_sections_by_id_course($id_course)
-		{
-			global $DB;
-			$requete = $DB->get_records_sql('SELECT * FROM {course_sections} WHERE course = ? ORDER BY section', array($id_course));
-            // $numsection = $DB->get_record_sql('SELECT value FROM {course_format_options} WHERE courseid = ? AND name = ?', array($id_course,"numsections"));
-            return $requete;
-            $sections = array();
-			$i = 0;
-			foreach ($requete as $value) {
-			    // if ($value->section > $numsection->value){
-			    //     continue;
-  			    //          }
-				$section = new course_format_iena_sections();
-				$section->get_section_by_id_section($value->id);
-				$sections[$i] = $section;
-				$i++;
-			}
-			// var_dump($sections);
-			return $sections;
-		}
-		
-		
-		/**
-		 * @param $id_section
-		 * @throws dml_exception
-		 */
-		public function get_section_by_id_section($id_section)
-		{
-			global $DB;
-			$requete = $DB->get_record_sql('SELECT * FROM {course_sections} WHERE id = ?', array($id_section));
-			$this->id = $requete->id;
-			$this->name = $requete->name;
-			$this->id_course = $requete->course;
-			
-			if (!$this->name) {
-				$this->name = get_string('section', 'format_iena') . " " . $requete->section;
-			}
-		}
-		
-		/**
-		 * @param $id_section
-		 * @return mixed
-		 * @throws dml_exception
-		 */
-		public function get_section_settings_by_id_section($id_section)
-		{
-			global $DB;
-			$requete = $DB->get_record_sql('SELECT * FROM {format_iena} WHERE id_section = ?', array($id_section));
-			return $requete;
-		}
-		
-		
-		/**
-		 * @param $id_section
-		 * @param $id_user
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_completion_by_sectionID_userID($id_section, $id_user)
-		{
-			global $DB;
-			$requete = $DB->get_records_sql('SELECT cmc.id as moduleid, cm.course, cm.section, cmc.userid, cmc.completionstate
-                                        FROM {course_modules} as cm
-                                        inner join  {course_modules_completion} as cmc on cmc.coursemoduleid = cm.id
-                                        WHERE cm.section= ? AND cmc.userid= ?
-                                        order by cm.section, cmc.userid', array($id_section, $id_user));
-			return $requete;
-		}
-		
-		/**
-		 * @param $id_section
-		 * @return array
-		 * @throws dml_exception
-		 */
-		public function get_hidden_modules_by_section($id_section)
-		{
-			global $DB;
-			$requete = $DB->get_records_sql('SELECT *
-                                        FROM {format_iena_settings}
-                                        WHERE sectionid =?', array($id_section));
-			return $requete;
-		}
-		
-	
-    /**
-     * @return mixed
-     */
-    public function getId()
-    {
-        return $this->id;
-    }
-
-    /**
-     * @param mixed $id
-     *
-     * @return self
-     */
-    public function setId($id)
-    {
-        $this->id = $id;
-
-        return $this;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getName()
-    {
-        return $this->name;
-    }
-
-    /**
-     * @param mixed $name
-     *
-     * @return self
-     */
-    public function setName($name)
-    {
-        $this->name = $name;
-
-        return $this;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getIdCourse()
-    {
-        return $this->id_course;
-    }
-
-    /**
-     * @param mixed $id_course
-     *
-     * @return self
-     */
-    public function setIdCourse($id_course)
-    {
-        $this->id_course = $id_course;
-
-        return $this;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getResources()
-    {
-        return $this->resources;
-    }
-
-    /**
-     * @param mixed $resources
-     *
-     * @return self
-     */
-    public function setResources($resources)
-    {
-        $this->resources = $resources;
-
-        return $this;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getDate()
-    {
-        return $this->date;
-    }
-
-    /**
-     * @param mixed $date
-     *
-     * @return self
-     */
-    public function setDate($date)
-    {
-        $this->date = $date;
-
-        return $this;
-    }
-
-    /**
-     * @return mixed
-     */
-    public function getAvailability()
-    {
-        return $this->availability;
-    }
-
-    /**
-     * @param mixed $availability
-     *
-     * @return self
-     */
-    public function setAvailability($availability)
-    {
-        $this->availability = $availability;
-
-        return $this;
-    }
-
-
-
-    /**
-     * @return mixed
-     */
-    public function getVisibility()
-    {
-        return $this->visibility;
-    }
-
-    /**
-     * @param mixed $visibility
-     *
-     * @return self
-     */
-    public function setVisibility($visibility)
-    {
-        $this->visibility = $visibility;
-
-        return $this;
-    }
-
-
-    public function toArray(){
-    	$vars = [];
-	    foreach($this as $varName => $varValue) {
-	        $vars[$varName] = $varValue;
-	    }
-
-	    return $vars;
-    }
-}
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * course_format_iena_sections
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille / Michaël Lebeau
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+class course_format_iena_sections {
+    /** @var int id of section */
+    public $id;
+    /** @var string name of section */
+    public $name;
+    /** @var int id of course */
+    public $idcourse;
+    /** @var block_career_resources array<Ressource> resources */
+    public $resources;
+    /** @var date */
+    public $date;
+    /** @var string availability */
+    public $availability;
+    public $visibility;
+
+    /**
+     * @param $idcourse
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_sections_by_id_course($idcourse) {
+        global $DB;
+        $requete = $DB->get_records_sql('SELECT *
+            FROM {course_sections}
+            WHERE course = ?
+            ORDER BY section',
+            array($idcourse));
+
+        return $requete;
+        $sections = array();
+        $i = 0;
+        foreach ($requete as $value) {
+            $section = new course_format_iena_sections();
+            $section->get_section_by_id_section($value->id);
+            $sections[$i] = $section;
+            $i++;
+        }
+        return $sections;
+    }
+
+    /**
+     * @param $idsection
+     * @throws dml_exception
+     */
+    public function get_section_by_id_section($idsection) {
+        global $DB;
+        $requete = $DB->get_record_sql('SELECT *
+            FROM {course_sections}
+            WHERE id = ?',
+            array($idsection));
+        $this->id = $requete->id;
+        $this->name = $requete->name;
+        $this->id_course = $requete->course;
+
+        if (!$this->name) {
+            $this->name = get_string('section', 'format_iena') . " " . $requete->section;
+        }
+    }
+
+    /**
+     * @param $idsection
+     * @return mixed
+     * @throws dml_exception
+     */
+    public function get_section_settings_by_id_section($idsection) {
+        global $DB;
+        $requete = $DB->get_record_sql('SELECT *
+            FROM {format_iena}
+            WHERE id_section = ?',
+            array($idsection));
+        return $requete;
+    }
+
+    /**
+     * @param $idsection
+     * @param $iduser
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_completion_by_sectionID_userID($idsection, $iduser) {
+        global $DB;
+        $requete = $DB->get_records_sql('SELECT cmc.id as moduleid, cm.course, cm.section, cmc.userid, cmc.completionstate
+            FROM {course_modules} cm
+            INNER JOIN  {course_modules_completion} cmc ON cmc.coursemoduleid = cm.id
+            WHERE cm.section= ?
+            AND cmc.userid= ?
+            ORDER BY cm.section, cmc.userid',
+            array($idsection, $iduser));
+        return $requete;
+    }
+
+    /**
+     * @param $idsection
+     * @return array
+     * @throws dml_exception
+     */
+    public function get_hidden_modules_by_section($idsection) {
+        global $DB;
+        $requete = $DB->get_records_sql('SELECT *
+            FROM {format_iena_settings}
+            WHERE sectionid =?',
+            array($idsection));
+        return $requete;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getId() {
+        return $this->id;
+    }
+
+    /**
+     * @param mixed $id
+     *
+     * @return self
+     */
+    public function setId($id) {
+        $this->id = $id;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getName() {
+        return $this->name;
+    }
+
+    /**
+     * @param mixed $name
+     *
+     * @return self
+     */
+    public function setName($name) {
+        $this->name = $name;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getIdCourse() {
+        return $this->id_course;
+    }
+
+    /**
+     * @param mixed $id_course
+     *
+     * @return self
+     */
+    public function setIdCourse($idcourse) {
+        $this->id_course = $idcourse;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getResources() {
+        return $this->resources;
+    }
+
+    /**
+     * @param mixed $resources
+     *
+     * @return self
+     */
+    public function setResources($resources) {
+        $this->resources = $resources;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getDate() {
+        return $this->date;
+    }
+
+    /**
+     * @param mixed $date
+     *
+     * @return self
+     */
+    public function setDate($date) {
+        $this->date = $date;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getAvailability() {
+        return $this->availability;
+    }
+
+    /**
+     * @param mixed $availability
+     *
+     * @return self
+     */
+    public function setAvailability($availability) {
+        $this->availability = $availability;
+
+        return $this;
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getVisibility() {
+        return $this->visibility;
+    }
+
+    /**
+     * @param mixed $visibility
+     *
+     * @return self
+     */
+    public function setVisibility($visibility) {
+        $this->visibility = $visibility;
+
+        return $this;
+    }
+
+    public function toArray() {
+        $vars = [];
+        foreach ($this as $varname => $varvalue) {
+            $vars[$varname] = $varvalue;
+        }
+        return $vars;
+    }
+}
diff --git a/format.php b/format.php
index 1f0c83396b48f65adaa845cdef54e69482952d2a..fa756d73ac831fa1df855a192e9e0a5d939dc94a 100644
--- a/format.php
+++ b/format.php
@@ -1,74 +1,64 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-	/**
-	 * format_iena
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 *
-	 * Point d'entrée du plugin
-	 */
-	
-	defined('MOODLE_INTERNAL') || die();
-	require_once($CFG->libdir . '/filelib.php');
-	require_once($CFG->libdir . '/completionlib.php');
-	require_once('entity/course_format_iena_section_ressources.php');
-	require_once('entity/course_format_iena_sections.php');
-	require_once('entity/course_format_iena_completion.php');
-	require_once('entity/course_format_iena_cron_action.php');
-	require_once('entity/course_format_iena_groups.php');
-	require_once('entity/course_format_iena_attendance.php');
-	
-	
-	
-	require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
-	require_once($CFG->dirroot . '/completion/classes/progress.php');
-	require_once($CFG->libdir . '/completionlib.php');
-
-	$PAGE->requires->js('/course/format/iena/js/jquery.min.js');
-	$PAGE->requires->js('/course/format/iena/format.js');
-
-	if ($topic = optional_param('topic', 0, PARAM_INT)) {
-		$url = $PAGE->url;
-		$url->param('section', $topic);
-		debugging('Outdated topic param passed to course/view.php', DEBUG_DEVELOPER);
-		redirect($url);
-	}
-	$context = context_course::instance($course->id);
-	if (($marker >= 0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
-		$course->marker = $marker;
-		course_set_marker($course->id, $marker);
-	}
-	$course = course_get_format($course)->get_course();
-	// course_create_sections_if_missing($course, range(0, $course->numsections));
-	course_create_sections_if_missing($course, 0);
-	$renderer = $PAGE->get_renderer('format_iena');
-	if (!empty($displaysection)) {
-		
-		$renderer->print_single_section_page($course, null, null, null, null, $displaysection);
-	} else {
-		
-		$renderer->switch_mode($course);
-		
-		
-		//$renderer->print_iena_section_pages($course);
-	}
-//	$PAGE->requires->js('/course/format/iena/js/jquery.min.js');
-//	$PAGE->requires->js('/course/format/iena/format.js');
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ *
+ * Point d'entrée du plugin
+ */
+
+defined('MOODLE_INTERNAL') || die();
+require_once($CFG->libdir . '/filelib.php');
+require_once($CFG->libdir . '/completionlib.php');
+require_once('entity/course_format_iena_section_ressources.php');
+require_once('entity/course_format_iena_sections.php');
+require_once('entity/course_format_iena_completion.php');
+require_once('entity/course_format_iena_cron_action.php');
+require_once('entity/course_format_iena_groups.php');
+require_once('entity/course_format_iena_attendance.php');
+
+require_once($CFG->dirroot . '/blocks/myoverview/lib.php');
+require_once($CFG->dirroot . '/completion/classes/progress.php');
+require_once($CFG->libdir . '/completionlib.php');
+
+$PAGE->requires->js('/course/format/iena/js/jquery.min.js');
+$PAGE->requires->js('/course/format/iena/format.js');
+
+if ($topic = optional_param('topic', 0, PARAM_INT)) {
+    $url = $PAGE->url;
+    $url->param('section', $topic);
+    debugging('Outdated topic param passed to course/view.php', DEBUG_DEVELOPER);
+    redirect($url);
+}
+$context = context_course::instance($course->id);
+if (($marker >= 0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
+    $course->marker = $marker;
+    course_set_marker($course->id, $marker);
+}
+$course = course_get_format($course)->get_course();
+course_create_sections_if_missing($course, 0);
+$renderer = $PAGE->get_renderer('format_iena');
+if (!empty($displaysection)) {
+
+    $renderer->print_single_section_page($course, null, null, null, null, $displaysection);
+} else {
+    $renderer->switch_mode($course);
+}
+
diff --git a/lang/en/format_iena.php b/lang/en/format_iena.php
index 7aad0ada65bf79cd48c3fb4ffc9d3974699e7ea7..af1468a33fd4992e43c8bd1493b687ca53f937a2 100644
--- a/lang/en/format_iena.php
+++ b/lang/en/format_iena.php
@@ -1,102 +1,100 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 * format_iena
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     Michael lebeau
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	defined('MOODLE_INTERNAL') || die();
-	
-	$string['pluginname'] = 'Blended learning format';
-	$string['currentsection'] = 'The section';
-	$string['editsection'] = 'Edit section';
-	$string['deletesection'] = 'Delete section';
-	$string['sectionname'] = 'Section';
-	$string['section0name'] = 'General';
-	$string['hidefromothers'] = 'Hide section';
-	$string['showfromothers'] = 'Show section';
-	$string['showdefaultsectionname'] = 'Show the default sections name';
-	$string['showdefaultsectionname_help'] = 'If no name is set for the section will not show anything.<br>
-By definition an unnamed section is displayed as <strong>section [N]</strong>.';
-	$string['yes'] = 'Yes';
-	$string['no'] = 'No';
-	$string['sectionposition'] = 'Section zero position';
-	
-	$string['name'] = 'Name';
-	$string['summary'] = 'Summary';
-	$string['modalite'] = 'Modality';
-	$string['notif'] = 'Notification';
-	$string['notif_summary'] = 'A notification can be sent to the student by email. She will remind her to consult the section and will contain various information (name of the course, link to the course, name of the section, date the section and modality';
-	$string['in_presence'] = 'Face-to-face session';
-	$string['not_presence'] = 'Remote session';
-	$string['days_before'] = 'A number of days before the session';
-	$string['days_after'] = 'A number of days after the session';
-	$string['days_same'] = 'The same day';
-	$string['nb_days_before'] = 'days before';
-	$string['nb_days_after'] = 'days after';
-	$string['hide_section'] = 'Hide the section';
-	$string['hide_section_summary'] = 'Restrict access to the session and hide it before a certain date';
-	$string['hide_option_1'] = 'Do not restrict access before a date';
-	$string['hide_option_2'] = 'Before the date of the session';
-	$string['hide_option_3'] = 'Before the date of notification';
-	$string['hide_bread_crum'] = 'Show progress bar';
-	$string['hide_icon_message'] = 'Show the mail icon';
-	$string['modules_for'] = 'Activities followed for';
-	$string['all_course'] = 'All the Course';
-	$string['students'] = 'Students';
-	$string['not_done'] = 'not having completed everything';
-	$string['all_students'] = 'all the students';
-	$string['student'] = 'Student';
-	$string['send_message'] = 'Send a message';
-	$string['for_section_select'] = 'For the selected section, you will have an indicator of the number of students who have not completed the activities below.';
-	$string['cancel'] = 'Cancel';
-	$string['save'] = 'Save';
-	$string['check_completion'] = 'Monitor completion';
-	$string['indic_suivi'] = 'Tracking indicators of the section';
-	$string['form_not_defined'] = 'Not specified';
-	$string['settings_section_form'] = 'Section parameter';
-	$string['course'] = 'Course';
-	$string['link'] = 'Link';
-	$string['prof'] = 'Professor';
-	$string['section'] = 'Section';
-	$string['hide_section'] = 'HIDE section ';
-	$string['show_section'] = 'SHOW section ';
-	$string['aboutcourse'] = 'About this course';
-	$string['modalite_help'] = 'The "Distance" mode will allow you to define a date for a course session and notifications x days before the session. The "Face to face" mode will allow you to define a date for an assessment, and notifications x days before the assessment due date';
-	$string['loadingResults'] = "Loading results...";
-	$string['errorLoadingResults'] = "Students could not be retrieved, please contact an administrator";
-	$string['caption']="Caption";
-	$string['status0']="Activity not completed";
-	$string['status1']="Activity completed";
-	$string['status2']="Activity completed and passed";
-	$string['status3']="Activity completed but not passed";
-	$string["send_message_title"]="Sending a message to {{nb_results}} people";
-	$string['display_course_infos']="Show/hide course information";
-	$string['my_progress']="My progress in the course: ";
-	$string['table_progress']="Tracking";
-	$string['displayInfos']="Display course informations";
-	$string['hideInfos']="Hide course informations";
-	$string['message_pres']="presential learning mail";
-	$string['message_dist']="distance learning mail";
-	$string['message_default_dist']="Default message distance learning";
-	$string['message_default_pres']="Default message presential learning";
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     Michael lebeau
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['pluginname'] = 'Blended learning format';
+$string['currentsection'] = 'The section';
+$string['editsection'] = 'Edit section';
+$string['deletesection'] = 'Delete section';
+$string['sectionname'] = 'Section';
+$string['section0name'] = 'General';
+$string['hidefromothers'] = 'Hide section';
+$string['showfromothers'] = 'Show section';
+$string['showdefaultsectionname'] = 'Show the default sections name';
+$string['showdefaultsectionname_help'] = 'If no name is set for the section will not show anything.<br>
+By definition an unnamed section is displayed as <strong>section [N]</strong>.';
+$string['yes'] = 'Yes';
+$string['no'] = 'No';
+$string['sectionposition'] = 'Section zero position';
+$string['name'] = 'Name';
+$string['summary'] = 'Summary';
+$string['modalite'] = 'Modality';
+$string['notif'] = 'Notification';
+$string['notif_summary'] = 'A notification can be sent to the student by email. She will remind her to consult the section and will contain various information (name of the course, link to the course, name of the section, date the section and modality';
+$string['in_presence'] = 'Face-to-face session';
+$string['not_presence'] = 'Remote session';
+$string['days_before'] = 'A number of days before the session';
+$string['days_after'] = 'A number of days after the session';
+$string['days_same'] = 'The same day';
+$string['nb_days_before'] = 'days before';
+$string['nb_days_after'] = 'days after';
+$string['hide_section'] = 'Hide the section';
+$string['hide_section_summary'] = 'Restrict access to the session and hide it before a certain date';
+$string['hide_option_1'] = 'Do not restrict access before a date';
+$string['hide_option_2'] = 'Before the date of the session';
+$string['hide_option_3'] = 'Before the date of notification';
+$string['hide_bread_crum'] = 'Show progress bar';
+$string['hide_icon_message'] = 'Show the mail icon';
+$string['modules_for'] = 'Activities followed for';
+$string['all_course'] = 'All the Course';
+$string['students'] = 'Students';
+$string['not_done'] = 'not having completed everything';
+$string['all_students'] = 'all the students';
+$string['student'] = 'Student';
+$string['send_message'] = 'Send a message';
+$string['for_section_select'] = 'For the selected section, you will have an indicator of the number of students who have not completed the activities below.';
+$string['cancel'] = 'Cancel';
+$string['save'] = 'Save';
+$string['check_completion'] = 'Monitor completion';
+$string['indic_suivi'] = 'Tracking indicators of the section';
+$string['form_not_defined'] = 'Not specified';
+$string['settings_section_form'] = 'Section parameter';
+$string['course'] = 'Course';
+$string['link'] = 'Link';
+$string['prof'] = 'Professor';
+$string['section'] = 'Section';
+$string['hide_section'] = 'HIDE section ';
+$string['show_section'] = 'SHOW section ';
+$string['aboutcourse'] = 'About this course';
+$string['modalite_help'] = 'The "Distance" mode will allow you to define a date for a course session and notifications x days before the session. The "Face to face" mode will allow you to define a date for an assessment, and notifications x days before the assessment due date';
+$string['loadingResults'] = "Loading results...";
+$string['errorLoadingResults'] = "Students could not be retrieved, please contact an administrator";
+$string['caption'] = "Caption";
+$string['status0'] = "Activity not completed";
+$string['status1'] = "Activity completed";
+$string['status2'] = "Activity completed and passed";
+$string['status3'] = "Activity completed but not passed";
+$string["send_message_title"] = "Sending a message to {{nb_results}} people";
+$string['display_course_infos'] = "Show/hide course information";
+$string['my_progress'] = "My progress in the course: ";
+$string['table_progress'] = "Tracking";
+$string['displayInfos'] = "Display course informations";
+$string['hideInfos'] = "Hide course informations";
+$string['message_pres'] = "presential learning mail";
+$string['message_default_pres'] = "Default message presential learning";
+$string['message_pres_desc'] = "Configure default presential course message";
+$string['message_dist'] = "distance learning mail";
+$string['message_dist_desc'] = "Configure default blended course message";
+$string['message_default_dist'] = "Default message distance learning";
diff --git a/lang/fr/format_iena.php b/lang/fr/format_iena.php
index 530f3db653c6efff1db79fc53052480486761e06..4fd493410e8eadbda5b7c8909683fd383ce4ef23 100644
--- a/lang/fr/format_iena.php
+++ b/lang/fr/format_iena.php
@@ -1,103 +1,100 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 * format_iena
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	defined('MOODLE_INTERNAL') || die();
-	
-	$string['pluginname'] = 'Format enseignement hybride';
-	$string['currentsection'] = 'La section';
-	$string['editsection'] = 'Modifier section';
-	$string['deletesection'] = 'Supprimer section';
-	$string['sectionname'] = 'Section';
-	$string['section0name'] = 'Général';
-	$string['hidefromothers'] = 'Cacher section';
-	$string['showfromothers'] = 'Voir section';
-	$string['showdefaultsectionname'] = 'Show the default sections name';
-	$string['showdefaultsectionname_help'] = 'If no name is set for the section will not show anything.<br>
-By definition an unnamed section is displayed as <strong>section [N]</strong>.';
-	$string['yes'] = 'Oui';
-	$string['no'] = 'Non';
-	$string['sectionposition'] = 'Section zero position';
-	
-	$string['name'] = 'Nom';
-	$string['summary'] = 'Résumé';
-	$string['modalite'] = 'Modalité';
-	$string['notif'] = 'Notification';
-	$string['notif_summary'] = 'Une notification peut être envoyée à l étudiant par mail. Elle lui rapplera de consulter la section et contiendra diverses informations (nom du cours, lien vers le cours, nom de la section, date le la section et modalité';
-	$string['in_presence'] = 'Session en présence';
-	$string['not_presence'] = 'Session à distance';
-	$string['days_before'] = 'Un certain nombre de jours avant la séance';
-	$string['days_after'] = 'Un certain nombre de jours après la séance';
-	$string['days_same'] = 'Le jour même';
-	$string['nb_days_before'] = 'jours avant';
-	$string['nb_days_after'] = 'jours après';
-	$string['hide_section'] = 'Cacher la section';
-	$string['hide_section_summary'] = 'Restreindre l\'accès à la séance et la cacher avant une certaine date';
-	$string['hide_option_1'] = 'Ne pas restreindre l\'accès avant une date';
-	$string['hide_option_2'] = 'Avant la date de la séance';
-	$string['hide_option_3'] = 'Avant la date de la notification';
-	$string['hide_bread_crum'] = 'Afficher la barre de progression';
-	$string['hide_icon_message'] = 'Afficher l\'icone messagerie';
-	$string['modules_for'] = 'Activités suivies pour';
-	$string['all_course'] = 'Tout le Cours';
-	$string['students'] = 'Etudiants';
-	$string['not_done'] = 'n\'ayant pas tout achevé';
-	$string['all_students'] = 'tous les étudiants';
-	$string['student'] = 'Eleve';
-	$string['send_message'] = 'Envoyer un message';
-	$string['for_section_select'] = 'Pour la section sélectionnée, vous aurez un indicateur du nombre d\'étudiant qui n\'ont pas achevé les activités ci-dessous.';
-	$string['cancel'] = 'Annuler';
-	$string['save'] = 'Enregistrer';
-	$string['check_completion'] = 'Surveiller l\'achèvement';
-	$string['indic_suivi'] = 'Indicateurs de suivi de la section';
-	$string['form_not_defined'] = 'Non renseigné';
-	$string['settings_section_form'] = 'Paramètre de la section';
-	$string['course'] = 'Cours';
-	$string['link'] = 'Lien';
-	$string['prof'] = 'Professeur';
-	$string['section'] = 'Section';
-	$string['hide_section'] = 'CACHER la section ';
-	$string['show_section'] = 'MONTRER la section ';
-	$string['aboutcourse'] = 'À propos de ce cours';
-	$string['modalite_help'] = 'La modalité "Distance" vous permettra de définir une date de séance et des notifications x jours avant la séance. La modalité "Présentiel" vous permettra de définir une date pour un rendu, et des notifications x jours avant la date de rendu';
-	$string['loadingResults'] = "Chargement des résultats...";
-	$string['errorLoadingResults'] = "Les étudiants n'ont pas pu être chargés, veuillez contacter un administrateur.";
-	$string['caption']="Légende";
-	$string['status0']="Activité non complétée";
-	$string['status1']="Activité complétée";
-	$string['status2']="Activité complétée et validée";
-	$string['status3']="Activité complétée non validée";
-	$string["send_message_title"]="Envoi d'un message à {{nb_results}} personnes";
-	$string['display_course_infos']="Afficher/Masquer les informations du cours";
-	$string['my_progress']="Ma progression dans le cours : ";
-	$string['table_progress']="Suivi des étudiants";
-	$string['displayInfos']="Afficher les infos du cours";
-	$string['hideInfos']="Masquer les infos du cours";
-	$string['message_pres']="Message présentiel";
-	$string['message_dist']="Message distanciel";
-	$string['message_default_dist']="message par défaut distance";
-	$string['message_default_pres']="message par defaut pres";
-
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$string['pluginname'] = 'Format enseignement hybride';
+$string['currentsection'] = 'La section';
+$string['editsection'] = 'Modifier section';
+$string['deletesection'] = 'Supprimer section';
+$string['sectionname'] = 'Section';
+$string['section0name'] = 'Général';
+$string['hidefromothers'] = 'Cacher section';
+$string['showfromothers'] = 'Voir section';
+$string['showdefaultsectionname'] = 'Show the default sections name';
+$string['showdefaultsectionname_help'] = 'If no name is set for the section will not show anything.<br>
+By definition an unnamed section is displayed as <strong>section [N]</strong>.';
+$string['yes'] = 'Oui';
+$string['no'] = 'Non';
+$string['sectionposition'] = 'Section zero position';
+$string['name'] = 'Nom';
+$string['summary'] = 'Résumé';
+$string['modalite'] = 'Modalité';
+$string['notif'] = 'Notification';
+$string['notif_summary'] = 'Une notification peut être envoyée à l étudiant par mail. Elle lui rapplera de consulter la section et contiendra diverses informations (nom du cours, lien vers le cours, nom de la section, date le la section et modalité';
+$string['in_presence'] = 'Session en présence';
+$string['not_presence'] = 'Session à distance';
+$string['days_before'] = 'Un certain nombre de jours avant la séance';
+$string['days_after'] = 'Un certain nombre de jours après la séance';
+$string['days_same'] = 'Le jour même';
+$string['nb_days_before'] = 'jours avant';
+$string['nb_days_after'] = 'jours après';
+$string['hide_section'] = 'Cacher la section';
+$string['hide_section_summary'] = 'Restreindre l\'accès à la séance et la cacher avant une certaine date';
+$string['hide_option_1'] = 'Ne pas restreindre l\'accès avant une date';
+$string['hide_option_2'] = 'Avant la date de la séance';
+$string['hide_option_3'] = 'Avant la date de la notification';
+$string['hide_bread_crum'] = 'Afficher la barre de progression';
+$string['hide_icon_message'] = 'Afficher l\'icone messagerie';
+$string['modules_for'] = 'Activités suivies pour';
+$string['all_course'] = 'Tout le Cours';
+$string['students'] = 'Etudiants';
+$string['not_done'] = 'n\'ayant pas tout achevé';
+$string['all_students'] = 'tous les étudiants';
+$string['student'] = 'Eleve';
+$string['send_message'] = 'Envoyer un message';
+$string['for_section_select'] = 'Pour la section sélectionnée, vous aurez un indicateur du nombre d\'étudiant qui n\'ont pas achevé les activités ci-dessous.';
+$string['cancel'] = 'Annuler';
+$string['save'] = 'Enregistrer';
+$string['check_completion'] = 'Surveiller l\'achèvement';
+$string['indic_suivi'] = 'Indicateurs de suivi de la section';
+$string['form_not_defined'] = 'Non renseigné';
+$string['settings_section_form'] = 'Paramètre de la section';
+$string['course'] = 'Cours';
+$string['link'] = 'Lien';
+$string['prof'] = 'Professeur';
+$string['section'] = 'Section';
+$string['hide_section'] = 'CACHER la section ';
+$string['show_section'] = 'MONTRER la section ';
+$string['aboutcourse'] = 'À propos de ce cours';
+$string['modalite_help'] = 'La modalité "Distance" vous permettra de définir une date de séance et des notifications x jours avant la séance. La modalité "Présentiel" vous permettra de définir une date pour un rendu, et des notifications x jours avant la date de rendu';
+$string['loadingResults'] = "Chargement des résultats...";
+$string['errorLoadingResults'] = "Les étudiants n'ont pas pu être chargés, veuillez contacter un administrateur.";
+$string['caption'] = "Légende";
+$string['status0'] = "Activité non complétée";
+$string['status1'] = "Activité complétée";
+$string['status2'] = "Activité complétée et validée";
+$string['status3'] = "Activité complétée non validée";
+$string["send_message_title"] = "Envoi d'un message à {{nb_results}} personnes";
+$string['display_course_infos'] = "Afficher/Masquer les informations du cours";
+$string['my_progress'] = "Ma progression dans le cours : ";
+$string['table_progress'] = "Suivi des étudiants";
+$string['displayInfos'] = "Afficher les infos du cours";
+$string['hideInfos'] = "Masquer les infos du cours";
+$string['message_pres'] = "Message présentiel";
+$string['message_default_pres'] = "message par defaut pres";
+$string['message_pres_desc'] = "Paramétrez le message qui sera envoyé par défaut pour un cours en présentiel";
+$string['message_dist'] = "Message distanciel";
+$string['message_dist_desc'] = "Paramétrez le message qui sera envoyé par défaut pour un cours à distance";
+$string['message_default_dist'] = "message par défaut distance";
diff --git a/lib.php b/lib.php
index 665ab51acce388fc2a61d1aee7a1ccb9e879bd74..ad4fcd6b23e4432104f2d877cc0bf2b2e9fe3a0a 100644
--- a/lib.php
+++ b/lib.php
@@ -1,418 +1,392 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	defined('MOODLE_INTERNAL') || die();
-	require_once($CFG->dirroot . '/course/format/topics/lib.php');
-	
-	/**
-	 * format_iena
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille/Thomas Fradet
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	class format_iena extends format_topics
-	{
-		
-		/**
-		 * course_format_options
-		 *
-		 * @param bool $foreditform
-		 * @return array
-		 */
-		public function course_format_options($foreditform = false)
-		{
-			global $PAGE;
-			static $courseformatoptions = false;
-			if ($courseformatoptions === false) {
-				// $courseconfig = get_config('moodlecourse');
-				$courseformatoptions['allmodulesbreadcrum'] = array(
-					'default' => 0,
-					'type' => PARAM_INT,
-				);
-				$courseformatoptions['viewiconmessage'] = array(
-					'default' => 1,
-					'type' => PARAM_INT,
-				);
-			}
-			if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) {
-				$choiceTab = array();
-				$choiceTab['1'] = get_string('yes', 'format_iena');
-				$choiceTab['0'] = get_string('no', 'format_iena');
-				$courseformatoptionsedit['allmodulesbreadcrum'] = array(
-					'label' => "Afficher les activités cachées mais disponibles dans la barre de progression.",
-					'element_type' => 'select',
-					'element_attributes' => array($choiceTab),
-				);
-				$courseformatoptionsedit['viewiconmessage'] = array(
-					'label' => get_string('hide_icon_message', 'format_iena'),
-					'element_type' => 'select',
-					'element_attributes' => array($choiceTab),
-				);
-				$courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
-			}
-			return $courseformatoptions;
-		}
-
-			 /**
-     * Definitions of the additional options that this course format uses for section
-     *
-     * See {@link format_base::course_format_options()} for return array definition.
-     *
-     * Additionally section format options may have property 'cache' set to true
-     * if this option needs to be cached in {@link get_fast_modinfo()}. The 'cache' property
-     * is recommended to be set only for fields used in {@link format_base::get_section_name()},
-     * {@link format_base::extend_course_navigation()} and {@link format_base::get_view_url()}
-     *
-     * For better performance cached options are recommended to have 'cachedefault' property
-     * Unlike 'default', 'cachedefault' should be static and not access get_config().
-     *
-     * Regardless of value of 'cache' all options are accessed in the code as
-     * $sectioninfo->OPTIONNAME
-     * where $sectioninfo is instance of section_info, returned by
-     * get_fast_modinfo($course)->get_section_info($sectionnum)
-     * or get_fast_modinfo($course)->get_section_info_all()
-     *
-     * All format options for particular section are returned by calling:
-     * $this->get_format_options($section);
-     *
-     * @param bool $foreditform
-     * @return array
-     */
-    public function section_format_options($foreditform = false) {
-         global $CFG;
-        static $courseformatoptions = false;
-
-        if ($courseformatoptions === false) {
-            $courseformatoptions = array(
-                'presence'=>array(
-                	'label'=>"Présence",
-                	'type'=>PARAM_INT
-                ),
-                'daterendu'=>array(
-                	'label'=>"Date rendu",
-                	'type'=>PARAM_INT
-            	),
-            	'daysnotif'=>array(
-            		'label'=>"Notification",
-            		'type'=>PARAM_INT
-				),
-				'msg'=>array(
-					'label'=>"Message",
-					'type'=>PARAM_RAW
-				),
-            );
-        }
-        
-        return $courseformatoptions;
-    }
-
-
-
-     /**
-     * Adds format options elements to the course/section edit form.
-     *
-     * This function is called from {@link course_edit_form::definition_after_data()}.
-     *
-     * @param MoodleQuickForm $mform form the elements are added to.
-     * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form.
-     * @return array array of references to the added form elements.
-     */
-    public function create_edit_form_elements(&$mform, $forsection = false) {
-        global $COURSE;
-        global $PAGE;
-
-        $elements = parent::create_edit_form_elements($mform, $forsection);
-
-        if ($forsection) {
-           	$mform->removeElement('presence', false);
-           	$mform->removeElement('daterendu', false);
-           	$mform->removeElement('daysnotif', false);
-			$mform->removeElement('msg', false);
-
-           	$sectionclass = new stdClass();
-           	$sectionclass->id=optional_param('id', 0, PARAM_INT);
-          	$section_config=$this->get_format_options($sectionclass);
-          	
-			$mform->addElement('header', 'nameforyourheaderelement', 'Format hybride');
-
-			//Modalité
-			$radioarray=array();
-	    	$radioarray[] = $mform->createElement('radio', 'presence', '', 'Distance', 2);
-			$radioarray[] = $mform->createElement('radio', 'presence', '', 'Présentiel', 1);
-			$radioarray[] = $mform->createElement('radio', 'presence', '', 'Aucune', 0);
-			$mform->addGroup($radioarray, 'modalite', 'Modalité', array(' '), false);
-			$mform->addHelpButton('modalite', 'modalite', 'format_iena');
-
-			//Date cours à distance
-			$datearray=array();
-			$datearray[] = $mform->createElement('date_time_selector', 'daterendu', '');
-			$datearray[] = $mform->createElement('checkbox', 'daterenducheck', 'Activer');
-			$mform->addGroup($datearray, 'groupdate', 'Date d\'échéance', array(' '), false);
-			$mform->disabledIf('groupdate', 'daterenducheck');
-			//On montre le groupe seulement si à distance
-			$mform->hideIf('groupdate', 'presence', 'neq', 2);
-			//$mform->hideIf('groupdate', 'id_presence_2', 'notchecked');
-			
-			//Date cours présentiel
-			$datearray=array();
-			$datearray[] = $mform->createElement('date_time_selector', 'daterendu2', '');
-			$datearray[] = $mform->createElement('checkbox', 'daterenducheck2', 'Activer');
-			$mform->addGroup($datearray, 'groupdate2', 'Date du cours', array(' '), false);
-			$mform->disabledIf('groupdate2', 'daterenducheck2');
-			//On montre le groupe si à présentiel
-			$mform->hideIf('groupdate2', 'presence', 'neq', 1);
-
-			//Notification distanciel
-			$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);
-			$daysarray[]=$mform->createElement('html', ' <span id="days-text">jours avant la séance</span>');
-			$daysarray[] = $mform->createElement('checkbox', 'selectdayscheck', 'Activer');
-			$mform->addGroup($daysarray, 'groupdays', 'Notification', array(' '), false);
-			$mform->disabledIf('groupdays', 'selectdayscheck');
-			$mform->disabledIf('groupdays', 'daterenducheck');
-			$mform->hideIf('groupdays', 'presence', 'neq', 2);
-			$mform->hideIf('groupdays', 'daterenducheck');
-
-			//Notification présentiel
-			$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', 'neq', 1);
-			$mform->hideIf('groupdays2', 'daterenducheck2');
-
-			//Message présentiel
-			//$mform->addElement('textarea', 'msg_pres', 'Message présentiel');
-			//$mform->disabledIf('msg_pres', 'selectdayscheck2');
-			//$mform->hideIf('msg_pres', 'presence', 'neq', 1);
-			//$mform->hideIf('msg_pres', 'selectdayscheck2');
-			//$mform->hideIf('msg_pres', 'daterenducheck2');
-			$msg_pres_grp=array();
-			$msg_pres_grp[] = $mform->createElement('editor', 'msg_pres', get_string('message_pres', 'format_iena'));
-			$mform->setType('msg_pres', PARAM_RAW);
-			$mform->setDefault('msg_pres', array('text'=>get_string('message_default_pres', 'format_iena')));
-			$mform->addGroup($msg_pres_grp, 'msg_pres_grp', get_string('message_pres', 'format_iena'), ' ', false);
-			//$mform->addRule('msg_pres_grp', get_string('err_minlength'), 'minlength', 50, 'client');
-			$mform->hideIf('msg_pres_grp', 'presence', 'neq', 1);
-			$mform->hideIf('msg_pres_grp', 'selectdayscheck2');
-			$mform->hideIf('msg_pres_grp', 'daterenducheck2');
-
-			//Message distanciel
-			//$mform->addElement('textarea', 'msg_dist', 'Message distanciel');
-			//$mform->disabledIf('msg_dist', 'selectdayscheck');
-			//$mform->hideIf('msg_dist', 'presence', 'neq', 2);
-			//$mform->hideIf('msg_dist', 'selectdayscheck');
-			//$mform->hideIf('msg_dist', 'daterenducheck');
-			$msg_dist_grp=array();
-			$msg_dist_grp[] = $mform->createElement('editor', 'msg_dist', get_string('message_dist', 'format_iena'));
-			$mform->setType('msg_dist', PARAM_RAW);
-			$mform->setDefault('msg_dist', array('text'=>get_string('message_default_dist', 'format_iena')));
-			$mform->addGroup($msg_dist_grp, 'msg_dist_grp', get_string('message_dist', 'format_iena'), ' ', false);
-			$mform->hideIf('msg_dist_grp', 'presence', 'neq', 2);
-			$mform->hideIf('msg_dist_grp', 'selectdayscheck');
-			$mform->hideIf('msg_dist_grp', 'daterenducheck');			
-
-
-			//on ne peut pas activer des notifs s'il n'y a pas de date de rendu/date de cours
-			//on prérempli le formulaire si des données existent en BDD
-          	if($section_config['presence']){
-          		$mform->setDefault('presence', $section_config['presence']);
-          	}
-          	if($section_config['daterendu']){
-				//cas distance
-          		if(isset($section_config['presence']) && $section_config['presence']==2){
-          			$mform->setDefault('daterendu', $section_config['daterendu']);
-          			$mform->setDefault('daterenducheck', "1");
-						if(isset($section_config['daysnotif']) && $section_config['daysnotif'] > -1){
-							$mform->setDefault('daysnotif', $section_config['daysnotif']);
-							$mform->setDefault('selectdayscheck', "1");
-							//$mform->setDefault('msg_dist', $section_config['msg']);
-							$mform->setDefault('msg_dist', array('text'=>$section_config['msg']));
-						}
-          		}
-				//cas présence
-          		else if(isset($section_config['presence']) && $section_config['presence']==1){
-          			$mform->setDefault('daterendu2', $section_config['daterendu']);
-          			$mform->setDefault('daterenducheck2', "1");
-					  	if(isset($section_config['daysnotif']) && $section_config['daysnotif'] > -1){
-							$mform->setDefault('daysnotif2', $section_config['daysnotif']);
-							$mform->setDefault('selectdayscheck2', "1");
-							//$mform->setDefault('msg_pres', $section_config['msg']);
-							$mform->setDefault('msg_pres', array('text'=>$section_config['msg']));
-						}          		
-				}	
-          	}
-        }
-
-        return $elements;
-    }
-
-    /**
-     * Updates format options for a course
-     *
-     * In case if course format was changed to 'periods', we try to copy options
-     * 'coursedisplay', 'numsections' and 'hiddensections' from the previous format.
-     * If previous course format did not have 'numsections' option, we populate it with the
-     * current number of sections
-     *
-     * @param stdClass|array $data return value from {@link moodleform::get_data()} or array with data
-     * @param stdClass $oldcourse if this function is called from {@link update_course()}
-     *     this object contains information about the course before update
-     * @return bool whether there were any changes to the options values
-     */
-    public function update_section_format_options($data) {
-        global $DB;
-        
-       	$objectSection=new stdClass();
-       	$objectSection->id=$data["id"];
-        $section_config=$this->get_format_options($objectSection);
-        
-        //$data = (array)$data;
-        //if a date was set but we want to remove it
-        if(!isset($data['daterenducheck']) && !isset($data['daterenducheck2'])){
-        	if(array_key_exists('daterendu', $section_config) && !empty($section_config['daterendu'])){
-        		$data['daterendu']=NULL;
-        	} else{
-        		unset($data['daterendu']);
-        	}
-        } else if(isset($data['daterenducheck2'])){
-        	$data['daterendu']=$data['daterendu2'];
-        }
-
-		if (isset($data['daysnotif']) && ($data['presence']==2)){
-			$data['msg']=$data['msg_dist']['text'];
-
-		} else if (isset($data['daysnotif2']) && ($data['presence']==1)){
-			$data['msg']=$data['msg_pres']['text'];
-		}
-
-
-	    /* De base daysnotifs est vide et daysnotifs2 n'existe pas */
-		// Le système de notification n'a jamais été activé et on veut l'activer
-		// Si c'est en présence
-		if(isset($data['daysnotif2']) && isset($data['selectdayscheck2']) && $data['presence'] == 1){	
-			$data['daysnotif']=$data["daysnotif2"];
-		}
-		//Le système de notif a déjà été activé  et on veut le désactiver OU il a jamais été activé et on ne veut pas l'activer.
-		if(empty($data['daysnotif']) || (!isset($data['selectdayscheck']) && !isset($data['selectdayscheck2']))){
-			if(array_key_exists('daysnotif', $section_config) && $section_config['daysnotif']>-1){
-	        	$data['daysnotif']=-1;
-				$data['msg']=NULL;
-	    	}
-	    	else{
-	    		unset($data['daysnotif']);
-	    	}
-		}
-
-        return $this->update_format_options($data, $data['id']);
-    }
-
-		
-		/**
-		 * get_view_url
-		 *
-		 * @param int|stdclass $section
-		 * @param array $options
-		 * @return null|moodle_url
-		 */
-		public function get_view_url($section, $options = array())
-		{
-			global $CFG;
-			$course = $this->get_course();
-			$url = new moodle_url('/course/view.php', array('id' => $course->id));
-			
-			$sr = null;
-			if (array_key_exists('sr', $options)) {
-				$sr = $options['sr'];
-			}
-			if (is_object($section)) {
-				$sectionno = $section->section;
-			} else {
-				$sectionno = $section;
-			}
-			if ($sectionno !== null) {
-				if ($sr !== null) {
-					if ($sr) {
-						$usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
-						$sectionno = $sr;
-					} else {
-						$usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
-					}
-				} else {
-					$usercoursedisplay = 0;
-				}
-				if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
-					$url->param('section', $sectionno);
-				} else {
-					if (empty($CFG->linkcoursesections) && !empty($options['navigation'])) {
-						return null;
-					}
-					$url->set_anchor('section-' . $sectionno);
-				}
-			}
-			return $url;
-		}
-	}
-	
-	/**
-	 * Implements callback inplace_editable() allowing to edit values in-place
-	 *
-	 * @param string $itemtype
-	 * @param int $itemid
-	 * @param mixed $newvalue
-	 * @return \core\output\inplace_editable
-	 */
-	function format_iena_inplace_editable($itemtype, $itemid, $newvalue)
-	{
-		global $DB, $CFG;
-		require_once($CFG->dirroot . '/course/lib.php');
-		if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
-			$section = $DB->get_record_sql(
-				'SELECT s.* FROM {course_sections} s JOIN {course} c ON s.course = c.id WHERE s.id = ? AND c.format = ?',
-				array($itemid, 'iena'),
-				MUST_EXIST
-			);
-			return course_get_format($section->course)->inplace_editable_update_section_name($section, $itemtype, $newvalue);
-		}
-	}
-
-	
-		/**
-	 * Extends the course administration navigation with the Badges page
-	 *
-	 * @param navigation_node $coursenode
-	 * @param object $course
-	 */
-	function iena_add_course_navigation(navigation_node $coursenode, stdClass $course) {
-		echo "<br><br>br>";
-		echo "ien add course";
-	}
-	function format_iena_add_course_navigation(navigation_node $coursenode, stdClass $course) {
-
-		echo "<br><br>br>";
-		echo "formatien add course";
-	}
-
-
-
-
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+defined('MOODLE_INTERNAL') || die();
+require_once($CFG->dirroot . '/course/format/topics/lib.php');
+
+/**
+ * format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille/Thomas Fradet
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class format_iena extends format_topics {
+    /**
+     * course_format_options
+     *
+     * @param bool $foreditform
+     * @return array
+     */
+    public function course_format_options($foreditform = false) {
+        global $PAGE;
+        static $courseformatoptions = false;
+        if ($courseformatoptions === false) {
+            $courseformatoptions['allmodulesbreadcrum'] = array(
+                'default' => 0,
+                'type' => PARAM_INT,
+            );
+            $courseformatoptions['viewiconmessage'] = array(
+                'default' => 1,
+                'type' => PARAM_INT,
+            );
+        }
+        if ($foreditform && !isset($courseformatoptions['coursedisplay']['label'])) {
+            $choicetab = array();
+            $choicetab['1'] = get_string('yes', 'format_iena');
+            $choicetab['0'] = get_string('no', 'format_iena');
+            $courseformatoptionsedit['allmodulesbreadcrum'] = array(
+                'label' => "Afficher les activités cachées mais disponibles dans la barre de progression.",
+                'element_type' => 'select',
+                'element_attributes' => array($choicetab),
+            );
+            $courseformatoptionsedit['viewiconmessage'] = array(
+                'label' => get_string('hide_icon_message', 'format_iena'),
+                'element_type' => 'select',
+                'element_attributes' => array($choicetab),
+            );
+            $courseformatoptions = array_merge_recursive($courseformatoptions, $courseformatoptionsedit);
+        }
+        return $courseformatoptions;
+    }
+
+    /**
+     * Definitions of the additional options that this course format uses for section
+     *
+     * See {@link format_base::course_format_options()} for return array definition.
+     *
+     * Additionally section format options may have property 'cache' set to true
+     * if this option needs to be cached in {@link get_fast_modinfo()}. The 'cache' property
+     * is recommended to be set only for fields used in {@link format_base::get_section_name()},
+     * {@link format_base::extend_course_navigation()} and {@link format_base::get_view_url()}
+     *
+     * For better performance cached options are recommended to have 'cachedefault' property
+     * Unlike 'default', 'cachedefault' should be static and not access get_config().
+     *
+     * Regardless of value of 'cache' all options are accessed in the code as
+     * $sectioninfo->OPTIONNAME
+     * where $sectioninfo is instance of section_info, returned by
+     * get_fast_modinfo($course)->get_section_info($sectionnum)
+     * or get_fast_modinfo($course)->get_section_info_all()
+     *
+     * All format options for particular section are returned by calling:
+     * $this->get_format_options($section);
+     *
+     * @param bool $foreditform
+     * @return array
+     */
+    public function section_format_options($foreditform = false) {
+        global $CFG;
+        static $courseformatoptions = false;
+
+        if ($courseformatoptions === false) {
+            $courseformatoptions = array(
+                'presence' => array(
+                    'label' => "Présence",
+                    'type' => PARAM_INT
+                ),
+                'daterendu' => array(
+                    'label' => "Date rendu",
+                    'type' => PARAM_INT
+                ),
+                'daysnotif' => array(
+                    'label' => "Notification",
+                    'type' => PARAM_INT
+                ),
+                'msg' => array(
+                    'label' => "Message",
+                    'type' => PARAM_RAW
+                ),
+            );
+        }
+
+        return $courseformatoptions;
+    }
+
+    /**
+     * Adds format options elements to the course/section edit form.
+     *
+     * This function is called from {@link course_edit_form::definition_after_data()}.
+     *
+     * @param MoodleQuickForm $mform form the elements are added to.
+     * @param bool $forsection 'true' if this is a section edit form, 'false' if this is course edit form.
+     * @return array array of references to the added form elements.
+     */
+    public function create_edit_form_elements(&$mform, $forsection = false) {
+        global $COURSE;
+        global $PAGE;
+
+        $elements = parent::create_edit_form_elements($mform, $forsection);
+
+        if ($forsection) {
+            $mform->removeElement('presence', false);
+            $mform->removeElement('daterendu', false);
+            $mform->removeElement('daysnotif', false);
+            $mform->removeElement('msg', false);
+
+            $sectionclass = new stdClass();
+            $sectionclass->id = optional_param('id', 0, PARAM_INT);
+            $sectionconfig = $this->get_format_options($sectionclass);
+
+            $mform->addElement('header', 'nameforyourheaderelement', 'Format hybride');
+
+            // Modalité.
+            $radioarray = array();
+            $radioarray[] = $mform->createElement('radio', 'presence', '', 'Distance', 2);
+            $radioarray[] = $mform->createElement('radio', 'presence', '', 'Présentiel', 1);
+            $radioarray[] = $mform->createElement('radio', 'presence', '', 'Aucune', 0);
+            $mform->addGroup($radioarray, 'modalite', 'Modalité', array(' '), false);
+            $mform->addHelpButton('modalite', 'modalite', 'format_iena');
+
+            // Date cours à distance.
+            $datearray = array();
+            $datearray[] = $mform->createElement('date_time_selector', 'daterendu', '');
+            $datearray[] = $mform->createElement('checkbox', 'daterenducheck', 'Activer');
+            $mform->addGroup($datearray, 'groupdate', 'Date d\'échéance', array(' '), false);
+            $mform->disabledIf('groupdate', 'daterenducheck');
+            // On montre le groupe seulement si à distance.
+            $mform->hideIf('groupdate', 'presence', 'neq', 2);
+
+            // Date cours présentiel.
+            $datearray = array();
+            $datearray[] = $mform->createElement('date_time_selector', 'daterendu2', '');
+            $datearray[] = $mform->createElement('checkbox', 'daterenducheck2', 'Activer');
+            $mform->addGroup($datearray, 'groupdate2', 'Date du cours', array(' '), false);
+            $mform->disabledIf('groupdate2', 'daterenducheck2');
+            // On montre le groupe si à présentiel.
+            $mform->hideIf('groupdate2', 'presence', 'neq', 1);
+
+            // Notification distanciel.
+            $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);
+            $daysarray[] = $mform->createElement('html', ' <span id="days-text">jours avant la séance</span>');
+            $daysarray[] = $mform->createElement('checkbox', 'selectdayscheck', 'Activer');
+            $mform->addGroup($daysarray, 'groupdays', 'Notification', array(' '), false);
+            $mform->disabledIf('groupdays', 'selectdayscheck');
+            $mform->disabledIf('groupdays', 'daterenducheck');
+            $mform->hideIf('groupdays', 'presence', 'neq', 2);
+            $mform->hideIf('groupdays', 'daterenducheck');
+
+            // Notification présentiel.
+            $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', 'neq', 1);
+            $mform->hideIf('groupdays2', 'daterenducheck2');
+
+            // Message présentiel.
+            $msgpresgrp = array();
+            $msgpresgrp[] = $mform->createElement('editor', 'msg_pres', get_string('message_pres', 'format_iena'));
+            $mform->setType('msg_pres', PARAM_RAW);
+            $mform->setDefault('msg_pres', array('text' => get_string('message_default_pres', 'format_iena')));
+            $mform->addGroup($msgpresgrp, 'msg_pres_grp', get_string('message_pres', 'format_iena'), ' ', false);
+            $mform->hideIf('msg_pres_grp', 'presence', 'neq', 1);
+            $mform->hideIf('msg_pres_grp', 'selectdayscheck2');
+            $mform->hideIf('msg_pres_grp', 'daterenducheck2');
+
+            // Message distanciel.
+            $msgdistgrp = array();
+            $msgdistgrp[] = $mform->createElement('editor', 'msg_dist', get_string('message_dist', 'format_iena'));
+            $mform->setType('msg_dist', PARAM_RAW);
+            $mform->setDefault('msg_dist', array('text' => get_string('message_default_dist', 'format_iena')));
+            $mform->addGroup($msgdistgrp, 'msg_dist_grp', get_string('message_dist', 'format_iena'), ' ', false);
+            $mform->hideIf('msg_dist_grp', 'presence', 'neq', 2);
+            $mform->hideIf('msg_dist_grp', 'selectdayscheck');
+            $mform->hideIf('msg_dist_grp', 'daterenducheck');
+
+            // On ne peut pas activer des notifs s'il n'y a pas de date de rendu/date de cours.
+            // On prérempli le formulaire si des données existent en BDD.
+            if ($sectionconfig['presence']) {
+                $mform->setDefault('presence', $sectionconfig['presence']);
+            }
+            if ($sectionconfig['daterendu']) {
+                // Cas distance.
+                if (isset($sectionconfig['presence']) && $sectionconfig['presence'] == 2) {
+                    $mform->setDefault('daterendu', $sectionconfig['daterendu']);
+                    $mform->setDefault('daterenducheck', "1");
+                    if (isset($sectionconfig['daysnotif']) && $sectionconfig['daysnotif'] > -1) {
+                        $mform->setDefault('daysnotif', $sectionconfig['daysnotif']);
+                        $mform->setDefault('selectdayscheck', "1");
+                        $mform->setDefault('msg_dist', array('text' => $sectionconfig['msg']));
+                    }
+                } else if (isset($sectionconfig['presence']) && $sectionconfig['presence'] == 1) {
+                    // Cas présence.
+                    $mform->setDefault('daterendu2', $sectionconfig['daterendu']);
+                    $mform->setDefault('daterenducheck2', "1");
+                    if (isset($sectionconfig['daysnotif']) && $sectionconfig['daysnotif'] > -1) {
+                        $mform->setDefault('daysnotif2', $sectionconfig['daysnotif']);
+                        $mform->setDefault('selectdayscheck2', "1");
+                        $mform->setDefault('msg_pres', array('text' => $sectionconfig['msg']));
+                    }
+                }
+            }
+        }
+        return $elements;
+    }
+
+    /**
+     * Updates format options for a course
+     *
+     * In case if course format was changed to 'periods', we try to copy options
+     * 'coursedisplay', 'numsections' and 'hiddensections' from the previous format.
+     * If previous course format did not have 'numsections' option, we populate it with the
+     * current number of sections
+     *
+     * @param stdClass|array $data return value from {@link moodleform::get_data()} or array with data
+     * @param stdClass $oldcourse if this function is called from {@link update_course()}
+     *     this object contains information about the course before update
+     * @return bool whether there were any changes to the options values
+     */
+    public function update_section_format_options($data) {
+        global $DB;
+
+        $objectsection = new stdClass();
+        $objectsection->id = $data["id"];
+        $sectionconfig = $this->get_format_options($objectsection);
+
+        // If a date was set but we want to remove it.
+        if (!isset($data['daterenducheck']) && !isset($data['daterenducheck2'])) {
+            if (array_key_exists('daterendu', $sectionconfig) && !empty($sectionconfig['daterendu'])) {
+                $data['daterendu'] = null;
+            } else {
+                unset($data['daterendu']);
+            }
+        } else if (isset($data['daterenducheck2'])) {
+            $data['daterendu'] = $data['daterendu2'];
+        }
+
+        if (isset($data['daysnotif']) && ($data['presence'] == 2)) {
+            $data['msg'] = $data['msg_dist']['text'];
+
+        } else if (isset($data['daysnotif2']) && ($data['presence'] == 1)) {
+            $data['msg'] = $data['msg_pres']['text'];
+        }
+
+        if ($data['msg'] == "<p dir=\"ltr\" style=\"text-align: left;\"><br></p>") {
+            $data['msg'] = "";
+        }
+
+        // De base daysnotifs est vide et daysnotifs2 n'existe pas.
+        // Le système de notification n'a jamais été activé et on veut l'activer
+        // Si c'est en présence.
+        if (isset($data['daysnotif2']) && isset($data['selectdayscheck2']) && $data['presence'] == 1) {
+            $data['daysnotif'] = $data["daysnotif2"];
+        }
+
+        // Le système de notif a déjà été activé  et on veut le désactiver OU il a jamais été activé et on ne veut pas l'activer.
+        if (empty($data['daysnotif']) || (!isset($data['selectdayscheck']) && !isset($data['selectdayscheck2']))) {
+            if (array_key_exists('daysnotif', $sectionconfig) && $sectionconfig['daysnotif'] > -1) {
+                $data['daysnotif'] = -1;
+                $data['msg'] = null;
+            } else {
+                unset($data['daysnotif']);
+            }
+        }
+
+        return $this->update_format_options($data, $data['id']);
+    }
+
+    /**
+     * get_view_url
+     *
+     * @param int|stdclass $section
+     * @param array $options
+     * @return null|moodle_url
+     */
+    public function get_view_url($section, $options = array()) {
+        global $CFG;
+        $course = $this->get_course();
+        $url = new moodle_url('/course/view.php', array('id' => $course->id));
+
+        $sr = null;
+        if (array_key_exists('sr', $options)) {
+            $sr = $options['sr'];
+        }
+        if (is_object($section)) {
+            $sectionno = $section->section;
+        } else {
+            $sectionno = $section;
+        }
+        if ($sectionno !== null) {
+            if ($sr !== null) {
+                if ($sr) {
+                    $usercoursedisplay = COURSE_DISPLAY_MULTIPAGE;
+                    $sectionno = $sr;
+                } else {
+                    $usercoursedisplay = COURSE_DISPLAY_SINGLEPAGE;
+                }
+            } else {
+                $usercoursedisplay = 0;
+            }
+            if ($sectionno != 0 && $usercoursedisplay == COURSE_DISPLAY_MULTIPAGE) {
+                $url->param('section', $sectionno);
+            } else {
+                if (empty($CFG->linkcoursesections) && !empty($options['navigation'])) {
+                    return null;
+                }
+                $url->set_anchor('section-' . $sectionno);
+            }
+        }
+        return $url;
+    }
+}
+
+/**
+ * Implements callback inplace_editable() allowing to edit values in-place
+ *
+ * @param string $itemtype
+ * @param int $itemid
+ * @param mixed $newvalue
+ * @return \core\output\inplace_editable
+ */
+function format_iena_inplace_editable($itemtype, $itemid, $newvalue) {
+    global $DB, $CFG;
+    require_once($CFG->dirroot . '/course/lib.php');
+    if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
+        $section = $DB->get_record_sql('SELECT s.*
+            FROM {course_sections} s
+            JOIN {course} c ON s.course = c.id
+            WHERE s.id = ?
+            AND c.format = ?',
+            array($itemid, 'iena'),
+            MUST_EXIST
+        );
+        return course_get_format($section->course)->inplace_editable_update_section_name($section, $itemtype, $newvalue);
+    }
+}
+
+/**
+ * Extends the course administration navigation with the Badges page
+ *
+ * @param navigation_node $coursenode
+ * @param object $course
+ */
+function iena_add_course_navigation(navigation_node $coursenode, stdClass $course) {
+    echo "<br><br>br>";
+    echo "ien add course";
+}
+
+function format_iena_add_course_navigation(navigation_node $coursenode, stdClass $course) {
+
+    echo "<br><br>br>";
+    echo "formatien add course";
+}
diff --git a/param_indicateur.php b/param_indicateur.php
index d9284ac384c59bb10636e85fb678ba403527eb59..f4c7d7fb934735ff4cac82b3e7f97fd5e1d8a600 100644
--- a/param_indicateur.php
+++ b/param_indicateur.php
@@ -1,401 +1,194 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- *
- * @package    format_iena
- * @category   format
- * @copyright  2018 Softia/Université lorraine
- * @author     vrignaud camille
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require_once('../../../config.php');
-	require_once('view/view_param_indicateur.php');
-		require_once('entity/course_format_iena_section_ressources.php');
-			require_once('entity/course_format_iena_sections.php');
-
-				global $COURSE, $DB, $USER;
-
-				$courseID = required_param('courseid', PARAM_INT);
-				$sectionID = required_param('sectionid', PARAM_INT);
-				$url = new moodle_url('/course/format/iena/param_indicateur.php', array('courseid' => $courseID));
-
-				$PAGE->set_pagelayout('course');
-				$PAGE->set_url($url);
-
-				if (!has_capability('moodle/course:sectionvisibility', $context = context_course::instance($courseID), $USER->id)) {
-					$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-					header("Location: {$link}");
-					exit;
-				}
-				$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
-				require_login($course, false, NULL);
-
-				$PAGE->set_title('Indicateurs de suivi');
-				$PAGE->set_heading('Indicateurs de suivi');
-
-				/* Update in Database all tables format_iena_settings for each module */
-				if ($_POST) {
-
-					if ($_POST['select-section']) {
-						$sectionid = $_POST['select-section'];
-						$sectionid = explode('-', $sectionid)[1];
-					} else {
-						$sectionid = "undefined";
-					}
-
-					/* Récupération de l'état des modules du formulaire */
-					$posted_module_ids = [];
-					$y = 0;
-					foreach ($_POST as $key => $form_module) {
-						$temp = explode($_POST['select-section'], $key);
-						if (count($temp) > 1) {
-							$posted_module_ids[$y] = $temp[0];
-						}
-						$y++;
-					}
-
-					$all_modules = explode("-", $_POST['all_modules']);
-
-
-					
-
-					// echo "<pre>";
-/* var_dump($_POST);
-echo "---<br>";
-var_dump($all_modules);
-echo "---<br>";
-var_dump($posted_module_ids);
-die; */
-
-$suivi_records = $DB->get_records('format_iena_settings', array('sectionid' => $sectionid));
-
-/* pour chaque activité du cours */
-foreach ($all_modules as $course_mod_id) {
-	$done = false;
-	/* pour chaque activité suivie ou non en base */
-	foreach ($suivi_records as $record) {
-		/* si l'activité est en base (suivie ou non) */
-		if ( $record->cmid == $course_mod_id ) {
-			/* l'activité est suivie en base (1 ou 0 => true, false) */
-			$is_suivi = $record->hide == 1 ? true : false;
-			/* l'activité a été checkée pour être suivie à présent (true ou false) */
-			$is_ask_suivi = in_array($record->cmid, $posted_module_ids);
-			/* si l'état de suivi de l'activité n'est pas le même que demandé */
-			if ( $is_suivi !== $is_ask_suivi ) {
-				/* mise à jour de l'état de l'activité suivie */
-				$update = new stdClass();
-				$update->id = $record->id;
-				$update->hide = $is_ask_suivi ? 1 : 0;
-				$DB->update_record('format_iena_settings', $update, false);
-				/* l'activité a été traitée */
-				$done = true;
-			} else {
-				/* l'activité n'a pas besoin d'être traitée */
-				$done = true;
-			}
-		}
-	}
-	/* si l'activité n'est pas en base (n'a pas été traitée) */
-	if ( $done == false ) {
-		/* si l'activité a été checkée pour être suivie à présent (true ou false) */
-		if ( in_array($course_mod_id, $posted_module_ids) ) {
-			$insert = new stdClass();
-			$insert->courseid = $COURSE->id;
-			$insert->cmid = $course_mod_id;
-			$insert->hide = 1;
-			$insert->sectionid = $sectionid;
-			$DB->insert_record('format_iena_settings', $insert, false);
-		}
-	}
-}
-
-// die;
-
-
-/*
-
-$DB->insert_record('format_iena_settings', $format_iena_setting_data, false);
-
-Records (0 ou 1)
-Form (1)
-
-Pour chaque activité $all_modules
-	Enregistrement traité = faux
-	Pour chaque enregistrement $suivi_records
-		Si l'enregistement $posted_module_ids existe dans $suivi_records
-			Si l'enregistrement est différent
-				Modifier l'enregistrement
-				Enregistrement traité = vrai
-				Break
-	Si Enregistrement traité == faux
-		Créer l'enregistrement
-
-*/
-
-
-		// foreach ($posted_module_ids as $module_id) {
-		// 	$prev_record_exists = false;
-		// 	foreach ( $suivi_records as $record ) {
-		// 		if ( $module_id == $record->cmid ) {
-		// 			$update = new stdClass();
-		// 			$update->id = $record->id;
-		// 			$update->hide = 1;
-		// 			$DB->update_record('format_iena_settings', $update, false);
-					$prev_record_exists = true;
-		// 			break;
-		// 		}
-		// 	}
-		// 	if ( !$prev_record_exists ) {
-		// 		$insert = new stdClass();
-		// 		$insert->courseid = $COURSE->id;
-		// 		$insert->cmid = $module_id;
-		// 		$insert->hide = 1;
-		// 		$insert->sectionid = $sectionid;
-		// 		$DB->insert_record('format_iena_settings', $insert, false);
-		// 	}
-		// }
-
-		
-
-
-
-
-
-		/*---*/
-
-
-		// // récupération de l'état des modules dans la BDD
-  // $modulesStates = $DB->get_records('format_iena_settings', array('sectionid' => $sectionid));
-
-  // foreach ($modulesStates as $module) {
-		// 	//var_dump($modulesStates);
-		// 	// Création de l'objet à updater
-		// 	//$format_iena_setting_data_upd = new stdClass();
-  // 	$indic = false;
-  // 	foreach ($posted_module_ids as $form_module) {
-  // 		if ($module->cmid == $form_module) {
-  // 			$format_iena_setting_data_upd = new stdClass();
-  // 			$format_iena_setting_data_upd->hide = 1;
-  // 			$format_iena_setting_data_upd->sectionid = $sectionid;
-  // 			$format_iena_setting_data_upd->id = $module->id;
-  // 			$DB->update_record('format_iena_settings', $format_iena_setting_data_upd, false);
-  // 			$indic = true;
-  // 			break;
-  // 		}
-  // 	}
-  // 	if ($indic == false) {
-  // 		$format_iena_setting_data_upd = new stdClass();
-  // 		$format_iena_setting_data_upd->hide = 0;
-  // 		$format_iena_setting_data_upd->sectionid = $sectionid;
-  // 		$format_iena_setting_data_upd->id = $module->id;
-  // 		$DB->update_record('format_iena_settings', $format_iena_setting_data_upd, false);
-  // 	}
-  // }
-
-
-
-		$link = $CFG->wwwroot . '/course/format/iena/suivi_unit.php?courseid=' . $courseID . '&sectionid=' . $sectionid;
-		header("Location: {$link}");
-		exit;
-
-
-
-	} elseif ( $_GET['sectionid'] ) {
-
-		echo $OUTPUT->header();
-
-		$get_section_id = $_GET['sectionid'];
-
-		$modinfo = get_fast_modinfo($COURSE->id);
-
-		$sections = $modinfo->get_section_info_all();
-
-		$suivi_cms = $DB->get_records_sql('SELECT id, cmid, hide from {format_iena_settings} where courseid = ? and sectionid = ?', array($COURSE->id, $get_section_id));
-
-		$is_course_section = false;
-		$current_section_name = "";
-
-		$sections_arr = [];
-
-		foreach ($sections as $section_num => $section) {
-
-			$section_id = $section->__get('id');
-			$section_name = $section->__get('name');
-			if ( $section_name == NULL ) {
-				$section_name = "Section " . $section_num;
-			}
-			if ( $section_id == $get_section_id ) {
-				$is_course_section = true;
-				$current_section_name = $section_name;
-				$current_section_id = $section_id;
-			}
-
-			$section_cms = [];
-			foreach ($modinfo->get_cms() as $module) {
-				if ( $module->section == $section_id ) {
-					$mod = new stdClass();
-					$mod->moduleid = $module->id;
-					$mod->name = $module->name;
-					$mod->courseid = $module->course;
-					$mod->sectionid = $module->section;
-					foreach ($suivi_cms as $suivi) {
-						if ( $module->id == $suivi->cmid ) {
-							if ( $suivi->hide == 1 ) {
-								$mod->suivi = 1;
-							} else {
-								$mod->suivi = 0;
-							}
-						}
-					}
-					array_push($section_cms, $mod);
-				}
-			}
-
-			$sec = new stdClass();
-			$sec->id = $section_id;
-			$sec->name = $section_name;
-			$sec->modules = $section_cms;
-			$sections_arr[] = $sec;
-		}
-
-		if ( $is_course_section == false ) {
-			echo "<p class='alert alert-warning'>Id de section invalide</p>";
-			echo $OUTPUT->footer();
-		} else {
-			// echo "<pre>";
-			// var_dump($sections_arr);
-			// echo "</pre>";
-			$view_param_indicateur = new view_param_indicateur();
-			echo $view_param_indicateur->get_content($sections_arr, $current_section_name, $current_section_id);
-			echo $OUTPUT->footer();
-		}
-
-	} else {
-		$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-		header("Location: {$link}");
-		exit;
-	}
-
-//	$PAGE->requires->js("/course/format/Sprint3/js/jquery.min.js");
-//	$PAGE->requires->js("/course/format/iena/js/file.js");
-//	$PAGE->requires->js_call_amd("/course/format/Sprint3/js/jquery.dataTables.js",  'init');
-	// echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"normalize.css\">";
-	// echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"common.css\">";
-	// echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css\">";
-	// echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
-
-
-
-	// var_dump(count($modinfo->get_cms()));
-
-	// $suivi_cms = $DB->get_records_sql('SELECT id, cmid, hide from {format_iena_settings}
-	// 	where courseid = ? and sectionid = ?', array($COURSE->id, 124));
-
-	// echo "<pre>";
-	// var_dump($suivi_cms);
-	// echo "</pre>";
-
-
-
-
-
-
-
-
-
-
-	// echo $OUTPUT->footer();
-	// die;
-
-
-	// $view_param_indicateur = new view_param_indicateur();
-	// $sections = $view_param_indicateur->get_course_sections_modules();
-
-
-
-
-	// $Tab_id_modules = array();
-	// $i = 0;
-
-	// foreach ($sections as $section) {
-	// 	foreach ($section->ressources as $mod) {
-	// 		$Tab_id_modules[$i] = $mod->id;
-	// 		$i++;
-	// 	}
-	// }
-
-	// $initee="avant creation";
-
-	// var_dump($initee);
-
-	// die;
-
-	// $suivi_cms = $DB->get_records_sql('SELECT * from {format_iena_settings}
-	// 	where courseid = ?', array($COURSE->id));
-
-	// // var_dump($suivi_cms);
-
-	// // die;
-
-	// $inidezaaaatee="apres premiere requete";
-
-	// var_dump($inidezaaaatee);
-
-	// $to_insert = [];
-
-	// foreach ($sections as $section) {
-	// 	foreach ($Tab_id_modules as $id_module) {
-	// 		// $verif_db = $DB->get_record('format_iena_settings', array('cmid' => $id_module, 'sectionid' => $section->id), '*');
-
-	// 		$verif_db = false;
-	// 		foreach ($suivi_cms as $suivi_cm) {
-	// 			if ( $suivi_cm->cmid == $id_module && $suivi_cm->sectionid == $section->id ) {
-	// 				$verif_db = true;
-	// 				break;
-	// 			}
-	// 		}
-
-	// 		// if ($verif_db == false) {
-	// 		if ($verif_db == false) {
-	// 			$format_iena_setting_data = new stdClass();
-	// 			$format_iena_setting_data->cmid = $id_module;
-	// 			$format_iena_setting_data->hide = 0;
-	// 			$format_iena_setting_data->courseid = $COURSE->id;
-	// 			$format_iena_setting_data->sectionid = $section->id;
-	// 			array_push($to_insert, $format_iena_setting_data);
-	// 			// $DB->insert_record('format_iena_settings', $format_iena_setting_data, false);
-	// 		}
-	// 	}
-	// }
-
-	// $indezite="avant requete";
-
-	// var_dump($indezite);
-
-	// if ( count($to_insert) > 0 ) {
-	// 	$DB->insert_records('format_iena_settings', $to_insert);
-	// }
-
-	// $inite="initialisation terminée";
-
-	// var_dump($inite);
-
-
-	// echo $view_param_indicateur->get_content();
-	// echo $OUTPUT->footer();
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('../../../config.php');
+require_once('view/view_param_indicateur.php');
+require_once('entity/course_format_iena_section_ressources.php');
+require_once('entity/course_format_iena_sections.php');
+
+global $COURSE, $DB, $USER;
+
+$courseid = required_param('courseid', PARAM_INT);
+$sectionid = required_param('sectionid', PARAM_INT);
+$url = new moodle_url('/course/format/iena/param_indicateur.php', array('courseid' => $courseid));
+
+$PAGE->set_pagelayout('course');
+$PAGE->set_url($url);
+
+if (!has_capability('moodle/course:sectionvisibility', $context = context_course::instance($courseid), $USER->id)) {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+}
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+require_login($course, false, null);
+
+$PAGE->set_title('Indicateurs de suivi');
+$PAGE->set_heading('Indicateurs de suivi');
+
+// Update in Database all tables format_iena_settings for each module.
+if ($_POST) {
+    if ($_POST['select-section']) {
+        $sectionid = $_POST['select-section'];
+        $sectionid = explode('-', $sectionid)[1];
+    } else {
+        $sectionid = "undefined";
+    }
+
+    // Récupération de l'état des modules du formulaire.
+    $postedmoduleids = [];
+    $y = 0;
+    foreach ($_POST as $key => $formmodule) {
+        $temp = explode($_POST['select-section'], $key);
+        if (count($temp) > 1) {
+            $postedmoduleids[$y] = $temp[0];
+        }
+        $y++;
+    }
+
+    $allmodules = explode("-", $_POST['all_modules']);
+
+    $suivirecords = $DB->get_records('format_iena_settings', array('sectionid' => $sectionid));
+
+    // Pour chaque activité du cours.
+    foreach ($allmodules as $coursemodid) {
+        $done = false;
+        // Pour chaque activité suivie ou non en base.
+        foreach ($suivirecords as $record) {
+            // Si l'activité est en base (suivie ou non).
+            if ($record->cmid == $coursemodid) {
+                // L'activité est suivie en base (1 ou 0 => true, false).
+                $issuivi = $record->hide == 1 ? true : false;
+                // L'activité a été checkée pour être suivie à présent (true ou false).
+                $isasksuivi = in_array($record->cmid, $postedmoduleids);
+                // Si l'état de suivi de l'activité n'est pas le même que demandé.
+                if ($issuivi !== $isasksuivi ) {
+                    // Mise à jour de l'état de l'activité suivie.
+                    $update = new stdClass();
+                    $update->id = $record->id;
+                    $update->hide = $isasksuivi ? 1 : 0;
+                    $DB->update_record('format_iena_settings', $update, false);
+                    // L'activité a été traitée.
+                    $done = true;
+                } else {
+                    // L'activité n'a pas besoin d'être traitée.
+                    $done = true;
+                }
+            }
+        }
+        // Si l'activité n'est pas en base (n'a pas été traitée).
+        if ($done == false) {
+            // Si l'activité a été checkée pour être suivie à présent (true ou false).
+            if (in_array($coursemodid, $postedmoduleids) ) {
+                $insert = new stdClass();
+                $insert->courseid = $COURSE->id;
+                $insert->cmid = $coursemodid;
+                $insert->hide = 1;
+                $insert->sectionid = $sectionid;
+                $DB->insert_record('format_iena_settings', $insert, false);
+            }
+        }
+    }
+
+            $prevrecordexists = true;
+
+        $link = $CFG->wwwroot . '/course/format/iena/suivi_unit.php?courseid=' . $courseid . '&sectionid=' . $sectionid;
+        header("Location: {$link}");
+        exit;
+
+} else if ( $_GET['sectionid'] ) {
+
+    echo $OUTPUT->header();
+
+    $getsectionid = $_GET['sectionid'];
+
+    $modinfo = get_fast_modinfo($COURSE->id);
+
+    $sections = $modinfo->get_section_info_all();
+
+    $suivicms = $DB->get_records_sql('SELECT id, cmid, hide
+        FROM {format_iena_settings}
+        WHERE courseid = ?
+        AND sectionid = ?',
+        array($COURSE->id, $getsectionid));
+
+    $iscoursesection = false;
+    $currentsectionname = "";
+
+    $sectionsarr = [];
+
+    foreach ($sections as $sectionnum => $section) {
+
+        $sectionid = $section->__get('id');
+        $sectionname = $section->__get('name');
+        if ($sectionname == null) {
+            $sectionname = "Section " . $sectionnum;
+        }
+        if ($sectionid == $getsectionid) {
+            $iscoursesection = true;
+            $currentsectionname = $sectionname;
+            $currentsectionid = $sectionid;
+        }
+
+        $sectioncms = [];
+        foreach ($modinfo->get_cms() as $module) {
+            if ( $module->section == $sectionid ) {
+                $mod = new stdClass();
+                $mod->moduleid = $module->id;
+                $mod->name = $module->name;
+                $mod->courseid = $module->course;
+                $mod->sectionid = $module->section;
+                foreach ($suivicms as $suivi) {
+                    if ($module->id == $suivi->cmid) {
+                        if ($suivi->hide == 1) {
+                            $mod->suivi = 1;
+                        } else {
+                            $mod->suivi = 0;
+                        }
+                    }
+                }
+                array_push($sectioncms, $mod);
+            }
+        }
+
+        $sec = new stdClass();
+        $sec->id = $sectionid;
+        $sec->name = $sectionname;
+        $sec->modules = $sectioncms;
+        $sectionsarr[] = $sec;
+    }
+
+    if ($iscoursesection == false) {
+        echo "<p class='alert alert-warning'>Id de section invalide</p>";
+        echo $OUTPUT->footer();
+    } else {
+        $viewparamindicateur = new view_param_indicateur();
+        echo $viewparamindicateur->get_content($sectionsarr, $currentsectionname, $currentsectionid);
+        echo $OUTPUT->footer();
+    }
+
+} else {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+}
diff --git a/param_section.php b/param_section.php
index 9d17da33727d1d66db6fa4a94abb35ade980b050..168706afbbaa35ced56de8785af48bde59624d8e 100644
--- a/param_section.php
+++ b/param_section.php
@@ -1,125 +1,111 @@
-<?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 06/03/18
-	 * Time: 10:20
-	 */
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	define('NO_OUTPUT_BUFFERING', true);
-	require_once('../../../config.php');
-	require_once('../../lib.php');
-	
-	global $COURSE, $DB, $USER;
-	
-	$courseID = required_param('courseid', PARAM_INT);
-	$sectionId = required_param('sectionid', PARAM_INT);
-	$url = new moodle_url('/course/format/iena/param_section.php', array('courseid' => $courseID, 'sectionid' => $sectionId));
-	
-	$PAGE->set_pagelayout('course');
-	$PAGE->set_url($url);
-
-	$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
-	require_login($course, false, NULL);
-	
-	if (!has_capability('moodle/course:update', $context = context_course::instance($courseID), $USER->id)) {
-		$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-		header("Location: {$link}");
-		exit;
-	}
-	
-	if ($_POST) {
-		global $DB;
-		$dateChaine = $_POST["date_iena"]["year"] . "-" . $_POST["date_iena"]["month"] . "-" . $_POST["date_iena"]["day"] . " " .
-		$_POST["date_iena"]["hour"] . ":" . $_POST["date_iena"]["minute"] . ":00";
-		$dateUp = date_create($dateChaine);
-		$data_iena = new stdClass();
-		if (isset($_POST['date_render'])) {
-			$dateChaine = "";
-		}
-		$data_iena->date_rendu = $dateChaine;
-		$data_iena->presence = $_POST['presence'];
-		$data_iena->id_section = $sectionId;
-		if (isset($_POST['day_same'])) {
-			$data_iena->day_same = $_POST['day_same'];
-		} else {
-			$data_iena->day_same = 0;
-		}
-		
-		if (isset($_POST['day_before'])) {
-			$data_iena->day_before = $_POST['day_before'];
-		} else {
-			$data_iena->day_before = 0;
-		}
-		if (isset($_POST['day_after'])) {
-			$data_iena->day_after = $_POST['day_after'];
-		} else {
-			$data_iena->day_after = 0;
-		}
-		$data_iena->nb_days_before = $_POST['nb_days_before'];
-		$data_iena->nb_days_after = $_POST['nb_days_after'];
-		/* Anciennement, servait à décider si la section était suivie dans les tableau de bord. Aujourd'hui, c'est le suivi d'achèvement d'activité qui est utilisé à la place. */
-		/* $data_iena->hide = $_POST['hide']; */
-		$data_iena->hide = false;
-		
-		$testIfsection = $DB->get_record('format_iena', array('id_section' => $sectionId), '*');
-		if ($testIfsection == false) {
-			$DB->insert_record('format_iena', $data_iena, false);
-		} else {
-			$data_iena->id = $testIfsection->id;
-			$DB->update_record('format_iena', $data_iena, false);
-		}
-		
-		$section = $DB->get_record('course_sections', array('id' => $sectionId), '*', MUST_EXIST);
-		$data = new stdClass();
-		$data->name = $_POST['name'];
-		$data->summary = $_POST['summary']['text'];
-		$data->summaryformat = $_POST['summary']['format'];
-		course_update_section($COURSE, $section, $data);
-		
-		$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-		header("Location: {$link}");
-		exit;
-
-	} else {
-
-		$dataSection = $DB->get_record('format_iena', array('id_section' => $sectionId), '*');
-
-		$PAGE->set_title($COURSE->fullname);
-		$PAGE->set_heading($COURSE->fullname);
-		echo $OUTPUT->header();
-		//$PAGE->requires->js("/course/format/Sprint3/js/jquery.min.js");
-		//$PAGE->requires->js("/course/format/iena/js/file.js");
-		//$PAGE->requires->js_call_amd("/course/format/Sprint3/js/jquery.dataTables.js",  'init');
-		require_once("$CFG->libdir/formslib.php");
-		require_once('view/view_param_section.php');
-		$view_param_section = new view_param_section();
-
-		echo $view_param_section->get_content($course, $dataSection);
-
-		echo $OUTPUT->footer();
-
-	}
\ No newline at end of file
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('NO_OUTPUT_BUFFERING', true);
+require_once('../../../config.php');
+require_once('../../lib.php');
+
+global $COURSE, $DB, $USER;
+
+$courseid = required_param('courseid', PARAM_INT);
+$sectionid = required_param('sectionid', PARAM_INT);
+$url = new moodle_url('/course/format/iena/param_section.php', array('courseid' => $courseid, 'sectionid' => $sectionid));
+
+$PAGE->set_pagelayout('course');
+$PAGE->set_url($url);
+
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+require_login($course, false, null);
+
+if (!has_capability('moodle/course:update', $context = context_course::instance($courseid), $USER->id)) {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+}
+
+if ($_POST) {
+    global $DB;
+    $datechaine = $_POST["date_iena"]["year"] . "-" . $_POST["date_iena"]["month"] . "-" . $_POST["date_iena"]["day"] . " " .
+    $_POST["date_iena"]["hour"] . ":" . $_POST["date_iena"]["minute"] . ":00";
+    $dateup = date_create($datechaine);
+    $dataiena = new stdClass();
+    if (isset($_POST['date_render'])) {
+        $datechaine = "";
+    }
+    $dataiena->date_rendu = $datechaine;
+    $dataiena->presence = $_POST['presence'];
+    $dataiena->id_section = $sectionid;
+    if (isset($_POST['day_same'])) {
+        $dataiena->day_same = $_POST['day_same'];
+    } else {
+        $dataiena->day_same = 0;
+    }
+
+    if (isset($_POST['day_before'])) {
+        $dataiena->day_before = $_POST['day_before'];
+    } else {
+        $dataiena->day_before = 0;
+    }
+    if (isset($_POST['day_after'])) {
+        $dataiena->day_after = $_POST['day_after'];
+    } else {
+        $dataiena->day_after = 0;
+    }
+    $dataiena->nb_days_before = $_POST['nb_days_before'];
+    $dataiena->nb_days_after = $_POST['nb_days_after'];
+    // Anciennement, servait à décider si la section était suivie dans les tableau de bord.
+    // Aujourd'hui, c'est le suivi d'achèvement d'activité qui est utilisé à la place.
+    $dataiena->hide = false;
+
+    $testifsection = $DB->get_record('format_iena', array('id_section' => $sectionid), '*');
+    if ($testifsection == false) {
+        $DB->insert_record('format_iena', $dataiena, false);
+    } else {
+        $dataiena->id = $testifsection->id;
+        $DB->update_record('format_iena', $dataiena, false);
+    }
+
+    $section = $DB->get_record('course_sections', array('id' => $sectionid), '*', MUST_EXIST);
+    $data = new stdClass();
+    $data->name = $_POST['name'];
+    $data->summary = $_POST['summary']['text'];
+    $data->summaryformat = $_POST['summary']['format'];
+    course_update_section($COURSE, $section, $data);
+
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+} else {
+    $datasection = $DB->get_record('format_iena', array('id_section' => $sectionid), '*');
+
+    $PAGE->set_title($COURSE->fullname);
+    $PAGE->set_heading($COURSE->fullname);
+    echo $OUTPUT->header();
+    require_once("$CFG->libdir/formslib.php");
+    require_once('view/view_param_section.php');
+    $viewparamsection = new view_param_section();
+
+    echo $viewparamsection->get_content($course, $datasection);
+
+    echo $OUTPUT->footer();
+}
diff --git a/renderer.php b/renderer.php
index 351c30594cdc4943deee2d0af467deec67af657f..6f188d9c07d204681378e4f73965541d24aabe9c 100644
--- a/renderer.php
+++ b/renderer.php
@@ -1,825 +1,723 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- * format_iena
- *
- * @package    format_iena
- * @category   format
- * @copyright  2018 Softia/Université lorraine
- * @author     vrignaud camille/Thomas Fradet
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->dirroot . '/course/format/topics/renderer.php');
-require_once($CFG->dirroot . '/course/format/iena/view/view_course_header.php');
-
-/**
- * format_iena_renderer
- *
- * @package    format_iena
- * @category   format
- * @copyright  2018 Softia/Université lorraine
- * @author     vrignaud camille
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class format_iena_renderer extends format_topics_renderer{
-
-
-	/**
-	 * start_section_list
-	 *
-	 * @return string
-	 */
-	//bientôt useless
-	protected function start_section_list()
-	{
-		return html_writer::start_tag('ul', ['class' => 'iena-editing']);
-	}
-
-	/**
-	 * section_header
-	 *
-	 * @param stdclass $section
-	 * @param stdclass $course
-	 * @param bool $onsectionpage
-	 * @param int $sectionreturn
-	 * @return string
-	 */
-	//Bientôt useless
-	protected function section_header($section, $course, $onsectionpage, $sectionreturn = null, $iena = false){
-		global $PAGE, $CFG;
-		$o = '';
-		$currenttext = '';
-		$sectionstyle = '';
-		if ($section->section != 0) {
-			if (!$section->visible) {
-				$sectionstyle = ' hidden';
-			} elseif (course_get_format($course)->is_section_current($section)) {
-				$sectionstyle = ' current';
-			}
-		}
-		
-		if ($PAGE->user_is_editing()) {
-			$o .= html_writer::start_tag('li', ['id' => 'section-' . $section->section,
-				'class' => 'section main clearfix' . $sectionstyle,
-				'role' => 'region', 'aria-label' => get_section_name($course, $section)]);
-		}
-		
-		$o .= html_writer::tag('span', $this->section_title($section, $course), ['class' => 'hidden sectionname']);
-
-		//This is were the editing menu is generated
-		if ($PAGE->user_is_editing()) {
-			$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
-			$o .= html_writer::tag('div', $leftcontent, ['class' => 'left side']);
-			$rightcontent = $this->section_right_content($section, $course, $onsectionpage);
-			$o .= html_writer::tag('div', $rightcontent, ['class' => 'right side']);
-		}
-
-		$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
-		$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
-		$classes = ' accesshide';
-		if ($hasnamenotsecpg || $hasnamesecpg) {
-			$classes = '';
-		}
-		$sectionname = html_writer::tag('span', $this->section_title($section, $course));
-		if ($PAGE->user_is_editing()) {
-			$o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
-		}
-		// if ($course->showdefaultsectionname) {
-		// 	$o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
-		// }
-		// if (!$iena) { $o .= $sectionname; }
-
-		$context = context_course::instance($course->id);
-		
-		/* résumé de section */
-		if ( $section->summary != "" ) {
-			$o .= html_writer::start_tag('div', ['class' => 'iena-description']);
-			$o .= html_writer::start_tag('div', ['class' => 'small']);
-
-			$o .= html_writer::start_tag('div', ['class' => 'iena-summary']);
-			$o .= $this->format_summary_text($section);
-			$o .= html_writer::end_tag('div');
-
-			$o .= html_writer::end_tag('div');
-			$o .= html_writer::end_tag('div');
-			$o .= html_writer::tag('a', 'Voir la description complète', ['href' => '#', 'class' => 'voir-plus']);
-		}
-		
-		$o .= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
-
-		
-
-		return $o;
-	}
-
-	/**
-	 * Add style attributes, classes (useless?), format section summary and add the hidden/restricted message 
-	 * @param StdClass $section 
-	 * @param StdClass $course 
-	 * @param bool $onsectionpage 
-	 * @param type|null $sectionreturn 
-	 * @param type|bool $iena 
-	 * @param type $groups
-	 * @return type
-	 */
-	protected function get_section_header($section, $course, $onsectionpage, $mods, $sectionreturn = null, $iena = false, $groups=false){
-		
-		global $PAGE, $CFG, $COURSE, $USER;
-		$completion_entity = new course_format_iena_completion();
-		$o = '';
-		$currenttext = '';
-		$sectionstyle = '';
-		if ($section->section != 0) {
-			if (!$section->visible) {
-				$section->sectionstyle = ' hidden';
-			} elseif (course_get_format($course)->is_section_current($section)) {
-				$section->sectionstyle = ' current';
-			}
-		}
-		
-		$section->edit=$this->section_title_without_link($section, $course);
-
-		$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
-		$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
-		$section->classes = ' accesshide';
-		if ($hasnamenotsecpg || $hasnamesecpg) {
-			$section->classes = '';
-		}
-		$section->sectionname = get_section_name($course, $section);
-		
-		$context = context_course::instance($course->id);
-		if($section->summary != ""){
-			$section->summary=$this->format_summary_text($section);
-		}
-		
-		$section->messageavailability= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
-
-
-		/* Paramètres */
-		$presence = "";
-		$format = course_get_format($course);
-		
-		$param_section = (object)$format->get_format_options($section);
-		if ($param_section !== false) {
-
-				if (isset($param_section->presence)) {
-					if ($param_section->presence == 1) {
-						$section->presence = true;
-						$section->distance =false;
-						$string_date_presence="Le ";
-					} else if ($param_section->presence == 2) {
-						$section->presence = false;
-						$section->distance =true;
-						$string_date_presence="Pour le ";
-					}
-					else{
-						$string_date_presence="Le ";
-						$section->presence = false;
-						$section->distance =false;
-					}
-				}
-
-				if (isset($param_section->daterendu) && $param_section->daterendu != 0) {
-					$section->date=date("j/m H:i", $param_section->daterendu);
-					$section->date_jour = date("j/m", $param_section->daterendu);
-					$section->date_heure =  date("H:i", $param_section->daterendu);
-
-					/*$section->dateUp = new DateTime("@$param_section->daterendu");
-					$section->date = $section->dateUp->format("j/m H:i");
-					$section->date_jour = $section->dateUp->format("j/m");
-					$section->date_heure = $section->dateUp->format("H:i");
-					$section->dateUp = $section->dateUp->getTimestamp();*/
-					if($string_date_presence){
-						$section->string_date=$string_date_presence.$section->date_jour." à ".$section->date_heure;
-					}
-					else{
-						$section->string_date="Le ".$section->date_jour." à ".$section->date_heure;
-					}
-				} else {
-					$section->date = "";
-				}
-		} else {
-			$section->date = "";
-		}
-		
-		//Bouton de suivi dans chaque section : si pas d'activités suivies on n'affiche pas le bouton
-		if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
-			$ressources_entity = new course_format_iena_section_ressources();
-			//$modules = $ressources_entity->get_ressources_completion_on_by_id_section($section->id);
-			$display_button=false;
-			foreach ($mods->get_cms() as $cm) {
-				if($cm->completion>0 && $cm->section==$section->id){
-					$display_button=true;
-					break;
-				}
-			}
-			//$nb_modules = count($modules);
-			if($display_button){
-				//si trop d'étudiants on va afficher le premier groupe dans le suivi
-				if($this->count_students($context)>299 && count($groups)>0){
-					$section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "&sectionid=" . $section->id . "&groupid=".reset($groups)->id;
-				}
-				else{
-					$section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "&sectionid=" . $section->id . "&groupid=0";
-				}
-				
-			}
-			
-			
-		}
-		else{
-			//On va chercher la progression pour la section
-			$section_progress=$completion_entity->get_completion_by_section([$section->name], [$section->id]);
-			if($section_progress){
-				$section->progress_exists=true;
-				$section->section_progress=$section_progress->total;
-				
-			}
-			
-			
-		}
-		
-	
-		return $section;
-	}
-
-	//useless
-	/*public function get_completion_by_section($idSection){
-		global $COURSE, $USER;
-		$ressources_entity = new course_format_iena_section_ressources();
-		$section_entity = new course_format_iena_sections();
-		$modules = $ressources_entity->get_ressources_completion_on_by_id_section($idSection);
-		$nb_modules = count($modules);
-		if ($nb_modules == 0) {
-			return array($nb_modules, 999);
-		}
-
-		$valueI = 100 / $nb_modules;
-		$valueTotal = 0;
-		foreach ($modules as $module) {
-			$complet = $ressources_entity->get_completions_by_module($USER->id, $COURSE->id, $module->id);
-			if ($complet->completionstate != 0) {
-				$valueTotal += $valueI;
-			}
-		}
-
-		return array($modules, $valueTotal);
-	}*/
-
-
-	//Bientôt useless
-	public function get_view_iena($course, $htmlsection, $nameSection, $introSection, $idSection){
-		global $CFG, $COURSE, $USER;
-		$section_entity = new course_format_iena_sections();
-
-		
-
-		// nouvelle génération du header
-
-		$view = "";
-
-		require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
-		// return false if completion disabled (site or course)
-		$cpl = course_format_iena_completion::get_completion_by_section($nameSection, $idSection);
-
-		/* Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue qui fait le header permet de ne pas récupérer deux fois les mêmes informations. */
-		$header = new view_course_header($nameSection, $idSection, $course, $cpl);
-		$view .= $header->get_content();
-
-		$i = 0;
-		$link = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id;
-		$view .= "<!-- <script defer src=\"https://use.fontawesome.com/releases/v5.0.8/js/all.js\"></script>  -->
-		<style>
-
-		/*
-		style for clean page
-		*/
-
-		/* [BOOST] : course header */
-		#page-header .card {
-					border: none;
-				}
-		#page-header .card-body {
-				padding-left: 0;
-			}
-			/* [BOOST] : left nav */
-		#nav-drawer,
-			[data-region='drawer'] {
-				background-color: #fff;
-			}
-		#nav-drawer .list-group-item {
-			border: 1px solid #ffffff;
-		}
-		#nav-drawer .list-group-item:hover {
-		background-color: #e7e9ea;
-		}
-		#nav-drawer .list-group-item.active:hover {
-		color: #000000;
-		}
-
-		/* [BOOST] : blocks */
-		#block-region-side-pre section.block {
-		border: none;
-		}
-		#block-region-side-pre section.block .card-body {
-		padding-top: 0;
-		}
-
-		/* [BOOST] : margin for ul, because ul is used to list sections */
-
-		ul, ul ul {
-			padding-left: 2.5rem;
-			margin-bottom: 0.5rem !important;
-		}
-
-		/* style for ? */
-
-					#completionprogressid {
-		display: none;
-		}
-
-		#region-main > .card {
-		border: none;
-		overflow-x: visible !important;
-		overflow-y: visible;
-		}
-
-		#region-main > .card > .card-body {
-		border: none;
-		padding: 0;
-		}
-
-		.centered {
-			display:flex;justify-content:center;align-items:center;
-		}
-		.contenu {
-			min-width: 15rem;
-		}
-		ul.bulle {
-			list-style: none;
-			padding:5%;
-		}
-
-		.bulle {
-			list-style: none;
-		}
-
-		.bulle > li {
-			list-style: none;
-			font-weight: normal;
-			font-size: 0.8rem;
-			line-height: 1rem;
-			padding-top: 5%;
-		}
-		</style>";
-		foreach ($htmlsection as $section) {
-			$presence = "";
-			if (!$section) {
-				continue;
-			}
-			$param_section = $section_entity->get_section_settings_by_id_section($idSection[$i]);
-			// dates, modality and notification section parameters : false if not set. 
-			if ($param_section !== false) {
-				if ($param_section->presence && $i != 0) {
-					if ($param_section->presence == 1) {
-						$presence = "En présence";
-					} else if ($param_section->presence == 2) {
-						$presence = "A distance";
-					}
-				}
-
-				if ($param_section->date_rendu) {
-					$dateUp = date_create($param_section->date_rendu);
-					$date = $dateUp->format("j/m H:i");
-					$date_jour = $dateUp->format("j/m");
-					$date_heure = $dateUp->format("H:i");
-					$dateUp = $dateUp->getTimestamp();
-				} else {
-					$date = "";
-				}
-			} else {
-				$date = "";
-			}
-
-			$titre = $nameSection[$i];
-			$sectionIntro = isset($introSection[$i]) ? $introSection[$i] : '';
-						//If section is hidden continue
-			if ($titre == null && !(has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id))) {
-				$i++;
-				continue;
-			}
-			$view .= "<section class=\"section iena-section\" id=\"section-$i\">
-			<div class=\"card card_block\">
-			<div class=\"heading-iena set_height\">";
-
-			if ( $cpl != false && count($cpl->sections[$i]->modules) > 0 && !has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
-				$view .= "<div class='iena-percent set_height'>" . $cpl->sections[$i]->completion . "%</div>";
-			}
-
-			if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
-			
-
-				$course_groups = groups_get_all_groups($COURSE->id);
-
-				$group_indicateur = 0;
-
-				$view .= "<a href='$link&sectionid=".$idSection[$i]."style='color : white'>";
-				$view .="<div onclick='change_grouplink(this)' style='display:block' class='nb_pers set_height id_groupe0'>";
-				$view .= "Suivi étudiants";
-				$view .= "</div>";
-				$view .="</a>";
-				
-				
-			}
-
-
-
-			$view .= "<div class=\"titre_section set_height\">
-			<p>$titre</p>
-			</div>
-			<div class=\"right_info\">
-			";
-						// if ($presence) {
-						// 	$view .= "
-						// 	<div class=\"label_item\">
-						// 	$presence
-						// 	</div>";
-						// }
-			if ($date) {
-				$link_date = $CFG->wwwroot . "/calendar/view.php?view=month&time=" . $dateUp . "&course=" . $COURSE->id;
-				if ($presence && $presence == "A distance") {
-					$view .= "
-					<div class=\"label_item sect-date\">
-					À distance
-					</div>
-					<div class=\"label_item sect-date\">
-					Pour le $date_jour à $date_heure
-					</div>";
-				} else if ($presence && $presence == "En présence") {	
-					$view .= "
-					<div class=\"label_item sect-date\">
-					En présence
-					</div>
-					<div class=\"label_item sect-date\">
-					Le $date_jour à $date_heure
-					</div>";
-				} else {
-					$view .= "
-					<div class=\"label_item sect-date\">
-					Le $date_jour à $date_heure
-					</div>";
-				}
-			} else {
-				if ($presence && $presence == "A distance") {
-					$view .= "
-					<div class=\"label_item sect-date\">
-					À distance
-					</div>";
-				} else if ($presence && $presence == "En présence") {	
-					$view .= "
-					<div class=\"label_item sect-date\">
-					En présence
-					</div>";
-				}
-			}
-			
-			$cpt = "";
-			if ($cpt != "") {
-				$view .= "
-				<div class=\"titre_section set_height\">
-
-				";
-				$view .= $cpt;
-				$view .= "</div>
-				";
-			}
-
-			$link_param = $CFG->wwwroot . "/course/format/iena/param_section.php?courseid=" . $COURSE->id . "&sectionid=" . $idSection[$i];
-			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
-				$view .= "<div class=\"titre_section set_height\">
-				<a href='$link_param' style=\"color : white\">
-				<i class=\"fa fa-cog \" aria-hidden=\"true\" ></i>
-				</a>
-				</div>";
-			}
-			$view .= "</div>
-
-			</div>
-			";
-			$view .= "<div class=\"wrapper section\">";
-			$view .= $sectionIntro;
-			
-			$view .= "<div class=\"wrapper\">
-			$section
-			</div >
-
-			</div>
-
-			</section>";
-			$i++;
-		}
-		return $view;
-	}
-
-	/**
-	 * Render le template du header avec les infos nécessaires : le progrès
-	 * @param StdObject $course 
-	 * @param array<string> $nameSections
-	 * @param array<int> $idSections
-	 * @return type
-	 */
-	public function get_view_iena_new($course,$nameSections, $idSections){
-		global $CFG, $COURSE, $USER;
-		$section_entity = new course_format_iena_sections();
-		require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
-		// return false if completion disabled (site or course)
-		$cpl = course_format_iena_completion::get_completion_by_section($nameSections, $idSections);
-
-		/* Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue qui fait le header permet de ne pas récupérer deux fois les mêmes informations. */
-		$header = new view_course_header($nameSections, $idSections, $course, $cpl);
-		$course_infos= $header->create_view($cpl);
-		//$course_infos=$header->get_data($cpl);
-
-
-		echo $this->render_from_template('format_iena/course-header', $course_infos);
-
-		
-	}
-
-
-
-	public function count_students($context){
-		$count = count_enrolled_users($context);
-		return $count;
-	}
-
-
-
-	//Seulement en mode édition - 
-	//bientôt useless
-	public function print_iena_section_pages($course){
-		global $PAGE, $USER;
-
-		
-
-		$context = context_course::instance($course->id);
-		$course = course_get_format($course)->get_course();
-		$completion = new \completion_info($course);
-
-
-		$modinfo = get_fast_modinfo($course);
-		// $course = course_get_format($course)->get_course();
-		
-		// $completioninfo = new completion_info($course);
-		if (isset($_COOKIE['sectionvisible_' . $course->id])) {
-			$sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
-		} elseif ($course->marker > 0) {
-			$sectionvisible = $course->marker;
-		} else {
-			$sectionvisible = 1;
-		}
-		$htmlsection = false;
-		$nameSection = [];
-		$idSection = false;
-		$introSection = false;
-		
-		//On récupère toutes les infos des sections
-		foreach ($modinfo->get_section_info_all() as $section => $thissection) {
-
-			//Nom de la section
-
-			$htmlsection[$section] = '';
-			
-			$numsections = course_get_format($course)->get_last_section_number();
-
-			// if ($section > $numsections) {
-			// // if ($section > $course->numsections) {
-			// 	// continue;
-			// }
-			/* if is not editing verify the rules to display the sections */
-			if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections', $context = context_course::instance($course->id), $USER->id))) {
-
-				//si la section est cachée
-				if (isset($course->hiddensections) && !(int)$thissection->visible) {
-					continue;
-				}
-
-				//si la section n'est pas disponible
-				if (!$thissection->available && !empty($thissection->availableinfo)) {
-					$htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
-					continue;
-				}
-
-				if (!$thissection->uservisible || !$thissection->visible) {
-					$htmlsection[$section] .= $this->section_hidden($section, $course->id);
-					continue;
-				}
-			}
-
-
-			//Affiche le nom de la section en mode propre sans lien
-			$idSection[$section] = $thissection->id;
-			// $nameSection[$section] .= $this->section_title_without_link($thissection, $course);
-			$nameSection[$section] = $this->section_title_without_link($thissection, $course);
-			if ($PAGE->user_is_editing()) {
-				$htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
-			}
-			$introSection[$section] = $this->section_header($thissection, $course, false, 0, true);
-			if ($thissection->uservisible) {
-				/* Ne pas enlever sinon le activity chooser ne fonctionne pas en JS */
-				$htmlsection[$section] .= "<div class='content'>";
-				// Renvoie le lien du cours avec icone
-				$htmlsection[$section] .= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
-				$htmlsection[$section] .= $this->courserenderer->course_section_add_cm_control($course, $section, 0);
-				$htmlsection[$section] .= "</div>";
-			}
-	
-			/* pas de footer car on ne commence par la structure par une div non fermée et que ce footer ferme par une div */
-			// $htmlsection[$section] .= $this->section_footer();
-			
-			
-		} //ENDFOREACH
-
-		// echo $completioninfo->display_help_icon();
-		
-		echo $this->output->heading($this->page_title(), 2, 'accesshide');
-		echo $this->course_activity_clipboard($course, 0);
-		echo $this->start_section_list();
-		
-		
-		//A ce stade on à toutes les activité déja prête en HTML par contre il manque le nom des sections
-		// Il se trouve dans : $thissection->name
-
-
-
-
-			//here all activities are displayed
-			//If we are in etition mode then we display the "BASE" page Otherwise our model
-		if (!$PAGE->user_is_editing()) {
-			echo $this->get_view_iena($course, $htmlsection, $nameSection, $introSection, $idSection);
-		} else {
-			foreach ($htmlsection as $current) {
-				echo $current;
-			}
-		}
-			//At this stage nothing is yet displayed except the icon: Your progress
-			// if ($course->sectionposition == 1 and isset($htmlsection0)) {
-				// if ($PAGE->user_is_editing())
-				// 	echo html_writer::tag('span', $htmlsection0, ['class' => 'below']);
-			// }
-
-			//Add the + and - at the end of the page to see which part of the code to really keep
-		if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
-			foreach ($modinfo->get_section_info_all() as $section => $thissection) {
-				if ($section <= $numsections or empty($modinfo->sections[$section])) {
-					continue;
-				}
-				echo $this->stealth_section_header($section);
-				echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
-				echo $this->stealth_section_footer();
-			}
-			echo $this->end_section_list();
-			echo html_writer::start_tag('div', ['id' => 'changenumsections', 'class' => 'mdl-right']);
-			$straddsection = get_string('addsections');
-			$url = $url = new moodle_url('/course/changenumsections.php', ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false, 'sesskey' => sesskey(), 'sectionreturn' => 0]);
-			$icon = $this->output->pix_icon('t/switch_plus', $straddsection);
-			echo html_writer::link($url, $icon . $straddsection, ['class' => 'increase-sections']);
-				
-			echo html_writer::end_tag('div');
-		} else {
-			echo $this->end_section_list();
-		}
-		echo html_writer::tag('style', '.course-content ul.iena #section-' . $sectionvisible . ' { display: block; }');
-		//if (!$PAGE->user_is_editing()) {
-				//$PAGE->requires->js_init_call('M.format_iena.init', [$course->numsections]);
-		//}
-
-	}
-
-	/**
-	 * Fetch the course sections with infos
-	 * @param StdObject $course 
-	 * @param bool $onsectionpage 
-	 * @return templates
-	 */
-	public function get_iena_sections($course, $editing, $onsectionpage=false){
-		global $PAGE, $USER;
-
-		$context = context_course::instance($course->id);
-		
-		$completion = new \completion_info($course);
-		$groups=groups_get_all_groups($course->id);
-		
-
-
-		$modinfo = get_fast_modinfo($course);
-		
-		if (isset($_COOKIE['sectionvisible_' . $course->id])) {
-			$sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
-		} elseif ($course->marker > 0) {
-			$sectionvisible = $course->marker;
-		} else {
-			$sectionvisible = 1;
-		}
-		$htmlsection = false;
-		$nameSections = [];
-		$idSections = [];
-		$introSection = false;
-	
-
-
-		$sections=['sections'=>[]];
-
-
-		
-
-		foreach($modinfo->get_section_info_all() as $section => $thissection){
-			if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections', $context = context_course::instance($course->id), $USER->id))) {
-				if (isset($course->hiddensections) && !(int)$thissection->visible) {
-					continue;
-				}
-				if (!$thissection->available && !empty($thissection->availableinfo)) {
-					$thissection= $this->get_section_header($thissection, $course, false,$modinfo, 0, $groups);
-					
-					continue;
-				}
-				if (!$thissection->uservisible || !$thissection->visible) {
-					$htmlsection = $this->section_hidden($section, $course->id);
-					
-					continue;
-				}
-			}
-			$thissection=$this->get_section_header($thissection, $course, false, $modinfo,0, true, $groups);
-
-			if ($thissection->uservisible) {
-				$thissection->resources= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
-				if ($editing) {
-
-					$thissection->addresources = $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
-					$thissection->leftcontent = $this->section_left_content($thissection, $course, $onsectionpage);
-					$thissection->rightcontent = $this->section_right_content($thissection, $course, $onsectionpage);
-
-				}
-		
-			}
-
-
-			array_push($sections['sections'], $thissection);
-			array_push($nameSections, $thissection->name);
-			array_push($idSections, $thissection->id);
-		}
-		if($editing){
-			$sections['link_add_sections']=new moodle_url('/course/changenumsections.php', ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false, 'sesskey' => sesskey(), 'sectionreturn' => 0]);
-		}
-
-		echo $this->get_view_iena_new($course, $nameSections, $idSections);
-		echo $this->render_from_template('format_iena/sections', $sections);
-		
-	}
-
-
-
-	//If edit mode, we use the old code that generates HTML, else we use the templates - bientôt useless
-	public function switch_mode($course){
-		global $PAGE, $CFG;
-		$context = context_course::instance($course->id);
-		$course = course_get_format($course)->get_course();
-		if($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)){
-			//$this->print_iena_section_pages($course);
-			$this->get_iena_sections($course, true);
-		}
-		else{
-			
-			$this->get_iena_sections($course, false);
-		}
-	}
-
-	public function display_completion($data){
-		echo $this->render_from_template('format_iena/suivi', $data);
-	}
-
-	public function display_table_completion($data){
-		echo $this->render_from_template('format_iena/suivi-table', $data);
-	}
-
-	public function display_message($data){
-		echo $this->render_from_template('format_iena/send-message', $data);
-	}
-}
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * format_iena
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille/Thomas Fradet
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->dirroot . '/course/format/topics/renderer.php');
+require_once($CFG->dirroot . '/course/format/iena/view/view_course_header.php');
+
+/**
+ * format_iena_renderer
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class format_iena_renderer extends format_topics_renderer {
+
+    /**
+     * start_section_list
+     *
+     * @return string
+     */
+    // Bientôt useless.
+    protected function start_section_list() {
+        return html_writer::start_tag('ul', ['class' => 'iena-editing']);
+    }
+
+    /**
+     * section_header
+     *
+     * @param stdclass $section
+     * @param stdclass $course
+     * @param bool $onsectionpage
+     * @param int $sectionreturn
+     * @return string
+     */
+    // Bientôt useless.
+    protected function section_header($section, $course, $onsectionpage, $sectionreturn = null, $iena = false) {
+        global $PAGE, $CFG;
+        $o = '';
+        $currenttext = '';
+        $sectionstyle = '';
+        if ($section->section != 0) {
+            if (!$section->visible) {
+                $sectionstyle = ' hidden';
+            } else if (course_get_format($course)->is_section_current($section)) {
+                $sectionstyle = ' current';
+            }
+        }
+
+        if ($PAGE->user_is_editing()) {
+            $o .= html_writer::start_tag('li', ['id' => 'section-' . $section->section,
+                'class' => 'section main clearfix' . $sectionstyle,
+                'role' => 'region', 'aria-label' => get_section_name($course, $section)]);
+        }
+
+        $o .= html_writer::tag('span', $this->section_title($section, $course), ['class' => 'hidden sectionname']);
+
+        // This is were the editing menu is generated.
+        if ($PAGE->user_is_editing()) {
+            $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
+            $o .= html_writer::tag('div', $leftcontent, ['class' => 'left side']);
+            $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
+            $o .= html_writer::tag('div', $rightcontent, ['class' => 'right side']);
+        }
+
+        $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
+        $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
+        $classes = ' accesshide';
+        if ($hasnamenotsecpg || $hasnamesecpg) {
+            $classes = '';
+        }
+        $sectionname = html_writer::tag('span', $this->section_title($section, $course));
+        if ($PAGE->user_is_editing()) {
+            $o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
+        }
+
+        $context = context_course::instance($course->id);
+
+        // Résumé de section.
+        if ( $section->summary != "" ) {
+            $o .= html_writer::start_tag('div', ['class' => 'iena-description']);
+            $o .= html_writer::start_tag('div', ['class' => 'small']);
+
+            $o .= html_writer::start_tag('div', ['class' => 'iena-summary']);
+            $o .= $this->format_summary_text($section);
+            $o .= html_writer::end_tag('div');
+
+            $o .= html_writer::end_tag('div');
+            $o .= html_writer::end_tag('div');
+            $o .= html_writer::tag('a', 'Voir la description complète', ['href' => '#', 'class' => 'voir-plus']);
+        }
+
+        $o .= $this->section_availability_message($section, has_capability('moodle/course:viewhiddensections', $context));
+
+        return $o;
+    }
+
+    /**
+     * Add style attributes, classes (useless?), format section summary and add the hidden/restricted message
+     * @param StdClass $section
+     * @param StdClass $course
+     * @param bool $onsectionpage
+     * @param type|null $sectionreturn
+     * @param type|bool $iena
+     * @param type $groups
+     * @return type
+     */
+    protected function get_section_header($section, $course, $onsectionpage, $mods,
+            $sectionreturn = null, $iena = false, $groups=false) {
+        global $PAGE, $CFG, $COURSE, $USER;
+        $completionentity = new course_format_iena_completion();
+        $o = '';
+        $currenttext = '';
+        $sectionstyle = '';
+        if ($section->section != 0) {
+            if (!$section->visible) {
+                $section->sectionstyle = ' hidden';
+            } else if (course_get_format($course)->is_section_current($section)) {
+                $section->sectionstyle = ' current';
+            }
+        }
+
+        $section->edit = $this->section_title_without_link($section, $course);
+
+        $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
+        $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
+        $section->classes = ' accesshide';
+        if ($hasnamenotsecpg || $hasnamesecpg) {
+            $section->classes = '';
+        }
+        $section->sectionname = get_section_name($course, $section);
+
+        $context = context_course::instance($course->id);
+        if ($section->summary != "") {
+            $section->summary = $this->format_summary_text($section);
+        }
+
+        $section->messageavailability = $this->section_availability_message($section,
+            has_capability('moodle/course:viewhiddensections', $context));
+
+        // Paramètres.
+        $presence = "";
+        $format = course_get_format($course);
+
+        $paramsection = (object)$format->get_format_options($section);
+        if ($paramsection !== false) {
+            if (isset($paramsection->presence)) {
+                if ($paramsection->presence == 1) {
+                    $section->presence = true;
+                    $section->distance = false;
+                    $stringdatepresence = "Le ";
+                } else if ($paramsection->presence == 2) {
+                    $section->presence = false;
+                    $section->distance = true;
+                    $stringdatepresence = "Pour le ";
+                } else {
+                    $stringdatepresence = "Le ";
+                    $section->presence = false;
+                    $section->distance = false;
+                }
+            }
+
+            if (isset($paramsection->daterendu) && $paramsection->daterendu != 0) {
+                $section->date = date("j/m H:i", $paramsection->daterendu);
+                $section->date_jour = date("j/m", $paramsection->daterendu);
+                $section->date_heure = date("H:i", $paramsection->daterendu);
+
+                if ($stringdatepresence) {
+                    $section->string_date = $stringdatepresence.$section->date_jour." à ".$section->date_heure;
+                } else {
+                    $section->string_date = "Le ".$section->date_jour." à ".$section->date_heure;
+                }
+            } else {
+                $section->date = "";
+            }
+        } else {
+            $section->date = "";
+        }
+
+        // Bouton de suivi dans chaque section : si pas d'activités suivies on n'affiche pas le bouton.
+        if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
+            $ressourcesentity = new course_format_iena_section_ressources();
+            $displaybutton = false;
+            foreach ($mods->get_cms() as $cm) {
+                if ($cm->completion > 0 && $cm->section == $section->id) {
+                    $displaybutton = true;
+                    break;
+                }
+            }
+            if ($displaybutton) {
+                // Si trop d'étudiants on va afficher le premier groupe dans le suivi.
+                if ($this->count_students($context) > 299 && count($groups) > 0) {
+                    $section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" .
+                    $COURSE->id . "&sectionid=" . $section->id .
+                    "&groupid=".reset($groups)->id;
+                } else {
+                    $section->link_suivi = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid="
+                    . $COURSE->id . "&sectionid=" . $section->id . "&groupid=0";
+                }
+
+            }
+        } else {
+            // On va chercher la progression pour la section.
+            $sectionprogress = $completionentity->get_completion_by_section([$section->name], [$section->id]);
+            if ($sectionprogress) {
+                $section->progress_exists = true;
+                $section->section_progress = $sectionprogress->total;
+            }
+        }
+        return $section;
+    }
+
+    // Bientôt useless.
+    public function get_view_iena($course, $htmlsection, $namesection, $introsection, $idsection) {
+        global $CFG, $COURSE, $USER;
+        $sectionentity = new course_format_iena_sections();
+
+        // Nouvelle génération du header.
+        $view = "";
+
+        require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
+        // Return false if completion disabled (site or course).
+        $cpl = course_format_iena_completion::get_completion_by_section($namesection, $idsection);
+
+        // Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue
+        // qui fait le header permet de ne pas récupérer deux fois les mêmes informations.
+        $header = new view_course_header($namesection, $idsection, $course, $cpl);
+        $view .= $header->get_content();
+
+        $i = 0;
+        $link = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id;
+        $view .= "<!-- <script defer src=\"https://use.fontawesome.com/releases/v5.0.8/js/all.js\"></script>  -->
+        <style>
+
+        /*
+        style for clean page
+        */
+
+        /* [BOOST] : course header */
+        #page-header .card {
+                    border: none;
+                }
+        #page-header .card-body {
+                padding-left: 0;
+            }
+            /* [BOOST] : left nav */
+        #nav-drawer,
+            [data-region='drawer'] {
+                background-color: #fff;
+            }
+        #nav-drawer .list-group-item {
+            border: 1px solid #ffffff;
+        }
+        #nav-drawer .list-group-item:hover {
+        background-color: #e7e9ea;
+        }
+        #nav-drawer .list-group-item.active:hover {
+        color: #000000;
+        }
+
+        /* [BOOST] : blocks */
+        #block-region-side-pre section.block {
+        border: none;
+        }
+        #block-region-side-pre section.block .card-body {
+        padding-top: 0;
+        }
+
+        /* [BOOST] : margin for ul, because ul is used to list sections */
+
+        ul, ul ul {
+            padding-left: 2.5rem;
+            margin-bottom: 0.5rem !important;
+        }
+
+        /* style for ? */
+
+                    #completionprogressid {
+        display: none;
+        }
+
+        #region-main > .card {
+        border: none;
+        overflow-x: visible !important;
+        overflow-y: visible;
+        }
+
+        #region-main > .card > .card-body {
+        border: none;
+        padding: 0;
+        }
+
+        .centered {
+            display:flex;justify-content:center;align-items:center;
+        }
+        .contenu {
+            min-width: 15rem;
+        }
+        ul.bulle {
+            list-style: none;
+            padding:5%;
+        }
+
+        .bulle {
+            list-style: none;
+        }
+
+        .bulle > li {
+            list-style: none;
+            font-weight: normal;
+            font-size: 0.8rem;
+            line-height: 1rem;
+            padding-top: 5%;
+        }
+        </style>";
+        foreach ($htmlsection as $section) {
+            $presence = "";
+            if (!$section) {
+                continue;
+            }
+            $paramsection = $sectionentity->get_section_settings_by_id_section($idsection[$i]);
+            // Dates, modality and notification section parameters : false if not set.
+            if ($paramsection !== false) {
+                if ($paramsection->presence && $i != 0) {
+                    if ($paramsection->presence == 1) {
+                        $presence = "En présence";
+                    } else if ($paramsection->presence == 2) {
+                        $presence = "A distance";
+                    }
+                }
+
+                if ($paramsection->date_rendu) {
+                    $dateup = date_create($paramsection->date_rendu);
+                    $date = $dateup->format("j/m H:i");
+                    $datejour = $dateup->format("j/m");
+                    $dateheure = $dateup->format("H:i");
+                    $dateup = $dateup->getTimestamp();
+                } else {
+                    $date = "";
+                }
+            } else {
+                $date = "";
+            }
+
+            $titre = $namesection[$i];
+            $sectionintro = isset($introsection[$i]) ? $introsection[$i] : '';
+            // If section is hidden continue.
+            if ($titre == null && !(has_capability('moodle/course:update',
+                $context = context_course::instance($COURSE->id), $USER->id))) {
+                $i++;
+                continue;
+            }
+            $view .= "<section class=\"section iena-section\" id=\"section-$i\">
+            <div class=\"card card_block\">
+            <div class=\"heading-iena set_height\">";
+
+            if ($cpl != false && count($cpl->sections[$i]->modules) > 0
+                && !has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id)) {
+                $view .= "<div class='iena-percent set_height'>" . $cpl->sections[$i]->completion . "%</div>";
+            }
+
+            if (has_capability('course/iena:suivi', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
+                $coursegroups = groups_get_all_groups($COURSE->id);
+
+                $groupindicateur = 0;
+
+                $view .= "<a href='$link&sectionid=".$idsection[$i]."style='color : white'>";
+                $view .= "<div onclick='change_grouplink(this)' style='display:block' class='nb_pers set_height id_groupe0'>";
+                $view .= "Suivi étudiants";
+                $view .= "</div>";
+                $view .= "</a>";
+            }
+
+            $view .= "<div class=\"titre_section set_height\">
+            <p>$titre</p>
+            </div>
+            <div class=\"right_info\">
+            ";
+
+            if ($date) {
+                $linkdate = $CFG->wwwroot . "/calendar/view.php?view=month&time=" . $dateup . "&course=" . $COURSE->id;
+                if ($presence && $presence == "A distance") {
+                    $view .= "
+                    <div class=\"label_item sect-date\">
+                    À distance
+                    </div>
+                    <div class=\"label_item sect-date\">
+                    Pour le $datejour à $dateheure
+                    </div>";
+                } else if ($presence && $presence == "En présence") {
+                    $view .= "
+                    <div class=\"label_item sect-date\">
+                    En présence
+                    </div>
+                    <div class=\"label_item sect-date\">
+                    Le $datejour à $dateheure
+                    </div>";
+                } else {
+                    $view .= "
+                    <div class=\"label_item sect-date\">
+                    Le $datejour à $dateheure
+                    </div>";
+                }
+            } else {
+                if ($presence && $presence == "A distance") {
+                    $view .= "
+                    <div class=\"label_item sect-date\">
+                    À distance
+                    </div>";
+                } else if ($presence && $presence == "En présence") {
+                    $view .= "
+                    <div class=\"label_item sect-date\">
+                    En présence
+                    </div>";
+                }
+            }
+
+            $cpt = "";
+            if ($cpt != "") {
+                $view .= "
+                <div class=\"titre_section set_height\">
+
+                ";
+                $view .= $cpt;
+                $view .= "</div>
+                ";
+            }
+
+            $linkparam = $CFG->wwwroot . "/course/format/iena/param_section.php?courseid=" . $COURSE->id .
+            "&sectionid=" . $idsection[$i];
+            if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id) && $i != 0) {
+                $view .= "<div class=\"titre_section set_height\">
+                <a href='$linkparam' style=\"color : white\">
+                <i class=\"fa fa-cog \" aria-hidden=\"true\" ></i>
+                </a>
+                </div>";
+            }
+            $view .= "</div>
+
+            </div>
+            ";
+            $view .= "<div class=\"wrapper section\">";
+            $view .= $sectionintro;
+
+            $view .= "<div class=\"wrapper\">
+            $section
+            </div >
+
+            </div>
+
+            </section>";
+            $i++;
+        }
+
+        return $view;
+    }
+
+    /**
+     * Render le template du header avec les infos nécessaires : le progrès
+     * @param StdObject $course
+     * @param array<string> $nameSections
+     * @param array<int> $idSections
+     * @return type
+     */
+    public function get_view_iena_new($course, $namesections, $idsections) {
+        global $CFG, $COURSE, $USER;
+        $sectionentity = new course_format_iena_sections();
+        require_once($CFG->dirroot . '/course/format/iena/entity/course_format_iena_completion.php');
+        // Return false if completion disabled (site or course).
+        $cpl = course_format_iena_completion::get_completion_by_section($namesections, $idsections);
+
+        // Passer le calcul de complétion de la classe course_format_iena_completion à part à la vue
+        // qui fait le header permet de ne pas récupérer deux fois les mêmes informations.
+        $header = new view_course_header($namesections, $idsections, $course, $cpl);
+        $courseinfos = $header->create_view($cpl);
+
+        echo $this->render_from_template('format_iena/course-header', $courseinfos);
+    }
+
+    public function count_students($context) {
+        $count = count_enrolled_users($context);
+        return $count;
+    }
+
+    // Seulement en mode édition -
+    // bientôt useless.
+    public function print_iena_section_pages($course) {
+        global $PAGE, $USER;
+
+        $context = context_course::instance($course->id);
+        $course = course_get_format($course)->get_course();
+        $completion = new \completion_info($course);
+
+        $modinfo = get_fast_modinfo($course);
+
+        if (isset($_COOKIE['sectionvisible_' . $course->id])) {
+            $sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
+        } else if ($course->marker > 0) {
+            $sectionvisible = $course->marker;
+        } else {
+            $sectionvisible = 1;
+        }
+        $htmlsection = false;
+        $namesection = [];
+        $idsection = false;
+        $introsection = false;
+
+        // On récupère toutes les infos des sections.
+        foreach ($modinfo->get_section_info_all() as $section => $thissection) {
+
+            // Nom de la section.
+            $htmlsection[$section] = '';
+
+            $numsections = course_get_format($course)->get_last_section_number();
+
+            // If is not editing verify the rules to display the sections.
+            if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections',
+                $context = context_course::instance($course->id), $USER->id))) {
+
+                // Si la section est cachée.
+                if (isset($course->hiddensections) && !(int)$thissection->visible) {
+                    continue;
+                }
+
+                // Si la section n'est pas disponible.
+                if (!$thissection->available && !empty($thissection->availableinfo)) {
+                    $htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
+                    continue;
+                }
+
+                if (!$thissection->uservisible || !$thissection->visible) {
+                    $htmlsection[$section] .= $this->section_hidden($section, $course->id);
+                    continue;
+                }
+            }
+
+            // Affiche le nom de la section en mode propre sans lien.
+            $idsection[$section] = $thissection->id;
+            $namesection[$section] = $this->section_title_without_link($thissection, $course);
+            if ($PAGE->user_is_editing()) {
+                $htmlsection[$section] .= $this->section_header($thissection, $course, false, 0);
+            }
+            $introsection[$section] = $this->section_header($thissection, $course, false, 0, true);
+            if ($thissection->uservisible) {
+                // Ne pas enlever sinon le activity chooser ne fonctionne pas en JS.
+                $htmlsection[$section] .= "<div class='content'>";
+                // Renvoie le lien du cours avec icone.
+                $htmlsection[$section] .= $this->courserenderer->course_section_cm_list($course, $thissection, 0);
+                $htmlsection[$section] .= $this->courserenderer->course_section_add_cm_control($course, $section, 0);
+                $htmlsection[$section] .= "</div>";
+            }
+
+            // Pas de footer car on ne commence par la structure par une div non fermée et que ce footer ferme par une div.
+
+        }
+
+        echo $this->output->heading($this->page_title(), 2, 'accesshide');
+        echo $this->course_activity_clipboard($course, 0);
+        echo $this->start_section_list();
+
+        // A ce stade on à toutes les activité déja prête en HTML par contre il manque le nom des sections.
+        // Il se trouve dans : $thissection->name.
+
+        // Here all activities are displayed
+        // If we are in edition mode then we display the "BASE" page Otherwise our model.
+        if (!$PAGE->user_is_editing()) {
+            echo $this->get_view_iena($course, $htmlsection, $namesection, $introsection, $idsection);
+        } else {
+            foreach ($htmlsection as $current) {
+                echo $current;
+            }
+        }
+
+        // At this stage nothing is yet displayed except the icon: Your progress.
+
+        // Add the + and - at the end of the page to see which part of the code to really keep.
+        if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
+            foreach ($modinfo->get_section_info_all() as $section => $thissection) {
+                if ($section <= $numsections or empty($modinfo->sections[$section])) {
+                    continue;
+                }
+                echo $this->stealth_section_header($section);
+                echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
+                echo $this->stealth_section_footer();
+            }
+            echo $this->end_section_list();
+            echo html_writer::start_tag('div', ['id' => 'changenumsections', 'class' => 'mdl-right']);
+            $straddsection = get_string('addsections');
+            $url = $url = new moodle_url('/course/changenumsections.php',
+                ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false,
+                'sesskey' => sesskey(), 'sectionreturn' => 0]);
+            $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
+            echo html_writer::link($url, $icon . $straddsection, ['class' => 'increase-sections']);
+
+            echo html_writer::end_tag('div');
+        } else {
+            echo $this->end_section_list();
+        }
+        echo html_writer::tag('style', '.course-content ul.iena #section-' . $sectionvisible . ' { display: block; }');
+    }
+
+    /**
+     * Fetch the course sections with infos
+     * @param StdObject $course
+     * @param bool $onsectionpage
+     * @return templates
+     */
+    public function get_iena_sections($course, $editing, $onsectionpage=false) {
+        global $PAGE, $USER;
+
+        $context = context_course::instance($course->id);
+
+        $completion = new \completion_info($course);
+        $groups = groups_get_all_groups($course->id);
+        $modinfo = get_fast_modinfo($course);
+
+        if (isset($_COOKIE['sectionvisible_' . $course->id])) {
+            $sectionvisible = $_COOKIE['sectionvisible_' . $course->id];
+        } else if ($course->marker > 0) {
+            $sectionvisible = $course->marker;
+        } else {
+            $sectionvisible = 1;
+        }
+        $htmlsection = false;
+        $namesections = [];
+        $idsections = [];
+        $introsection = false;
+
+        $sections = ['sections' => []];
+
+        foreach ($modinfo->get_section_info_all() as $section => $thissection) {
+            if (!$PAGE->user_is_editing() && (!has_capability('moodle/course:viewhiddensections',
+                $context = context_course::instance($course->id), $USER->id))) {
+                if (isset($course->hiddensections) && !(int)$thissection->visible) {
+                    continue;
+                }
+                if (!$thissection->available && !empty($thissection->availableinfo)) {
+                    $thissection = $this->get_section_header($thissection, $course, false, $modinfo, 0, $groups);
+
+                    continue;
+                }
+                if (!$thissection->uservisible || !$thissection->visible) {
+                    $htmlsection = $this->section_hidden($section, $course->id);
+
+                    continue;
+                }
+            }
+            $thissection = $this->get_section_header($thissection, $course, false, $modinfo, 0, true, $groups);
+
+            if ($thissection->uservisible) {
+                $thissection->resources = $this->courserenderer->course_section_cm_list($course,
+                    $thissection, 0);
+                if ($editing) {
+                    $thissection->addresources =
+                        $this->courserenderer->course_section_add_cm_control($course, $thissection->section, 0);
+                    $thissection->leftcontent =
+                        $this->section_left_content($thissection, $course, $onsectionpage);
+                    $thissection->rightcontent =
+                        $this->section_right_content($thissection, $course, $onsectionpage);
+                }
+            }
+
+            array_push($sections['sections'], $thissection);
+            array_push($namesections, $thissection->name);
+            array_push($idsections, $thissection->id);
+        }
+        if ($editing) {
+            $sections['link_add_sections'] = new moodle_url('/course/changenumsections.php',
+                ['courseid' => $course->id, 'insertsection' => 0, 'increase' => false,
+                    'sesskey' => sesskey(), 'sectionreturn' => 0]);
+        }
+
+        echo $this->get_view_iena_new($course, $namesections, $idsections);
+        echo $this->render_from_template('format_iena/sections', $sections);
+    }
+
+    // If edit mode, we use the old code that generates HTML, else we use the templates - bientôt useless.
+    public function switch_mode($course) {
+        global $PAGE, $CFG;
+        $context = context_course::instance($course->id);
+        $course = course_get_format($course)->get_course();
+        if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
+            $this->get_iena_sections($course, true);
+        } else {
+            $this->get_iena_sections($course, false);
+        }
+    }
+
+    public function display_completion($data) {
+        echo $this->render_from_template('format_iena/suivi', $data);
+    }
+
+    public function display_table_completion($data) {
+        echo $this->render_from_template('format_iena/suivi-table', $data);
+    }
+
+    public function display_message($data) {
+        echo $this->render_from_template('format_iena/send-message', $data);
+    }
+}
diff --git a/send_message.php b/send_message.php
index f589f690fe55156c71019a4a87f7612ece00d616..e5ddc598500547cd1340180b0c3ad58d77c4d2f9 100644
--- a/send_message.php
+++ b/send_message.php
@@ -1,11 +1,4 @@
 <?php
-	/**
-	 * Created by PhpStorm.
-	 * User: softia
-	 * Date: 06/03/18
-	 * Time: 10:20
-	 */
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -20,168 +13,112 @@
 //
 // You should have received a copy of the GNU General Public License
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     vrignaud camille
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	define('NO_OUTPUT_BUFFERING', true);
-	require_once('../../../config.php');
-	
-	global $COURSE, $DB, $USER, $CFG;
-	
-	$courseID = required_param('courseid', PARAM_INT);
-	$url = new moodle_url('/course/format/iena/send_message.php', array('courseid' => $courseID));
-	
-	$PAGE->set_pagelayout('course');
-	$PAGE->set_url($url);
-	
-	if (!has_capability('course/iena:suivi', $context = context_course::instance($courseID), $USER->id)) {
-		$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-		header("Location: {$link}");
-		exit;
-	}
-	
-	$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
-	require_login($course, false, NULL);
-	
-	/*if (isset($_POST['action'])) {
-		$messageContent = $_POST['summary']['text'];
-		$usersid = explode(",", $_POST["usersid"]);
-		// $messageContent .= "<br>". get_string('course', 'format_iena') . " : " . $course->fullname;
-		$messageContent .= "<br>". get_string('course', 'format_iena') . " :  <a href='" . $CFG->wwwroot . "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a>";
-		$messageContent .= "<br> ". get_string('prof', 'format_iena') . " : " . $USER->firstname . " " . $USER->lastname;
-		$brutMessageContent = $course->fullname . " " . $_POST['summary']['text'];
-		$course_ctx = context_course::instance($courseID);
-		$students = get_enrolled_users($course_ctx);
-		
-		// sending a notification to each students
-		foreach ($usersid as $userID) {
-			foreach ($students as $student) {
-				if ($student->id == $userID) {
-					$message = new \core\message\message();
-					$message->courseid = $course->id;
-					$message->component = 'moodle';
-					$message->name = 'instantmessage';
-					$message->userfrom = $USER;
-					$message->notification = '0';
-					$message->fullmessageformat = FORMAT_HTML;
-					$message->subject = "Rappel : " . $course->fullname;
-					$message->smallmessage = $messageContent;
-					$message->fullmessage = $brutMessageContent;
-					$message->fullmessagehtml = $messageContent;
-					$message->userto = $student;
-					$messageid = message_send($message);
-					break;
-				}
-			}
-		}
-		$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-		header("Location: {$link}");
-		exit;
-	}*/
-	
-	//$dataSection = $DB->get_record('format_iena', array('id_section' => $sectionId), '*');
-	//$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
-	// require_login($course, false, NULL);
-
-	$students="";
-	$back_url=$CFG->wwwroot . '/course/view.php?id=' . $courseID;
-	
-	if(isset($_POST["students"])){
-		$students=$_POST["students"];
-	}
-	if(isset($_POST["back_url"])){
-		$back_url=$_POST["back_url"];
-		
-	}
-
-
-	$data=new stdClass();
-	$nb = $students != "" ? count( explode(",", $students) ) : 0;
-	require_once('entity/course_format_iena_message.php');
-	$send_message = new course_format_iena_message(null, array('back_url'=>$back_url, 'students'=>$students));
-	
-	if ( $nb == 0 ) {
-		$data->nb_results=0;
-		
-	} else {
-		$data->nb_results=$nb;
-		$data->users_id=$students;
-		$courseID = required_param('courseid', PARAM_INT);
-		$data->link_cancel= $CFG->wwwroot . "/course/view.php?id=" . $courseID;;
-		$data->form=$send_message->render();
-	}
-
-	
-
-	
-	//if form is cancelled, we go back to the table. Else, we send the message and then go back to the table, with a success or failure message.
-	if($send_message->is_cancelled()){
-		$back_url=$CFG->wwwroot . '/course/format/iena/suivi_unit.php'.$back_url;
-		
-		header("Location: {$back_url}");
-	}
-	else if ($fromform = $send_message->get_data()) {
-		$back_url=$CFG->wwwroot . '/course/format/iena/suivi_unit.php'.$back_url;
-		
-		try{
-			$messageContent = $fromform->summary['text'];
-			
-			$usersid = explode(",", $fromform->students);
-			
-			$messageContent .= "<br>". get_string('course', 'format_iena') . " :  <a href='" . $CFG->wwwroot . "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a>";
-			$messageContent .= "<br> ". get_string('prof', 'format_iena') . " : " . $USER->firstname . " " . $USER->lastname;
-			$brutMessageContent = $course->fullname . " " . $_POST['summary']['text'];
-			$course_ctx = context_course::instance($courseID);
-			$students = get_enrolled_users($course_ctx);
-			
-			// sending a notification to each students
-			foreach ($usersid as $userID) {
-				foreach ($students as $student) {
-					if ($student->id == $userID) {
-						$message = new \core\message\message();
-						$message->courseid = $course->id;
-						$message->component = 'moodle';
-						$message->name = 'instantmessage';
-						$message->userfrom = $USER;
-						$message->notification = '0';
-						$message->fullmessageformat = FORMAT_HTML;
-						$message->subject = "Rappel : " . $course->fullname;
-						$message->smallmessage = $messageContent;
-						$message->fullmessage = $brutMessageContent;
-						$message->fullmessagehtml = $messageContent;
-						$message->userto = $student;
-						$messageid = message_send($message);
-						break;
-					}
-				}
-			}
-			$back_url.="&msg_success=true";
-		}
-		catch(Exception $e){
-			$back_url.="&msg_failure=true";
-		}
-		
-    	header("Location: {$back_url}");
-	}
-	else{
-		echo $OUTPUT->header();
-		$renderer = $PAGE->get_renderer('format_iena');
-		$renderer->display_message($data);
-		echo $OUTPUT->footer();
-	}
-
-
-
-	//echo $view_param_section->get_content($course, $dataSection);
-	
-	
-	
-	
+/**
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('NO_OUTPUT_BUFFERING', true);
+require_once('../../../config.php');
+
+global $COURSE, $DB, $USER, $CFG;
+
+$courseid = required_param('courseid', PARAM_INT);
+$url = new moodle_url('/course/format/iena/send_message.php', array('courseid' => $courseid));
+
+$PAGE->set_pagelayout('course');
+$PAGE->set_url($url);
+
+if (!has_capability('course/iena:suivi',
+    $context = context_course::instance($courseid), $USER->id)) {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+}
+
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+require_login($course, false, null);
+
+$students = "";
+$backurl = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+
+if (isset($_POST["students"])) {
+    $students = $_POST["students"];
+}
+if (isset($_POST["back_url"])) {
+    $backurl = $_POST["back_url"];
+}
+
+$data = new stdClass();
+$nb = $students != "" ? count( explode(",", $students) ) : 0;
+require_once('entity/course_format_iena_message.php');
+$sendmessage = new course_format_iena_message(null, array('back_url' => $backurl,
+    'students' => $students));
+
+if ($nb == 0) {
+    $data->nb_results = 0;
+} else {
+    $data->nb_results = $nb;
+    $data->users_id = $students;
+    $courseid = required_param('courseid', PARAM_INT);
+    $data->link_cancel = $CFG->wwwroot . "/course/view.php?id=" . $courseid;
+    $data->form = $sendmessage->render();
+}
+
+// If form is cancelled, we go back to the table.
+// Else, we send the message and then go back to the table, with a success or failure message.
+if ($sendmessage->is_cancelled()) {
+    $backurl = $CFG->wwwroot . '/course/format/iena/suivi_unit.php'.$backurl;
+
+    header("Location: {$backurl}");
+} else if ($fromform = $sendmessage->get_data()) {
+    $backurl = $CFG->wwwroot . '/course/format/iena/suivi_unit.php'.$backurl;
+    try {
+        $messagecontent = $fromform->summary['text'];
+
+        $usersid = explode(",", $fromform->students);
+
+        $messagecontent .= "<br>". get_string('course', 'format_iena') . " :  <a href='" . $CFG->wwwroot .
+            "/course/view.php?id=" . $course->id . "'>" . $course->fullname . "</a>";
+        $messagecontent .= "<br> ". get_string('prof', 'format_iena') . " : " .
+            $USER->firstname . " " . $USER->lastname;
+        $brutmessagecontent = $course->fullname . " " . $_POST['summary']['text'];
+        $coursectx = context_course::instance($courseid);
+        $students = get_enrolled_users($coursectx);
+
+        // Sending a notification to each students.
+        foreach ($usersid as $userid) {
+            foreach ($students as $student) {
+                if ($student->id == $userid) {
+                    $message = new \core\message\message();
+                    $message->courseid = $course->id;
+                    $message->component = 'moodle';
+                    $message->name = 'instantmessage';
+                    $message->userfrom = $USER;
+                    $message->notification = '0';
+                    $message->fullmessageformat = FORMAT_HTML;
+                    $message->subject = "Rappel : " . $course->fullname;
+                    $message->smallmessage = $messagecontent;
+                    $message->fullmessage = $brutmessagecontent;
+                    $message->fullmessagehtml = $messagecontent;
+                    $message->userto = $student;
+                    $messageid = message_send($message);
+                    break;
+                }
+            }
+        }
+        $backurl .= "&msg_success=true";
+    } catch (Exception $e) {
+        $backurl .= "&msg_failure=true";
+    }
 
+    header("Location: {$backurl}");
+} else {
+    echo $OUTPUT->header();
+    $renderer = $PAGE->get_renderer('format_iena');
+    $renderer->display_message($data);
+    echo $OUTPUT->footer();
+}
diff --git a/settings.php b/settings.php
new file mode 100644
index 0000000000000000000000000000000000000000..0ce4ff8df770039088d5cf409df5afe9d7d24914
--- /dev/null
+++ b/settings.php
@@ -0,0 +1,31 @@
+<?php
+// This file is part of Moodle - https://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * Adds admin settings for the plugin.
+ *
+ * @package     format_iena
+ * @copyright   2018 Softia/Université lorraine
+ * @license     https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+if ($hassiteconfig) {
+    $settings->add(new admin_setting_confightmleditor('format_iena/msg_dist', get_string('message_dist', 'format_iena'),
+    get_string('message_dist_desc', 'format_iena'), get_string('message_default_dist', 'format_iena'), PARAM_RAW));
+    $settings->add(new admin_setting_confightmleditor('format_iena/msg_pres', get_string('message_pres', 'format_iena'),
+    get_string('message_pres_desc', 'format_iena'), get_string('message_default_pres', 'format_iena'), PARAM_RAW));
+}
\ No newline at end of file
diff --git a/suivi_unit.php b/suivi_unit.php
index ce8e60d461ad44fd11ddcb013988dd0a39dfcb09..698ff2f87855ace4ae6e7c2244a039709da00947 100644
--- a/suivi_unit.php
+++ b/suivi_unit.php
@@ -1,466 +1,365 @@
-<?php
-
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-
-/**
- *
- * @package    format_iena
- * @category   format
- * @copyright  2018 Softia/Université lorraine
- * @author     vrignaud camille / Thomas Fradet
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-define('NO_OUTPUT_BUFFERING', true);
-require_once('../../../config.php');
-require_once('view/view_param_indicateur.php');
-require_once('entity/course_format_iena_section_ressources.php');
-require_once('entity/course_format_iena_sections.php');
-require_once('entity/course_format_iena_groups.php');
-$PAGE->requires->css('/course/format/iena/styles.css');
-
-
-global $COURSE, $DB, $USER, $PAGE;
-
-function init_page($course){
-	global $PAGE;
-	// Defines the id of the course with a get parameter
-	
-	// Getting DB information (*)  of the course
-	
-	$PAGE->set_title($course->fullname);
-	$PAGE->set_heading($course->fullname . " – " .get_string('table_progress', 'format_iena'));
-
-	$PAGE->set_pagelayout('incourse');
-
-
-	/* Cache le menu dans le header ?  */
-	$coursenode = $PAGE->navbar->add(get_string('table_progress', 'format_iena'), null, navigation_node::TYPE_CONTAINER, null, 'suiviena');
-	$coursenode->make_active();
-	$coursenode->force_open();
-
-}
-
-function get_groups($context, $active_group_id, $progress, $groups){
-	global $USER, $COURSE;
-	/* Groupe du GET provenant du sélecteur de la page du cours, ou premier groupe de l'utilisateur, ou groupe 0 (tous les groupes). */
-	$groups_all=new StdClass();
-	// @TODO à supprimer si pas utilisé dans le JS (mettre dans la clause IF pour éviter un appel inutile si le GET existe)
-	$current_user_groups_ids = groups_get_user_groups($COURSE->id, $USER->id)[0];
-	$current_user_groups=[];
-	$other_groups=[];
-	/* Si pas de groupe dans le get ou groupe 0 (tous) mais pas le droit => premier groupe existant du user ou groupe 0 (tous) */
-	if ($active_group_id == NULL || ($active_group_id == 0 && !has_capability('course/iena:suivi_edit', $context, $USER->id)) ) {
-		
-		if ( count($current_user_groups_ids) == 0 ) {
-			$active_group_id = 0;
-		} else {
-			
-			
-			$active_group_id = $current_user_groups_ids[0];
-		}
-	}
-	/* Groupes du cours avec id, nom et liste des id utilisateur de tous les membres (3 clefs d'un tableau de groupes : id, name, member) */
-	
-
-	//$current_user_groups = [];
-	$active_group_name = "";
-	
-	foreach ($groups as $group) {
-		/* Récupération du nom du group actif au passage */
-		if ( $group->id == $active_group_id ) {
-			$active_group_name = $group->name;
-
-			$group->selected='selected';
-		}
-		/*
-		foreach ($current_user_groups_ids as $ugi) {
-			if ( $group->id == $ugi ) {
-				$current_user_groups[] = $group;
-			}
-			else{
-				$other_groups[]=$group;
-			}
-		}*/
-		if ( in_array($group->id, $current_user_groups_ids)){
-			$current_user_groups[] = $group;
-		}
-		else{
-			$other_groups[]=$group;
-		}
-}
-
-	//Réservé pour l'export ?
-	/*if ( $active_group_id == 0 ) {
-		foreach ($progress as $prog) {
-
-			
-			$prog->groups = "";
-			foreach ($groups as $group) {
-				if ( in_array($prog->id, $group->members) ) {
-					$prog->groups .= $group->name . " ";
-				}
-			}
-		}
-	}*/
-	$groups_all->groups=$other_groups;
-	$groups_all->current_user_groups=$current_user_groups;
-	return $groups_all;
-
-}
-
-//Formate l'achèvement d'activités pour le tableau de suivi. Pour chaque étudiant, on aura dans le bon ordre la liste des modules et le completionstate
-function format_progress($progress, $modules, $groups, $active_group_id, $active_section_id){
-	global $CFG, $COURSE;
-	$students=array();
-	foreach ($progress as $prog_info) {
-		$progress_student=new StdClass();
-		$progress_student->firstname=$prog_info->firstname;
-		$progress_student->lastname=$prog_info->lastname;
-		//$progress_student->name=$prog_info->firstname." ".$prog_info->lastname;
-		$progress_student->id=$prog_info->id;
-		$progress_student->email=$prog_info->email;
-		$progress_student->progress=array();
-		$progress_student->report_link=$CFG->wwwroot . "/report/outline/user.php?id=" . $progress_student->id . "&course=" . $COURSE->id . "&mode=outline";
-		$progress_student->message_link=$CFG->wwwroot . "/message/index.php?id=" . $progress_student->id;
-
-
-		if ( $active_group_id == 0 ) {	
-			$progress_student->groups = "";
-			foreach ($groups as $group) {
-				if ( in_array($progress_student->id, $group->members) ) {
-					$progress_student->groups .= $group->name . " ";
-				}
-			}
-		}
-
-
-		foreach($modules as $key=>$module){
-			
-			$module_progress=new StdClass();
-			
-			if(!isset($prog_info->progress[$module->id])){
-				
-				$module_progress->completionstate='0';
-			}
-			else{
-				$module_progress->completionstate=$prog_info->progress[$module->id]->completionstate;
-			}
-			/*if($module->section == $active_section_id || $active_section_id == 0){
-				$module_progress->visible=true;
-			}
-			else{
-				$module_progress->visible=false;
-			}*/
-			$module_progress->namemodule=$module->name;
-			$module_progress->idmodule=$module->id;
-			
-			$progress_student->progress[$key]=$module_progress;
-		}
-
-		$students[]=$progress_student;
-	}
-
-	return $students;
-	
-}
-
-
-function get_activities($completion, $active_section_id){
-	$activities = $completion->get_activities();
-	$modules = [];
-	foreach ($activities as $activity) {
-		$module = new StdClass();
-		$module->id = $activity->id;
-		$module->name = $activity->name;
-		$displayname = format_string($activity->name, true, array('context' => $activity->context));
-		$module->displayname = strlen($displayname) > 20 ? mb_substr($displayname, 0, 19, 'UTF-8').'…' : $displayname;
-		$module->section = $activity->section;
-		$modules[] = $module;
-		if($activity->section == $active_section_id || $active_section_id==0 ){
-			$module->visible=true;
-		}
-		else{
-			$module->visible=false;
-		}
-		
-	}
-	return $modules;
-}
-
-function get_sections($active_section_id){
-	global $COURSE;
-	// Liste des sections du cours
-	$modinfo = get_fast_modinfo($COURSE->id);
-	$sections_info_all = $modinfo->get_section_info_all();
-	$sections = [];
-
-	
-
-
-	foreach ($sections_info_all as $key => $section_info) {
-		$section = new StdClass();
-		$section->id = $section_info->id;
-		$section->name = $section_info->name === NULL || $section_info->name === '' ? 'Section ' . $key : $section_info->name;
-		if($section->id==$active_section_id){
-			$section->selected="selected";
-		}
-
-		$sections[] = $section;
-
-	}
-	return $sections;
-}
-
-
-
-
-function set_filters($data, $filters, $symbols, $sections, $groups, $current_user_groups, $active_group_name, $active_section_id){
-	
-	if (isset($_GET['filter'])) {
-		$filterComplete = $_GET['filter'];
-		$symbols[substr($filterComplete, 0, 1)]->selected="selected";
-		$filters[substr($filterComplete, 1)]->selected="selected";
-	} else {
-		$filters["0"]->selected="selected";
-		$symbols["≥"]->selected="selected";
-	}
-
-
-	$data['filters']=array_values($filters);
-	$data['symbols']=array_values($symbols);
-	$data["sections"]=$sections;
-	$data["groups"]=array_values($groups);
-	$data['current_user_groups']=$current_user_groups;
-	//$data['active_section_id']=$active_section_id;
-
-	if($active_group_name==""){
-		$data['default_group']='selected';	
-	}
-
-
-	$data['data']=array();
-	$data['data']["sections"]=$sections;
-	$data['data']["groups"]=array_values($groups);
-	$data['data']['current_user_groups']=$current_user_groups;
-	$data['data']['active_group_name']=$active_group_name;
-	$data['data']['active_section_id']=$active_section_id;
-
-	return $data;
-}
-
-function set_data($data, $modules, $progress, $groups, $active_group_id, $active_section_id){
-	
-	global $COURSE, $USER, $CFG;
-
-
-
-
-	$data["modules"]=$modules;
-	$count_modules=count($data["modules"]);
-
-	$data["students"]=format_progress($progress, $modules, $groups, $active_group_id, $active_section_id);
-	$count_students=count($data["students"]);
-
-	if($count_students>0 && $count_modules>0){
-		$data['count_results']=count($data["students"]);
-	}
-	
-
-	if (has_capability('course/iena:suivi_edit', $context = context_course::instance($COURSE->id), $USER->id)) {
-		$data['link_bulkcompletion']= $CFG->wwwroot . "/course/bulkcompletion.php?id=" . $COURSE->id;
-	}
-
-	$data['link_classicview']= $CFG->wwwroot . "/report/progress/index.php?course=" . $COURSE->id;
-
-
-	//Pour le téléchargement du tableau ?
-	if(!isset($data['data'])){
-		$data['data']=array();
-	}
-	
-
-	$data['data']=json_encode($data);
-	
-
-
-	return $data;
-
-
-}
-
-$filters=[
-	"0"=>(object)[
-		"value"=>"0",
-		"name"=>"0",
-	],
-	"25"=>(object)[
-		"value"=>"25",
-		"name"=>"25%",
-	],
-	"50"=>(object)[
-		"value"=>"50",
-		"name"=>"50%",
-	],
-	"75"=>(object)[
-		"value"=>"75",
-		"name"=>"75%",
-	],
-	"100"=>(object)[
-		"value"=>"100",
-		"name"=>"100%",
-	]
-	,
-	
-];
-
-$symbols=[
-	"="=>(object)[
-		"value"=>"=",
-		"name"=>"=",
-	],
-	"<"=>(object)[
-		"value"=>"<",
-		"name"=>"<",
-	],
-	">"=>(object)[
-		"value"=>">",
-		"name"=>">",
-	],
-	"≤"=>(object)[
-		"value"=>"≤",
-		"name"=>"≤",
-	],
-	"≥"=>(object)[
-		"value"=>"≥",
-		"name"=>"≥",
-	]
-];
-
-
-
-$courseID = required_param('courseid', PARAM_INT);
-// Define the url of the view
-$url = new moodle_url('/course/format/iena/suivi_unit.php', array('courseid' => $courseID));
-
-
-$PAGE->set_url($url);
-
-
-
-$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
-require_login($course);
-
-require_once($CFG->libdir . '/completionlib.php');
-$completion = new completion_info($course);
-$context = context_course::instance($COURSE->id);
-
-// if (!has_capability('moodle/course:sectionvisibility', $context = context_course::instance($courseID), $USER->id)) {
-if (!has_capability('course/iena:suivi', $context = context_course::instance($courseID), $USER->id)) {
-	$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-	header("Location: {$link}");
-	exit;
-}
-
-
-if(isset($_GET['groupid'])){
-	$active_group_id = $_GET['groupid'];
-}
-else{
-	$active_group_id=0;
-}
-
-$progress = $completion->get_progress_all(
-	'',
-	array(),
-	$active_group_id,
-	'u.lastname ASC, u.firstname ASC',
-	'',
-	'',
-	$context
-);
-
-
-$active_section_id=0;
-// Section du get acquise depuis le clic sur l'indicateur dans la page du cours, section depuis laquelle on a cliqué sur le bouton pour voir le suivi. 
-
-if(isset($_GET['sectionid'])){
-	$active_section_id = $_GET['sectionid'];
-}
-
-
-
-if ( $active_group_id == 0 ) {
-	//On récupère les ids des membres parce que dans l'excel on veut savoir qui appartient à quel groupe 
-	//$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
-	$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
-} else {
-	//On ne récupère pas les ids des membres
-	$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', false);
-}
-
-
-
-// If a post is sent trought the page
-/*if ($_POST && !isset($_POST["action"])) {
-	require_once("$CFG->libdir/formslib.php");
-	require_once('view/view_send_message.php');
-	$usersID = $_POST["api_url"];
-	$view = new view_send_message();
-	echo $view->get_content($usersID);
-} else */
-if(isset($_POST['action']) && !empty($_POST['action'])) {
-
-	//Si on change les filtres
-	$data=[];
-	$modules=get_activities($completion, $active_section_id);
-
-	$data=set_data($data, $modules, $progress, $groups, $active_group_id, $active_section_id);
-	echo json_encode($data);
-}
-else {
-
-	init_page($course, $PAGE);
-	echo $OUTPUT->header();
-	$current_user_groups=[];
-	$active_group_name="";
-	$data=[];
-
-	$modules=get_activities($completion, $active_section_id);
-	$groups_all=get_groups($context, $active_group_id, $progress, $groups);
-	
-	if(isset($groups_all->current_user_groups) && !empty($groups_all->current_user_groups)){
-		$current_user_groups=$groups_all->current_user_groups;
-	}
-	$groups=$groups_all->groups;
-	$sections=get_sections($active_section_id);
-	$data=set_filters($data, $filters, $symbols, $sections, $groups, $current_user_groups, $active_group_name, $active_section_id);
-
-	$data=set_data($data, $modules, $progress, $groups, $active_group_id, $active_section_id);
-	
-	if(isset($_GET["msg_success"])){
-		$msg=$_GET["msg_success"];
-		$data["msg_success"]=$msg;
-	}
-
-	$renderer = $PAGE->get_renderer('format_iena');
-	
-	$renderer->display_completion($data);
-	echo $OUTPUT->footer();
-}
-
-
-
-?>
\ No newline at end of file
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     vrignaud camille / Thomas Fradet
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+define('NO_OUTPUT_BUFFERING', true);
+require_once('../../../config.php');
+require_once('view/view_param_indicateur.php');
+require_once('entity/course_format_iena_section_ressources.php');
+require_once('entity/course_format_iena_sections.php');
+require_once('entity/course_format_iena_groups.php');
+$PAGE->requires->css('/course/format/iena/styles.css');
+
+global $COURSE, $DB, $USER, $PAGE;
+
+function init_page($course) {
+    global $PAGE;
+    // Defines the id of the course with a get parameter.
+    // Getting DB information (*)  of the course.
+
+    $PAGE->set_title($course->fullname);
+    $PAGE->set_heading($course->fullname . " – " .get_string('table_progress', 'format_iena'));
+    $PAGE->set_pagelayout('incourse');
+
+    // Cache le menu dans le header.
+    $coursenode = $PAGE->navbar->add(get_string('table_progress', 'format_iena'),
+        null, navigation_node::TYPE_CONTAINER, null, 'suiviena');
+    $coursenode->make_active();
+    $coursenode->force_open();
+}
+
+function get_groups($context, $activegroupid, $progress, $groups) {
+    global $USER, $COURSE;
+    // Groupe du GET provenant du sélecteur de la page du cours
+    // ou premier groupe de l'utilisateur, ou groupe 0 (tous les groupes).
+    $groupsall = new StdClass();
+    // TODO à supprimer si pas utilisé dans le JS (mettre dans la clause IF pour éviter un appel inutile si le GET existe).
+    $currentusergroupsids = groups_get_user_groups($COURSE->id, $USER->id)[0];
+    $currentusergroups = [];
+    $othergroups = [];
+    // Si pas de groupe dans le get ou groupe 0 (tous) mais pas le droit => premier groupe existant du user ou groupe 0 (tous).
+    if ($activegroupid == null || ($activegroupid == 0 &&
+        !has_capability('course/iena:suivi_edit', $context, $USER->id)) ) {
+        if ( count($currentusergroupsids) == 0 ) {
+            $activegroupid = 0;
+        } else {
+            $activegroupid = $currentusergroupsids[0];
+        }
+    }
+    // Groupes du cours avec id, nom et liste des id utilisateur de tous les
+    // membres (3 clefs d'un tableau de groupes : id, name, member).
+
+    $activegroupname = "";
+
+    foreach ($groups as $group) {
+        // Récupération du nom du group actif au passage.
+        if ( $group->id == $activegroupid ) {
+            $activegroupname = $group->name;
+            $group->selected = 'selected';
+        }
+        if (in_array($group->id, $currentusergroupsids)) {
+            $currentusergroups[] = $group;
+        } else {
+            $othergroups[] = $group;
+        }
+    }
+
+    $groupsall->groups = $othergroups;
+    $groupsall->current_user_groups = $currentusergroups;
+    return $groupsall;
+
+}
+
+// Formate l'achèvement d'activités pour le tableau de suivi. Pour chaque étudiant, on aura
+// dans le bon ordre la liste des modules et le completionstate.
+function format_progress($progress, $modules, $groups, $activegroupid, $activesectionid) {
+    global $CFG, $COURSE;
+    $students = array();
+    foreach ($progress as $proginfo) {
+        $progressstudent = new StdClass();
+        $progressstudent->firstname = $proginfo->firstname;
+        $progressstudent->lastname = $proginfo->lastname;
+        $progressstudent->id = $proginfo->id;
+        $progressstudent->email = $proginfo->email;
+        $progressstudent->progress = array();
+        $progressstudent->report_link = $CFG->wwwroot . "/report/outline/user.php?id=" .
+            $progressstudent->id . "&course=" . $COURSE->id . "&mode=outline";
+        $progressstudent->message_link = $CFG->wwwroot . "/message/index.php?id=" . $progressstudent->id;
+
+        if ($activegroupid == 0) {
+            $progressstudent->groups = "";
+            foreach ($groups as $group) {
+                if (in_array($progressstudent->id, $group->members)) {
+                    $progressstudent->groups .= $group->name . " ";
+                }
+            }
+        }
+
+        foreach ($modules as $key => $module) {
+            $moduleprogress = new StdClass();
+
+            if (!isset($proginfo->progress[$module->id])) {
+                $moduleprogress->completionstate = '0';
+            } else {
+                $moduleprogress->completionstate = $proginfo->progress[$module->id]->completionstate;
+            }
+            $moduleprogress->namemodule = $module->name;
+            $moduleprogress->idmodule = $module->id;
+
+            $progressstudent->progress[$key] = $moduleprogress;
+        }
+
+        $students[] = $progressstudent;
+    }
+
+    return $students;
+}
+
+function get_activities($completion, $activesectionid) {
+    $activities = $completion->get_activities();
+    $modules = [];
+    foreach ($activities as $activity) {
+        $module = new StdClass();
+        $module->id = $activity->id;
+        $module->name = $activity->name;
+        $displayname = format_string($activity->name, true, array('context' => $activity->context));
+        $module->displayname = strlen($displayname) > 20 ? mb_substr($displayname, 0, 19, 'UTF-8').'…' : $displayname;
+        $module->section = $activity->section;
+        $modules[] = $module;
+        if ($activity->section == $activesectionid || $activesectionid == 0 ) {
+            $module->visible = true;
+        } else {
+            $module->visible = false;
+        }
+    }
+    return $modules;
+}
+
+function get_sections($activesectionid) {
+    global $COURSE;
+    // Liste des sections du cours.
+    $modinfo = get_fast_modinfo($COURSE->id);
+    $sectionsinfoall = $modinfo->get_section_info_all();
+    $sections = [];
+
+    foreach ($sectionsinfoall as $key => $sectioninfo) {
+        $section = new StdClass();
+        $section->id = $sectioninfo->id;
+        $section->name = $sectioninfo->name === null || $sectioninfo->name === '' ? 'Section ' . $key : $sectioninfo->name;
+        if ($section->id == $activesectionid) {
+            $section->selected = "selected";
+        }
+
+        $sections[] = $section;
+    }
+    return $sections;
+}
+
+function set_filters($data, $filters, $symbols, $sections, $groups, $currentusergroups, $activegroupname, $activesectionid) {
+    if (isset($_GET['filter'])) {
+        $filtercomplete = $_GET['filter'];
+        $symbols[substr($filtercomplete, 0, 1)]->selected = "selected";
+        $filters[substr($filtercomplete, 1)]->selected = "selected";
+    } else {
+        $filters["0"]->selected = "selected";
+        $symbols["≥"]->selected = "selected";
+    }
+
+    $data['filters'] = array_values($filters);
+    $data['symbols'] = array_values($symbols);
+    $data["sections"] = $sections;
+    $data["groups"] = array_values($groups);
+    $data['current_user_groups'] = $currentusergroups;
+
+    if ($activegroupname == "") {
+        $data['default_group'] = 'selected';
+    }
+
+    $data['data'] = array();
+    $data['data']["sections"] = $sections;
+    $data['data']["groups"] = array_values($groups);
+    $data['data']['current_user_groups'] = $currentusergroups;
+    $data['data']['active_group_name'] = $activegroupname;
+    $data['data']['active_section_id'] = $activesectionid;
+
+    return $data;
+}
+
+function set_data($data, $modules, $progress, $groups, $activegroupid, $activesectionid) {
+    global $COURSE, $USER, $CFG;
+
+    $data["modules"] = $modules;
+    $countmodules = count($data["modules"]);
+
+    $data["students"] = format_progress($progress, $modules, $groups, $activegroupid, $activesectionid);
+    $countstudents = count($data["students"]);
+
+    if ($countstudents > 0 && $countmodules > 0) {
+        $data['count_results'] = count($data["students"]);
+    }
+
+    if (has_capability('course/iena:suivi_edit', $context = context_course::instance($COURSE->id), $USER->id)) {
+        $data['link_bulkcompletion'] = $CFG->wwwroot . "/course/bulkcompletion.php?id=" . $COURSE->id;
+    }
+
+    $data['link_classicview'] = $CFG->wwwroot . "/report/progress/index.php?course=" . $COURSE->id;
+
+    // Pour le téléchargement du tableau ?
+    if (!isset($data['data'])) {
+        $data['data'] = array();
+    }
+
+    $data['data'] = json_encode($data);
+    return $data;
+}
+
+$filters = [
+    "0" => (object)[
+        "value" => "0",
+        "name" => "0",
+    ],
+    "25" => (object)[
+        "value" => "25",
+        "name" => "25%",
+    ],
+    "50" => (object)[
+        "value" => "50",
+        "name" => "50%",
+    ],
+    "75" => (object)[
+        "value" => "75",
+        "name" => "75%",
+    ],
+    "100" => (object)[
+        "value" => "100",
+        "name" => "100%",
+    ]
+];
+
+$symbols = [
+    "=" => (object)[
+        "value" => "=",
+        "name" => "=",
+    ],
+    "<" => (object)[
+        "value" => "<",
+        "name" => "<",
+    ],
+    ">" => (object)[
+        "value" => ">",
+        "name" => ">",
+    ],
+    "≤" => (object)[
+        "value" => "≤",
+        "name" => "≤",
+    ],
+    "≥" => (object)[
+        "value" => "≥",
+        "name" => "≥",
+    ]
+];
+
+$courseid = required_param('courseid', PARAM_INT);
+// Define the url of the view.
+$url = new moodle_url('/course/format/iena/suivi_unit.php', array('courseid' => $courseid));
+$PAGE->set_url($url);
+
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+require_login($course);
+require_once($CFG->libdir . '/completionlib.php');
+
+$completion = new completion_info($course);
+$context = context_course::instance($COURSE->id);
+
+if (!has_capability('course/iena:suivi', $context = context_course::instance($courseid), $USER->id)) {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
+}
+
+if (isset($_GET['groupid'])) {
+    $activegroupid = $_GET['groupid'];
+} else {
+    $activegroupid = 0;
+}
+
+$progress = $completion->get_progress_all(
+    '',
+    array(),
+    $activegroupid,
+    'u.lastname ASC, u.firstname ASC',
+    '',
+    '',
+    $context
+);
+
+$activesectionid = 0;
+// Section du get acquise depuis le clic sur l'indicateur dans la page du cours,
+// section depuis laquelle on a cliqué sur le bouton pour voir le suivi.
+if (isset($_GET['sectionid'])) {
+    $activesectionid = $_GET['sectionid'];
+}
+
+if ($activegroupid == 0) {
+    // On récupère les ids des membres parce que dans l'excel on veut savoir qui appartient à quel groupe.
+    $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
+} else {
+    // On ne récupère pas les ids des membres.
+    $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', false);
+}
+
+// If a post is sent trought the page.
+if (isset($_POST['action']) && !empty($_POST['action'])) {
+    // Si on change les filtres.
+    $data = [];
+    $modules = get_activities($completion, $activesectionid);
+
+    $data = set_data($data, $modules, $progress, $groups, $activegroupid, $activesectionid);
+    echo json_encode($data);
+} else {
+    init_page($course, $PAGE);
+    echo $OUTPUT->header();
+    $currentusergroups = [];
+    $activegroupname = "";
+    $data = [];
+
+    $modules = get_activities($completion, $activesectionid);
+    $groupsall = get_groups($context, $activegroupid, $progress, $groups);
+
+    if (isset($groupsall->current_user_groups) && !empty($groupsall->current_user_groups)) {
+        $currentusergroups = $groupsall->current_user_groups;
+    }
+    $groups = $groupsall->groups;
+    $sections = get_sections($activesectionid);
+    $data = set_filters($data, $filters, $symbols, $sections, $groups, $currentusergroups, $activegroupname, $activesectionid);
+    $data = set_data($data, $modules, $progress, $groups, $activegroupid, $activesectionid);
+
+    if (isset($_GET["msg_success"])) {
+        $msg = $_GET["msg_success"];
+        $data["msg_success"] = $msg;
+    }
+
+    $renderer = $PAGE->get_renderer('format_iena');
+
+    $renderer->display_completion($data);
+    echo $OUTPUT->footer();
+}
diff --git a/suivi_unit_old.php b/suivi_unit_old.php
index b69a4491bdf0fc22d1df55d7ec052fa7c46ce6f9..40ce1f56d521678beede32cdbd9babe154031288 100644
--- a/suivi_unit_old.php
+++ b/suivi_unit_old.php
@@ -1,5 +1,4 @@
 <?php
-
 // This file is part of Moodle - http://moodle.org/
 //
 // Moodle is free software: you can redistribute it and/or modify
@@ -18,7 +17,6 @@
 /**
  *
  * @package    format_iena
- * @category   format
  * @copyright  2018 Softia/Université lorraine
  * @author     vrignaud camille / Thomas Fradet
  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -32,322 +30,265 @@ require_once('entity/course_format_iena_groups.php');
 
 global $COURSE, $DB, $USER;
 
+// Defines the id of the course with a get parameter.
+$courseid = required_param('courseid', PARAM_INT);
 
-
-// Defines the id of the course with a get parameter
-$courseID = required_param('courseid', PARAM_INT);
-// Define the url of the view
-$url = new moodle_url('/course/format/iena/suivi_unit.php', array('courseid' => $courseID));
-
+// Define the url of the view.
+$url = new moodle_url('/course/format/iena/suivi_unit.php', array('courseid' => $courseid));
 
 $PAGE->set_url($url);
 
-// Getting DB information (*)  of the course
-$course = $DB->get_record('course', array('id' => $courseID), '*', MUST_EXIST);
+// Getting DB information (*)  of the course.
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
 
-//require_login($course, false, NULL);
 require_login($course);
 $PAGE->set_title($course->fullname);
 $PAGE->set_heading($course->fullname . " – Suivi des étudiants");
 
 $PAGE->set_pagelayout('incourse');
 
-
-/* Cache le menu dans le header ?  */
+// Cache le menu dans le header.
 $coursenode = $PAGE->navbar->add('suiviiena', null, navigation_node::TYPE_CONTAINER, null, 'suiviena');
 $coursenode->make_active();
 $coursenode->force_open();
 
-
-
-
-
 require_once($CFG->libdir . '/completionlib.php');
 $completion = new completion_info($course);
 $context = context_course::instance($COURSE->id);
 
-// if (!has_capability('moodle/course:sectionvisibility', $context = context_course::instance($courseID), $USER->id)) {
-if (!has_capability('course/iena:suivi', $context = context_course::instance($courseID), $USER->id)) {
-	$link = $CFG->wwwroot . '/course/view.php?id=' . $courseID;
-	header("Location: {$link}");
-	exit;
+if (!has_capability('course/iena:suivi', $context = context_course::instance($courseid), $USER->id)) {
+    $link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
+    header("Location: {$link}");
+    exit;
 }
-//$PAGE->requires->js_call_amd('format_iena/suivi', 'init');
-
-
 
 echo $OUTPUT->header();
 
-/*$filters = [
-	"all" => "Tous",
-	"=100" => "100%",
-	"=0" => "0%",
-	"<100" => "&lt;100%",
-	"<50" => "&lt;50%",
-	"<25" => "&lt;25%",
-	">50" => "&gt;=50%",
-	">25" => "&gt;=25%",
-	">0" => "&gt;0%",
-];*/
-
-$filters=[
-	"0"=>array(
-		"value"=>"all",
-		"name"=>"Tous",
-	),
-	"1"=>array(
-		"value"=>"=100%",
-		"name"=>"100%",
-	),
-	"2"=>array(
-		"value"=>"=0",
-		"name"=>"0",
-	),
-	"3"=>array(
-		"value"=>"<100",
-		"name"=>"<100%",
-	),
-	"4"=>array(
-		"value"=>"<50",
-		"name"=>"<50%",
-	),
-	"5"=>array(
-		"value"=>"<25",
-		"name"=>"<25%",
-	),
-	"6"=>array(
-		"value"=>">50",
-		"name"=>">=50%",
-	),
-	"7"=>array(
-		"value"=>">25",
-		"name"=>">=25%",
-	),
-	"8"=>array(
-		"value"=>"0",
-		"name"=>">0%",
-	),
-];
-
 
+$filters = [
+    "0" => array(
+        "value" => "all",
+        "name" => "Tous",
+    ),
+    "1" => array(
+        "value" => "=100%",
+        "name" => "100%",
+    ),
+    "2" => array(
+        "value" => "=0",
+        "name" => "0",
+    ),
+    "3" => array(
+        "value" => "<100",
+        "name" => "<100%",
+    ),
+    "4" => array(
+        "value" => "<50",
+        "name" => "<50%",
+    ),
+    "5" => array(
+        "value" => "<25",
+        "name" => "<25%",
+    ),
+    "6" => array(
+        "value" => ">50",
+        "name" => ">=50%",
+    ),
+    "7" => array(
+        "value" => ">25",
+        "name" => ">=25%",
+    ),
+    "8" => array(
+        "value" => "0",
+        "name" => ">0%",
+    ),
+];
 
-/* Groupe du GET provenant du sélecteur de la page du cours, ou premier groupe de l'utilisateur, ou groupe 0 (tous les groupes). */
-if(isset($_GET['groupid'])){
-	$active_group_id = $_GET['groupid'];
-}
-else{
-	$active_group_id=NULL;
+// Groupe du GET provenant du sélecteur de la page du cours, ou premier groupe de l'utilisateur, ou groupe 0 (tous les groupes).
+if (isset($_GET['groupid'])) {
+    $activegroupid = $_GET['groupid'];
+} else {
+    $activegroupid = null;
 }
 
-// @TODO à supprimer si pas utilisé dans le JS (mettre dans la clause IF pour éviter un appel inutile si le GET existe)
-$current_user_groups_ids=array();
-/* Si pas de groupe dans le get ou groupe 0 (tous) mais pas le droit => premier groupe existant du user ou groupe 0 (tous) */
-if ($active_group_id == NULL || ($active_group_id == 0 && !has_capability('course/iena:suivi_edit', $context, $USER->id)) ) {
-	if ( count($current_user_groups_ids) == 0 ) {
-		$active_group_id = 0;
-	} else {
-		$current_user_groups_ids = groups_get_user_groups($COURSE->id, $USER->id)[0];
-		$active_group_id = $current_user_groups_ids[0];
-	}
+// TODO à supprimer si pas utilisé dans le JS (mettre dans la clause IF pour éviter un appel inutile si le GET existe).
+$currentusergroupsids = array();
+// Si pas de groupe dans le get ou groupe 0 (tous) mais pas le droit => premier groupe existant du user ou groupe 0 (tous).
+if ($activegroupid == null || ($activegroupid == 0 && !has_capability('course/iena:suivi_edit', $context, $USER->id)) ) {
+    if (count($currentusergroupsids) == 0) {
+        $activegroupid = 0;
+    } else {
+        $currentusergroupsids = groups_get_user_groups($COURSE->id, $USER->id)[0];
+        $activegroupid = $currentusergroupsids[0];
+    }
 }
 
-/* Groupes du cours avec id, nom et liste des id utilisateur de tous les membres (3 clefs d'un tableau de groupes : id, name, member) */
-if ( $active_group_id == 0 ) {
-	//On récupère les ids des membres
-	//$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
-	$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
+// Groupes du cours avec id, nom et liste des id utilisateur de tous les
+// membres (3 clefs d'un tableau de groupes : id, name, member).
+if ($activegroupid == 0) {
+    // On récupère les ids des membres.
+    $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
 } else {
-	//On ne récupère pas les ids des membres
-	$groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', false);
+    // On ne récupère pas les ids des membres.
+    $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', false);
 }
 
-$current_user_groups = [];
-$active_group_name = "";
+$currentusergroups = [];
+$activegroupname = "";
 foreach ($groups as $group) {
-	/* Récupération du nom du group actif au passage */
-	if ( $group->id == $active_group_id ) {
-		$active_group_name = $group->name;
-		$group->selected='selected';
-	}
-	foreach ($current_user_groups_ids as $ugi) {
-		if ( $group->id == $ugi ) {
-			$current_user_groups[] = $group;
-		}
-	}
+    // Récupération du nom du group actif au passage.
+    if ($group->id == $activegroupid) {
+        $activegroupname = $group->name;
+        $group->selected = 'selected';
+    }
+    foreach ($currentusergroupsids as $ugi) {
+        if ($group->id == $ugi) {
+            $currentusergroups[] = $group;
+        }
+    }
 }
 
 
-/* Liste de tous les utilisateurs avec : 
-- informations personnelles (tous les utilisateurs du cours)
-- liste des activités avec état d'achèvement (si achevées, sinon vide) */
+// Liste de tous les utilisateurs avec :
+// - informations personnelles (tous les utilisateurs du cours)
+// - liste des activités avec état d'achèvement (si achevées, sinon vide).
 $progress = $completion->get_progress_all(
-	'',
-	array(),
-	$active_group_id,
-	'u.lastname ASC, u.firstname ASC',
-	'',
-	'',
-	$context
+    '',
+    array(),
+    $activegroupid,
+    'u.lastname ASC, u.firstname ASC',
+    '',
+    '',
+    $context
 );
 
-//Formate l'achèvement d'activités pour le tableau de suivi. Pour chaque étudiant, on aura dans le bon ordre la liste des modules et le completionstate
-function format_progress($progress, $modules){
-	global $CFG, $COURSE;
-	$students=array();
-	foreach ($progress as $prog_info) {
-		$progress_student=new StdClass();
-		$progress_student->name=$prog_info->firstname." ".$prog_info->lastname;
-		$progress_student->id=$prog_info->id;
-		$progress_student->email=$prog_info->email;
-		$progress_student->progress=array();
-		$progress_student->report_link=$CFG->wwwroot . "/report/outline/user.php?id=" . $progress_student->id . "&course=" . $COURSE->id . "&mode=outline";
-		$progress_student->message_link=$CFG->wwwroot . "/message/index.php?id=" . $progress_student->id;
-		foreach($modules as $key=>$module){
-			
-			$module_progress=new StdClass();
-			
-			if(!isset($prog_info->progress[$module->id])){
-				
-				$module_progress->completionstate='0';
-			}
-			else{
-				$module_progress->completionstate=$prog_info->progress[$module->id]->completionstate;
-			}
-			$module_progress->namemodule=$module->name;
-			
-			$progress_student->progress[$key]=$module_progress;
-		}
-
-		$students[]=$progress_student;
-	}
-	return $students;
-	
+// Formate l'achèvement d'activités pour le tableau de suivi.
+// Pour chaque étudiant, on aura dans le bon ordre la liste des modules et le completionstate.
+function format_progress($progress, $modules) {
+    global $CFG, $COURSE;
+    $students = array();
+    foreach ($progress as $proginfo) {
+        $progressstudent = new StdClass();
+        $progressstudent->name = $proginfo->firstname." ".$proginfo->lastname;
+        $progressstudent->id = $proginfo->id;
+        $progressstudent->email = $proginfo->email;
+        $progressstudent->progress = array();
+        $progressstudent->report_link = $CFG->wwwroot . "/report/outline/user.php?id=" .
+            $progressstudent->id . "&course=" . $COURSE->id . "&mode=outline";
+        $progressstudent->message_link = $CFG->wwwroot . "/message/index.php?id=" . $progressstudent->id;
+        foreach ($modules as $key => $module) {
+            $moduleprogress = new StdClass();
+            if (!isset($proginfo->progress[$module->id])) {
+                $moduleprogress->completionstate = '0';
+            } else {
+                $moduleprogress->completionstate = $proginfo->progress[$module->id]->completionstate;
+            }
+            $moduleprogress->namemodule = $module->name;
+            $progressstudent->progress[$key] = $moduleprogress;
+        }
+        $students[] = $progressstudent;
+    }
+    return $students;
 }
 
-/* Ajoute les groupes de l'utilisateur pour l'afficher dans l'export */
-/* Si le user a le droit d'afficher pour tous les groupes ou qu'il n'y en a pas, on récupère le groupe de l'utilisateur pour qu'il puisse être téléchargé dans le tableau blobal intergroupe. */
-if ( $active_group_id == 0 ) {
-	foreach ($progress as $prog) {
-
-		
-		$prog->groups = "";
-		foreach ($groups as $group) {
-			if ( in_array($prog->id, $group->members) ) {
-				$prog->groups .= $group->name . " ";
-			}
-		}
-	}
+// Ajoute les groupes de l'utilisateur pour l'afficher dans l'export
+// Si le user a le droit d'afficher pour tous les groupes ou qu'il n'y en a pas,
+// on récupère le groupe de l'utilisateur pour qu'il puisse être téléchargé dans le tableau blobal intergroupe.
+if ($activegroupid == 0) {
+    foreach ($progress as $prog) {
+        $prog->groups = "";
+        foreach ($groups as $group) {
+            if (in_array($prog->id, $group->members)) {
+                $prog->groups .= $group->name . " ";
+            }
+        }
+    }
 }
 
-/* Liste de toutes les activités du cours (sauf en attente de suppression). La liste est épurée et constitue un tableau d'objet. */
+// Liste de toutes les activités du cours (sauf en attente de suppression). La liste est épurée et constitue un tableau d'objet.
 $activities = $completion->get_activities();
 $modules = [];
 foreach ($activities as $activity) {
-	$module = new StdClass();
-	$module->id = $activity->id;
-	$module->name = $activity->name;
-	$displayname = format_string($activity->name, true, array('context' => $activity->context));
-	$module->displayname = strlen($displayname) > 20 ? mb_substr($displayname, 0, 19, 'UTF-8').'…' : $displayname;
-	$module->section = $activity->section;
-	$modules[] = $module;
+    $module = new StdClass();
+    $module->id = $activity->id;
+    $module->name = $activity->name;
+    $displayname = format_string($activity->name, true, array('context' => $activity->context));
+    $module->displayname = strlen($displayname) > 20 ? mb_substr($displayname, 0, 19, 'UTF-8').'…' : $displayname;
+    $module->section = $activity->section;
+    $modules[] = $module;
 }
 
-// Liste des sections du cours
+// Liste des sections du cours.
 $modinfo = get_fast_modinfo($COURSE->id);
-$sections_info_all = $modinfo->get_section_info_all();
+$sectionsinfoall = $modinfo->get_section_info_all();
 $sections = [];
 
-// Section du get acquise depuis le clic sur l'indicateur dans la page du cours, section depuis laquelle on a cliqué sur le bouton pour voir le suivi. 
-
-if(isset($_GET['sectionid'])){
-	$active_section_id = $_GET['sectionid'];
-}
-else{
-	$active_section_id=0;
+// Section du get acquise depuis le clic sur l'indicateur dans la page du cours,
+// section depuis laquelle on a cliqué sur le bouton pour voir le suivi.
+if (isset($_GET['sectionid'])) {
+    $activesectionid = $_GET['sectionid'];
+} else {
+    $activesectionid = 0;
 }
 
+foreach ($sectionsinfoall as $key => $sectioninfo) {
+    $section = new StdClass();
+    $section->id = $sectioninfo->id;
+    $section->name = $sectioninfo->name === null || $sectioninfo->name === '' ? 'Section ' . $key : $sectioninfo->name;
+    if ($section->id == $activesectionid) {
+        $section->selected = "selected";
+    }
 
-foreach ($sections_info_all as $key => $section_info) {
-	$section = new StdClass();
-	$section->id = $section_info->id;
-	$section->name = $section_info->name === NULL || $section_info->name === '' ? 'Section ' . $key : $section_info->name;
-	if($section->id==$active_section_id){
-		$section->selected="selected";
-	}
-
-	$sections[] = $section;
-
+    $sections[] = $section;
 }
 
-
-
-// Filtre actif si il existe (si la page est rechargée pour un filtre de groupe p.ex.)
+// Filtre actif si il existe (si la page est rechargée pour un filtre de groupe p.ex.).
 if (isset($_GET['filter'])) {
-	$filter = $_GET['filter'];
+    $filter = $_GET['filter'];
 } else {
-	$filter = 'all';
+    $filter = 'all';
 }
 
+// On a récupéré toutes les données, on met ça dans un tableau pour le template.
+$data = array();
+$data['filters'] = $filters;
+$data["sections"] = $sections;
+$data["groups"] = array_values($groups);
+$data['current_user_groups'] = $currentusergroups;
 
-
-
-
-
-
-/*On a récupéré toutes les données, on met ça dans un tableau pour le template*/
-$data=array();
-$data['filters']=$filters;
-$data["sections"]=$sections;
-$data["groups"]=array_values($groups);
-$data['current_user_groups']=$current_user_groups;
-
-if($active_group_name==""){
-	$data['default_group']='selected';	
+if ($activegroupname == "") {
+    $data['default_group'] = 'selected';
 }
 
-$data["modules"]=$modules;
-
-
-$data["students"]=format_progress($progress, $modules);
+$data["modules"] = $modules;
+$data["students"] = format_progress($progress, $modules);
 
 if (has_capability('course/iena:suivi_edit', $context = context_course::instance($COURSE->id), $USER->id)) {
-	$data['link_bulkcompletion']= $CFG->wwwroot . "/course/bulkcompletion.php?id=" . $COURSE->id;
+    $data['link_bulkcompletion'] = $CFG->wwwroot . "/course/bulkcompletion.php?id=" . $COURSE->id;
 }
 
-$data['link_classicview']= $CFG->wwwroot . "/report/progress/index.php?course=" . $COURSE->id;
-
-
+$data['link_classicview'] = $CFG->wwwroot . "/report/progress/index.php?course=" . $COURSE->id;
 
+$data['data'] = array();
+$data['data']["sections"] = $sections;
+$data['data']["groups"] = array_values($groups);
+$data['data']['current_user_groups'] = $currentusergroups;
+$data['data']["modules"] = $modules;
+$data['data']["students"] = format_progress($progress, $modules);
+$data['data'] = json_encode($data['data']);
 
-$data['data']=array();
-$data['data']["sections"]=$sections;
-$data['data']["groups"]=array_values($groups);
-$data['data']['current_user_groups']=$current_user_groups;
-$data['data']["modules"]=$modules;
-$data['data']["students"]=format_progress($progress, $modules);
-$data['data']=json_encode($data['data']);
-
-
-
-// If a post is sent trought the page
+// If a post is sent trought the page.
 if ($_POST && !isset($_POST["action"])) {
-	require_once("$CFG->libdir/formslib.php");
-	require_once('view/view_send_message.php');
-	$usersID = $_POST["api_url"];
-	$view = new view_send_message();
-	echo $view->get_content($usersID);
-} else if(isset($_POST['action']) && !empty($_POST['action'])) {
-   return $data;
-}
-else {
-
-	//require_once('view/view_suivi_unit3.php');
-
-	$renderer = $PAGE->get_renderer('format_iena');
-	$renderer->display_completion($data);
+    require_once("$CFG->libdir/formslib.php");
+    require_once('view/view_send_message.php');
+    $usersid = $_POST["api_url"];
+    $view = new view_send_message();
+    echo $view->get_content($usersid);
+} else if (isset($_POST['action']) && !empty($_POST['action'])) {
+    return $data;
+} else {
+    $renderer = $PAGE->get_renderer('format_iena');
+    $renderer->display_completion($data);
 }
 
-
-
-
-echo $OUTPUT->footer();
\ No newline at end of file
+echo $OUTPUT->footer();
diff --git a/version.php b/version.php
index 747ee575bf217d1c2ac2ce9027aa26d2193b0e50..7f36504f48f5a541476a3da195fb5f3ab100f816 100644
--- a/version.php
+++ b/version.php
@@ -1,35 +1,33 @@
-<?php
-// This file is part of Moodle - http://moodle.org/
-//
-// Moodle is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Moodle is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
-	
-	/**
-	 * Version details
-	 *
-	 * The iena format plugin add new course format
-	 *
-	 * @package    format_iena
-	 * @category   format
-	 * @copyright  2018 Softia/Université lorraine
-	 * @author     Vrignaud Camille / Lebeau Michael / Thomas fradet
-	 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-	 */
-	
-	defined('MOODLE_INTERNAL') || die();
-	
-	$plugin->version = 2022000000;
-	$plugin->requires = 2014111000;
-	$plugin->component = 'format_iena';
-	$plugin->release = "1.0";
-	$plugin->maturity = MATURITY_STABLE;
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+/**
+ * Version details
+ *
+ * The iena format plugin add new course format
+ *
+ * @package    format_iena
+ * @copyright  2018 Softia/Université lorraine
+ * @author     Vrignaud Camille / Lebeau Michael / Thomas fradet
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+$plugin->version = 2022000000;
+$plugin->requires = 2014111000;
+$plugin->component = 'format_iena';
+$plugin->release = "1.0";
+$plugin->maturity = MATURITY_STABLE;
diff --git a/view/subview_param_indic.php b/view/subview_param_indic.php
index 5181d4d635dcf04eaf062048d8aa30feff9cf571..06bca82544fe9fe4a9a2d2ca1720c7cdb1d8c477 100644
--- a/view/subview_param_indic.php
+++ b/view/subview_param_indic.php
@@ -1,82 +1,82 @@
-<script type=\"text/javascript\" charset=\"utf8\" src=\"https://code.jquery.com/jquery-3.3.1.min.js\"></script>
-
-<script>
-    $(document).ready(function () {
-        $('.sectionH').hide();
-        $('.' + $('#select-section').val()).show();
-        $('#select-section').on('change', function () {
-            $('.sectionH').hide();
-            $('.' + this.value).show();
-        });
-    });
-</script>
-
-<form action="/course/format/iena/param_indicateur.php?courseid=<?= $COURSE->id; ?>" method="post">
-	<section class="section" id="params">
-		<div class="\">
-			<h2 class="param"><?php get_string('indic_suivi', 'format_iena') ?></h2>
-			<select class="select" name='select-section' id="select-section">
-				<?php
-					foreach ($sections as $section) {
-						$checked = "";
-						if ($section->id == $_GET['sectionid']) {
-							$checked = "selected";
-						}
-						$content .= "<option value=\"section-" . $section->id . "\" " . $checked . ">" . $section->name . "</option>";
-					}
-				?>
-			</select>
-		</div>
-		<div class="\">
-			<h2 class="param"><?php get_string('check_completion', 'format_iena') ?></h2>
-			<p><?php get_string('for_section_select', 'format_iena') ?></p>
-		</div>
-	</section>
-	<?php
-		foreach ($sections
-		
-		as $section) {
-		$hidden_modules = $this->get_ressource_hide_indicator_new($section->id);
-	?>
-	<section class="section-<?= $section->id ?> sectionH ">
-		<div class="iena-heading_title">
-			<p><?= $section->name ?></p>
-		</div>
-		<?php
-			
-			foreach ($hidden_modules
-			
-			as $hidden_mod) {
-		?>
-
-		<div class="iena-field">
-			<div class="control">
-				<label class="checkbox">
-					<input type="checkbox" name="<?= $hidden_mod->cmid ?> section- <?= $hidden_mod->sectionid ?>
-			<?php
-						if ($hidden_mod->hide == 1) {
-							echo "checked";
-						}
-					?>
-			
-			">
-							<?php
-						$moduleTools->get_ressource_by_id($hidden_mod->cmid);
-						echo $moduleTools->name ?>
-						</label>
-					</div>
-				</div>
-				<?php
-						} ?>
-			</section>
-			<?php
-						}
-						$link_annuler = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "&sectionid=" . $_GET['sectionid'];
-					?>
-	<section>
-		<a id="button" href='<?= $link_annuler?>' class="btn btn_reset big_button" style="font-weight:bold">
-					<i><?= get_string('cancel', 'format_iena')?> </i></a>
-					<button id="button" class="btn btn_blue big_button" style="font-weight:bold;" type="submit"><?= get_string('save', 'format_iena')?> "</i>
-					</button>
-	</section>
+<script type=\"text/javascript\" charset=\"utf8\" src=\"https://code.jquery.com/jquery-3.3.1.min.js\"></script>
+
+<script>
+    $(document).ready(function () {
+        $('.sectionH').hide();
+        $('.' + $('#select-section').val()).show();
+        $('#select-section').on('change', function () {
+            $('.sectionH').hide();
+            $('.' + this.value).show();
+        });
+    });
+</script>
+
+<form action="/course/format/iena/param_indicateur.php?courseid=<?= $COURSE->id; ?>" method="post">
+    <section class="section" id="params">
+        <div class="\">
+            <h2 class="param"><?php get_string('indic_suivi', 'format_iena') ?></h2>
+            <select class="select" name='select-section' id="select-section">
+                <?php
+                    foreach ($sections as $section) {
+                        $checked = "";
+                        if ($section->id == $_GET['sectionid']) {
+                            $checked = "selected";
+                        }
+                        $content .= "<option value=\"section-" . $section->id . "\" " . $checked . ">" . $section->name . "</option>";
+                    }
+                ?>
+            </select>
+        </div>
+        <div class="\">
+            <h2 class="param"><?php get_string('check_completion', 'format_iena') ?></h2>
+            <p><?php get_string('for_section_select', 'format_iena') ?></p>
+        </div>
+    </section>
+    <?php
+        foreach ($sections
+        
+        as $section) {
+        $hidden_modules = $this->get_ressource_hide_indicator_new($section->id);
+    ?>
+    <section class="section-<?= $section->id ?> sectionH ">
+        <div class="iena-heading_title">
+            <p><?= $section->name ?></p>
+        </div>
+        <?php
+            
+            foreach ($hidden_modules
+            
+            as $hidden_mod) {
+        ?>
+
+        <div class="iena-field">
+            <div class="control">
+                <label class="checkbox">
+                    <input type="checkbox" name="<?= $hidden_mod->cmid ?> section- <?= $hidden_mod->sectionid ?>
+            <?php
+                        if ($hidden_mod->hide == 1) {
+                            echo "checked";
+                        }
+                    ?>
+            
+            ">
+                            <?php
+                        $moduleTools->get_ressource_by_id($hidden_mod->cmid);
+                        echo $moduleTools->name ?>
+                        </label>
+                    </div>
+                </div>
+                <?php
+                        } ?>
+            </section>
+            <?php
+                        }
+                        $link_annuler = $CFG->wwwroot . "/course/format/iena/suivi_unit.php?courseid=" . $COURSE->id . "&sectionid=" . $_GET['sectionid'];
+                    ?>
+    <section>
+        <a id="button" href='<?= $link_annuler?>' class="btn btn_reset big_button" style="font-weight:bold">
+                    <i><?= get_string('cancel', 'format_iena')?> </i></a>
+                    <button id="button" class="btn btn_blue big_button" style="font-weight:bold;" type="submit"><?= get_string('save', 'format_iena')?> "</i>
+                    </button>
+    </section>
 </form>
\ No newline at end of file