Project

General

Profile

Bug #7588 ยป exercise_show.php

exercise_show.php version 470c12d0 with e4ba3c92 included, and 73e38162 excluded Cf #7588 - Torkil Zachariassen, 09/04/2015 17:12

 
1
<?php
2
/* File: exercise_show.php version 470c12d0 with e4ba3c92 included, and 73e38162 excluded Cf #7588 ...torkil... */
3
/* For licensing terms, see /license.txt */
4
/**
5
 *  Shows the exercise results
6
 *
7
 * @author Julio Montoya Armas Added switchable fill in blank option added
8
 * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
9
 * @package chamilo.exercise
10
 * @todo remove the debug code and use the general debug library
11
 * @todo small letters for table variables
12
 *
13
 */
14

    
15
// name of the language file that needs to be included
16

    
17
use \ChamiloSession as Session;
18

    
19
$language_file = array('exercice');
20

    
21
// including additional libraries
22
require_once 'exercise.class.php';
23
require_once 'question.class.php'; //also defines answer type constants
24
require_once 'answer.class.php';
25
require_once '../inc/global.inc.php';
26
require_once 'exercise.lib.php';
27

    
28
require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
29

    
30
if (empty($origin) ) {
31
    $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
32
}
33

    
34
if ($origin == 'learnpath') {
35
    api_protect_course_script(false, false, true);
36
} else {
37
    api_protect_course_script(true, false, true);
38
}
39

    
40
// Database table definitions
41
$TBL_EXERCICE_QUESTION 	= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
42
$TBL_QUESTIONS         	= Database::get_course_table(TABLE_QUIZ_QUESTION);
43
$TBL_TRACK_EXERCICES    = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
44
$TBL_TRACK_ATTEMPT		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
45

    
46
// General parameters passed via POST/GET
47
if ($debug) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); }
48

    
49
if (empty($formSent)) {            $formSent       = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null; }
50
if (empty($exerciseResult)) {      $exerciseResult = isset($_SESSION['exerciseResult']) ? $_SESSION['exerciseResult'] : null; }
51
if (empty($questionId)) {          $questionId     = isset($_REQUEST['questionId']) ? $_REQUEST['questionId'] : null;}
52
if (empty($choice)) {              $choice         = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;}
53
if (empty($questionNum)) {         $questionNum    = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;}
54
if (empty($nbrQuestions)) {        $nbrQuestions   = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null;}
55
if (empty($questionList)) {        $questionList   = isset($_SESSION['questionList']) ? $_SESSION['questionList'] : null;}
56
if (empty($objExercise)) {         $objExercise    = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;}
57
if (empty($exeId)) {               $exeId          = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;}
58
if (empty($action)) {              $action         = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;}
59

    
60
$id = intval($_REQUEST['id']); //exe id
61

    
62
if (empty($id)) {
63
    api_not_allowed(true);
64
}
65

    
66
if (api_is_course_session_coach(
67
    api_get_user_id(),
68
    api_get_course_id(),
69
    api_get_session_id()
70
)) {
71
    if (!api_coach_can_edit_view_results(api_get_course_id(), api_get_session_id())) {
72
        api_not_allowed(true);
73
    }
74
}
75

    
76
$is_allowedToEdit = api_is_allowed_to_edit(null, true) || $is_courseTutor || api_is_session_admin() || api_is_drh();
77

    
78
//Getting results from the exe_id. This variable also contain all the information about the exercise
79
$track_exercise_info = get_exercise_track_exercise_info($id);
80

    
81
//No track info
82
if (empty($track_exercise_info)) {
83
    api_not_allowed(true);
84
}
85

    
86
$exercise_id        = $track_exercise_info['id'];
87
$exercise_date      = $track_exercise_info['start_date'];
88
$student_id         = $track_exercise_info['exe_user_id'];
89
$learnpath_id       = $track_exercise_info['orig_lp_id'];
90
$learnpath_item_id  = $track_exercise_info['orig_lp_item_id'];
91
$lp_item_view_id    = $track_exercise_info['orig_lp_item_view_id'];
92
$current_user_id    = api_get_user_id();
93

    
94
$locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
95

    
96
if (empty($objExercise)) {
97
	$objExercise = new Exercise();
98
    $objExercise->read($exercise_id);
99
}
100
$feedback_type = $objExercise->feedback_type;
101

    
102
//Only users can see their own results
103
if (!$is_allowedToEdit) {
104
    if ($student_id != $current_user_id) {
105
    	api_not_allowed(true);
106
    }
107
}
108

    
109
if (isset($_SESSION['gradebook'])) {
110
	$gradebook=	Security::remove_XSS($_SESSION['gradebook']);
111
}
112

    
113
if (!empty($gradebook) && $gradebook=='view') {
114
	$interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
115
}
116

    
117
$fromlink = '';
118

    
119
$interbreadcrumb[]= array("url" => "exercice.php?".api_get_cidreq(),"name" => get_lang('Exercices'));
120
$interbreadcrumb[]= array("url" => "overview.php?exerciseId=".$exercise_id.'&'.api_get_cidreq(),"name" => $objExercise->name);
121
$interbreadcrumb[]= array("url" => "#","name" => get_lang('Result'));
122

    
123
$this_section = SECTION_COURSES;
124

    
125
if ($origin != 'learnpath') {
126
	Display::display_header('');
127
} else {
128
	Display::display_reduced_header();
129
}
130
?>
131
<script>
132
function showfck(sid,marksid) {
133
	document.getElementById(sid).style.display='block';
134
	document.getElementById(marksid).style.display='block';
135
	var comment = 'feedback_'+sid;
136
	document.getElementById(comment).style.display='none';
137
}
138

    
139
function getFCK(vals,marksid) {
140
	var f=document.getElementById('myform');
141

    
142
	var m_id = marksid.split(',');
143
	for(var i=0;i<m_id.length;i++){
144
		var oHidn = document.createElement("input");
145
		oHidn.type = "hidden";
146
		var selname = oHidn.name = "marks_"+m_id[i];
147
		var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
148
		oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
149
		f.appendChild(oHidn);
150
	}
151

    
152
	var ids = vals.split(',');
153
	for(var k=0;k<ids.length;k++){
154
		var oHidden = document.createElement("input");
155
		oHidden.type = "hidden";
156
		oHidden.name = "comments_"+ids[k];
157
		oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
158
		oHidden.value = oEditor.GetXHTML(true);
159
		f.appendChild(oHidden);
160
	}
161
}
162
</script>
163
<?php
164
$show_results           = true;
165
$show_only_total_score  = false;
166

    
167
// Avoiding the "Score 0/0" message  when the exe_id is not set
168
if (!empty($track_exercise_info)) {
169
    // if the results_disabled of the Quiz is 1 when block the script
170
    $result_disabled		= $track_exercise_info['results_disabled'];
171

    
172
    if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
173
        if ($result_disabled == 1) {
174
            $show_results = false;
175
            if ($origin != 'learnpath') {
176
                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
177
                      <tr>
178
                        <td colspan="2">';
179
                Display::display_warning_message(
180
                    get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>',
181
                    false
182
                );
183
                echo '</td>
184
                </tr>
185
                </table>';
186
            }
187
        } elseif ($result_disabled == 2) {
188
            $show_results = false;
189
            $show_only_total_score = true;
190
            if ($origin != 'learnpath') {
191
                echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
192
                      <tr>
193
                        <td colspan="2">';
194
                Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
195
                echo '</td>
196
                </tr>
197
                </table>';
198
            }
199
        }
200
    }
