question_admin.inc.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. /**
  12. * Code
  13. */
  14. // ALLOWED_TO_INCLUDE is defined in admin.php
  15. if(!defined('ALLOWED_TO_INCLUDE')) {
  16. exit();
  17. }
  18. $course_id = api_get_course_int_id();
  19. // INIT QUESTION
  20. if (isset($_GET['editQuestion'])) {
  21. $objQuestion = Question::read ($_GET['editQuestion']);
  22. $action = api_get_self()."?".api_get_cidreq()."&myid=1&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  23. if (isset($exerciseId) && !empty($exerciseId)) {
  24. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  25. $sql="SELECT max_score FROM $TBL_LP_ITEM
  26. WHERE c_id = $course_id AND item_type = '".TOOL_QUIZ."' AND path ='".Database::escape_string($exerciseId)."'";
  27. $result = Database::query($sql);
  28. if (Database::num_rows($result) > 0) {
  29. //Display::display_warning_message(get_lang('EditingScoreCauseProblemsToExercisesInLP'));
  30. }
  31. }
  32. } else {
  33. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  34. $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  35. }
  36. if(is_object($objQuestion)) {
  37. //INIT FORM
  38. $form = new FormValidator('question_admin_form','post',$action);
  39. //FORM CREATION
  40. if(isset($_GET['editQuestion'])) {
  41. $class="save";
  42. $text=get_lang('ModifyQuestion');
  43. $type = Security::remove_XSS($_GET['type']);
  44. } else {
  45. $class="add";
  46. $text=get_lang('AddQuestionToExercise');
  47. $type = $_REQUEST['answerType'];
  48. }
  49. $types_information = $objQuestion->get_types_information();
  50. $form_title_extra = get_lang($types_information[$type][1]);
  51. // form title
  52. $form->addElement('header', '', $text.': '.$form_title_extra);
  53. // question form elements
  54. $objQuestion->createForm ($form,array('Height'=>150));
  55. // answer form elements
  56. $objQuestion->createAnswersForm ($form);
  57. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  58. if (!$show_quiz_edition) {
  59. $form->freeze();
  60. }
  61. // submit button is implemented in every question type
  62. //$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
  63. //$renderer = $form->defaultRenderer();
  64. //$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','submitQuestion');
  65. // FORM VALIDATION
  66. if (isset($_POST['submitQuestion']) && $form->validate()) {
  67. // question
  68. $objQuestion->processCreation($form,$objExercise);
  69. // answers
  70. $objQuestion->processAnswersCreation($form,$nb_answers);
  71. // TODO: maybe here is the better place to index this tool, including answers text
  72. // redirect
  73. if ($objQuestion -> type != HOT_SPOT && $objQuestion -> type != HOT_SPOT_DELINEATION) {
  74. if(isset($_GET['editQuestion'])) {
  75. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemUpdated"</script>';
  76. } else {
  77. //New question
  78. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&message=ItemAdded"</script>';
  79. }
  80. } else {
  81. echo '<script type="text/javascript">window.location.href="admin.php?exerciseId='.$exerciseId.'&hotspotadmin='.$objQuestion->id.'"</script>';
  82. }
  83. } else {
  84. echo '<h3>'.$questionName.'</h3>';
  85. if(!empty($pictureName)){
  86. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  87. }
  88. if(!empty($msgErr)) {
  89. Display::display_normal_message($msgErr); //main API
  90. }
  91. // display the form
  92. $form->display();
  93. }
  94. }