Project

General

Profile

Bug #2027 » exercice.php

Yannick Warnier, 21/10/2010 20:42

 
1
<?php
2
/* For licensing terms, see /license.txt */
3

    
4
/**
5
*	Exercise list: This script shows the list of exercises for administrators and students.
6
*	@package chamilo.exercise
7
*	@author Olivier Brouckaert, original author
8
*	@author Denes Nagy, HotPotatoes integration
9
*	@author Wolfgang Schneider, code/html cleanup
10
*	@author Julio Montoya <gugli100@gmail.com>, lots of cleanup + several improvements
11
* 	@version $Id:exercice.php 12269 2007-05-03 14:17:37Z elixir_julian $
12
*/
13

    
14
// name of the language file that needs to be included
15
$language_file = 'exercice';
16

    
17
// including the global library
18
require_once '../inc/global.inc.php';
19
require_once api_get_path(LIBRARY_PATH).'sortabletable.class.php';
20
require_once '../gradebook/lib/be.inc.php';
21
// setting the tabs
22
$this_section = SECTION_COURSES;
23

    
24
// access control
25
api_protect_course_script(true);
26

    
27
$show = (isset ($_GET['show']) && $_GET['show'] == 'result') ? 'result' : 'test'; // moved down to fix bug: http://www.dokeos.com/forum/viewtopic.php?p=18609#18609
28

    
29
// including additional libraries
30
require_once 'exercise.class.php';
31
require_once 'question.class.php';
32
require_once 'answer.class.php';
33
require_once api_get_path(LIBRARY_PATH) . 'fileManage.lib.php';
34
require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
35
require_once 'hotpotatoes.lib.php';
36
require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
37
require_once api_get_path(LIBRARY_PATH) . 'mail.lib.inc.php';
38
require_once api_get_path(LIBRARY_PATH) . 'usermanager.lib.php';
39

    
40
/*
41
	Constants and variables
42
*/
43
$is_allowedToEdit 			= api_is_allowed_to_edit(null,true);
44
$is_tutor 					= api_is_allowed_to_edit(true);
45
$is_tutor_course 			= api_is_course_tutor();
46
$tbl_course_rel_user		= Database :: get_main_table(TABLE_MAIN_COURSE_USER);
47
$TBL_USER 					= Database :: get_main_table(TABLE_MAIN_USER);
48
$TBL_DOCUMENT 				= Database :: get_course_table(TABLE_DOCUMENT);
49
$TBL_ITEM_PROPERTY 			= Database :: get_course_table(TABLE_ITEM_PROPERTY);
50
$TBL_EXERCICE_ANSWER 		= Database :: get_course_table(TABLE_QUIZ_ANSWER);
51
$TBL_EXERCICE_QUESTION 		= Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
52
$TBL_EXERCICES 				= Database :: get_course_table(TABLE_QUIZ_TEST);
53
$TBL_QUESTIONS 				= Database :: get_course_table(TABLE_QUIZ_QUESTION);
54
$TBL_TRACK_EXERCICES 		= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
55
$TBL_TRACK_HOTPOTATOES 		= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
56
$TBL_TRACK_ATTEMPT 			= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
57
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
58
$TBL_LP_ITEM_VIEW 			= Database :: get_course_table(TABLE_LP_ITEM_VIEW);
59
$TBL_LP_ITEM 				= Database :: get_course_table(TABLE_LP_ITEM);
60
$TBL_LP_VIEW 				= Database :: get_course_table(TABLE_LP_VIEW);
61

    
62
// document path
63
$documentPath = api_get_path(SYS_COURSE_PATH) . $_course['path'] . "/document";
64
// picture path
65
$picturePath = $documentPath . '/images';
66
// audio path
67
$audioPath = $documentPath . '/audio';
68

    
69
// hotpotatoes
70
$uploadPath = DIR_HOTPOTATOES; //defined in main_api
71
$exercicePath = api_get_self();
72
$exfile = explode('/', $exercicePath);
73
$exfile = strtolower($exfile[sizeof($exfile) - 1]);
74
$exercicePath = substr($exercicePath, 0, strpos($exercicePath, $exfile));
75
$exercicePath = $exercicePath . "exercice.php";
76

    
77
// maximum number of exercises on a same page
78
$limitExPage = 50;
79

    
80
// Clear the exercise session
81
if (isset ($_SESSION['objExercise'])) {
82
	api_session_unregister('objExercise');
83
}
84
if (isset ($_SESSION['objQuestion'])) {
85
	api_session_unregister('objQuestion');
86
}
87
if (isset ($_SESSION['objAnswer'])) {
88
	api_session_unregister('objAnswer');
89
}
90
if (isset ($_SESSION['questionList'])) {
91
	api_session_unregister('questionList');
92
}
93
if (isset ($_SESSION['exerciseResult'])) {
94
	api_session_unregister('exerciseResult');
95
}
96

    
97

    
98
//general POST/GET/SESSION/COOKIES parameters recovery
99
if (empty ($origin)) {
100
	$origin = Security::remove_XSS($_REQUEST['origin']);
101
}
102
if (empty ($choice)) {
103
	$choice = $_REQUEST['choice'];
104
}
105
if (empty ($hpchoice)) {
106
	$hpchoice = $_REQUEST['hpchoice'];
107
}
108
if (empty ($exerciseId)) {
109
	$exerciseId = Database :: escape_string($_REQUEST['exerciseId']);
110
}
111
if (empty ($file)) {
112
	$file = Database :: escape_string($_REQUEST['file']);
113
}
114
$learnpath_id = Database :: escape_string(Security::remove_XSS($_REQUEST['learnpath_id']));
115
$learnpath_item_id = Database :: escape_string(Security::remove_XSS($_REQUEST['learnpath_item_id']));
116
$page = Database :: escape_string($_REQUEST['page']);
117

    
118
if ($origin == 'learnpath') {
119
	$show = 'result';
120
}
121

    
122
if ($_GET['delete'] == 'delete' && ($is_allowedToEdit || api_is_coach()) && !empty ($_GET['did']) && $_GET['did'] == strval(intval($_GET['did']))) {
123
	$sql = 'DELETE FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES) . ' WHERE exe_id = ' . $_GET['did']; //_GET[did] filtered by entry condition
124
	Database::query($sql);
125
	$filter=Security::remove_XSS($_GET['filter']);
126
	header('Location: exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '');
127
	exit;
128
}
129

    
130
if ($show == 'result' && $_REQUEST['comments'] == 'update' && ($is_allowedToEdit || $is_tutor) && $_GET['exeid']== strval(intval($_GET['exeid']))) {
131
	$id 		= intval($_GET['exeid']); //filtered by post-condition
132
	$emailid 	= $_GET['emailid'];
133
	$test 		= $_GET['test'];
134
	$from 		= $_SESSION['_user']['mail'];
135
	$from_name  = api_get_person_name($_SESSION['_user']['firstName'], $_SESSION['_user']['lastName'], null, PERSON_NAME_EMAIL_ADDRESS);
136
	$url		= api_get_path(WEB_CODE_PATH) . 'exercice/exercice.php?' . api_get_cidreq() . '&show=result';
137
	$TBL_RECORDING = Database :: get_statistic_table('track_e_attempt_recording');
138
	$total_weighting = $_REQUEST['totalWeighting'];
139

    
140
	$my_post_info=array();
141
	$post_content_id=array();
142
	$comments_exist=false;
143
	foreach ($_POST as $key_index=>$key_value) {
144
		$my_post_info=explode('_',$key_index);
145
		$post_content_id[]=$my_post_info[1];
146
		if ($my_post_info[0]=='comments') {
147
			$comments_exist=true;
148
		}
149
	}
150

    
151
	$loop_in_track=($comments_exist===true) ? (count($_POST)/2) : count($_POST);
152
	$array_content_id_exe=array();
153
	if ($comments_exist===true) {
154
		$array_content_id_exe=array_slice($post_content_id,$loop_in_track);
155
	} else {
156
		$array_content_id_exe=$post_content_id;
157
	}
158

    
159

    
160
	for ($i=0;$i<$loop_in_track;$i++) {
161

    
162
		$my_marks=Database::escape_string($_POST['marks_'.$array_content_id_exe[$i]]);
163

    
164
		$contain_comments=Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
165

    
166
		if (isset($contain_comments)) {
167
			$my_comments=Database::escape_string($_POST['comments_'.$array_content_id_exe[$i]]);
168
		} else {
169
			$my_comments='';
170
		}
171
		$my_questionid=$array_content_id_exe[$i];
172
		$sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'";
173
		$result =Database::query($sql);
174
		$ques_name = Database::result($result,0,"question");
175

    
176
		$query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '$my_marks',teacher_comment = '$my_comments'
177
				  WHERE question_id = '".$my_questionid."'
178
				  AND exe_id='".$id."'";
179

    
180
		Database::query($query);
181

    
182
		$qry = 'SELECT sum(marks) as tot
183
				FROM '.$TBL_TRACK_ATTEMPT.' WHERE exe_id = '.$id.'
184
				GROUP BY question_id';
185

    
186
		$res = Database::query($qry);
187
		$tot = Database::result($res,0,'tot');
188
		//updating also the total weight
189
		$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '".Database::escape_string($tot)."', exe_weighting = '".Database::escape_string($total_weighting)."'
190
					 WHERE exe_Id='".$id."'";
191
		Database::query($totquery);
192
		$recording_changes = 'INSERT INTO '.$TBL_RECORDING.' ' .
193
				'(exe_id,
194
				question_id,
195
				marks,
196
				insert_date,
197
				author,
198
				teacher_comment)
199
				VALUES
200
				('."'$id','".$my_questionid."','$my_marks','".date('Y-m-d H:i:s')."','".api_get_user_id()."'".',"'.$my_comments.'")';
201
		Database::query($recording_changes);
202
	}
203

    
204
	$post_content_id=array();
205
	$array_content_id_exe=array();
206
	/*foreach ($_POST as $key => $v) {
207
		$keyexp = explode('_', $key);
208

    
209
		$id = Database :: escape_string($id);
210
		$v = Database :: escape_string($v);
211
		$my_questionid = Database :: escape_string($keyexp[1]);
212

    
213
		if ($keyexp[0] == "marks") {
214
			$sql = "SELECT question from $TBL_QUESTIONS WHERE id = '$my_questionid'";
215
			$result = Database::query($sql);
216
			$ques_name = Database :: result($result, 0, "question");
217

    
218
			$query = "UPDATE $TBL_TRACK_ATTEMPT SET marks = '" . $v . "'
219
								  WHERE question_id = '" . $my_questionid . "'
220
								  AND exe_id='" . $id . "'";
221
			Database::query($query);
222

    
223
			$qry = 'SELECT sum(marks) as tot
224
								FROM ' . $TBL_TRACK_ATTEMPT . ' WHERE exe_id = ' . intval($id) . '
225
								GROUP BY question_id';
226

    
227
			$res = Database::query($qry);
228
			$tot = Database :: result($res, 0, 'tot');
229
			//updating also the total weight
230
			$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . Database :: escape_string($tot) . "', exe_weighting = '" . Database :: escape_string($total_weighting) . "'
231
									 WHERE exe_Id='" . Database :: escape_string($id) . "'";
232

    
233
			Database::query($totquery);
234

    
235
			$recording_changes = 'INSERT INTO ' . $TBL_RECORDING . ' ' .
236
			'(exe_id,
237
								question_id,
238
								marks,
239
								insert_date,
240
								author)
241
								VALUES
242
								(' . "'$id','" . $my_questionid . "','$v','" . date('Y-m-d H:i:s') . "','" . api_get_user_id() . "'" . ')';
243
			Database::query($recording_changes);
244
		} else {
245
			$query = "UPDATE $TBL_TRACK_ATTEMPT SET teacher_comment = '" . $v . "'
246
					  			WHERE question_id = '" . $my_questionid . "'
247
					  			AND exe_id = '" . $id . "'";
248
			Database::query($query);
249

    
250
			$recording_changes = 'INSERT INTO ' . $TBL_RECORDING . ' ' .
251
			'(exe_id,
252
								question_id,
253
								teacher_comment,
254
								insert_date,
255
								author)
256
								VALUES
257
								(' . "'$id','" . $my_questionid . "','$v','" . date('Y-m-d H:i:s') . "','" . api_get_user_id() . "'" . ')';
258
			Database::query($recording_changes);
259
		}
260
	}*/
261

    
262
	$qry = 'SELECT DISTINCT question_id, marks
263
			FROM ' . $TBL_TRACK_ATTEMPT . ' where exe_id = ' . intval($id) . '
264
			GROUP BY question_id';
265

    
266
	$res = Database::query($qry);
267
	$tot = 0;
268
	while ($row = Database :: fetch_array($res, 'ASSOC')) {
269
		$tot += $row['marks'];
270
	}
271

    
272
	$totquery = "UPDATE $TBL_TRACK_EXERCICES SET exe_result = '" . Database :: escape_string($tot) . "' WHERE exe_Id='" . Database :: escape_string($id) . "'";
273

    
274
	//search items
275
	if (isset($_POST['my_exe_exo_id']) && isset($_POST['student_id'])) {
276
		$sql_lp='SELECT li.id as lp_item_id,li.lp_id,li.item_type,li.path,liv.id AS lp_view_id,liv.user_id,max(liv.view_count) AS view_count FROM '.$TBL_LP_ITEM.' li
277
		INNER JOIN '.$TBL_LP_VIEW.' liv ON li.lp_id=liv.lp_id WHERE li.path="'.Database::escape_string($_POST['my_exe_exo_id']).'" AND li.item_type="quiz" AND user_id="'.Database::escape_string($_POST['student_id']).'" ';
278
		$rs_lp=Database::query($sql_lp);
279
		if (!($rs_lp===false)) {
280
			$row_lp=Database::fetch_array($rs_lp);
281
			//update score in learnig path
282
			$sql_lp_view='UPDATE '.$TBL_LP_ITEM_VIEW.' liv SET score ="'.$tot.'" WHERE liv.lp_item_id="'.(int)$row_lp['lp_item_id'].'" AND liv.lp_view_id="'.(int)$row_lp['lp_view_id'].'" AND liv.view_count="'.(int)$row_lp['view_count'].'" ;';
283
			$rs_lp_view=Database::query($sql_lp_view);
284
		}
285
	}
286
	Database::query($totquery);
287

    
288
	$subject = get_lang('ExamSheetVCC');
289
	$htmlmessage = '<html>' .
290
	'<head>' .
291
	'<style type="text/css">' .
292
	'<!--' .
293
	'.body{' .
294
	'font-family: Verdana, Arial, Helvetica, sans-serif;' .
295
	'font-weight: Normal;' .
296
	'color: #000000;' .
297
	'}' .
298
	'.style8 {font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: bold; color: #006699; }' .
299
	'.style10 {' .
300
	'	font-family: Verdana, Arial, Helvetica, sans-serif;' .
301
	'	font-size: 12px;' .
302
	'	font-weight: bold;' .
303
	'}' .
304
	'.style16 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }' .
305
	'-->' .
306
	'</style>' .
307
	'</head>' .
308
	'<body>' .
309
	'<div>' .
310
	'  <p>' . get_lang('DearStudentEmailIntroduction') . '</p>' .
311
	'  <p class="style10"> ' . get_lang('AttemptVCC') . ' </p>' .
312
	'  <table width="417">' .
313
	'    <tr>' .
314
	'      <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Question') . '</span></td>' .
