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 /************************************************************************/
12 // $Id: enroll_edit.php 6662 2006-11-20 15:52:49Z joel $
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);
93 $sql = "DELETE FROM ".TABLE_PREFIX."groups_members WHERE member_id IN ($members)";
94 $result = mysql_query($sql, $db);
95 // $groupModule->unenroll(course_id, user_id);
96 // $forumModule->unenroll(course_id, user_id);
98 // remove forum subscriptions as admin else instructor
99 if($_SESSION['course_id'] == "-1"){
100 $this_course_id = $_REQUEST['course_id'];
102 $this_course_id = $_SESSION['course_id'];
105 // get a list for forums in this course
106 $sql = "SELECT forum_id from ".TABLE_PREFIX."forums_courses WHERE course_id = '$this_course_id'";
107 $result = mysql_query($sql, $db);
109 if($result && mysql_num_rows($result)>0){
110 while($row = mysql_fetch_assoc($result)){
111 $this_course_forums[] = $row['forum_id'];
113 $this_forum_list = implode(',', $this_course_forums);
115 // delete from forum_subscription any member in $members (being unenrolled)
116 // with posts to forums in this course.
117 foreach ($this_course_forums as $this_course_forum){
118 $sql1 = "DELETE FROM ".TABLE_PREFIX."forums_subscriptions WHERE forum_id = '$this_course_forum' AND member_id IN ($members)";
119 $result_unsub = mysql_query($sql1, $db);
123 // get a list of posts for forums in the current course
124 $sql = "SELECT post_id FROM ".TABLE_PREFIX."forums_threads WHERE forum_id IN ($this_forum_list)";
125 $result = mysql_query($sql, $db);
126 if($result && mysql_num_rows($result)>0){
127 while($row = mysql_fetch_assoc($result)){
128 $this_course_posts[] = $row['post_id'];
130 $this_post_list = implode(',', $this_course_posts);
132 // delete from forums_accessed any post with member_id in $members being unenrolled,
134 foreach($this_course_posts as $this_course_post){
136 $sql2 = "DELETE FROM ".TABLE_PREFIX."forums_accessed WHERE post_id = '$this_course_post' AND member_id IN ($members)";
137 $result_unsub2 = mysql_query($sql2, $db);
144 * Enrolls students into course enrollement
146 * @param array $list the IDs of the members to be added
147 * @author Shozub Qureshi
149 function enroll ($list) {
150 global $db, $msg, $_config, $course_id, $owner;
151 require(AT_INCLUDE_PATH . 'classes/phpmailer/atutormailer.class.php');
153 $num_list = count($list);
154 $members = '(member_id='.$list[0].')';
155 for ($i=0; $i < $num_list; $i++) {
156 $id = intval($list[$i]);
157 $members .= ' OR (member_id='.$id.')';
158 $sql = "INSERT INTO ".TABLE_PREFIX."course_enrollment VALUES ($id, $course_id, 'y', 0, '', 0)";
159 $result = mysql_query($sql, $db);
160 if (mysql_affected_rows($db) != 1) {
161 $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET approved='y' WHERE course_id=$course_id AND member_id=$id";
162 $result = mysql_query($sql, $db);
166 //get First_name, Last_name of course Instructor
167 $sql_from = "SELECT first_name, last_name, email FROM ".TABLE_PREFIX."members WHERE member_id = $owner";
168 $result_from = mysql_query($sql_from, $db);
169 $row_from = mysql_fetch_assoc($result_from);
171 $email_from_name = $row_from['first_name'] . ' ' . $row_from['last_name'];
172 $email_from = $row_from['email'];
174 //get email addresses of users:
175 $sql_to = "SELECT email FROM ".TABLE_PREFIX."members WHERE ($members)";
176 $result_to = mysql_query($sql_to, $db);
178 while ($row_to = mysql_fetch_assoc($result_to)) {
180 $login_link = AT_BASE_HREF . 'login.php?course=' . $course_id;
181 $subject = SITE_NAME.': '._AT('enrol_message_subject');
182 $body = SITE_NAME.': '._AT('enrol_message_approved', $_SESSION['course_title'], $login_link)."\n\n";
184 $mail = new ATutorMailer;
185 $mail->From = $_config['contact_email'];
186 $mail->FromName = $_config['site_name'];
187 $mail->AddAddress($row_to['email']);
188 $mail->Subject = $subject;
191 if (!$mail->Send()) {
192 $msg->addError('SENDING_ERROR');
200 function group ($list, $gid) {
202 $sql = "REPLACE INTO ".TABLE_PREFIX."groups_members VALUES ";
204 for ($i=0; $i < count($list); $i++) {
205 $student_id = intval($list[$i]);
206 $sql .= "($gid, $student_id),";
208 $sql = substr($sql, 0, -1);
209 mysql_query($sql, $db);
211 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
212 header('Location: index.php');
216 function group_remove ($ids, $gid) {
220 $ids=implode(',', $ids);
223 $sql = "DELETE FROM ".TABLE_PREFIX."groups_members WHERE group_id=$gid AND member_id IN ($ids)";
224 mysql_query($sql, $db);
225 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
228 header('Location: index.php');
233 * Marks a student as an alumni of the course (not enrolled, but can view course material and participate in forums)
235 * @param array $list the IDs of the members to be alumni
236 * @author Heidi Hazelton
238 function alumni ($list) {
239 global $db, $course_id;
240 $members = '(member_id='.$list[0].')';
241 for ($i=1; $i < count($list); $i++) {
242 $members .= ' OR (member_id='.$list[$i].')';
245 $sql = "UPDATE ".TABLE_PREFIX."course_enrollment SET approved = 'a' WHERE course_id=$course_id AND ($members)";
246 $result = mysql_query($sql, $db);
251 $owner = $system_courses[$course_id]['member_id'];
253 if (isset($_POST['submit_no'])) {
254 //if user decides to forgo option
255 $msg->addFeedback('CANCELLED');
256 header('Location: index.php?current_tab='.$_POST['curr_tab'].SEP.'course_id='.$course_id);
259 // No longer used. Unenroll does the same job and removes from groups too.
260 else if (isset($_POST['submit_yes']) && $_POST['func'] =='remove' ) {
261 //Remove student from list (unenrolls automatically)
263 //you cannot remove anyone unless you are the course owner
264 authenticate(AT_PRIV_ADMIN);
266 //echo 'atleast this worked';
267 remove($_POST['id']);
269 $msg->addFeedback('MEMBERS_REMOVED');
270 header('Location: index.php?current_tab=4');
273 else if (isset($_POST['submit_yes']) && $_POST['func'] =='unenroll' ) {
274 //Unenroll student from course
275 unenroll($_POST['id']);
277 // $msg->addFeedback('MEMBERS_UNENROLLED');
278 $msg->addFeedback('MEMBERS_REMOVED');
279 header('Location: index.php?current_tab=4'.SEP.'course_id='.$course_id);
281 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='enroll' ) {
282 //Enroll student in course
283 enroll($_POST['id']);
285 $msg->addFeedback('MEMBERS_ENROLLED');
286 header('Location: index.php?current_tab=0'.SEP.'course_id='.$course_id);
288 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='alumni' ) {
289 //Mark student as course alumnus
290 alumni($_POST['id']);
292 $msg->addFeedback('MEMBERS_ALUMNI');
293 header('Location: index.php?current_tab=2'.SEP.'course_id='.$course_id);
295 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='group' ) {
296 //Mark student as a member of the group
297 group($_POST['id'],$_POST['gid']);
299 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
300 header('Location: index.php?current_tab='.$_POST['current_tab'].SEP.'course_id='.$course_id);
302 } else if (isset($_POST['submit_yes']) && $_POST['func'] =='group_remove' ) {
303 // Remove student as a member of the group
304 group_remove($_POST['id'],$_POST['gid']);
306 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
307 header('Location: index.php?current_tab='.$_POST['current_tab'].SEP.'course_id='.$course_id);
310 require(AT_INCLUDE_PATH.'header.inc.php');
312 //Store id's into a hidden element for use by functions
314 while ($_GET['id'.$j]) {
315 $_GET['id'.$j] = abs($_GET['id'.$j]);
316 if ($_GET['id'.$j] == $owner) {
319 $hidden_vars['id['.$j.']'] = $_GET['id'.$j];
320 $member_ids .= $_GET['id'.$j].', ';
324 $member_ids = substr($member_ids, 0, -2);
326 $hidden_vars['func'] = $_GET['func'];
327 $hidden_vars['current_tab'] = $_GET['current_tab'];
328 $hidden_vars['gid'] = abs($_GET['gid']);
329 $hidden_vars['course_id'] = $course_id;
330 //get usernames of users about to be edited
331 $str = get_usernames($member_ids);
333 //Print appropriate confirm msg for action
334 if ($_GET['func'] == 'remove') {
335 $confirm = array('REMOVE_STUDENT', $str);
336 $msg->addConfirm($confirm, $hidden_vars);
337 } else if ($_GET['func'] == 'enroll') {
338 $confirm = array('ENROLL_STUDENT', $str);
339 $msg->addconfirm($confirm, $hidden_vars);
340 } else if ($_GET['func'] == 'unenroll') {
341 if (check_roles($member_ids) == 1) {
342 $confirm = array('UNENROLL_PRIV', $str);
343 $msg->addConfirm($confirm, $hidden_vars);
345 $confirm = array('UNENROLL_STUDENT', $str);
346 $msg->addConfirm($confirm, $hidden_vars);
348 } else if ($_GET['func'] == 'alumni') {
349 $confirm = array('ALUMNI', $str);
350 $msg->addConfirm($confirm, $hidden_vars);
351 } else if ($_GET['func'] == 'group') {
352 $sql = "SELECT title FROM ".TABLE_PREFIX."groups WHERE group_id=".$hidden_vars['gid'];
353 $result = mysql_query($sql, $db);
354 $row = mysql_fetch_assoc($result);
356 $confirm = array('STUDENT_GROUP', $row['title'], $str);
357 $msg->addConfirm($confirm, $hidden_vars);
358 } else if ($_GET['func'] == 'group_remove') {
359 $sql = "SELECT title FROM ".TABLE_PREFIX."groups WHERE group_id=".$hidden_vars['gid'];
360 $result = mysql_query($sql, $db);
361 $row = mysql_fetch_assoc($result);
363 $confirm = array('STUDENT_REMOVE_GROUP', $row['title'], $str);
364 $msg->addConfirm($confirm, $hidden_vars);
367 $msg->printConfirm();
369 require(AT_INCLUDE_PATH.'footer.inc.php');