201
} else {
202
	Display::display_warning_message(get_lang('CantViewResults'));
203
	$show_results = false;
204
}
205

    
206
if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
207
	$show_results = false;
208
}
209

    
210
if ($show_results || $show_only_total_score) {
211
    $user_info = api_get_user_info($student_id);
212
    //Shows exercise header
213
    echo $objExercise->show_exercise_result_header(
214
        $user_info,
215
        api_convert_and_format_date($exercise_date)
216
    );
217
}
218

    
219
$i = $totalScore = $totalWeighting = 0;
220

    
221
if ($debug > 0){error_log("ExerciseResult: ".print_r($exerciseResult,1)); error_log("QuestionList: ".print_r($questionList,1));}
222

    
223
$arrques = array();
224
$arrans  = array();
225

    
226
$user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($student_id)." ";
227
$sql = "SELECT attempts.question_id, answer
228
        FROM ".$TBL_TRACK_ATTEMPT." as attempts
229
        INNER JOIN ".$TBL_TRACK_EXERCICES." AS stats_exercices
230
        ON stats_exercices.exe_id=attempts.exe_id
231
        INNER JOIN ".$TBL_EXERCICE_QUESTION." AS quizz_rel_questions
232
        ON
233
            quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND
234
            quizz_rel_questions.question_id = attempts.question_id AND
