question_admin.inc.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Statement (?) administration
  5. * This script allows to manage the statements of questions.
  6. * It is included from the script admin.php
  7. * @package chamilo.exercise
  8. * @author Olivier Brouckaert
  9. * @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
  10. */
  11. // INIT QUESTION
  12. if (isset($_GET['editQuestion'])) {
  13. $objQuestion = Question::read ($_GET['editQuestion']);
  14. $action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  15. } else {
  16. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  17. $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  18. }
  19. if (is_object($objQuestion)) {
  20. //FORM CREATION
  21. $form = new FormValidator('question_admin_form','post', $action);
  22. if (isset($_GET['editQuestion'])) {
  23. $class="btn save";
  24. $text=get_lang('ModifyQuestion');
  25. $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : null;
  26. } else {
  27. $class="btn add";
  28. $text=get_lang('AddQuestionToExercise');
  29. $type = $_REQUEST['answerType'];
  30. }
  31. $typesInformation = Question::get_question_type_list();
  32. $form_title_extra = isset($typesInformation[$type][1]) ? get_lang($typesInformation[$type][1]) : null;
  33. // form title
  34. $form->addElement('header', $text.': '.$form_title_extra);
  35. // question form elements
  36. $objQuestion->createForm($form);
  37. // answer form elements
  38. $objQuestion->createAnswersForm($form);
  39. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  40. if ($objExercise->edit_exercise_in_lp == false) {
  41. $form->freeze();
  42. }
  43. // FORM VALIDATION
  44. if (isset($_POST['submitQuestion']) && $form->validate()) {
  45. // question
  46. $objQuestion->processCreation($form, $objExercise);
  47. // answers
  48. $nb_answers = isset($nb_answers) ? $nb_answers : 0;
  49. $objQuestion->processAnswersCreation($form, $nb_answers);
  50. // TODO: maybe here is the better place to index this tool, including answers text
  51. // redirect
  52. if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
  53. if(isset($_GET['editQuestion'])) {
  54. echo '<script type="text/javascript">window.location.href="admin.php?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
  55. } else {
  56. //New question
  57. echo '<script type="text/javascript">window.location.href="admin.php?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
  58. }
  59. } else {
  60. echo '<script type="text/javascript">window.location.href="admin.php?'.api_get_cidreq().'&exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
  61. }
  62. } else {
  63. if (isset($questionName)) {
  64. echo '<h3>'.$questionName.'</h3>';
  65. }
  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. }