question_admin.inc.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. *
  7. * @package chamilo.exercise
  8. *
  9. * @author Olivier Brouckaert
  10. *
  11. * @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
  12. */
  13. if (isset($_GET['editQuestion'])) {
  14. $objQuestion = Question::read($_GET['editQuestion']);
  15. $action = api_get_self().'?'.api_get_cidreq().'&modifyQuestion='.$modifyQuestion.'&editQuestion='.$objQuestion->id.'&page='.$page;
  16. } else {
  17. $objQuestion = Question::getInstance($_REQUEST['answerType']);
  18. $action = api_get_self().'?'.api_get_cidreq().'&modifyQuestion='.$modifyQuestion.'&newQuestion='.$newQuestion;
  19. }
  20. if (is_object($objQuestion)) {
  21. // FORM CREATION
  22. $form = new FormValidator('question_admin_form', 'post', $action);
  23. if (isset($_GET['editQuestion'])) {
  24. $class = 'btn btn-default';
  25. $text = get_lang('ModifyQuestion');
  26. $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
  27. } else {
  28. $class = 'btn btn-default';
  29. $text = get_lang('AddQuestionToExercise');
  30. $type = $_REQUEST['answerType'];
  31. }
  32. $typesInformation = Question::get_question_type_list();
  33. $form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
  34. $code = '';
  35. if (isset($objQuestion->code) && !empty($objQuestion->code)) {
  36. $code = ' ('.$objQuestion->code.')';
  37. }
  38. // form title
  39. $form->addHeader($text.': '.$form_title_extra.$code);
  40. // question form elements
  41. $objQuestion->createForm($form, $objExercise);
  42. // answer form elements
  43. $objQuestion->createAnswersForm($form);
  44. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  45. if (!empty($objExercise->id) && $objExercise->edit_exercise_in_lp == false) {
  46. $form->freeze();
  47. }
  48. // FORM VALIDATION
  49. if (isset($_POST['submitQuestion']) && $form->validate()) {
  50. // Question
  51. $objQuestion->processCreation($form, $objExercise);
  52. $objQuestion->processAnswersCreation($form, $objExercise);
  53. // TODO: maybe here is the better place to index this tool, including answers text
  54. // redirect
  55. if ($objQuestion->type != HOT_SPOT &&
  56. $objQuestion->type != HOT_SPOT_DELINEATION
  57. ) {
  58. if (isset($_GET['editQuestion'])) {
  59. if (empty($exerciseId)) {
  60. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  61. $url = 'admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&editQuestion='.$objQuestion->id;
  62. echo '<script type="text/javascript">window.location.href="'.$url.'"</script>';
  63. exit;
  64. }
  65. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemUpdated"</script>';
  66. } else {
  67. // New question
  68. $page = 1;
  69. $length = api_get_configuration_value('question_pagination_length');
  70. if (!empty($length)) {
  71. $page = round($objExercise->getQuestionCount() / $length);
  72. }
  73. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&page='.$page.'&message=ItemAdded"</script>';
  74. }
  75. } else {
  76. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&page='.$page.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
  77. }
  78. } else {
  79. if (isset($questionName)) {
  80. echo '<h3>'.$questionName.'</h3>';
  81. }
  82. if (!empty($pictureName)) {
  83. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  84. }
  85. if (!empty($msgErr)) {
  86. echo Display::return_message($msgErr);
  87. }
  88. // display the form
  89. $form->display();
  90. }
  91. }