235
            quizz_rel_questions.c_id=".api_get_course_int_id()."
236
        INNER JOIN ".$TBL_QUESTIONS." AS questions
237
        ON
238
            questions.id=quizz_rel_questions.question_id AND
239
            questions.c_id = ".api_get_course_int_id()."
240
        WHERE attempts.exe_id = ".intval($id)." $user_restriction
241
		GROUP BY quizz_rel_questions.question_order, attempts.question_id";
242

    
243
$result = Database::query($sql);
244

    
245
$question_list_from_database = array();
246
$exerciseResult = array();
247

    
248
while ($row = Database::fetch_array($result)) {
249
	$question_list_from_database[] = $row['question_id'];
250
	$exerciseResult[$row['question_id']] = $row['answer'];
251
}
252

    
253
//Fixing #2073 Fixing order of questions
254
if (!empty($track_exercise_info['data_tracking'])) {
255
	$temp_question_list = explode(',', $track_exercise_info['data_tracking']);
256

    
257
    // Getting question list from data_tracking
258
    if (!empty($temp_question_list)) {
259
        $questionList = $temp_question_list;
260
    }
261
    // If for some reason data_tracking is empty we select the question list from db
262
    if (empty($questionList)) {
263
        $questionList = $question_list_from_database;
264
    }
265
} else {
266
    $questionList = $question_list_from_database;
267
}
268

    
269
// Display the text when finished message if we are on a LP #4227
270
$end_of_message = $objExercise->selectTextWhenFinished();
271
if (!empty($end_of_message) && ($origin == 'learnpath')) {
272
    Display::display_normal_message($end_of_message, false);
273
    echo "<div class='clear'>&nbsp;</div>";
274
}
275

    
276
// for each question
277
$total_weighting = 0;
278
foreach ($questionList as $questionId) {
279
    $objQuestionTmp     = Question::read($questionId);
280
    $total_weighting  +=$objQuestionTmp->selectWeighting();
281
}
282

    
283
$counter = 1;
284
$exercise_content = null;
285
$category_list = array();
286

    
287
foreach ($questionList as $questionId) {
288

    
289
	$choice = $exerciseResult[$questionId];
290
	// destruction of the Question object
291
	unset($objQuestionTmp);
292

    
293
	// creates a temporary Question object
294
	$objQuestionTmp 	= Question::read($questionId);
295
	$questionWeighting	= $objQuestionTmp->selectWeighting();
296
	$answerType			= $objQuestionTmp->selectType();
297

    
298
	// Start buffer
299
    ob_start();
300

    
301
    /* Use switch
302
    switch ($answerType) {
303
    }*/
304

    
305
	if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
306
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
307
        $questionScore   = $question_result['score'];
308
        $totalScore      += $question_result['score'];
309
	} elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType ==  MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
310
		$choice = array();
311
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
312
        $questionScore   = $question_result['score'];
313
        $totalScore     += $question_result['score'];
