diff --git a/block_competency_iena.php b/block_competency_iena.php
index ffbc8145d905dda93366c989c518a0d09b285e03..c6ab020c9b20d5ed357f901abadd119d9e66de15 100644
--- a/block_competency_iena.php
+++ b/block_competency_iena.php
@@ -1,98 +1,99 @@
 <?php
 
-require_once('entity/block_competency_iena_competency.php');
+defined('MOODLE_INTERNAL') || die();
 
-class block_competency_iena extends block_base
-{
-	public function init()
-	{
-		$this->title = get_string('title_plugin', 'block_competency_iena');
-	}
+class block_competency_iena extends block_base{
+    public function init()
+    {
+        $this->title = get_string('title_plugin', 'block_competency_iena');
+    }
 
-	function instance_allow_multiple()
-	{
-		return false;
-	}
+    function instance_allow_multiple()
+    {
+        return false;
+    }
 
-	/**
-		 * Set the applicable formats for this block to all
-		 * @return array
-		 */
-	function applicable_formats()
-	{
-		return array('course' => true);
-	}
-	
-		/**
-		 * Allow the user to configure a block instance
-		 * @return bool Returns true
-		 */
-		function instance_allow_config()
-		{
-			return true;
-		}
-		
-		function has_config()
-		{
-			return true;
-		}
-		
-		public function get_content()
-		{
-			global $CFG;
-			global $COURSE;
-			global $USER;
-			
-			if ($this->content !== null) {
-				return $this->content;
-			}
-			if (empty($this->config)) {
-				$this->config = new stdClass();
-			}
-			
-			$this->content = new stdClass;
-			$this->content->text = "";
-			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
-				$this->content->text .= '<h4>Tableaux de bord</h4>';
-				$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Par étudiant</a>';
-				$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_students_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100" style="white-space: normal;">Par compétence</a>';
-				// marche plus
-				// $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Acquisition des compétences</a>';
-				$this->content->text .= '<hr>';
-				$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Gérer les compétences</a>';
-				$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Informations sur l\'APC</a>';
-			} else {
-				$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Mes compétences</a>';
-			}
+    /**
+         * Set the applicable formats for this block to all
+         * @return array
+         */
+    function applicable_formats()
+    {
+        return array('course' => true);
+    }
+    
+        /**
+         * Allow the user to configure a block instance
+         * @return bool Returns true
+         */
+        function instance_allow_config()
+        {
+            return true;
+        }
+        
+        function has_config()
+        {
+            return true;
+        }
+        
+        public function get_content()
+        {
+            global $CFG;
+            global $COURSE;
+            global $USER;
+            
+            if ($this->content !== null) {
+                return $this->content;
+            }
+            if (empty($this->config)) {
+                $this->config = new stdClass();
+            }
+            
+            $this->content = new stdClass;
+            $this->content->text = "";
+            if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
+                $this->content->text .= '<h4>Tableaux de bord</h4>';
+                $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Par étudiant</a>';
+                $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_students_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100" style="white-space: normal;">Par compétence</a>';
+                // marche plus
+                // $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Acquisition des compétences</a>';
+                $this->content->text .= '<hr>';
+                $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Gérer les compétences</a>';
+                $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Informations sur l\'APC</a>';
+            } else {
+                $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3" style="white-space: normal;">Mes compétences</a>';
+            }
 
-			// $competenceI = new block_competency_iena_competency();
-			// $competences = $competenceI->get_competencies_by_userID($USER->id);
-			// $nb_ok = 0;
-			// $nb_total = count($competences);
-			// foreach ($competences as $comp) {
-			// 	if ($comp->proficiency == 1) {
-			// 		$nb_ok++;
-			// 	}
-			// }
-			// // $this->content->text .= "<p></p>";
-			// if ($nb_total > 0) {
-			// 	$progress_percentage = ceil($nb_ok*100/$nb_total);
-			// 	$this->content->text .= "
-			// 	<div class=\"progress\">
-			// 	<div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\">$nb_ok/$nb_total</div>
-			// 	</div>
-			// 	";
-			// } else {
-			// 	$progress_percentage = 0;
-			// 	$this->content->text .= "
-			// 	<div class=\"progress\">
-			// 	<div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\"></div>
-			// 	</div>
-			// 	";
-			// }
-			
-			return $this->content;
-		}
-	}
+            // $competenceI = new block_competency_iena_competency();
+            // $competences = $competenceI->get_competencies_by_userID($USER->id);
+            // $nb_ok = 0;
+            // $nb_total = count($competences);
+            // foreach ($competences as $comp) {
+            //  if ($comp->proficiency == 1) {
+            //      $nb_ok++;
+            //  }
+            // }
+            // // $this->content->text .= "<p></p>";
+            // if ($nb_total > 0) {
+            //  $progress_percentage = ceil($nb_ok*100/$nb_total);
+            //  $this->content->text .= "
+            //  <div class=\"progress\">
+            //  <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\">$nb_ok/$nb_total</div>
+            //  </div>
+            //  ";
+            // } else {
+            //  $progress_percentage = 0;
+            //  $this->content->text .= "
+            //  <div class=\"progress\">
+            //  <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\"></div>
+            //  </div>
+            //  ";
+            // }
+            
+            return $this->content;
+        }
 
