2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay,Joel Kronenberg & Heidi Hazelton */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /************************************************************************/
16 function delete_course($course, $material) {
17 global $db, $moduleFactory;
19 $delete_groups = FALSE; // whether or not to delete the groups as well
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()
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'];
36 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_DISABLED);
37 $keys = array_keys($module_list);
39 //loop through mods and call delete function
40 foreach ($keys as $module_name) {
41 if ($module_name == '_core/groups') {
44 if ($module_name == '_core/enrolment') {
47 $module =& $module_list[$module_name];
49 if (($material === TRUE) || isset($material[$module_name])) {
50 $module->delete($course, $groups);
54 // groups and enrollment must be deleted last because that info is used by other modules
56 if (($material === TRUE) || isset($material['_core/groups'])) {
57 $module =& $moduleFactory->getModule('_core/groups');
58 $module->delete($course, $groups);
60 if (($material === TRUE) || isset($material['_core/enrolment'])) {
61 $module =& $moduleFactory->getModule('_core/enrolment');
62 $module->delete($course, $groups);
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);