question_admin.inc.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  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. // form title
  35. $form->addHeader($text.': '.$form_title_extra);
  36. // question form elements
  37. $objQuestion->createForm($form, $objExercise);
  38. // answer form elements
  39. $objQuestion->createAnswersForm($form);
  40. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  41. if ($objExercise->edit_exercise_in_lp == false) {
  42. $form->freeze();
  43. }
  44. // FORM VALIDATION
  45. if (isset($_POST['submitQuestion']) && $form->validate()) {
  46. // Question
  47. $objQuestion->processCreation($form, $objExercise);
  48. $objQuestion->processAnswersCreation($form, $objExercise);
  49. // TODO: maybe here is the better place to index this tool, including answers text
  50. // redirect
  51. if ($objQuestion->type != HOT_SPOT &&
  52. $objQuestion->type != HOT_SPOT_DELINEATION
  53. ) {
  54. if (isset($_GET['editQuestion'])) {
  55. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemUpdated"</script>';
  56. } else {
  57. // New question
  58. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&message=ItemAdded"</script>';
  59. }
  60. } else {
  61. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'&'.api_get_cidreq().'"</script>';
  62. }
  63. } else {
  64. if (isset($questionName)) {
  65. echo '<h3>'.$questionName.'</h3>';
  66. }
  67. if (!empty($pictureName)) {
  68. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  69. }
  70. if (!empty($msgErr)) {
  71. echo Display::return_message($msgErr, 'normal');
  72. }
  73. // display the form
  74. $form->display();
  75. }
  76. }