-	?>
\ No newline at end of file
+        
+
+}
+?>
\ No newline at end of file
diff --git a/classes/observer.php b/classes/observer.php
new file mode 100644
index 0000000000000000000000000000000000000000..359dc7046be468c28275382c0cc680cbb2e73a4c
--- /dev/null
+++ b/classes/observer.php
@@ -0,0 +1,21 @@
+<?php
+defined('MOODLE_INTERNAL') || die();
+//require_once($CFG->dirroot.'/blocks/competency_iena/block_competency_iena.php');
+require_once($CFG->dirroot.'/blocks/competency_iena/lib.php');
+
+class block_competency_iena_observer {
+    /**
+     * Observer that monitors course module suppressed event and update the linked matrix competencies .
+     *
+     * @param \core\event\course_module_deleted $event the event object.
+     */
+    public static function course_module_deleted(\core\event\course_module_deleted $event) {
+        $cmid = $event->contextinstanceid;
+        delete_matrix_competencies($cmid);
+    }
+
+    public static function course_module_created(\core\event\course_module_created $event) {
+        $cmid = $event->contextinstanceid;
+        duplicate_matrix_competencies($cmid, );
+    }
+}
diff --git a/competency_iena_competencies_2.php b/competency_iena_competencies_2.php
index 1695256e8144b50a9c230ea38a1a6d694284d08c..a007833d392062fe80cff27249312090ee103b33 100644
--- a/competency_iena_competencies_2.php
+++ b/competency_iena_competencies_2.php
@@ -3,6 +3,8 @@
 require_once('../../config.php');
 
 require_once('entity/block_competency_iena_student.php');
+require_once('../../user/lib.php');
+require_once('lib.php');
 
 global $COURSE, $DB, $USER, $CFG;
 
@@ -15,58 +17,72 @@ $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
 require_login($course, false, NULL);
 $PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
 
+
 $is_student = false; 
 if (!has_capability('moodle/course:update', $context = context_course::instance($course->id), $USER->id)) {
-	$is_student = true;
-	if ( $studentid != $USER->id ) {
-		//Si on est un étudiant on ne peux consulter que son propre dashboard ?
-		$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $courseid . '&studentid=' . $USER->id;
-		header("Location: {$link}");
-		exit;
-	}
+    $is_student = true;
+    if ( $studentid != $USER->id ) {
+        //Si on est un étudiant on ne peux consulter que son propre dashboard ?
+        $link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $courseid . '&studentid=' . $USER->id;
+        header("Location: {$link}");
+        exit;
+    }
 }
 
-
+//fetch the linked activities for a competency/student and create a link to the corresponding page when possible
+if(isset($_GET["action"]) && $_GET['action']=="get_links"){
+    $competencyid=$_GET["competencyid"];
+    $courseid=$_GET["courseid"];
+    if(isset($_GET["studentid"])){
+         $studentid=$_GET["studentid"];
+    }
+    else{
+        $studentid=$USER->id;
+    }
+
+    echo(fetch_linked_activities($competencyid, $courseid, $studentid));
+    return;
+}
 //Si on a fait une évaluation 
 if(isset($_POST) && !empty($_POST)){
-	$courseid = required_param('courseid', PARAM_INT);
-	$studentid = required_param('studentid', PARAM_INT);
-	$competencyid = required_param('competencyid', PARAM_INT);
+    $courseid = required_param('courseid', PARAM_INT);
+    $studentid = required_param('studentid', PARAM_INT);
+    $competencyid = required_param('competencyid', PARAM_INT);
 
 
-	$sql_rev = "SELECT * FROM {competency_usercomp} WHERE userid = ? AND competencyid = ? AND status = ?";
-	$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
-	$review_asked = count($reviews_data) > 0 ? true : false;
+    $sql_rev = "SELECT * FROM {competency_usercomp} WHERE userid = ? AND competencyid = ? AND status = ?";
+    $reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
+    $review_asked = count($reviews_data) > 0 ? true : false;
 
 
-	/* <<< POST >>> */
+    /* <<< POST >>> */
 
-	/* POST EVALUATION */
+    /* POST EVALUATION */
 
-	if ( isset($_POST['grade']) ) {
-		$note = $_POST['note'];
-		\core_competency\api::grade_competency_in_course($courseid, $studentid, $competencyid, $_POST['grade'], $note);
-		if ( $review_asked ) {
-			\core_competency\api::user_competency_start_review($studentid, $competencyid);
-			\core_competency\api::user_competency_stop_review($studentid, $competencyid);
-			/* Refresh review data */
-			$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
-			$review_asked = count($reviews_data) > 0 ? true : false;
-		}
-	}
+    if ( isset($_POST['grade']) ) {
+        $note = $_POST['note'];
+        \core_competency\api::grade_competency_in_course($courseid, $studentid, $competencyid, $_POST['grade'], $note);
+        if ( $review_asked ) {
+            \core_competency\api::user_competency_start_review($studentid, $competencyid);
+            \core_competency\api::user_competency_stop_review($studentid, $competencyid);
+            /* Refresh review data */
+            $reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
+            $review_asked = count($reviews_data) > 0 ? true : false;
+        }
+    }
 
-	/* POST REVIEW */
+    /* POST REVIEW */
 
-	if ( isset($_POST['review']) ) {
-		if ( $_POST['review'] == 'request' ) {
-			\core_competency\api::user_competency_request_review($studentid, $competencyid);
-		} elseif ( $_POST['review'] == 'cancel' ) {
-			\core_competency\api::user_competency_cancel_review_request($studentid, $competencyid);
-		}
-		/* Refresh review data */
-		$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
-		$review_asked = count($reviews_data) > 0 ? true : false;
-	}
+    if ( isset($_POST['review']) ) {
+        if ( $_POST['review'] == 'request' ) {
+            \core_competency\api::user_competency_request_review($studentid, $competencyid);
+        } elseif ( $_POST['review'] == 'cancel' ) {
+            \core_competency\api::user_competency_cancel_review_request($studentid, $competencyid);
+        }
+        /* Refresh review data */
+        $reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
+        $review_asked = count($reviews_data) > 0 ? true : false;
+    }
 
 }
 
@@ -101,21 +117,21 @@ $PAGE->requires->css("/blocks/competency_iena/styles.css");
 echo $OUTPUT->header();
 
 $sql = "SELECT * FROM {competency_usercomp} 
