Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / course / reset.php
blobc405e5af777892daedad1ac842c6f46e558dc9d1
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_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
20 $strreset = get_string('reset');
21 $strresetcourse = get_string('resetcourse');
22 $strremove = get_string('remove');
24 print_header($course->fullname.': '.$strresetcourse, $course->fullname.': '.$strresetcourse,
25 '<a href="view.php?id='.$course->id.'">'.$course->shortname.'</a> -> '.$strresetcourse);
27 print_simple_box_start();
29 print_heading($strresetcourse);
31 /// If we have data, then process it.
32 if ($data = data_submitted() and confirm_sesskey()) {
34 $data->courseid = $course->id;
36 reset_course_userdata($data, true);
38 if (!empty($data->reset_start_date)) {
39 if (set_field('course', 'startdate',
40 make_timestamp($data->startyear, $data->startmonth, $data->startday),
41 'id', $course->id)) {
42 notify(get_string('datechanged'), 'notifysuccess');
45 print_continue('view.php?id='.$course->id); // Back to course page
46 print_simple_box_end();
47 print_footer($course);
48 exit;
53 /// Print forms so the user can make choices about what to delete
55 print_simple_box(get_string('resetinfo'), 'center', '60%');
57 echo '<form id="reset" action="reset.php" method="POST">';
59 print_heading(get_string('course'), 'left', 3);
61 echo '<div class="courseinfo">';
62 echo $strremove.':<br />';
63 print_checkbox('reset_students', 1, true, get_string('students'), '', ''); echo '<br />';
64 print_checkbox('reset_teachers', 1, true, get_string('teachers'), '', ''); echo '<br />';
65 print_checkbox('reset_events', 1, true, get_string('courseevents', 'calendar'), '', ''); echo '<br />';
66 print_checkbox('reset_logs', 1, true, get_string('logs'), '', ''); echo '<br />';
67 print_checkbox('reset_groups', 1, true, get_string('groups'), '', ''); echo '<br />';
68 print_checkbox('reset_start_date', 1, true, get_string('startdate'), '', '');
69 print_date_selector('startday', 'startmonth', 'startyear');
70 helpbutton('coursestartdate', get_string('startdate'));
71 echo '</div>';
73 // Check each module and see if there is specific data to be removed
75 if ($allmods = get_records('modules') ) {
76 foreach ($allmods as $mod) {
77 $modname = $mod->name;
78 $modfile = $CFG->dirroot .'/mod/'. $modname .'/lib.php';
79 $mod_reset_course_form = $modname .'_reset_course_form';
80 if (file_exists($modfile)) {
81 @include_once($modfile);
82 if (function_exists($mod_reset_course_form)) {
83 print_heading(get_string('modulenameplural', $modname), 'left', 3);
84 echo '<div class="'.$modname.'info">';
85 $mod_reset_course_form($course);
86 echo '</div>';
90 } else {
91 error('No modules are installed!');
94 echo '<input name="id" value="'.$course->id.'" type="hidden" />';
95 echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />';
96 echo '<p align="center"><input name="submit" value="'.$strresetcourse.'" type="submit" /></p>';
97 echo '</form>';
99 print_simple_box_end();
100 print_footer($course);