question_create.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php // $Id: question_create.php 20569 2009-05-12 21:34:00Z pcool $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. // name of the language file that needs to be included
  21. $language_file='exercice';
  22. // including global Dokeos file
  23. include("../inc/global.inc.php");
  24. // including additional libraries
  25. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  26. require_once ('question.class.php');
  27. // the section (tabs)
  28. $this_section=SECTION_COURSES;
  29. // notice for unauthorized people.
  30. api_protect_course_script(true);
  31. // breadcrumbs
  32. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  33. // Tool name
  34. $nameTools=get_lang('AddQuestionToExercise');
  35. // The form
  36. $form = new FormValidator('add_question','post');
  37. // form title
  38. $form->addElement('header','',get_lang('AddQuestionToExercise'));
  39. // the question types (normal form element)
  40. /*
  41. foreach (Question::$questionTypes as $key=>$value)
  42. {
  43. $question_types[] = get_lang($value[1]);
  44. }
  45. $form->addElement('select', 'question_type', get_lang('QuestionType'), $question_types);
  46. */
  47. // the question types (jquery form element)
  48. $form->addElement('hidden', 'question_type_hidden', get_lang('QuestionType'), array('id'=>'question_type_hidden'));
  49. $form->addElement('static','','<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript"></script>
  50. <script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.customselect.js" type="text/javascript"></script>');
  51. $form->addElement('static','select_question_type', get_lang('QuestionType'),'<div id="questiontypes"></div>');
  52. // the exercices
  53. $tbl_exercices = Database :: get_course_table(TABLE_QUIZ_TEST);
  54. $sql = "SELECT id,title,type,description, results_disabled FROM $tbl_exercices WHERE active<>'-1' ORDER BY title ASC";
  55. $result = Database::query($sql, __FILE__, __LINE__);
  56. $exercises['-'] = '-'.get_lang('SelectExercice').'-';
  57. while ($row = Database :: fetch_array($result))
  58. {
  59. $exercises[$row['id']] = $row['title'];
  60. }
  61. $form->addElement('select', 'exercice', get_lang('Exercice'), $exercises);
  62. // the submit button
  63. $form->addElement('style_submit_button', 'SubmitCreateQuestion', get_lang('CreateQuestion'), 'class="add"');
  64. // setting the rules
  65. // $form->addRule('question_type', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  66. $form->addRule('exercice', '<span class="required">'.get_lang('ThisFieldIsRequired').'</span>', 'required');
  67. $form->addRule('exercice', '<span class="required">'.get_lang('YouHaveToSelectATest').'</span>', 'numeric');
  68. $form->registerRule('validquestiontype', 'callback', 'check_question_type');
  69. $form->addRule('question_type_hidden', get_lang('InvalidQuestionType'), 'validquestiontype');
  70. if ($form->validate())
  71. {
  72. $values = $form->exportValues();
  73. //echo 'form validates';
  74. //print_r($values);
  75. foreach (Question::$questionTypes as $question_type_id => $question_type_class_and_name)
  76. {
  77. if (get_lang($question_type_class_and_name[1]) == $values['question_type_hidden'])
  78. {
  79. $answer_type = $question_type_id;
  80. }
  81. }
  82. header('Location: admin.php?exerciseId='.$values['exercice'].'&newQuestion=yes&answerType='.$answer_type);
  83. }
  84. else
  85. {
  86. // header
  87. Display::display_header($nameTools);
  88. // displaying the form
  89. $form->display();
  90. // footer
  91. Display::display_footer();
  92. }
  93. ?>
  94. <script>
  95. 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;".get_lang('SelectQuestionType');?>',selectImage:'<?php echo api_get_path(WEB_IMG_PATH); ?>select.png', viewMouseoverColor: '#EFEFEF'});
  96. $("#test-select").bind('click',function(){
  97. $("#question_type_hidden").val(ddlObj1.getText());
  98. });
  99. <?php
  100. // defining the pictures of the question types
  101. $pictures_question_types[1] = 'mcua.gif';
  102. $pictures_question_types[2] = 'mcma.gif';
  103. $pictures_question_types[3] = 'fill_in_blanks.gif';
  104. $pictures_question_types[4] = 'matching.gif';
  105. $pictures_question_types[5] = 'open_answer.gif';
  106. $pictures_question_types[6] = 'hotspot.gif';
  107. foreach (Question::$questionTypes as $key=>$value)
  108. {
  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. </script>
  115. <?php
  116. function check_question_type($parameter)
  117. {
  118. foreach (Question::$questionTypes as $key=>$value)
  119. {
  120. $valid_question_types[] = get_lang($value[1]);
  121. //$valid_question_types[] = trim($value[1]);
  122. }
  123. if (in_array($parameter, $valid_question_types))
  124. {
  125. return true;
  126. }
  127. else
  128. {
  129. return false;
  130. }
  131. }
  132. ?>