question_admin.inc.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 dokeos.exercise
  8. * @author Olivier Brouckaert
  9. * @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
  10. */
  11. /*
  12. ==============================================================================
  13. INIT SECTION
  14. ==============================================================================
  15. */
  16. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  17. require_once api_get_path(LIBRARY_PATH).'image.lib.php';
  18. // ALLOWED_TO_INCLUDE is defined in admin.php
  19. if(!defined('ALLOWED_TO_INCLUDE')) {
  20. exit();
  21. }
  22. /*********************
  23. * INIT QUESTION
  24. *********************/
  25. if(isset($_GET['editQuestion'])) {
  26. $objQuestion = Question::read ($_GET['editQuestion']);
  27. $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  28. if (isset($exerciseId) && !empty($exerciseId)) {
  29. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  30. $sql="SELECT max_score FROM $TBL_LP_ITEM
  31. WHERE item_type = '".TOOL_QUIZ."' AND path ='".Database::escape_string($exerciseId)."'";
  32. $result = Database::query($sql);
  33. if (Database::num_rows($result) > 0) {
  34. //Display::display_warning_message(get_lang('EditingScoreCauseProblemsToExercisesInLP'));
  35. }
  36. }
  37. } else {
  38. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  39. $action = api_get_self()."?".api_get_cidreq()."&modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  40. }
  41. if(is_object($objQuestion)) {
  42. /*********************
  43. * FORM STYLES
  44. *********************/
  45. // if you have a better way to improve the display, please inform me e.marguin@elixir-interactive.com
  46. $styles = '
  47. <style>
  48. div.row div.label{
  49. width: 10%;
  50. }
  51. div.row div.formw{
  52. width: 85%;
  53. }
  54. </style>
  55. ';
  56. echo $styles;
  57. /*********************
  58. * INIT FORM
  59. *********************/
  60. $form = new FormValidator('question_admin_form','post',$action);
  61. /*********************
  62. * FORM CREATION
  63. *********************/
  64. if(isset($_GET['editQuestion'])) {
  65. $class="save";
  66. $text=get_lang('ModifyQuestion');
  67. $type = Security::remove_XSS($_GET['type']);
  68. } else {
  69. $class="add";
  70. $text=get_lang('AddQuestionToExercise');
  71. $type = $_REQUEST['answerType'];
  72. }
  73. $types_information = $objQuestion->get_types_information();
  74. $form_title_extra = get_lang($types_information[$type][1]);
  75. // form title
  76. $form->addElement('header', '', $text.': '.$form_title_extra);
  77. // question form elements
  78. $objQuestion -> createForm ($form,array('Height'=>150));
  79. // answer form elements
  80. $objQuestion -> createAnswersForm ($form);
  81. // this variable $show_quiz_edition comes from admin.php blocks the exercise/quiz modifications
  82. if (!$show_quiz_edition) {
  83. $form->freeze();
  84. }
  85. // submit button is implemented in every question type
  86. //$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
  87. //$renderer = $form->defaultRenderer();
  88. //$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','submitQuestion');
  89. /**********************
  90. * FORM VALIDATION
  91. **********************/
  92. if(isset($_POST['submitQuestion']) && $form->validate()) {
  93. // question
  94. $objQuestion -> processCreation($form,$objExercise);
  95. // answers
  96. $objQuestion -> processAnswersCreation($form,$nb_answers);
  97. // TODO: maybe here is the better place to index this tool, including answers text
  98. // redirect
  99. if($objQuestion -> type != HOT_SPOT)
  100. echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  101. else
  102. echo '<script type="text/javascript">window.location.href="admin.php?hotspotadmin='.$objQuestion->id.'"</script>';
  103. } else {
  104. /******************
  105. * FORM DISPLAY
  106. ******************/
  107. echo '<h3>'.$questionName.'</h3>';
  108. if(!empty($pictureName)){
  109. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  110. }
  111. if(!empty($msgErr))
  112. {
  113. Display::display_normal_message($msgErr); //main API
  114. }
  115. // display the form
  116. $form->display();
  117. }
  118. }
  119. ?>