314
	} elseif ($answerType == UNIQUE_ANSWER || $answerType ==  UNIQUE_ANSWER_NO_OPTION) {
315
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
316
        $questionScore   = $question_result['score'];
317
        $totalScore     += $question_result['score'];
318
		echo '</table>';
319
	} elseif ($answerType == FILL_IN_BLANKS) {
320
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
321
        $questionScore   = $question_result['score'];
322
        $totalScore     += $question_result['score'];
323
	} elseif ($answerType == GLOBAL_MULTIPLE_ANSWER) {
324
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
325
        $questionScore   = $question_result['score'];
326
        $totalScore     += $question_result['score'];
327
	} elseif ($answerType == FREE_ANSWER) {
328
        $answer = $str;
329
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
330
        $questionScore   = $question_result['score'];
331
        $totalScore     += $question_result['score'];
332
	} elseif ($answerType == ORAL_EXPRESSION) {
333
		$answer = $str;
334
		$question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
335
		$questionScore   = $question_result['score'];
336
		$totalScore     += $question_result['score'];
337
	} elseif ($answerType == MATCHING) {
338
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
339
        $questionScore   = $question_result['score'];
340
        $totalScore     += $question_result['score'];
341
	} elseif ($answerType == HOT_SPOT) {
342
	    if ($show_results) {
343
		    echo '<table width="500" border="0"><tr>
344
                    <td valign="top" align="center" style="padding-left:0px;" >
345
                        <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
346
		}
347
        $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
348
        $questionScore  = $question_result['score'];
349
        $totalScore    += $question_result['score'];
350

    
351
        if ($show_results) {
352
			echo '</table></td></tr>';
353
		 	echo '<tr>
354
				<td colspan="2">'.
355
					'<object type="application/x-shockwave-flash" data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
356
						<param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
357
					</object>
358
				</td>
359
			</tr>
360
			</table><br/>';
361
        }
362
	} else if($answerType == HOT_SPOT_DELINEATION) {
363

    
364
        $question_result  = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
365

    
366
        $questionScore    = $question_result['score'];
367
        $totalScore      += $question_result['score'];
368

    
369
        $final_overlap    = $question_result['extra']['final_overlap'];
370
        $final_missing    = $question_result['extra']['final_missing'];
371
        $final_excess     = $question_result['extra']['final_excess'];
372

    
373
        $overlap_color    = $question_result['extra']['overlap_color'];
374
        $missing_color    = $question_result['extra']['missing_color'];
375
        $excess_color     = $question_result['extra']['excess_color'];
376

    
377
        $threadhold1      = $question_result['extra']['threadhold1'];
378
        $threadhold2      = $question_result['extra']['threadhold2'];
379
        $threadhold3      = $question_result['extra']['threadhold3'];
380

    
381
        if ($show_results) {
382

    
383
            if ($overlap_color) {
384
                $overlap_color='green';
385
            } else {
386
                $overlap_color='red';
387
            }
388

    
389
            if ($missing_color) {
390
                $missing_color='green';
391
            } else {
392
                $missing_color='red';
393
            }
394
            if ($excess_color) {
395
                $excess_color='green';
396
            } else {
397
                $excess_color='red';
398
            }
399

    
400
            if (!is_numeric($final_overlap)) {
401
                $final_overlap = 0;
402
            }
403

    
404
            if (!is_numeric($final_missing)) {
405
                $final_missing = 0;
406
            }
407
            if (!is_numeric($final_excess)) {
408
                $final_excess = 0;
409
            }
410

    
411
            if ($final_excess>100) {
412
                $final_excess = 100;
413
            }
414

    
415
            $table_resume='<table class="data_table">
416
            <tr class="row_odd" >
417
            <td></td>
418
            <td ><b>'.get_lang('Requirements').'</b></td>
419
            <td><b>'.get_lang('YourAnswer').'</b></td>
420
            </tr>
421

    
422
            <tr class="row_even">
423
            <td><b>'.get_lang('Overlap').'</b></td>
424
            <td>'.get_lang('Min').' '.$threadhold1.'</td>
425
                <td><div style="color:'.$overlap_color.'">'.(($final_overlap < 0)?0:intval($final_overlap)).'</div></td>
426
            </tr>
427

    
428
            <tr>
429
                <td><b>'.get_lang('Excess').'</b></td>
430
                <td>'.get_lang('Max').' '.$threadhold2.'</td>
431
                <td><div style="color:'.$excess_color.'">'.(($final_excess < 0)?0:intval($final_excess)).'</div></td>
432
            </tr>
433

    
434
            <tr class="row_even">
435
                <td><b>'.get_lang('Missing').'</b></td>
436
                <td>'.get_lang('Max').' '.$threadhold3.'</td>
437
                <td><div style="color:'.$missing_color.'">'.(($final_missing < 0)?0:intval($final_missing)).'</div></td>
438
            </tr></table>';
439

    
440
            if ($answerType!= HOT_SPOT_DELINEATION) {
441
                $item_list = explode('@@',$destination);
442

    
443
                $try = $item_list[0];
444
                $lp = $item_list[1];
445
                $destinationid = $item_list[2];
446
                $url = $item_list[3];
447
                $table_resume='';
448
            } else {
449
                if ($next==0) {
450
                    $try = $try_hotspot;
451
                    $lp = $lp_hotspot;
452
                    $destinationid= $select_question_hotspot;
453
                    $url=$url_hotspot;
454
                } else {
455
                    //show if no error
456
                    //echo 'no error';
457
                    $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
458
                    $answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
459
                }
460
            }
461

    
462
            echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
463
            if ($answerType == HOT_SPOT_DELINEATION) {
464
                if ($organs_at_risk_hit > 0) {
465
                    $message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
466
                    $message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
467
                } else {
468
                    $message='<p>'.get_lang('YourDelineation').'</p>';
469
                    $message.=$table_resume;
470
                    $message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
471
                }
472
                $message.='<p>'.$comment.'</p>';
473
                echo $message;
474
            } else {
475
                echo '<p>'.$comment.'</p>';
476
            }
477

    
478
            //showing the score
479
            $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." WHERE exe_id = ".intval($id)." and question_id= ".intval($questionId)."";
480
            $resfree = Database::query($queryfree);
481
            $questionScore= Database::result($resfree,0,"marks");
482
            $totalScore+=$questionScore;
483
            echo '</table></td></tr>';
484
            echo '<tr>
485
                    <td colspan="2">
486
                        <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
487
                            <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" />
488
                        </object>
489
                    </td>
490
                </tr>
491
                </table>';
492
        }
493
	}
