3 class block_admin
extends block_list
{
5 $this->title
= get_string('administration');
6 $this->version
= 2007101509;
9 function get_content() {
11 global $CFG, $USER, $SITE, $COURSE;
13 if ($this->content
!== NULL) {
14 return $this->content
;
17 $this->content
= new stdClass
;
18 $this->content
->items
= array();
19 $this->content
->icons
= array();
20 $this->content
->footer
= '';
22 if (empty($this->instance
)) {
23 return $this->content
= '';
24 } else if ($this->instance
->pageid
== SITEID
) {
25 // return $this->content = '';
28 if (!empty($this->instance
->pageid
)) {
29 $context = get_context_instance(CONTEXT_COURSE
, $this->instance
->pageid
);
30 if ($COURSE->id
== $this->instance
->pageid
) {
33 $course = get_record('course', 'id', $this->instance
->pageid
);
36 $context = get_context_instance(CONTEXT_SYSTEM
);
40 if (!has_capability('moodle/course:view', $context)) { // Just return
41 return $this->content
;
44 if (empty($CFG->loginhttps
)) {
45 $securewwwroot = $CFG->wwwroot
;
47 $securewwwroot = str_replace('http:','https:',$CFG->wwwroot
);
50 /// Course editing on/off
52 if ($course->id
!== SITEID
and has_capability('moodle/course:update', $context)) {
53 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/edit.gif" class="icon" alt="" />';
54 if (isediting($this->instance
->pageid
)) {
55 $this->content
->items
[]='<a href="view.php?id='.$this->instance
->pageid
.'&edit=off&sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
57 $this->content
->items
[]='<a href="view.php?id='.$this->instance
->pageid
.'&edit=on&sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
60 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/edit.php?id='.$this->instance
->pageid
.'">'.get_string('settings').'</a>';
61 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/settings.gif" class="icon" alt="" />';
64 /// Assign roles to the course
66 if ($course->id
!= SITEID
) {
67 if (has_capability('moodle/role:assign', $context)) {
68 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$context->id
.'">'.get_string('assignroles', 'role').'</a>';
69 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/roles.gif" class="icon" alt="" />';
70 } else if (get_overridable_roles($context, 'name', ROLENAME_ORIGINAL
)) {
71 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/override.php?contextid='.$context->id
.'">'.get_string('overridepermissions', 'role').'</a>';
72 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/roles.gif" class="icon" alt="" />';
76 /// View course grades (or just your own grades, same link)
77 /// find all accessible reports
78 if ($course->id
!== SITEID
) {
79 $reportavailable = false;
80 if (has_capability('moodle/grade:viewall', $context)) {
81 $reportavailable = true;
82 } else if (!empty($course->showgrades
)) {
83 if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
84 arsort($reports); // user is last, we want to test it first
85 foreach ($reports as $plugin) {
86 if (has_capability('gradereport/'.$plugin.':view', $context)) {
87 //stop when the first visible plugin is found
88 $reportavailable = true;
95 if ($reportavailable) {
96 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/report/index.php?id='.$this->instance
->pageid
.'">'.get_string('grades').'</a>';
97 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/grades.gif" class="icon" alt="" />';
101 /// Course outcomes (to help give it more prominence because it's important)
102 if (!empty($CFG->enableoutcomes
)) {
103 if ($course->id
!==SITEID
and has_capability('moodle/course:update', $context)) {
104 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/edit/outcome/course.php?id='.$this->instance
->pageid
.'">'.get_string('outcomes', 'grades').'</a>';
105 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/outcomes.gif" class="icon" alt="" />';
109 /// Manage metacourses
110 if ($course->metacourse
) {
111 if (has_capability('moodle/course:managemetacourse', $context)) {
112 $strchildcourses = get_string('childcourses');
113 $this->content
->items
[]='<a href="importstudents.php?id='.$this->instance
->pageid
.'">'.$strchildcourses.'</a>';
114 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
115 } else if (has_capability('moodle/role:assign', $context)) {
116 $strchildcourses = get_string('childcourses');
117 $this->content
->items
[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
118 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
123 /// Manage groups in this course
125 if (($course->id
!==SITEID
) && ($course->groupmode ||
!$course->groupmodeforce
) && has_capability('moodle/course:managegroups', $context)) {
126 $strgroups = get_string('groups');
127 $this->content
->items
[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot
.'/group/index.php?id='.$this->instance
->pageid
.'">'.$strgroups.'</a>';
128 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/group.gif" class="icon" alt="" />';
131 /// Backup this course
133 if ($course->id
!==SITEID
and has_capability('moodle/site:backup', $context)) {
134 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/backup/backup.php?id='.$this->instance
->pageid
.'">'.get_string('backup').'</a>';
135 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/backup.gif" class="icon" alt="" />';
138 /// Restore to this course
139 if ($course->id
!== SITEID
and has_capability('moodle/site:restore', $context)) {
140 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'&wdir=/backupdata">'.get_string('restore').'</a>';
141 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
144 /// Import data from other courses
145 if ($course->id
!== SITEID
and has_capability('moodle/site:import', $context)) {
146 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/import.php?id='.$this->instance
->pageid
.'">'.get_string('import').'</a>';
147 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
150 /// Reset this course
151 if ($course->id
!==SITEID
and has_capability('moodle/course:reset', $context)) {
152 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/reset.php?id='.$this->instance
->pageid
.'">'.get_string('reset').'</a>';
153 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/return.gif" class="icon" alt="" />';
156 /// View course reports
157 if ($course->id
!== SITEID
and has_capability('moodle/site:viewreports', $context)) {
158 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/report.php?id='.$this->instance
->pageid
.'">'.get_string('reports').'</a>';
159 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/stats.gif" class="icon" alt="" />';
163 if ($course->id
!== SITEID
){
165 $questioncaps = array(
166 'moodle/question:add',
167 'moodle/question:editmine',
168 'moodle/question:editall',
169 'moodle/question:viewmine',
170 'moodle/question:viewall',
171 'moodle/question:movemine',
172 'moodle/question:moveall');
173 foreach ($questioncaps as $questioncap){
174 if (has_capability($questioncap, $context)){
175 $questionlink = 'edit.php';
179 if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
180 $questionlink = 'category.php';
183 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/question/'.$questionlink.
184 '?courseid='.$this->instance
->pageid
.'">'.get_string('questions', 'quiz').'</a>';
185 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/questions.gif" class="icon" alt="" />';
191 if ($course->id
!== SITEID
and has_capability('moodle/course:managefiles', $context)) {
192 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'">'.get_string('files').'</a>';
193 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/files.gif" class="icon" alt="" />';
197 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize') && ($course->id
!==SITEID
)) {
198 require_once($CFG->dirroot
.'/enrol/authorize/const.php');
199 $paymenturl = '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?course='.$course->id
.'">'.get_string('payments').'</a> ';
200 if (has_capability('enrol/authorize:managepayments', $context)) {
201 if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH
, 'courseid', $course->id
)) {
202 $paymenturl .= '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH
.'&course='.$course->id
.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
205 $this->content
->items
[] = $paymenturl;
206 $this->content
->icons
[] = '<img src="'.$CFG->pixpath
.'/i/payment.gif" class="icon" alt="" />';
210 if (empty($course->metacourse
) && ($course->id
!==SITEID
)) {
211 if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
212 $this->content
->items
[]='<a href="enrol.php?id='.$this->instance
->pageid
.'">'.get_string('enrolme', '', format_string($course->shortname
)).'</a>';
213 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
214 } else if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id
, false)) { // Have some role
215 $this->content
->items
[]='<a href="unenrol.php?id='.$this->instance
->pageid
.'">'.get_string('unenrolme', '', format_string($course->shortname
)).'</a>';
216 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
220 /// Link to the user own profile (except guests)
221 if (!isguestuser() and isloggedin()) {
222 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$USER->id
.'&course='.$course->id
.'">'.get_string('profile').'</a>';
223 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" alt="" />';
226 return $this->content
;
229 function applicable_formats() {
230 return array('course' => true); // Not needed on site