question_admin.inc.php 3.6 KB

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