1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use ChamiloSession as Session; |
||
6 | |||
7 | /** |
||
8 | * Shows the exercise results. |
||
9 | * |
||
10 | * @author Julio Montoya - Added switchable fill in blank option added |
||
11 | * |
||
12 | * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $ |
||
13 | * |
||
14 | * @todo remove the debug code and use the general debug library |
||
15 | * @todo small letters for table variables |
||
16 | */ |
||
17 | require_once __DIR__.'/../inc/global.inc.php'; |
||
18 | $current_course_tool = TOOL_QUIZ; |
||
19 | $origin = api_get_origin(); |
||
20 | $currentUserId = api_get_user_id(); |
||
21 | $printHeaders = 'learnpath' === $origin; |
||
22 | $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; //exe id |
||
23 | $exportTypeAllResults = ('export' === $_GET['action'] && 'all_results' === $_GET['export_type']); |
||
24 | |||
25 | if (empty($id)) { |
||
26 | api_not_allowed(true); |
||
27 | } |
||
28 | |||
29 | // Getting results from the exe_id. This variable also contain all the information about the exercise |
||
30 | $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id); |
||
31 | |||
32 | if (empty($track_exercise_info)) { |
||
33 | api_not_allowed($printHeaders); |
||
34 | } |
||
35 | |||
36 | $exercise_id = $track_exercise_info['iid']; |
||
37 | $student_id = $track_exercise_info['exe_user_id']; |
||
38 | $learnpath_id = $track_exercise_info['orig_lp_id']; |
||
39 | $learnpath_item_id = $track_exercise_info['orig_lp_item_id']; |
||
40 | $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id']; |
||
41 | $isBossOfStudent = false; |
||
42 | if (!$exportTypeAllResults) { |
||
43 | if (api_is_student_boss()) { |
||
44 | // Check if boss has access to user info. |
||
45 | if (UserManager::userIsBossOfStudent($currentUserId, $student_id)) { |
||
46 | $isBossOfStudent = true; |
||
47 | } else { |
||
48 | api_not_allowed($printHeaders); |
||
49 | } |
||
50 | } else { |
||
51 | api_protect_course_script($printHeaders, false, true); |
||
52 | } |
||
53 | } |
||
54 | |||
55 | // Database table definitions |
||
56 | $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
||
57 | $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
||
58 | $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
||
59 | $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||
60 | |||
61 | if (empty($formSent)) { |
||
62 | $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null; |
||
63 | } |
||
64 | if (empty($exerciseResult)) { |
||
65 | $exerciseResult = Session::read('exerciseResult'); |
||
66 | } |
||
67 | |||
68 | if (empty($choiceDegreeCertainty)) { |
||
69 | $choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : null; |
||
70 | } |
||
71 | $questionId = isset($_REQUEST['questionId']) ? (int) $_REQUEST['questionId'] : null; |
||
72 | |||
73 | if (empty($choice)) { |
||
74 | $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null; |
||
75 | } |
||
76 | if (empty($questionNum)) { |
||
77 | $questionNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null; |
||
78 | } |
||
79 | if (empty($nbrQuestions)) { |
||
80 | $nbrQuestions = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null; |
||
81 | } |
||
82 | if (empty($questionList)) { |
||
83 | $questionList = Session::read('questionList'); |
||
84 | } |
||
85 | /* @var Exercise $objExercise */ |
||
86 | if (empty($objExercise)) { |
||
87 | $objExercise = Session::read('objExercise'); |
||
88 | } |
||
89 | $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null; |
||
90 | |||
91 | $courseInfo = api_get_course_info(); |
||
92 | $sessionId = api_get_session_id(); |
||
93 | |||
94 | $is_allowedToEdit = |
||
95 | api_is_allowed_to_edit(null, true) || |
||
96 | api_is_course_tutor() || |
||
97 | api_is_session_admin() || |
||
98 | api_is_drh() || |
||
99 | api_is_student_boss() || |
||
100 | $exportTypeAllResults; |
||
101 | |||
102 | if (!empty($sessionId) && !$is_allowedToEdit) { |
||
103 | if (api_is_course_session_coach( |
||
104 | $currentUserId, |
||
105 | api_get_course_int_id(), |
||
106 | $sessionId |
||
107 | )) { |
||
108 | if (!api_coach_can_edit_view_results(api_get_course_int_id(), $sessionId)) { |
||
109 | api_not_allowed($printHeaders); |
||
110 | } |
||
111 | } |
||
112 | } else { |
||
113 | if (!$is_allowedToEdit) { |
||
114 | api_not_allowed($printHeaders); |
||
115 | } |
||
116 | } |
||
117 | |||
118 | $allowCoachFeedbackExercises = 'true' === api_get_setting('allow_coach_feedback_exercises'); |
||
119 | $maxEditors = (int) api_get_setting('exercise_max_ckeditors_in_page'); |
||
120 | $isCoachAllowedToEdit = api_is_allowed_to_edit(false, true); |
||
121 | $isFeedbackAllowed = false; |
||
122 | |||
123 | if (api_is_excluded_user_type(true, $student_id)) { |
||
124 | api_not_allowed($printHeaders); |
||
125 | } |
||
126 | |||
127 | $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE); |
||
128 | |||
129 | if (empty($objExercise)) { |
||
130 | $objExercise = new Exercise(); |
||
131 | $objExercise->read($exercise_id); |
||
132 | } |
||
133 | $feedback_type = $objExercise->getFeedbackType(); |
||
134 | |||
135 | // Only users can see their own results |
||
136 | if (!$is_allowedToEdit) { |
||
137 | if ($student_id != $currentUserId) { |
||
138 | api_not_allowed($printHeaders); |
||
139 | } |
||
140 | } |
||
141 | |||
142 | $allowRecordAudio = 'true' === api_get_setting('enable_record_audio'); |
||
143 | $allowTeacherCommentAudio = true === api_get_configuration_value('allow_teacher_comment_audio'); |
||
144 | |||
145 | $js = '<script>'.api_get_language_translate_html().'</script>'; |
||
146 | $htmlHeadXtra[] = $js; |
||
147 | |||
148 | if (api_is_in_gradebook()) { |
||
149 | $interbreadcrumb[] = [ |
||
150 | 'url' => Category::getUrl(), |
||
151 | 'name' => get_lang('ToolGradebook'), |
||
152 | ]; |
||
153 | } |
||
154 | |||
155 | $interbreadcrumb[] = [ |
||
156 | 'url' => 'exercise.php?'.api_get_cidreq(), |
||
157 | 'name' => get_lang('Exercises'), |
||
158 | ]; |
||
159 | $interbreadcrumb[] = [ |
||
160 | 'url' => 'overview.php?exerciseId='.$exercise_id.'&'.api_get_cidreq(), |
||
161 | 'name' => $objExercise->selectTitle(true), |
||
162 | ]; |
||
163 | $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Result')]; |
||
164 | |||
165 | $this_section = SECTION_COURSES; |
||
166 | |||
167 | $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/css/hotspot.css">'; |
||
168 | $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>'; |
||
169 | $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'annotation/js/annotation.js"></script>'; |
||
170 | |||
171 | if ($allowRecordAudio && $allowTeacherCommentAudio) { |
||
172 | $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>'; |
||
173 | $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>'; |
||
174 | $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>'; |
||
175 | $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>'; |
||
176 | $htmlHeadXtra[] = api_get_js('record_audio/record_audio.js'); |
||
177 | } |
||
178 | |||
179 | if (RESULT_DISABLE_RADAR === (int) $objExercise->results_disabled) { |
||
180 | $htmlHeadXtra[] = api_get_js('chartjs/Chart.min.js'); |
||
181 | } |
||
182 | |||
183 | if (api_get_configuration_value('allow_skill_rel_items') == true) { |
||
184 | $htmlContentExtraClass[] = 'feature-item-user-skill-on'; |
||
185 | } |
||
186 | |||
187 | if ($action !== 'export') { |
||
188 | $scoreJsCode = ExerciseLib::getJsCode(); |
||
189 | if ($origin !== 'learnpath') { |
||
190 | Display::display_header(''); |
||
191 | } else { |
||
192 | $htmlHeadXtra[] = "<style>body { background: none; } </style>"; |
||
193 | Display::display_reduced_header(); |
||
194 | } |
||
195 | |||
196 | echo Display::toolbarAction('toolbar', [ |
||
197 | Display::url( |
||
198 | Display::return_icon('pdf.png', get_lang('Export')), |
||
199 | api_get_self().'?'.api_get_cidreq().'&id='.$id.'&action=export&' |
||
200 | ), |
||
201 | ]); ?> |
||
202 | <script> |
||
203 | <?php echo $scoreJsCode; ?> |
||
204 | var maxEditors = <?php echo $maxEditors; ?>; |
||
205 | |||
206 | function showfck(sid, marksid) { |
||
207 | $('#' + sid).toggleClass('hidden'); |
||
208 | $('#' + marksid).toggleClass('hidden'); |
||
209 | $('#feedback_' + sid).toggleClass('hidden', !$('#' + sid).is('.hidden')); |
||
210 | } |
||
211 | |||
212 | function openEmailWrapper() { |
||
213 | $('#email_content_wrapper').toggle(); |
||
214 | } |
||
215 | |||
216 | function getFCK(vals, marksid) { |
||
217 | var f = document.getElementById('form-email'); |
||
218 | |||
219 | var m_id = marksid.split(','); |
||
220 | for (var i = 0; i < m_id.length; i++) { |
||
221 | var oHidn = document.createElement("input"); |
||
222 | oHidn.type = "hidden"; |
||
223 | var selname = oHidn.name = "marks_" + m_id[i]; |
||
224 | var elMarks = document.forms['marksform_' + m_id[i]].marks; |
||
225 | |||
226 | if (elMarks.tagName.toLowerCase() === 'select') { |
||
227 | var selid = elMarks.selectedIndex; |
||
228 | oHidn.value = elMarks.options[selid].value; |
||
229 | } else if (elMarks.tagName.toLowerCase() === 'input') { |
||
230 | oHidn.value = elMarks.value; |
||
231 | } |
||
232 | |||
233 | f.appendChild(oHidn); |
||
234 | } |
||
235 | |||
236 | var ids = vals.split(','); |
||
237 | for (var k = 0; k < ids.length; k++) { |
||
238 | var oHidden = document.createElement("input"); |
||
239 | oHidden.type = "hidden"; |
||
240 | oHidden.name = "comments_" + ids[k]; |
||
241 | if (CKEDITOR.instances[oHidden.name]) { |
||
242 | oHidden.value = CKEDITOR.instances[oHidden.name].getData(); |
||
243 | } else { |
||
244 | oHidden.value = $("textarea[name='" + oHidden.name + "']").val(); |
||
245 | } |
||
246 | f.appendChild(oHidden); |
||
247 | } |
||
248 | } |
||
249 | </script> |
||
250 | <?php |
||
251 | } |
||
252 | |||
253 | $show_results = true; |
||
254 | $show_only_total_score = false; |
||
255 | $showTotalScoreAndUserChoicesInLastAttempt = true; |
||
256 | |||
257 | // Avoiding the "Score 0/0" message when the exe_id is not set |
||
258 | if (!empty($track_exercise_info)) { |
||
259 | // if the results_disabled of the Quiz is 1 when block the script |
||
260 | $result_disabled = $track_exercise_info['results_disabled']; |
||
261 | switch ($result_disabled) { |
||
262 | case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS: |
||
263 | $show_results = false; |
||
264 | break; |
||
265 | case RESULT_DISABLE_SHOW_SCORE_ONLY: |
||
266 | $show_results = false; |
||
267 | $show_only_total_score = true; |
||
268 | if ($origin !== 'learnpath') { |
||
269 | if ($currentUserId == $student_id) { |
||
270 | echo Display::return_message( |
||
271 | get_lang('ThankYouForPassingTheTest'), |
||
272 | 'warning', |
||
273 | false |
||
274 | ); |
||
275 | } |
||
276 | } |
||
277 | break; |
||
278 | case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK: |
||
279 | case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT: |
||
280 | case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK: |
||
281 | $attempts = Event::getExerciseResultsByUser( |
||
282 | $currentUserId, |
||
283 | $objExercise->iid, |
||
284 | api_get_course_int_id(), |
||
285 | api_get_session_id(), |
||
286 | $track_exercise_info['orig_lp_id'], |
||
287 | $track_exercise_info['orig_lp_item_id'], |
||
288 | 'desc' |
||
289 | ); |
||
290 | $numberAttempts = count($attempts); |
||
291 | if ($numberAttempts >= $track_exercise_info['max_attempt']) { |
||
292 | $show_results = true; |
||
293 | $show_only_total_score = true; |
||
294 | // Attempt reach max so show score/feedback now |
||
295 | $showTotalScoreAndUserChoicesInLastAttempt = true; |
||
296 | } else { |
||
297 | $show_results = true; |
||
298 | $show_only_total_score = true; |
||
299 | // Last attempt not reach don't show score/feedback |
||
300 | $showTotalScoreAndUserChoicesInLastAttempt = false; |
||
301 | } |
||
302 | |||
303 | if ($is_allowedToEdit && |
||
304 | RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT_NO_FEEDBACK == $result_disabled |
||
305 | ) { |
||
306 | $showTotalScoreAndUserChoicesInLastAttempt = true; |
||
307 | } |
||
308 | break; |
||
309 | } |
||
310 | } else { |
||
311 | echo Display::return_message(get_lang('CantViewResults'), 'warning'); |
||
312 | $show_results = false; |
||
313 | } |
||
314 | |||
315 | if ($origin === 'learnpath' && !isset($_GET['fb_type'])) { |
||
316 | $show_results = false; |
||
317 | } |
||
318 | |||
319 | if ($is_allowedToEdit && in_array($action, ['qualify', 'edit', 'export'])) { |
||
320 | $show_results = true; |
||
321 | } |
||
322 | |||
323 | if ($action === 'export') { |
||
324 | ob_start(); |
||
325 | } |
||
326 | |||
327 | $user_info = api_get_user_info($student_id); |
||
328 | if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) { |
||
329 | // Shows exercise header |
||
330 | echo $objExercise->showExerciseResultHeader( |
||
331 | $user_info, |
||
332 | $track_exercise_info, |
||
333 | false, |
||
334 | false, |
||
335 | api_get_configuration_value('quiz_results_answers_report') |
||
336 | ); |
||
337 | } |
||
338 | |||
339 | $i = $totalScore = $totalWeighting = 0; |
||
340 | $arrques = []; |
||
341 | $arrans = []; |
||
342 | $user_restriction = $is_allowedToEdit ? '' : " AND user_id = $student_id "; |
||
343 | $sql = "SELECT attempts.question_id, answer |
||
344 | FROM $TBL_TRACK_ATTEMPT as attempts |
||
345 | INNER JOIN $TBL_TRACK_EXERCISES AS stats_exercises |
||
346 | ON stats_exercises.exe_id = attempts.exe_id |
||
347 | INNER JOIN $TBL_EXERCISE_QUESTION AS quizz_rel_questions |
||
348 | ON |
||
349 | quizz_rel_questions.exercice_id=stats_exercises.exe_exo_id AND |
||
350 | quizz_rel_questions.question_id = attempts.question_id AND |
||
351 | quizz_rel_questions.c_id=".api_get_course_int_id()." |
||
352 | INNER JOIN $TBL_QUESTIONS AS questions |
||
353 | ON |
||
354 | questions.iid = quizz_rel_questions.question_id |
||
355 | WHERE |
||
356 | attempts.exe_id = $id $user_restriction |
||
357 | GROUP BY quizz_rel_questions.question_order, attempts.question_id"; |
||
358 | $result = Database::query($sql); |
||
359 | $question_list_from_database = []; |
||
360 | $exerciseResult = []; |
||
361 | while ($row = Database::fetch_array($result)) { |
||
362 | $question_list_from_database[] = $row['question_id']; |
||
363 | $exerciseResult[$row['question_id']] = $row['answer']; |
||
364 | } |
||
365 | |||
366 | // Fixing #2073 Fixing order of questions |
||
367 | if (!empty($track_exercise_info['data_tracking'])) { |
||
368 | $temp_question_list = explode(',', $track_exercise_info['data_tracking']); |
||
369 | |||
370 | // Getting question list from data_tracking |
||
371 | if (!empty($temp_question_list)) { |
||
372 | $questionList = $temp_question_list; |
||
373 | } |
||
374 | // If for some reason data_tracking is empty we select the question list from db |
||
375 | if (empty($questionList)) { |
||
376 | $questionList = $question_list_from_database; |
||
377 | } |
||
378 | } else { |
||
379 | $questionList = $question_list_from_database; |
||
380 | } |
||
381 | |||
382 | // Display the text when finished message if we are on a LP #4227 |
||
383 | $end_of_message = $objExercise->getTextWhenFinished(); |
||
384 | if (!empty($end_of_message) && ($origin === 'learnpath')) { |
||
385 | echo Display::return_message($end_of_message, 'normal', false); |
||
386 | echo "<div class='clear'> </div>"; |
||
387 | } |
||
388 | |||
389 | // for each question |
||
390 | $total_weighting = 0; |
||
391 | foreach ($questionList as $questionId) { |
||
392 | $objQuestionTmp = Question::read($questionId); |
||
393 | if ($objQuestionTmp) { |
||
394 | $total_weighting += $objQuestionTmp->selectWeighting(); |
||
395 | } |
||
396 | } |
||
397 | |||
398 | $counter = 1; |
||
399 | $exercise_content = ''; |
||
400 | $category_list = []; |
||
401 | $useAdvancedEditor = true; |
||
402 | |||
403 | if (!empty($maxEditors) && count($questionList) > $maxEditors) { |
||
404 | $useAdvancedEditor = false; |
||
405 | } |
||
406 | |||
407 | $objExercise->export = $action === 'export'; |
||
408 | $arrid = []; |
||
409 | $arrmarks = []; |
||
410 | $strids = ''; |
||
411 | $marksid = ''; |
||
412 | $countPendingQuestions = 0; |
||
413 | $audioTemplate = null; |
||
414 | if ($allowRecordAudio && $allowTeacherCommentAudio) { |
||
415 | $audioTemplate = new Template('', false, false, false, false, false, false); |
||
416 | } |
||
417 | |||
418 | foreach ($questionList as $questionId) { |
||
419 | $choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : ''; |
||
420 | // destruction of the Question object |
||
421 | unset($objQuestionTmp); |
||
422 | $questionWeighting = 0; |
||
423 | $answerType = 0; |
||
424 | $questionScore = 0; |
||
425 | // Creates a temporary Question object |
||
426 | $objQuestionTmp = Question::read($questionId); |
||
427 | if (empty($objQuestionTmp)) { |
||
428 | continue; |
||
429 | } |
||
430 | $questionWeighting = $objQuestionTmp->selectWeighting(); |
||
431 | $answerType = $objQuestionTmp->selectType(); |
||
432 | |||
433 | // Start buffer |
||
434 | ob_start(); |
||
435 | if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { |
||
436 | $choice = []; |
||
437 | } |
||
438 | |||
439 | $relPath = api_get_path(WEB_CODE_PATH); |
||
440 | switch ($answerType) { |
||
441 | case MULTIPLE_ANSWER_COMBINATION: |
||
442 | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||
443 | case UNIQUE_ANSWER: |
||
444 | case UNIQUE_ANSWER_NO_OPTION: |
||
445 | case UNIQUE_ANSWER_IMAGE: |
||
446 | case MULTIPLE_ANSWER: |
||
447 | case MULTIPLE_ANSWER_TRUE_FALSE: |
||
448 | case FILL_IN_BLANKS: |
||
449 | case FILL_IN_BLANKS_COMBINATION: |
||
450 | case CALCULATED_ANSWER: |
||
451 | case GLOBAL_MULTIPLE_ANSWER: |
||
452 | case FREE_ANSWER: |
||
453 | case UPLOAD_ANSWER: |
||
454 | case ORAL_EXPRESSION: |
||
455 | case MATCHING: |
||
456 | case MATCHING_COMBINATION: |
||
457 | case DRAGGABLE: |
||
458 | case READING_COMPREHENSION: |
||
459 | case MATCHING_DRAGGABLE: |
||
460 | case MATCHING_DRAGGABLE_COMBINATION: |
||
461 | case MULTIPLE_ANSWER_DROPDOWN: |
||
462 | case MULTIPLE_ANSWER_DROPDOWN_COMBINATION: |
||
463 | $question_result = $objExercise->manage_answer( |
||
464 | $id, |
||
465 | $questionId, |
||
466 | $choice, |
||
467 | 'exercise_show', |
||
468 | [], |
||
469 | false, |
||
470 | true, |
||
471 | $show_results, |
||
472 | $objExercise->selectPropagateNeg(), |
||
473 | [], |
||
474 | $showTotalScoreAndUserChoicesInLastAttempt |
||
475 | ); |
||
476 | $questionScore = $question_result['score']; |
||
477 | $totalScore += $question_result['score']; |
||
478 | break; |
||
479 | case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY: |
||
480 | $choiceTmp = []; |
||
481 | $choiceTmp['choice'] = $choice; |
||
482 | $choiceTmp['choiceDegreeCertainty'] = $choiceDegreeCertainty; |
||
483 | |||
484 | $questionResult = $objExercise->manage_answer( |
||
485 | $id, |
||
486 | $questionId, |
||
487 | $choiceTmp, |
||
488 | 'exercise_show', |
||
489 | [], |
||
490 | false, |
||
491 | true, |
||
492 | $show_results, |
||
493 | $objExercise->selectPropagateNeg() |
||
494 | ); |
||
495 | $questionScore = $questionResult['score']; |
||
496 | $totalScore += $questionResult['score']; |
||
497 | break; |
||
498 | case HOT_SPOT: |
||
499 | case HOT_SPOT_COMBINATION: |
||
500 | if ($show_results || $showTotalScoreAndUserChoicesInLastAttempt) { |
||
501 | // echo '<table class="table table-bordered table-striped"><tr><td>'; |
||
502 | } |
||
503 | $question_result = $objExercise->manage_answer( |
||
504 | $id, |
||
505 | $questionId, |
||
506 | $choice, |
||
507 | 'exercise_show', |
||
508 | [], |
||
509 | false, |
||
510 | true, |
||
511 | $show_results, |
||
512 | $objExercise->selectPropagateNeg(), |
||
513 | [], |
||
514 | $showTotalScoreAndUserChoicesInLastAttempt |
||
515 | ); |
||
516 | $questionScore = $question_result['score']; |
||
517 | $totalScore += $question_result['score']; |
||
518 | |||
519 | if ($show_results || $showTotalScoreAndUserChoicesInLastAttempt) { |
||
520 | echo '</table></td></tr>'; |
||
521 | echo " |
||
522 | <tr> |
||
523 | <td> |
||
524 | <div id=\"hotspot-solution-$questionId-$id\"></div> |
||
525 | <script> |
||
526 | $(function() { |
||
527 | new HotspotQuestion({ |
||
528 | questionId: $questionId, |
||
529 | exerciseId: {$objExercise->iid}, |
||
530 | exeId: $id, |
||
531 | selector: '#hotspot-solution-$questionId-$id', |
||
532 | for: 'solution', |
||
533 | relPath: '$relPath' |
||
534 | }); |
||
535 | }); |
||
536 | </script> |
||
537 | </td> |
||
538 | </tr> |
||
539 | </table> |
||
540 | <br> |
||
541 | "; |
||
542 | } |
||
543 | break; |
||
544 | case HOT_SPOT_DELINEATION: |
||
545 | $question_result = $objExercise->manage_answer( |
||
546 | $id, |
||
547 | $questionId, |
||
548 | $choice, |
||
549 | 'exercise_show', |
||
550 | [], |
||
551 | false, |
||
552 | true, |
||
553 | $show_results, |
||
554 | $objExercise->selectPropagateNeg(), |
||
555 | 'database', |
||
556 | [], |
||
557 | $showTotalScoreAndUserChoicesInLastAttempt |
||
558 | ); |
||
559 | |||
560 | $questionScore = $question_result['score']; |
||
561 | $totalScore += $question_result['score']; |
||
562 | |||
563 | //$organs_at_risk_hit |
||
564 | echo $objExercise->getDelineationResult($objQuestionTmp, $questionId, $show_results, $question_result); |
||
565 | break; |
||
566 | case ANNOTATION: |
||
567 | $question_result = $objExercise->manage_answer( |
||
568 | $id, |
||
569 | $questionId, |
||
570 | $choice, |
||
571 | 'exercise_show', |
||
572 | [], |
||
573 | false, |
||
574 | true, |
||
575 | $show_results, |
||
576 | $objExercise->selectPropagateNeg(), |
||
577 | [], |
||
578 | $showTotalScoreAndUserChoicesInLastAttempt |
||
579 | ); |
||
580 | $questionScore = $question_result['score']; |
||
581 | $totalScore += $question_result['score']; |
||
582 | |||
583 | if ($show_results) { |
||
584 | echo ' |
||
585 | <div id="annotation-canvas-'.$questionId.'"></div> |
||
586 | <script> |
||
587 | AnnotationQuestion({ |
||
588 | questionId: '.(int) $questionId.', |
||
589 | exerciseId: '.(int) $id.', |
||
590 | relPath: \''.$relPath.'\', |
||
591 | courseId: '.(int) $courseInfo['real_id'].' |
||
592 | }); |
||
593 | </script> |
||
594 | '; |
||
595 | } |
||
596 | break; |
||
597 | } |
||
598 | |||
599 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { |
||
600 | echo '</table>'; |
||
601 | } |
||
602 | |||
603 | if ($show_results && !in_array($answerType, [HOT_SPOT_COMBINATION, HOT_SPOT])) { |
||
604 | echo '</table>'; |
||
605 | } |
||
606 | |||
607 | $comnt = null; |
||
608 | if ($show_results) { |
||
609 | if ($is_allowedToEdit && $locked == false && !api_is_drh() && $isCoachAllowedToEdit) { |
||
610 | $isFeedbackAllowed = true; |
||
611 | } elseif (!$isCoachAllowedToEdit && $allowCoachFeedbackExercises) { |
||
612 | $isFeedbackAllowed = true; |
||
613 | } |
||
614 | // Boss cannot edit exercise result |
||
615 | if ($isBossOfStudent) { |
||
616 | $isFeedbackAllowed = false; |
||
617 | } |
||
618 | $marksname = ''; |
||
619 | if ($isFeedbackAllowed && $action !== 'export') { |
||
620 | $name = 'fckdiv'.$questionId; |
||
621 | $marksname = 'marksName'.$questionId; |
||
622 | if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { |
||
623 | $url_name = get_lang('EditCommentsAndMarks'); |
||
624 | } else { |
||
625 | $url_name = get_lang('AddComments'); |
||
626 | if ($action === 'edit') { |
||
627 | $url_name = get_lang('EditIndividualComment'); |
||
628 | } |
||
629 | } |
||
630 | echo '<p>'; |
||
631 | echo Display::button( |
||
632 | 'show_ck', |
||
633 | $url_name, |
||
634 | [ |
||
635 | 'type' => 'button', |
||
636 | 'class' => 'btn btn-default', |
||
637 | 'onclick' => "showfck('".$name."', '".$marksname."');", |
||
638 | ] |
||
639 | ); |
||
640 | echo '</p>'; |
||
641 | |||
642 | echo '<div id="feedback_'.$name.'" class="show">'; |
||
643 | $comnt = Event::get_comments($id, $questionId); |
||
644 | if (!empty($comnt)) { |
||
645 | echo ExerciseLib::getFeedbackText($comnt); |
||
646 | } |
||
647 | echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id); |
||
648 | echo '</div>'; |
||
649 | |||
650 | echo '<div id="'.$name.'" class="row hidden">'; |
||
651 | echo '<div class="col-sm-'.($allowTeacherCommentAudio ? 7 : 12).'">'; |
||
652 | |||
653 | $arrid[] = $questionId; |
||
654 | $feedback_form = new FormValidator('frmcomments'.$questionId); |
||
655 | $renderer = &$feedback_form->defaultRenderer(); |
||
656 | $renderer->setFormTemplate('<form{attributes}><div>{content}</div></form>'); |
||
657 | $renderer->setCustomElementTemplate('<div>{element}</div>'); |
||
658 | $textareaId = 'comments_'.$questionId; |
||
659 | $default = [$textareaId => $comnt]; |
||
660 | |||
661 | if ($useAdvancedEditor) { |
||
662 | $feedback_form->addElement( |
||
663 | 'html_editor', |
||
664 | $textareaId, |
||
665 | null, |
||
666 | ['id' => $textareaId], |
||
667 | [ |
||
668 | 'ToolbarSet' => 'TestAnswerFeedback', |
||
669 | 'Width' => '100%', |
||
670 | 'Height' => '120', |
||
671 | ] |
||
672 | ); |
||
673 | } else { |
||
674 | $feedback_form->addElement('textarea', $textareaId, ['id' => $textareaId]); |
||
675 | } |
||
676 | $feedback_form->setDefaults($default); |
||
677 | $feedback_form->display(); |
||
678 | echo '</div>'; |
||
679 | |||
680 | if ($allowRecordAudio && $allowTeacherCommentAudio) { |
||
681 | echo '<div class="col-sm-5">'; |
||
682 | echo ExerciseLib::getOralFeedbackForm($audioTemplate, $id, $questionId, $student_id); |
||
683 | echo '</div>'; |
||
684 | } |
||
685 | echo '</div>'; |
||
686 | } else { |
||
687 | $comnt = Event::get_comments($id, $questionId); |
||
688 | echo '<br />'; |
||
689 | if (!empty($comnt)) { |
||
690 | echo '<b>'.get_lang('Feedback').'</b>'; |
||
691 | echo ExerciseLib::getFeedbackText($comnt); |
||
692 | echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id); |
||
693 | } |
||
694 | } |
||
695 | |||
696 | if ($is_allowedToEdit && $isFeedbackAllowed && $action !== 'export') { |
||
697 | if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { |
||
698 | $marksname = 'marksName'.$questionId; |
||
699 | $arrmarks[] = $questionId; |
||
700 | |||
701 | echo '<div id="'.$marksname.'" class="hidden">'; |
||
702 | |||
703 | $allowDecimalScore = api_get_configuration_value('quiz_open_question_decimal_score'); |
||
704 | $formMark = new FormValidator('marksform_'.$questionId, 'post'); |
||
705 | $formMark->addHeader(get_lang('AssignMarks')); |
||
706 | $model = ExerciseLib::getCourseScoreModel(); |
||
707 | |||
708 | if ($allowDecimalScore && empty($model)) { |
||
709 | $formMark->addElement( |
||
710 | 'number', |
||
711 | 'marks', |
||
712 | get_lang('AssignMarks'), |
||
713 | [ |
||
714 | 'step' => 0.01, |
||
715 | 'min' => 0, |
||
716 | 'max' => $questionWeighting, |
||
717 | 'placeholder' => 0, |
||
718 | 'class' => 'grade_select', |
||
719 | 'id' => "select_marks_$questionId", |
||
720 | ] |
||
721 | ); |
||
722 | $formMark->setDefaults(['marks' => $questionScore]); |
||
723 | $formMark->applyFilter('marks', 'stripslashes'); |
||
724 | $formMark->applyFilter('marks', 'trim'); |
||
725 | $formMark->applyFilter('marks', 'floatval'); |
||
726 | $formMark->addRule('marks', get_lang('Numeric'), 'numeric'); |
||
727 | $formMark->addRule('marks', get_lang('ValueTooSmall'), 'min_numeric_length', 0); |
||
728 | $formMark->addRule('marks', get_lang('ValueTooBig'), 'max_numeric_length', $questionWeighting); |
||
729 | } else { |
||
730 | $select = $formMark->addSelect( |
||
731 | 'marks', |
||
732 | get_lang('AssignMarks'), |
||
733 | [], |
||
734 | ['disable_js' => true, 'extra_class' => 'grade_select'] |
||
735 | ); |
||
736 | |||
737 | if (empty($model)) { |
||
738 | for ($i = 0; $i <= $questionWeighting; $i++) { |
||
739 | $attributes = []; |
||
740 | if ($questionScore == $i) { |
||
741 | $attributes['selected'] = 'selected'; |
||
742 | } |
||
743 | $select->addOption($i, $i, $attributes); |
||
744 | } |
||
745 | } else { |
||
746 | foreach ($model['score_list'] as $item) { |
||
747 | $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2); |
||
748 | $model = ExerciseLib::getModelStyle($item, $i); |
||
749 | $attributes = ['class' => $item['css_class']]; |
||
750 | if ($questionScore == $i) { |
||
751 | $attributes['selected'] = 'selected'; |
||
752 | } |
||
753 | $select->addOption($model, $i, $attributes); |
||
754 | } |
||
755 | $select->updateSelectWithSelectedOption($formMark); |
||
756 | } |
||
757 | } |
||
758 | |||
759 | $formMark->display(); |
||
760 | echo '</div>'; |
||
761 | if ($questionScore == -1) { |
||
762 | $questionScore = 0; |
||
763 | echo ExerciseLib::getNotCorrectedYetText(); |
||
764 | } |
||
765 | } else { |
||
766 | $arrmarks[] = $questionId; |
||
767 | echo ' |
||
768 | <div id="'.$marksname.'" class="hidden"> |
||
769 | <form name="marksform_'.$questionId.'" method="post" action=""> |
||
770 | <select |
||
771 | name="marks" |
||
772 | id="select_marks_'.$questionId.'" |
||
773 | style="display:none;" |
||
774 | class="exercise_mark_select" |
||
775 | > |
||
776 | <option value="'.$questionScore.'" >'.$questionScore.'</option> |
||
777 | </select> |
||
778 | </form> |
||
779 | <br/> |
||
780 | </div> |
||
781 | '; |
||
782 | } |
||
783 | } else { |
||
784 | if ($questionScore == -1) { |
||
785 | $questionScore = 0; |
||
786 | } |
||
787 | } |
||
788 | } |
||
789 | |||
790 | $my_total_score = $questionScore; |
||
791 | $my_total_weight = $questionWeighting; |
||
792 | $totalWeighting += $questionWeighting; |
||
793 | $category_was_added_for_this_test = false; |
||
794 | if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) { |
||
795 | if (!isset($category_list[$objQuestionTmp->category]['score'])) { |
||
796 | $category_list[$objQuestionTmp->category]['score'] = 0; |
||
797 | } |
||
798 | |||
799 | if (!isset($category_list[$objQuestionTmp->category]['total'])) { |
||
800 | $category_list[$objQuestionTmp->category]['total'] = 0; |
||
801 | } |
||
802 | |||
803 | $category_list[$objQuestionTmp->category]['score'] += $my_total_score; |
||
804 | $category_list[$objQuestionTmp->category]['total'] += $my_total_weight; |
||
805 | $category_was_added_for_this_test = true; |
||
806 | } |
||
807 | |||
808 | if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) { |
||
809 | foreach ($objQuestionTmp->category_list as $category_id) { |
||
810 | $category_list[$category_id]['score'] += $my_total_score; |
||
811 | $category_list[$category_id]['total'] += $my_total_weight; |
||
812 | $category_was_added_for_this_test = true; |
||
813 | } |
||
814 | } |
||
815 | |||
816 | // No category for this question! |
||
817 | if (!isset($category_list['none']['score'])) { |
||
818 | $category_list['none']['score'] = 0; |
||
819 | } |
||
820 | |||
821 | if (!isset($category_list['none']['total'])) { |
||
822 | $category_list['none']['total'] = 0; |
||
823 | } |
||
824 | |||
825 | if ($category_was_added_for_this_test == false) { |
||
826 | $category_list['none']['score'] += $my_total_score; |
||
827 | $category_list['none']['total'] += $my_total_weight; |
||
828 | } |
||
829 | |||
830 | if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) { |
||
831 | $my_total_score = 0; |
||
832 | } |
||
833 | |||
834 | $score = []; |
||
835 | if ($show_results) { |
||
836 | $scorePassed = ExerciseLib::scorePassed($my_total_score, $my_total_weight); |
||
837 | $score['result'] = ExerciseLib::show_score( |
||
838 | $my_total_score, |
||
839 | $my_total_weight, |
||
840 | false, |
||
841 | false |
||
842 | ); |
||
843 | $score['pass'] = $scorePassed; |
||
844 | $score['type'] = $answerType; |
||
845 | $score['score'] = $my_total_score; |
||
846 | $score['weight'] = $my_total_weight; |
||
847 | $score['comments'] = isset($comnt) ? $comnt : null; |
||
848 | |||
849 | if (isset($question_result['user_answered'])) { |
||
850 | $score['user_answered'] = $question_result['user_answered']; |
||
851 | } |
||
852 | } |
||
853 | |||
854 | if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION, UPLOAD_ANSWER])) { |
||
855 | $scoreToReview = [ |
||
856 | 'score' => $my_total_score, |
||
857 | 'comments' => isset($comnt) ? $comnt : null, |
||
858 | ]; |
||
859 | $check = $objQuestionTmp->isQuestionWaitingReview($scoreToReview); |
||
860 | if ($check === false) { |
||
861 | $countPendingQuestions++; |
||
862 | } |
||
863 | } |
||
864 | |||
865 | unset($objAnswerTmp); |
||
866 | $i++; |
||
867 | |||
868 | $contents = ob_get_clean(); |
||
869 | $question_content = '<div class="question_row">'; |
||
870 | if ($show_results && $objQuestionTmp) { |
||
871 | $objQuestionTmp->export = $action === 'export'; |
||
872 | // Shows question title an description |
||
873 | $question_content .= $objQuestionTmp->return_header( |
||
874 | $objExercise, |
||
875 | $counter, |
||
876 | $score |
||
877 | ); |
||
878 | } |
||
879 | $counter++; |
||
880 | $question_content .= $contents; |
||
881 | $question_content .= '</div>'; |
||
882 | $exercise_content .= Display::panel($question_content); |
||
883 | } // end of large foreach on questions |
||
884 | |||
885 | $totalScoreText = ''; |
||
886 | if ($answerType != MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) { |
||
887 | $pluginEvaluation = QuestionOptionsEvaluationPlugin::create(); |
||
888 | |||
889 | if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) { |
||
890 | $formula = $pluginEvaluation->getFormulaForExercise($objExercise->selectId()); |
||
891 | |||
892 | if (!empty($formula)) { |
||
893 | $totalScore = $pluginEvaluation->getResultWithFormula($id, $formula); |
||
894 | $totalWeighting = $pluginEvaluation->getMaxScore(); |
||
895 | } |
||
896 | } |
||
897 | } |
||
898 | |||
899 | // Total score |
||
900 | $myTotalScoreTemp = $totalScore; |
||
901 | if ($origin !== 'learnpath' || ($origin === 'learnpath' && isset($_GET['fb_type']))) { |
||
902 | if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) { |
||
903 | $totalScoreText .= '<div class="question_row">'; |
||
904 | if ($objExercise->selectPropagateNeg() == 0 && $myTotalScoreTemp < 0) { |
||
905 | $myTotalScoreTemp = 0; |
||
906 | } |
||
907 | |||
908 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) { |
||
909 | $totalScoreText .= ExerciseLib::getQuestionDiagnosisRibbon( |
||
910 | $objExercise, |
||
911 | $myTotalScoreTemp, |
||
912 | $totalWeighting, |
||
913 | true |
||
914 | ); |
||
915 | } else { |
||
916 | $totalScoreText .= ExerciseLib::getTotalScoreRibbon( |
||
917 | $objExercise, |
||
918 | $myTotalScoreTemp, |
||
919 | $totalWeighting, |
||
920 | true, |
||
921 | $countPendingQuestions |
||
922 | ); |
||
923 | } |
||
924 | |||
925 | $totalScoreText .= '</div>'; |
||
926 | } |
||
927 | } |
||
928 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) { |
||
929 | $chartMultiAnswer = MultipleAnswerTrueFalseDegreeCertainty::displayStudentsChartResults($id, $objExercise); |
||
930 | echo $chartMultiAnswer; |
||
931 | } |
||
932 | |||
933 | if (!empty($category_list) && |
||
934 | ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) |
||
935 | ) { |
||
936 | // Adding total. |
||
937 | $category_list['total'] = [ |
||
938 | 'score' => $myTotalScoreTemp, |
||
939 | 'total' => $totalWeighting, |
||
940 | ]; |
||
941 | echo TestCategory::get_stats_table_by_attempt($objExercise, $category_list); |
||
942 | } |
||
943 | |||
944 | if (in_array( |
||
945 | $track_exercise_info['results_disabled'], |
||
946 | [RESULT_DISABLE_RANKING, RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING] |
||
947 | )) { |
||
948 | echo Display::page_header(get_lang('Ranking'), null, 'h4'); |
||
949 | echo ExerciseLib::displayResultsInRanking( |
||
950 | $objExercise, |
||
951 | $student_id, |
||
952 | $courseInfo['real_id'], |
||
953 | $sessionId |
||
954 | ); |
||
955 | } |
||
956 | |||
957 | echo $totalScoreText; |
||
958 | echo $exercise_content; |
||
959 | |||
960 | // only show "score" in bottom of page if there's exercise content |
||
961 | if ($show_results) { |
||
962 | echo $totalScoreText; |
||
963 | } |
||
964 | |||
965 | if ('export' === $action) { |
||
966 | $content = ob_get_clean(); |
||
967 | // needed in order to mpdf to work |
||
968 | if (ob_get_contents()) { |
||
969 | ob_clean(); |
||
970 | } |
||
971 | |||
972 | $content = Security::remove_XSS($content); |
||
973 | |||
974 | $params = [ |
||
975 | 'filename' => api_replace_dangerous_char( |
||
976 | $objExercise->name.' '. |
||
977 | $user_info['complete_name'].' '. |
||
978 | api_get_local_time() |
||
979 | ), |
||
980 | 'course_code' => api_get_course_id(), |
||
981 | 'session_info' => api_get_session_info(api_get_session_id()), |
||
982 | 'course_info' => '', |
||
983 | 'pdf_date' => '', |
||
984 | 'show_real_course_teachers' => false, |
||
985 | 'show_teacher_as_myself' => false, |
||
986 | 'orientation' => 'P', |
||
987 | ]; |
||
988 | $pdf = new PDF('A4', $params['orientation'], $params); |
||
989 | if ('all_results' === $_GET['export_type']) { |
||
990 | $sessionId = api_get_session_id(); |
||
991 | $courseId = api_get_course_int_id(); |
||
992 | $exportName = 'S'.$sessionId.'-C'.$courseId.'-T'.$exercise_id; |
||
993 | $baseDir = api_get_path(SYS_ARCHIVE_PATH); |
||
994 | $folderName = 'pdfexport-'.$exportName; |
||
995 | $exportFolderPath = $baseDir.$folderName; |
||
996 | if (!is_dir($exportFolderPath)) { |
||
997 | @mkdir($exportFolderPath); |
||
0 ignored issues
–
show
|
|||
998 | } |
||
999 | $pdfFileName = $user_info['firstname'].' '.$user_info['lastname'].'-attemptId'.$id.'.pdf'; |
||
1000 | $pdfFileName = api_replace_dangerous_char($pdfFileName); |
||
1001 | $fileNameToSave = $exportFolderPath.'/'.$pdfFileName; |
||
1002 | $pdf->html_to_pdf_with_template($content, true, false, true, [], 'F', $fileNameToSave); |
||
1003 | } else { |
||
1004 | $pdf->html_to_pdf_with_template($content, false, false, true); |
||
1005 | } |
||
1006 | |||
1007 | exit; |
||
1008 | } |
||
1009 | |||
1010 | if ($isFeedbackAllowed) { |
||
1011 | if (is_array($arrid) && is_array($arrmarks)) { |
||
1012 | $strids = implode(',', $arrid); |
||
1013 | $marksid = implode(',', $arrmarks); |
||
1014 | } |
||
1015 | } |
||
1016 | |||
1017 | if ($isFeedbackAllowed && $origin !== 'learnpath' && $origin !== 'student_progress') { |
||
1018 | if (in_array($origin, ['tracking_course', 'user_course', 'correct_exercise_in_lp'])) { |
||
1019 | $formUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&'; |
||
1020 | $formUrl .= http_build_query([ |
||
1021 | 'exerciseId' => $exercise_id, |
||
1022 | 'filter' => 2, |
||
1023 | 'comments' => 'update', |
||
1024 | 'exeid' => $id, |
||
1025 | 'origin' => $origin, |
||
1026 | 'details' => 'true', |
||
1027 | 'course' => Security::remove_XSS($_GET['cidReq']), |
||
1028 | ]); |
||
1029 | |||
1030 | $emailForm = new FormValidator('form-email', 'post', $formUrl, '', ['id' => 'form-email']); |
||
1031 | $emailForm->addHidden('lp_item_id', $learnpath_id); |
||
1032 | $emailForm->addHidden('lp_item_view_id', $lp_item_view_id); |
||
1033 | $emailForm->addHidden('student_id', $student_id); |
||
1034 | $emailForm->addHidden('total_score', $totalScore); |
||
1035 | $emailForm->addHidden('my_exe_exo_id', $exercise_id); |
||
1036 | } else { |
||
1037 | $formUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&'; |
||
1038 | $formUrl .= http_build_query([ |
||
1039 | 'exerciseId' => $exercise_id, |
||
1040 | 'filter' => 1, |
||
1041 | 'comments' => 'update', |
||
1042 | 'exeid' => $id, |
||
1043 | ]); |
||
1044 | |||
1045 | $emailForm = new FormValidator( |
||
1046 | 'form-email', |
||
1047 | 'post', |
||
1048 | $formUrl, |
||
1049 | '', |
||
1050 | ['id' => 'form-email'] |
||
1051 | ); |
||
1052 | } |
||
1053 | |||
1054 | if ($objExercise->results_disabled != RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS) { |
||
1055 | $emailForm->addCheckBox( |
||
1056 | 'send_notification', |
||
1057 | get_lang('SendEmail'), |
||
1058 | get_lang('SendEmail'), |
||
1059 | ['onclick' => 'openEmailWrapper();'] |
||
1060 | ); |
||
1061 | $emailForm->addHtml('<div id="email_content_wrapper" style="display:none; margin-bottom: 20px;">'); |
||
1062 | $emailForm->addHtmlEditor( |
||
1063 | 'notification_content', |
||
1064 | get_lang('Content'), |
||
1065 | false |
||
1066 | ); |
||
1067 | $emailForm->addHtml('</div>'); |
||
1068 | } |
||
1069 | |||
1070 | if (empty($track_exercise_info['orig_lp_id']) || empty($track_exercise_info['orig_lp_item_id'])) { |
||
1071 | // Default url |
||
1072 | $url = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq() |
||
1073 | .'&show_headers=1&id_session='.api_get_session_id(); |
||
1074 | } else { |
||
1075 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&item_id=' |
||
1076 | .$track_exercise_info['orig_lp_item_id'].'&lp_id='.$track_exercise_info['orig_lp_id'].'&'.api_get_cidreq() |
||
1077 | .'&id_session='.api_get_session_id(); |
||
1078 | } |
||
1079 | |||
1080 | Skill::addSkillsToUserForm( |
||
1081 | $emailForm, |
||
1082 | ITEM_TYPE_EXERCISE, |
||
1083 | $exercise_id, |
||
1084 | $student_id, |
||
1085 | $track_exercise_info['exe_id'], |
||
1086 | true |
||
1087 | ); |
||
1088 | |||
1089 | $content = ExerciseLib::getEmailNotification( |
||
1090 | $currentUserId, |
||
1091 | api_get_course_info(), |
||
1092 | $track_exercise_info['title'], |
||
1093 | $url |
||
1094 | ); |
||
1095 | $emailForm->setDefaults(['notification_content' => $content]); |
||
1096 | $emailForm->addButtonSend( |
||
1097 | get_lang('CorrectTest'), |
||
1098 | 'submit', |
||
1099 | false, |
||
1100 | ['onclick' => "getFCK('$strids', '$marksid')"] |
||
1101 | ); |
||
1102 | echo $emailForm->returnForm(); |
||
1103 | } |
||
1104 | |||
1105 | //Came from lpstats in a lp |
||
1106 | if ($origin === 'student_progress') { |
||
1107 | ?> |
||
1108 | <button type="button" class="back" onclick="window.history.go(-1);" value="<?php echo get_lang('Back'); ?>"> |
||
1109 | <?php echo get_lang('Back'); ?> |
||
1110 | </button> |
||
1111 | <?php |
||
1112 | } elseif ($origin === 'myprogress') { |
||
1113 | ?> |
||
1114 | <button type="button" class="save" |
||
1115 | onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id(); ?>'" |
||
1116 | value="<?php echo get_lang('Finish'); ?>"> |
||
1117 | <?php echo get_lang('Finish'); ?> |
||
1118 | </button> |
||
1119 | <?php |
||
1120 | } |
||
1121 | |||
1122 | if ($origin !== 'learnpath') { |
||
1123 | //we are not in learnpath tool |
||
1124 | Display::display_footer(); |
||
1125 | } else { |
||
1126 | if (!isset($_GET['fb_type'])) { |
||
1127 | $lp_mode = Session::read('lp_mode'); |
||
1128 | $url = '../lp/lp_controller.php?'.api_get_cidreq().'&'; |
||
1129 | $url .= http_build_query([ |
||
1130 | 'action' => 'view', |
||
1131 | 'lp_id' => $learnpath_id, |
||
1132 | 'lp_item_id' => $learnpath_item_id, |
||
1133 | 'exeId' => $id, |
||
1134 | 'fb_type' => $feedback_type, |
||
1135 | ]); |
||
1136 | $href = ($lp_mode === 'fullscreen') |
||
1137 | ? ' window.opener.location.href="'.$url.'" ' |
||
1138 | : ' top.location.href="'.$url.'" '; |
||
1139 | echo '<script type="text/javascript">'.$href.'</script>'; |
||
1140 | // Record the results in the learning path, using the SCORM interface (API) |
||
1141 | echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>"; |
||
1142 | echo '</body></html>'; |
||
1143 | } else { |
||
1144 | echo Display::return_message( |
||
1145 | get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'), |
||
1146 | 'normal' |
||
1147 | ); |
||
1148 | echo '<br />'; |
||
1149 | } |
||
1150 | } |
||
1151 | |||
1152 | Session::erase('questionList'); |
||
1153 | unset($questionList); |
||
1154 | Session::erase('exerciseResult'); |
||
1155 | unset($exerciseResult); |
||
1156 | Session::erase('calculatedAnswerId'); |
||
1157 |
If you suppress an error, we recommend checking for the error condition explicitly: