Adding of calendar events broken MDL-7297; merged from MOODLE_17_STABLE

This commit is contained in:
skodak 2006-10-30 22:33:45 +00:00
parent 4a58a22806
commit 695e03f00a
2 changed files with 34 additions and 27 deletions

View File

@ -181,7 +181,7 @@
case 'new': case 'new':
$title = get_string('newevent', 'calendar'); $title = get_string('newevent', 'calendar');
$form = data_submitted(); $form = data_submitted();
if(!empty($form) && $form->type == 'defined') { if(!empty($form) && !empty($form->name)) {
$form->name = clean_text(strip_tags($form->name, '<lang><span>')); $form->name = clean_text(strip_tags($form->name, '<lang><span>'));
@ -198,7 +198,7 @@
else { else {
$form->timeduration = 0; $form->timeduration = 0;
} }
if(!calendar_add_event_allowed($form->courseid, $form->groupid, $form->userid)) { if(!calendar_add_event_allowed($form)) {
error('You are not authorized to do this'); error('You are not authorized to do this');
} }
validate_form($form, $err); validate_form($form, $err);
@ -405,6 +405,7 @@
$form->repeat = 0; $form->repeat = 0;
$form->repeats = ''; $form->repeats = '';
$form->minutes = ''; $form->minutes = '';
$form->type = 'user';
$header = get_string('typeuser', 'calendar'); $header = get_string('typeuser', 'calendar');
break; break;
case 'group': case 'group':
@ -427,6 +428,7 @@
$form->repeat = 0; $form->repeat = 0;
$form->repeats = ''; $form->repeats = '';
$form->minutes = ''; $form->minutes = '';
$form->type = 'group';
$header = get_string('typegroup', 'calendar'); $header = get_string('typegroup', 'calendar');
} }
break; break;
@ -450,6 +452,7 @@
$form->repeat = 0; $form->repeat = 0;
$form->repeats = ''; $form->repeats = '';
$form->minutes = ''; $form->minutes = '';
$form->type = 'course';
$header = get_string('typecourse', 'calendar'); $header = get_string('typecourse', 'calendar');
} }
break; break;
@ -467,9 +470,9 @@
$form->repeat = 0; $form->repeat = 0;
$form->repeats = ''; $form->repeats = '';
$form->minutes = ''; $form->minutes = '';
$form->type = 'site';
$header = get_string('typesite', 'calendar'); $header = get_string('typesite', 'calendar');
break; break;
case 'defined':
case 'select': case 'select':
break; break;
default: default:
@ -579,40 +582,44 @@ function validate_form(&$form, &$err) {
} }
} }
function calendar_add_event_allowed($courseid, $groupid, $userid) { function calendar_add_event_allowed($event) {
global $USER; global $USER;
// can not be using guest account // can not be using guest account
if ($USER->username == "guest") { if (empty($USER->id) or $USER->username == 'guest') {
return false; return false;
} }
$sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID); $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
// if user has manageentries at site level, return true // if user has manageentries at site level, always return true
if (has_capability('moodle/calendar:manageentries', $sitecontext)) { if (has_capability('moodle/calendar:manageentries', $sitecontext)) {
return true; return true;
} }
// editting userid account switch ($event->type) {
if ($event->userid) { case 'course':
if ($event->userid == $USER->id) { return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid));
return (has_capability('moodle/calendar:manageownentries', $sitecontext));
} case 'group':
} else if ($event->groupid) { if (!$group = get_record('groups', 'id', $event->groupid)) {
$group = get_record('groups', 'id', $event->groupid); return false;
if($group === false) { }
return false; // this is ok because if you have this capability at course level, you should be able
} // to edit group calendar too
// there is no need to check membership, because if you have this capability
// this is ok because if you have this capability at course level, you should be able // you will have a role in this group context
// to edit group calendar too return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $group->id));
// there is no need to check membership, because if you have this capability
// you will have a role in this group context case 'user':
return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_GROUP, $group->id)); if ($event->userid == $USER->id) {
} else if ($event->courseid) { return (has_capability('moodle/calendar:manageownentries', $sitecontext));
return has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $event->courseid)); }
//there is no 'break;' intentionally
case 'site':
default:
return false; // should already return true above if having moodle/calendar:manageentries
} }
return false;
} }
function calendar_get_allowed_types(&$allowed) { function calendar_get_allowed_types(&$allowed) {

View File

@ -97,7 +97,7 @@
<input type="hidden" name="instance" value="<?php echo $form->instance?>" /> <input type="hidden" name="instance" value="<?php echo $form->instance?>" />
<input type="hidden" name="format" value="<?php echo $form->format; ?>" /> <input type="hidden" name="format" value="<?php echo $form->format; ?>" />
<input type="hidden" name="action" value="new" /> <input type="hidden" name="action" value="new" />
<input type="hidden" name="type" value="defined" /> <input type="hidden" name="type" value="<?php echo $form->type; ?>" />
</p> </p>
</form> </form>