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 /************************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require (AT_INCLUDE_PATH.'vitals.inc.php');
16 authenticate(AT_PRIV_ENROLLMENT);
20 /*EXPORT LIST OF STUDENTS*/
21 if(isset($_POST['export'])) {
22 //if not list was selected
23 if (!$_POST['enrolled'] && !$_POST['pending_enrollment'] && !$_POST['alumni']) {
24 $msg->addError('NO_STUDENT_SELECTED');
26 //retrieve info from database based on selection (make sure that instructor is not exported!)
28 if ($_POST['enrolled'] && $_POST['pending_enrollment'] && $_POST['alumni']) {
30 } else if ($_POST['enrolled'] && $_POST['pending_enrollment']) {
31 $condition = "AND approved <> 'a'";
32 } else if ($_POST['enrolled'] && $_POST['alumni']) {
33 $condition = "AND approved <> 'n'";
34 } else if ($_POST['pending_enrollment'] && $_POST['alumni']) {
35 $condition = "AND approved <> 'y'";
36 } else if ($_POST['pending_enrollment']) {
37 $condition = "AND approved = 'n'";
38 } else if ($_POST['enrolled']) {
39 $condition = "AND approved = 'y'";
40 } else if ($_POST['alumni']) {
41 $condition = "AND approved = 'a'";
44 $sql = "SELECT m.first_name, m.last_name, m.email
45 FROM ".TABLE_PREFIX."course_enrollment cm JOIN ".TABLE_PREFIX."members m ON cm.member_id = m.member_id JOIN ".TABLE_PREFIX."courses c ON (cm.course_id = c.course_id AND cm.member_id <> c.member_id) WHERE cm.course_id = $_SESSION[course_id] " . $condition . "ORDER BY m.last_name";
47 $result = mysql_query($sql,$db);
48 while ($row = mysql_fetch_assoc($result)){
49 $this_row .= quote_csv($row['first_name']).",";
50 $this_row .= quote_csv($row['last_name']).",";
51 $this_row .= quote_csv($row['email'])."\n";
55 header('Content-Type: text/csv');
56 header('Content-transfer-encoding: binary');
57 header('Content-Disposition: attachment; filename="course_list_'.$_SESSION['course_id'].'.csv"');
59 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
60 header('Pragma: public');
64 // nothing to send. empty file
65 $msg->addError('ENROLLMENT_NONE_FOUND');
66 header('Location: export_course_list.php');
71 if(isset($_POST['cancel'])) {
72 $msg->addFeedback('CANCELLED');
73 header('Location: index.php');
77 if(isset($_POST['done'])) {
78 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
79 header('Location: index.php');
82 require(AT_INCLUDE_PATH.'header.inc.php');
87 * Creates csv file to be exported
89 * @param string $line The line ot be converted to csv
90 * @return string The line after conversion to csv
91 * @author Shozub Qureshi
93 function quote_csv($line) {
94 $line = str_replace('"', '""', $line);
96 $line = str_replace("\n", '\n', $line);
97 $line = str_replace("\r", '\r', $line);
98 $line = str_replace("\x00", '\0', $line);
100 return '"'.$line.'"';
102 $savant->display('instructor/enrolment/export_course_list.tmpl.php');
103 require(AT_INCLUDE_PATH.'footer.inc.php');