MDL-10092:
[moodle-linuxchix.git] / course / reset.php
blob4f078f139bc62a5cabf46565bef3620c2ec8c61c
1 <?php // $Id$
2 /*
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.
9 */
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 $navlinks = array();
27 $navlinks[] = array('name' => $strresetcourse, 'link' => null, 'type' => 'misc');
28 $navigation = build_navigation($navlinks);
30 print_header($course->fullname.': '.$strresetcourse, $course->fullname.': '.$strresetcourse, $navigation);
32 print_simple_box_start();
34 print_heading($strresetcourse);
36 /// If we have data, then process it.
37 if ($data = data_submitted() and confirm_sesskey()) {
39 $data->courseid = $course->id;
41 reset_course_userdata($data, true);
43 if (!empty($data->reset_start_date)) {
44 if (set_field('course', 'startdate',
45 make_timestamp($data->startyear, $data->startmonth, $data->startday),
46 'id', $course->id)) {
47 notify(get_string('datechanged'), 'notifysuccess');
50 print_continue('view.php?id='.$course->id); // Back to course page
51 print_simple_box_end();
52 print_footer($course);
53 exit;
58 /// Print forms so the user can make choices about what to delete
60 print_simple_box(get_string('resetinfo'), 'center', '60%');
62 echo '<form id="reset" action="reset.php" method="POST">';
64 print_heading(get_string('course'), 'left', 3);
66 echo '<div class="courseinfo">';
67 echo $strremove.':<br />';
68 print_checkbox('reset_teachers', 1, false, get_string('teachers'), '', ''); echo '<br />';
69 print_checkbox('reset_students', 1, true, get_string('students'), '', ''); echo '<br />';
70 print_checkbox('reset_events', 1, true, get_string('courseevents', 'calendar'), '', ''); echo '<br />';
71 print_checkbox('reset_logs', 1, true, get_string('logs'), '', ''); echo '<br />';
72 print_checkbox('reset_groups', 1, true, get_string('groups'), '', ''); echo '<br />';
73 print_checkbox('reset_start_date', 1, true, get_string('startdate'), '', '');
74 print_date_selector('startday', 'startmonth', 'startyear');
75 helpbutton('coursestartdate', get_string('startdate'));
76 echo '</div>';
78 // Check each module and see if there is specific data to be removed
80 if ($allmods = get_records('modules') ) {
81 foreach ($allmods as $mod) {
82 $modname = $mod->name;
83 $modfile = $CFG->dirroot .'/mod/'. $modname .'/lib.php';
84 $mod_reset_course_form = $modname .'_reset_course_form';
85 if (file_exists($modfile)) {
86 @include_once($modfile);
87 if (function_exists($mod_reset_course_form)) {
88 print_heading(get_string('modulenameplural', $modname), 'left', 3);
89 echo '<div class="'.$modname.'info">';
90 $mod_reset_course_form($course);
91 echo '</div>';
95 } else {
96 error('No modules are installed!');
99 echo '<input name="id" value="'.$course->id.'" type="hidden" />';
100 echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
101 echo '<p align="center"><input name="submit" value="'.$strresetcourse.'" type="submit" /></p>';
102 echo '</form>';
104 print_simple_box_end();
105 print_footer($course);