494

    
495
	if ($show_results) {
496
	    if ($answerType != HOT_SPOT) {
497
	        echo '</table>';
498
	    }
499
	}
500

    
501
	$comnt = null;
502

    
503
    if ($show_results) {
504
		if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
505
			$name = "fckdiv".$questionId;
506
			$marksname = "marksName".$questionId;
507
			if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
508
				$url_name = get_lang('EditCommentsAndMarks');
509
			} else {
510
				if ($action=='edit') {
511
					$url_name = get_lang('EditIndividualComment');
512
				} else {
513
					$url_name = get_lang('AddComments');
514
				}
515
			}
516
            echo '<br />';
517
            echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick'=>"showfck('".$name."', '".$marksname."');"));
518
			echo '<br />';
519

    
520
            echo '<div id="feedback_'.$name.'" style="width:100%">';
521
			$comnt = trim(get_comments($id, $questionId));
522
			if (empty($comnt)) {
523
				echo '<br />';
524
			} else {
525
				echo '<div id="question_feedback">'.$comnt.'</div>';
526
			}
527
			echo '</div>';
528

    
529
            echo '<div id="'.$name.'" style="display:none">';
530
			$arrid[] = $questionId;
531
			$feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
532
			$feedback_form->addElement('html','<br>');
533
			$renderer =& $feedback_form->defaultRenderer();
534
			$renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
