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