question_admin.inc.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /* For licensing terms, see /chamilo_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. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  17. include_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. } else {
  68. $class="add";
  69. $text=get_lang('AddQuestionToExercise');
  70. }
  71. $types_information = $objQuestion->get_types_information();
  72. $form_title_extra = get_lang($types_information[$_REQUEST['answerType']][1]);
  73. // form title
  74. $form->addElement('header', '', $text.': '.$form_title_extra);
  75. // question form elements
  76. $objQuestion -> createForm ($form,array('Height'=>150));
  77. // answer form elements
  78. $objQuestion -> createAnswersForm ($form);
  79. // submit button is implemented in every question type
  80. //$form->addElement('style_submit_button','submitQuestion',$text, 'class="'.$class.'"');
  81. //$renderer = $form->defaultRenderer();
  82. //$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','submitQuestion');
  83. /**********************
  84. * FORM VALIDATION
  85. **********************/
  86. if(isset($_POST['submitQuestion']) && $form->validate())
  87. {
  88. // question
  89. $objQuestion -> processCreation($form,$objExercise);
  90. // answers
  91. $objQuestion -> processAnswersCreation($form,$nb_answers);
  92. // TODO: maybe here is the better place to index this tool, including answers text
  93. // redirect
  94. if($objQuestion -> type != HOT_SPOT)
  95. echo '<script type="text/javascript">window.location.href="admin.php"</script>';
  96. else
  97. echo '<script type="text/javascript">window.location.href="admin.php?hotspotadmin='.$objQuestion->id.'"</script>';
  98. }
  99. else
  100. {
  101. /******************
  102. * FORM DISPLAY
  103. ******************/
  104. echo '<h3>'.$questionName.'</h3>';
  105. if(!empty($pictureName)){
  106. echo '<img src="../document/download.php?doc_url=%2Fimages%2F'.$pictureName.'" border="0">';
  107. }
  108. if(!empty($msgErr))
  109. {
  110. Display::display_normal_message($msgErr); //main API
  111. }
  112. // display the form
  113. $form->display();
  114. }
  115. }
  116. ?>