question_create.php 5.9 KB

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