Moodle 1.9.19 release
[moodle.git] / course / reset.php
blobcf165cd51ccc05dfde25097fe69d2690435df9fc
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 */
11 require('../config.php');
12 require_once('reset_form.php');
14 $id = required_param('id', PARAM_INT);
16 if (!$course = get_record('course', 'id', $id)) {
17 error("Course is misconfigured");
20 require_login($course);
21 require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
23 $strreset = get_string('reset');
24 $strresetcourse = get_string('resetcourse');
25 $strremove = get_string('remove');
27 $navlinks = array(array('name' => $strresetcourse, 'link' => null, 'type' => 'misc'));
28 $navigation = build_navigation($navlinks);
30 $mform = new course_reset_form();
32 if ($mform->is_cancelled()) {
33 redirect($CFG->wwwroot.'/course/view.php?id='.$id);
35 } else if ($data = $mform->get_data(false)) { // no magic quotes
37 if (isset($data->selectdefault)) {
38 $_POST = array();
39 $mform = new course_reset_form();
40 $mform->load_defaults();
42 } else if (isset($data->deselectall)) {
43 $_POST = array();
44 $mform = new course_reset_form();
46 } else {
47 print_header($course->fullname.': '.$strresetcourse, $course->fullname.': '.$strresetcourse, $navigation);
48 print_heading($strresetcourse);
50 $data->reset_start_date_old = $course->startdate;
51 $status = reset_course_userdata($data);
53 $data = array();;
54 foreach ($status as $item) {
55 $line = array();
56 $line[] = $item['component'];
57 $line[] = $item['item'];
58 $line[] = ($item['error']===false) ? get_string('ok') : '<div class="notifyproblem">'.$item['error'].'</div>';
59 $data[] = $line;
62 $table = new object();
63 $table->head = array(get_string('resetcomponent'), get_string('resettask'), get_string('resetstatus'));
64 $table->size = array('20%', '40%', '40%');
65 $table->align = array('left', 'left', 'left');
66 $table->width = '80%';
67 $table->data = $data;
68 print_table($table);
70 print_continue('view.php?id='.$course->id); // Back to course page
71 print_footer($course);
72 exit;
76 print_header($course->fullname.': '.$strresetcourse, $course->fullname.': '.$strresetcourse, $navigation);
77 print_heading($strresetcourse);
79 print_simple_box(get_string('resetinfo'), 'center', '60%');
81 $mform->display();
82 print_footer($course);