-	WHERE userid = ? AND status = ?";
-	$params_rev = array();
-	$params_rev[] = $student->studentid;
-	$params_rev[] = 1;
-	$reviews_data = $DB->get_records_sql($sql, $params_rev);
-	$reviews_count = count($reviews_data);
-
-	/* <<< DASHBORD >>> */
-
-	$count_proficients = 0;
-	foreach ($user_course_competencies as $u_c_cpt) {
-		if ( $u_c_cpt->get('proficiency') == 1 ) {
-			$count_proficients++;
-		}
-	}
+    WHERE userid = ? AND status = ?";
+    $params_rev = array();
+    $params_rev[] = $student->studentid;
+    $params_rev[] = 1;
+    $reviews_data = $DB->get_records_sql($sql, $params_rev);
+    $reviews_count = count($reviews_data);
+
+    /* <<< DASHBORD >>> */
+
+    $count_proficients = 0;
+    foreach ($user_course_competencies as $u_c_cpt) {
+        if ( $u_c_cpt->get('proficiency') == 1 ) {
+            $count_proficients++;
+        }
+    }
 
 $chart = new \core\chart_pie();
 $proficiency_serie = new core\chart_series(get_string('competencies', 'core_competency'), [$count_proficients, $count_course_cpts - $count_proficients]);
@@ -131,52 +147,52 @@ $array_frameworks=array();
 
 
 foreach ($user_course_competencies as $user_course_competency) {
-	
-	// Crée un obj cpt à partir de l'ID. Attention, id de compétence et course_competency sont différents. 
-	$cpt = new \core_competency\competency($user_course_competency->get('competencyid'));
-	/* Visuel indentation to reflect levels in cpt framework */
-	$cpt_level_in_framework = substr_count($cpt->get('path'), '/') - 1; /* start at 1 */
-
-	$user_course_competency->level_indentation = $cpt_level_in_framework * 1.5;
-	$user_course_competency->cpt_level_in_framework=$cpt_level_in_framework;
-	$framework_id=$cpt->get('competencyframeworkid');
-	if(!in_array($framework_id,array_keys($array_frameworks))){
-		$framework = new \core_competency\competency_framework($cpt->get('competencyframeworkid'));
-		$array_frameworks[$framework_id]=array();
-		$array_frameworks[$framework_id]['taxonomy']=$framework->get('taxonomies');
-	}
-	$user_course_competency->taxonomy=get_string("taxonomy_".$array_frameworks[$framework_id]["taxonomy"][$cpt_level_in_framework], 'core_competency');
-
-	// Récupère les chaines de caractère de l'échelle d'évaluation
-	$cpt_scale = $cpt->get_scale()->scale_items;
-	$user_course_competency->eval = "-";
-	if ( $user_course_competency->get('grade') != null ) {
-		$user_course_competency->eval = $cpt_scale[$user_course_competency->get('grade') - 1];
-	}
-	$user_course_competency->id=$user_course_competency->get('competencyid');
-	
-	$user_course_competency->scale=array();
-	for($i=0; $i<count($cpt_scale); $i++){
-		$user_course_competency->scale[$i]=array('title'=>$cpt_scale[$i], 'value'=>$i+1);
-		if($cpt_scale[$i]==$user_course_competency->eval){
-			$user_course_competency->scale[$i]['selected']='selected';
-		}
-		
-	}
-
-	$user_course_competency->proficient_class = $user_course_competency->get('proficiency') == 1 ? " list-group-item-success" : "";
-	$user_course_competency->proficient_str = $user_course_competency->get('proficiency') == 1 ? "Oui" : "Non";
-	$user_course_competency->shortname=$cpt->get('shortname');
-	$user_course_competency->link=$CFG->wwwroot."/blocks/competency_iena/course_competency.php?courseid=".$COURSE->id."&studentid=".$student->studentid."&competencyid=".$cpt->get('id')."&from=students";
-	foreach ($reviews_data as $review) {
-		if ( $review->competencyid == $cpt->get('id') ) {
-			$user_course_competency->review_asked=true;
-			break;
-		}
-	}
-	
-	//$user_course_competency->reviews_data=array_values($reviews_data);
-	
+    
+    // Crée un obj cpt à partir de l'ID. Attention, id de compétence et course_competency sont différents. 
+    $cpt = new \core_competency\competency($user_course_competency->get('competencyid'));
+    /* Visuel indentation to reflect levels in cpt framework */
+    $cpt_level_in_framework = substr_count($cpt->get('path'), '/') - 1; /* start at 1 */
+
+    $user_course_competency->level_indentation = $cpt_level_in_framework * 1.5;
+    $user_course_competency->cpt_level_in_framework=$cpt_level_in_framework;
+    $framework_id=$cpt->get('competencyframeworkid');
+    if(!in_array($framework_id,array_keys($array_frameworks))){
+        $framework = new \core_competency\competency_framework($cpt->get('competencyframeworkid'));
+        $array_frameworks[$framework_id]=array();
+        $array_frameworks[$framework_id]['taxonomy']=$framework->get('taxonomies');
+    }
+    $user_course_competency->taxonomy=get_string("taxonomy_".$array_frameworks[$framework_id]["taxonomy"][$cpt_level_in_framework], 'core_competency');
+
+    // Récupère les chaines de caractère de l'échelle d'évaluation
+    $cpt_scale = $cpt->get_scale()->scale_items;
+    $user_course_competency->eval = "-";
+    if ( $user_course_competency->get('grade') != null ) {
+        $user_course_competency->eval = $cpt_scale[$user_course_competency->get('grade') - 1];
+    }
+    $user_course_competency->id=$user_course_competency->get('competencyid');
+    
+    $user_course_competency->scale=array();
+    for($i=0; $i<count($cpt_scale); $i++){
+        $user_course_competency->scale[$i]=array('title'=>$cpt_scale[$i], 'value'=>$i+1);
+        if($cpt_scale[$i]==$user_course_competency->eval){
+            $user_course_competency->scale[$i]['selected']='selected';
+        }
+        
+    }
+
+    $user_course_competency->proficient_class = $user_course_competency->get('proficiency') == 1 ? " list-group-item-success" : "";
+    $user_course_competency->proficient_str = $user_course_competency->get('proficiency') == 1 ? "Oui" : "Non";
+    $user_course_competency->shortname=$cpt->get('shortname');
+    $user_course_competency->link=$CFG->wwwroot."/blocks/competency_iena/course_competency.php?courseid=".$COURSE->id."&studentid=".$student->studentid."&competencyid=".$cpt->get('id')."&from=students";
+    foreach ($reviews_data as $review) {
+        if ( $review->competencyid == $cpt->get('id') ) {
+            $user_course_competency->review_asked=true;
+            break;
+        }
+    }
+    
+    //$user_course_competency->reviews_data=array_values($reviews_data);
+    
 }
 
 $data=array();
