question_admin.inc.php 3.6 KB

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