2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2007 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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; }
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)) {
20 if (!$_SESSION['enroll']) {
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))) {
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:
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);
41 if ($row2 = mysql_fetch_assoc($result2)) {
49 function print_question_cats($cat_id = 0) {
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);
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" ';
62 echo '>'.$row['title'].'</option>';
66 function print_VE ($area) {
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>');
73 //possibley add a <noscript> link to filemanager with target="_blank"
76 function get_random_outof($test_id, $result_id) {
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;
82 $result = mysql_query($sql, $db);
84 if ($row = mysql_fetch_assoc($result)) {
85 return $row['weight'];