315
	'      <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#ques_name#</span></td>' .
316
	'    </tr>' .
317
	'    <tr>' .
318
	'      <td width="229" valign="top" bgcolor="E5EDF8">&nbsp;&nbsp;<span class="style10">' . get_lang('Exercice') . '</span></td>' .
319
	'       <td width="469" valign="top" bgcolor="#F3F3F3"><span class="style16">#test#</span></td>' .
320
	'    </tr>' .
321
	'  </table>' .
322
	'  <p>' . get_lang('ClickLinkToViewComment') . ' <a href="#url#">#url#</a><br />' .
323
	'    <br />' .
324
	'  ' . get_lang('Regards') . ' </p>' .
325
	'  </div>' .
326
	'  </body>' .
327
	'  </html>';
328
	$message = '<p>' . sprintf(get_lang('AttemptVCCLong'), Security::remove_XSS($test)) . ' <A href="#url#">#url#</A></p><br />';
329
	$mess = str_replace("#test#", Security::remove_XSS($test), $message);
330
	//$message= str_replace("#ques_name#",$ques_name,$mess);
331
	$message = str_replace("#url#", $url, $mess);
332
	$mess = $message;
333
	$headers = " MIME-Version: 1.0 \r\n";
334
	$headers .= "User-Agent: Dokeos/1.6";
335
	$headers .= "Content-Transfer-Encoding: 7bit";
336
	$headers .= 'From: ' . $from_name . ' <' . $from . '>' . "\r\n";
337
	$headers = "From:$from_name\r\nReply-to: $to";
338
	//mail($emailid, $subject, $mess,$headers);
339

    
340
	@api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
