We are using an external database to handle enrollments and course creation in our 1.8 installation. Unfortunately, some teachers have taken it upon themselves to change course names and IDs, which we'd rather they didn't. At first glance, I only see a way to block access to the Course Settings option entirely. This is far less than ideal, as we still want instructors to be able to set course availability, among other things.
Is there a way to lock individual course settings?
Christopher,
While researching the has_capability function to do further php tweaking, I found this forum post with a code snippet that will do exactly what I need:
http://moodle.org/mod/forum/discuss.php?d=95028&parent=419586
Thanks! (and thank you, Wen Yu Shu!)
While researching the has_capability function to do further php tweaking, I found this forum post with a code snippet that will do exactly what I need:
http://moodle.org/mod/forum/discuss.php?d=95028&parent=419586
Thanks! (and thank you, Wen Yu Shu!)
Don,
I was looking into that as well and the process I want to achieve is (probably like yours)
- Check what role user is logged in as
- if non-admin, make those fields read-only
else, make it editable
I gather you've looked at this page (how permissions are calculated).
http://docs.moodle.org/en/How_permissions_are_calculated
I was looking into that as well and the process I want to achieve is (probably like yours)
- Check what role user is logged in as
- if non-admin, make those fields read-only
else, make it editable
I gather you've looked at this page (how permissions are calculated).
http://docs.moodle.org/en/How_permissions_are_calculated
Great mod to the code, my instructors have been really messing up the automated enrollment process. This code works everywhere in edit_form.php except for the course start and end dates section. If you make this an admin only function when instructors try to save changes they are allowed to make them but it errors because the little check boxes that disable start and end dates are enabled, but instructors cannot see the error because its only viewable to admins. if you view it as an admin the boxes are check "disable" and all is fine. I was only able to discover this by removing the "if(has capability"code, then when I refresh the screen logged in as the instructor it shows the check boxes unchecked and you learn the default course start and end date are the same, which is throwing the error now visible. below is the code, any way to fix this?
//disable course startdates admins only
if (has_capability('moodle/course:create', $categorycontext)) {
$enroldatestartgrp = array();
$enroldatestartgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolstartdate');
$enroldatestartgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolstartdisabled', null, get_string('disable'));
$mform->addGroup($enroldatestartgrp, 'enrolstartdategrp', get_string('enrolstartdate'), ' ', false);
$mform->setDefault('enrolstartdate', 0);
$mform->setDefault('enrolstartdisabled', 1);
$mform->disabledIf('enrolstartdategrp', 'enrolstartdisabled', 'checked');
} else {
$mform->addElement('hidden', 'enrolstartdate', null);
}
//disable course enddates admin feature only
if (has_capability('moodle/course:create', $categorycontext)) {
$enroldateendgrp = array();
$enroldateendgrp[] = &MoodleQuickForm::createElement('date_selector', 'enrolenddate');
$enroldateendgrp[] = &MoodleQuickForm::createElement('checkbox', 'enrolenddisabled', null, get_string('disable'));
$mform->addGroup($enroldateendgrp, 'enroldateendgrp', get_string('enrolenddate'), ' ', false);
$mform->setDefault('enrolenddate', 0);
$mform->setDefault('enrolenddisabled', 1);
$mform->disabledIf('enroldateendgrp', 'enrolenddisabled', 'checked');
} else {
$mform->addElement('hidden', 'enrolenddate', null);
}