question_admin.inc.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * Statement (?) administration
  19. * This script allows to manage the statements of questions.
  20. * It is included from the script admin.php
  21. * @package dokeos.exercise
  22. * @author Olivier Brouckaert
  23. * @version $Id: question_admin.inc.php 22126 2009-07-15 22:38:39Z juliomontoya $
  24. */
  25. /*
  26. ==============================================================================
  27. INIT SECTION
  28. ==============================================================================
  29. */
  30. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  31. include_once(api_get_path(LIBRARY_PATH).'image.lib.php');
  32. // ALLOWED_TO_INCLUDE is defined in admin.php
  33. if(!defined('ALLOWED_TO_INCLUDE'))
  34. {
  35. exit();
  36. }
  37. /*********************
  38. * INIT QUESTION
  39. *********************/
  40. if(isset($_GET['editQuestion']))
  41. {
  42. $objQuestion = Question::read ($_GET['editQuestion']);
  43. $action = api_get_self()."?modifyQuestion=".$modifyQuestion."&editQuestion=".$objQuestion->id;
  44. if (isset($exerciseId) && !empty($exerciseId)) {
  45. $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
  46. $sql="SELECT max_score FROM $TBL_LP_ITEM
  47. WHERE item_type = '".TOOL_QUIZ."' AND path ='".Database::escape_string($exerciseId)."'";
  48. $result = api_sql_query($sql);
  49. if (Database::num_rows($result) > 0) {
  50. Display::display_warning_message(get_lang('EditingScoreCauseProblemsToExercisesInLP'));
  51. }
  52. }
  53. } else {
  54. $objQuestion = Question :: getInstance($_REQUEST['answerType']);
  55. $action = api_get_self()."?modifyQuestion=".$modifyQuestion."&newQuestion=".$newQuestion;
  56. }
  57. if(is_object($objQuestion))
  58. {
  59. /*********************
  60. * FORM STYLES
  61. *********************/
  62. // if you have a better way to improve the display, please inform me e.marguin@elixir-interactive.com
  63. $styles = '
  64. <style>
  65. div.row div.label{
  66. width: 10%;
  67. }
  68. div.row div.formw{
  69. width: 85%;
  70. }
  71. </style>
  72. ';
  73. echo $styles;
  74. /*********************
  75. * INIT FORM
  76. *********************/
  77. $form = new FormValidator('question_admin_form','post',$action);
  78. /*********************
  79. * FORM CREATION
  80. *********************/
  81. if(isset($_GET['editQuestion'])) {
  82. $class="save";
  83. $text=get_lang('ModifyQuestion');
  84. } else {
  85. $class="add";
  86. $text=get_lang('AddQuestionToExercise');
  87. }
  88. $types_information = $objQuestion->get_types_information();
  89. $form_title_extra = get_lang($types_information[$_REQUEST['answerType']][1]);
  90. // form title
  91. $form->addElement('header', '', $text.': '.$form_title_extra);
  92. // question form elements
  93. $objQuestion -> createForm ($form,array('Height'=>150));
  94. // answer form elements
  95. $objQuestion -> createAnswersForm ($form);
  96. // submit button is implemented in every question type
  97. //$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
  98. //$renderer = $form->defaultRenderer();
  99. //$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','submitQuestion');
  100. /**********************
  101. * FORM VALIDATION
  102. **********************/
  103. if(isset($_POST['submitQuestion']) && $form->validate())
  104. {
  105. // question
  106. $objQuestion -> processCreation($form,$objExercise);
  107. // answers
  108. $objQuestion -> processAnswersCreation($form,$nb_answers);
  109. // TODO: maybe here is the better place to index this tool, including answers text
  110. // redirect
  111. if($objQuestion -> type != HOT_SPOT)
  112. echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  113. else
  114. echo '<script type="text/javascript">window.location.href="admin.php?hotspotadmin='.$objQuestion->id.'"</script>';
  115. }
  116. else
  117. {
  118. /******************
  119. * FORM DISPLAY
  120. ******************/
  121. echo '<h3>'.$questionName.'</h3>';
  122. if(!empty($pictureName)){
  123. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  124. }
  125. if(!empty($msgErr))
  126. {
  127. Display::display_normal_message($msgErr); //main API
  128. }
  129. // display the form
  130. $form->display();
  131. }
  132. }
  133. ?>