|
19 | 19 | Session::erase('objAnswer');
|
20 | 20 |
|
21 | 21 | $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
|
| 22 | +$action = $_REQUEST['action'] ?? ''; |
| 23 | +$id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : ''; |
| 24 | +$description = $_REQUEST['description'] ?? ''; |
| 25 | +$title = $_REQUEST['title'] ?? ''; |
| 26 | +$page = isset($_GET['page']) && !empty($_GET['page']) ? (int) $_GET['page'] : 1; |
22 | 27 |
|
23 | 28 | // Prepare lists for form
|
24 | 29 | // Courses list
|
|
81 | 86 | 'selected_course',
|
82 | 87 | [get_lang('Course'), get_lang('CourseInWhichTheQuestionWasInitiallyCreated')],
|
83 | 88 | $courseSelectionList,
|
84 |
| - ['onchange' => 'mark_course_id_changed(); submit_form(this);', 'id' => 'selected_course'] |
| 89 | + ['id' => 'selected_course'] |
85 | 90 | )
|
86 | 91 | ->setSelected($selectedCourse);
|
87 | 92 | $form
|
88 | 93 | ->addSelect(
|
89 | 94 | 'question_level',
|
90 | 95 | get_lang('Difficulty'),
|
91 | 96 | $levels,
|
92 |
| - ['onchange' => 'submit_form(this);', 'id' => 'question_level'] |
| 97 | + ['id' => 'question_level'] |
93 | 98 | )
|
94 | 99 | ->setSelected($questionLevel);
|
95 | 100 | $form
|
96 | 101 | ->addSelect(
|
97 | 102 | 'answer_type',
|
98 | 103 | get_lang('AnswerType'),
|
99 | 104 | $questionTypesList,
|
100 |
| - ['onchange' => 'submit_form(this);', 'id' => 'answer_type'] |
| 105 | + ['id' => 'answer_type'] |
101 | 106 | )
|
102 | 107 | ->setSelected($answerType);
|
103 | 108 |
|
|
112 | 117 | $questionCount = 0;
|
113 | 118 | $start = 0;
|
114 | 119 | $end = 0;
|
115 |
| - |
| 120 | +$pdfContent = ''; |
| 121 | + |
| 122 | +$params = [ |
| 123 | + 'id' => $id, |
| 124 | + 'title' => Security::remove_XSS($title), |
| 125 | + 'description' => Security::remove_XSS($description), |
| 126 | + 'selected_course' => $selectedCourse, |
| 127 | + 'question_level' => $questionLevel, |
| 128 | + 'answer_type' => $answerType, |
| 129 | +]; |
116 | 130 | if ($formSent) {
|
117 |
| - $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : ''; |
118 |
| - $description = $_REQUEST['description'] ?? ''; |
119 |
| - $title = $_REQUEST['title'] ?? ''; |
120 |
| - $page = isset($_GET['page']) && !empty($_GET['page']) ? (int) $_GET['page'] : 1; |
121 |
| - |
| 131 | + $params['form_sent'] = 1; |
122 | 132 | $em = Database::getManager();
|
123 | 133 | $repo = $em->getRepository('ChamiloCourseBundle:CQuizQuestion');
|
124 | 134 | $criteria = new Criteria();
|
|
149 | 159 |
|
150 | 160 | $questions = $repo->matching($criteria);
|
151 | 161 |
|
152 |
| - if (empty($id)) { |
153 |
| - $id = ''; |
154 |
| - } |
155 |
| - $params = [ |
156 |
| - 'id' => $id, |
157 |
| - 'title' => Security::remove_XSS($title), |
158 |
| - 'description' => Security::remove_XSS($description), |
159 |
| - 'form_sent' => 1, |
160 |
| - ]; |
161 | 162 | $url = api_get_self().'?'.http_build_query($params);
|
162 | 163 | $form->setDefaults($params);
|
163 | 164 | $questionCount = count($questions);
|
164 | 165 |
|
| 166 | + if ('export_pdf' === $action) { |
| 167 | + $length = $questionCount; |
| 168 | + } |
| 169 | + |
165 | 170 | $paginator = new Paginator();
|
166 | 171 | $pagination = $paginator->paginate($questions, $page, $length);
|
167 | 172 | $pagination->setItemNumberPerPage($length);
|
|
209 | 214 | $question->courseCode = $courseCode;
|
210 | 215 | // Creating empty exercise
|
211 | 216 | $exercise = new Exercise($courseId);
|
| 217 | + /* @var Question $questionObject */ |
212 | 218 | $questionObject = Question::read($question->getIid(), $courseInfo);
|
213 | 219 |
|
214 | 220 | ob_start();
|
|
226 | 232 | );
|
227 | 233 | $question->questionData = ob_get_contents();
|
228 | 234 |
|
| 235 | + if ('export_pdf' === $action) { |
| 236 | + $pdfContent .= '<span style="color:#000; font-weight:bold; font-size:x-large;">#'.$question->getIid().'. '.$question->getQuestion().'</span><br />'; |
| 237 | + $pdfContent .= '<span style="color:#444;">('.$questionTypesList[$question->getType()].') ['.get_lang('Source').': '.$courseCode.']</span><br />'; |
| 238 | + $pdfContent .= $question->getDescription().'<br />'; |
| 239 | + $pdfContent .= $question->questionData; |
| 240 | + continue; |
| 241 | + } |
| 242 | + |
229 | 243 | $deleteUrl = $url.'&'.http_build_query([
|
230 | 244 | 'courseId' => $question->getCId(),
|
231 |
| - 'questionId' => $question->getId(), |
| 245 | + 'questionId' => $question->getIid(), |
232 | 246 | 'action' => 'delete',
|
233 | 247 | ]);
|
234 | 248 |
|
|
250 | 264 | 'id_session' => $exercise->sessionId,
|
251 | 265 | 'exerciseId' => $exerciseId,
|
252 | 266 | 'type' => $question->getType(),
|
253 |
| - 'editQuestion' => $question->getId(), |
| 267 | + 'editQuestion' => $question->getIid(), |
254 | 268 | ]
|
255 | 269 | ),
|
256 | 270 | ['target' => '_blank']
|
|
309 | 323 |
|
310 | 324 | $formContent = $form->returnForm();
|
311 | 325 |
|
312 |
| -$action = $_REQUEST['action'] ?? ''; |
313 | 326 | switch ($action) {
|
| 327 | + case 'export_pdf': |
| 328 | + $pdfContent = Security::remove_XSS($pdfContent); |
| 329 | + $pdfParams = [ |
| 330 | + 'filename' => 'questions-export-'.api_get_local_time(), |
| 331 | + 'pdf_date' => api_get_local_time(), |
| 332 | + 'orientation' => 'P', |
| 333 | + ]; |
| 334 | + $pdf = new PDF('A4', $pdfParams['orientation'], $pdfParams); |
| 335 | + $pdf->html_to_pdf_with_template($pdfContent, false, false, true); |
| 336 | + exit; |
314 | 337 | case 'delete':
|
315 | 338 | $questionId = $_REQUEST['questionId'] ?? '';
|
316 | 339 | $courseId = $_REQUEST['courseId'] ?? '';
|
|
338 | 361 | Display::return_icon('back.png', get_lang('PlatformAdmin'), [], ICON_SIZE_MEDIUM),
|
339 | 362 | api_get_path(WEB_CODE_PATH).'admin/index.php'
|
340 | 363 | );
|
341 |
| -$actionsRight = ''; |
342 |
| -/* |
| 364 | + |
| 365 | +$exportUrl = api_get_path(WEB_CODE_PATH) |
| 366 | + .'admin/questions.php?action=export_pdf&' |
| 367 | + .http_build_query($params); |
| 368 | + |
343 | 369 | $actionsRight = Display::url(
|
344 | 370 | Display::return_icon('pdf.png', get_lang('ExportToPDF'), [], ICON_SIZE_MEDIUM),
|
345 |
| - api_get_path(WEB_CODE_PATH).'admin/questions.php?action=exportpdf' |
| 371 | + $exportUrl |
346 | 372 | );
|
347 |
| -*/ |
348 | 373 |
|
349 | 374 | $toolbar = Display::toolbarAction(
|
350 | 375 | 'toolbar-admin-questions',
|
351 | 376 | [$actionsLeft, $actionsRight]
|
352 | 377 | );
|
353 | 378 |
|
354 |
| -$htmlHeadXtra[] = " |
355 |
| -<script> |
356 |
| - function submit_form(obj) { |
357 |
| - document.question_pool.submit(); |
358 |
| - } |
359 |
| -
|
360 |
| - function mark_course_id_changed() { |
361 |
| - $('#course_id_changed').val('1'); |
362 |
| - } |
363 |
| -</script>"; |
364 |
| - |
365 | 379 | $tpl = new Template(get_lang('Questions'));
|
366 | 380 | $tpl->assign('form', $formContent);
|
367 | 381 | $tpl->assign('toolbar', $toolbar);
|
|
0 commit comments