question_create.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. // name of the language file that needs to be included
  4. $language_file='exercice';
  5. // including global Dokeos file
  6. require_once '../inc/global.inc.php';
  7. // including additional libraries
  8. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  9. require_once 'question.class.php';
  10. require_once 'exercise.class.php';
  11. // the section (tabs)
  12. $this_section=SECTION_COURSES;
  13. // notice for unauthorized people.
  14. api_protect_course_script(true);
  15. // breadcrumbs
  16. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  17. // Tool name
  18. $nameTools=get_lang('AddQuestionToExercise');
  19. // The form
  20. $form = new FormValidator('add_question','post',api_get_self().'?'.api_get_cidreq());
  21. // form title
  22. $form->addElement('header','',get_lang('AddQuestionToExercise'));
  23. // the question types (jquery form element)
  24. $form->addElement('hidden', 'question_type_hidden', get_lang('QuestionType'), array('id'=>'question_type_hidden'));
  25. $form->addElement('static','','<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.customselect.js" type="text/javascript"></script>');
  26. $form->addElement('static','select_question_type', get_lang('QuestionType'),'<div id="questiontypes"></div>');
  27. //session id
  28. $session_id = api_get_session_id();
  29. // the exercices
  30. $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
  31. $sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE active<>'-1' AND session_id=".$session_id." ORDER BY title ASC";
  32. $result = Database::query($sql);
  33. $exercises['-'] = '-'.get_lang('SelectExercice').'-';
  34. while ($row = Database :: fetch_array($result)) {
  35. $exercises[$row['id']] = cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  36. }
  37. $form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
  38. // generate default content
  39. $form->addElement('checkbox', 'is_content', get_lang('DefaultContent'), null, array('checked' => true));
  40. // the submit button
  41. $form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
  42. // setting the rules
  43. // $form->addRule('question_type', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  44. $form->addRule('exercice', '<span class="required">'.get_lang('ThisFieldIsRequired').'</span>', 'required');
  45. $form->addRule('exercice', '<span class="required">'.get_lang('YouHaveToSelectATest').'</span>', 'numeric');
  46. $form->registerRule('validquestiontype', 'callback', 'check_question_type');
  47. $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
  48. if ($form->validate()) {
  49. $values = $form->exportValues();
  50. foreach (Question::$questionTypes as $question_type_id => $question_type_class_and_name) {
  51. if (get_lang($question_type_class_and_name[1]) == $values['question_type_hidden']) {
  52. $answer_type = $question_type_id;
  53. }
  54. }
  55. // check feedback_type from current exercise for type of question delineation
  56. $exercise_id = intval($values['exercice']);
  57. $sql = "SELECT feedback_type FROM $tbl_exercices WHERE id = '$exercise_id'";
  58. $rs_feedback_type = Database::query($sql,__FILE__,__LINE__);
  59. $row_feedback_type = Database::fetch_row($rs_feedback_type);
  60. $feedback_type = $row_feedback_type[0];
  61. // if question type does not belong to self-evaluation (immediate feedback) it'll send an error
  62. if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
  63. ($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
  64. header('Location: question_create.php?'.api_get_cidreq().'&error=true');
  65. exit;
  66. }
  67. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
  68. exit;
  69. } else {
  70. // header
  71. Display::display_header($nameTools);
  72. echo '<div class="actions">';
  73. echo '<a href="exercice.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'','32').'</a>';
  74. echo '</div>';
  75. // displaying the form
  76. $form->display();
  77. // footer
  78. Display::display_footer();
  79. }
  80. ?>
  81. <script>
  82. var ddlObj1=$("#questiontypes").finalselect({id:"test",viewWidth:'260px', viewHeight:'150px', selectText:'<?php echo Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle; cursor:hand'))."&nbsp;&nbsp;<a href=\"#\"> ".get_lang('SelectQuestionType'); echo "</a>"; ?>', viewMouseoverColor: '#EFEFEF'});
  83. $("#test-select").bind('click',function(){
  84. $("#question_type_hidden").val(ddlObj1.getText());
  85. });
  86. <?php
  87. // defining the pictures of the question types
  88. $pictures_question_types[1] = 'mcua.gif';
  89. $pictures_question_types[2] = 'mcma.gif';
  90. $pictures_question_types[3] = 'fill_in_blanks.gif';
  91. $pictures_question_types[4] = 'matching.gif';
  92. $pictures_question_types[5] = 'open_answer.gif';
  93. $pictures_question_types[6] = 'hotspot.gif';
  94. $pictures_question_types[8] = 'hotspot_delineation.gif';
  95. $pictures_question_types[9] = 'mcmac.gif';
  96. $pictures_question_types[10] = 'mcuao.gif';
  97. $pictures_question_types[11] = 'mcmao.gif';
  98. $pictures_question_types[12] = 'mcmaco.gif';
  99. foreach (Question::$questionTypes as $key=>$value) {
  100. if ($key != HOT_SPOT_DELINEATION ) { // DELINEATION hide
  101. ?>
  102. ddlObj1.addItem('<table width="100%"><tr><td style="width: 37px;" valign="top"><?php Display::display_icon($pictures_question_types[$key],addslashes(get_lang($value[1])),array('height'=>'40px;', 'style' => 'vertical-align:top; cursor:hand;')); ?></td><td><span class="thistext" style="cursor:hand"><?php echo addslashes(get_lang($value[1])); ?></span><br/><sub><?php /*echo addslashes(get_lang($value[1].'Comment'));*/ ?></sub></td></tr></table>','');
  103. <?php
  104. }
  105. }
  106. ?>
  107. </script>
  108. <?php
  109. function check_question_type($parameter) {
  110. foreach (Question::$questionTypes as $key=>$value) {
  111. $valid_question_types[] = get_lang($value[1]);
  112. //$valid_question_types[] = trim($value[1]);
  113. }
  114. if (in_array($parameter, $valid_question_types)) {
  115. return true;
  116. } else {
  117. return false;
  118. }
  119. }