341
	if (in_array($origin, array ('tracking_course','user_course'))) {
342

    
343
		if (isset ($_POST['lp_item_id']) && isset ($_POST['lp_item_view_id']) && isset ($_POST['student_id']) && isset ($_POST['total_score']) && isset ($_POST['total_time']) && isset ($_POST['totalWeighting'])) {
344
			$lp_item_id = $_POST['lp_item_id'];
345
			$lp_item_view_id = $_POST['lp_item_view_id'];
346
			$student_id = $_POST['student_id'];
347
			$totalWeighting = $_POST['totalWeighting'];
348

    
349
			if ($lp_item_id == strval(intval($lp_item_id)) && $lp_item_view_id == strval(intval($lp_item_view_id)) && $student_id == strval(intval($student_id))) {
350

    
351
				$score = Database :: escape_string($_POST['total_score']); //This is the new note
352
				$total_time = Database :: escape_string($_POST['total_time']);
353

    
354
				//I need the lp_item_view_id in order to update the record
355

    
356
				//@todo add the lp_item_view_id in the track_exercise table in order to have a real match between the lp_item_view and the track_exercise
357

    
358
				//$my_real_lp_item_view_id = Database :: escape_string($_POST['real_lp_item_view_id']);
359

    
360
				$lp_item_id 	 = Database :: escape_string($lp_item_id);
361
				$lp_item_view_id = Database :: escape_string($lp_item_view_id);
362
				$student_id		 = Database :: escape_string($student_id);
363
				$totalWeighting  = Database :: escape_string($totalWeighting);
364

    
365
				/*
366
				$sql = "SELECT (view_count) FROM $TBL_LP_ITEM_VIEW
367
						WHERE lp_item_id = '" . (int) $lp_item_view_id . "' AND lp_view_id = $my_real_lp_item_view_id ORDER BY id DESC LIMIT 1";
368
				$res_view_count = Database::query($sql);
369
				$res_view_count = Database :: fetch_row($res_view_count);
370
				$my_view_count =  intval($res_view_count[0]);
371
				*/
372

    
373
				//Checking if this is the lastest attempt
374
				$sql = "SELECT exe_id FROM $TBL_TRACK_EXERCICES
375
						WHERE exe_user_id = '" . Database :: escape_string($_POST['student_id']) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND orig_lp_id = '$lp_item_id' AND orig_lp_item_id =  '$lp_item_view_id'  AND session_id =  '" . api_get_session_id() . "' AND status = ''
376
						ORDER BY exe_id DESC LIMIT 1 ";
377
				$res_view_count = Database::query($sql);
378
				$res_view_count = Database :: fetch_row($res_view_count);
379
				$my_view_count =  intval($res_view_count[0]);
380

    
381
				//Update lp_item_view if this attempts is the latest
382
				$sql = "SELECT MAX(view_count) FROM $TBL_LP_ITEM_VIEW
383
						WHERE lp_item_id = '" . (int) $lp_item_view_id . "' AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "')";
384
				$res_max_view_count = Database::query($sql);
385
				$row_max_view_count = Database :: fetch_row($res_max_view_count);
386
				$max_view_count =  intval($row_max_view_count[0]);
387

    
388
				//Only update if is the last attempt
389
				if ($my_view_count == $_GET['exeid']) {
390
					// update score and total_time from last attempt when you qualify the exercise in Learning path detail
391
					$sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . intval($tot) . "' WHERE lp_item_id = '" . (int) $lp_item_view_id . "'
392
					    					AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "') AND view_count = '$max_view_count'";
393
					Database::query($sql_update_score);
394
				}
395

    
396
				/*
397
				/*
398
				// update score and total_time from last attempt when you qualify the exercise in Learning path detail
399
				$sql_update_score = "UPDATE $TBL_LP_ITEM_VIEW SET score = '" . (float) $score . "',total_time = '" . (int) $total_time . "' WHERE lp_item_id = '" . (int) $lp_item_view_id . "'
400
				    					AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '" . (int) $student_id . "' and lp_id='" . (int) $lp_item_id . "') AND view_count = '$max_view_count'";
401
				Database::query($sql_update_score);*/
402

    
403
				// update max_score from a exercise in lp
404
				//$sql_update_max_score = "UPDATE $TBL_LP_ITEM SET max_score = '" . (float) $totalWeighting . "'  WHERE id = '" . (int) $lp_item_view_id . "'";
405

    
406
				//Database::query($sql_update_max_score);
407

    
408
			}
409
		}
410
		if ($origin == 'tracking_course' && !empty($_POST['lp_item_id'])) {
411
			//Redirect to the course detail in lp
412
			header('location: ../mySpace/lp_tracking.php?course=' . Security :: remove_XSS($_GET['course']) . '&origin=' . $origin . '&lp_id=' . Security :: remove_XSS($_POST['lp_item_id']) . '&student_id=' . Security :: remove_XSS($_GET['student']).'&from='.Security::remove_XSS($_GET['from']));
413
			exit;
414
		} else {
415
			//Redirect to the reporting
416
			header('location: ../mySpace/myStudents.php?origin=' . $origin . '&student=' . Security :: remove_XSS($_GET['student']) . '&details=true&course=' . Security :: remove_XSS($_GET['course']));
417
			exit;
418
		}
419
	}
420
}
421

    
422
if (!empty($_GET['gradebook']) && $_GET['gradebook']=='view' ) {
423
	$_SESSION['gradebook']=Security::remove_XSS($_GET['gradebook']);
424
	$gradebook=	$_SESSION['gradebook'];
425
} elseif (empty($_GET['gradebook'])) {
426
	unset($_SESSION['gradebook']);
427
	$gradebook=	'';
428
}
429

    
430
if (!empty($gradebook) && $gradebook=='view') {
431
	$interbreadcrumb[] = array (
432
		'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
433
		'name' => get_lang('ToolGradebook')
434
	);
435
}
436

    
437
if ($show != 'result') {
438
	$nameTools = get_lang('Exercices');
439
} else {
440
	if ($is_allowedToEdit || $is_tutor) {
441
		$nameTools = get_lang('StudentScore');
442
		$interbreadcrumb[] = array (
443
			"url" => "exercice.php?gradebook=$gradebook",
444
			"name" => get_lang('Exercices')
445
		);
446
	} else {
447
		$nameTools = get_lang('YourScore');
448
		$interbreadcrumb[] = array (
449
			"url" => "exercice.php?gradebook=$gradebook",
450
			"name" => get_lang('Exercices')
451
		);
452
	}
453
}
454

    
455
// need functions of statsutils lib to display previous exercices scores
456
require_once (api_get_path(LIBRARY_PATH) . 'statsUtils.lib.inc.php');
457

    
458
if ($is_allowedToEdit && !empty ($choice) && $choice == 'exportqti2') {
459
	require_once 'export/qti2/qti2_export.php';
460
	$export = export_exercise($exerciseId, true);
461

    
462
	require_once api_get_path(LIBRARY_PATH) . 'pclzip/pclzip.lib.php';
463
	$archive_path = api_get_path(SYS_ARCHIVE_PATH);
464
	$temp_dir_short = uniqid();
465
	$temp_zip_dir = $archive_path . "/" . $temp_dir_short;
466
	if (!is_dir($temp_zip_dir))
467
		mkdir($temp_zip_dir, api_get_permissions_for_new_directories());
468
	$temp_zip_file = $temp_zip_dir . "/" . md5(time()) . ".zip";
469
	$temp_xml_file = $temp_zip_dir . "/qti2export_" . $exerciseId . '.xml';
470
	file_put_contents($temp_xml_file, $export);
471
	$zip_folder = new PclZip($temp_zip_file);
472
	$zip_folder->add($temp_xml_file, PCLZIP_OPT_REMOVE_ALL_PATH);
473
	$name = 'qti2_export_' . $exerciseId . '.zip';
474

    
475
	//DocumentManager::string_send_for_download($export,true,'qti2export_'.$exerciseId.'.xml');
476
	DocumentManager :: file_send_for_download($temp_zip_file, true, $name);
477
	unlink($temp_zip_file);
478
	unlink($temp_xml_file);
479
	rmdir($temp_zip_dir);
480
	exit (); //otherwise following clicks may become buggy
481
}
482
if (!empty ($_POST['export_user_fields'])) {
483
	switch ($_POST['export_user_fields']) {
484
		case 'export_user_fields' :
485
			$_SESSION['export_user_fields'] = true;
486
			break;
487
		case 'do_not_export_user_fields' :
488
		default :
489
			$_SESSION['export_user_fields'] = false;
490
			break;
491
	}
492
}
493
if (!empty ($_POST['export_report']) && $_POST['export_report'] == 'export_report') {
494
	if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
495
		$user_id = null;
496
		if (empty ($_SESSION['export_user_fields']))
497
			$_SESSION['export_user_fields'] = false;
498
		if (!$is_allowedToEdit and !$is_tutor) {
499
			$user_id = api_get_user_id();
500
		}
501
		require_once ('exercise_result.class.php');
502
		switch ($_POST['export_format']) {
503
			case 'xls' :
504
				$export = new ExerciseResult();
505
				$export->exportCompleteReportXLS($documentPath, $user_id, $_SESSION['export_user_fields'], $_POST['export_filter']);
506
				exit;
507
				break;
508
			case 'csv' :
509
			default :
510
				$export = new ExerciseResult();
511
				$export->exportCompleteReportCSV($documentPath, $user_id, $_SESSION['export_user_fields']);
512
				exit;
513
				break;
514
		}
515
	} else {
516
		api_not_allowed(true);
517
	}
