question_create.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. $course_id = api_get_course_int_id();
  39. $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";
  40. $result = Database::query($sql);
  41. $exercises['-'] = '-'.get_lang('SelectExercice').'-';
  42. while ($row = Database :: fetch_array($result)) {
  43. $exercises[$row['id']] = cut($row['title'], EXERCISE_MAX_NAME_SIZE);
  44. }
  45. $form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
  46. // generate default content
  47. $form->addElement('checkbox', 'is_content', get_lang('DefaultContent'), null, array('checked' => true));
  48. // the submit button
  49. $form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
  50. // setting the rules
  51. // $form->addRule('question_type', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  52. $form->addRule('exercice', '<span class="required">'.get_lang('ThisFieldIsRequired').'</span>', 'required');
  53. $form->addRule('exercice', '<span class="required">'.get_lang('YouHaveToSelectATest').'</span>', '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. foreach (Question::$questionTypes as $question_type_id => $question_type_class_and_name) {
  59. if (get_lang($question_type_class_and_name[1]) == $values['question_type_hidden']) {
  60. $answer_type = $question_type_id;
  61. }
  62. }
  63. // check feedback_type from current exercise for type of question delineation
  64. $exercise_id = intval($values['exercice']);
  65. $sql = "SELECT feedback_type FROM $tbl_exercices WHERE c_id = $course_id AND id = '$exercise_id'";
  66. $rs_feedback_type = Database::query($sql,__FILE__,__LINE__);
  67. $row_feedback_type = Database::fetch_row($rs_feedback_type);
  68. $feedback_type = $row_feedback_type[0];
  69. // if question type does not belong to self-evaluation (immediate feedback) it'll send an error
  70. if (($answer_type == HOT_SPOT_DELINEATION && $feedback_type != 1) ||
  71. ($feedback_type == 1 && ($answer_type != HOT_SPOT_DELINEATION && $answer_type != UNIQUE_ANSWER))) {
  72. header('Location: question_create.php?'.api_get_cidreq().'&error=true');
  73. exit;
  74. }
  75. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
  76. exit;
  77. } else {
  78. // header
  79. Display::display_header($nameTools);
  80. echo '<div class="actions">';
  81. echo '<a href="exercice.php?show=test">'.Display :: return_icon('back.png', get_lang('BackToExercisesList'),'','32').'</a>';
  82. echo '</div>';
  83. // displaying the form
  84. $form->display();
  85. // footer
  86. Display::display_footer();
  87. }
  88. ?>
  89. <script>
  90. 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'});
  91. $("#test-select").bind('click',function(){
  92. $("#question_type_hidden").val(ddlObj1.getText());
  93. });
  94. <?php
  95. // defining the pictures of the question types
  96. $pictures_question_types[1] = 'mcua.gif';
  97. $pictures_question_types[2] = 'mcma.gif';
  98. $pictures_question_types[3] = 'fill_in_blanks.gif';
  99. $pictures_question_types[4] = 'matching.gif';
  100. $pictures_question_types[5] = 'open_answer.gif';
  101. $pictures_question_types[6] = 'hotspot.gif';
  102. $pictures_question_types[8] = 'hotspot_delineation.gif';
  103. $pictures_question_types[9] = 'mcmac.gif';
  104. $pictures_question_types[10] = 'mcuao.gif';
  105. $pictures_question_types[11] = 'mcmao.gif';
  106. $pictures_question_types[12] = 'mcmaco.gif';
  107. foreach (Question::$questionTypes as $key=>$value) {
  108. if ($key != HOT_SPOT_DELINEATION ) { // DELINEATION hide
  109. ?>
  110. 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>','');
  111. <?php
  112. }
  113. }
  114. ?>
  115. </script>
  116. <?php
  117. function check_question_type($parameter) {
  118. foreach (Question::$questionTypes as $key=>$value) {
  119. $valid_question_types[] = get_lang($value[1]);
  120. //$valid_question_types[] = trim($value[1]);
  121. }
  122. if (in_array($parameter, $valid_question_types)) {
  123. return true;
  124. } else {
  125. return false;
  126. }
  127. }