2004-09-12 12:21:27 +00:00
|
|
|
<?php // $Id$
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-05-30 23:09:21 +00:00
|
|
|
// Moves, adds, updates, duplicates or deletes modules in a course
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
require("../config.php");
|
2007-02-07 07:09:31 +00:00
|
|
|
require_once("lib.php");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2003-05-24 06:53:47 +00:00
|
|
|
require_login();
|
2003-05-06 02:51:38 +00:00
|
|
|
|
2005-03-05 05:19:26 +00:00
|
|
|
$sectionreturn = optional_param('sr', '', PARAM_INT);
|
2006-04-11 21:41:21 +00:00
|
|
|
$add = optional_param('add','', PARAM_ALPHA);
|
|
|
|
$type = optional_param('type', '', PARAM_ALPHA);
|
|
|
|
$indent = optional_param('indent', 0, PARAM_INT);
|
|
|
|
$update = optional_param('update', 0, PARAM_INT);
|
|
|
|
$hide = optional_param('hide', 0, PARAM_INT);
|
|
|
|
$show = optional_param('show', 0, PARAM_INT);
|
|
|
|
$copy = optional_param('copy', 0, PARAM_INT);
|
|
|
|
$moveto = optional_param('moveto', 0, PARAM_INT);
|
|
|
|
$movetosection = optional_param('movetosection', 0, PARAM_INT);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
|
|
|
$course = optional_param('course', 0, PARAM_INT);
|
|
|
|
$groupmode = optional_param('groupmode', -1, PARAM_INT);
|
|
|
|
$cancel = optional_param('cancel', 0, PARAM_BOOL);
|
|
|
|
$cancelcopy = optional_param('cancelcopy', 0, PARAM_BOOL);
|
2008-06-01 20:15:50 +00:00
|
|
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
2003-08-08 16:46:16 +00:00
|
|
|
|
2006-04-11 21:41:21 +00:00
|
|
|
if ($cancel) {
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect($return);
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2002-10-16 04:53:44 +00:00
|
|
|
|
2006-11-09 18:25:58 +00:00
|
|
|
//check if we are adding / editing a module that has new forms using formslib
|
|
|
|
if (!empty($add)){
|
2008-06-01 20:15:50 +00:00
|
|
|
$id = required_param('id', PARAM_INT);
|
|
|
|
$section = required_param('section', PARAM_INT);
|
|
|
|
$type = optional_param('type', '', PARAM_ALPHA);
|
2006-12-05 13:23:18 +00:00
|
|
|
$returntomod = optional_param('return', 0, PARAM_BOOL);
|
2002-10-16 04:53:44 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("$CFG->wwwroot/course/modedit.php?add=$add&type=$type&course=$id§ion=$section&return=$returntomod");
|
2004-10-09 17:23:28 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
} else if (!empty($update)){
|
|
|
|
$cm = get_cm($update);
|
|
|
|
$returntomod = optional_param('return', 0, PARAM_BOOL);
|
|
|
|
redirect("$CFG->wwwroot/course/modedit.php?update=$update&return=$returntomod");
|
2005-10-09 07:12:58 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
} else if (!empty($delete)) {
|
|
|
|
$cm = get_cm($delete);
|
2004-02-15 03:19:52 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (!$course = $DB->get_record("course", array("id"=>$cm->course))) {
|
|
|
|
print_error("invalidcourseid");
|
|
|
|
}
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($course->id); // needed to setup proper $COURSE
|
2006-09-20 20:31:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:manageactivities', $context);
|
2006-11-09 18:25:58 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
$return = "$CFG->wwwroot/course/view.php?id=$cm->course#section-$cm->sectionnum";
|
|
|
|
|
|
|
|
if (!$confirm or !confirm_sesskey()) {
|
|
|
|
$fullmodulename = get_string("modulename", $cm->modname);
|
|
|
|
|
|
|
|
$optionsyes = array('confirm'=>1, 'delete'=>$cm->id, 'sesskey'=>sesskey());
|
|
|
|
$optionsno = array('id'=>$cm->course);
|
|
|
|
|
|
|
|
$strdeletecheck = get_string('deletecheck', '', $fullmodulename);
|
|
|
|
$strdeletecheckfull = get_string('deletecheckfull', '', "$fullmodulename '$cm->name'");
|
|
|
|
|
|
|
|
$CFG->pagepath = 'mod/'.$cm->modname.'/delete';
|
|
|
|
|
|
|
|
print_header_simple($strdeletecheck, '', build_navigation(array(array('name'=>$strdeletecheck,'link'=>'','type'=>'misc'))));
|
|
|
|
|
|
|
|
print_simple_box_start('center', '60%', '#FFAAAA', 20, 'noticebox');
|
|
|
|
notice_yesno($strdeletecheckfull, 'mod.php', $return, $optionsyes, $optionsno, 'post', 'get');
|
|
|
|
print_simple_box_end();
|
|
|
|
print_footer($course);
|
|
|
|
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$modlib = "$CFG->dirroot/mod/$cm->modname/lib.php";
|
2004-09-28 15:58:13 +00:00
|
|
|
|
2002-08-03 02:29:21 +00:00
|
|
|
if (file_exists($modlib)) {
|
2008-06-01 20:15:50 +00:00
|
|
|
require_once($modlib);
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error('modulemissingcode', '', '', $modlib);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
$deleteinstancefunction = $cm->modname."_delete_instance";
|
|
|
|
|
|
|
|
if (! $deleteinstancefunction($cm->instance)) {
|
|
|
|
notify("Could not delete the $cm->modname (instance)");
|
|
|
|
}
|
|
|
|
if (! delete_course_module($cm->id)) {
|
|
|
|
notify("Could not delete the $cm->modname (coursemodule)");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! delete_mod_from_section($cm->id, "$cm->section")) {
|
|
|
|
notify("Could not delete the $cm->modname from that section");
|
|
|
|
}
|
|
|
|
|
|
|
|
add_to_log($course->id, "course", "delete mod",
|
|
|
|
"view.php?id=$cm->course",
|
|
|
|
"$cm->modname $cm->instance", $cm->id);
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-02-15 03:19:52 +00:00
|
|
|
rebuild_course_cache($course->id);
|
2002-11-10 07:37:15 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect($return);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2005-02-13 09:35:40 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
|
|
|
|
$cm = get_cm($USER->activitycopy, 'copiedcmnotexist');
|
2003-07-14 13:08:38 +00:00
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
if (!empty($movetosection)) {
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $section = $DB->get_record("course_sections", array("id"=>$movetosection))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("sectionnotexist");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
$beforecm = NULL;
|
|
|
|
|
|
|
|
} else { // normal moveto
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $beforecm = $DB->get_record("course_modules", array("id"=>$moveto))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("destinationcmnotexit");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $section = $DB->get_record("course_sections", array("id"=>$beforecm->section))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("sectionnotexist");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($section->course); // needed to setup proper $COURSE
|
2006-09-20 20:31:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $section->course);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:manageactivities', $context);
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
if (!ismoving($section->course)) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("needcopy");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
moveto_module($cm, $section, $beforecm);
|
|
|
|
|
|
|
|
unset($USER->activitycopy);
|
|
|
|
unset($USER->activitycopycourse);
|
|
|
|
unset($USER->activitycopyname);
|
|
|
|
|
|
|
|
rebuild_course_cache($section->course);
|
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if (SITEID == $section->course) {
|
2003-07-14 13:08:38 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
} else {
|
2005-11-23 23:14:25 +00:00
|
|
|
redirect("view.php?id=$section->course#section-$sectionreturn");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
} else if (!empty($indent) and confirm_sesskey()) {
|
2006-03-07 23:30:27 +00:00
|
|
|
$id = required_param('id',PARAM_INT);
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_cm($id);
|
2003-09-14 16:31:33 +00:00
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($cm->course); // needed to setup proper $COURSE
|
2006-09-20 20:31:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:manageactivities', $context);
|
2005-10-09 19:41:34 +00:00
|
|
|
|
2005-06-10 11:06:19 +00:00
|
|
|
$cm->indent += $indent;
|
2003-09-14 16:31:33 +00:00
|
|
|
|
|
|
|
if ($cm->indent < 0) {
|
|
|
|
$cm->indent = 0;
|
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (!$DB->set_field("course_modules", "indent", $cm->indent, array("id"=>$cm->id))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("cannotupdatelevel");
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if (SITEID == $cm->course) {
|
2003-09-14 16:31:33 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
} else {
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("view.php?id=$cm->course#section-$cm->sectionnum");
|
2003-09-14 16:31:33 +00:00
|
|
|
}
|
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
} else if (!empty($hide) and confirm_sesskey()) {
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_cm($hide);
|
2003-05-24 06:53:47 +00:00
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($cm->course); // needed to setup proper $COURSE
|
2007-02-16 07:57:19 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:activityvisibility', $context);
|
2005-02-13 09:35:40 +00:00
|
|
|
|
2005-02-12 21:41:22 +00:00
|
|
|
set_coursemodule_visible($cm->id, 0);
|
2003-04-14 15:11:09 +00:00
|
|
|
|
2003-05-09 17:24:17 +00:00
|
|
|
rebuild_course_cache($cm->course);
|
2003-04-14 15:11:09 +00:00
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if (SITEID == $cm->course) {
|
2003-05-06 02:51:38 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
} else {
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("view.php?id=$cm->course#section-$cm->sectionnum");
|
2003-05-06 02:51:38 +00:00
|
|
|
}
|
2003-04-14 15:11:09 +00:00
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
} else if (!empty($show) and confirm_sesskey()) {
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_cm($show);
|
2003-04-14 15:11:09 +00:00
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($cm->course); // needed to setup proper $COURSE
|
2006-09-20 20:31:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:activityvisibility', $context);
|
2003-05-24 06:53:47 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $section = $DB->get_record("course_sections", array("id"=>$cm->section))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("sectionnotexist");
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $module = $DB->get_record("modules", array("id"=>$cm->module))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("moduledoesnotexist");
|
2003-05-09 17:24:17 +00:00
|
|
|
}
|
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if ($module->visible and ($section->visible or (SITEID == $cm->course))) {
|
2005-02-12 21:41:22 +00:00
|
|
|
set_coursemodule_visible($cm->id, 1);
|
2003-05-09 17:24:17 +00:00
|
|
|
rebuild_course_cache($cm->course);
|
2002-11-10 14:45:11 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if (SITEID == $cm->course) {
|
2003-05-06 02:51:38 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
} else {
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("view.php?id=$cm->course#section-$cm->sectionnum");
|
2004-01-31 08:40:38 +00:00
|
|
|
}
|
|
|
|
|
2006-03-23 23:36:20 +00:00
|
|
|
} else if ($groupmode > -1 and confirm_sesskey()) {
|
2004-01-31 08:40:38 +00:00
|
|
|
|
2006-03-07 23:30:27 +00:00
|
|
|
$id = required_param( 'id', PARAM_INT );
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_cm($id);
|
2004-01-31 08:40:38 +00:00
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($cm->course); // needed to setup proper $COURSE
|
2007-02-16 07:57:19 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:manageactivities', $context);
|
2005-02-13 09:35:40 +00:00
|
|
|
|
2005-06-10 11:06:19 +00:00
|
|
|
set_coursemodule_groupmode($cm->id, $groupmode);
|
2004-01-31 08:40:38 +00:00
|
|
|
|
|
|
|
rebuild_course_cache($cm->course);
|
|
|
|
|
2004-08-29 14:15:40 +00:00
|
|
|
if (SITEID == $cm->course) {
|
2004-01-31 08:40:38 +00:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
} else {
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("view.php?id=$cm->course#section-$cm->sectionnum");
|
2003-05-06 02:51:38 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
} else if (!empty($copy) and confirm_sesskey()) { // value = course module
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_cm($copy);
|
2003-07-14 13:08:38 +00:00
|
|
|
|
2006-09-30 20:46:31 +00:00
|
|
|
require_login($cm->course); // needed to setup proper $COURSE
|
2006-09-20 20:31:09 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $cm->course);
|
2006-10-11 03:48:09 +00:00
|
|
|
require_capability('moodle/course:manageactivities', $context);
|
2003-07-14 13:08:38 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $section = $DB->get_record("course_sections", array("id"=>$cm->section))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("sectionnotexist");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $module = $DB->get_record("modules", array("id"=>$cm->module))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("moduledoesnotexist");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (! $instance = $DB->get_record($module->name, array("id"=>$cm->instance))) {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("moduleinstancedoesnotexist");
|
2003-07-14 13:08:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$USER->activitycopy = $copy;
|
|
|
|
$USER->activitycopycourse = $cm->course;
|
|
|
|
$USER->activitycopyname = $instance->name;
|
|
|
|
|
2005-11-23 23:14:25 +00:00
|
|
|
redirect("view.php?id=$cm->course#section-$sectionreturn");
|
2003-07-14 13:08:38 +00:00
|
|
|
|
2006-03-10 11:07:10 +00:00
|
|
|
} else if (!empty($cancelcopy) and confirm_sesskey()) { // value = course module
|
2003-07-14 13:08:38 +00:00
|
|
|
|
|
|
|
$courseid = $USER->activitycopycourse;
|
|
|
|
|
|
|
|
unset($USER->activitycopy);
|
|
|
|
unset($USER->activitycopycourse);
|
|
|
|
unset($USER->activitycopyname);
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
redirect("view.php?id=$courseid");
|
2006-03-01 02:34:34 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2008-05-07 06:02:51 +00:00
|
|
|
print_error("unknowaction");
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
function get_cm($id, $error='cmunknown') {
|
|
|
|
global $DB;
|
2007-08-17 19:09:11 +00:00
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
if (!$modname = $DB->get_field_sql("SELECT md.name
|
|
|
|
FROM {course_modules} cm, {modules} md
|
|
|
|
WHERE cm.id = ? AND md.id = cm.module", array($id))){
|
2008-06-15 11:34:42 +00:00
|
|
|
print_error('cmunknown');
|
2006-08-08 05:13:06 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm = get_coursemodule_from_id($modname, $id);
|
|
|
|
if ($cw = $DB->get_record("course_sections", array("id"=>$cm->section))) {
|
|
|
|
$cm->sectionnum = $cw->section;
|
2001-11-22 06:23:56 +00:00
|
|
|
} else {
|
2008-06-01 20:15:50 +00:00
|
|
|
$cm->sectionnum = 0;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2008-06-01 20:15:50 +00:00
|
|
|
return $cm;
|
|
|
|
}
|
2006-04-29 15:13:31 +00:00
|
|
|
?>
|