MDL-11382 added a link 'Profil' to the administration block
[moodle-linuxchix.git] / blocks / admin / block_admin.php
blob7a8614cfce42a03cf0b931a074e90b956aaa8dbb
1 <?php //$Id$
3 class block_admin extends block_list {
4 function init() {
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) {
31 $course = $COURSE;
32 } else {
33 $course = get_record('course', 'id', $this->instance->pageid);
35 } else {
36 $context = get_context_instance(CONTEXT_SYSTEM);
37 $course = $SITE;
40 if (!has_capability('moodle/course:view', $context)) { // Just return
41 return $this->content;
44 if (empty($CFG->loginhttps)) {
45 $securewwwroot = $CFG->wwwroot;
46 } else {
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.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
56 } else {
57 $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;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 and has_capability('moodle/role:assign', $context)) {
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 /// find all accessible reports
74 if ($course->id !== SITEID) {
75 $reportavailable = false;
76 if (has_capability('moodle/grade:viewall', $context)) {
77 $reportavailable = true;
78 } else if (!empty($course->showgrades)) {
79 if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
80 arsort($reports); // user is last, we want to test it first
81 foreach ($reports as $plugin) {
82 if (has_capability('gradereport/'.$plugin.':view', $context)) {
83 //stop when the first visible plugin is found
84 $reportavailable = true;
85 break;
91 if ($reportavailable) {
92 $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
93 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
97 /// Course outcomes (to help give it more prominence because it's important)
98 if (!empty($CFG->enableoutcomes)) {
99 if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
100 $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
101 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
105 /// Manage metacourses
106 if ($course->metacourse) {
107 if (has_capability('moodle/course:managemetacourse', $context)) {
108 $strchildcourses = get_string('childcourses');
109 $this->content->items[]='<a href="importstudents.php?id='.$this->instance->pageid.'">'.$strchildcourses.'</a>';
110 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
111 } else if (has_capability('moodle/role:assign', $context)) {
112 $strchildcourses = get_string('childcourses');
113 $this->content->items[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
114 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
119 /// Manage groups in this course
121 if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
122 $strgroups = get_string('groups');
123 $this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
124 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
127 /// Backup this course
129 if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
130 $this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
131 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
134 /// Restore to this course
135 if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
136 $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
137 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
140 /// Import data from other courses
141 if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
142 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
143 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
146 /// Reset this course
147 if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
148 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
149 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
152 /// View course reports
153 if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) {
154 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
155 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
158 /// Manage questions
159 if ($course->id !== SITEID){
160 $questionlink = '';
161 $questioncaps = array(
162 'moodle/question:add',
163 'moodle/question:editmine',
164 'moodle/question:editall',
165 'moodle/question:viewmine',
166 'moodle/question:viewall',
167 'moodle/question:movemine',
168 'moodle/question:moveall');
169 foreach ($questioncaps as $questioncap){
170 if (has_capability($questioncap, $context)){
171 $questionlink = 'edit.php';
172 break;
175 if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
176 $questionlink = 'category.php';
178 if ($questionlink) {
179 $this->content->items[]='<a href="'.$CFG->wwwroot.'/question/'.$questionlink.
180 '?courseid='.$this->instance->pageid.'">'.get_string('questions', 'quiz').'</a>';
181 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/questions.gif" class="icon" alt="" />';
186 /// Manage files
187 if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
188 $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
189 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt="" />';
192 /// Authorize hooks
193 if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize') && ($course->id!==SITEID)) {
194 require_once($CFG->dirroot.'/enrol/authorize/const.php');
195 $paymenturl = '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?course='.$course->id.'">'.get_string('payments').'</a> ';
196 if (has_capability('enrol/authorize:managepayments', $context)) {
197 if ($cnt = count_records('enrol_authorize', 'status', AN_STATUS_AUTH, 'courseid', $course->id)) {
198 $paymenturl .= '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH.'&amp;course='.$course->id.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
201 $this->content->items[] = $paymenturl;
202 $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/payment.gif" class="icon" alt="" />';
205 /// Unenrol link
206 if (empty($course->metacourse) && ($course->id!==SITEID)) {
207 if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
208 $this->content->items[]='<a href="enrol.php?id='.$this->instance->pageid.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
209 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
210 } else if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id, false)) { // Have some role
211 $this->content->items[]='<a href="unenrol.php?id='.$this->instance->pageid.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
212 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
216 /// Link to the user own profile
217 $this->content->items[]='<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id.'">'.get_string('profile').'</a>';
218 $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