question_admin.inc.php 3.3 KB

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