d409e910b45941a576407c3122561ff9e657d0b0
[atutor.git] / docs / users / remove_course.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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 /****************************************************************/
13 // $Id$
14
15 $_user_location = 'users';
16 define('AT_INCLUDE_PATH', '../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18
19 if (isset($_POST['submit_no'])) {
20         $msg->addFeedback('CANCELLED');
21         header('Location: index.php');
22         exit;
23 } else if (isset($_POST['submit_yes'])) {
24         $course = intval($_POST['course']);
25         if ($system_courses[$course]['member_id'] != $_SESSION['member_id']) {
26                 $sql    = "DELETE FROM ".TABLE_PREFIX."course_enrollment WHERE member_id=$_SESSION[member_id] AND course_id=$course";
27                 $result = mysql_query($sql, $db) or die(mysql_error());
28
29                 // Unsubscribe from forums and threads of the course
30                 $sql    = "DELETE FROM ".TABLE_PREFIX."forums_subscriptions 
31                          WHERE forum_id IN (SELECT forum_id FROM ".TABLE_PREFIX."forums_courses WHERE course_id=$course)
32                            AND member_id=".$_SESSION[member_id];
33                 $result = mysql_query($sql, $db) or die(mysql_error());
34
35                 $sql    = "UPDATE ".TABLE_PREFIX."forums_accessed 
36                            SET subscribe = 0
37                          WHERE post_id IN (SELECT distinct t.post_id FROM ".TABLE_PREFIX."forums_courses c, ".TABLE_PREFIX."forums_threads t WHERE c.course_id=$course)
38                            AND member_id=".$_SESSION[member_id];
39                 $result = mysql_query($sql, $db) or die(mysql_error());
40
41                 $msg->addFeedback('COURSE_REMOVED');
42         }
43         header("Location: ".AT_BASE_HREF."users/index.php");
44         exit;
45 }
46
47 require(AT_INCLUDE_PATH.'header.inc.php');
48
49 unset($hidden_vars);
50 $hidden_vars['course'] = $_GET['course'];
51 $msg->addConfirm(array('UNENROLL', $system_courses[$_GET['course']]['title']), $hidden_vars);
52
53 $msg->printConfirm();
54
55 require(AT_INCLUDE_PATH.'footer.inc.php');
56 ?>