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 if (!defined('AT_INCLUDE_PATH')) { exit; }
17 * Generates the list of login ids of the selected user
19 * @param string $member_ids the list of members to be checked
20 * @return string The list of login IDs
21 * @author Shozub Qureshi
23 function get_usernames ($member_ids) {
26 $sql = "SELECT login FROM ".TABLE_PREFIX."members WHERE `member_id` IN ($member_ids)";
28 $result = mysql_query($sql, $db);
30 while ($row = mysql_fetch_assoc($result)) {
31 $str .= '<li>' . $row['login'] . '</li>';
37 * Checks if any of the selected users have non-zero roles or privileges
39 * @param string $member_ids the list of members to be checked
40 * @return int whether the role/priv is empty or not (0 = if empty, 1 = if ok)
41 * @author Shozub Qureshi
43 function check_roles ($member_ids) {
46 $sql = "SELECT * FROM ".TABLE_PREFIX."course_enrollment WHERE `member_id` IN ($member_ids)";
47 $result = mysql_query($sql, $db);
49 while ($row = mysql_fetch_assoc($result)) {
50 if ($row['role'] != 'Student' || $row['privileges'] != 0) {
58 * Removes students from course enrollement
60 * @param array $list the IDs of the members to be removed
61 * @author Shozub Qureshi
64 // no longer used. Unenroll does this job AND removes groups too.
65 function remove ($list) {
68 $members = '(member_id='.$list[0].')';
69 for ($i=1; $i < count($list); $i++) {
70 $members .= ' OR (member_id='.$list[$i].')';
72 $sql = "DELETE FROM ".TABLE_PREFIX."course_enrollment WHERE course_id = $_SESSION[course_id] AND ($members)";
73 $result = mysql_query($sql, $db);
77 * Unenrolls students from course enrollement
79 * @param array $list the IDs of the members to be removed
80 * @author Shozub Qureshi
81 * @author Greg Gay added Unsubscribe when unenrolling
83 function unenroll ($list) {
84 global $db, $system_courses, $course_id;
85 $members = implode(',', $list);
88 $members = addslashes($members);
90 $sql = "DELETE FROM ".TABLE_PREFIX."course_enrollment WHERE course_id=$course_id AND member_id IN ($members)";
91 $result = mysql_query($sql, $db);
94 $sql = "DELETE FROM ".TABLE_PREFIX."groups_members
95 WHERE member_id IN ($members)
96 AND group_id IN (SELECT group_id from ".TABLE_PREFIX."groups G, ".TABLE_PREFIX."groups_types GT
97 WHERE G.type_id = GT.type_id AND GT.course_id = ".$course_id.")";
98 $result = mysql_query($sql, $db);
100 // remove forum subscriptions as admin else instructor
101 if($_SESSION['course_id'] == "-1"){
102 $this_course_id = $_REQUEST['course_id'];
104 $this_course_id = $_SESSION['course_id'];
107 // get a list for forums in this course
108 $sql = "SELECT forum_id from ".TABLE_PREFIX."forums_courses WHERE course_id = '$this_course_id'";
109 $result = mysql_query($sql, $db);
111 if($result && mysql_num_rows($result)>0){
112 while($row = mysql_fetch_assoc($result)){
113 $this_course_forums[] = $row['forum_id'];
115 $this_forum_list = implode(',', $this_course_forums);
117 // delete from forum_subscription any member in $members (being unenrolled)
118 // with posts to forums in this course.
119 foreach ($this_course_forums as $this_course_forum){
120 $sql1 = "DELETE FROM ".TABLE_PREFIX."forums_subscriptions WHERE forum_id = '$this_course_forum' AND member_id IN ($members)";
121 $result_unsub = mysql_query($sql1, $db);
125 // get a list of posts for forums in the current course
126 $sql = "SELECT post_id FROM ".TABLE_PREFIX."forums_threads WHERE forum_id IN ($this_forum_list)";
127 $result = mysql_query($sql, $db);
128 if($result && mysql_num_rows($result)>0){
129 while($row = mysql_fetch_assoc($result)){
130 $this_course_posts[] = $row['post_id'];
132 $this_post_list = implode(',', $this_course_posts);
134 // delete from forums_accessed any post with member_id in $members being unenrolled,
136 foreach($this_course_posts as $this_course_post){
138 $sql2 = "DELETE FROM ".TABLE_PREFIX."forums_accessed WHERE post_id = '$this_course_post' AND member_id IN ($members)";
139 $result_unsub2 = mysql_query($sql2, $db);
146 * Enrolls students into course enrollement
148 * @param array $list the IDs of the members to be added
149 * @author Shozub Qureshi
151 function enroll ($list) {
152 global $db, $msg, $_config, $course_id, $owner;
153 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
155 $num_list = count($list);
156 $members = '(member_id='.$list[0].')';
157 for ($i=0; $i < $num_list; $i++) {
158 $id = intval($list[$i]);
159 $members .= ' OR (member_id='.$id.')';
160 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($id, $course_id, 'y', 0, '', 0)";
161 $result = mysql_query($sql, $db);
162 if (mysql_affected_rows($db) != 1) {
163 $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET approved='y' WHERE course_id=$course_id AND member_id=$id";
164 $result = mysql_query($sql, $db);
168 //get First_name, Last_name of course Instructor
169 $sql_from = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id = $owner";
170 $result_from = mysql_query($sql_from, $db);
171 $row_from = mysql_fetch_assoc($result_from);
173 $email_from_name = $row_from['first_name'] . ' ' . $row_from['last_name'];
174 $email_from = $row_from['email'];
176 //get email addresses of users:
177 $sql_to = "SELECT email FROM ".TABLE_PREFIX."members WHERE ($members)";
178 $result_to = mysql_query($sql_to, $db);
180 while ($row_to = mysql_fetch_assoc($result_to)) {
182 $login_link = AT_BASE_HREF . 'login.php?course=' . $course_id;
183 $subject = SITE_NAME.': '._AT('enrol_message_subject');
184 $body = SITE_NAME.': '._AT('enrol_message_approved', $_SESSION['course_title'], $login_link)."\n\n";
186 $mail = new ATutorMailer;
187 $mail->From = $_config['contact_email'];
188 $mail->FromName = $_config['site_name'];
189 $mail->AddAddress($row_to['email']);
190 $mail->Subject = $subject;
193 if (!$mail->Send()) {
194 $msg->addError('SENDING_ERROR');
203 function group ($list, $gid) {
206 $sql = "REPLACE INTO ".TABLE_PREFIX."groups_members VALUES ";
208 for ($i=0; $i < count($list); $i++) {
209 $student_id = intval($list[$i]);
210 $sql .= "($gid, $student_id),";
212 $sql = substr($sql, 0, -1);
213 mysql_query($sql, $db);
215 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
216 header('Location: index.php');
220 function group_remove ($ids, $gid) {
224 $ids=implode(',', $ids);
227 $sql = "DELETE FROM ".TABLE_PREFIX."groups_members WHERE group_id=$gid AND member_id IN ($ids)";
228 mysql_query($sql, $db);
229 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
232 header('Location: index.php');
237 * Marks a student as an alumni of the course (not enrolled, but can view course material and participate in forums)
239 * @param array $list the IDs of the members to be alumni
240 * @author Heidi Hazelton
242 function alumni ($list) {
243 global $db, $course_id;
244 $members = '(member_id='.$list[0].')';
245 for ($i=1; $i < count($list); $i++) {
246 $members .= ' OR (member_id='.$list[$i].')';
249 $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET approved = 'a' WHERE course_id=$course_id AND ($members)";
250 $result = mysql_query($sql, $db);
255 $owner = $system_courses[$course_id]['member_id'];
257 if (isset($_POST['submit_no'])) {
258 //if user decides to forgo option
259 $msg->addFeedback('CANCELLED');
260 header('Location: index.php?current_tab='.$_POST['curr_tab'].SEP.'course_id='.$course_id);
263 // No longer used. Unenroll does the same job and removes from groups too.
264 else if (isset($_POST['submit_yes']) && $_POST['func'] =='remove' ) {
265 //Remove student from list (unenrolls automatically)
267 //you cannot remove anyone unless you are the course owner
268 authenticate(AT_PRIV_ADMIN);
270 //echo 'atleast this worked';
271 remove($_POST['id']);
273 $msg->addFeedback('MEMBERS_REMOVED');
274 header('Location: index.php?current_tab=4');
277 else if (isset($_POST['submit_yes']) && $_POST['func'] =='unenroll' ) {
278 //Unenroll student from course
279 unenroll($_POST['id']);
281 // $msg->addFeedback('MEMBERS_UNENROLLED');
282 $msg->addFeedback('MEMBERS_REMOVED');
283 header('Location: index.php?current_tab=4'.SEP.'course_id='.$course_id);
285 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='enroll' ) {
286 //Enroll student in course
287 enroll($_POST['id']);
289 $msg->addFeedback('MEMBERS_ENROLLED');
290 header('Location: index.php?current_tab=0'.SEP.'course_id='.$course_id);
292 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='alumni' ) {
293 //Mark student as course alumnus
294 alumni($_POST['id']);
296 $msg->addFeedback('MEMBERS_ALUMNI');
297 header('Location: index.php?current_tab=2'.SEP.'course_id='.$course_id);
299 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='group' ) {
300 //Mark student as a member of the group
301 group($_POST['id'],$_POST['gid']);
303 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
304 header('Location: index.php?current_tab='.$_POST['current_tab'].SEP.'course_id='.$course_id);
306 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='group_remove' ) {
307 // Remove student as a member of the group
308 group_remove($_POST['id'],$_POST['gid']);
310 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
311 header('Location: index.php?current_tab='.$_POST['current_tab'].SEP.'course_id='.$course_id);
314 require(AT_INCLUDE_PATH.'header.inc.php');
316 //Store id's into a hidden element for use by functions
318 while ($_GET['id'.$j]) {
319 $_GET['id'.$j] = abs($_GET['id'.$j]);
320 if ($_GET['id'.$j] == $owner) {
323 $hidden_vars['id['.$j.']'] = $_GET['id'.$j];
324 $member_ids .= $_GET['id'.$j].', ';
328 $member_ids = substr($member_ids, 0, -2);
330 $hidden_vars['func'] = $_GET['func'];
331 $hidden_vars['current_tab'] = $_GET['current_tab'];
332 $hidden_vars['gid'] = abs($_GET['gid']);
333 $hidden_vars['course_id'] = $course_id;
334 //get usernames of users about to be edited
335 $str = get_usernames($member_ids);
337 //Print appropriate confirm msg for action
338 if ($_GET['func'] == 'remove') {
339 $confirm = array('REMOVE_STUDENT', $str);
340 $msg->addConfirm($confirm, $hidden_vars);
341 } else if ($_GET['func'] == 'enroll') {
342 $confirm = array('ENROLL_STUDENT', $str);
343 $msg->addConfirm($confirm, $hidden_vars);
344 } else if ($_GET['func'] == 'unenroll') {
345 if (check_roles($member_ids) == 1) {
346 $confirm = array('UNENROLL_PRIV', $str);
347 $msg->addConfirm($confirm, $hidden_vars);
349 $confirm = array('UNENROLL_STUDENT', $str);
350 $msg->addConfirm($confirm, $hidden_vars);
352 } else if ($_GET['func'] == 'alumni') {
353 $confirm = array('ALUMNI', $str);
354 $msg->addConfirm($confirm, $hidden_vars);
355 } else if ($_GET['func'] == 'group') {
356 $sql = "SELECT title FROM ".TABLE_PREFIX."groups WHERE group_id=".$hidden_vars['gid'];
357 $result = mysql_query($sql, $db);
358 $row = mysql_fetch_assoc($result);
360 $confirm = array('STUDENT_GROUP', $row['title'], $str);
361 $msg->addConfirm($confirm, $hidden_vars);
362 } else if ($_GET['func'] == 'group_remove') {
363 $sql = "SELECT title FROM ".TABLE_PREFIX."groups WHERE group_id=".$hidden_vars['gid'];
364 $result = mysql_query($sql, $db);
365 $row = mysql_fetch_assoc($result);
367 $confirm = array('STUDENT_REMOVE_GROUP', $row['title'], $str);
368 $msg->addConfirm($confirm, $hidden_vars);
371 $msg->printConfirm();
373 require(AT_INCLUDE_PATH.'footer.inc.php');