question_admin.inc.php 3.0 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. * @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. // INIT QUESTION
  15. if (isset($_GET['editQuestion'])) {
  16. $objQuestion = Question::read ($_GET['editQuestion']);
  17. $action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  18. } else {
  19. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  20. $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  21. }
  22. if (is_object($objQuestion)) {
  23. //Form creation
  24. $form = new FormValidator('question_admin_form','post', $action);
  25. if (isset($_GET['editQuestion'])) {
  26. $class="btn save";
  27. $text=get_lang('ModifyQuestion');
  28. //$type = Security::remove_XSS($_GET['type']); already loaded in admin.php
  29. } else {
  30. $class="btn add";
  31. $text=get_lang('AddQuestionToExercise');
  32. //$type = $_REQUEST['answerType']; //already loaded in admin.php
  33. }
  34. $types_information = Question::get_question_type_list();
  35. $form_title_extra = get_lang($types_information[$type][1]);
  36. // form title
  37. $form->addElement('header', $text.': '.$form_title_extra);
  38. if ($fastEdition) {
  39. $form->setAllowRichEditorInForm(false);
  40. $form->setAllowedRichEditorList(array('questionDescription'));
  41. }
  42. // question form elements
  43. $objQuestion->createForm($form);
  44. // answer form elements
  45. $objQuestion->createAnswersForm($form);
  46. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  47. if ($objExercise->edit_exercise_in_lp == false) {
  48. $form->freeze();
  49. }
  50. // FORM VALIDATION
  51. if (isset($_POST['submitQuestion']) && $form->validate()) {
  52. // question
  53. $objQuestion->processCreation($form, $objExercise);
  54. // answers
  55. $objQuestion->processAnswersCreation($form, $nb_answers);
  56. // TODO: maybe here is the better place to index this tool, including answers text
  57. // redirect
  58. if ($objQuestion -> type != HOT_SPOT && $objQuestion -> type != HOT_SPOT_DELINEATION) {
  59. if(isset($_GET['editQuestion'])) {
  60. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
  61. } else {
  62. //New question
  63. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
  64. }
  65. } else {
  66. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
  67. }
  68. } else {
  69. if (isset($questionName)) {
  70. echo '<h3>'.$questionName.'</h3>';
  71. }
  72. if(!empty($pictureName)){
  73. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  74. }
  75. if(!empty($msgErr)) {
  76. Display::display_normal_message($msgErr); //main API
  77. }
  78. // display the form
  79. $form->display();
  80. }
  81. }