question_create.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 id,title,type,description, results_disabled FROM $tbl_exercices WHERE c_id = $course_id AND active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
  41. $result = Database::query($sql);
  42. $exercises['-'] = '-'.get_lang('SelectExercice').'-';
  43. while ($row = Database :: fetch_array($result)) {
  44. $exercises[$row['id']] = Text::cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  45. }
  46. $form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
  47. // generate default content
  48. $form->addElement('checkbox', 'is_content', null, get_lang('DefaultContent'), array('checked' => true));
  49. // the submit button
  50. $form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
  51. // setting the rules
  52. $form->addRule('exercice', get_lang('ThisFieldIsRequired'), 'required');
  53. $form->addRule('exercice', get_lang('YouHaveToSelectATest'), 'numeric');
  54. $form->registerRule('validquestiontype', 'callback', 'check_question_type');
  55. $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
  56. if ($form->validate()) {
  57. $values = $form->exportValues();
  58. $answer_type = $values['question_type_hidden'];
  59. // check feedback_type from current exercise for type of question delineation
  60. $exercise_id = intval($values['exercice']);
  61. $sql = "SELECT feedback_type FROM $tbl_exercices WHERE c_id = $course_id AND id = '$exercise_id'";
  62. $rs_feedback_type = Database::query($sql);
  63. $row_feedback_type = Database::fetch_row($rs_feedback_type);
  64. $feedback_type = $row_feedback_type[0];
  65. // if question type does not belong to self-evaluation (immediate feedback) it'll send an error
  66. if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
  67. ($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
  68. header('Location: question_create.php?'.api_get_cidreq().'&error=true');
  69. exit;
  70. }
  71. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
  72. exit;
  73. } else {
  74. // header
  75. Display::display_header($nameTools);
  76. echo '<div class="actions">';
  77. echo '<a href="exercice.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'',ICON_SIZE_MEDIUM).'</a>';
  78. echo '</div>';
  79. // displaying the form
  80. $form->display();
  81. // footer
  82. Display::display_footer();
  83. }
  84. function check_question_type($parameter) {
  85. $question_list = Question::get_question_type_list();
  86. foreach ($question_list as $key => $value) {
  87. $valid_question_types[] = $key;
  88. }
  89. if (in_array($parameter, $valid_question_types)) {
  90. return true;
  91. } else {
  92. return false;
  93. }
  94. }