tagging as ATutor 1.5.4-release
[atutor.git] / include / lib / test_result_functions.inc.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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 if (!defined('AT_INCLUDE_PATH')) { exit; }
14
15 // returns T/F whether or not this member can view this test:
16 function authenticate_test($tid) {
17         if (authenticate(AT_PRIV_ADMIN, AT_PRIV_RETURN)) {
18                 return TRUE;
19         }
20         if (!$_SESSION['enroll']) {
21                 return FALSE;
22         }
23         global $db;
24
25         $sql    = "SELECT approved FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=$_SESSION[course_id] AND approved='y'";
26         $result = mysql_query($sql, $db);
27         if (!($row = mysql_fetch_assoc($result))) {
28                 return FALSE;
29         }
30
31         $sql    = "SELECT group_id FROM ".TABLE_PREFIX."tests_groups WHERE test_id=$tid";
32         $result = mysql_query($sql, $db);
33         if (mysql_num_rows($result) == 0) {
34                 // not limited to any group; everyone has access:
35                 return TRUE;
36         }
37         while ($row = mysql_fetch_assoc($result)) {
38                 $sql     = "SELECT * FROM ".TABLE_PREFIX."groups_members WHERE group_id=$row[group_id] AND member_id=$_SESSION[member_id]";
39                 $result2 = mysql_query($sql, $db);
40
41                 if ($row2 = mysql_fetch_assoc($result2)) {
42                         return TRUE;
43                 }
44         }
45
46         return FALSE;
47 }
48
49 function print_question_cats($cat_id = 0) {     
50
51         global $db;
52
53         echo '<option value="0">'._AT('cats_uncategorized').'</option>';
54         $sql    = 'SELECT * FROM '.TABLE_PREFIX.'tests_questions_categories WHERE course_id='.$_SESSION['course_id'].' ORDER BY title';
55         $result = mysql_query($sql, $db);
56
57         while ($row = mysql_fetch_array($result)) {
58                 echo '<option value="'.$row['category_id'].'"';
59                 if ($row['category_id'] == $cat_id) {
60                         echo 'selected="selected" ';
61                 }
62                 echo '>'.$row['title'].'</option>';
63         }
64 }
65
66 function print_VE ($area) {
67 ?>
68         <script type="text/javascript" language="javascript">
69                 document.writeln('<a href="#" onclick="javascript:window.open(\'<?php echo AT_BASE_HREF; ?>tools/tests/form_editor.php?area=<?php echo $area; ?>\',\'newWin1\',\'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width=640,height=480\'); return false;" style="cursor: pointer; text-decoration: none" ><?php echo _AT('use_visual_editor'); ?></a>');
70         </script>
71
72 <?php
73         //possibley add a <noscript> link to filemanager with target="_blank"
74 }
75
76 function get_random_outof($test_id, $result_id) {       
77         global $db;
78         $total = 0;
79
80         $sql    = 'SELECT SUM(Q.weight) AS weight FROM '.TABLE_PREFIX.'tests_questions_assoc Q, '.TABLE_PREFIX.'tests_answers A WHERE Q.test_id='.$test_id.' AND Q.question_id=A.question_id AND A.result_id='.$result_id;
81
82         $result = mysql_query($sql, $db);
83
84         if ($row = mysql_fetch_assoc($result)) {
85                 return $row['weight'];
86         }
87
88         return 0;
89 }
90
91 ?>