question_create.php 3.9 KB

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