Merge branch 'w08_MDL-38096_m25_manenrol' of git://github.com/skodak/moodle

This commit is contained in:
Damyon Wiese
2013-02-25 10:44:54 +08:00
2 changed files with 22 additions and 9 deletions
+4 -2
View File
@@ -68,7 +68,9 @@ class enrol_manual_plugin extends enrol_plugin {
$context = context_course::instance($instance->courseid, MUST_EXIST);
if (!has_capability('enrol/manual:manage', $context) or !has_capability('enrol/manual:enrol', $context) or !has_capability('enrol/manual:unenrol', $context)) {
if (!has_capability('enrol/manual:enrol', $context) and !has_capability('enrol/manual:unenrol', $context)) {
// Note: manage capability not used here because it is used for editing
// of existing enrolments which is not possible here.
return NULL;
}
@@ -111,7 +113,7 @@ class enrol_manual_plugin extends enrol_plugin {
$icons = array();
if (has_capability('enrol/manual:manage', $context)) {
if (has_capability('enrol/manual:enrol', $context) or has_capability('enrol/manual:unenrol', $context)) {
$managelink = new moodle_url("/enrol/manual/manage.php", array('enrolid'=>$instance->id));
$icons[] = $OUTPUT->action_icon($managelink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall')));
}
+18 -7
View File
@@ -35,9 +35,17 @@ $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_
$context = context_course::instance($course->id, MUST_EXIST);
require_login($course);
require_capability('enrol/manual:enrol', $context);
require_capability('enrol/manual:manage', $context);
require_capability('enrol/manual:unenrol', $context);
$canenrol = has_capability('enrol/manual:enrol', $context);
$canunenrol = has_capability('enrol/manual:unenrol', $context);
// Note: manage capability not used here because it is used for editing
// of existing enrolments which is not possible here.
if (!$canenrol and !$canunenrol) {
// No need to invent new error strings here...
require_capability('enrol/manual:enrol', $context);
require_capability('enrol/manual:unenrol', $context);
}
if ($roleid < 0) {
$roleid = $instance->roleid;
@@ -95,7 +103,7 @@ if ($course->startdate > 0) {
$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
// Process add and removes.
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
if ($canenrol && optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
$userstoassign = $potentialuserselector->get_selected_users();
if (!empty($userstoassign)) {
foreach($userstoassign as $adduser) {
@@ -126,7 +134,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
}
// Process incoming role unassignments.
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
if ($canunenrol && optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
$userstounassign = $currentuserselector->get_selected_users();
if (!empty($userstounassign)) {
foreach($userstounassign as $removeuser) {
@@ -145,6 +153,9 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
echo $OUTPUT->header();
echo $OUTPUT->heading($instancename);
$addenabled = $canenrol ? '' : 'disabled="disabled"';
$removeenabled = $canunenrol ? '' : 'disabled="disabled"';
?>
<form id="assignform" method="post" action="<?php echo $PAGE->url ?>"><div>
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
@@ -157,7 +168,7 @@ echo $OUTPUT->heading($instancename);
</td>
<td id="buttonscell">
<div id="addcontrols">
<input name="add" id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<input name="add" <?php echo $addenabled; ?> id="add" type="submit" value="<?php echo $OUTPUT->larrow().'&nbsp;'.get_string('add'); ?>" title="<?php print_string('add'); ?>" /><br />
<div class="enroloptions">
@@ -174,7 +185,7 @@ echo $OUTPUT->heading($instancename);
</div>
<div id="removecontrols">
<input name="remove" id="remove" type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
<input name="remove" id="remove" <?php echo $removeenabled; ?> type="submit" value="<?php echo get_string('remove').'&nbsp;'.$OUTPUT->rarrow(); ?>" title="<?php print_string('remove'); ?>" />
</div>
</td>
<td id="potentialcell">