Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / course / reset_form.php
blob37b47c077412e6e68b41b46d035bd6b9f277c222
1 <?php // $Id$
2 require_once $CFG->libdir.'/formslib.php';
4 class course_reset_form extends moodleform {
5 function definition (){
6 global $CFG, $COURSE;
8 $mform =& $this->_form;
10 $mform->addElement('header', 'generalheader', get_string('general'));
12 $mform->addElement('date_selector', 'reset_start_date', get_string('startdate'), array('optional'=>true));
13 $mform->setHelpButton('reset_start_date', array('coursestartdate', get_string('startdate')));
14 $mform->addElement('checkbox', 'reset_events', get_string('deleteevents', 'calendar'));
15 $mform->addElement('checkbox', 'reset_logs', get_string('deletelogs'));
16 $mform->addElement('checkbox', 'reset_notes', get_string('deletenotes', 'notes'));
19 $mform->addElement('header', 'rolesheader', get_string('roles'));
21 $roles = get_assignable_roles(get_context_instance(CONTEXT_COURSE, $COURSE->id));
22 $mform->addElement('select', 'reset_roles', get_string('unenrolroleusers'), $roles, array('multiple' => 'multiple'));
23 $mform->addElement('checkbox', 'reset_roles_overrides', get_string('deletecourseoverrides', 'role'));
24 $mform->setAdvanced('reset_roles_overrides');
25 $mform->addElement('checkbox', 'reset_roles_local', get_string('deletelocalroles', 'role'));
28 $mform->addElement('header', 'gradebookheader', get_string('gradebook', 'grades'));
30 $mform->addElement('checkbox', 'reset_gradebook_items', get_string('removeallcourseitems', 'grades'));
31 $mform->addElement('checkbox', 'reset_gradebook_grades', get_string('removeallcoursegrades', 'grades'));
32 $mform->disabledIf('reset_gradebook_grades', 'reset_gradebook_items', 'checked');
35 $mform->addElement('header', 'groupheader', get_string('groups'));
37 $mform->addElement('checkbox', 'reset_groups_remove', get_string('deleteallgroups', 'group'));
38 $mform->setAdvanced('reset_groups_remove');
39 $mform->addElement('checkbox', 'reset_groups_members', get_string('removegroupsmembers', 'group'));
40 $mform->setAdvanced('reset_groups_members');
41 $mform->disabledIf('reset_groups_members', 'reset_groups_remove', 'checked');
43 if (!empty($CFG->enablegroupings)) {
44 $mform->addElement('checkbox', 'reset_groupings_remove', get_string('deleteallgroupings', 'group'));
45 $mform->setAdvanced('reset_groupings_remove');
46 $mform->addElement('checkbox', 'reset_groupings_members', get_string('removegroupingsmembers', 'group'));
47 $mform->setAdvanced('reset_groupings_members');
48 $mform->disabledIf('reset_groupings_members', 'reset_groupings_remove', 'checked');
51 $unsupported_mods = array();
52 if ($allmods = get_records('modules') ) {
53 foreach ($allmods as $mod) {
54 $modname = $mod->name;
55 if (!count_records($modname, 'course', $COURSE->id)) {
56 continue; // skip mods with no instances
58 $modfile = $CFG->dirroot."/mod/$modname/lib.php";
59 $mod_reset_course_form_definition = $modname.'_reset_course_form_definition';
60 $mod_reset__userdata = $modname.'_reset_userdata';
61 if (file_exists($modfile)) {
62 include_once($modfile);
63 if (function_exists($mod_reset_course_form_definition)) {
64 $mod_reset_course_form_definition($mform);
65 } else if (!function_exists($mod_reset__userdata)) {
66 $unsupported_mods[] = $mod;
68 } else {
69 debugging('Missing lib.php in '.$modname.' module');
73 // mention unsupported mods
74 if (!empty($unsupported_mods)) {
75 $mform->addElement('header', 'unsupportedheader', get_string('resetnotimplemented'));
76 foreach($unsupported_mods as $mod) {
77 $mform->addElement('static', 'unsup'.$mod->name, get_string('modulenameplural', $mod->name));
78 $mform->setAdvanced('unsup'.$mod->name);
82 $mform->addElement('hidden', 'id', $COURSE->id);
84 $buttonarray = array();
85 $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse'));
86 $buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
87 $buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
88 $buttonarray[] = &$mform->createElement('cancel');
89 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
90 $mform->closeHeaderBefore('buttonar');
93 function load_defaults() {
94 global $CFG, $COURSE;
96 $mform =& $this->_form;
98 $defaults = array ('reset_events'=>1, 'reset_logs'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
100 if (!empty($COURSE->defaultrole)) {
101 $defaults['reset_roles'] = array($COURSE->defaultrole);
102 } else {
103 $defaults['reset_roles'] = array($CFG->defaultcourseroleid);
106 if ($allmods = get_records('modules') ) {
107 foreach ($allmods as $mod) {
108 $modname = $mod->name;
109 $modfile = $CFG->dirroot."/mod/$modname/lib.php";
110 $mod_reset_course_form_defaults = $modname.'_reset_course_form_defaults';
111 if (file_exists($modfile)) {
112 @include_once($modfile);
113 if (function_exists($mod_reset_course_form_defaults)) {
114 $defaults = $defaults + $mod_reset_course_form_defaults($COURSE);
120 foreach ($defaults as $element=>$default) {
121 $mform->setDefault($element, $default);