3 class block_admin
extends block_list
{
5 $this->title
= get_string('administration');
6 $this->version
= 2004081200;
9 function get_content() {
11 global $CFG, $USER, $SITE;
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
);
32 if (empty($context)) {
33 $context = get_context_instance(CONTEXT_SYSTEM
);
36 if (!$course = get_record('course', 'id', $this->instance
->pageid
)) {
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 (has_capability('moodle/course:update', $context) && ($course->id
!==SITEID
)) {
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="" />';
65 /// Assign roles to the course
67 if (has_capability('moodle/role:assign', $context) && ($course->id
!==SITEID
)) {
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="" />';
73 /// Manage metacourses
74 if ($course->metacourse
) {
75 if (has_capability('moodle/course:managemetacourse', $context)) {
76 $strchildcourses = get_string('childcourses');
77 $this->content
->items
[]='<a href="importstudents.php?id='.$this->instance
->pageid
.'">'.$strchildcourses.'</a>';
78 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
79 } else if (has_capability('moodle/role:assign', $context)) {
80 $strchildcourses = get_string('childcourses');
81 $this->content
->items
[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
82 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
87 /// Manage groups in this course
89 if (($course->groupmode ||
!$course->groupmodeforce
) && has_capability('moodle/course:managegroups', $context) && ($course->id
!==SITEID
)) {
90 $strgroups = get_string('groups');
91 $this->content
->items
[]='<a title="'.$strgroups.'" href="'.groups_home_url($this->instance
->pageid
).'">'.$strgroups.'</a>';
92 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/group.gif" class="icon" alt="" />';
95 /// Backup this course
97 if (has_capability('moodle/site:backup', $context)&& ($course->id
!==SITEID
)) {
98 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/backup/backup.php?id='.$this->instance
->pageid
.'">'.get_string('backup').'</a>';
99 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/backup.gif" class="icon" alt="" />';
102 /// Restore to this course
103 if (has_capability('moodle/site:restore', $context) && ($course->id
!==SITEID
)) {
104 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'&wdir=/backupdata">'.get_string('restore').'</a>';
105 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
108 /// Import data from other courses
109 if (has_capability('moodle/site:import', $context) && ($course->id
!==SITEID
)) {
110 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/import.php?id='.$this->instance
->pageid
.'">'.get_string('import').'</a>';
111 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
114 /// Reset this course
115 if (has_capability('moodle/course:reset', $context) && ($course->id
!==SITEID
)) {
116 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/reset.php?id='.$this->instance
->pageid
.'">'.get_string('reset').'</a>';
117 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/return.gif" class="icon" alt="" />';
120 /// View course reports
121 if (has_capability('moodle/site:viewreports', $context) && ($course->id
!==SITEID
)) {
122 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/report.php?id='.$this->instance
->pageid
.'">'.get_string('reports').'</a>';
123 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/stats.gif" class="icon" alt="" />';
127 if (has_capability('moodle/question:manage', $context) && ($course->id
!==SITEID
)) {
128 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/question/edit.php?courseid='.$this->instance
->pageid
.'&clean=true">'.get_string('questions', 'quiz').'</a>';
129 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/questions.gif" class="icon" alt="" />';
133 if (has_capability('moodle/course:managescales', $context) && ($course->id
!==SITEID
)) {
134 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/edit/scale/index.php?id='.$this->instance
->pageid
.'">'.get_string('scales').'</a>';
135 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/scales.gif" class="icon" alt="" />';
140 if (has_capability('moodle/course:managefiles', $context) && ($course->id
!==SITEID
)) {
141 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'">'.get_string('files').'</a>';
142 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/files.gif" class="icon" alt="" />';
146 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize') && ($course->id
!==SITEID
)) {
147 require_once($CFG->dirroot
.'/enrol/authorize/const.php');
148 $paymenturl = '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?course='.$course->id
.'">'.get_string('payments').'</a> ';
149 if (has_capability('enrol/authorize:managepayments', $context)) {
150 if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH
, 'courseid', $course->id
)) {
151 $paymenturl .= '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH
.'&course='.$course->id
.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
154 $this->content
->items
[] = $paymenturl;
155 $this->content
->icons
[] = '<img src="'.$CFG->pixpath
.'/i/payment.gif" class="icon" alt="" />';
158 /// View course grades (or just your own grades, same link)
159 if ((has_capability('moodle/grade:viewall', $context) or
160 (has_capability('moodle/grade:view', $context) && $course->showgrades
)) && ($course->id
!==SITEID
)) {
161 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/report/index.php?id='.$this->instance
->pageid
.'">'.get_string('grades').'</a>';
162 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/grades.gif" class="icon" alt="" />';
165 if (empty($course->metacourse
) && ($course->id
!==SITEID
)) {
166 if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
167 $this->content
->items
[]='<a href="enrol.php?id='.$this->instance
->pageid
.'">'.get_string('enrolme', '', format_string($course->shortname
)).'</a>';
168 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
169 } else if (has_capability('moodle/role:unassignself', $context, NULL, false)) { // Have some role
170 $this->content
->items
[]='<a href="unenrol.php?id='.$this->instance
->pageid
.'">'.get_string('unenrolme', '', format_string($course->shortname
)).'</a>';
171 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
175 /// Should the following two be in this block?
178 /// View own activity report
179 // if ($course->showreports) {
180 // $this->content->items[]='<a href="user.php?id='.$this->instance->pageid.'&user='.$USER->id.'">'.get_string('activityreport').'</a>';
181 // $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/report.gif" alt="" />';
185 /// Edit your own profile
187 // $fullname = fullname($USER, has_capability('moodle/site:viewfullnames', $context));
188 // $editmyprofile = '<a title="'.$fullname.'" href="'.$CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&course='.$this->instance->pageid.'">'.get_string('editmyprofile').'</a>';
189 // if (empty($USER->description)) {
190 // //Accessibility: replace non-standard <blink> with CSS (<a> makes title visible in IE).
191 // $text = get_string('profile').' '.get_string('missingdescription');
192 // $this->content->items[]= $editmyprofile.' <a title="'.$text.'" class="useredit blink">*<span class="accesshide">'.$text.'</span></a>';
194 // $this->content->items[]= $editmyprofile;
196 // $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" alt="" />';
200 return $this->content
;
203 function applicable_formats() {
204 return array('course' => true); // Not needed on site