518
}
519

    
520
if ($origin != 'learnpath') {
521
	//so we are not in learnpath tool
522
	Display :: display_header($nameTools, "Exercise");
523
	if (isset ($_GET['message'])) {
524
		if (in_array($_GET['message'], array (
525
				'ExerciseEdited'
526
			))) {
527
			Display :: display_confirmation_message(get_lang($_GET['message']));
528
		}
529
	}
530
} else {
531
	echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
532
}
533

    
534
event_access_tool(TOOL_QUIZ);
535

    
536
// Tool introduction
537
Display :: display_introduction_section(TOOL_QUIZ);
538

    
539
// selects $limitExPage exercises at the same time
540
$from = $page * $limitExPage;
541
$sql = "SELECT count(id) FROM $TBL_EXERCICES";
542
$res = Database::query($sql);
543
list ($nbrexerc) = Database :: fetch_array($res);
544

    
545
HotPotGCt($documentPath, 1, $_user['user_id']);
546
$tbl_grade_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
547
// only for administrator
548

    
549
if ($is_allowedToEdit) {
550
	if (!empty ($choice)) {
551
		// construction of Exercise
552

    
553
		$objExerciseTmp = new Exercise();
554
		$check = Security::check_token('get');
555

    
556
		if ($objExerciseTmp->read($exerciseId)) {
557
			if ($check) {
558
				switch ($choice) {
559
					case 'delete' : // deletes an exercise
560
						$objExerciseTmp->delete();
561

    
562
						//delete link of exercise of gradebook tool
563
						$sql = 'SELECT gl.id FROM ' . $tbl_grade_link . ' gl WHERE gl.type="1" AND gl.ref_id="' . $exerciseId . '";';
564
						$result = Database::query($sql);
565
						$row = Database :: fetch_array($result, 'ASSOC');
566
						//see
567
						if (!empty($row['id'])) {
568
	                 		$link = LinkFactory :: load($row['id']);
569
	                     		if ($link[0] != null) {
570
	                            	$link[0]->delete();
571
	                     		}
572
	           			}
573
						Display :: display_confirmation_message(get_lang('ExerciseDeleted'));
574
						break;
575
					case 'enable' : // enables an exercise
576
						$objExerciseTmp->enable();
577
						$objExerciseTmp->save();
578
						// "WHAT'S NEW" notification: update table item_property (previously last_tooledit)
579
						Display :: display_confirmation_message(get_lang('VisibilityChanged'));
580

    
581
						break;
582
					case 'disable' : // disables an exercise
583
						$objExerciseTmp->disable();
584
						$objExerciseTmp->save();
585
						Display :: display_confirmation_message(get_lang('VisibilityChanged'));
586
						break;
587
					case 'disable_results' : //disable the results for the learners
588
						$objExerciseTmp->disable_results();
589
						$objExerciseTmp->save();
590
						Display :: display_confirmation_message(get_lang('ResultsDisabled'));
591
						break;
592
					case 'enable_results' : //disable the results for the learners
593
						$objExerciseTmp->enable_results();
594
						$objExerciseTmp->save();
595
						Display :: display_confirmation_message(get_lang('ResultsEnabled'));
596
						break;
597
					case 'clean_results' : //clean student results
598
							$quantity_results_deleted= $objExerciseTmp->clean_results();
599
							Display :: display_confirmation_message(sprintf(get_lang('XResultsCleaned'),$quantity_results_deleted));
600
					break;
601
					case 'copy_exercise' : //copy an exercise
602
							$objExerciseTmp->copy_exercise();
603
							Display :: display_confirmation_message(get_lang('ExerciseCopied'));
604
					break;
605
				}
606
			}
607
		}
608

    
609
		// destruction of Exercise
610
		unset ($objExerciseTmp);
611
		Security::clear_token();
612
	}
613

    
614
	if (!empty ($hpchoice)) {
615
		switch ($hpchoice) {
616
			case 'delete' : // deletes an exercise
617
				$imgparams = array ();
618
				$imgcount = 0;
619
				GetImgParams($file, $documentPath, $imgparams, $imgcount);
620
				$fld = GetFolderName($file);
621
				for ($i = 0; $i < $imgcount; $i++) {
622
					my_delete($documentPath . $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
623
					update_db_info("delete", $uploadPath . "/" . $fld . "/" . $imgparams[$i]);
624
				}
625

    
626
				if (my_delete($documentPath . $file)) {
627
					update_db_info("delete", $file);
628
				}
629
				my_delete($documentPath . $uploadPath . "/" . $fld . "/");
630
				break;
631
			case 'enable' : // enables an exercise
632
				$newVisibilityStatus = "1"; //"visible"
633
				$query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
634
				$res = Database::query($query);
635
				$row = Database :: fetch_array($res, 'ASSOC');
636
				api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'visible', $_user['user_id']);
637
				//$dialogBox = get_lang('ViMod');
638

    
639
				break;
640
			case 'disable' : // disables an exercise
641
				$newVisibilityStatus = "0"; //"invisible"
642
				$query = "SELECT id FROM $TBL_DOCUMENT WHERE path='" . Database :: escape_string($file) . "'";
643
				$res = Database::query($query);
644
				$row = Database :: fetch_array($res, 'ASSOC');
645
				api_item_property_update($_course, TOOL_DOCUMENT, $row['id'], 'invisible', $_user['user_id']);
646
				break;
647
			default :
648
				break;
649
		}
650
	}
651

    
652
	if ($show == 'test') {
653
		$sql = "SELECT id,title,type,active,description, results_disabled FROM $TBL_EXERCICES WHERE active<>'-1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
654
		$result = Database::query($sql);
655
	}
656

    
657
}
658
elseif ($show == 'test') { // only for students //fin
659
	$sql = "SELECT id,title,type,description, results_disabled FROM $TBL_EXERCICES WHERE active='1' ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
660
	$result = Database::query($sql);
661
}
662

    
663
// the actions
664
echo '<div class="actions">';
665

    
666
// display the next and previous link if needed
667
$from = $page * $limitExPage;
668
$sql = "SELECT count(id) FROM $TBL_EXERCICES";
669
$res = Database::query($sql);
670
list ($nbrexerc) = Database :: fetch_array($res);
671
HotPotGCt($documentPath, 1, $_user['user_id']);
672

    
673
//condition for the session
674
$session_id = api_get_session_id();
675
$condition_session = api_get_session_condition($session_id,true,true);
676

    
677
// only for administrator
678
if ($is_allowedToEdit) {
679
	if ($show == 'test') {
680
		$sql = "SELECT id, title, type, active, description, results_disabled, session_id, start_time FROM $TBL_EXERCICES WHERE active<>'-1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
681
		$result = Database::query($sql);
682
	}
683
}
684
elseif ($show == 'test') { // only for students
685
	$sql = "SELECT id, title, type, description, results_disabled, session_id, start_time FROM $TBL_EXERCICES WHERE active='1' $condition_session ORDER BY title LIMIT " . (int) $from . "," . (int) ($limitExPage +1);
686
	$result = Database::query($sql);
687
}
688
if ($show == 'test') {
689
	$nbrExercises = Database :: num_rows($result);
690

    
691
	//get HotPotatoes files (active and inactive)
692
	$res = Database::query("SELECT *
693
						FROM $TBL_DOCUMENT
694
						WHERE
695
						path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'");
696
	$nbrTests = Database :: num_rows($res);
697
	$res = Database::query("SELECT *
698
						FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
699
						WHERE  d.id = ip.ref
700
						AND ip.tool = '" . TOOL_DOCUMENT . "'
701
						AND d.path LIKE '" . Database :: escape_string($uploadPath) . "/%/%'
702
						AND ip.visibility='1'");
703
	$nbrActiveTests = Database :: num_rows($res);
704

    
705
	if ($is_allowedToEdit) {
706
		//if user is allowed to edit, also show hidden HP tests
707
		$nbrHpTests = $nbrTests;
708
	} else {
709
		$nbrHpTests = $nbrActiveTests;
710
	}
711
	$nbrNextTests = $nbrexerc - $nbrHpTests - (($page * $limitExPage));
712

    
713
	echo '<span style="float:right">';
714
	//show pages navigation link for previous page
715
	if ($page) {
716
		echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page -1) . "\">" . Display :: return_icon('previous.gif') . get_lang("PreviousPage") . "</a> | ";
717
	}
718
	elseif ($nbrExercises + $nbrNextTests > $limitExPage) {
719
		echo Display :: return_icon('previous.gif') . get_lang('PreviousPage') . " | ";
720
	}
721

    
722
	//show pages navigation link for previous page
723
	if ($nbrExercises + $nbrNextTests > $limitExPage) {
724
		echo "<a href=\"" . api_get_self() . "?" . api_get_cidreq() . "&amp;page=" . ($page +1) . "\">" . get_lang("NextPage") . Display :: return_icon('next.gif') . "</a>";
725
	}
726
	elseif ($page) {
727
		echo get_lang("NextPage") . Display :: return_icon('next.gif');
728
	}
729
	echo '</span>';
730
}
731

    
732
if (($is_allowedToEdit) and ($origin != 'learnpath')) {
733
	if ($_GET['show'] != 'result') {
734
		echo '<a href="exercise_admin.php?' . api_get_cidreq() . '">' . Display :: return_icon('new_test.gif', get_lang('NewEx')) . get_lang('NewEx') . '</a>';
735
		echo '<a href="question_create.php?' . api_get_cidreq() . '">' . Display :: return_icon('question_add.gif', get_lang('AddQuestionToExercise')) . get_lang('AddQuestionToExercise') . '</a>';
736
		echo '<a href="hotpotatoes.php?' . api_get_cidreq() . '">' . Display :: return_icon('hotpotatoes_s.png', get_lang('ImportHotPotatoesQuiz')) . get_lang('ImportHotPotatoesQuiz') . '</a>';
737
		// link to import qti2 ...
738
		echo '<a href="qti2.php?' . api_get_cidreq() . '">' . Display :: return_icon('import_db.png', get_lang('ImportQtiQuiz')) . get_lang('ImportQtiQuiz') . '</a>';
739
		echo '<a href="exercice.php?' . api_get_cidreq() . '&show=result">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
740
	}
741

    
742
	// the actions for the statistics
743
	if ($show == 'result') {
744
		// the form
745
		if (api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
746
			if ($_SESSION['export_user_fields']) {
747
				$alt = get_lang('ExportWithUserFields');
748
				$extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
749
			} else {
750
				$alt = get_lang('ExportWithoutUserFields');
751
				$extra_user_fields = '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
752
			}
753
			echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
754
			echo '<a href="javascript: void(0);" onclick="javascript: document.form1a.submit();">'.Display::return_icon('csv.gif',get_lang('ExportAsCSV')).get_lang('ExportAsCSV').'</a>';
755
			echo '<a href="javascript: void(0);" onclick="javascript: document.form1b.submit();">' . Display :: return_icon('excel.gif', get_lang('ExportAsXLS')) . get_lang('ExportAsXLS') . '</a>';
756
			echo '<form id="form1a" name="form1a" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
757
			echo '<input type="hidden" name="export_report" value="export_report">';
758
			echo '<input type="hidden" name="export_format" value="csv">';
759
			echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
760
			echo '</form>';
761
			echo '<form id="form1b" name="form1b" method="post" action="' . api_get_self() . '?show=' . Security :: remove_XSS($_GET['show']) . '" style="display:inline">';
762
			echo '<input type="hidden" name="export_report" value="export_report">';
763
			echo '<input type="hidden" name="export_filter" value="'.(empty($filter)?1:intval($filter)).'">';
764
			echo '<input type="hidden" name="export_format" value="xls">';
765
			echo '</form>';
766
		}
767
	}
768
} else {
769
	//the student view
770
	if ($show == 'result') {
771
		echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=test') . '">' . Display :: return_icon('back.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
772
	} else {
773
		echo '<a href="' . api_add_url_param($_SERVER['REQUEST_URI'], 'show=result') . '">' . Display :: return_icon('show_test_results.gif', get_lang('Results')) . get_lang('Results') . '</a>';
774
	}
775
}
776
if ($_configuration['tracking_enabled']) {
777
	if ($show == 'result') {
778
		if (api_is_allowed_to_edit(null,true)) {
779
			if (!$_GET['filter']) {
780
				$filter_by_not_revised = true;
781
				$filter = 1;
782
			} else {
783
				$filter=Security::remove_XSS($_GET['filter']);
784
			}
785
			$filter = (int) $_GET['filter'];
786

    
787
			switch ($filter) {
788
				case 1 :
789
					$filter_by_not_revised = true;
790
					break;
791
				case 2 :
792
					$filter_by_revised = true;
793
					break;
794
				default :
795
					null;
796
			}
797
			if ($_GET['filter'] == '1' or !isset ($_GET['filter']) or $_GET['filter'] == 0 ) {
798
				$view_result = '<a href="' . api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=2&gradebook='.$gradebook.'" >'.Display :: return_icon('check.gif', get_lang('ShowCorrectedOnly')).get_lang('ShowCorrectedOnly').'</a>';
799
			} else {
800
				$view_result = '<a href="' .api_get_self() . '?cidReq=' . api_get_course_id() . '&show=result&filter=1&gradebook='.$gradebook.'" >'.Display :: return_icon('un_check.gif', get_lang('ShowUnCorrectedOnly')).get_lang('ShowUnCorrectedOnly').'</a>';
801
			}
802
			echo $view_result;
803
		}
804
	}
805
}
806

    
807
echo '</div>'; // closing the actions div
808

    
809
if ($show == 'test') {
810
?>
811
<table class="data_table">
812
  <?php
813
	if (($is_allowedToEdit) and ($origin != 'learnpath')) {
814
?>
815
	  <tr class="row_odd">
816
	    <th colspan="3"><?php  echo get_lang('ExerciseName');?></th>
817
	     <th><?php echo get_lang('QuantityQuestions');?></th>
818
		 <th><?php echo get_lang('Modify');?></th>
819
	  </tr>
820
	  <?php
821
	} else {
822
		//student only
823
?> <tr>
824
	     <th colspan="2"><?php echo get_lang('ExerciseName');?></th>
825
	     <th><?php echo get_lang('QuantityQuestions');?></th>
826
		 <th><?php echo get_lang('State');?></th>
827
	  </tr>
828
		<?php
829
	}
830
	// show message if no HP test to show
831
	if (!($nbrExercises + $nbrHpTests)) {
832
?>
833
	  <tr>
834
	    <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
835
	  </tr>
836
	  <?php
837
	}
838
	$i = 1;
839

    
840
	/*
841
	 * Listing exercises
842
	 */
843
	if ($origin != 'learnpath') {
844
		//avoid sending empty parameters
845
		$myorigin = (empty ($origin) ? '' : '&origin=' . $origin);
846
		$mylpid = (empty ($learnpath_id) ? '' : '&learnpath_id=' . $learnpath_id);
847
		$mylpitemid = (empty ($learnpath_item_id) ? '' : '&learnpath_item_id=' . $learnpath_item_id);
848

    
849
		$token = Security::get_token();
850
				while ($row = Database :: fetch_array($result)) {
851
				//validacion when belongs to a session
852
				$session_img = api_get_session_image($row['session_id'], $_user['status']);
853

    
854
				// check if start time
855
				$time_limits = false;
856
				if ($row['start_time'] != '0000-00-00 00:00:00' && $row['end_time'] != '0000-00-00 00:00:00') {
857
					$time_limits = true;
858
$start_time = api_strtotime(api_get_local_time($row['start_time']));
859
$end_time   = api_strtotime(api_get_local_time($row['end_time']));
860
$now 		= api_strtotime(api_get_local_time());
861
$is_actived_time = false;
862
if ($now > $start_time && $end_time > $now ) {
863
$is_actived_time = true;}
864
				}
865

    
866
				if ($i % 2 == 0)
867
					$s_class = "row_odd";
868
				else
869
					$s_class = "row_even";
870
				// prof only
871
				if ($is_allowedToEdit) {
872
					echo '<tr class="' . $s_class . '">';
873

    
874
					echo '<td width="30" align="left">'.Display::return_icon('quiz.gif', get_lang('Exercice')).'</td>';
875
					echo '<td width="15" valign="left">'.($i+($page*$limitExPage)).'.'.'</td>';
876

    
877
					//Showing exercise title
878
					$row['title']=api_parse_tex($row['title']);
879

    
880
					echo '<td>';
881
					$class_invisible = '';
882
					if (!$row['active']) {
883
						$class_invisible = 'class="invisible"';
884
					}
885
					echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$mylpitemid.'&amp;exerciseId='.$row['id'].'" '.$class_invisible.'>';
886
					echo Security::remove_XSS($row['title']);
887
					echo '</a>';
888
					echo $session_img;
889
					echo '</td>';
890
					echo '<td align="center">';
891

    
892
					$exid = $row['id'];
893

    
894
					//count number exercice - teacher
895
					$sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
896
					$sqlresult = Database::query($sqlquery);
897
					$rowi = Database :: result($sqlresult, 0);
898

    
899
					//count number random exercice - teacher
900
					$sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
901
					$rs_random = Database::query($sql_random_query);
902
					$row_random = Database :: fetch_array($rs_random);
903
					if ($row_random['random'] > 0) {
904
						echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question'))) . '</td>';
905
					} else {
906
						echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question'))) . '</td>';
907
					}
908
					echo '<td align="center">';
909
					if ($session_id == $row['session_id']) {
910
						?>
911
						<a href="admin.php?<?php echo api_get_cidreq()?>&amp;exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('Edit'),ENT_QUOTES,$charset); ?>" /></a>
912
						<a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=copy_exercise&amp;sec_token=<?php echo $token; ?>&amp;exerciseId=<?php echo $row['id']; ?>"  onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToCopy'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;"><img width="16" src="../img/cd.gif" border="0" title="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CopyExercise'),ENT_QUOTES,$charset); ?>" /></a>
913
						<a href="exercice.php?<?php echo api_get_cidreq()?>&amp;choice=clean_results&amp;sec_token=<?php echo $token; ?>&amp;exerciseId=<?php echo $row['id']; ?>"  onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDeleteResults'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;" ><img width="16" src="../img/clean_group.gif" border="0" title="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" alt="<?php echo api_htmlentities(get_lang('CleanStudentResults'),ENT_QUOTES,$charset); ?>" /></a>
914
						<a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=delete&sec_token=<?php echo$token; ?>&amp;exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(api_htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset)); echo " ".addslashes($row['title']); echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" title="<?php echo get_lang('Delete'); ?>" alt="<?php echo api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>
915
						<?php
916
						//if active
917
						if ($row['active']) {
918
							?>
919
							<a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=disable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/visible.gif"  border="0" title="<?php echo get_lang('Deactivate'); ?>" alt="<?php echo api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
920
							<?php
921
						} else { // else if not active
922
							?>
923
							<a href="exercice.php?<?php echo api_get_cidreq() ?>&choice=enable&sec_token=<?php echo$token; ?>&amp;page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0"  title="<?php echo get_lang('Activate'); ?>" alt="<?php echo api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
924
							<?php
925
						}
926
						// Export qti ...
927
						echo '<a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export_db.png" border="0" title="IMS/QTI" /></a>';
928
					} else { // not session resource
929
						echo get_lang('ExerciseEditionNotAvailableInSession');
930
					}
931
					echo "</td>";
932
					echo "</tr>";
933
				} else { // student only
934
					?>
935
					<tr>
936
					  <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
937
					  <?php $row['title']=api_parse_tex($row['title']);?>
938
					  <td>
939

    
940
					<?php
941
					// if time is actived show link to exercise
942
					if ($time_limits) { 
943
						if($is_actived_time) {
944
echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
945
						} else {
946
							echo $row['title'];
947
						}
948
					} else {
949
echo '<a href="exercice_submit.php?'.api_get_cidreq().$myorigin.$mylpid.$myllpitemid.'&exerciseId='.$row['id'].'">'.$row['title'].'</a>';
950
					}
951
					echo '</td><td align="center">';
952
					$exid = $row['id'];
953
					//count number exercise questions
954
					$sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '" . Database :: escape_string($exid) . "'";
955
					$sqlresult = Database::query($sqlquery);
956
					$rowi = Database :: result($sqlresult, 0);
957
					//count number random exercice
958
					$sql_random_query = 'SELECT type,random,active,results_disabled,max_attempt FROM ' . $TBL_EXERCICES . ' WHERE id="' . Database :: escape_string($exid) . '" ';
959
					$rs_random = Database::query($sql_random_query);
960
					$row_random = Database :: fetch_array($rs_random);
961
					if ($row_random['random'] > 0) {
962
						echo $row_random['random'] . ' ' . api_strtolower(get_lang(($row_random['random'] > 1 ? 'Questions' : 'Question')));
963
					} else {
964
						//show results student
965
						echo $rowi . ' ' . api_strtolower(get_lang(($rowi > 1 ? 'Questions' : 'Question')));
966
					}
967
					echo '</td>';
968
					echo '<td align="center">';
969
					$eid = $row['id'];
970
					$uid = api_get_user_id();
971
					//this query might be improved later on by ordering by the new "tms" field rather than by exe_id
972
					$qry = "SELECT * FROM $TBL_TRACK_EXERCICES
973
							WHERE exe_exo_id = '" . Database :: escape_string($eid) . "' and exe_user_id = '" . Database :: escape_string($uid) . "' AND exe_cours_id = '" . api_get_course_id() . "' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id =  '" . api_get_session_id() . "'
974
							ORDER BY exe_id DESC";
975
					$qryres = Database::query($qry);
976
					$num = Database :: num_rows($qryres);
977

    
978
					//hide the results
979
					if ($time_limits) {
980
						$my_result_disabled = $row['results_disabled'];
981
						if ($my_result_disabled == 0) {
982
							if ($num > 0) {
983
								echo sprintf(get_lang('ExerciseWillBeActivatedFromXToY'), api_get_local_time($row['start_time']), api_get_local_time($row['end_time']));
984
							} else {
985
								echo get_lang('NotAttempted');
986
							}
987
						} else {
988
							echo get_lang('CantShowResults');
989
						}
990
					} else {
991
						if ($my_result_disabled == 0) {
992
							if ($num > 0) {
993
								$row = Database :: fetch_array($qryres);
994
								$percentage = 0;
995
								if ($row['exe_weighting'] != 0) {
996
									$percentage = ($row['exe_result'] / $row['exe_weighting']) * 100;
997
								}
998
								echo get_lang('Attempted').' ('.get_lang('Score').': ';
999
								printf("%1.2f\n", $percentage);
1000
								echo " %)";
1001
							} else {
1002
								echo get_lang('NotAttempted');
1003
							}
1004
						} else {
1005
							echo get_lang('CantShowResults');
1006
						}
1007
					}
1008
					echo '</td></tr>';
1009
				}
1010
			// skips the last exercise, that is only used to know if we have or not to create a link "Next page"
1011
			if ($i == $limitExPage) {
1012
				break;
1013
			}
1014
			$i++;
1015
		} // end while()
1016
		$ind = $i;
1017
		if (($from + $limitExPage -1) > $nbrexerc) {
1018
			if ($from > $nbrexerc) {
1019
				$from = $from - $nbrexerc;
1020
				$to = $limitExPage;
1021
			} else {
1022
				$to = $limitExPage - ($nbrexerc - $from);
1023
				$from = 0;
1024
			}
1025
		} else {
1026
			$to = $limitExPage;
1027
		}
1028

    
1029
		if ($is_allowedToEdit) {
1030
			$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
1031
					FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
1032
					WHERE   d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
1033
					AND   d.path  LIKE '" . Database :: escape_string($uploadPath) . "/%/%' LIMIT " . (int) $from . "," . (int) $to; // only .htm or .html files listed
1034
		} else {
1035
			$sql = "SELECT d.path as path, d.comment as comment, ip.visibility as visibility
1036
					FROM $TBL_DOCUMENT d, $TBL_ITEM_PROPERTY ip
1037
					WHERE d.id = ip.ref AND ip.tool = '" . TOOL_DOCUMENT . "' AND (d.path LIKE '%htm%')
1038
					AND   d.path  LIKE '" . Database :: escape_string($uploadPath) . "/%/%' AND ip.visibility='1' LIMIT " . (int) $from . "," . (int) $to;
1039
		}
1040

    
1041
		$result = Database::query($sql);
1042

    
1043
		while ($row = Database :: fetch_array($result, 'ASSOC')) {
1044
			$attribute['path'][] = $row['path'];
1045
			$attribute['visibility'][] = $row['visibility'];
1046
			$attribute['comment'][] = $row['comment'];
1047
		}
1048
		$nbrActiveTests = 0;
1049
		if (is_array($attribute['path'])) {
1050
			while (list ($key, $path) = each($attribute['path'])) {
1051
				list ($a, $vis) = each($attribute['visibility']);
1052
				if (strcmp($vis, "1") == 0) {
1053
					$active = 1;
1054
				} else {
1055
					$active = 0;
1056
				}
1057
				echo "<tr>\n";
1058

    
1059
				$title = GetQuizName($path, $documentPath);
1060
				if ($title == '') {
1061
					$title = basename($path);
1062
				}
1063
				// prof only
1064
				if ($is_allowedToEdit) {
1065
					echo '   <tr>'.
1066
					'      <td><img src="../img/hotpotatoes_s.png" alt="HotPotatoes" /></td>'.
1067
					'      <td>'.($ind+($page*$limitExPage)).'.</td>'.
1068
					'      <td><a href="showinframes.php?file='.$path.'&cid='.$_course['official_code'].'&uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'>'.$title.'</a></td>'.
1069
					'      <td align="center">-</td>'.
1070
					'      <td align="center">' .
1071
					'        <a href="adminhp.php?'.api_get_cidreq().'&hotpotatoesName='.$path.'">'.
1072
					'          <img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="'.api_htmlentities(get_lang('Modify'),ENT_QUOTES,$charset).'" />' .
1073
					'        </a>'.
1074
					'        <a href="'.$exercicePath.'?'.api_get_cidreq().'&amp;hpchoice=delete&amp;file='.$path.'" onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('AreYouSure'),ENT_QUOTES,$charset).$title."?").'\')) return false;"><img src="../img/delete.gif" border="0" title="'.get_lang('Delete').'" alt="'.api_htmlentities(get_lang('Delete'),ENT_QUOTES,$charset).'" /></a>';
1075
					// if active
1076
					if ($active) {
1077
						$nbrActiveTests = $nbrActiveTests +1;
1078
						echo '      <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=disable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/visible.gif" border="0" title="'.get_lang('Deactivate').'" alt="'.api_htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset).'" /></a>';
1079
					} else { // else if not active
1080
						echo '    <a href="'.$exercicePath.'?'.api_get_cidreq().'&hpchoice=enable&amp;page='.$page.'&amp;file='.$path.'"><img src="../img/invisible.gif" border="0" title="'.get_lang('Activate').'" alt="'.api_htmlentities(get_lang('Activate'),ENT_QUOTES,$charset).'" /></a>';
1081
					}
1082
					echo '<img src="../img/lp_quiz_na.gif" border="0" title="'.get_lang('NotMarkActivity').'" alt="" />';
1083
					echo '</td>';
1084
				} else { // student only
1085
					if ($active == 1) {
1086
						$nbrActiveTests = $nbrActiveTests +1;
1087
						echo '    <tr>'.
1088
							'       <td>'.($ind+($page*$limitExPage)).'.<!--<img src="../img/jqz.jpg" alt="HotPotatoes" />--></td>' .
1089
							'       <td><a href="showinframes.php?'.api_get_cidreq().'&amp;file='.$path.'&amp;cid='.$_course['official_code'].'&amp;uid='.$_user['user_id'].'"'.(!$active?'class="invisible"':'').'">'.$title.'</a></td>'.
1090
							'       <td style="text-align: center;">-</td><td style="text-align: center;">-</td>'.
1091
							'     </tr>';
1092
					}
1093
				}
1094
				if ($ind == $limitExPage) {
1095
					break;
1096
				}
1097
				if ($is_allowedToEdit) {
1098
					$ind++;
1099
				} else {
1100
					if ($active == 1) {
1101
						$ind++;
1102
					}
1103
				}
1104
			}
1105
		}
1106

    
1107
	} //end if ($origin != 'learnpath') {
