3 resetcourse.php - Mark Flach and moodle.com
4 The purpose of this feature is to quickly remove all user related data from a course
5 in order to make it available for a new semester. This feature can handle the removal
6 of general course data like students, teachers, logs, events and groups as well as module
7 specific data. Each module must be modified to take advantage of this new feature.
8 The feature will also reset the start date of the course if necessary.
10 require('../config.php');
12 $id = required_param('id', PARAM_INT
);
14 if (! $course = get_record('course', 'id', $id)) {
15 error("Course is misconfigured");
18 require_login($course->id
);
20 require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE
, $course->id
));
22 $strreset = get_string('reset');
23 $strresetcourse = get_string('resetcourse');
24 $strremove = get_string('remove');
26 print_header($course->fullname
.': '.$strresetcourse, $course->fullname
.': '.$strresetcourse,
27 '<a href="view.php?id='.$course->id
.'">'.$course->shortname
.'</a> -> '.$strresetcourse);
29 print_simple_box_start();
31 print_heading($strresetcourse);
33 /// If we have data, then process it.
34 if ($data = data_submitted() and confirm_sesskey()) {
36 $data->courseid
= $course->id
;
38 reset_course_userdata($data, true);
40 if (!empty($data->reset_start_date
)) {
41 if (set_field('course', 'startdate',
42 make_timestamp($data->startyear
, $data->startmonth
, $data->startday
),
44 notify(get_string('datechanged'), 'notifysuccess');
47 print_continue('view.php?id='.$course->id
); // Back to course page
48 print_simple_box_end();
49 print_footer($course);
55 /// Print forms so the user can make choices about what to delete
57 print_simple_box(get_string('resetinfo'), 'center', '60%');
59 echo '<form id="reset" action="reset.php" method="POST">';
61 print_heading(get_string('course'), 'left', 3);
63 echo '<div class="courseinfo">';
64 echo $strremove.':<br />';
65 print_checkbox('reset_students', 1, true, get_string('students'), '', ''); echo '<br />';
66 print_checkbox('reset_teachers', 1, true, get_string('teachers'), '', ''); echo '<br />';
67 print_checkbox('reset_events', 1, true, get_string('courseevents', 'calendar'), '', ''); echo '<br />';
68 print_checkbox('reset_logs', 1, true, get_string('logs'), '', ''); echo '<br />';
69 print_checkbox('reset_groups', 1, true, get_string('groups'), '', ''); echo '<br />';
70 print_checkbox('reset_start_date', 1, true, get_string('startdate'), '', '');
71 print_date_selector('startday', 'startmonth', 'startyear');
72 helpbutton('coursestartdate', get_string('startdate'));
75 // Check each module and see if there is specific data to be removed
77 if ($allmods = get_records('modules') ) {
78 foreach ($allmods as $mod) {
79 $modname = $mod->name
;
80 $modfile = $CFG->dirroot
.'/mod/'. $modname .'/lib.php';
81 $mod_reset_course_form = $modname .'_reset_course_form';
82 if (file_exists($modfile)) {
83 @include_once
($modfile);
84 if (function_exists($mod_reset_course_form)) {
85 print_heading(get_string('modulenameplural', $modname), 'left', 3);
86 echo '<div class="'.$modname.'info">';
87 $mod_reset_course_form($course);
93 error('No modules are installed!');
96 echo '<input name="id" value="'.$course->id
.'" type="hidden" />';
97 echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
98 echo '<p align="center"><input name="submit" value="'.$strresetcourse.'" type="submit" /></p>';
101 print_simple_box_end();
102 print_footer($course);