question_admin.inc.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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);
  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. // Answers
  46. $nb_answers = isset($nb_answers) ? $nb_answers : 0;
  47. $objQuestion->processAnswersCreation($form, $nb_answers);
  48. // TODO: maybe here is the better place to index this tool, including answers text
  49. // redirect
  50. if ($objQuestion->type != HOT_SPOT && $objQuestion->type != HOT_SPOT_DELINEATION) {
  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. }