diff --git a/main/exercise/exercise_result.php b/main/exercise/exercise_result.php
index e16d9f0ef8..d3b33d4384 100755
--- a/main/exercise/exercise_result.php
+++ b/main/exercise/exercise_result.php
@@ -212,7 +212,9 @@ $stats = ExerciseLib::displayQuestionListByAttempt(
$objExercise,
$exe_id,
$saveResults,
- $remainingMessage
+ $remainingMessage,
+ false,
+ api_get_configuration_value('quiz_results_answers_report')
);
$pageContent .= ob_get_contents();
ob_end_clean();
@@ -428,7 +430,6 @@ if (!in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
if (api_is_allowed_to_session_edit()) {
Exercise::cleanSessionVariables();
}
-
Session::write('attempt_remaining', $remainingMessage);
$showFooter = false;
} else {
@@ -446,7 +447,6 @@ if (!in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
// Record the results in the learning path, using the SCORM interface (API)
$pageBottom .= "";
$pageBottom .= '';
-
$showFooter = false;
}
diff --git a/main/exercise/result.php b/main/exercise/result.php
index 51db64dd02..2276fe7caa 100755
--- a/main/exercise/result.php
+++ b/main/exercise/result.php
@@ -13,6 +13,7 @@ require_once __DIR__.'/../inc/global.inc.php';
$id = isset($_REQUEST['id']) ? (int) $_GET['id'] : 0; // exe id
$show_headers = isset($_REQUEST['show_headers']) ? (int) $_REQUEST['show_headers'] : null;
+$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
$origin = api_get_origin();
if (in_array($origin, ['learnpath', 'embeddable', 'mobileapp'])) {
@@ -105,17 +106,59 @@ if ($show_headers) {
$message = Session::read('attempt_remaining');
Session::erase('attempt_remaining');
+$allowExportPdf = api_get_configuration_value('quiz_results_answers_report');
+
ob_start();
-ExerciseLib::displayQuestionListByAttempt(
+$stats = ExerciseLib::displayQuestionListByAttempt(
$objExercise,
$id,
false,
$message,
- $allowSignature
+ $allowSignature,
+ $allowExportPdf
);
$pageContent = ob_get_contents();
ob_end_clean();
+switch ($action) {
+ case 'export':
+ if ($allowExportPdf) {
+ $allAnswers = $stats['all_answers_html'];
+ @$pdf = new PDF();
+ $cssFile = api_get_path(SYS_CSS_PATH).'themes/chamilo/default.css';
+ $title = get_lang('ResponseReport');
+ $exerciseTitle = $objExercise->get_formated_title();
+ $studentInfo = api_get_user_info($student_id);
+ $userHeader = $objExercise->showExerciseResultHeader(
+ $studentInfo,
+ $track_exercise_info,
+ false,
+ false,
+ false
+ );
+ $filename = get_lang('Exercise').'_'.$exerciseTitle;
+ $pdf->content_to_pdf("
+
+ $title
+ $userHeader
+ $allAnswers
+ ",
+ file_get_contents($cssFile),
+ $filename,
+ api_get_course_id(),
+ 'D',
+ false,
+ null,
+ false,
+ true
+ );
+ } else {
+ api_not_allowed(true);
+ }
+ exit;
+ break;
+}
+
$template = new Template('', $show_headers, $show_headers);
$template->assign('page_content', $pageContent);
$template->assign('allow_signature', $allowSignature);
diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php
index a8a90a5625..e1a2ff31ad 100644
--- a/main/inc/lib/exercise.lib.php
+++ b/main/inc/lib/exercise.lib.php
@@ -4434,13 +4434,16 @@ EOT;
* @param bool $save_user_result save users results (true) or just show the results (false)
* @param string $remainingMessage
* @param bool $allowSignature
+ * @param bool $allowExportPdf
+ *
*/
public static function displayQuestionListByAttempt(
$objExercise,
$exeId,
$save_user_result = false,
$remainingMessage = '',
- $allowSignature = false
+ $allowSignature = false,
+ $allowExportPdf = false
) {
$origin = api_get_origin();
$courseId = api_get_course_int_id();
@@ -4587,6 +4590,11 @@ EOT;
}
}
+ if ($allowExportPdf) {
+ $showTotalScore = false;
+ $showQuestionScore = false;
+ }
+
if ('embeddable' !== $origin &&
!empty($exercise_stat_info['exe_user_id']) &&
!empty($studentInfo)
@@ -4596,7 +4604,8 @@ EOT;
$studentInfo,
$exercise_stat_info,
$save_user_result,
- $allowSignature
+ $allowSignature,
+ $allowExportPdf
);
}
diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php
index 8c39a6798a..b9e7282a92 100755
--- a/main/install/configuration.dist.php
+++ b/main/install/configuration.dist.php
@@ -1702,6 +1702,9 @@ $_configuration['auth_password_links'] = [
// Use exercise score in platform settings in gradebook total rows/columns.
//$_configuration['gradebook_use_exercise_score_settings_in_total'] = false;
+// Show a link on the results page to download an answers report
+// $_configuration['quiz_results_answers_report'] = false;
+
// KEEP THIS AT THE END
// -------- Custom DB changes
// Add user activation by confirmation email
diff --git a/main/lang/english/trad4all.inc.php b/main/lang/english/trad4all.inc.php
index a7a256451a..3975967fa5 100644
--- a/main/lang/english/trad4all.inc.php
+++ b/main/lang/english/trad4all.inc.php
@@ -8676,4 +8676,6 @@ $CourseUsedInOtherURL = "This course is used in at least one other portal";
$SubscribeUserGroupsToLp = "Add classes to a learning path";
$ReplaceFile = "Replace file";
$SubscribeClassesToLpCategory = "Subscribe classes to category";
+$ExportResponseReport = "Export response report";
+$ResponseReport = "Response report";
?>
\ No newline at end of file
diff --git a/main/lang/spanish/trad4all.inc.php b/main/lang/spanish/trad4all.inc.php
index fe45b9da0b..fa23641f98 100644
--- a/main/lang/spanish/trad4all.inc.php
+++ b/main/lang/spanish/trad4all.inc.php
@@ -8704,4 +8704,6 @@ $CourseUsedInOtherURL = "Este curso es usado en otro portal";
$SubscribeUserGroupsToLp = "Inscripción de clases a lección";
$ReplaceFile = "Reemplazar archivo";
$SubscribeClassesToLpCategory = "Suscribir clases a la categoría de lecciones";
+$ExportResponseReport = "Exportar reporte de respuestas";
+$ResponseReport = "Reporte de respuestas";
?>
\ No newline at end of file
diff --git a/main/template/default/exercise/partials/result_exercise.tpl b/main/template/default/exercise/partials/result_exercise.tpl
index 7cd4940c0f..3f7314054e 100644
--- a/main/template/default/exercise/partials/result_exercise.tpl
+++ b/main/template/default/exercise/partials/result_exercise.tpl
@@ -45,13 +45,23 @@
{% endif %}
{% if allow_signature %}
-
+
{% endif %}
+
+ {% if allow_export_pdf %}
+
+
+ {% endif %}