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 /************************************************************************/
15 function delete_course($course, $material) {
16 global $db, $moduleFactory;
18 $delete_groups = FALSE; // whether or not to delete the groups as well
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()
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'];
35 $module_list = $moduleFactory->getModules(AT_MODULE_STATUS_ENABLED | AT_MODULE_STATUS_DISABLED);
36 $keys = array_keys($module_list);
38 //loop through mods and call delete function
39 foreach ($keys as $module_name) {
40 if ($module_name == '_core/groups') {
43 if ($module_name == '_core/enrolment') {
46 $module =& $module_list[$module_name];
48 if (($material === TRUE) || isset($material[$module_name])) {
49 $module->delete($course, $groups);
53 // groups and enrollment must be deleted last because that info is used by other modules
55 if (($material === TRUE) || isset($material['_core/groups'])) {
56 $module =& $moduleFactory->getModule('_core/groups');
57 $module->delete($course, $groups);
59 if (($material === TRUE) || isset($material['_core/enrolment'])) {
60 $module =& $moduleFactory->getModule('_core/enrolment');
61 $module->delete($course, $groups);
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);