question_create.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // the section (tabs)
  11. $this_section=SECTION_COURSES;
  12. // notice for unauthorized people.
  13. api_protect_course_script(true);
  14. // breadcrumbs
  15. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  16. // Tool name
  17. $nameTools=get_lang('AddQuestionToExercise');
  18. // The form
  19. $form = new FormValidator('add_question','post',api_get_self().'?'.api_get_cidreq());
  20. // form title
  21. $form->addElement('header','',get_lang('AddQuestionToExercise'));
  22. // the question types (normal form element)
  23. /*
  24. foreach (Question::$questionTypes as $key=>$value)
  25. {
  26. $question_types[] = get_lang($value[1]);
  27. }
  28. $form->addElement('select', 'question_type', get_lang('QuestionType'), $question_types);
  29. */
  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.js" type="text/javascript"></script>
  33. <script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.customselect.js" type="text/javascript"></script>');
  34. $form->addElement('static','select_question_type', get_lang('QuestionType'),'<div id="questiontypes"></div>');
  35. //session id
  36. $session_id = api_get_session_id();
  37. // the exercices
  38. $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
  39. $sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE 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']] = $row['title'];
  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. //echo 'form validates';
  59. //print_r($values);
  60. foreach (Question::$questionTypes as $question_type_id => $question_type_class_and_name) {
  61. if (get_lang($question_type_class_and_name[1]) == $values['question_type_hidden']) {
  62. $answer_type = $question_type_id;
  63. }
  64. }
  65. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&isContent='.$values['is_content'].'&answerType='.$answer_type);
  66. exit;
  67. } else {
  68. // header
  69. Display::display_header($nameTools);
  70. echo '<div class="actions">';
  71. echo '<a href="exercice.php?show=test">' . Display :: return_icon('message_reply_forum.png', get_lang('GoBackToQuestionList')) . get_lang('GoBackToQuestionList') . '</a>';
  72. echo '</div>';
  73. // displaying the form
  74. $form->display();
  75. // footer
  76. Display::display_footer();
  77. }
  78. ?>
  79. <script>
  80. 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>"; ?>',selectImage:'<?php echo api_get_path(WEB_IMG_PATH); ?>select.png', viewMouseoverColor: '#EFEFEF'});
  81. $("#test-select").bind('click',function(){
  82. $("#question_type_hidden").val(ddlObj1.getText());
  83. });
  84. <?php
  85. // defining the pictures of the question types
  86. $pictures_question_types[1] = 'mcua.gif';
  87. $pictures_question_types[2] = 'mcma.gif';
  88. $pictures_question_types[3] = 'fill_in_blanks.gif';
  89. $pictures_question_types[4] = 'matching.gif';
  90. $pictures_question_types[5] = 'open_answer.gif';
  91. $pictures_question_types[6] = 'hotspot.gif';
  92. $pictures_question_types[9] = 'mcmac.gif';
  93. foreach (Question::$questionTypes as $key=>$value) {
  94. ?>
  95. 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>','');
  96. <?php
  97. }
  98. ?>
  99. </script>
  100. <?php
  101. function check_question_type($parameter) {
  102. foreach (Question::$questionTypes as $key=>$value) {
  103. $valid_question_types[] = get_lang($value[1]);
  104. //$valid_question_types[] = trim($value[1]);
  105. }
  106. if (in_array($parameter, $valid_question_types)) {
  107. return true;
  108. } else {
  109. return false;
  110. }
  111. }
  112. ?>