2 require_once $CFG->libdir
.'/formslib.php';
4 class course_reset_form
extends moodleform
{
5 function definition (){
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;
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
);
83 $mform->setType('id', PARAM_INT
);
85 $buttonarray = array();
86 $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('resetcourse'));
87 $buttonarray[] = &$mform->createElement('submit', 'selectdefault', get_string('selectdefault'));
88 $buttonarray[] = &$mform->createElement('submit', 'deselectall', get_string('deselectall'));
89 $buttonarray[] = &$mform->createElement('cancel');
90 $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
91 $mform->closeHeaderBefore('buttonar');
94 function load_defaults() {
97 $mform =& $this->_form
;
99 $defaults = array ('reset_events'=>1, 'reset_logs'=>1, 'reset_roles_local'=>1, 'reset_gradebook_grades'=>1, 'reset_notes'=>1);
101 if (!empty($COURSE->defaultrole
)) {
102 $defaults['reset_roles'] = array($COURSE->defaultrole
);
104 $defaults['reset_roles'] = array($CFG->defaultcourseroleid
);
107 if ($allmods = get_records('modules') ) {
108 foreach ($allmods as $mod) {
109 $modname = $mod->name
;
110 $modfile = $CFG->dirroot
."/mod/$modname/lib.php";
111 $mod_reset_course_form_defaults = $modname.'_reset_course_form_defaults';
112 if (file_exists($modfile)) {
113 @include_once
($modfile);
114 if (function_exists($mod_reset_course_form_defaults)) {
115 if ($moddefs = $mod_reset_course_form_defaults($COURSE)) {
116 $defaults = $defaults +
$moddefs;
123 foreach ($defaults as $element=>$default) {
124 $mform->setDefault($element, $default);