moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[moodle.git] / blocks / admin / block_admin.php
CommitLineData
d99ceac2 1<?php //$Id$
0f3fe4b6 2
3ef642d9 3class block_admin extends block_list {
9b4b78fd 4 function init() {
0f3fe4b6 5 $this->title = get_string('administration');
433c242f 6 $this->version = 2007101509;
0f3fe4b6 7 }
89adb174 8
0f3fe4b6 9 function get_content() {
0f3fe4b6 10
830dd6e9 11 global $CFG, $USER, $SITE, $COURSE, $DB, $PAGE;
b649a19e 12
13 if ($this->content !== NULL) {
0f3fe4b6 14 return $this->content;
15 }
16
9b4b78fd 17 $this->content = new stdClass;
0f3fe4b6 18 $this->content->items = array();
19 $this->content->icons = array();
20 $this->content->footer = '';
21
ee1efe0b 22 if (empty($this->instance->pageid)) { // sticky
23 if (!empty($COURSE)) {
24 $this->instance->pageid = $COURSE->id;
25 }
26 }
27
9b4b78fd 28 if (empty($this->instance)) {
b649a19e 29 return $this->content = '';
9b4b78fd 30 } else if ($this->instance->pageid == SITEID) {
7cf0769e 31 // return $this->content = '';
89adb174 32 }
33
d4484f32 34 if (!empty($this->instance->pageid)) {
35 $context = get_context_instance(CONTEXT_COURSE, $this->instance->pageid);
b571c6b3 36 if ($COURSE->id == $this->instance->pageid) {
37 $course = $COURSE;
38 } else {
f33e1ed4 39 $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
b571c6b3 40 }
41 } else {
d4484f32 42 $context = get_context_instance(CONTEXT_SYSTEM);
d4484f32 43 $course = $SITE;
44 }
a1931e61 45
b030054c 46 if (!has_capability('moodle/course:view', $context)) { // Just return
0f3fe4b6 47 return $this->content;
48 }
49
b649a19e 50 if (empty($CFG->loginhttps)) {
70efd568 51 $securewwwroot = $CFG->wwwroot;
52 } else {
53 $securewwwroot = str_replace('http:','https:',$CFG->wwwroot);
54 }
55
b649a19e 56 /// Course editing on/off
0f3fe4b6 57
dd97c328 58 if ($course->id !== SITEID and has_capability('moodle/course:update', $context)) {
440d1648 59 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/edit.gif" class="icon" alt="" />';
830dd6e9 60 if ($PAGE->user_is_editing()) {
b649a19e 61 $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=off&amp;sesskey='.sesskey().'">'.get_string('turneditingoff').'</a>';
cf0b6604 62 } else {
b649a19e 63 $this->content->items[]='<a href="view.php?id='.$this->instance->pageid.'&amp;edit=on&amp;sesskey='.sesskey().'">'.get_string('turneditingon').'</a>';
cf0b6604 64 }
b030054c 65
c517c8f7 66 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/edit.php?id='.$this->instance->pageid.'">'.get_string('settings').'</a>';
440d1648 67 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/settings.gif" class="icon" alt="" />';
b649a19e 68 }
b030054c 69
b649a19e 70 /// Assign roles to the course
71
3a0c6cca 72 if ($course->id != SITEID) {
73 if (has_capability('moodle/role:assign', $context)) {
74 $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id.'">'.get_string('assignroles', 'role').'</a>';
75 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
96f1a7a2 76 } else if (get_overridable_roles($context, ROLENAME_ORIGINAL)) {
3a0c6cca 77 $this->content->items[]='<a href="'.$CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id.'">'.get_string('overridepermissions', 'role').'</a>';
78 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/roles.gif" class="icon" alt="" />';
79 }
a7a54c3b 80 }
81
60e25927 82 /// View course grades (or just your own grades, same link)
9ce2fe53 83 /// find all accessible reports
dd97c328 84 if ($course->id !== SITEID) {
85 $reportavailable = false;
1ee0c983 86 if (has_capability('moodle/grade:viewall', $context)) {
87 $reportavailable = true;
88 } else if (!empty($course->showgrades)) {
f1401c24 89 if ($reports = get_list_of_plugins('grade/report')) { // Get all installed reports
90 arsort($reports); // user is last, we want to test it first
91 foreach ($reports as $plugin) {
92 if (has_capability('gradereport/'.$plugin.':view', $context)) {
1ee0c983 93 //stop when the first visible plugin is found
f1401c24 94 $reportavailable = true;
95 break;
96 }
9ce2fe53 97 }
98 }
99 }
100
dd97c328 101 if ($reportavailable) {
9ce2fe53 102 $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/report/index.php?id='.$this->instance->pageid.'">'.get_string('grades').'</a>';
103 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/grades.gif" class="icon" alt="" />';
104 }
60e25927 105 }
106
1966aa49 107 /// Course outcomes (to help give it more prominence because it's important)
8bdd8660 108 if (!empty($CFG->enableoutcomes)) {
dd97c328 109 if ($course->id!==SITEID and has_capability('moodle/course:update', $context)) {
8bdd8660 110 $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/outcome/course.php?id='.$this->instance->pageid.'">'.get_string('outcomes', 'grades').'</a>';
111 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="" />';
112 }
113 }
1966aa49 114
a7a54c3b 115 /// Manage metacourses
116 if ($course->metacourse) {
b030054c 117 if (has_capability('moodle/course:managemetacourse', $context)) {
bbbf2d40 118 $strchildcourses = get_string('childcourses');
119 $this->content->items[]='<a href="importstudents.php?id='.$this->instance->pageid.'">'.$strchildcourses.'</a>';
440d1648 120 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
a7a54c3b 121 } else if (has_capability('moodle/role:assign', $context)) {
122 $strchildcourses = get_string('childcourses');
123 $this->content->items[]='<span class="dimmed_text">'.$strchildcourses.'</span>';
440d1648 124 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/course.gif" class="icon" alt="" />';
84bb3c12 125 }
b649a19e 126 }
0f3fe4b6 127
bbbf2d40 128
b649a19e 129 /// Manage groups in this course
130
dd97c328 131 if (($course->id!==SITEID) && ($course->groupmode || !$course->groupmodeforce) && has_capability('moodle/course:managegroups', $context)) {
b649a19e 132 $strgroups = get_string('groups');
13534ef7 133 $this->content->items[]='<a title="'.$strgroups.'" href="'.$CFG->wwwroot.'/group/index.php?id='.$this->instance->pageid.'">'.$strgroups.'</a>';
440d1648 134 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/group.gif" class="icon" alt="" />';
b649a19e 135 }
136
137 /// Backup this course
138
dd97c328 139 if ($course->id!==SITEID and has_capability('moodle/site:backup', $context)) {
b649a19e 140 $this->content->items[]='<a href="'.$CFG->wwwroot.'/backup/backup.php?id='.$this->instance->pageid.'">'.get_string('backup').'</a>';
440d1648 141 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/backup.gif" class="icon" alt="" />';
b649a19e 142 }
b030054c 143
b649a19e 144 /// Restore to this course
dd97c328 145 if ($course->id !== SITEID and has_capability('moodle/site:restore', $context)) {
b649a19e 146 $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'&amp;wdir=/backupdata">'.get_string('restore').'</a>';
440d1648 147 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
b649a19e 148 }
b030054c 149
b649a19e 150 /// Import data from other courses
dd97c328 151 if ($course->id !== SITEID and has_capability('moodle/site:import', $context)) {
b649a19e 152 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/import.php?id='.$this->instance->pageid.'">'.get_string('import').'</a>';
440d1648 153 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/restore.gif" class="icon" alt="" />';
b649a19e 154 }
b030054c 155
b649a19e 156 /// Reset this course
dd97c328 157 if ($course->id!==SITEID and has_capability('moodle/course:reset', $context)) {
b649a19e 158 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/reset.php?id='.$this->instance->pageid.'">'.get_string('reset').'</a>';
440d1648 159 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/return.gif" class="icon" alt="" />';
b649a19e 160 }
b030054c 161
b649a19e 162 /// View course reports
a2e4bf7f 163 if ($course->id !== SITEID and has_capability('moodle/site:viewreports', $context)) { // basic capability for listing of reports
b649a19e 164 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/report.php?id='.$this->instance->pageid.'">'.get_string('reports').'</a>';
440d1648 165 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/stats.gif" class="icon" alt="" />';
b649a19e 166 }
b030054c 167
b649a19e 168 /// Manage questions
dd97c328 169 if ($course->id !== SITEID){
e5a3a517 170 $questionlink = '';
8bdd8660 171 $questioncaps = array(
172 'moodle/question:add',
173 'moodle/question:editmine',
174 'moodle/question:editall',
175 'moodle/question:viewmine',
176 'moodle/question:viewall',
177 'moodle/question:movemine',
178 'moodle/question:moveall');
8bdd8660 179 foreach ($questioncaps as $questioncap){
180 if (has_capability($questioncap, $context)){
e5a3a517 181 $questionlink = 'edit.php';
8bdd8660 182 break;
183 }
184 }
e5a3a517 185 if (!$questionlink && has_capability('moodle/question:managecategory', $context)) {
186 $questionlink = 'category.php';
187 }
188 if ($questionlink) {
189 $this->content->items[]='<a href="'.$CFG->wwwroot.'/question/'.$questionlink.
190 '?courseid='.$this->instance->pageid.'">'.get_string('questions', 'quiz').'</a>';
8bdd8660 191 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/questions.gif" class="icon" alt="" />';
192 }
b649a19e 193 }
0f3fe4b6 194
faaa613d 195 /// Repository Instances
f48fb4d6 196 require_once($CFG->dirroot.'/repository/lib.php');
dbc01944 197 $editabletypes = repository::get_editable_types($context);
f48fb4d6 198 if ($course->id !== SITEID && has_capability('moodle/course:update', $context) && !empty($editabletypes)) {
faaa613d 199 $this->content->items[]='<a href="'.$CFG->wwwroot.'/repository/manage_instances.php?contextid='.$context->id.'">'.get_string('repositories').'</a>';
a6600395 200 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/repository.png" alt=""/>';
201 }
0f3fe4b6 202
b649a19e 203 /// Manage files
dd97c328 204 if ($course->id !== SITEID and has_capability('moodle/course:managefiles', $context)) {
b649a19e 205 $this->content->items[]='<a href="'.$CFG->wwwroot.'/files/index.php?id='.$this->instance->pageid.'">'.get_string('files').'</a>';
a6600395 206 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/files.gif" class="icon" alt=""/>';
b649a19e 207 }
208
209 /// Authorize hooks
7cf0769e 210 if ($course->enrol == 'authorize' || (empty($course->enrol) && $CFG->enrol == 'authorize') && ($course->id!==SITEID)) {
bd4128e9 211 require_once($CFG->dirroot.'/enrol/authorize/const.php');
212 $paymenturl = '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?course='.$course->id.'">'.get_string('payments').'</a> ';
f440589b 213 if (has_capability('enrol/authorize:managepayments', $context)) {
c7da4357 214 if ($cnt = $DB->count_records('enrol_authorize', array('status'=>AN_STATUS_AUTH, 'courseid'=>$course->id))) {
f440589b 215 $paymenturl .= '<a href="'.$CFG->wwwroot.'/enrol/authorize/index.php?status='.AN_STATUS_AUTH.'&amp;course='.$course->id.'">'.get_string('paymentpending', 'moodle', $cnt).'</a>';
216 }
d70fd561 217 }
bd4128e9 218 $this->content->items[] = $paymenturl;
440d1648 219 $this->content->icons[] = '<img src="'.$CFG->pixpath.'/i/payment.gif" class="icon" alt="" />';
b649a19e 220 }
d70fd561 221
60e25927 222 /// Unenrol link
7cf0769e 223 if (empty($course->metacourse) && ($course->id!==SITEID)) {
bd4128e9 224 if (has_capability('moodle/legacy:guest', $context, NULL, false)) { // Are a guest now
cf743008 225 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/enrol.php?id='.$this->instance->pageid.'">'.get_string('enrolme', '', format_string($course->shortname)).'</a>';
440d1648 226 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
76b570d6 227 } else if (has_capability('moodle/role:unassignself', $context, NULL, false) and get_user_roles($context, $USER->id, false)) { // Have some role
cf743008 228 $this->content->items[]='<a href="'.$CFG->wwwroot.'/course/unenrol.php?id='.$this->instance->pageid.'">'.get_string('unenrolme', '', format_string($course->shortname)).'</a>';
440d1648 229 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" class="icon" alt="" />';
bd4128e9 230 }
b649a19e 231 }
0f3fe4b6 232
d927c5b4 233 /// Link to the user own profile (except guests)
234 if (!isguestuser() and isloggedin()) {
235 $this->content->items[]='<a href="'.$CFG->wwwroot.'/user/view.php?id='.$USER->id.'&amp;course='.$course->id.'">'.get_string('profile').'</a>';
236 $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/user.gif" alt="" />';
237 }
b649a19e 238
239 return $this->content;
0f3fe4b6 240 }
0d6b9d4f 241
242 function applicable_formats() {
052ba1f5 243 return array('course' => true); // Not needed on site
0d6b9d4f 244 }
0f3fe4b6 245}
246
0f3fe4b6 247?>