|
51 | 51 | }
|
52 | 52 |
|
53 | 53 | // FORM VALIDATION
|
54 |
| - if (isset($_POST['submitQuestion']) && $form->validate()) { |
55 |
| - // Question |
56 |
| - $objQuestion->processCreation($form, $objExercise); |
57 |
| - $objQuestion->processAnswersCreation($form, $objExercise); |
58 |
| - // TODO: maybe here is the better place to index this tool, including answers text |
59 |
| - // redirect |
60 |
| - if (in_array($objQuestion->type, [HOT_SPOT, HOT_SPOT_COMBINATION, HOT_SPOT_DELINEATION])) { |
61 |
| - echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&page='.$page.'&hotspotadmin='.$objQuestion->iid.'&'.api_get_cidreq( |
62 |
| - ).'"</script>'; |
63 |
| - } elseif (in_array($objQuestion->type, [MULTIPLE_ANSWER_DROPDOWN, MULTIPLE_ANSWER_DROPDOWN_COMBINATION])) { |
64 |
| - $url = 'admin.php?' |
65 |
| - .api_get_cidreq().'&' |
66 |
| - .http_build_query(['exerciseId' => $exerciseId, 'page' => $page, 'mad_admin' => $objQuestion->iid]); |
67 |
| - echo '<script type="text/javascript">window.location.href="'.$url.'"</script>'; |
68 |
| - } else { |
69 |
| - if (isset($_GET['editQuestion'])) { |
70 |
| - if (empty($exerciseId)) { |
71 |
| - Display::addFlash(Display::return_message(get_lang('ItemUpdated'))); |
72 |
| - $url = 'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->iid; |
73 |
| - echo '<script type="text/javascript">window.location.href="'.$url.'"</script>'; |
74 |
| - exit; |
75 |
| - } |
76 |
| - echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemUpdated"</script>'; |
| 54 | + if (isset($_POST['submitQuestion'])) { |
| 55 | + $validationResult = true; |
| 56 | + if (method_exists($objQuestion, 'validateAnswers')) { |
| 57 | + $validationResult = $objQuestion->validateAnswers($form); |
| 58 | + } |
| 59 | + if (is_array($validationResult) && !empty($validationResult['errors'])) { |
| 60 | + echo Display::return_message(implode("<br>", $validationResult['errors']), 'error', false); |
| 61 | + } elseif ($form->validate()) { |
| 62 | + $objQuestion->processCreation($form, $objExercise); |
| 63 | + $objQuestion->processAnswersCreation($form, $objExercise); |
| 64 | + if (in_array($objQuestion->type, [HOT_SPOT, HOT_SPOT_COMBINATION, HOT_SPOT_DELINEATION])) { |
| 65 | + echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&page='.$page.'&hotspotadmin='.$objQuestion->iid.'&'.api_get_cidreq().'";</script>'; |
| 66 | + } elseif (in_array($objQuestion->type, [MULTIPLE_ANSWER_DROPDOWN, MULTIPLE_ANSWER_DROPDOWN_COMBINATION])) { |
| 67 | + $url = 'admin.php?'.api_get_cidreq().'&'.http_build_query(['exerciseId' => $exerciseId, 'page' => $page, 'mad_admin' => $objQuestion->iid]); |
| 68 | + echo '<script type="text/javascript">window.location.href="'.$url.'";</script>'; |
77 | 69 | } else {
|
78 |
| - // New question |
79 |
| - $page = 1; |
80 |
| - $length = api_get_configuration_value('question_pagination_length'); |
81 |
| - if (!empty($length)) { |
82 |
| - $page = round($objExercise->getQuestionCount() / $length); |
| 70 | + if (isset($_GET['editQuestion'])) { |
| 71 | + if (empty($exerciseId)) { |
| 72 | + Display::addFlash(Display::return_message(get_lang('ItemUpdated'))); |
| 73 | + $url = 'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->iid; |
| 74 | + echo '<script type="text/javascript">window.location.href="'.$url.'";</script>'; |
| 75 | + exit; |
| 76 | + } |
| 77 | + echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemUpdated";</script>'; |
| 78 | + } else { |
| 79 | + // New question |
| 80 | + $page = 1; |
| 81 | + $length = api_get_configuration_value('question_pagination_length'); |
| 82 | + if (!empty($length)) { |
| 83 | + $page = round($objExercise->getQuestionCount() / $length); |
| 84 | + } |
| 85 | + echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemAdded";</script>'; |
83 | 86 | }
|
84 |
| - echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemAdded"</script>'; |
85 | 87 | }
|
| 88 | + exit(); |
86 | 89 | }
|
87 |
| - } else { |
88 |
| - if (isset($questionName)) { |
89 |
| - echo '<h3>'.$questionName.'</h3>'; |
90 |
| - } |
91 |
| - if (!empty($pictureName)) { |
92 |
| - echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">'; |
93 |
| - } |
94 |
| - if (!empty($msgErr)) { |
95 |
| - echo Display::return_message($msgErr); |
96 |
| - } |
97 |
| - // display the form |
98 |
| - $form->display(); |
99 | 90 | }
|
| 91 | + |
| 92 | + if (isset($questionName)) { |
| 93 | + echo '<h3>'.$questionName.'</h3>'; |
| 94 | + } |
| 95 | + if (!empty($pictureName)) { |
| 96 | + echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">'; |
| 97 | + } |
| 98 | + if (!empty($msgErr)) { |
| 99 | + echo Display::return_message($msgErr); |
| 100 | + } |
| 101 | + |
| 102 | + $form->display(); |
100 | 103 | }
|
0 commit comments