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