PageRenderTime 71ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_core/editor/editor_tabs/tests.inc.php

https://github.com/harriswong/ATutor
PHP | 214 lines | 153 code | 28 blank | 33 comment | 37 complexity | ea40e28ea6092782f812e6a98f5f932b 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. ?>
  16. <?php
  17. /* Get the list of associated tests with this content on page load */
  18. $_REQUEST['cid'] = intval($_REQUEST['cid']); //uses request 'cause after 'saved', the cid will become $_GET.
  19. $sql = 'SELECT * FROM '.TABLE_PREFIX."content_tests_assoc WHERE content_id=$_REQUEST[cid]";
  20. $result = mysql_query($sql, $db);
  21. while ($row = mysql_fetch_assoc($result)) {
  22. $_POST['tid'][] = $row['test_id'];
  23. }
  24. /* get a list of all the tests we have, and links to create, edit, delete, preview */
  25. $sql = "SELECT *, UNIX_TIMESTAMP(start_date) AS us, UNIX_TIMESTAMP(end_date) AS ue
  26. FROM ".TABLE_PREFIX."tests
  27. WHERE course_id=$_SESSION[course_id]
  28. ORDER BY start_date DESC";
  29. $result = mysql_query($sql, $db);
  30. $num_tests = mysql_num_rows($result);
  31. //If there are no tests, don't display anything except a message
  32. if ($num_tests == 0){
  33. $msg->addInfo('NO_TESTS');
  34. $msg->printInfos();
  35. return;
  36. }
  37. $i = 0;
  38. while($row = mysql_fetch_assoc($result))
  39. {
  40. $results[$i]['test_id'] = $row['test_id'];
  41. $results[$i]['title'] = $row['title'];
  42. if ( ($row['us'] <= time()) && ($row['ue'] >= time() ) ) {
  43. $results[$i]['status'] = '<strong>'._AT('ongoing').'</strong>';
  44. } else if ($row['ue'] < time() ) {
  45. $results[$i]['status'] = '<strong>'._AT('expired').'</strong>';
  46. } else if ($row['us'] > time() ) {
  47. $results[$i]['status'] = '<strong>'._AT('pending').'</strong>';
  48. }
  49. $startend_date_format=_AT('startend_date_format');
  50. $results[$i]['availability'] = AT_date($startend_date_format, $row['start_date'], AT_DATE_MYSQL_DATETIME). ' ' ._AT('to_2').' ';
  51. $results[$i]['availability'] .= AT_date($startend_date_format, $row['end_date'], AT_DATE_MYSQL_DATETIME);
  52. // get result release
  53. if ($row['result_release'] == AT_RELEASE_IMMEDIATE)
  54. $results[$i]['result_release'] = _AT('release_immediate');
  55. else if ($row['result_release'] == AT_RELEASE_MARKED)
  56. $results[$i]['result_release'] = _AT('release_marked');
  57. else if ($row['result_release'] == AT_RELEASE_NEVER)
  58. $results[$i]['result_release'] = _AT('release_never');
  59. //get # marked submissions
  60. $sql_sub = "SELECT COUNT(*) AS sub_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id'];
  61. $result_sub = mysql_query($sql_sub, $db);
  62. $row_sub = mysql_fetch_assoc($result_sub);
  63. $results[$i]['submissions'] = $row_sub['sub_cnt'].' '._AT('submissions').', ';
  64. //get # submissions
  65. $sql_sub = "SELECT COUNT(*) AS marked_cnt FROM ".TABLE_PREFIX."tests_results WHERE status=1 AND test_id=".$row['test_id']." AND final_score=''";
  66. $result_sub = mysql_query($sql_sub, $db);
  67. $row_sub = mysql_fetch_assoc($result_sub);
  68. $results[$i]['submissions'] .= $row_sub['marked_cnt'].' '._AT('unmarked');
  69. //get assigned groups
  70. $sql_sub = "SELECT G.title FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."tests_groups T USING (group_id) WHERE T.test_id=".$row['test_id'];
  71. $result_sub = mysql_query($sql_sub, $db);
  72. if (mysql_num_rows($result_sub) == 0) {
  73. $results[$i]['assign_to'] = _AT('everyone');
  74. } else {
  75. $row_sub = mysql_fetch_assoc($result_sub);
  76. $results[$i]['assign_to'] = $row_sub['title'];
  77. do {
  78. $results[$i]['assign_to'] .= ', '.$row_sub['title'];
  79. } while ($row_sub = mysql_fetch_assoc($result_sub));
  80. }
  81. if ($row['passscore'] == 0 && $row['passpercent'] == 0)
  82. $results[$i]['pass_score'] = _AT('no_pass_score');
  83. else if ($row['passscore'] <> 0)
  84. $results[$i]['pass_score'] = $row['passscore'];
  85. else if ($row['passpercent'] <> 0)
  86. $results[$i]['pass_score'] = $row['passpercent'].'%';
  87. $i++;
  88. }
  89. ?>
  90. <div class="row">
  91. <span style="font-weight:bold"><?php echo _AT('about_content_tests'); ?></span>
  92. </div>
  93. <input type="hidden" name="allow_test_export" id="disallow_test_export" value="0"/>
  94. <!-- <div class="row">
  95. This option has been commented out for the timebeing until the ability to export and view
  96. tests a part of a CP or CP is actually possible
  97. <?php
  98. //Need radio button 'cause one checkbox makes the states indeterministic
  99. //@harris
  100. /*
  101. $test_export_y_checked = '';
  102. $test_export_n_checked = '';
  103. if ($_POST['allow_test_export'] == 1){
  104. $test_export_y_checked = ' checked="checked"';
  105. } else {
  106. $test_export_n_checked = ' checked="checked"';
  107. }
  108. echo _AT('allow_test_export');
  109. */
  110. ?>
  111. <input type="radio" name="allow_test_export" id="allow_test_export" value="1" <?php //echo $test_export_y_checked; ?>/>
  112. <label for="allow_test_export"><?php //echo _AT('yes'); ?></label>
  113. <input type="radio" name="allow_test_export" id="disallow_test_export" value="0" <?php //echo $test_export_n_checked; ?>/>
  114. <label for="disallow_test_export"><?php //echo _AT('no'); ?></label>
  115. </div>
  116. -->
  117. <div class="row">
  118. <p><?php echo _AT('custom_test_message'); ?></p>
  119. <textarea name="test_message"><?php echo $_POST['test_message']; ?></textarea>
  120. </div>
  121. <?php print_test_table($results, $_POST['tid']);?>
  122. <?php
  123. // display pre-tests
  124. $sql = 'SELECT * FROM '.TABLE_PREFIX."content_prerequisites WHERE content_id=$_REQUEST[cid] AND type='".CONTENT_PRE_TEST."'";
  125. $result = mysql_query($sql, $db);
  126. while ($row = mysql_fetch_assoc($result)) {
  127. $_POST['pre_tid'][] = $row['item_id'];
  128. }
  129. ?>
  130. <div class="row">
  131. <span style="font-weight:bold"><?php echo _AT('define_pretest'); ?></span><br />
  132. <small>&middot; <?php echo _AT('about_pretest'); ?></small><br />
  133. <?php echo _AT('applies_to_all_sub_pages');?>
  134. </div>
  135. <?php print_test_table($results, $_POST['pre_tid'], 'pre_');?>
  136. <?php function print_test_table($results, $post_tids, $id_prefix='') {?>
  137. <div>
  138. <table class="data" summary="" style="width: 90%" rules="cols">
  139. <thead>
  140. <tr>
  141. <th scope="col">&nbsp;</th>
  142. <th scope="col"><?php echo _AT('title'); ?></th>
  143. <th scope="col"><?php echo _AT('status'); ?></th>
  144. <th scope="col"><?php echo _AT('availability'); ?></th>
  145. <th scope="col"><?php echo _AT('result_release'); ?></th>
  146. <th scope="col"><?php echo _AT('submissions'); ?></th>
  147. <th scope="col"><?php echo _AT('pass_score'); ?></th>
  148. <th scope="col"><?php echo _AT('assigned_to'); ?></th>
  149. </tr>
  150. </thead>
  151. <tbody>
  152. <?php foreach ($results as $row) { ?>
  153. <?php
  154. $checkMe = '';
  155. if (is_array($post_tids) && in_array($row['test_id'], $post_tids)){
  156. $checkMe = ' checked="checked"';
  157. }
  158. ?>
  159. <tr onmousedown="toggleTestSelect('<?php echo $id_prefix; ?>r_<?php echo $row['test_id']; ?>');rowselect(this);" id="<?php echo $id_prefix; ?>r_<?php echo $row['test_id']; ?>">
  160. <td><input type="checkbox" name="<?php echo $id_prefix; ?>tid[]" value="<?php echo $row['test_id']; ?>" id="<?php echo $id_prefix; ?>t<?php echo $row['test_id']; ?>" <?php echo $checkMe; ?> onmouseup="this.checked=!this.checked" /></td>
  161. <td><?php echo $row['title']; ?></td>
  162. <td><?php echo $row['status']; ?></td>
  163. <td><?php echo $row['availability']; ?></td>
  164. <td><?php echo $row['result_release']; ?></td>
  165. <td><?php echo $row['submissions']; ?></td>
  166. <td><?php echo $row['pass_score']; ?></td>
  167. <td><?php echo $row['assign_to']; ?></td>
  168. </tr>
  169. <?php } ?>
  170. </tbody>
  171. </table>
  172. </div>
  173. <br />
  174. <?php }?>
  175. <script language="javascript" type="text/javascript">
  176. function toggleTestSelect(r_id){
  177. var row = document.getElementById(r_id);
  178. var checkBox = row.cells[0].firstChild;
  179. if (checkBox.checked == true){
  180. checkBox.checked = false;
  181. } else {
  182. checkBox.checked = true;
  183. }
  184. }
  185. </script>