PageRenderTime 99ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/mods/_standard/tests/html/tests_questions.inc.php

https://github.com/harriswong/ATutor
PHP | 168 lines | 134 code | 17 blank | 17 comment | 18 complexity | 4c8b49ad7e7882ae0957bf847e03445e MD5 | raw file
  1. <?php
  2. /************************************************************************/
  3. /* ATutor */
  4. /************************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  9. /* This program is free software. You can redistribute it and/or */
  10. /* modify it under the terms of the GNU General Public License */
  11. /* as published by the Free Software Foundation. */
  12. /************************************************************************/
  13. // $Id$
  14. if (!defined('AT_INCLUDE_PATH')) { exit; }
  15. if (isset($_GET['reset_filter'])) {
  16. unset($_GET['category_id']);
  17. }
  18. if (!isset($_GET['category_id'])) {
  19. // Suppress warnings
  20. $_GET['category_id'] = -1;
  21. }
  22. require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
  23. ?>
  24. <fieldset class="group_form" style="width:93%"><legend class="group_form"><?php echo _AT('category'); ?></legend>
  25. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  26. <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
  27. <div class="row">
  28. <label for="cats"><?php echo _AT('category'); ?></label><br />
  29. <select name="category_id" id="cats">
  30. <option value="-1"><?php echo _AT('cats_all'); ?></option>
  31. <?php print_question_cats($_GET['category_id']); ?>
  32. </select>
  33. </div>
  34. <div class="row buttons">
  35. <input type="submit" name="filter" value="<?php echo _AT('filter'); ?>" />
  36. <input type="submit" name="reset_filter" value="<?php echo _AT('reset_filter'); ?>" />
  37. </div>
  38. </form>
  39. </fieldset>
  40. <?php
  41. $cats = array();
  42. if ($_GET['category_id'] >= 0) {
  43. $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions_categories WHERE course_id=$_SESSION[course_id] AND category_id=$_GET[category_id] ORDER BY title";
  44. } else {
  45. $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions_categories WHERE course_id=$_SESSION[course_id] ORDER BY title";
  46. }
  47. $result = mysql_query($sql, $db);
  48. if ($_GET['category_id'] <= 0) {
  49. $cats[] = array('title' => _AT('cats_uncategorized'), 'category_id' => 0);
  50. }
  51. while ($row = mysql_fetch_assoc($result)) {
  52. $cats[] = $row;
  53. }
  54. $cols = 3;
  55. ?>
  56. <?php if ($tid): ?>
  57. <form method="post" action="mods/_standard/tests/add_test_questions_confirm.php" name="form">
  58. <?php else: ?>
  59. <form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="form">
  60. <?php endif; ?>
  61. <table class="data" summary="" rules="cols">
  62. <thead>
  63. <tr>
  64. <th scope="col">&nbsp;</th>
  65. <th scope="col"><?php echo _AT('question'); ?></th>
  66. <th scope="col"><?php echo _AT('type'); ?></th>
  67. </tr>
  68. </thead>
  69. <tfoot>
  70. <?php if ($tid): ?>
  71. <tr>
  72. <td colspan="3">
  73. <input type="hidden" name="tid" value="<?php echo $tid; ?>" />
  74. <input type="submit" name="submit" value="<?php echo _AT('add_to_test_survey'); ?>" accesskey="s" />
  75. <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
  76. </td>
  77. </tr>
  78. <?php else: ?>
  79. <tr>
  80. <td colspan="3">
  81. <input type="submit" name="edit" value="<?php echo _AT('edit'); ?>" />
  82. <input type="submit" name="preview" value="<?php echo _AT('preview'); ?>" />
  83. <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />
  84. <select name='qti_export_version' >
  85. <option selected='selected' value='1.2.1'>QTI 1.2.1</option>
  86. <option value='2.1'>QTI 2.1</option>
  87. </select>
  88. <input type="submit" name="delete" value="<?php echo _AT('delete'); ?>" />
  89. </td>
  90. </tr>
  91. <?php endif; ?>
  92. </tfoot>
  93. <tbody>
  94. <?php
  95. $question_flag = FALSE;
  96. //output categories
  97. foreach ($cats as $cat) {
  98. //ouput questions
  99. $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND category_id=".$cat['category_id']." ORDER BY question";
  100. $result = mysql_query($sql, $db);
  101. if ($row = mysql_fetch_assoc($result)) {
  102. $question_flag = TRUE;
  103. echo '<tr>';
  104. echo '<th colspan="'.$cols.'">';
  105. echo '<input type="checkbox" name="cat'.$cat['category_id'].'" id="cat'.$cat['category_id'].'" onclick="javascript:selectCat('.$cat['category_id'].', this);" /><label for="cat'.$cat['category_id'].'">'.$cat['title'].'</label>';
  106. echo '</th>';
  107. echo '</tr>';
  108. do {
  109. echo '<tr onmousedown="document.form[\'q' . $row['question_id'] . '\'].checked = !document.form[\'q' . $row['question_id'] . '\'].checked; togglerowhighlight(this, \'q'.$row['question_id'].'\');" id="rq'.$row['question_id'].'">';
  110. echo '<td>';
  111. echo '<input type="checkbox" value="'.$row['question_id'].'|'.$row['type'].'" name="questions['.$cat['category_id'].'][]" id="q'.$row['question_id'].'" onmouseup="this.checked=!this.checked" /></td>';
  112. echo '<td>';
  113. echo '<a title="'.AT_print($row[question], 'tests_questions.question').'">';
  114. echo AT_print((validate_length($row['question'], 100, VALIDATE_LENGTH_FOR_DISPLAY)), 'tests_questions.question');
  115. echo '</a>';
  116. echo '</td>';
  117. echo '<td>';
  118. $o = TestQuestions::getQuestion($row['type']);
  119. $o->printName();
  120. echo '</td>';
  121. echo '</tr>';
  122. } while ($row = mysql_fetch_assoc($result));
  123. }
  124. }
  125. if (!$question_flag) {
  126. echo '<tr><td colspan="'.$cols.'">'._AT('none_found').'</td></tr>';
  127. }
  128. ?>
  129. </tbody>
  130. </table>
  131. </form>
  132. <script language="javascript" type="text/javascript">
  133. // <!--
  134. function selectCat(catID, cat) {
  135. for (var i=0;i<document.form.elements.length;i++) {
  136. var e = document.form.elements[i];
  137. if ((e.name == 'questions[' + catID + '][]') && (e.type=='checkbox')) {
  138. e.checked = cat.checked;
  139. togglerowhighlight(document.getElementById("r" + e.id), e.id);
  140. }
  141. }
  142. }
  143. function togglerowhighlight(obj, boxid) {
  144. if (document.getElementById(boxid).checked) {
  145. obj.className = 'selected';
  146. } else {
  147. obj.className = '';
  148. }
  149. }
  150. // -->
  151. </script>