535
			$renderer->setElementTemplate('<div align="left">{element}</div>');
536
			$comnt = get_comments($id, $questionId);
537
			$default = array('comments_'.$questionId =>  $comnt);
538
			$feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
539
			$feedback_form->addElement('html','<br>');
540
			$feedback_form->setDefaults($default);
541
			$feedback_form->display();
542
			echo '</div>';
543

    
544
		} else {
545
			$comnt = get_comments($id, $questionId);
546
			echo '<br />';
547
			if (!empty($comnt)) {
548
				echo '<b>'.get_lang('Feedback').'</b>';
549
				echo '<div id="question_feedback">'.$comnt.'</div>';
550
			}
551
		}
552

    
553
		if ($is_allowedToEdit) {
554
			if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
555
				$marksname = "marksName".$questionId;
556
                echo '<div id="'.$marksname.'" style="display:none">';
557
                echo '<form name="marksform_'.$questionId.'" method="post" action="">';
558
				$arrmarks[] = $questionId;
559
				echo get_lang("AssignMarks");
560
				echo "&nbsp;<select name='marks' id='marks'>";
561
				for ($i=0;$i<=$questionWeighting;$i++) {
562
					echo '<option '.(($i==$questionScore)?"selected='selected'":'').'>'.$i.'</option>';
563
				}
564
				echo '</select>';
565
				echo '</form><br /></div>';
566

    
567
				if ($questionScore == -1 ) {
568
					$questionScore = 0;
569
				  	echo Display::return_message(get_lang('notCorrectedYet'));
570
				}
571
			} else {
572
				$arrmarks[] = $questionId;
573
				echo '<div id="'.$marksname.'" style="display:none"><form name="marksform_'.$questionId.'" method="post" action="">
574
					  <select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form><br/ ></div>';
575
			}
576
		} else {
577
			if ($questionScore == -1) {
578
				 $questionScore = 0;
579
			}
580
		}
581
	}
582

    
583
    $my_total_score  = $questionScore;
584
	$my_total_weight = $questionWeighting;
585
    $totalWeighting += $questionWeighting;
586
    $category_was_added_for_this_test = false;
587

    
588
    if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
589
        if (!isset($category_list[$objQuestionTmp->category]['score'])) {
590
            $category_list[$objQuestionTmp->category]['score'] = 0;
591
        }
592

    
593
        if (!isset($category_list[$objQuestionTmp->category]['total'])) {
594
            $category_list[$objQuestionTmp->category]['total'] = 0;
595
        }
596

    
597
        $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
598
        $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
599
        $category_was_added_for_this_test = true;
600
    }
601

    
602
    if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
603
        foreach($objQuestionTmp->category_list as $category_id) {
604
            $category_list[$category_id]['score'] += $my_total_score;
605
            $category_list[$category_id]['total'] += $my_total_weight;
606
            $category_was_added_for_this_test = true;
607
        }
608
    }
609

    
610
    // No category for this question!
611
    if (!isset($category_list['none']['score'])) {
612
        $category_list['none']['score'] = 0;
613
    }
614

    
615
    if (!isset($category_list['none']['total'])) {
616
        $category_list['none']['total'] = 0;
617
    }
618

    
619
    if ($category_was_added_for_this_test == false) {
620
        $category_list['none']['score'] += $my_total_score;
621
        $category_list['none']['total'] += $my_total_weight;
622
    }
623

    
624
    if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
625
        $my_total_score = 0;
626
    }
627

    
628
    $score = array();
629
    if ($show_results) {
630
		$score['result'] = get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);
631
        $score['pass']   = $my_total_score >= $my_total_weight ? true : false;
632
        $score['type']   = $answerType;
633
        $score['score']  = $my_total_score;
634
        $score['weight'] = $my_total_weight;
635
        $score['comments'] = isset($comnt) ? $comnt : null;
636
    }
637

    
638
	unset($objAnswerTmp);
639
	$i++;
640

    
641
    $contents = ob_get_clean();
