question_admin.inc.php 2.8 KB

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