2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
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 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require (AT_INCLUDE_PATH.'vitals.inc.php');
17 authenticate(AT_PRIV_ENROLLMENT);
21 /*EXPORT LIST OF STUDENTS*/
22 if(isset($_POST['export'])) {
23 //if not list was selected
24 if (!$_POST['enrolled'] && !$_POST['pending_enrollment'] && !$_POST['alumni']) {
25 $msg->addError('NO_STUDENT_SELECTED');
27 //retrieve info from database based on selection (make sure that instructor is not exported!)
29 if ($_POST['enrolled'] && $_POST['pending_enrollment'] && $_POST['alumni']) {
31 } else if ($_POST['enrolled'] && $_POST['pending_enrollment']) {
32 $condition = "AND approved <> 'a'";
33 } else if ($_POST['enrolled'] && $_POST['alumni']) {
34 $condition = "AND approved <> 'n'";
35 } else if ($_POST['pending_enrollment'] && $_POST['alumni']) {
36 $condition = "AND approved <> 'y'";
37 } else if ($_POST['pending_enrollment']) {
38 $condition = "AND approved = 'n'";
39 } else if ($_POST['enrolled']) {
40 $condition = "AND approved = 'y'";
41 } else if ($_POST['alumni']) {
42 $condition = "AND approved = 'a'";
45 $sql = "SELECT m.first_name, m.last_name, m.email
46 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";
48 $result = mysql_query($sql,$db);
49 while ($row = mysql_fetch_assoc($result)){
50 $this_row .= quote_csv($row['first_name']).",";
51 $this_row .= quote_csv($row['last_name']).",";
52 $this_row .= quote_csv($row['email'])."\n";
56 header('Content-Type: text/csv');
57 header('Content-transfer-encoding: binary');
58 header('Content-Disposition: attachment; filename="course_list_'.$_SESSION['course_id'].'.csv"');
60 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
61 header('Pragma: public');
65 // nothing to send. empty file
66 $msg->addError('ENROLLMENT_NONE_FOUND');
67 header('Location: export_course_list.php');
72 if(isset($_POST['cancel'])) {
73 $msg->addFeedback('CANCELLED');
74 header('Location: index.php');
78 if(isset($_POST['done'])) {
79 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
80 header('Location: index.php');
83 require(AT_INCLUDE_PATH.'header.inc.php');
88 <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="selectform">
89 <div class="input-form">
90 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('export'); ?></legend>
92 <label><input type="checkbox" name="enrolled" value="1" id="enrolled" /><?php echo _AT('enrolled_list_includes_assistants'); ?></label><br />
93 <label><input type="checkbox" name="pending_enrollment" value="1" id="pending_enrollment" /><?php echo _AT('pending_enrollment'); ?></label><br />
94 <label><input type="checkbox" name="alumni" value="1" id="alumni" /><?php echo _AT('alumni'); ?></label>
97 <div class="row buttons">
98 <input type="submit" name="export" value="<?php echo _AT('export'); ?>" />
99 <input type="submit" name="cancel" value="<?php echo _AT('cancel'); ?>" />
108 * Creates csv file to be exported
110 * @param string $line The line ot be converted to csv
111 * @return string The line after conversion to csv
112 * @author Shozub Qureshi
114 function quote_csv($line) {
115 $line = str_replace('"', '""', $line);
117 $line = str_replace("\n", '\n', $line);
118 $line = str_replace("\r", '\r', $line);
119 $line = str_replace("\x00", '\0', $line);
121 return '"'.$line.'"';
124 require(AT_INCLUDE_PATH.'footer.inc.php');