1108
echo '</table>';
1109
}
1110

    
1111
/* Exercise Results (uses tracking tool) */
1112

    
1113
// if tracking is enabled
1114
if ($_configuration['tracking_enabled'] && ($show == 'result')) {
1115

    
1116
	$session_id_and = ' AND ce.session_id = ' . api_get_session_id() . ' ';
1117
	if ($is_allowedToEdit || $is_tutor) {
1118
		$user_id_and = '';
1119
		if (!empty ($_POST['filter_by_user'])) {
1120
			if ($_POST['filter_by_user'] == 'all') {
1121
				$user_id_and = " AND user_id like '%'";
1122
			} else {
1123
				$user_id_and = " AND user_id = '" . Database :: escape_string((int) $_POST['filter_by_user']) . "' ";
1124
			}
1125
		}
1126
		if ($_GET['gradebook'] == 'view') {
1127
			$exercise_where_query = 'te.exe_exo_id =ce.id AND ';
1128
		}
1129

    
1130
			$sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users, ce.title, te.exe_result ,
1131
								 te.exe_weighting, te.exe_date, te.exe_id, email, te.start_date, steps_counter,cuser.user_id,te.exe_duration
1132
						  FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
1133
						  WHERE  user.user_id=cuser.user_id AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
1134
						  AND cuser.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
1135
						  AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
1136

    
1137
			$hpsql="SELECT ".(api_is_western_name_order() ? "CONCAT(tu.firstname,' ',tu.lastname)" : "CONCAT(tu.lastname,' ',tu.firstname)").", tth.exe_name,
1138
								tth.exe_result , tth.exe_weighting, tth.exe_date
1139
							FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
1140
							WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '" . Database :: escape_string($_cid) . " $user_id_and '
1141
							ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
1142

    
1143
	} else {
1144
		// get only this user's results
1145
		$user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
1146

    
1147
				$sql="SELECT ".(api_is_western_name_order() ? "CONCAT(firstname,' ',lastname)" : "CONCAT(lastname,' ',firstname)")." as users,ce.title, te.exe_result ,
1148
							 te.exe_weighting, te.exe_date, te.exe_id, email, te.start_date, steps_counter,cuser.user_id,te.exe_duration, ce.results_disabled
1149
						  FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
1150
						  WHERE  user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='" . Database :: escape_string($_cid) . "'
1151
						  AND cuser.status<>1 AND cuser.relation_type<>".COURSE_RELATION_TYPE_RRHH." $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0
1152
						  AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
1153

    
1154
		$hpsql = "SELECT '',exe_name, exe_result , exe_weighting, exe_date
1155
						FROM $TBL_TRACK_HOTPOTATOES
1156
						WHERE exe_user_id = '" . $_user['user_id'] . "' AND exe_cours_id = '" . Database :: escape_string($_cid) . "'
1157
						ORDER BY exe_cours_id ASC, exe_date DESC";
1158
	}
1159
	$results = getManyResultsXCol($sql, 12);
1160
	$hpresults = getManyResultsXCol($hpsql, 5);
1161

    
1162
	$has_test_results = false;
1163
	$list_info = array();
1164

    
1165
	// Print test results.
1166
	$lang_nostartdate = get_lang('NoStartDate') . ' / ';
1167

    
1168
	if (is_array($results)) {
1169

    
1170
		$has_test_results = true;
1171

    
1172
		$users_array_id = array ();
1173
		if ($_GET['gradebook'] == 'view') {
1174
			$filter_by_no_revised = true;
1175
			$from_gradebook = true;
1176
		}
1177
		$sizeof = sizeof($results);
1178
		$user_list_id = array ();
1179
		$user_list_name = '';
1180
		$quiz_name_list = '';
1181
		$duration_list = '';
1182
		$date_list = '';
1183
		$result_list = '';
1184
		$more_details_list = '';
1185
		for ($i = 0; $i < $sizeof; $i++) {
1186
			$revised = false;
1187
			$sql_exe = 'SELECT exe_id FROM ' . Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING) . '
1188
									  WHERE author != ' . "''" . ' AND exe_id = ' . "'" . Database :: escape_string($results[$i][5]) . "'" . ' LIMIT 1';
1189
			$query = Database::query($sql_exe);
1190

    
1191
			if (Database :: num_rows($query) > 0) {
1192
				$revised = true;
1193
			}
1194
			if ($filter_by_not_revised && $revised) {
1195
				continue;
1196
			}
1197
			if ($filter_by_revised && !$revised) {
1198
				continue;
1199
			}
1200
			if ($from_gradebook && ($is_allowedToEdit || $is_tutor)) {
1201
				if (in_array($results[$i][1] . $results[$i][0], $users_array_id)) {
1202
					continue;
1203
				}
1204
				$users_array_id[] = $results[$i][1] . $results[$i][0];
1205
			}
1206

    
1207
			$user_list_name = $results[$i][0];
1208
			$user_list_id[] = $results[$i][9];
1209
			$id = $results[$i][5];
1210
			$mailid = $results[$i][6];
1211
			$user = $results[$i][0];
1212
			$test = $results[$i][1];
1213
			$quiz_name_list = $test;
1214
			$dt = api_convert_and_format_date($results[$i][4], null, date_default_timezone_get());
1215
			$res = $results[$i][2];
1216

    
1217
			$duration = intval($results[$i][10]);
1218
			// we filter the results if we have the permission to
1219
			if (isset ($results[$i][11]))
1220
				$result_disabled = intval($results[$i][11]);
1221
			else
1222
				$result_disabled = 0;
1223

    
1224
			if ($result_disabled == 0) {
1225
				$add_start_date = $lang_nostartdate;
1226

    
1227
				if ($is_allowedToEdit || $is_tutor) {
1228
					$user = $results[$i][0];
1229
				}
1230
				if ($results[$i][7] != "0000-00-00 00:00:00") {
1231
					//echo ceil((($results[$i][4] - $results[$i][7]) / 60)) . ' ' . get_lang('MinMinutes');
1232
					$exe_date_timestamp = api_strtotime($results[$i][4], date_default_timezone_get());
1233
					$start_date_timestamp = api_strtotime($results[$i][7], date_default_timezone_get());
1234
					$duration_list = ceil((($exe_date_timestamp - $start_date_timestamp) / 60)) . ' ' . get_lang('MinMinutes');
1235
					if ($results[$i][8] > 1) {
1236
						//echo ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
1237
						$duration_list = ' ( ' . $results[$i][8] . ' ' . get_lang('Steps') . ' )';
1238
					}
1239
					$add_start_date = api_convert_and_format_date($results[$i][7], null, date_default_timezone_get()) . ' / ';
1240
				} else {
1241
					$duration_list = get_lang('NoLogOfDuration');
1242
					//echo get_lang('NoLogOfDuration');
1243
				}
1244
				// Date conversion
1245
				$date_list = api_get_local_time($results[$i][7], null, date_default_timezone_get()). ' / ' . api_get_local_time($results[$i][4], null, date_default_timezone_get());
1246
				// there are already a duration test period calculated??
1247
				//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
1248

    
1249
				// if the float look like 10.00 we show only 10
1250

    
1251
				$my_res		= float_format($results[$i][2],1);
1252
				$my_total 	= float_format($results[$i][3],1);
1253

    
1254
				//echo '<td>' . round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')</td>';
1255
				$result_list = round(($my_res / ($my_total != 0 ? $my_total : 1)) * 100, 2) . '% (' . $my_res . ' / ' . $my_total . ')';
1256
				// Is hard to read this!!
1257
				/*
1258
				echo '<td>'.(($is_allowedToEdit||$is_tutor)?
1259
							"<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
1260
							(($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
1261
							((api_is_platform_admin() || $is_tutor)?' - <a href="exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result&filter='.$filter.'&delete=delete&did='.$id.'" onclick="javascript:if(!confirm(\''.sprintf(get_lang('DeleteAttempt'),$user,$dt).'\')) return false;">'.get_lang('Delete').'</a>':'')
1262
							.(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>':'')
1263
							:(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
1264
				*/
1265

    
1266
				//echo '<td>';
1267
				$html_link = '';
1268
				if ($is_allowedToEdit || $is_tutor) {
1269
					if ($revised) {
1270
						//echo "<a href='exercise_show.php?action=edit&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('edit.gif', get_lang('Edit'));
1271
						//echo '&nbsp;';
1272
						$html_link.= "<a href='exercise_show.php?".api_get_cidreq()."&action=edit&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('edit.gif', get_lang('Edit'));
1273
						$html_link.= '&nbsp;';
1274
					} else {
1275
						//echo "<a href='exercise_show.php?action=qualify&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
1276
						//echo '&nbsp;';
1277
						$html_link.="<a href='exercise_show.php?".api_get_cidreq()."&action=qualify&user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".Display :: return_icon('quizz_small.gif', get_lang('Qualify'));
1278
						$html_link.='&nbsp;';
1279
					}
1280
					//echo "</a>";
1281
					$html_link.="</a>";
1282
					if (api_is_platform_admin() || $is_tutor) {
1283
						//echo ' <a href="exercice.php?cidReq=' . Security::remove_XSS($_GET['cidReq']) . '&show=result&filter=' . $filter . '&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.gif', get_lang('Delete')).'</a>';
1284
						//echo '&nbsp;';
1285
						$html_link.=' <a href="exercice.php?'.api_get_cidreq().'&show=result&filter=' . $filter . '&delete=delete&did=' . $id . '" onclick="javascript:if(!confirm(\'' . sprintf(get_lang('DeleteAttempt'), $user, $dt) . '\')) return false;">'.Display :: return_icon('delete.gif', get_lang('Delete')).'</a>';
1286
						$html_link.='&nbsp;';
1287
					}
1288
					if ($is_allowedToEdit) {
1289
						//echo ' <a href="exercice_history.php?cidReq=' . security::remove_XSS($_GET['cidReq']) . '&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
1290
						if ($filter==2){
1291
							$html_link.=' <a href="exercice_history.php?'.api_get_cidreq().'&exe_id=' . $id . '">' .Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).'</a>';
1292
						}
1293
					}
1294
				} else {
1295
					if ($revised) {
1296
						//echo "<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
1297
						$html_link.="<a href='exercise_show.php?".api_get_cidreq()."&dt=$dt&res=$res&id=$id'>" . get_lang('Show') . "</a> ";
1298

    
1299
					} else {
1300
					//	echo '&nbsp;' . get_lang('NoResult');
1301
						$html_link.='&nbsp;' . get_lang('NoResult');
1302
					}
1303

    
1304
				}
1305
				$more_details_list = $html_link;
1306
				if ($is_allowedToEdit || $is_tutor) {
1307
					$list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
1308
				} else {
1309
					$list_info [] = array($quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
1310
				}
1311
				//$list_info [] = array($user_list_name,$quiz_name_list,$duration_list,$date_list,$result_list,$more_details_list);
1312
				//echo '</td>';
1313

    
1314
				//echo '</tr>';
1315
			}
1316
		}
1317
	}
