2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require_once(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_GRADEBOOK);
20 require_once("lib/gradebook.inc.php");
22 // Checks if the given test has students taken it more than once, if has,
23 // print feedback and return false, otherwise, return true.
24 function is_test_updatable($gradebook_test_id)
28 $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;
29 $result = mysql_query($sql, $db) or die(mysql_error());
30 $row = mysql_fetch_assoc($result);
34 $studs_take_num = get_studs_take_more_than_once($_SESSION["course_id"], $row["id"]);
36 foreach ($studs_take_num as $member_id => $num)
38 if ($no_error) $no_error = false;
39 $error_msg .= get_display_name($member_id) . ": " . $num . " times<br>";
44 $f = array('UPDATE_GRADEBOOK',
47 $msg->addFeedback($f);
56 function update_gradebook($gradebook_test_id, $member_id)
60 $sql = "SELECT id, grade_scale_id FROM ".TABLE_PREFIX."gradebook_tests WHERE gradebook_test_id = ". $gradebook_test_id;
61 $result = mysql_query($sql, $db) or die(mysql_error());
62 $row = mysql_fetch_assoc($result);
63 $test_id = $row["id"];
64 $grade_scale_id = $row["grade_scale_id"];
67 $grade = get_member_grade($test_id, $member_id, $grade_scale_id);
71 $sql = "REPLACE INTO ".TABLE_PREFIX."gradebook_detail(gradebook_test_id, member_id, grade) VALUES (".$gradebook_test_id.", ".$member_id.", '".$grade."')";
72 $result = mysql_query($sql, $db) or die(mysql_error());
76 // Initialize all applicable tests array and all enrolled students array
80 // generate gradebook test array
81 $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"];
82 $result = mysql_query($sql, $db) or die(mysql_error());
83 while ($row = mysql_fetch_assoc($result))
85 $test["gradebook_test_id"] = $row["gradebook_test_id"];
86 $test["title"] = $row["title"];
88 array_push($tests, $test);
91 // generate students array
92 $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";
93 $result = mysql_query($sql, $db) or die(mysql_error());
95 while ($row = mysql_fetch_assoc($result))
97 $student["first_name"] = $row["first_name"];
98 $student["last_name"] = $row["last_name"];
99 $student["member_id"] = $row["member_id"];
101 array_push($students, $student);
103 // end of initialization
105 if (isset($_POST['cancel']))
107 $msg->addFeedback('CANCELLED');
108 header('Location: gradebook_tests.php');
111 else if (isset($_POST['update']))
113 if (!$msg->containsErrors())
115 if ($_POST["gradebook_test_id"] == 0)
117 foreach($tests as $test)
119 if (is_test_updatable($test["gradebook_test_id"]))
121 if ($_POST["member_id"]==0)
123 // delete old data for this test
124 $sql = "DELETE from ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id = ".$test["gradebook_test_id"];
125 $result = mysql_query($sql, $db) or die(mysql_error());
127 foreach($students as $student)
128 update_gradebook($test["gradebook_test_id"], $student["member_id"]);
131 update_gradebook($test["gradebook_test_id"], $_POST["member_id"]);
137 if (is_test_updatable($_POST["gradebook_test_id"]))
139 if ($_POST["member_id"]==0)
141 // delete old data for this test
142 $sql = "DELETE from ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id = ".$_POST["gradebook_test_id"];
143 $result = mysql_query($sql, $db) or die(mysql_error());
145 foreach($students as $student)
146 update_gradebook($_POST["gradebook_test_id"], $student["member_id"]);
149 update_gradebook($_POST["gradebook_test_id"], $_POST["member_id"]);
153 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
157 require(AT_INCLUDE_PATH.'header.inc.php');
160 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
161 <div class="input-form">
162 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('update_gradebook'); ?></legend>
165 if (count($tests) == 0)
169 <strong><?php echo _AT('none_found'); ?></strong>
176 echo ' <div class="row">'."\n\r";
177 echo ' <label for="select_tid1">'. _AT("tests") .'</label><br />'."\n\r";
178 echo ' <select name="gradebook_test_id" id="select_tid1">'."\n\r";
179 echo ' <option value="0">'. _AT('all') .'</option>'."\n\r";
181 foreach($tests as $test)
183 echo ' <option value="'.$test[gradebook_test_id].'">'.$test[title].'</option>'."\n\r";
185 echo ' </select>'."\n\r";
186 echo ' </div>'."\n\r";
189 echo ' <div class="row">'."\n\r";
190 echo ' <label for="select_sid">'. _AT("students") .'</label><br />'."\n\r";
191 echo ' <select name="member_id" id="select_sid">'."\n\r";
192 echo ' <option value="0">'. _AT('all') .'</option>'."\n\r";
194 foreach($students as $student)
196 echo ' <option value="'.$student[member_id].'">'.$student[first_name].' '.$student[last_name].'</option>'."\n\r";
198 echo ' </select>'."\n\r";
199 echo ' </div>'."\n\r";
202 <div class="row buttons">
203 <input type="submit" name="update" value="<?php echo _AT('update'); ?>" />
204 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
214 <form name="form1" method="post" action="mods/_standard/gradebook/verify_tests.php">
215 <div class="input-form">
216 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('combine_tests'); ?></legend>
218 <p><?php echo _AT('combine_tests_info'); ?></p>
222 if (count($tests) == 0)
226 <strong><?php echo _AT('none_found'); ?></strong>
233 echo ' <div class="row">'."\n\r";
234 echo ' <label for="select_tid2">'. _AT("tests") .' '. _AT("combine_into").'</label><br />'."\n\r";
235 echo ' <select name="gradebook_test_id" id="select_tid2">'."\n\r";
237 foreach($tests as $test)
238 echo ' <option value="'.$test[gradebook_test_id].'">'.$test[title].'</option>'."\n\r";
240 echo ' </select>'."\n\r";
241 echo ' </div>'."\n\r";
243 // list of atutor tests that can be combined.
244 // These tests can only be taken once and are not in gradebook yet
245 // note: surveys are excluded by checking if question weights are defined
246 $sql_at = "SELECT * FROM ".TABLE_PREFIX."tests t".
247 " WHERE course_id=".$_SESSION["course_id"].
248 " AND num_takes = 1".
249 " AND NOT EXISTS (SELECT 1".
250 " FROM ".TABLE_PREFIX."gradebook_tests g".
251 " WHERE g.id = t.test_id".
252 " AND g.type='ATutor Test')".
253 " AND test_id IN (SELECT test_id FROM ".TABLE_PREFIX."tests_questions_assoc ".
254 " GROUP BY test_id ".
255 " HAVING sum(weight) > 0) ".
257 $result_at = mysql_query($sql_at, $db) or die(mysql_error());
259 if (mysql_num_rows($result_at) == 0)
260 echo _AT('none_found');
263 echo ' <div class="row">'."\n\r";
264 echo ' <label for="select_tid3">'. _AT("tests") .' '. _AT("combine_from").'</label><br />'."\n\r";
265 echo ' <select name="test_id" id="select_tid3">'."\n\r";
267 if (mysql_num_rows($result_at) > 0)
269 while ($row_at = mysql_fetch_assoc($result_at))
271 echo ' <option value="'.$row_at[test_id].'">'.$row_at[title].'</option>'."\n\r";
275 echo ' </select>'."\n\r";
276 echo ' </div>'."\n\r";
280 <div class="row buttons">
281 <input type="submit" name="combine" value="<?php echo _AT('combine'); ?>" />
282 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
292 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>