made a copy
[atutor.git] / include / lib / delete_course.inc.php
1 <?php
2 /************************************************************************/
3 /* ATutor                                                                                                                               */
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay,Joel Kronenberg & Heidi Hazelton */
6 /* Adaptive Technology Resource Centre / University of Toronto                  */
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
16 function delete_course($course, $material) {
17         global $db, $moduleFactory;
18
19         $delete_groups = FALSE; // whether or not to delete the groups as well
20
21         $groups = array();
22
23         //unset s_cid var
24         if ($material === TRUE) {
25                 unset($_SESSION['s_cid']);
26                 $delete_groups = TRUE;
27                 // get a list of groups in an array to send to module::delete()
28                 // get groups
29                 $sql    = "SELECT G.group_id FROM ".TABLE_PREFIX."groups G INNER JOIN ".TABLE_PREFIX."groups_types T USING (type_id) WHERE T.course_id=$course";
30                 $result = mysql_query($sql, $db);
31                 while ($group_row = mysql_fetch_assoc($result)) {
32                         $groups[] = $group_row['group_id'];
33                 }
34         }
35
36         $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_DISABLED);
37         $keys = array_keys($module_list);
38
39         //loop through mods and call delete function
40         foreach ($keys as $module_name) {
41                 if ($module_name == '_core/groups') {
42                         continue;
43                 }
44                 if ($module_name == '_core/enrolment') {
45                         continue;
46                 }
47                 $module =& $module_list[$module_name];
48
49                 if (($material === TRUE) || isset($material[$module_name])) {
50                         $module->delete($course, $groups);
51                 }
52         }
53
54         // groups and enrollment must be deleted last because that info is used by other modules
55
56         if (($material === TRUE) || isset($material['_core/groups'])) {
57                 $module =& $moduleFactory->getModule('_core/groups');
58                 $module->delete($course, $groups);
59         }
60         if (($material === TRUE) || isset($material['_core/enrolment'])) {
61                 $module =& $moduleFactory->getModule('_core/enrolment');
62                 $module->delete($course, $groups);
63         }
64
65         if ($material === TRUE) {
66                 // delete actual course
67                 $sql = "DELETE FROM ".TABLE_PREFIX."courses WHERE course_id=$course";
68                 $result = mysql_query($sql, $db);
69         }
70 }
71 ?>