question_admin.inc.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script allows to manage the statements of questions.
  5. * It is included from the script admin.php
  6. * @package chamilo.exercise
  7. * @author Olivier Brouckaert
  8. * @author Julio Montoya
  9. */
  10. /**
  11. * Code
  12. */
  13. $course_id = api_get_course_int_id();
  14. $urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
  15. // INIT QUESTION
  16. if (isset($_GET['editQuestion'])) {
  17. $objQuestion = Question::read($_GET['editQuestion'], null, $objExercise);
  18. $action = api_get_self()."?".api_get_cidreq(
  19. )."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id."&exerciseId=$objExercise->id";
  20. } else {
  21. $objQuestion = Question::getInstance($_REQUEST['answerType'], $objExercise);
  22. $action = api_get_self()."?".api_get_cidreq(
  23. )."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion."&exerciseId=$objExercise->id";
  24. }
  25. /** @var Question $objQuestion */
  26. if (is_object($objQuestion)) {
  27. //Form creation
  28. $form = new FormValidator('question_admin_form', 'post', $action);
  29. if (isset($_GET['editQuestion'])) {
  30. $objQuestion->submitClass = "btn save";
  31. $objQuestion->submitText = get_lang('ModifyQuestion');
  32. } else {
  33. $objQuestion->submitClass = "btn add";
  34. $objQuestion->submitText = get_lang('AddQuestionToExercise');
  35. }
  36. /*if (!isset($_GET['fromExercise'])) {
  37. $objQuestion->setDefaultQuestionValues = true;
  38. }*/
  39. // This condition depends of the exercice/question_create.php page that sets the "isContent" value
  40. if (isset($_REQUEST['newQuestion']) && $_REQUEST['newQuestion'] == 'yes' &&
  41. (isset($_REQUEST['isContent']) && $_REQUEST['isContent'] == '1')
  42. ) {
  43. $objQuestion->setDefaultQuestionValues = true;
  44. }
  45. $types_information = Question::get_question_type_list();
  46. $form_title_extra = get_lang($types_information[$type][1]);
  47. // form title
  48. $form->addElement('header', $objQuestion->submitText.': '.$form_title_extra);
  49. // question form elements
  50. $objQuestion->createForm($form);
  51. // answer form elements
  52. $objQuestion->createAnswersForm($form);
  53. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  54. if ($objExercise->edit_exercise_in_lp == false) {
  55. $form->freeze();
  56. }
  57. // Form validation
  58. //$result = $objQuestion->allQuestionWithMediaHaveTheSameCategory($exerciseId, 100);
  59. if (isset($_POST['submitQuestion']) && $form->validate()) {
  60. // Media is selected?
  61. $parentId = $form->getSubmitValue('parent_id');
  62. $categories = $form->getSubmitValue('questionCategory');
  63. $process = true;
  64. $message = null;
  65. // A media question was sent
  66. if (isset($parentId) && !empty($parentId)) {
  67. // No allowing 2 categories if a media was selected
  68. $tryAgain = Display::url(
  69. get_lang('TryAgain'),
  70. api_get_path(WEB_CODE_PATH).'exercice/admin.php?exerciseId='.$exerciseId.'&myid=1&editQuestion='.$objQuestion->id.'&'.api_get_cidreq(),
  71. array('class' => 'btn')
  72. );
  73. if (isset($categories) && !empty($categories)) {
  74. if (count($categories) > 1) {
  75. $message = Display::display_warning_message(get_lang('WhenUsingAMediaQuestionYouCantAddMoreThanOneCategory'));
  76. $message .= ' '.$tryAgain;
  77. $process = false;
  78. }
  79. // If media exists
  80. $questionCategoriesOfMediaQuestions = $objQuestion->getQuestionCategoriesOfMediaQuestions($exerciseId, $parentId);
  81. if (!empty($questionCategoriesOfMediaQuestions)) {
  82. // Check if the media sent matches other medias sent before
  83. $result = $objQuestion->allQuestionWithMediaHaveTheSameCategory($exerciseId, $parentId, $categories, $objQuestion->id);
  84. if ($result == false) {
  85. $message = Display::display_warning_message(get_lang('TheSelectedCategoryDoesNotMatchWithTheOtherQuestionWithTheSameMediaQuestion'));
  86. $message .= ' '.$tryAgain;
  87. $process = false;
  88. }
  89. }
  90. } else {
  91. if (!empty($objQuestion->category_list)) {
  92. $message = Display::display_warning_message(get_lang('YouMustProvideACategoryBecauseTheCurrentCategoryDoesNotMatchOtherMediaQuestions'));
  93. $message .= ' '.$tryAgain;
  94. $process = false;
  95. }
  96. }
  97. }
  98. if ($process) {
  99. // Question
  100. $objQuestion->processCreation($form, $objExercise);
  101. // Answers
  102. $objQuestion->processAnswersCreation($form);
  103. // TODO: maybe here is the better place to index this tool, including answers text
  104. // redirect
  105. if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
  106. if (isset($_GET['editQuestion'])) {
  107. echo '<script type="text/javascript">window.location.href="'.$urlMainExercise.'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemUpdated"</script>';
  108. } else {
  109. //New question
  110. echo '<script type="text/javascript">window.location.href="'.$urlMainExercise.'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemAdded"</script>';
  111. }
  112. } else {
  113. echo '<script type="text/javascript">window.location.href="'.$urlMainExercise.'admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
  114. }
  115. } else {
  116. echo $message;
  117. }
  118. } else {
  119. if (isset($questionName)) {
  120. echo '<h3>'.$questionName.'</h3>';
  121. }
  122. if (!empty($pictureName)) {
  123. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  124. }
  125. if (!empty($msgErr)) {
  126. Display::display_normal_message($msgErr); //main API
  127. }
  128. // display the form
  129. $form->display();
  130. }
  131. }