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, $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 (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="" />';
64 /// Assign roles to the course
66 if (has_capability('moodle/role:assign', $context) && ($course->id
!==SITEID
)) {
67 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/roles/assign.php?contextid='.$context->id
.'">'.get_string('assignroles', 'role').'</a>';
68 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/roles.gif" class="icon" alt="" />';
72 /// View course grades (or just your own grades, same link)
73 if ((has_capability('moodle/grade:viewall', $context) or
74 (has_capability('moodle/grade:view', $context) && $course->showgrades
)) && ($course->id
!==SITEID
)) {
75 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/report/index.php?id='.$this->instance
->pageid
.'">'.get_string('grades').'</a>';
76 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/grades.gif" class="icon" alt="" />';
79 /// Course outcomes (to help give it more prominence because it's important)
80 if (!empty($CFG->enableoutcomes
)) {
81 if (has_capability('moodle/course:update', $context) && ($course->id
!==SITEID
)) {
82 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/grade/edit/outcome/course.php?id='.$this->instance
->pageid
.'">'.get_string('outcomes', 'grades').'</a>';
83 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/outcomes.gif" class="icon" alt="" />';
87 /// Manage metacourses
88 if ($course->metacourse
) {
89 if (has_capability('moodle/course:managemetacourse', $context)) {
90 $strchildcourses = get_string('childcourses');
91 $this->content
->items
[]='<a href="importstudents.php?id='.$this->instance
->pageid
.'">'.$strchildcourses.'</a>';
92 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
93 } else if (has_capability('moodle/role:assign', $context)) {
94 $strchildcourses = get_string('childcourses');
95 $this->content
->items
[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
96 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/course.gif" class="icon" alt="" />';
101 /// Manage groups in this course
103 if (($course->groupmode ||
!$course->groupmodeforce
) && has_capability('moodle/course:managegroups', $context) && ($course->id
!==SITEID
)) {
104 $strgroups = get_string('groups');
105 $this->content
->items
[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot
.'/group/index.php?id='.$this->instance
->pageid
.'">'.$strgroups.'</a>';
106 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/group.gif" class="icon" alt="" />';
109 /// Backup this course
111 if (has_capability('moodle/site:backup', $context)&& ($course->id
!==SITEID
)) {
112 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/backup/backup.php?id='.$this->instance
->pageid
.'">'.get_string('backup').'</a>';
113 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/backup.gif" class="icon" alt="" />';
116 /// Restore to this course
117 if (has_capability('moodle/site:restore', $context) && ($course->id
!==SITEID
)) {
118 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'&wdir=/backupdata">'.get_string('restore').'</a>';
119 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
122 /// Import data from other courses
123 if (has_capability('moodle/site:import', $context) && ($course->id
!==SITEID
)) {
124 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/import.php?id='.$this->instance
->pageid
.'">'.get_string('import').'</a>';
125 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/restore.gif" class="icon" alt="" />';
128 /// Reset this course
129 if (has_capability('moodle/course:reset', $context) && ($course->id
!==SITEID
)) {
130 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/reset.php?id='.$this->instance
->pageid
.'">'.get_string('reset').'</a>';
131 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/return.gif" class="icon" alt="" />';
134 /// View course reports
135 if (has_capability('moodle/site:viewreports', $context) && ($course->id
!==SITEID
)) {
136 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/course/report.php?id='.$this->instance
->pageid
.'">'.get_string('reports').'</a>';
137 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/stats.gif" class="icon" alt="" />';
141 if ($course->id
!==SITEID
){
142 $questioncaps = array(
143 'moodle/question:add',
144 'moodle/question:editmine',
145 'moodle/question:editall',
146 'moodle/question:viewmine',
147 'moodle/question:viewall',
148 'moodle/question:movemine',
149 'moodle/question:moveall');
150 $questionpermission = false;
151 foreach ($questioncaps as $questioncap){
152 if (has_capability($questioncap, $context)){
153 $questionpermission = true;
157 if ($questionpermission) {
158 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/question/edit.php?courseid='.$this->instance
->pageid
.'">'.get_string('questions', 'quiz').'</a>';
159 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/questions.gif" class="icon" alt="" />';
165 if (has_capability('moodle/course:managefiles', $context) && ($course->id
!==SITEID
)) {
166 $this->content
->items
[]='<a href="'.$CFG->wwwroot
.'/files/index.php?id='.$this->instance
->pageid
.'">'.get_string('files').'</a>';
167 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/files.gif" class="icon" alt="" />';
171 if ($course->enrol
== 'authorize' ||
(empty($course->enrol
) && $CFG->enrol
== 'authorize') && ($course->id
!==SITEID
)) {
172 require_once($CFG->dirroot
.'/enrol/authorize/const.php');
173 $paymenturl = '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?course='.$course->id
.'">'.get_string('payments').'</a> ';
174 if (has_capability('enrol/authorize:managepayments', $context)) {
175 if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH
, 'courseid', $course->id
)) {
176 $paymenturl .= '<a href="'.$CFG->wwwroot
.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH
.'&course='.$course->id
.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
179 $this->content
->items
[] = $paymenturl;
180 $this->content
->icons
[] = '<img src="'.$CFG->pixpath
.'/i/payment.gif" class="icon" alt="" />';
184 if (empty($course->metacourse
) && ($course->id
!==SITEID
)) {
185 if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
186 $this->content
->items
[]='<a href="enrol.php?id='.$this->instance
->pageid
.'">'.get_string('enrolme', '', format_string($course->shortname
)).'</a>';
187 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
188 } else if (has_capability('moodle/role:unassignself', $context, NULL, false)) { // Have some role
189 $this->content
->items
[]='<a href="unenrol.php?id='.$this->instance
->pageid
.'">'.get_string('unenrolme', '', format_string($course->shortname
)).'</a>';
190 $this->content
->icons
[]='<img src="'.$CFG->pixpath
.'/i/user.gif" class="icon" alt="" />';
195 /// Should the following two be in this block?
198 /// View own activity report
199 // if ($course->showreports) {
200 // $this->content->items[]='<a href="user.php?id='.$this->instance->pageid.'&user='.$USER->id.'">'.get_string('activityreport').'</a>';
201 // $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/report.gif" alt="" />';
205 /// Edit your own profile
207 // $fullname = fullname($USER, has_capability('moodle/site:viewfullnames', $context));
208 // $editmyprofile = '<a title="'.$fullname.'" href="'.$CFG->wwwroot.'/user/edit.php?id='.$USER->id.'&course='.$this->instance->pageid.'">'.get_string('editmyprofile').'</a>';
209 // if (empty($USER->description)) {
210 // //Accessibility: replace non-standard <blink> with CSS (<a> makes title visible in IE).
211 // $text = get_string('profile').' '.get_string('missingdescription');
212 // $this->content->items[]= $editmyprofile.' <a title="'.$text.'" class="useredit blink">*<span class="accesshide">'.$text.'</span></a>';
214 // $this->content->items[]= $editmyprofile;
216 // $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" alt="" />';
220 return $this->content
;
223 function applicable_formats() {
224 return array('course' => true); // Not needed on site