@@ -197,8 +213,8 @@ $data['link_dashboard']=$CFG->wwwroot."/blocks/competency_iena/competency_iena_c
 $renderer = $PAGE->get_renderer('block_competency_iena');
 
 $renderer->get_dashboard_students($data);
-	
-	
+    
+    
 echo $OUTPUT->footer();
 
 ?>
\ No newline at end of file
diff --git a/competency_iena_competencies_mgmt.php b/competency_iena_competencies_mgmt.php
index 9364b868d04fd89a25f1cc9f61887b85344ebc52..35952c2100fdb49b6f086aed2917c4583cd9de7a 100644
--- a/competency_iena_competencies_mgmt.php
+++ b/competency_iena_competencies_mgmt.php
@@ -194,8 +194,7 @@
 		$matrix_modules=$module_instance->get_matrix_modules_by_id_section($section->id);
 		
 		foreach ($modules as $key => $module) {
-
-			if($module->section == $section->id && $module->completion!=0){
+			if($module->section == $section->id && $module->completion!=0 && $module->deletioninprogress==0){
 				
 				$completion_activity=true;
 				if(in_array($key, array_column($matrix_modules, 'cmid'))){
diff --git a/competency_iena_competency_students_2.php b/competency_iena_competency_students_2.php
index 3536d7f1bbdcf596b5facde3ac596cc67c82d1fb..79504a3acbe68c458ddd974e4c932d5d6811b2ea 100644
--- a/competency_iena_competency_students_2.php
+++ b/competency_iena_competency_students_2.php
@@ -8,6 +8,7 @@ require_once('../../config.php');
 // require_once('entity/block_competency_iena_ressource.php');
 // require_once('entity/block_competency_iena_section.php');
 require_once('entity/block_competency_iena_student.php');
+require_once('lib.php');
 
 
 global $COURSE, $DB, $CFG;
@@ -39,6 +40,20 @@ $thingnode->make_active();
 /* Liste des compétences du cours */
 $course_cpts = \core_competency\course_competency::list_competencies($COURSE->id);
 
+if(isset($_GET["action"]) && $_GET['action']=="get_links"){
+    $competencyid=$_GET["competencyid"];
+    $courseid=$_GET["courseid"];
+    if(isset($_GET["studentid"])){
+         $studentid=$_GET["studentid"];
+    }
+    else{
+        $studentid=$USER->id;
+    }
+
+    echo(fetch_linked_activities($competencyid, $courseid, $studentid));
+    return;
+}
+
 if(isset($_POST) && !empty($_POST)){
 
 	$studentid = required_param('studentid', PARAM_INT);
@@ -258,6 +273,7 @@ if (count($course_cpts) > 0) {
 		$course_cpts_all = $DB->get_records_sql($sql, $params);
 
 		$cpt_studs = array();
+		
 		foreach ($students as $student) {
 
 			$cpt_stud = new stdClass();
@@ -271,6 +287,7 @@ if (count($course_cpts) > 0) {
 				if ( $course_cpt->userid == $student->id ) {
 					$cpt_stud->proficiency = $course_cpt->proficiency;
 					$cpt_stud->grade = $course_cpt->grade;
+					//Sortir la scale de la boucle; Ce serait bien qu'on garde juste l
 					$cpt_stud->scale=array();
 					//pour chaque valeur de l'échelle, on ajoute dans un tableau pour l'étudiant avec selected
 
@@ -290,6 +307,13 @@ if (count($course_cpts) > 0) {
 					}
 					break;
 				}
+				else{
+					$cpt_stud->scale=array();
+					for($i=0; $i<count($current_cpt->scale); $i++){
+						$cpt_stud->scale[$i]=array('title'=>$current_cpt->scale[$i], 'value'=>$i+1);
+						
+					}
+				}
 				
 			}
 			
@@ -351,7 +375,7 @@ if (count($course_cpts) > 0) {
 			}
 
 			$data["cpt_studs"]=array_values($cpt_studs);
-			//var_dump($cpt_studs);
+			
 		}
 		else{
 
@@ -384,7 +408,6 @@ if (count($course_cpts) > 0) {
 	$data['link_dashboard']=$CFG->wwwroot."/blocks/competency_iena/competency_iena_students_2.php";
 	$data['message']=$message;
 
-
 	
 	$renderer = $PAGE->get_renderer('block_competency_iena');
 
diff --git a/db/events.php b/db/events.php
new file mode 100644
index 0000000000000000000000000000000000000000..434eba2bc204074b11f3750f165edffa4fbfe469
--- /dev/null
+++ b/db/events.php
@@ -0,0 +1,15 @@
+<?php
+defined('MOODLE_INTERNAL') || die();
+
+$observers = array(
+    array(
+        'eventname'   => '\core\event\course_module_deleted',
+        'callback'    => 'block_competency_iena_observer::course_module_deleted',
+    ),
+    array(
+        'eventname'   => '\core\event\course_module_created',
+        'callback'    => 'block_competency_iena_observer::course_module_created',
+    )
+);
+
+?>
\ No newline at end of file
diff --git a/js/dropdown.js b/js/dropdown.js
index 2d6675af47e53b0f93262c936bc728906a16592a..7ae9693e2ce0a34f968fa4528ca12d0c2f4bd6b9 100644
--- a/js/dropdown.js
+++ b/js/dropdown.js
@@ -1,4 +1,4 @@
-(function() {
+
 	function filter (e) {
 		let filter = e.target.value.toUpperCase();
 		let a = e.target.parentNode.querySelectorAll('a');
@@ -175,6 +175,30 @@
 
 
 
+
 	});
 
-})()
\ No newline at end of file
+		function loadLinkedActivities(courseid, id, source){
+			if(source=="competencies"){
+				competencyid=document.getElementById('competencyid_sel').value;
+				user=id;
+			}
+			else if(source=="students"){
+				user=document.getElementById('studentid_sel').value;
+				competencyid=id;
+			}
+            $.ajax({
+                url: window.location.href,
+                type: 'GET',
+                data: {competencyid:competencyid, courseid:courseid, user:user, action:"get_links"},
+                success: function(html) {
+                    if(html=='false'){
+                    	html="<p><i>Il n'y a aucune activité liée</i></p>"
+                    }
+                    $("#modal-assess-"+id+" #linked-activities").html(html);
+ 
+                }
+            });
+        }
+
+
diff --git a/lang/en/block_competency_iena.php b/lang/en/block_competency_iena.php
index 640bfdd9ed9eccc5ae8b529d74bcaa92eaad55a4..c194e6bd7b3d21de02d8fe3663c5441d38711d63 100644
--- a/lang/en/block_competency_iena.php
+++ b/lang/en/block_competency_iena.php
@@ -1,20 +1,20 @@
 <?php
     $string['delete_comp_btn'] = 'Supprimer la liaison (test)';
-	$string['date_release'] = '{$a->month}.{$a->date}.{$a->year}';
-	$string['competency_iena'] = 'Moodle Version';
-	$string['competency_iena:addinstance'] = 'Add a new moodle version block';
-	$string['competency_iena:myaddinstance'] = 'Add a new moodle version block to the My Moodle page';
+    $string['date_release'] = '{$a->month}.{$a->date}.{$a->year}';
+    $string['competency_iena'] = 'Moodle Version';
+    $string['competency_iena:addinstance'] = 'Add a new moodle version block';
+    $string['competency_iena:myaddinstance'] = 'Add a new moodle version block to the My Moodle page';
     $string['pluginname'] = 'Competency block';
-	$string['release'] = 'Release: ';
-	$string['title_plugin'] = 'Competencies iena';
-	$string['titleadd_plugin'] = 'New competency';
-	$string['titleaddname_plugin'] = 'Name';
-	$string['titleadddesc_plugin'] = 'Description';
-	$string['titleaddimg_plugin'] = 'Course picture';
-	$string['titleaddelem_plugin'] = 'Course elements';
-	$string['titleaddelemdesc_plugin'] = 'Drag and drop the elements of the course you want to add to this course';
-	$string['heading_plugin'] = 'The courses allow you to group some course resources in a particular sequence.';
-	$string['add_course'] = 'Add a course';
+    $string['release'] = 'Release: ';
+    $string['title_plugin'] = 'Competencies iena';
+    $string['titleadd_plugin'] = 'New competency';
+    $string['titleaddname_plugin'] = 'Name';
+    $string['titleadddesc_plugin'] = 'Description';
+    $string['titleaddimg_plugin'] = 'Course picture';
+    $string['titleaddelem_plugin'] = 'Course elements';
+    $string['titleaddelemdesc_plugin'] = 'Drag and drop the elements of the course you want to add to this course';
+    $string['heading_plugin'] = 'The courses allow you to group some course resources in a particular sequence.';
+    $string['add_course'] = 'Add a course';
     $string['any_carrer'] = 'No competency_iena in this course';
     $string['name_role'] = 'Nom abrégé du rôle';
     $string['name_parcour'] = 'Nom du plan';
@@ -96,5 +96,10 @@
     $string['linked_activities']="Activities and resources related to this competency";
     $string['completion_course']="Activity completion is not enabled in this course, to do so please go to the course parameters <a href='{{{link_edit_course}}}'>here</a>.";
     $string['completion_activity']="No activy or resources have completion enabled. The activities need completion enabled to be used in the matrix.";
-    
+    $string['caption_attach_evidence']="Attach evidence: the competency is linked to the activity and its completion is added to the evaluation history";
+    $string['caption_mark_complete']="Complete the competency: the competency is linked to the activity and its completion triggers the automatic acquisition of the competency, according to the \"default\" parameter of the scale";
+    $string['caption_none']="the competency is linked to the activity but does not trigger any action upon its completion";
+    $string['caption_recommend']="Send for review: the competency is linked to the activity and its completion triggers an automatic evaluation request from the student";
+    $string['caption']="Caption";
+
 ?>
\ No newline at end of file
diff --git a/lang/fr/block_competency_iena.php b/lang/fr/block_competency_iena.php
index c8e67ecea8ef4da5dbd01fcb9b45266fb00c54f2..60cb5780f33bff1e0adf37b8e5d3a8df2ac4070d 100644
--- a/lang/fr/block_competency_iena.php
+++ b/lang/fr/block_competency_iena.php
@@ -1,20 +1,20 @@
 <?php
     $string['delete_comp_btn'] = 'Supprimer la liaison (test)';
-	$string['date_release'] = '{$a->month}.{$a->date}.{$a->year}';
-	$string['competency_iena'] = 'Version Moodle';
-	$string['competency_iena:addinstance'] = 'Ajouter le module moodle version';
-	$string['competency_iena:myaddinstance'] = 'Ajouter le module moodle version sur ma page';
-	$string['pluginname'] = 'Bloc Compétences';
-	$string['title_plugin'] = 'Compétences';
-	$string['titleadd_plugin'] = 'Ajouter une compétence';
-	$string['titleaddname_plugin'] = 'Nom';
-	$string['titleadddesc_plugin'] = 'Description';
-	$string['titleaddimg_plugin'] = 'Image de la compétence';
-	$string['titleaddelem_plugin'] = 'Elements de la compétence';
-	$string['titleaddelemdesc_plugin'] = 'Glissez-déposez les élements du cours que vous souhaitez ajouter à cette compétence';
-	$string['heading_plugin'] = 'Les compétences permettent de ....................';
-	$string['add_course'] = 'Ajouter une compétence';
-	$string['any_carrer'] = 'Pas de compétence';
+    $string['date_release'] = '{$a->month}.{$a->date}.{$a->year}';
+    $string['competency_iena'] = 'Version Moodle';
+    $string['competency_iena:addinstance'] = 'Ajouter le module moodle version';
+    $string['competency_iena:myaddinstance'] = 'Ajouter le module moodle version sur ma page';
+    $string['pluginname'] = 'Bloc Compétences';
+    $string['title_plugin'] = 'Compétences';
+    $string['titleadd_plugin'] = 'Ajouter une compétence';
+    $string['titleaddname_plugin'] = 'Nom';
+    $string['titleadddesc_plugin'] = 'Description';
+    $string['titleaddimg_plugin'] = 'Image de la compétence';
+    $string['titleaddelem_plugin'] = 'Elements de la compétence';
+    $string['titleaddelemdesc_plugin'] = 'Glissez-déposez les élements du cours que vous souhaitez ajouter à cette compétence';
+    $string['heading_plugin'] = 'Les compétences permettent de ....................';
+    $string['add_course'] = 'Ajouter une compétence';
+    $string['any_carrer'] = 'Pas de compétence';
     $string['name_role'] = 'Nom abrégé du rôle';
     $string['name_parcour'] = 'Nom du plan';
     $string['no_evalued'] = 'Non évalué ';
@@ -95,8 +95,11 @@
     $string['linked_activities']="Activités et ressources liées à cette compétence";
     $string['completion_course']="Le suivi d'achèvement d'activités n'est pas activé dans ce cours. Activez-le dans les paramètres du cours <a href='{{{link_edit_course}}}'>ici</a>.";
     $string['completion_activity']="Aucune activité ou ressource n'a été paramétrée avec le suivi d'achèvement. Seules les activités avec suivi d'achèvement peuvent être ajoutées à la matrice.";
-
-
+    $string['caption_attach_evidence']="Joindre une preuve : la compétence est liée à l'activité et sa complétion est ajoutée à l'historique d'évaluation";
+    $string['caption_mark_complete']="Marquer la compétence comme atteinte : la compétence est liée à l'activité et sa complétion déclenche l'acquisition automatique de la compétence, selon le paramètre \"défaut\" du barème";
+    $string['caption_none']="Ne rien faire : la compétence est liée à l'activité mais ne déclenche aucune action à sa complétion";
+    $string['caption_recommend']="Envoyer pour validation : la compétence est liée à l'activité et sa complétion déclenche une demande d'évaluation automatique de la part de l'étudiant";
+    $string['caption']="Légende";
 
 
 
diff --git a/lib.php b/lib.php
new file mode 100644
index 0000000000000000000000000000000000000000..ae641d03523c7bbdc85686ad304ba981cf0a2297
--- /dev/null
+++ b/lib.php
@@ -0,0 +1,68 @@
+<?php
+
+defined('MOODLE_INTERNAL') || die();
+
+/**
+ * Delete an activity from the matrix when it's deleted from a course
+ * @param int $moduleid 
+ */
+function delete_matrix_competencies($moduleid){
+    global $DB;
+    $activity=$DB->record_exists('block_competency_iena', array('cmid' => $moduleid));
+    if($activity){
+        $DB->delete_records('block_competency_iena', array('cmid' => $moduleid));
+    }
+    
+
+}
+
+/**
+ * Add an activity to the matrix when it's duplicated (if the new one is linked to competencies). Moodle automatically add the corresponding competencies to the new activity, so we just have to check that to add it to the matrix if necessary
+ * @param int $moduleid 
+ */
+function duplicate_matrix_competencies($moduleid){
+    global $DB;
+    $sql = "SELECT mc.cmid, m.section FROM {competency_modulecomp} mc JOIN {course_modules} m ON mc.cmid=m.id WHERE mc.cmid= :moduleid";
+    $params=array('moduleid'=>$moduleid);
+    $activity=$DB->get_record_sql($sql, $params);
+    if($activity){
+         $DB->insert_record('block_competency_iena', array('cmid' => $activity->cmid, 'sectionid'=>$activity->section));
+    }   
+
+}
+
+function fetch_linked_activities($competencyid, $courseid, $studentid){
+    global $PAGE;
+    global $DB;
+    global $USER;
+    global $CFG;
+    $cm_ids = \core_competency\api::list_course_modules_using_competency($competencyid, $courseid);
+    $data=array();
+    if ( count($cm_ids) !== 0 ) {
+        $modules=array();
+        $modinfo = get_fast_modinfo($courseid);
+        foreach ($cm_ids as $cm_id) {
+            $module=new StdClass();
+            //if the activity is an assignment or a quiz we'll try to redirect to the student submissions specifically
+            $is_assign = strpos($modinfo->cms[$cm_id]->url->out(), '/mod/assign') !== false;
+            $is_quiz= strpos($modinfo->cms[$cm_id]->url->out(), '/mod/quiz') !== false;
+            $module->url = $modinfo->cms[$cm_id]->url->out();
+            $user=$DB->get_record("user", array("id"=>$studentid));
+            
+            //for the moment we don't manage accents in names
+            if (has_capability('mod/assign:grade', $context = context_course::instance($courseid), $USER->id) && $is_assign) {
+                $module->url = $module->url . "&action=grading&tifirst=" . $user->firstname[0] . "&tilast=". $user->lastname[0];
+            }
+            else if (has_capability('mod/quiz:grade', $context = context_course::instance($courseid), $USER->id) && $is_quiz) {
+                $module->url = $module->url . "&mode=responses&tifirst=" . $user->firstname[0] . "&tilast=". $user->lastname[0];
+            }    
+            $module->link_icon=$CFG->wwwroot."/theme/image.php/boost/".$modinfo->cms[$cm_id]->modname."/1/icon";
+            $module->name=$modinfo->cms[$cm_id]->name;
+            array_push($modules, $module);
+        }
+        $data["modules"]=$modules;
+        $renderer = $PAGE->get_renderer('block_competency_iena');
+        return $renderer->get_linked_activities($data);
+    }
+    return "false";
+}
\ No newline at end of file
diff --git a/renderer.php b/renderer.php
index d0c65cc9ada1f72de8e254f11a365380af821433..19a8c5428860983e7d63b35930a657b7de46c804 100644
--- a/renderer.php
+++ b/renderer.php
@@ -87,4 +87,8 @@ class block_competency_iena_renderer extends plugin_renderer_base {
     function get_dashboard_competency_student($data){
          echo $this->render_from_template('block_competency_iena/dashboard_competency_student', $data);
     }
+
+    function get_linked_activities($data){
+        echo $this->render_from_template('block_competency_iena/linked_activities', $data);
+    }
 }
diff --git a/styles.css b/styles.css
index c02c381983f6690dc7705b1bebc5b017c6421946..3998a5b12095d0683dc4fd83182f29f04acc73df 100644
--- a/styles.css
+++ b/styles.css
@@ -416,4 +416,12 @@ table.dataTable{
 
 /*.chart-table-data{
     display: block !important;
-}*/
\ No newline at end of file
+}*/
+
+.linked{
+    margin-bottom: 10px;
+}
+
+.linked .list-group-item{
+    padding: 0.5rem 0.5rem;
+}
\ No newline at end of file
diff --git a/templates/dashboard_competencies.mustache b/templates/dashboard_competencies.mustache
index 794034e70c2b22e70eab3dc96f6b7c6788018a23..f1da780a988874f87db4b02eb8b78b407782f074 100644
--- a/templates/dashboard_competencies.mustache
+++ b/templates/dashboard_competencies.mustache
@@ -16,7 +16,7 @@
 					{{/review}}
 					<span hidden id='competencyid'>{{current_cpt.id}}</span>
 					<div id='student_dropdown' class='iena-dropdown' style='z-index: 1;'>
-						<input type='text' hidden name='competencyid' id='competencyid_sel' class='iena-drop-input-value' value=''>
+						<input type='text' hidden name='competencyid' id='competencyid_sel' class='iena-drop-input-value' value={{current_cpt.id}}>
 						<input type='text' value='' class='form-control iena-drop-input' style='width: 300px;' placeholder='{{current_cpt.shortname}}' autocomplete='nope'><button class='btn btn-secondary' id='prevCpt' style='margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextCpt' style='margin-left: 0.5rem;'>Suivant</button>
 						<div class='iena-droplist' id='competency_list'>
 						{{#course_cpts}}
@@ -81,7 +81,7 @@
 								<div><small class='review-badge'>Évaluation demandée</small></div>
 							{{/review_asked}}
 							<div class="user-competency-actions">
-							<a href="#" data-toggle='modal' data-target='#modal-assess-{{id}}' class="action-icon" title="Evaluer" aria-label="Evaluation"><i class="icon fa fa-file-text-o fa-fw " aria-hidden="true"></i></a>
+							<a href="#" data-toggle='modal' data-target='#modal-assess-{{id}}' class="action-icon" title="Evaluer" aria-label="Evaluation" onclick="loadLinkedActivities({{courseid}},{{id}}, 'competencies')"><i class="icon fa fa-file-text-o fa-fw " aria-hidden="true"></i></a>
 							
 							<a href="{{link_cpt}}" class="action-icon" title="Détails" aria-label="{{#str}} eval, block_competency_iena {{/str}}"><i class="icon fa fa-search-plus fa-fw " aria-hidden="true"></i></a>
 							</div>
@@ -102,7 +102,7 @@
 							<div class='modal-body'>
 								<form method='post' action='{{link_assess}}'>
 									<div class='form-group'><div class='form-group'>
-										<label>Évaluation</label>
+										
 										<select name='grade' class='form-control'>
 										{{#scale}}
 											<option value='{{value}}'{{selected}}>{{title}}</option>
@@ -112,6 +112,12 @@
 									<div class='form-group'>
 										<textarea name='note' class='form-control' placeholder="Commentaire d'évaluation"></textarea>
 									</div>
+									<div class="linked">
+											<h5>Activités liées</h5>
+											<div id="linked-activities">
+
+											</div>
+										</div>
 									<button type='submit' class='btn btn-primary'>Évaluer</button>
 								</form>
 								
@@ -128,6 +134,7 @@
 			</div>
 		</div>
 	</div>
+
 {{/count_course_cpts}}
 {{^count_course_cpts}}
 <p class='alert alert-warning'>Pour le moment, aucune compétence n'a été liée à ce cours. Pour lier des compétences au cours et les associer à des activités, rendez-vous dans la page <a href='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid={$courseid}'>Gestion des compétences</a>. </p>
diff --git a/templates/dashboard_students.mustache b/templates/dashboard_students.mustache
index 7191db18765e0c0455d1ff4c2d39f2e59be882c5..d365519d8361e562332fe27442625ff9ec7a870f 100644
--- a/templates/dashboard_students.mustache
+++ b/templates/dashboard_students.mustache
@@ -11,7 +11,7 @@
 						<input type='text' hidden name='courseid' value='{{courseid}}'>
 						<span hidden id='studentid'>{{student.studentid}}</span>
 						<div id='student_dropdown' class='iena-dropdown' style='z-index: 10;'>
-							<input type='text' hidden name='studentid' id='studentid_sel' class='iena-drop-input-value' value=''>
+							<input type='text' hidden name='studentid' id='studentid_sel' class='iena-drop-input-value' value={{student.studentid}}>
 							<input type='text' value='' class='form-control iena-drop-input' style=' width: 300px;' placeholder='{{student.firstname}} {{student.lastname}}'><button class='btn btn-secondary' id='prevStud' style=' margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextStud' style=' margin-left: 0.5rem;'>Suivant</button>
 							<div class='iena-droplist' id='student_list'>
 								{{#students}}
@@ -52,7 +52,7 @@
 										<div><small class='review-badge'>Évaluation demandée</small></div>
 									{{/review_asked}}
 									<div class="user-competency-actions">
-									{{#is_not_student}}<a href="#" data-toggle='modal' data-target='#modal-assess-{{id}}' class="action-icon" title="Evaluer" aria-label="Evaluation"><i class="icon fa fa-file-text-o fa-fw " aria-hidden="true"></i></a>
+									{{#is_not_student}}<a href="#" data-toggle='modal' data-target='#modal-assess-{{id}}' class="action-icon" title="Evaluer" aria-label="Evaluation" onclick="loadLinkedActivities({{courseid}},{{id}}, 'students')"><i class="icon fa fa-file-text-o fa-fw " aria-hidden="true"></i></a>
 									{{/is_not_student}}
 									<a href="{{link}}" class="action-icon" title="Détails" aria-label="{{#str}} eval, block_competency_iena {{/str}}"><i class="icon fa fa-search-plus fa-fw " aria-hidden="true"></i></a>
 									</div>
@@ -74,7 +74,7 @@
 								<div class='modal-body'>
 									<form method='post' action='{{link_dashboard}}?courseid={{courseid}}&studentid={{student.studentid}}&competencyid={{id}}'>
 										<div class='form-group'><div class='form-group'>
-											<label>Évaluation</label>
+											
 											<select name='grade' class='form-control'>
 											{{#scale}}
 												<option value='{{value}}'{{selected}}>{{title}}</option>
@@ -84,6 +84,12 @@
 										<div class='form-group'>
 											<textarea name='note' class='form-control' placeholder="Commentaire d'évaluation"></textarea>
 										</div>
+										<div class="linked">
+											<h5>Activités liées</h5>
+											<div id="linked-activities">
+
+											</div>
+										</div>
 										<button type='submit' class='btn btn-primary'>Évaluer</button>
 									</form>
 									
diff --git a/templates/linked_activities.mustache b/templates/linked_activities.mustache
new file mode 100644
index 0000000000000000000000000000000000000000..8389a460ae6ea6e548c5b54bdd0eb9683ec8a8cf
--- /dev/null
+++ b/templates/linked_activities.mustache
@@ -0,0 +1,9 @@
+<div>
+    {{#modules}}
+        <a href='{{url}}' target='_blank' class='list-group-item list-group-item-action'><img src='{{link_icon}}' style='height: 1.3rem;'><span class='align-middle'> {{name}}</span></a>
+    {{/modules}}
+    {{^modules}}
+        Pas d'activité
+    {{/modules}}
+</div>
+
diff --git a/templates/matrix_competencies.mustache b/templates/matrix_competencies.mustache
index 3d35eef0cb822a6ce41577a99664c0a9f481783d..10270b1dc220a3d78082d28912cb9c741f74faa9 100644
--- a/templates/matrix_competencies.mustache
+++ b/templates/matrix_competencies.mustache
@@ -8,6 +8,15 @@
 <div class="alert alert-warning">{{#str}} completion_activity, block_competency_iena{{/str}}</div>
 {{/completion_activity}}
 
+<div class="alert alert-info">
+	<span><b>{{#str}} caption, block_competency_iena{{/str}}</b></span>
+	<li>{{#str}} caption_none, block_competency_iena{{/str}}</li>
+	<li>{{#str}} caption_attach_evidence, block_competency_iena{{/str}}</li>
+	<li>{{#str}} caption_recommend, block_competency_iena{{/str}}</li>
+	<li>{{#str}} caption_mark_complete, block_competency_iena{{/str}}</li>
+</div>
+
+
 <table id="tab_mgmt" class="table-bordered order-column row-border dataTable" >
 	<thead>
 		<tr>
diff --git a/version.php b/version.php
index ac8ba53664f526d7b34094388ee9eb5664bf9c67..bf7522f481f9a90a499f5181a789d96e1b11ce61 100644
--- a/version.php
+++ b/version.php
@@ -28,7 +28,7 @@
  */
 defined('MOODLE_INTERNAL') || die();
 
-$plugin->version = 2022000000;
+$plugin->version = 2022062800;
 $plugin->requires = 2014051200;
 $plugin->component = 'block_competency_iena';
 $plugin->release = 'v1.0';