question_create.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise
  5. * @package chamilo.exercise
  6. */
  7. /**
  8. * Code
  9. */
  10. // name of the language file that needs to be included
  11. $language_file='exercice';
  12. // including global Dokeos file
  13. //require_once '../inc/global.inc.php';
  14. // including additional libraries
  15. require_once 'question.class.php';
  16. require_once 'exercise.class.php';
  17. // the section (tabs)
  18. $this_section=SECTION_COURSES;
  19. // notice for unauthorized people.
  20. api_protect_course_script(true);
  21. // breadcrumbs
  22. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  23. // Tool name
  24. $nameTools=get_lang('AddQuestionToExercise');
  25. // The form
  26. $form = new FormValidator('add_question','post',api_get_self().'?'.api_get_cidreq());
  27. // form title
  28. $form->addElement('header','',get_lang('AddQuestionToExercise'));
  29. $question_list = Question::get_question_type_list();
  30. $question_list_options = array();
  31. foreach ($question_list as $key=> $value) {
  32. $question_list_options[$key] = addslashes(get_lang($value[1]));
  33. }
  34. $form->addElement('select', 'question_type_hidden', get_lang('QuestionType'), $question_list_options, array('id' => 'question_type_hidden'));
  35. //session id
  36. $session_id = api_get_session_id();
  37. // the exercices
  38. $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
  39. $course_id = api_get_course_int_id();
  40. $sql = "SELECT iid,title,type,description, results_disabled
  41. FROM $tbl_exercices WHERE c_id = $course_id AND active<>'-1' AND session_id=".$session_id."
  42. ORDER BY title ASC";
  43. $result = Database::query($sql);
  44. $exercises['-'] = '-'.get_lang('SelectExercice').'-';
  45. while ($row = Database :: fetch_array($result)) {
  46. $exercises[$row['iid']] = Text::cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  47. }
  48. $form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
  49. // generate default content
  50. $form->addElement('checkbox', 'is_content', null, get_lang('DefaultContent'), array('checked' => true));
  51. // the submit button
  52. $form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
  53. // setting the rules
  54. $form->addRule('exercice', get_lang('ThisFieldIsRequired'), 'required');
  55. $form->addRule('exercice', get_lang('YouHaveToSelectATest'), 'numeric');
  56. $form->registerRule('validquestiontype', 'callback', 'check_question_type');
  57. $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
  58. if ($form->validate()) {
  59. $values = $form->exportValues();
  60. $answer_type = $values['question_type_hidden'];
  61. // check feedback_type from current exercise for type of question delineation
  62. $exercise_id = intval($values['exercice']);
  63. $exercise = new Exercise();
  64. $exercise->read($exercise_id);
  65. $feedback_type = $exercise->feedback_type;
  66. // if question type does not belong to self-evaluation (immediate feedback) it'll send an error
  67. if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
  68. ($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
  69. header('Location: question_create.php?'.api_get_cidreq().'&error=true');
  70. exit;
  71. }
  72. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
  73. exit;
  74. } else {
  75. // header
  76. Display::display_header($nameTools);
  77. echo '<div class="actions">';
  78. echo '<a href="exercice.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  79. echo '</div>';
  80. // displaying the form
  81. $form->display();
  82. // footer
  83. Display::display_footer();
  84. }
  85. function check_question_type($parameter) {
  86. $question_list = Question::get_question_type_list();
  87. foreach ($question_list as $key => $value) {
  88. $valid_question_types[] = $key;
  89. }
  90. if (in_array($parameter, $valid_question_types)) {
  91. return true;
  92. } else {
  93. return false;
  94. }
  95. }