view_competency_iena_user.php 46 KB
Newer Older
Thomas Fradet's avatar
folder  
Thomas Fradet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
// MICHAEL LEBEAU
// CAMILLE VRIGNAUD

class view_competency_iena_user
{
	public function get_competency_history($studentid, $competencyid)
	{
		global $COURSE, $DB, $USER;

		try {
			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
				$tab_competency_history = $DB->get_records_sql('select * FROM {competency_evidence} as ce
					inner join {competency_usercomp} as cuc on cuc.id = ce.usercompetencyid
					WHERE cuc.userid = ? AND cuc.competencyid = ?', array($studentid, $competencyid));
			} else {
				$tab_competency_history = $DB->get_records_sql('select * FROM {competency_evidence} as ce
					inner join {competency_usercomp} as cuc on cuc.id = ce.usercompetencyid
					WHERE cuc.userid = ? AND cuc.competencyid = ?', array($USER->id, $competencyid));
			}
		} catch (coding_exception $e) {
		} catch (dml_exception $e) {
		}
		return $tab_competency_history;

	}

	public function get_usercomp_id ($userid, $competency_id) {
		global $DB;
		$res = $DB->get_record_sql('SELECT id FROM {competency_usercomp} as CUC WHERE CUC.userid = ? AND CUC.competencyid = ?', [$userid, $competency_id]);
		return $res->id;
	}

	public function get_content()
	{

		global $COURSE, $DB, $USER, $CFG;

		$competencyid = $_GET['competencyid'];
			//$id_student = $_GET['studentid'];

		if ($_GET['studentid']) {
			$tmpiduser = $_GET['studentid'];
		} else {
			$tmpiduser = $USER->id;
		}
		$competency_instance = new block_competency_iena_competency();
		$competencies = $competency_instance->get_competencies_by_courseID($COURSE->id);

		$competency_instance->get_competency_by_id($competencyid);
		$module_instance = new block_competency_iena_module();
		$module_comp = $module_instance->get_modules_by_competencyID($competencyid);

		$data = $competency_instance->get_data($tmpiduser, $competencyid, $COURSE->id);
Thomas Fradet's avatar
Thomas Fradet committed
55
		$scale = \grade_scale::fetch(array('id' => $data->usercompetencysummary->competency->scaleid));
Thomas Fradet's avatar
folder  
Thomas Fradet committed
56
		$scale->load_items();
Thomas Fradet's avatar
Thomas Fradet committed
57
58
59
60
61
62
63
64
65

		// $core_comp = core_competency\api::read_competency($competencyid);

		// echo "<pre>";
		// var_dump($data);
		// var_dump($data->usercompetencysummary->competency->scaleid);
		// var_dump($scale);
		// echo "</pre>";

Thomas Fradet's avatar
folder  
Thomas Fradet committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
			//var_dump($scale->scale_items);die;

		$student_instance = new block_competency_iena_student();
			// FILTRER PROF
		$students = $student_instance->get_all_students_by_course($COURSE->id);
		$student_instance->get_student_by_id($USER->id);

			//$link2 = $CFG->wwwroot. $_SERVER['REQUEST_URI'];
		$link2 = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_user.php?courseid=' . $COURSE->id . '&competencyid=' . $competencyid . '&studentid=';
		$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_user.php?courseid=' . $COURSE->id . '&competencyid=';

		$instance = new view_competency_iena_user();
		$tab_competency_history = $instance->get_competency_history($tmpiduser, $competencyid);


		try {
			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
				$tab_comments = $DB->get_records_sql('select * FROM {block_competency_iena_com}
					WHERE idstudent = ? AND idcompetency = ?', array($tmpiduser, $_GET['competencyid']));
			} else {
				$tab_comments = $DB->get_records_sql('select * FROM {block_competency_iena_com}
					WHERE idstudent = ? AND idcompetency = ?', array($USER->id, $_GET['competencyid']));
			}
		} catch (coding_exception $e) {
		} catch (dml_exception $e) {
		}

		/* La compétence */
		$current_competency = core_competency\api::read_competency($competencyid);
		
		/* Le référentiel */
		$competency_framework = core_competency\api::read_framework( $current_competency->get('competencyframeworkid') );

		$descendants_ids = core_competency\competency::get_descendants_ids($current_competency);
		
		$course_competencies = core_competency\course_competency::list_course_competencies($COURSE->id);
		
		$course_competencies_ids = [];
		foreach ( $course_competencies as $course_competency ) {
			$course_competencies_ids[] = $course_competency->get('competencyid');
		}

		$in_course_descendant_ids = [];
		foreach ( $descendants_ids as $desc_id ) {
			if ( in_array( $desc_id, $course_competencies_ids ) ) {
				$in_course_descendant_ids[] = $desc_id;
			}
		}
		
		// var_dump($in_course_descendant_ids);
		// die;


		if ( count( $in_course_descendant_ids ) > 0 ) {
			$children_competencies = [];
			foreach ( $in_course_descendant_ids as $child_id ) {
Thomas Fradet's avatar
Thomas Fradet committed
122

Thomas Fradet's avatar
folder  
Thomas Fradet committed
123
124
125
126
127
128
129
130
131
132
133
				$child_competency = core_competency\api::read_competency($child_id);
				if ( $child_competency->get('parentid') != $competencyid ) {
					continue;
				}
				try {
					$child_in_course_competency = core_competency\api::get_user_competency_in_course($COURSE->id, $tmpiduser, $child_id);
				} catch (Exception $e) {
				}
				$tmp_cpt = new StdClass();
				$tmp_cpt->id = $child_competency->get('id');
				$tmp_cpt->name = $child_competency->get('shortname');
Thomas Fradet's avatar
Thomas Fradet committed
134
135
136
137
138
139
140
141
142
143
144
145
				// echo "<pre>";
				// var_dump($child_in_course_competency);
				
				// before
				// $scale = \grade_scale::fetch( ['id' => $child_competency->get('scaleid')] );
				// $tmp_cpt->scale = $scale->load_items();

				// after
				$data = $competency_instance->get_data($tmpiduser, $child_id, $COURSE->id);
				$sub_scale = \grade_scale::fetch(array('id' => $data->usercompetencysummary->competency->scaleid));
				$tmp_cpt->scale = $sub_scale->load_items();

Thomas Fradet's avatar
folder  
Thomas Fradet committed
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
				$tmp_cpt->proficiency = $child_in_course_competency->get('proficiency');
				$tmp_cpt->grade = $child_in_course_competency->get('grade');
				$children_competencies[] = $tmp_cpt;
			}
		}

		if ( count($children_competencies) == 0 ) {
			$children_competencies = false;
		}

		?>

		<!-- VIEW -->

		<script type="text/javascript" charset="utf8" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" charset="utf8" src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>

		<!-- Description de la compétence actuelle, de ses parents dans la référentiel et du référentiel lui-même + actions rapides sur les cpt enfants. -->
		<h2 style="color: #008c7d;font-weight: 400;font-variant: small-caps; margin-bottom: 1rem; border-bottom: 1px solid #008c7d;"><?php echo $current_competency->get('shortname') ?></h2>
		<div class="row m-b-2">
			<div class="col-md-9 iena-ul-left">
				<style>.iena-ul-left ul { margin-left: 1.5rem; }</style>

				<!-- Début de l'accordéon -->

				<!-- Infos sur le référentiel -->
				<div id="acc-ref" class="iena-acc-title"><?php echo $competency_framework->get('shortname') ?></div>
				<div id="acc-ref-content" class="iena-acc-content"><div style="padding: 1rem 0;"><?php echo $competency_framework->get('description') ?></div></div>

				<!-- Infos sur chaque compétence parente de celle-ci dans le référentiel -->
				<?php foreach ( $current_competency->get_ancestors() as $ancestor_id => $ancestor ) {
					echo '<div id="acc-'.$ancestor_id.'" class="iena-acc-title">'.$ancestor->get('shortname').'</div>';
					echo '<div id="acc-'.$ancestor_id.'-content" class="iena-acc-content"><div style="padding: 1rem 0;">'.$ancestor->get('description').'</div></div>';
				} ?>

				<!-- Infos sur la compétence actuelle -->
				<div id="acc-current-cpt" class="iena-acc-title acc-current-cpt <?php if( !isset($_GET['active']) || $_GET['active'] !== "sub" ) { echo 'iena-acc-active'; } ?>"><?php echo $current_competency->get('shortname') ?></div>
				<div id="acc-current-cpt-content" class="iena-acc-content acc-current-cpt <?php if( !isset($_GET['active']) || $_GET['active'] !== "sub" ) { echo 'iena-acc-active'; } ?>">
					<div style="padding: 1rem 0;"><?php echo $current_competency->get('description') ?></div>
				</div>

				<!-- Compétences filles de la cpt actuelle dans le référentiel -->
				<?php if ( $children_competencies !== false ): ?>
					<div id="acc-children-cpt" class="iena-acc-title iena-acc-children <?php if( isset($_GET['active']) && $_GET['active'] == "sub" ) { echo 'iena-acc-active'; } ?>">Dans «&nbsp;<?php echo $current_competency->get('shortname') ?>&nbsp;»</div>
					<div id="acc-children-cpt-content" class="iena-acc-content iena-acc-children <?php if( isset($_GET['active']) && $_GET['active'] == "sub" ) { echo 'iena-acc-active'; } ?>" style="padding: 0; max-height: initial;">

						<?php 
						foreach ( $children_competencies as $key_cpt => $child ) {
							if ( $key_cpt == 0 ) {
								echo "<div style='padding: 1rem;'>";
							} else {
								echo "<div style='padding: 1rem; border-top: 1px solid white;'>";
							}

							/* Nom de l'élément de cpt */
							echo "<h4>$child->name</h4>";

							/* Compétent ou non (proficiency) */
							if ( $child->proficiency == NULL || $child->proficiency == 0 ) {
								$child->proficiency = "Non";
							} else {
								$child->proficiency = "Oui";
							}
							echo "<p class='m-0'>Acquis&nbsp;: $child->proficiency</p>";

							/* Evaluation actuelle (grade) */
							if ( $child->grade == NULL ) {
								echo "<p>Évaluation : –</p>";
							} else {
								echo "<p>Évaluation : «&nbsp;".$child->scale[$child->grade-1]."&nbsp;»</p>";
							}

							/* Lien vers la page complète de l'élément de cpt */
							$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_user.php?courseid=' . $COURSE->id . '&competencyid=' . $child->id . '&studentid=' . $tmpiduser;
							echo "<a class='btn btn-secondary btn-sm' href='$link'>Consulter</a>";

							if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {

								/* Boutons pour une évaluation rapide et l'historique */
								echo "<button class='btn btn-primary btn-sm' onclick='$(\"#eval-$key_cpt\").toggle();'>Évaluation rapide</button>";
								echo "<button class='btn btn-success btn-sm' onclick='$(\"#history-$key_cpt\").toggle();'>Historique</button>";

								/* Evaluation rapide de la cpt-enfant */
								echo "<div id='eval-$key_cpt' style='display: none;'>";
								echo "<select class=\"form-control\" style='display: inline-block;' id=\"slc-eval_$key_cpt\">";
								foreach ($child->scale as $key => $item){
									echo "<option value='$key'>$item</option>";
								}
								echo "</select>";
								echo "<textarea id=\"slc-eval-note_$key_cpt\" class=\"mt-1 form-control\"  rows='4' class='w-100' placeholder=\"Message joint à l'évaluation.\"></textarea>";
								echo "
								<input type='hidden' value='$tmpiduser' id='iduser_iena_$key_cpt'>
								<input type='hidden' value='$child->id' id='compid_iena_$key_cpt'>
								<input type='hidden' value='$COURSE->id' id='courseid_iena_$key_cpt'>
								<input type='hidden' value='$CFG->wwwroot' id='wwwroot_iena_$key_cpt'>
								<button type='button' class='btn btn-primary mt-1' id='btn-eval-$key_cpt'>Valider</button>";
								?>
								<script>
									$(document).ready(function () {
										$('#btn-eval-<?php echo $key_cpt; ?>').click(function () {
Thomas Fradet's avatar
Thomas Fradet committed
246
247
											// console.log(this);
											// console.log($("#courseid_iena_<?php echo $key_cpt; ?>").val());
Thomas Fradet's avatar
folder  
Thomas Fradet committed
248
249
250
251
252
253
											var data = {
												eval_comp: $("#slc-eval_<?php echo $key_cpt; ?>").val(),
												userid : $("#iduser_iena_<?php echo $key_cpt; ?>").val(), 
												compid : $("#compid_iena_<?php echo $key_cpt; ?>").val(), 
												eval_comp_note: "Evaluation données dans le cours « <?php echo $COURSE->fullname ?> » par <?php echo( $USER->firstname . " " . $USER->lastname ) ?>. " + $("#slc-eval-note_<?php echo $key_cpt; ?>").val()
											}
Thomas Fradet's avatar
Thomas Fradet committed
254
											// console.log( data );
Thomas Fradet's avatar
folder  
Thomas Fradet committed
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
											$.ajax({
												url: $("#wwwroot_iena").val() + '/blocks/competency_iena/' +
												'competency_iena_competencies_api.php?courseid=' + $("#courseid_iena_<?php echo $key_cpt; ?>").val(),
												type: 'POST',
												timeout: 30000,
												contentType: 'application/x-www-form-urlencoded',
												data: {
													eval_comp: $("#slc-eval_<?php echo $key_cpt; ?>").val(),
													userid : $("#iduser_iena_<?php echo $key_cpt; ?>").val(), 
													compid : $("#compid_iena_<?php echo $key_cpt; ?>").val(), 
													eval_comp_note: "Evaluation données dans le cours « <?php echo $COURSE->fullname ?> » par <?php echo( $USER->firstname . " " . $USER->lastname ) ?>. " + $("#slc-eval-note_<?php echo $key_cpt; ?>").val()
												},
												success: function (result) {
													/* Recharge avec les sous-éléments de cpt déjà dépliés */
													window.location = window.location.href + '&active=sub';
												}
											});
										});
									});
								</script>
								<?php
								echo "</div>"; /* Fin de la div d'évaluation rapide de la cpt enfant. */

								/* Zone d'historique pour la sous-cpt */
								echo "<div id='history-$key_cpt' style='display: none; margin-top: 1rem;' class='row'>";

								/* Historique propre au cours */
								/* Extraction de l'historique */
								$user_competency_summary_in_course = new \tool_lp\output\user_competency_summary_in_course($tmpiduser, $child->id, $COURSE->id);
								$dataSumCourse = $user_competency_summary_in_course->export_for_template(new renderer_base(new moodle_page(), 'autre'));
								$course_history_size = count($dataSumCourse->usercompetencysummary->evidence);
								if ( $course_history_size == NULL ) {
									$course_history_size = 0;
								}
								if ( $course_history_size == 0 ) {
									echo "<div class='col-md-6'><h5>Pas d'historique de cours pour ce élément de compétence.</h5></div>";
								} else {
									echo "<div class='col-md-6'><h5>Historique de cours (" . $course_history_size . ")</h5>";
									echo "<div style='color: black;max-height: 300px; overflow: scroll;'>";
									foreach ($dataSumCourse->usercompetencysummary->evidence as $value) {
										echo "<div class=\"card card-block\">
										<div class=\"card-body\">
										<div class=\"pull-xs-right iena-cpt-abs-right\"><a href=\"#\" onclick='deleteProof(\"$value->id\",\"$COURSE->id\",\"$CFG->wwwroot\")' ><i class=\"icon fa fa-trash fa-fw \" aria-hidden=\"true\" aria-label=\"\"></i></a></div>";
										if ($value->actionuserid != NULL) {
											echo "<div><span><a href=\"" . $value->actionuser->profileurl . "\" title=\"Consulter le profil\"><img height=\"18\" src=\"" . $value->actionuser->profileimageurlsmall . "\" alt=\"\" role=\"presentation\"><span>" . $value->actionuser->fullname . "</span></a></span></div>";
										}
										echo "<strong><time>";
										date_default_timezone_set('Europe/Paris');
										echo strftime("%A %d %B %Y", $value->timemodified);
										echo "</time></strong>
										<p class='mb-0'><span class=\"tag tag-info\">$value->gradename</span></p>
										<p class='mb-0'>$value->description";
										if ($value->descidentifier == "evidence_coursemodulecompleted") {
											echo " <a href=\"$value->url\"> — Voir</a>";
										}
										echo "</p>";
										if ($value->note != NULL) {
											echo "<div class='alert alert-success'>$value->note</div>";
										}
										echo "</div></div>";
									} /* fin boucle liste historique de cours */

									echo '</div>'; /* Fin de la div de hauteur fixe de l'historique de cours. */
									echo '</div>'; /* Fin de la div de l'historique de cours. */
								} /* Fin condition qu'il y ait un historique de cours */

								/* Historique complet */
								/* Id compétence x utilisateur d'après cpt_id et user_id */
								$usercomp_id = $this->get_usercomp_id($tmpiduser, $child->id);
								if ( $usercomp_id != NULL ) {
									/* Compétence utilisateur d'après cpt_user_id */
									$complete_current_competency = core_competency\api::get_user_competency_by_id($usercomp_id);
									/* Extraction de l'historique */
									$apiCompSum = new \tool_lp\output\user_competency_summary($complete_current_competency);
									$dataSum = $apiCompSum->export_for_template(new renderer_base(new moodle_page(), 'autre'));
									$full_history_size = count($dataSum->evidence);
								} else {
									$full_history_size = 0;
								}
								if ( $full_history_size == 0 ) {
									echo "<div class='col-md-6'><h5>Pas d'historique pour ce élément de compétence. </h5></div>";
								} else {
									echo "<div class='col-md-6'><h5>Historique complet (" . $full_history_size . ")</h5>";
									echo "<div style='color: black;max-height: 300px; overflow: scroll;'>";
									foreach ($dataSum->evidence as $value) {
										echo "<div class=\"card card-block\">
										<div class=\"card-body\">
										<div class=\"pull-xs-right iena-cpt-abs-right\"><a href=\"#\" onclick='deleteProof(\"$value->id\",\"$COURSE->id\",\"$CFG->wwwroot\")' ><i class=\"icon fa fa-trash fa-fw \" aria-hidden=\"true\" aria-label=\"\"></i></a></div>";
										if ($value->actionuserid != NULL) {
											echo "<div><span><a href=\"" . $value->actionuser->profileurl . "\" title=\"Consulter le profil\"><img height=\"18\" src=\"" . $value->actionuser->profileimageurlsmall . "\" alt=\"\" role=\"presentation\"><span>" . $value->actionuser->fullname . "</span></a></span></div>";
										}
										echo "<strong><time>";
										date_default_timezone_set('Europe/Paris');
										echo strftime("%A %d %B %Y", $value->timemodified);
										echo "</time></strong>
										<p class='mb-0'><span class=\"tag tag-info\">$value->gradename</span></p>
										<p class='mb-0'>$value->description";
										if ($value->descidentifier == "evidence_coursemodulecompleted") {
											echo " <a href=\"$value->url\"> — Voir</a>";
										}
										echo "</p>";
										if ($value->note != NULL) {
											echo "<div class='alert alert-success'>$value->note</div>";
										}
										echo "</div></div>";
									} /* fin boucle liste historique complet */

									echo '</div>'; /* Fin de la div de hauteur fixe de l'historique complet. */
									echo '</div>'; /* Fin de la div de l'historique complet. */
								} /* Fin condition qu'il y ait un historique complet */

								echo "</div>"; /* fin de la div englobant les 2 historiques */
							}

							echo '</div>'; /* Fin de la div pour chaque compétence enfant. */
						} /* Fin de la boucle pour chaque compétence enfant. */
						?>

					</div> <!-- Fin de la div de l'accordéon pour les cpt enfant. -->
					<?php endif; ?> <!-- Fin de la condition qu'il y ait des compétences enfant. -->

					<style>
					/* Style de l'accordéon de la description */
					.iena-acc-title { cursor: pointer; padding: 0.5rem 1rem; background-color: #eee; font-variant: small-caps; }
					.iena-acc-title:hover { font-weight: bold; }
					.iena-acc-active { background-color: #ddd; }
					.iena-acc-content { display: none; padding: 0 1rem; max-height: 250px; overflow: scroll; background-color: white; border-left: 1px solid #ccc; border-right: 1px solid #ccc; }
					.iena-acc-content.iena-acc-active { display: block; }
					.iena-acc-content.acc-current-cpt, .iena-acc-content.iena-acc-children { border:  none; }
					.acc-current-cpt { background-color: #008c7d; color: white; }
					.iena-acc-children { background-color: #008696; color: white; }
					.iena-acc-content.iena-acc-children { background-color: #026773; }
					.iena-acc-content.acc-current-cpt { background-color: #02695e; }
					.iena-acc-title.acc-current-cpt { border-bottom: 1px solid white; }
					.iena-acc-title.iena-acc-children { border-bottom: 1px solid white; }
				</style>
				<script>
					/* Script de l'accordéon de la description */
					window.onload = function () {	
						$('.iena-acc-title').click(function () {
							$('.iena-acc-active').removeClass('iena-acc-active')
							$(this).addClass('iena-acc-active')
							$('#' + this.id + '-content').addClass('iena-acc-active')
						})
					}
				</script>
			</div> <!-- Fin de la div colonne de la description + action rapide sur les cpt enfant -->

			<!-- Changement d'utilisateur et de compétence. -->
			<div class="col-md-3">
				<?php
				try {
					if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
						try {
							echo
							"
							<label class='mb-0'>" . get_string('chang_student', 'block_competency_iena') . "</label>
							<span class=\"myarrow\">
							<input list=\"student_browser\" id=\"myStudentBrowser\" name=\"myStudentBrowser\" placeholder=\"";
						} catch (coding_exception $e) {
						}
						if ($_GET['studentid']) {
							foreach ($students as $student) {
								if ($student->id == $tmpiduser) {
									echo $student->firstname . " " . $student->lastname;
								}
							}
						} else {
							echo $USER->firstname . " " . $USER->lastname;
						}
						echo "\" data-studid=\"";
						if ($_GET['studentid']) {
							foreach ($students as $student) {
								if ($student->id == $tmpiduser) {
									echo $student->id;
								}
							}
						} else {
							echo $USER->id;
						}
						echo "\">
						</span>
						<datalist id=\"student_browser\">";
						foreach ($students as $student) {
							echo "<option data-value=\"" . $link2 . $student->id . "\" value=\"" . $student->id . "\" data-studid=\"".$student->id."\">" . $student->firstname . " " . $student->lastname . "</option>";
						}
						try {
							echo
							"</datalist>

							<div><span id='prev_student'>Précédent</span><span id='next_student'>Suivant</span></div>

							<style>
							#myStudentBrowser, #myCompetencyBrowser { width: 100%;height: 2rem;margin: 0.5rem 0; }
							label { font-weight: bold; clear: both; display: block; }
							#prev_student, #next_student { font-size: 0.9rem; padding: 0.25rem 0.5rem; background-color: #eee; margin-bottom: 0.5rem; cursor: pointer; }
							#prev_student:hover, #next_student:hover { background-color: #ccc; }
							#prev_student { float: left; }
							#next_student { float: right; }
							</style>


							<label class='mb-0'>" . get_string('change_comp', 'block_competency_iena') . "</label>
							<span class=\"myarrow\">
							<input list=\"competency_browser\" id=\"myCompetencyBrowser\" name=\"myCompetencyBrowser\" placeholder=\"" . $competency_instance->shortname . "\"/>
							</span>
							<datalist id=\"competency_browser\">";
						} catch (coding_exception $e) {
						}
						foreach ($competencies as $competency) {
							echo "<option data-value=\"" . $link . $competency->id . "&studentid=" . $tmpiduser . "\" value=\"" . $competency->shortname . "\"></option>";
						}
						echo
						"</datalist>

						";
					} else {
						echo "
						<div class=\"centered\">
						<p>" . get_string('change_comp', 'block_competency_iena') . "</p>
						<span class=\"myarrow\">
						<input list=\"competency_browser\" id=\"myCompetencyBrowser\" name=\"myCompetencyBrowser\" placeholder=\"" . $competency_instance->shortname . "\" />
						</span>
						<datalist id=\"competency_browser\">";
						foreach ($competencies as $competency) {
							echo "<option data-value=\"" . $link . $competency->id . "\" value=\"" . $competency->shortname . "\"></option>";
						}
						echo
						"</datalist>
						</div>
						";
					}
				} catch (coding_exception $e) {
				}
				?>
			</div>
		</div>

		<!-- Evaluation de la compétence et liste des modules liés. -->
		<div class="row">
			<!-- Evaluation de la compétence -->
			<div class="col-md-6">
				<section id="list_module" class="block_compet_param">
					<h2 class="title_blue">
						<?php echo get_string('eval_2', 'block_competency_iena'); ?>
					</h2>
					<div style="border: 1px solid #ccc; border-radius: 0.15rem; padding: 1rem; margin-bottom: 1rem;">
						<p class="mb-0">
							<?php 
							echo get_string('comp_2', 'block_competency_iena');
							$proficiency_color = 'inherit';
							if ( $data->usercompetencysummary->usercompetencycourse->proficiency == 1 ) {
								$proficiency_color = 'green';
							}
							?>
							<span style="color:<?php echo $proficiency_color; ?>"><?php echo $data->usercompetencysummary->usercompetencycourse->proficiencyname ?></span>
						</p>
						<p>
							<?php echo get_string('eval_3', 'block_competency_iena'); ?>
							<span><?php echo $data->usercompetencysummary->usercompetencycourse->gradename ?></span>
						</p>

						<?php 

						$val_asked = $DB->get_record_sql('select * FROM {competency_usercomp} WHERE competencyid = ? AND userid = ?', array($competencyid, $tmpiduser));

Thomas Fradet's avatar
Thomas Fradet committed
521
522
						if ( has_capability('moodle/course:update',
							$context = context_course::instance($COURSE->id), $USER->id) ) {
Thomas Fradet's avatar
folder  
Thomas Fradet committed
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738

							if ( $val_asked->status == "1" ) {
								echo "<div class='alert alert-info'>Validation / Evaluation demandée par l'étudiant</div>";
							}

							echo "<button type=\"button\"
							class=\"btn btn-primary\" id='eval-show'>".get_string('evalute_iena', 'block_competency_iena')."</button>
							<div id='eval-hide'>
							<select class=\"form-control\" style='display: inline-block;' id=\"slc-eval\">";
							foreach ($scale->scale_items as $key => $item){
								echo "<option value='$key'>$item</option>";
							}
							echo "</select>";
							echo "<textarea id=\"slc-eval-note\" class=\"mt-1 form-control\"  rows='4' class='w-100' placeholder=\"Message joint à l'évaluation.\"></textarea>";
							echo "
							<input type='hidden' value='$tmpiduser' id='iduser_iena'>
							<input type='hidden' value='$competencyid' id='compid_iena'>
							<input type='hidden' value='$COURSE->id' id='courseid_iena'>
							<input type='hidden' value='$CFG->wwwroot' id='wwwroot_iena'>
							<button type='button' class='btn btn-primary mt-1' id='btn-eval'>Valider</button>
							</div>";
						} else {
							if ( $val_asked->status == "1" ) {
							// var_dump($val_asked->status);
								$display_demande = 'none';
								$display_cancel = 'block';
							} else {
								$display_demande = 'block';
								$display_cancel = 'none';
							}
							echo " <button style='display: $display_demande;' type=\"button\" onclick='AskValide(\"$competencyid\",\"$tmpiduser\",1,\"$COURSE->id\",\"$CFG->wwwroot\")' 
							class=\"btn btn-outline-primary btn-block\" id='show-valide'>".get_string('ask_demande', 'block_competency_iena')."</button>";
							echo " <button style='display: $display_cancel;' type=\"button\" onclick='AskValide(\"$competencyid\",\"$tmpiduser\",0,\"$COURSE->id\",\"$CFG->wwwroot\")' 
							class=\"btn btn-outline-primary btn-block\" id='cancel-valide'>".get_string('cancel_demande', 'block_competency_iena')."</button>";
						} ?>
					</div>
				</section>
			</div>

			<!-- Liste des modules liés -->
			<div class="col-md-6">
				<?php if ( count($module_comp) > 0 ): ?>
					<section id="list_module" class="block_compet_param">
						<?php echo '<h2 class="title_blue">' . get_string('list_modules', 'block_competency_iena') . '</h2>'; ?>
						<div style="overflow-y: scroll; max-height:15.7rem; border: 1px solid #ccc; border-radius: 0.15rem; margin-bottom: 1rem;">

							<?php
							foreach ($module_comp as $module) {
								$moduleI = new block_competency_iena_ressource();
								$moduleI->get_ressource_by_id($module->moduleid);
								$completion = $module->get_completions_by_module($tmpiduser, $COURSE->id, $module->moduleid);
								$pictureC = "";
								if ($moduleI->completion == 0) {
									$pictureC = "";
								} else if (!$completion) {
									$pictureC = "<img class=\"icon\" src=\"$CFG->wwwroot/theme/image.php/boost/core/1/i/completion-manual-n\">";
								} else if ($completion->completionstate == 1) {
									$pictureC = "<img class=\"icon\" src=\"$CFG->wwwroot/theme/image.php/boost/core/1/i/completion-manual-y\">";
								} else if ($completion->completionstate == 2) {
									$pictureC = "<img class=\"icon\" src=\"$CFG->wwwroot/theme/image.php/boost/core/1/i/completion-auto-pass\">";
								}
							// echo "<a href=\"$moduleI->link\" class=\"list-group-item list-group-item-action flex-column align-items-start\">
							// <div class=\"d-flex w-100 justify-content-between\">
							// <h5 class=\"mb-1\"><div class='row'><div class='col-md-11'><img class=\"\" alt=\"\" src=\"$CFG->wwwroot/theme/image.php/boost/$moduleI->type/1/icon>\">
							// $moduleI->name </div> <div class='col-md-1'> $pictureC</div></div></h5></div></a>";
								echo "<a href='$moduleI->link' class='list-group-item'>$pictureC<img src='$CFG->wwwroot/theme/image.php/boost/$moduleI->type/1/icon>'>$moduleI->name</a>";
							}

							?>
						</div>
					</section>
				<?php endif; ?>
			</div>
		</div>

		<!-- Commentaires et historique -->
		<div class="row mt-3">

			<!-- Commentaires -->
			<div class="col-md-6">
				<section id="discussion" class="block_compet_param">
					<h2 class="title_blue">
						<?php try {
							echo get_string('discus', 'block_competency_iena');
						} catch (coding_exception $e) {
						} ?>
					</h2>
					<div class="block_compet_param commentaire" style="border: 1px solid #ccc; border-radius: 0.15rem; padding: 1rem; margin-bottom: 1rem;">
						<div class="more">
							<div data-region="comments" class="m-t-1">
								<div class="mdl-left" id="yui_3_17_2_1_1522940951276_214">
									<a style="cursor:pointer;" class="comment-link"
									id="comment-link-plancommentarea2" aria-expanded="false"
									onclick="toggle_comments();">
									<i class="icon fa fa-plus-square fa-fw " style="color:#1587bc;"
									aria-hidden="true" title="Commentaires" aria-label="Commentaires"></i>
									<span id="comment-link-text-plancommentarea1"><?php try {
										echo get_string('comment', 'block_competency_iena');
									} catch (coding_exception $e) {
									} ?>
									(<?php echo count($tab_comments); ?>)</span>
								</a>
								<div id="comment-ctrl-plancommentarea2" class="comment-ctrl"
								style="display: block;">
								<ul id="comment-list-plancommentarea2" class="comment-list"
								style="display: none;">
								<?php
								foreach ($tab_comments as $comment) {
									echo "
									<li id=\"comment-3-plancommentarea2\">
									<div class=\"comment-message\">
									<div class=\"comment-message-meta m-r-3\">
									<!-- <span class=\"picture\">
									<a href=\"" . $CFG->wwwroot . "/user/profile.php?id=" . $comment->idsender . "\">
									<img src=\"" . $CFG->wwwroot . "/theme/image.php/boost/core/1522839783/u/f2\" alt=\"\" title=\"\" class=\"userpicture defaultuserpic\" width=\"18\" height=\"18\">
									</a>
									</span> -->
									<span class=\"user\">
									<a href=\"" . $CFG->wwwroot . "/user/view.php?id=2&amp;course=" . $comment->idcourse . "\">";

									try {
										$the_sender = $DB->get_record_sql('select * FROM {user} WHERE id = ?', array($comment->idsender));
									} catch (dml_exception $e) {
									}
									echo $the_sender->firstname . " " . $the_sender->lastname .

									"</a>
									</span> - <span class=\"time\">"

									. date('d-m-Y H:i', $comment->date) .

									"</span>
									</div>
									<div class=\"text\"><div class=\"comment-delete\">
									<a  style=\"cursor:pointer;\" onclick=\"delete_comment(this);\" role=\"button\" id=\"" . $comment->id . "\" title=\"Supprimer le commentaire de " . $comment->idsender . " écrit le " . date('d/m/Y', $comment->date) . "\">
									<i class=\"icon fa fa-trash fa-fw \" aria-hidden=\"true\" title=\"Supprimer le commentaire de " . $comment->idsender . " écrit le " . date('d/m/Y', $comment->date) . "\" aria-label=\"Supprimer le commentaire de " . $comment->idsender . " écrit le " . date('d/m/Y', $comment->date) . "\"></i>
									</a>
									</div>
									<div class=\"no-overflow\">
									<div class=\"text_to_html\">" . $comment->message . "<br></div>
									</div>
									</div>
									</div>
									</li>
									<hr>";
								}
								?>
							</ul>
							<div class="">
								<textarea name="context" id="input_message" rows="2"
								class="w-100"></textarea>
								<div class="" id="">
									<button class='btn btn-primary mt-2' id="
									<?php
									try {
										if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
											if (!empty($_GET)) {
												echo "sender" . $USER->id . "-student" .$tmpiduser . "-course" . $_GET['courseid'] . "-competency" . $_GET['competencyid'];
											}
										} else {
											echo "sender" . $USER->id . "-student" . $USER->id . "-course" . $_GET['courseid'] . "-competency" . $_GET['competencyid'];
										}
									} catch (coding_exception $e) {
									}
									?>
									"
									onclick='write_comment(this)'><?php echo get_string('save_comment', 'block_competency_iena'); ?></button>
								</div>
							</div>
							<div class="clearer"></div>
						</div>
					</div>
				</div>

			</div>
		</section>
	</div>

	<!-- Historique de la compétence -->
	<div class="col-md-6">
		<section id="history" class="block_compet_param">
			<?php
			$data = $competency_instance->get_data($tmpiduser, $competencyid, $COURSE->id);
			$taille_proof = count($data->usercompetencysummary->evidence) * 12.5;
			$history_size = count($data->usercompetencysummary->evidence);
			if ($taille_proof > 25) {
				$taille_proof = 25;
			} 

			$usercomp_id = $this->get_usercomp_id($tmpiduser, $competencyid);

			if ( $usercomp_id != NULL ) {
				$complete_current_competency = core_competency\api::get_user_competency_by_id($usercomp_id);
					// $ccc = $complete_current_competency->get_competency();
					// $evidences = core_competency\api::list_user_evidence($tmpiduser);
				$apiCompSum = new \tool_lp\output\user_competency_summary($complete_current_competency);
				$dataSum = $apiCompSum->export_for_template(new renderer_base(new moodle_page(), 'autre'));
				$full_history_size = count($dataSum->evidence);

			} else {
				$full_history_size = 0;
			}

			?>

			<h2 class="title_blue"><?php echo "Historique complet" . " (" . $full_history_size . ")"; ?></h2>

			<?php if ($full_history_size != 0): ?>
				<!-- Penser au script pour la suppression ; ne permettre la suppression que si c'est dans le contexte du cours ? -->
				<div class="block_compet_param commentaire" id="proof_iena"
				style="max-height: 29rem; overflow: scroll; border: 1px solid #ccc; border-radius: 0.15rem; padding: 1rem; margin-bottom: 1rem;">
				<div class="entete">

					<?php

					foreach ($dataSum->evidence as $value) {
Thomas Fradet's avatar
Thomas Fradet committed
739
						/*echo "<div class=\"well well-small evidence\" id=\"proof_iena_id_$value->id\">*/
Thomas Fradet's avatar
folder  
Thomas Fradet committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
						echo "<div class=\"card card-block\" id=\"proof_iena_id_$value->id\">
						<div class=\"card-body\">
						<div class=\"pull-xs-right iena-cpt-abs-right\">
						<a href=\"#\" onclick='deleteProof(\"$value->id\",\"$COURSE->id\",\"$CFG->wwwroot\")' ><i class=\"icon fa fa-trash fa-fw \" aria-hidden=\"true\" aria-label=\"\"></i></a>
						</div>";
						if ($value->actionuserid != NULL) {
							echo "
							<div>
							<span>
							<a href=\"" . $value->actionuser->profileurl . "\" title=\"Consulter le profil\">
							<img height=\"18\" src=\"" . $value->actionuser->profileimageurlsmall . "\" alt=\"\" role=\"presentation\">
							<span>" . $value->actionuser->fullname . "</span>
							</a>
							</span>
							</div>";
						}
						echo "<strong><time>";
						date_default_timezone_set('Europe/Paris');
						echo strftime("%A %d %B %Y", $value->timemodified);
						echo "</time></strong>
						<p class='mb-0'><span class=\"tag tag-info\">$value->gradename</span></p>
						<p class='mb-0'>$value->description";
						if ($value->descidentifier == "evidence_coursemodulecompleted") {
							echo " <a href=\"$value->url\"> — Voir</a>";
						}
						echo "</p>";
						if ($value->note != NULL) {
							echo "<div class='alert alert-success'>$value->note</div>";
						}
						echo "</div></div>";
					} ?>
				</div>
			</div>
		<?php endif; ?>

		<h2 class="title_blue"><?php echo get_string('history_comp', 'block_competency_iena') . " (" . $history_size . ")"; ?></h2>

		<?php if ( $usercomp_id != NULL ): ?>
Thomas Fradet's avatar
Thomas Fradet committed
778
779
			<a target="_blank" href="<?php echo $CFG->wwwroot ?>/admin/tool/lp/user_competency.php?id=<?php echo $usercomp_id; ?>" class="btn btn-block btn-default m-y-1">Consulter les informations pour tous les cours</a>
		<?php endif; ?>
Thomas Fradet's avatar
folder  
Thomas Fradet committed
780

Thomas Fradet's avatar
Thomas Fradet committed
781
		<?php if ($history_size != 0): ?>
Thomas Fradet's avatar
folder  
Thomas Fradet committed
782
783
784
785
786
787
788
			<!-- height: < ? p h p echo $taille_proof ?>rem; -->
			<div class="block_compet_param commentaire" id="proof_iena"
			style="max-height: 29rem; overflow: scroll; border: 1px solid #ccc; border-radius: 0.15rem; padding: 1rem; margin-bottom: 1rem;">
			<div class="entete">

				<?php
				foreach ($data->usercompetencysummary->evidence as $value) {
Thomas Fradet's avatar
Thomas Fradet committed
789
790

					/*echo "<div class=\"well well-small evidence\" id=\"proof_iena_id_$value->id\">*/
Thomas Fradet's avatar
folder  
Thomas Fradet committed
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
					echo "<div class=\"card card-block\" id=\"proof_iena_id_$value->id\">
					<div class=\"card-body\">
					<div class=\"pull-xs-right iena-cpt-abs-right\">
					<a href=\"#\" onclick='deleteProof(\"$value->id\",\"$COURSE->id\",\"$CFG->wwwroot\")' ><i class=\"icon fa fa-trash fa-fw \" aria-hidden=\"true\" aria-label=\"\"></i></a>
					</div>";
					if ($value->actionuserid != NULL) {
						echo "
						<div>
						<span>
						<a href=\"" . $value->actionuser->profileurl . "\" title=\"Consulter le profil\">
						<img height=\"18\" src=\"" . $value->actionuser->profileimageurlsmall . "\" alt=\"\" role=\"presentation\">
						<span>" . $value->actionuser->fullname . "</span>
						</a>
						</span>
						</div>";
					}
					echo "<strong><time>";
					date_default_timezone_set('Europe/Paris');
					echo strftime("%A %d %B %Y", $value->timemodified);
					echo "</time></strong>
					<p class='mb-0'><span class=\"tag tag-info\">$value->gradename</span></p>
					<p class='mb-0'>$value->description";
					if ($value->descidentifier == "evidence_coursemodulecompleted") {
						echo " <a href=\"$value->url\"> — Voir</a>";
					}
					echo "</p>";
					if ($value->note != NULL) {
						echo "<div class='alert alert-success'>$value->note</div>";
					}
					echo "</div></div>";
				} ?>

			</div>
		</div>
Thomas Fradet's avatar
Thomas Fradet committed
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
	<?php endif; ?>
</section>
</div>

</div>
</div>


<script>

	function delete_comment(obj) {
		var url = window.location.href;

		var t = obj.parentNode.parentNode.parentNode.parentNode;
		var info = [];
		info[0] = "delete";
		info[1] = obj.id;

		$.ajax({
			type: "POST",
			data: {info: info},
			url: url,
			timeout: 10000,
			contentType: 'application/x-www-form-urlencoded',
			success: function (data, status) {
				if (status == "success") {
Thomas Fradet's avatar
Thomas Fradet committed
851
852
					// console.log(status);
					// console.log(data);
Thomas Fradet's avatar
Thomas Fradet committed
853
					location.reload();
Thomas Fradet's avatar
folder  
Thomas Fradet committed
854
				}
Thomas Fradet's avatar
Thomas Fradet committed
855
856
857
858
859
			},
			error: function (xhr, status, error) {
				alert(status);
			}
		});
Thomas Fradet's avatar
folder  
Thomas Fradet committed
860
861


Thomas Fradet's avatar
Thomas Fradet committed
862
	}
Thomas Fradet's avatar
folder  
Thomas Fradet committed
863

Thomas Fradet's avatar
Thomas Fradet committed
864
865
866
	function toggle_comments() {
		if (document.getElementById("comment-list-plancommentarea2").style.display === 'none') {
			document.getElementById("comment-list-plancommentarea2").style.display = 'block';
Thomas Fradet's avatar
folder  
Thomas Fradet committed
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
				// console.log(document.getElementById("comment-list-plancommentarea2").style.display);
			} else {
				document.getElementById("comment-list-plancommentarea2").style.display = 'none';
			}
		}

		function AskValide(competencyID, userId, value, idcourse,wwwroot){
			$("#show-valide").toggle();
			$("#cancel-valide").toggle();
			console.log(competencyID,userId);
			$.ajax({
				url:  wwwroot+'/blocks/competency_iena/competency_iena_competencies_api.php?courseid='+idcourse,
				type: 'POST',
				timeout: 20000,
				contentType: 'application/x-www-form-urlencoded',
				data: {askvalide:value,askidcomp:competencyID,iduser:userId},
				success: function(result) {
				}
			});
		}

		function write_comment(obj) {
			var url = window.location.href;
Thomas Fradet's avatar
Thomas Fradet committed
890
			// console.log(url);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
891
			var input_message_id = obj.id;
Thomas Fradet's avatar
Thomas Fradet committed
892
			// console.log(input_message_id);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
893
894
			var idsender = input_message_id.split('-')[0];
			idsender = idsender.replace(/[^\d.]/g, '');
Thomas Fradet's avatar
Thomas Fradet committed
895
			// console.log(idsender);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
896
897
			var idstudent = input_message_id.split('-')[1];
			idstudent = idstudent.replace(/[^\d.]/g, '');
Thomas Fradet's avatar
Thomas Fradet committed
898
			// console.log(idstudent);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
899
900
			var idcourse = input_message_id.split('-')[2];
			idcourse = idcourse.replace(/[^\d.]/g, '');
Thomas Fradet's avatar
Thomas Fradet committed
901
			// console.log(idcourse);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
902
903
			var idcompetency = input_message_id.split('-')[3];
			idcompetency = idcompetency.replace(/[^\d.]/g, '');
Thomas Fradet's avatar
Thomas Fradet committed
904
			// console.log(idcompetency);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
905
			var message = document.getElementById("input_message").value;
Thomas Fradet's avatar
Thomas Fradet committed
906
			// console.log(message);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
907
			var date = new Date().getTime() / 1000;
Thomas Fradet's avatar
Thomas Fradet committed
908
			// console.log(date);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926

			var info = [];
			info[0] = "insert";
			info[1] = idsender;
			info[2] = idstudent;
			info[3] = idcourse;
			info[4] = idcompetency;
			info[5] = message;
			/* info[6] = date; */

			$.ajax({
				type: "POST",
				data: {info: info},
				url: url,
				timeout: 10000,
				contentType: 'application/x-www-form-urlencoded',
				success: function (data, status) {
					if (status == "success") {
Thomas Fradet's avatar
Thomas Fradet committed
927
928
						// console.log(status);
						// console.log(data);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
						location.reload();
					}

				},
				error: function (xhr, status, error) {
					alert(status);
				}
			});
		}

		$(document).ready(function () {
			/* $('#cancel-valide').hide(); */
			$('#eval-hide').hide();
			$('#eval-show').click(function () {
				$('#eval-show').hide();
				$('#eval-hide').toggle();
			});

			$('#btn-eval').click(function () {
				$('#eval-hide').toggle();
				$('#eval-show').show();
				$.ajax({
					url: $("#wwwroot_iena").val() + '/blocks/competency_iena/' +
					'competency_iena_competencies_api.php?courseid=' + $("#courseid_iena").val(),
					type: 'POST',
					timeout: 30000,
					contentType: 'application/x-www-form-urlencoded',
					data: {
						eval_comp: $("#slc-eval").val(),
						userid : $("#iduser_iena").val(), 
						compid : $("#compid_iena").val(), 
						eval_comp_note: "Evaluation données dans le cours « <?php echo $COURSE->fullname ?> » par <?php echo( $USER->firstname . " " . $USER->lastname ) ?>. " + $("#slc-eval-note").val()
					},
					success: function (result) {
						location.reload();
					}
				});
			});

			/*$('.wrapper').find('a[href="#"]').on('click', function (e) {
				e.preventDefault();
				this.expand = !this.expand;
				$(this).text(this.expand ? "Réduire" : "Voir la description compléte");
				$(this).closest('.wrapper').find('.small, .big').toggleClass('small big');
			});*/

			$('#extand_iena_proof').click(function () {
				$('#proof_iena').css('overflow', 'visible');
				$('#proof_iena').css('height', 'auto');
				$('#extand_iena_proof').hide();
			});

			$("#myCompetencyBrowser").on('input', function () {
				var val = this.value;
				if ($('#competency_browser option').filter(function () {
					return this.value === val;
				}).length) {
					var value3send = document.querySelector("#competency_browser option[value='" + this.value + "']").dataset.value;
					window.location.replace(value3send);
				}
			});



			// $("#student_browser").on('click', function (e) {
			// 	console.log(e)
			// 	console.log("e")

			// });

			$("#myStudentBrowser").on('input', function (e) {

				var student_list = document.querySelectorAll('#student_browser option');
				for ( var i = 0; i < student_list.length; i++ ) {
					if ( student_list[i].dataset.studid == document.getElementById('myStudentBrowser').value ) {
						window.location.replace(student_list[i].dataset.value);
					}
				}

				/*var val = this.value;*/
				/* Si l'élément sélectionné dans la datalist est dans la datalist... */
				/*if ( $('#student_browser option').filter(function () {
					return this.value === val;
				}).length ) {
					var value2send = document.querySelector("#student_browser option[value='" + this.value + "']").dataset.value;
					window.location.replace(value2send);
				}*/
			});

			/* Change d'URL pour passer à l'étudiant suivant, basé sur la datalist des étudiants et l'étudiant actuel dans l'input. */
			document.getElementById('next_student').addEventListener('click', function (e) {
				var student_list = document.querySelectorAll('#student_browser option');
				for ( var i = 0; i < student_list.length; i++ ) {
					if ( student_list[i].dataset.studid == document.getElementById('myStudentBrowser').dataset.studid ) {
						if ( i+1 < student_list.length ) {
							window.location.replace(student_list[i+1].dataset.value);
						} else {
							e.target.style.display = 'none';
						}
					}
				}
			});
			/* Change d'URL pour passer à l'étudiant précédent, basé sur la datalist des étudiants et l'étudiant actuel dans l'input. */
			document.getElementById('prev_student').addEventListener('click', function (e) {
				var student_list = document.querySelectorAll('#student_browser option');
				for ( var i = 0; i < student_list.length; i++ ) {
					if ( student_list[i].dataset.studid == document.getElementById('myStudentBrowser').dataset.studid ) {
						if ( i-1 >= 0 ) {
							window.location.replace(student_list[i-1].dataset.value);
						} else {
							e.target.style.display = 'none';
						}
					}
				}
			});

		});

		function show_parag() {
			if (document.getElementById("AffichePlusInfos").innerHTML == 'Réduire') {
				document.getElementById("AffichePlusInfos").innerHTML = 'Afficher plus d\'informations';
				document.getElementById("parag").classList.add('para_descript');
			}
			else {
				document.getElementById("AffichePlusInfos").innerHTML = 'Réduire';
				document.getElementById("parag").classList.remove('para_descript');
			}
		}

		function deleteProof(value, idcourse, wwwroot) {
			console.log(value);
			$.ajax({
				url: wwwroot + '/blocks/competency_iena/competency_iena_competencies_api.php?courseid=' + idcourse,
				type: 'POST',
				timeout: 10000,
				contentType: 'application/x-www-form-urlencoded',
				data: {delproof: value},
				success: function (result) {
					$('#proof_iena_id_' + value).hide();
				}
			});
		}


	</script>

	<?php
}
}

?>