642

    
643
    $question_content = '<div class="question_row">';
644

    
645
 	if ($show_results) {
646
        //Shows question title an description
647
	    $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
648
	}
649
	$counter++;
650
    $question_content .= $contents;
651
    $question_content .= '</div>';
652
    $exercise_content .= $question_content;
653
} // end of large foreach on questions
654

    
655
$total_score_text = null;
656

    
657
//Total score
658
if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
659
	if ($show_results || $show_only_total_score) {
660
        $total_score_text .= '<div class="question_row">';
661
        $my_total_score_temp = $totalScore;
662
	    if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
663
	        $my_total_score_temp = 0;
664
	    }
665
        $total_score_text .= get_question_ribbon($objExercise, $my_total_score_temp, $totalWeighting, true);
666
        $total_score_text .= '</div>';
667
	}
668
}
669

    
670
if (!empty($category_list) && ($show_results || $show_only_total_score)) {
671
    //Adding total
672
    $category_list['total'] = array(
673
        'score' => $my_total_score_temp,
674
        'total' => $totalWeighting
675
    );
676
    echo Testcategory::get_stats_table_by_attempt($objExercise->id, $category_list);
677
}
678

    
679
echo $total_score_text;
680
echo $exercise_content;
681
echo $total_score_text;
682

    
683
if (is_array($arrid) && is_array($arrmarks)) {
684
	$strids = implode(",",$arrid);
685
	$marksid = implode(",",$arrmarks);
686
}
687

    
688
if ($is_allowedToEdit && $locked == false && !api_is_drh()) {
689
	if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) {
690
		echo ' <form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=2&comments=update&exeid='.$id.'&origin='.$origin.'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';
691
		echo '<input type = "hidden" name="lp_item_id"       value="'.$learnpath_id.'">';
692
		echo '<input type = "hidden" name="lp_item_view_id"  value="'.$lp_item_view_id.'">';
693
		echo '<input type = "hidden" name="student_id"       value="'.$student_id.'">';
694
		echo '<input type = "hidden" name="total_score"      value="'.$totalScore.'"> ';
695
		echo '<input type = "hidden" name="my_exe_exo_id"    value="'.$exercise_id.'"> ';
696
	} else {
697
		echo ' <form name="myform" id="myform" action="exercise_report.php?exerciseId='.$exercise_id.'&filter=1&comments=update&exeid='.$id.'" method="post">';
698
	}
699
	if ($origin !='learnpath' && $origin!='student_progress') {
700

    
701
        echo '<label><input type= "checkbox" name="send_notification"> '.get_lang('SendEmail').'</label>';
702
		?>
703
		<button type="submit" class="btn btn-primary" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
704
            <?php echo get_lang('CorrectTest'); ?>
705
        </button>
706
		</form>
707
		<?php
708
	}
709
}
710

    
711
//Came from lpstats in a lp
712
if ($origin =='student_progress') { ?>
713
	<button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back');?></button>
714
<?php
715
} else if($origin=='myprogress') {
716
?>
717
	<button type="button" class="save" onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id()?>'" value="<?php echo get_lang('Finish'); ?>" >
718
        <?php echo get_lang('Finish');?>
719
    </button>
720
<?php
721
}
722

    
723
if ($origin != 'learnpath') {
724
	//we are not in learnpath tool
725
	Display::display_footer();
726
} else {
727
	if (!isset($_GET['fb_type'])) {
728
		$lp_mode =  $_SESSION['lp_mode'];
729
		$url = '../newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
730
		$href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
731
		echo '<script type="text/javascript">'.$href.'</script>';
732

    
733
		//Record the results in the learning path, using the SCORM interface (API)
734
		echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
735
		echo '</body></html>';
736
	} else {
737
		Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
738
        echo '<br />';
739
	}
740
}
741

    
742
// Destroying the session
743
Session::erase('questionList');
744
unset ($questionList);
745

    
746
Session::erase('exerciseResult');
747
unset ($exerciseResult);
    (1-1/1)