2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
\r
6 /* Adaptive Technology Resource Centre / University of Toronto */
\r
7 /* http://atutor.ca */
\r
9 /* This program is free software. You can redistribute it and/or */
\r
10 /* modify it under the terms of the GNU General Public License */
\r
11 /* as published by the Free Software Foundation. */
\r
12 /************************************************************************/
\r
13 // $Id: grade_scale_add.php 7208 2008-05-28 16:07:24Z cindy $
\r
15 $page = 'gradebook';
\r
17 define('AT_INCLUDE_PATH', '../../include/');
\r
18 require_once(AT_INCLUDE_PATH.'vitals.inc.php');
\r
19 authenticate(AT_PRIV_GRADEBOOK);
\r
21 require_once("lib/gradebook.inc.php");
\r
23 // Checks if the given test has students taken it more than once, if has,
\r
24 // print feedback and return false, otherwise, return true.
\r
25 function is_test_updatable($gradebook_test_id)
\r
29 $sql = "SELECT g.id, t.title FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t WHERE g.id=t.test_id AND g.type='ATutor Test' AND g.gradebook_test_id = ". $gradebook_test_id;
\r
30 $result = mysql_query($sql, $db) or die(mysql_error());
\r
31 $row = mysql_fetch_assoc($result);
\r
35 $studs_take_num = get_studs_take_more_than_once($_SESSION["course_id"], $row["id"]);
\r
37 foreach ($studs_take_num as $student => $num)
\r
39 if ($no_error) $no_error = false;
\r
40 $error_msg .= $student . ": " . $num . " times<br>";
\r
45 $f = array('UPDATE_GRADEBOOK',
\r
48 $msg->addFeedback($f);
\r
57 function update_gradebook($gradebook_test_id, $member_id)
\r
61 $sql = "SELECT id, grade_scale_id FROM ".TABLE_PREFIX."gradebook_tests WHERE gradebook_test_id = ". $gradebook_test_id;
\r
62 $result = mysql_query($sql, $db) or die(mysql_error());
\r
63 $row = mysql_fetch_assoc($result);
\r
64 $test_id = $row["id"];
\r
65 $grade_scale_id = $row["grade_scale_id"];
\r
68 $grade = get_member_grade($test_id, $member_id, $grade_scale_id);
\r
72 $sql = "REPLACE INTO ".TABLE_PREFIX."gradebook_detail(gradebook_test_id, member_id, grade) VALUES (".$gradebook_test_id.", ".$member_id.", '".$grade."')";
\r
73 $result = mysql_query($sql, $db) or die(mysql_error());
\r
77 // Initialize all applicable tests array and all enrolled students array
\r
79 $students = array();
\r
81 // generate gradebook test array
\r
82 $sql = "SELECT *, t.title FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t WHERE g.id = t.test_id AND g.type='ATutor Test' AND t.course_id=".$_SESSION["course_id"];
\r
83 $result = mysql_query($sql, $db) or die(mysql_error());
\r
84 while ($row = mysql_fetch_assoc($result))
\r
86 $test["gradebook_test_id"] = $row["gradebook_test_id"];
\r
87 $test["title"] = $row["title"];
\r
89 array_push($tests, $test);
\r
92 // generate students array
\r
93 $sql = "SELECT m.first_name, m.last_name, e.member_id FROM ".TABLE_PREFIX."members m, ".TABLE_PREFIX."course_enrollment e WHERE m.member_id = e.member_id AND e.course_id=".$_SESSION["course_id"]." AND e.approved='y' AND e.role<>'Instructor' ORDER BY m.first_name,m.last_name";
\r
94 $result = mysql_query($sql, $db) or die(mysql_error());
\r
96 while ($row = mysql_fetch_assoc($result))
\r
98 $student["first_name"] = $row["first_name"];
\r
99 $student["last_name"] = $row["last_name"];
\r
100 $student["member_id"] = $row["member_id"];
\r
102 array_push($students, $student);
\r
104 // end of initialization
\r
106 if (isset($_POST['cancel']))
\r
108 $msg->addFeedback('CANCELLED');
\r
109 header('Location: gradebook_tests.php');
\r
112 else if (isset($_POST['update']))
\r
114 if (!$msg->containsErrors())
\r
116 if ($_POST["gradebook_test_id"] == 0)
\r
118 foreach($tests as $test)
\r
120 if (is_test_updatable($test["gradebook_test_id"]))
\r
122 if ($_POST["member_id"]==0)
\r
124 // delete old data for this test
\r
125 $sql = "DELETE from ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id = ".$test["gradebook_test_id"];
\r
126 $result = mysql_query($sql, $db) or die(mysql_error());
\r
128 foreach($students as $student)
\r
129 update_gradebook($test["gradebook_test_id"], $student["member_id"]);
\r
132 update_gradebook($test["gradebook_test_id"], $_POST["member_id"]);
\r
138 if (is_test_updatable($_POST["gradebook_test_id"]))
\r
140 if ($_POST["member_id"]==0)
\r
142 // delete old data for this test
\r
143 $sql = "DELETE from ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id = ".$_POST["gradebook_test_id"];
\r
144 $result = mysql_query($sql, $db) or die(mysql_error());
\r
146 foreach($students as $student)
\r
147 update_gradebook($_POST["gradebook_test_id"], $student["member_id"]);
\r
150 update_gradebook($_POST["gradebook_test_id"], $_POST["member_id"]);
\r
154 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
\r
158 require(AT_INCLUDE_PATH.'header.inc.php');
\r
161 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
\r
162 <div class="input-form">
\r
163 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('update_gradebook'); ?></legend>
\r
166 if (count($tests) == 0)
\r
170 <strong><?php echo _AT('none_found'); ?></strong>
\r
177 echo ' <div class="row">'."\n\r";
\r
178 echo ' <label for="select_tid1">'. _AT("tests") .'</label><br />'."\n\r";
\r
179 echo ' <select name="gradebook_test_id" id="select_tid1">'."\n\r";
\r
180 echo ' <option value="0">'. _AT('all') .'</option>'."\n\r";
\r
182 foreach($tests as $test)
\r
184 echo ' <option value="'.$test[gradebook_test_id].'">'.$test[title].'</option>'."\n\r";
\r
186 echo ' </select>'."\n\r";
\r
187 echo ' </div>'."\n\r";
\r
189 // list of students
\r
190 echo ' <div class="row">'."\n\r";
\r
191 echo ' <label for="select_sid">'. _AT("students") .'</label><br />'."\n\r";
\r
192 echo ' <select name="member_id" id="select_sid">'."\n\r";
\r
193 echo ' <option value="0">'. _AT('all') .'</option>'."\n\r";
\r
195 foreach($students as $student)
\r
197 echo ' <option value="'.$student[member_id].'">'.$student[first_name].' '.$student[last_name].'</option>'."\n\r";
\r
199 echo ' </select>'."\n\r";
\r
200 echo ' </div>'."\n\r";
\r
203 <div class="row buttons">
\r
204 <input type="submit" name="update" value="<?php echo _AT('update'); ?>" />
\r
205 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
215 <form name="form1" method="post" action="mods/gradebook/verify_tests.php">
\r
216 <div class="input-form">
\r
217 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('combine_tests'); ?></legend>
\r
219 <p><?php echo _AT('combine_tests_info'); ?></p>
\r
223 if (count($tests) == 0)
\r
227 <strong><?php echo _AT('none_found'); ?></strong>
\r
234 echo ' <div class="row">'."\n\r";
\r
235 echo ' <label for="select_tid2">'. _AT("tests") .' '. _AT("combine_into").'</label><br />'."\n\r";
\r
236 echo ' <select name="gradebook_test_id" id="select_tid2">'."\n\r";
\r
238 foreach($tests as $test)
\r
239 echo ' <option value="'.$test[gradebook_test_id].'">'.$test[title].'</option>'."\n\r";
\r
241 echo ' </select>'."\n\r";
\r
242 echo ' </div>'."\n\r";
\r
244 // list of atutor tests that can be combined.
\r
245 // These tests can only be taken once and are not in gradebook yet
\r
246 // note: surveys are excluded by checking if question weights are defined
\r
247 $sql_at = "SELECT * FROM ".TABLE_PREFIX."tests t".
\r
248 " WHERE course_id=".$_SESSION["course_id"].
\r
249 " AND num_takes = 1".
\r
250 " AND NOT EXISTS (SELECT 1".
\r
251 " FROM ".TABLE_PREFIX."gradebook_tests g".
\r
252 " WHERE g.id = t.test_id".
\r
253 " AND g.type='ATutor Test')".
\r
254 " AND test_id IN (SELECT test_id FROM ".TABLE_PREFIX."tests_questions_assoc ".
\r
255 " WHERE weight > 0 ".
\r
256 " GROUP BY test_id ".
\r
257 " HAVING count(*) > 1) ".
\r
259 $result_at = mysql_query($sql_at, $db) or die(mysql_error());
\r
261 if (mysql_num_rows($result_at) == 0)
\r
262 echo _AT('none_found');
\r
265 echo ' <div class="row">'."\n\r";
\r
266 echo ' <label for="select_tid3">'. _AT("tests") .' '. _AT("combine_from").'</label><br />'."\n\r";
\r
267 echo ' <select name="test_id" id="select_tid3">'."\n\r";
\r
269 if (mysql_num_rows($result_at) > 0)
\r
271 while ($row_at = mysql_fetch_assoc($result_at))
\r
273 echo ' <option value="'.$row_at[test_id].'">'.$row_at[title].'</option>'."\n\r";
\r
277 echo ' </select>'."\n\r";
\r
278 echo ' </div>'."\n\r";
\r
282 <div class="row buttons">
\r
283 <input type="submit" name="combine" value="<?php echo _AT('combine'); ?>" />
\r
284 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
\r
294 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>
\r