e92c286c20
even non-course and sticky blocks. The parent context is block_instances.parentcontextid. The block context should be used for checking permissions directly related to the block, like moodle/block:view or moodle/site:manageblocks. However, if the block is displaying information about the current page, for example the participants block showing who 'here', then it may be better to use the context of the page where the bloack is appearing - in other words $this->page->context - to check permissions about the user's ability to see participants here. Or, if the block is displaying something stronly related to courses, for example, a course meny block, the block should probably use the context for $this->page->course to check permissions.
221 lines
12 KiB
PHP
221 lines
12 KiB
PHP
<?php //$Id$
|
|
|
|
class block_admin extends block_list {
|
|
function init() {
|
|
$this->title = get_string('administration');
|
|
$this->version = 2007101509;
|
|
}
|
|
|
|
function get_content() {
|
|
global $CFG, $USER, $DB, $OUTPUT;
|
|
|
|
if ($this->content !== NULL) {
|
|
return $this->content;
|
|
}
|
|
|
|
$this->content = new stdClass;
|
|
$this->content->items = array();
|
|
$this->content->icons = array();
|
|
$this->content->footer = '';
|
|
|
|
$course = $this->page->course;
|
|
|
|
if (!has_capability('moodle/course:view', $this->page->context)) { // Just return
|
|
return $this->content;
|
|
}
|
|
|
|
if (empty($CFG->loginhttps)) {
|
|
$securewwwroot = $CFG->wwwroot;
|
|
} else {
|
|
$securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
|
|
}
|
|
|
|
/// Course editing on/off
|
|
if ($course->id !== SITEID and has_capability('moodle/course:update', $this->page->context)) {
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/edit') . '" class="icon" alt="" />';
|
|
if ($this->page->user_is_editing()) {
|
|
$this->content->items[]='<a href="view.php?id='.$course->id.'&edit=off&sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
|
|
} else {
|
|
$this->content->items[]='<a href="view.php?id='.$course->id.'&edit=on&sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
|
|
}
|
|
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/edit.php?id='.$course->id.'">'.get_string('settings').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/settings') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Assign roles to the course
|
|
if ($course->id != SITEID) {
|
|
if (has_capability('moodle/role:assign', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$this->page->context->id.'">'.get_string('assignroles', 'role').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/roles') . '" class="icon" alt="" />';
|
|
} else if (get_overridable_roles($this->page->context, ROLENAME_ORIGINAL)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$this->page->context->id.'">'.get_string('overridepermissions', 'role').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/roles') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
/// View course grades (or just your own grades, same link)
|
|
/// find all accessible reports
|
|
if ($course->id !== SITEID) {
|
|
$reportavailable = false;
|
|
if (has_capability('moodle/grade:viewall', $this->page->context)) {
|
|
$reportavailable = true;
|
|
} else if (!empty($course->showgrades)) {
|
|
if ($reports = get_plugin_list('gradereport')) { // Get all installed reports
|
|
arsort($reports); // user is last, we want to test it first
|
|
foreach ($reports as $plugin => $plugindir) {
|
|
if (has_capability('gradereport/'.$plugin.':view', $this->page->context)) {
|
|
//stop when the first visible plugin is found
|
|
$reportavailable = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ($reportavailable) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$course->id.'">'.get_string('grades').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/grades') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
/// Course outcomes (to help give it more prominence because it's important)
|
|
if (!empty($CFG->enableoutcomes)) {
|
|
if ($course->id!==SITEID and has_capability('moodle/course:update', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$course->id.'">'.get_string('outcomes', 'grades').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/outcomes') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
/// Manage metacourses
|
|
if ($course->metacourse) {
|
|
if (has_capability('moodle/course:managemetacourse', $this->page->context)) {
|
|
$strchildcourses = get_string('childcourses');
|
|
$this->content->items[]='<a href="importstudents.php?id='.$course->id.'">'.$strchildcourses.'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/course') . '" class="icon" alt="" />';
|
|
} else if (has_capability('moodle/role:assign', $this->page->context)) {
|
|
$strchildcourses = get_string('childcourses');
|
|
$this->content->items[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/course') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
|
|
/// Manage groups in this course
|
|
if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $this->page->context)) {
|
|
$strgroups = get_string('groups');
|
|
$this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$course->id.'">'.$strgroups.'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/group') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Backup this course
|
|
if ($course->id!==SITEID and has_capability('moodle/site:backup', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$course->id.'">'.get_string('backup').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/backup') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Restore to this course
|
|
if ($course->id !== SITEID and has_capability('moodle/site:restore', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$course->id.'&wdir=/backupdata">'.get_string('restore').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/restore') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Import data from other courses
|
|
if ($course->id !== SITEID and has_capability('moodle/site:import', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$course->id.'">'.get_string('import').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/restore') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Reset this course
|
|
if ($course->id!==SITEID and has_capability('moodle/course:reset', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$course->id.'">'.get_string('reset').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/return') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// View course reports
|
|
if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $this->page->context)) { // basic capability for listing of reports
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$course->id.'">'.get_string('reports').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/stats') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Manage questions
|
|
if ($course->id !== SITEID){
|
|
$questionlink = '';
|
|
$questioncaps = array(
|
|
'moodle/question:add',
|
|
'moodle/question:editmine',
|
|
'moodle/question:editall',
|
|
'moodle/question:viewmine',
|
|
'moodle/question:viewall',
|
|
'moodle/question:movemine',
|
|
'moodle/question:moveall');
|
|
foreach ($questioncaps as $questioncap){
|
|
if (has_capability($questioncap, $this->page->context)){
|
|
$questionlink = 'edit.php';
|
|
break;
|
|
}
|
|
}
|
|
if (!$questionlink && has_capability('moodle/question:managecategory', $this->page->context)) {
|
|
$questionlink = 'category.php';
|
|
}
|
|
if ($questionlink) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/question/'.$questionlink.
|
|
'?courseid='.$course->id.'">'.get_string('questions', 'quiz').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/questions') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
/// Repository Instances
|
|
require_once($CFG->dirroot.'/repository/lib.php');
|
|
$editabletypes = repository::get_editable_types($this->page->context);
|
|
if ($course->id !== SITEID && has_capability('moodle/course:update', $this->page->context) && !empty($editabletypes)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage_instances.php?contextid='.$this->page->context->id.'">'.get_string('repositories').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/repository') . '" alt=""/>';
|
|
}
|
|
|
|
/// Manage files
|
|
if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $this->page->context)) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$course->id.'">'.get_string('files').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/files') . '" class="icon" alt=""/>';
|
|
}
|
|
|
|
/// Authorize hooks
|
|
if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize') && ($course->id!==SITEID)) {
|
|
require_once($CFG->dirroot.'/enrol/authorize/const.php');
|
|
$paymenturl = '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?course='.$course->id.'">'.get_string('payments').'</a> ';
|
|
if (has_capability('enrol/authorize:managepayments', $this->page->context)) {
|
|
if ($cnt = $DB->count_records('enrol_authorize', array('status'=>AN_STATUS_AUTH, 'courseid'=>$course->id))) {
|
|
$paymenturl .= '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH.'&course='.$course->id.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
|
|
}
|
|
}
|
|
$this->content->items[] = $paymenturl;
|
|
$this->content->icons[] = '<img src="'.$OUTPUT->old_icon_url('i/payment') . '" class="icon" alt="" />';
|
|
}
|
|
|
|
/// Unenrol link
|
|
if (empty($course->metacourse) && ($course->id!==SITEID)) {
|
|
if (has_capability('moodle/legacy:guest', $this->page->context, NULL, false)) { // Are a guest now
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/enrol.php?id='.$course->id.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/user') . '" class="icon" alt="" />';
|
|
} else if (has_capability('moodle/role:unassignself', $this->page->context, NULL, false) and get_user_roles($this->page->context, $USER->id, false)) { // Have some role
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/course/unenrol.php?id='.$course->id.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/user') . '" class="icon" alt="" />';
|
|
}
|
|
}
|
|
|
|
/// Link to the user own profile (except guests)
|
|
if (!isguestuser() and isloggedin()) {
|
|
$this->content->items[]='<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&course='.$course->id.'">'.get_string('profile').'</a>';
|
|
$this->content->icons[]='<img src="'.$OUTPUT->old_icon_url('i/user') . '" alt="" />';
|
|
}
|
|
|
|
return $this->content;
|
|
}
|
|
|
|
function applicable_formats() {
|
|
return array('course' => true); // Not needed on site
|
|
}
|
|
}
|
|
|
|
?>
|