download-pdf.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /* For license terms, see /license.txt */
  3. require_once '../config.php';
  4. $plugin = Test2pdfPlugin::create();
  5. $enable = $plugin->get('enable_plugin') == 'true';
  6. if (!$enable) {
  7. header('Location: ../../../index.php');
  8. exit;
  9. }
  10. api_protect_course_script();
  11. $courseId = intval($_GET['c_id']);
  12. $sessionId = api_get_session_id();
  13. $quizId = intval($_GET['id_quiz']);
  14. $infoCourse = api_get_course_info_by_id($courseId);
  15. $infoQuiz = getInfoQuiz($courseId, $quizId);
  16. $titleCourse = removeHtml($infoCourse['title']);
  17. $titleQuiz = removeHtml($infoQuiz['title']);
  18. $mpdf = new PDF();
  19. $mpdf->set_header($infoCourse);
  20. $mpdf->set_footer();
  21. $pdf = $mpdf->pdf;
  22. $pdf->SetTitle($titleCourse.' - '.$titleQuiz);
  23. $pdf->AddPage();
  24. $pdf->SetFont('Arial', '', 16);
  25. $pdf->SetTextColor(64);
  26. $pdf->MultiCell(0, 7, $infoQuiz['title'], 0, 'L', false);
  27. if (!empty($infoQuiz['description'])) {
  28. $pdf->WriteHTML(removeQuotes($infoQuiz['description']));
  29. }
  30. // Select all questions of the supported types from the given course
  31. $questionsList = getQuestionsFromCourse($courseId, $quizId, $sessionId);
  32. // Go through all questions and get the answers
  33. if ($_GET['type'] == 'question' || $_GET['type'] == 'all') {
  34. $j = 1;
  35. foreach ($questionsList as $key => $value) {
  36. $infoQuestion = getInfoQuestion($courseId, $value);
  37. if ($pdf->y > 240) {
  38. $pdf->AddPage();
  39. }
  40. $pdf->SetFont('Arial', '', 12);
  41. $pdf->SetTextColor(64);
  42. $pdf->MultiCell(0, 7, ($key + $j).' - '.$infoQuestion['question'], 0, 'L', false);
  43. if (!empty($infoQuestion['description'])) {
  44. $pdf->WriteHTML(removeQuotes($infoQuestion['description']));
  45. }
  46. $infoAnswer = getAnswers($courseId, $value);
  47. foreach ($infoAnswer as $key2 => $value2) {
  48. $pdf->SetFont('Arial', 'I', 10);
  49. $pdf->SetTextColor(96);
  50. $pdf->Cell(1, 7, '', 0, 0);
  51. $pdf->Rect($pdf->x + 2, $pdf->y, 4, 4);
  52. $pdf->Cell(7, 7, '', 0, 0);
  53. $pdf->MultiCell(0, 5, $letters[$key2].' - '.removeHtml($value2['answer']), 0, 'L', false);
  54. $pdf->Ln(1);
  55. }
  56. $pdf->Ln(4);
  57. }
  58. }
  59. $j = 1;
  60. if ($_GET['type'] == 'answer' || $_GET['type'] == 'all') {
  61. $answerList = [];
  62. foreach ($questionsList as $key => $value) {
  63. $infoQuestion = getInfoQuestion($courseId, $value);
  64. if ($infoQuestion['question'] == $plugin->get_lang('Statement')) {
  65. $j = 0;
  66. } else {
  67. $answers = '';
  68. $infoQuestion = getInfoQuestion($courseId, $value);
  69. if ($infoQuestion['type'] == 2 ||
  70. $infoQuestion['type'] == 9 ||
  71. $infoQuestion['type'] == 11 ||
  72. $infoQuestion['type'] == 12 ||
  73. $infoQuestion['type'] == 14
  74. ) {
  75. $infoAnswer = getAnswers($courseId, $value);
  76. $answers .= ' '.($key + $j).' -';
  77. foreach ($infoAnswer as $key2 => $value2) {
  78. if ($value2['correct'] == 1) {
  79. $answers .= ' '.$letters[$key2].',';
  80. }
  81. }
  82. $i = strrpos($answers, ',');
  83. $answers = substr($answers, 0, $i);
  84. $answers .= ' ';
  85. $answerList[] = $answers;
  86. } else {
  87. $infoAnswer = getAnswers($courseId, $value);
  88. foreach ($infoAnswer as $key2 => $value2) {
  89. if ($value2['correct'] == 1) {
  90. $answers .= ' '.($key + $j).' - '.$letters[$key2].' ';
  91. break;
  92. }
  93. }
  94. $answerList[] = $answers;
  95. }
  96. }
  97. }
  98. $pdf->SetFont('Arial', '', 12);
  99. $pdf->SetTextColor(64);
  100. $pdf->Cell(0, 7, $plugin->get_lang('AnswersColumn'), 0, 1, 'L', false);
  101. $pdf->SetFont('Arial', 'I', 10);
  102. $pdf->SetTextColor(64, 64, 255);
  103. $i = 1;
  104. foreach ($answerList as $resp) {
  105. $pdf->Cell(50, 6, $resp, 0);
  106. if ($i % 4 == 0) {
  107. $pdf->Ln();
  108. }
  109. $i++;
  110. }
  111. }
  112. $pdf->Output();