title = get_string('administration');
$this->version = 2004081200;
}
function get_content() {
global $CFG, $USER, $SITE, $COURSE;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if (empty($this->instance)) {
return $this->content = '';
} else if ($this->instance->pageid == SITEID) {
// return $this->content = '';
}
if (!empty($this->instance->pageid)) {
$context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
if ($COURSE->id == $this->instance->pageid) {
$course = $COURSE;
} else {
$course = get_record('course', 'id', $this->instance->pageid);
}
} else {
$context = get_context_instance(CONTEXT_SYSTEM);
$course = $SITE;
}
if (!has_capability('moodle/course:view', $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 (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
$this->content->icons[]='
';
if (isediting($this->instance->pageid)) {
$this->content->items[]=''.get_string('turneditingoff').'';
} else {
$this->content->items[]=''.get_string('turneditingon').'';
}
$this->content->items[]=''.get_string('settings').'';
$this->content->icons[]='
';
}
/// Assign roles to the course
if (has_capability('moodle/role:assign', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('assignroles', 'role').'';
$this->content->icons[]='
';
}
/// View course grades (or just your own grades, same link)
/// find all accessible reports
if ($course->id!==SITEID) {
if ($reports = get_list_of_plugins('grade/report', 'CVS')) { // Get all installed reports
foreach ($reports as $key => $plugin) { // Remove ones we can't see
if (!has_capability('gradereport/'.$plugin.':view', $context)) {
unset($reports[$key]);
}
}
}
if (!empty($reports)) {
$this->content->items[]=''.get_string('grades').'';
$this->content->icons[]='
';
}
}
/// Course outcomes (to help give it more prominence because it's important)
if (!empty($CFG->enableoutcomes)) {
if (has_capability('moodle/course:update', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('outcomes', 'grades').'';
$this->content->icons[]='
';
}
}
/// Manage metacourses
if ($course->metacourse) {
if (has_capability('moodle/course:managemetacourse', $context)) {
$strchildcourses = get_string('childcourses');
$this->content->items[]=''.$strchildcourses.'';
$this->content->icons[]='
';
} else if (has_capability('moodle/role:assign', $context)) {
$strchildcourses = get_string('childcourses');
$this->content->items[]=''.$strchildcourses.'';
$this->content->icons[]='
';
}
}
/// Manage groups in this course
if (($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context) && ($course->id!==SITEID)) {
$strgroups = get_string('groups');
$this->content->items[]=''.$strgroups.'';
$this->content->icons[]='
';
}
/// Backup this course
if (has_capability('moodle/site:backup', $context)&& ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('backup').'';
$this->content->icons[]='
';
}
/// Restore to this course
if (has_capability('moodle/site:restore', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('restore').'';
$this->content->icons[]='
';
}
/// Import data from other courses
if (has_capability('moodle/site:import', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('import').'';
$this->content->icons[]='
';
}
/// Reset this course
if (has_capability('moodle/course:reset', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('reset').'';
$this->content->icons[]='
';
}
/// View course reports
if (has_capability('moodle/site:viewreports', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('reports').'';
$this->content->icons[]='
';
}
/// 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, $context)){
$questionlink = 'edit.php';
break;
}
}
if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
$questionlink = 'category.php';
}
if ($questionlink) {
$this->content->items[]=''.get_string('questions', 'quiz').'';
$this->content->icons[]='
';
}
}
/// Manage files
if (has_capability('moodle/course:managefiles', $context) && ($course->id!==SITEID)) {
$this->content->items[]=''.get_string('files').'';
$this->content->icons[]='
';
}
/// Authorize hooks
if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize') && ($course->id!==SITEID)) {
require_once($CFG->dirroot.'/enrol/authorize/const.php');
$paymenturl = ''.get_string('payments').' ';
if (has_capability('enrol/authorize:managepayments', $context)) {
if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
$paymenturl .= ''.get_string('paymentpending', 'moodle', $cnt).'';
}
}
$this->content->items[] = $paymenturl;
$this->content->icons[] = '
';
}
/// Unenrol link
if (empty($course->metacourse) && ($course->id!==SITEID)) {
if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
$this->content->items[]=''.get_string('enrolme', '', format_string($course->shortname)).'';
$this->content->icons[]='
';
} else if (has_capability('moodle/role:unassignself', $context, NULL, false)) { // Have some role
$this->content->items[]=''.get_string('unenrolme', '', format_string($course->shortname)).'';
$this->content->icons[]='
';
}
}
/// Should the following two be in this block?
/// View own activity report
// if ($course->showreports) {
// $this->content->items[]=''.get_string('activityreport').'';
// $this->content->icons[]='
';
// }
/// Edit your own profile
// $fullname = fullname($USER, has_capability('moodle/site:viewfullnames', $context));
// $editmyprofile = ''.get_string('editmyprofile').'';
// if (empty($USER->description)) {
// //Accessibility: replace non-standard