2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
17 define('AT_INCLUDE_PATH', '../../../include/');
18 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 authenticate(AT_PRIV_GRADEBOOK);
21 // initialize relationship between gradebook_test_id and external test name
25 $sql = "SELECT * FROM ".TABLE_PREFIX."gradebook_tests WHERE course_id=".$_SESSION["course_id"]." ORDER BY title";
27 $sql_at = "SELECT gradebook_test_id, t.title FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t".
28 " WHERE g.id=t.test_id " .
29 " AND g.type='ATutor Test' ".
30 " AND t.course_id=".$_SESSION["course_id"].
32 $result_at = mysql_query($sql_at, $db) or die(mysql_error());
35 $sql_aa = "SELECT gradebook_test_id, a.title FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."assignments a".
36 " WHERE g.id=a.assignment_id " .
37 " AND g.type='ATutor Assignment' ".
38 " AND a.course_id=".$_SESSION["course_id"].
40 $result_aa = mysql_query($sql_aa, $db) or die(mysql_error());
43 $sql_e = "SELECT gradebook_test_id, title FROM ".TABLE_PREFIX."gradebook_tests".
44 " WHERE type='External' ".
45 " AND course_id=".$_SESSION["course_id"].
47 $result_e = mysql_query($sql_e, $db) or die(mysql_error());
49 // end of initialization
51 if (isset($_POST['cancel']))
53 $msg->addFeedback('CANCELLED');
54 header('Location: gradebook_tests.php');
57 else if (isset($_POST['export']))
59 // generate students array
60 $sql = "SELECT m.first_name, m.last_name, m.email, 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,m.email";
61 $result = mysql_query($sql, $db) or die(mysql_error());
63 if (mysql_num_rows($result)==0)
65 // nothing to send. empty file
66 $msg->addError('ENROLLMENT_NONE_FOUND');
70 $this_row = "First Name, Last Name, Email, Grade\n";
71 while ($row = mysql_fetch_assoc($result))
74 $sql_title = "(SELECT g.gradebook_test_id, t.title".
75 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."tests t".
76 " WHERE g.type='ATutor Test'".
77 " AND g.id = t.test_id".
78 " AND g.gradebook_test_id=".$_POST['gradebook_test_id'].")".
79 " UNION (SELECT g.gradebook_test_id, a.title".
80 " FROM ".TABLE_PREFIX."gradebook_tests g, ".TABLE_PREFIX."assignments a".
81 " WHERE g.type='ATutor Assignment'".
82 " AND g.id = a.assignment_id".
83 " AND g.gradebook_test_id=".$_POST['gradebook_test_id'].")".
84 " UNION (SELECT gradebook_test_id, title ".
85 " FROM ".TABLE_PREFIX."gradebook_tests".
86 " WHERE type='External'".
87 " AND gradebook_test_id=".$_POST['gradebook_test_id'].")";
88 $result_title = mysql_query($sql_title, $db) or die(mysql_error());
89 $row_title = mysql_fetch_assoc($result_title);
92 $sql_grade = "SELECT grade FROM ".TABLE_PREFIX."gradebook_detail WHERE gradebook_test_id=".$_POST["gradebook_test_id"]." AND member_id=".$row["member_id"];
93 $result_grade = mysql_query($sql_grade, $db) or die(mysql_error());
94 $row_grade = mysql_fetch_assoc($result_grade);
95 $grade=$row_grade["grade"];
97 $this_row .= quote_csv($row['first_name']).",";
98 $this_row .= quote_csv($row['last_name']).",";
99 $this_row .= quote_csv($row['email']).",";
100 $this_row .= quote_csv($grade)."\n";
102 header('Content-Type: text/csv');
103 header('Content-transfer-encoding: binary');
104 header('Content-Disposition: attachment; filename="grade_'.$row_title["title"].'.csv"');
105 header('Expires: 0');
106 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
107 header('Pragma: public');
114 require(AT_INCLUDE_PATH.'header.inc.php');
117 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
118 <div class="input-form">
119 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('export'); ?></legend>
121 <p><?php echo _AT('export_marks_info'); ?></p>
124 if (mysql_num_rows($result_aa) == 0 && mysql_num_rows($result_at) == 0 && mysql_num_rows($result_e) == 0)
128 <strong><?php echo _AT('none_found'); ?></strong>
136 <label for="select_gid"><?php echo _AT('export_content_package_what'); ?></label><br />
137 <select name="gradebook_test_id" id="select_gid">
139 if (mysql_num_rows($result_aa) > 0)
141 echo ' <optgroup label="'. _AT('assignments') .'">'."\n\r";
143 while ($row_aa = mysql_fetch_assoc($result_aa))
145 echo ' <option value="'.$row_aa[gradebook_test_id].'">'.$row_aa[title].'</option>'."\n\r";
147 echo ' </optgroup>'."\n\r";
150 if (mysql_num_rows($result_at) > 0)
152 echo ' <optgroup label="'. _AT('tests') .'">'."\n\r";
154 while ($row_at = mysql_fetch_assoc($result_at))
156 echo ' <option value="'.$row_at[gradebook_test_id].'">'.$row_at[title].'</option>'."\n\r";
158 echo ' </optgroup>'."\n\r";
161 if (mysql_num_rows($result_e) > 0)
163 echo ' <optgroup label="'. _AT('external_tests') .'">'."\n\r";
165 while ($row_e = mysql_fetch_assoc($result_e))
167 echo ' <option value="'.$row_e[gradebook_test_id].'">'.$row_e[title].'</option>'."\n\r";
169 echo ' </optgroup>'."\n\r";
176 <div class="row buttons">
177 <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />
178 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
189 <form name="form1" method="post" action="mods/_standard/gradebook/verify_list.php" enctype="multipart/form-data">
190 <div class="input-form">
191 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('import'); ?></legend>
193 <p><?php echo _AT('import_marks_info'); ?></p>
197 if (mysql_num_rows($result_aa) == 0 && mysql_num_rows($result_e) == 0)
201 <strong><?php echo _AT('none_found'); ?></strong>
209 <label for="select_gid2"><?php echo _AT('import_content_package_where'); ?></label><br />
210 <select name="gradebook_test_id" id="select_gid2">
212 mysql_data_seek($result_aa, 0);
213 mysql_data_seek($result_e, 0);
215 if (mysql_num_rows($result_aa) > 0)
217 echo ' <optgroup label="'. _AT('assignments') .'">'."\n\r";
219 while ($row_aa = mysql_fetch_assoc($result_aa))
221 echo ' <option value="'.$row_aa[gradebook_test_id].'">'.$row_aa[title].'</option>'."\n\r";
223 echo ' </optgroup>'."\n\r";
226 if (mysql_num_rows($result_e) > 0)
228 echo ' <optgroup label="'. _AT('external_tests') .'">'."\n\r";
230 while ($row_e = mysql_fetch_assoc($result_e))
232 echo ' <option value="'.$row_e[gradebook_test_id].'">'.$row_e[title].'</option>'."\n\r";
234 echo ' </optgroup>'."\n\r";
242 <label for="to_file"><?php echo _AT('upload'); ?></label><br />
243 <input type="file" name="file" id="to_file" />
246 <div class="row buttons">
247 <input type="submit" name="import" value="<?php echo _AT('import'); ?>" />
248 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
260 * Creates csv file to be exported
262 * @param string $line The line ot be converted to csv
263 * @return string The line after conversion to csv
264 * @author Shozub Qureshi
266 function quote_csv($line) {
267 $line = str_replace('"', '""', $line);
269 $line = str_replace("\n", '\n', $line);
270 $line = str_replace("\r", '\r', $line);
271 $line = str_replace("\x00", '\0', $line);
273 return '"'.$line.'"';
276 require (AT_INCLUDE_PATH.'footer.inc.php');