1318

    
1319
	// Print HotPotatoes test results.
1320
	if (is_array($hpresults)) {
1321

    
1322
		$has_test_results = true;
1323

    
1324
		for ($i = 0; $i < sizeof($hpresults); $i++) {
1325
			$hp_title = GetQuizName($hpresults[$i][1], $documentPath);
1326
			if ($hp_title == '') {
1327
				$hp_title = basename($hpresults[$i][1]);
1328
			}
1329
			//$hp_date = api_convert_and_format_date($hpresults[$i][4], null, date_default_timezone_get());
1330
			$hp_date = api_get_local_time($hpresults[$i][4], null, date_default_timezone_get());
1331
			$hp_result = round(($hpresults[$i][2] / ($hpresults[$i][3] != 0 ? $hpresults[$i][3] : 1)) * 100, 2).'% ('.$hpresults[$i][2].' / '.$hpresults[$i][3].')';
1332
			if ($is_allowedToEdit) {
1333
				$list_info[] = array($hpresults[$i][0], $hp_title, '-', $hp_date , $hp_result , '-');
1334
			} else {
1335
				$list_info[] = array($hp_title, '-', $hp_date , $hp_result , '-');
1336
			}
1337
		}
1338
	}
1339

    
1340
	if ($has_test_results) {
1341

    
1342
		$parameters=array('cidReq'=>Security::remove_XSS($_GET['cidReq']),'show'=>Security::remove_XSS($_GET['show']),'filter' => Security::remove_XSS($_GET['filter']),'gradebook' =>Security::remove_XSS($_GET['gradebook']));
1343

    
1344
		$table = new SortableTableFromArrayConfig($list_info, 1,20,'quiz_table');
1345
		$table->set_additional_parameters($parameters);
1346
		if ($is_allowedToEdit || $is_tutor) {
1347
			$table->set_header(0, get_lang('User'));
1348
			$secuence = 0;
1349
		} else {
1350
			$secuence = 1;
1351
		}
1352
		$table->set_header(-$secuence + 1, get_lang('Exercice'));
1353
		$table->set_header(-$secuence + 2, get_lang('Duration'),false);
1354
		$table->set_header(-$secuence + 3, get_lang('Date'));
1355
		$table->set_header(-$secuence + 4, get_lang('Result'),false);
1356
		$table->set_header(-$secuence + 5, (($is_allowedToEdit||$is_tutor) ? get_lang('CorrectTest') : get_lang('ViewTest')), false);
1357
		$table->display();
1358

    
1359
	} else {
1360

    
1361
		echo get_lang('NoResult');
1362

    
1363
	}
1364

    
1365
}
1366

    
1367
if ($origin != 'learnpath') { //so we are not in learnpath tool
1368
	Display :: display_footer();
1369
} else {
1370
?>
1371
<link rel="stylesheet" type="text/css" href="<?php echo $clarolineRepositoryWeb ?>css/default.css" />
1372
<?php
1373
}
1374
?>
(2-2/2)