/** * Checks to see if the user can edit a given subscription feed. * * @param mixed $subscriptionorid Subscription object or id * @return bool true if current user can edit the subscription else false */ function calendar_can_edit_subscription($subscriptionorid) { global $DB; if (is_array($subscriptionorid)) { $subscription = (object) $subscriptionorid; } else { if (is_object($subscriptionorid)) { $subscription = $subscriptionorid; } else { $subscription = calendar_get_subscription($subscriptionorid); } } $allowed = new stdClass(); $courseid = $subscription->courseid; $groupid = $subscription->groupid; calendar_get_allowed_types($allowed, $courseid); switch ($subscription->eventtype) { case 'user': return $allowed->user; case 'course': if (isset($allowed->courses[$courseid])) { return $allowed->courses[$courseid]; } else { return false; } case 'site': return $allowed->site; case 'group': if (isset($allowed->groups[$groupid])) { return $allowed->groups[$groupid]; } else { return false; } default: return false; } }
/** * see if user can add calendar entries at all * used to print the "New Event" button * @return bool */ function calendar_user_can_add_event() { calendar_get_allowed_types($allowed); return (bool) ($allowed->user || $allowed->groups || $allowed->courses || $allowed->site); }
$form->modulename = ''; $form->eventtype = ''; $form->instance = 0; $form->timeduration = 0; $form->duration = 0; $form->repeat = 0; $form->repeats = ''; $form->minutes = ''; $form->type = 'group'; $header = get_string('typegroup', 'calendar'); } break; case 'course': $courseid = optional_param('courseid', 0, PARAM_INT); if (!record_exists('course', 'id', $courseid)) { calendar_get_allowed_types($allowed); $eventtype = 'select'; } else { $form->name = ''; $form->description = ''; $form->courseid = $courseid; $form->groupid = 0; $form->userid = $USER->id; $form->modulename = ''; $form->eventtype = ''; $form->instance = 0; $form->timeduration = 0; $form->duration = 0; $form->repeat = 0; $form->repeats = ''; $form->minutes = '';
/** * See if user can add calendar entries at all * used to print the "New Event" button * * @param stdClass $course object of a course or course id * @return bool has the capability to add at least one event type */ function calendar_user_can_add_event($course) { if (!isloggedin() || isguestuser()) { return false; } calendar_get_allowed_types($allowed, $course); return (bool) ($allowed->user || $allowed->groups || $allowed->courses || $allowed->site); }
/** * Returns option list of available options for the calendar event type, given the current user and course. * * @param int $courseid The id of the course * @return array An array containing the event types the user can create. */ function calendar_get_eventtype_choices($courseid) { $choices = array(); $allowed = new stdClass(); calendar_get_allowed_types($allowed, $courseid); if ($allowed->user) { $choices['user'] = get_string('userevents', 'calendar'); } if ($allowed->site) { $choices['site'] = get_string('siteevents', 'calendar'); } if (!empty($allowed->courses)) { $choices['course'] = get_string('courseevents', 'calendar'); } if (!empty($allowed->groups) and is_array($allowed->groups)) { $choices['group'] = get_string('group'); } return array($choices, $allowed->groups); }
if ($eventid !== 0) { $title = get_string('editevent', 'calendar'); $event = calendar_event::load($eventid); if (!calendar_edit_event_allowed($event)) { print_error('nopermissions'); } $event->action = $action; $event->course = $courseid; $event->timedurationuntil = $event->timestart + $event->timeduration; $event->count_repeats(); if (!calendar_add_event_allowed($event)) { print_error('nopermissions'); } } else { $title = get_string('newevent', 'calendar'); calendar_get_allowed_types($formoptions->eventtypes, $USER->id); $event = new stdClass(); $event->action = $action; $event->course = $courseid; $event->timeduration = 0; if ($formoptions->eventtypes->courses) { if ($courseexists) { $event->courseid = $courseid; $event->eventtype = 'course'; } else { unset($formoptions->eventtypes->courses); unset($formoptions->eventtypes->groups); } } if ($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) { $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);
if ($eventid !== 0) { $title = get_string('editevent', 'calendar'); $event = calendar_event::load($eventid); if (!calendar_edit_event_allowed($event)) { print_error('nopermissions'); } $event->action = $action; $event->course = $courseid; $event->timedurationuntil = $event->timestart + $event->timeduration; $event->count_repeats(); if (!calendar_add_event_allowed($event)) { print_error('nopermissions'); } } else { $title = get_string('newevent', 'calendar'); calendar_get_allowed_types($formoptions->eventtypes, $course); $event = new stdClass(); $event->action = $action; $event->course = $courseid; $event->courseid = $courseid; $event->timeduration = 0; if ($formoptions->eventtypes->courses) { if (!$issite) { $event->eventtype = 'course'; } else { unset($formoptions->eventtypes->courses); unset($formoptions->eventtypes->groups); } } if ($cal_y && $cal_m && $cal_d && checkdate($cal_m, $cal_d, $cal_y)) { $event->timestart = make_timestamp($cal_y, $cal_m, $cal_d, 0, 0, 0);