file SafeEmbed.php was added on branch MOODLE_19_STABLE on 2010-05-21 11:39:45 +0000
[moodle.git] / admin / roles / tabs.php
blobdebafcbc3da2f14f9a74c018f63cdd9942ad2a8f
1 <?php // $Id$
3 // Handles headers and tabs for the roles control at any level apart from SYSTEM level
4 // We also assume that $currenttab, $assignableroles and $overridableroles are defined
6 if (!defined('MOODLE_INTERNAL')) {
7 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
10 $navlinks = array();
11 if ($currenttab != 'update') {
12 switch ($context->contextlevel) {
14 case CONTEXT_SYSTEM:
15 $stradministration = get_string('administration');
16 $navlinks[] = array('name' => $stradministration, 'link' => '../index.php', 'type' => 'misc');
17 $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
18 $navigation = build_navigation($navlinks);
19 print_header($SITE->fullname, "$SITE->fullname", $navigation);
20 break;
22 case CONTEXT_USER:
23 print_header();
24 break;
26 case CONTEXT_COURSECAT:
27 $category = get_record('course_categories', 'id', $context->instanceid);
28 $strcategories = get_string("categories");
29 $strcategory = get_string("category");
30 $strcourses = get_string("courses");
32 $navlinks[] = array('name' => $strcategories,
33 'link' => "$CFG->wwwroot/course/index.php",
34 'type' => 'misc');
35 $navlinks[] = array('name' => $category->name,
36 'link' => "$CFG->wwwroot/course/category.php?id=$category->id",
37 'type' => 'misc');
38 $navlinks[] = array('name' => get_string("roles"),
39 'link' => null,
40 'type' => 'misc');
41 $navigation = build_navigation($navlinks);
43 print_header("$SITE->shortname: $category->name", "$SITE->fullname: $strcourses", $navigation, "", "", true);
44 break;
46 case CONTEXT_COURSE:
47 if ($context->instanceid != SITEID) {
48 $streditcoursesettings = get_string("editcoursesettings");
50 $course = get_record('course', 'id', $context->instanceid);
52 require_login($course);
53 $navlinks[] = array('name' => get_string('roles'),
54 'link' => "$CFG->wwwroot/$CFG->admin/roles/assign.php?contextid=$context->id",
55 'type' => 'misc');
56 $navigation = build_navigation($navlinks);
57 print_header($streditcoursesettings, $course->fullname, $navigation);
59 break;
61 case CONTEXT_MODULE:
62 // get module type?
63 if (!$cm = get_record('course_modules','id',$context->instanceid)) {
64 error('Bad course module ID');
66 if (!$module = get_record('modules','id',$cm->module)) { //$module->name;
67 error('Bad module ID');
69 if (!$course = get_record('course','id',$cm->course)) {
70 error('Bad course ID');
72 if (!$instance = get_record($module->name, 'id', $cm->instance)) {
73 error("The required instance of this module doesn't exist");
76 require_login($course);
78 $fullmodulename = get_string("modulename", $module->name);
79 $streditinga = get_string("editinga", "moodle", $fullmodulename);
80 $strmodulenameplural = get_string("modulenameplural", $module->name);
82 if ($module->name == "label") {
83 $focuscursor = "";
84 } else {
85 $focuscursor = "form.name";
88 $navlinks[] = array('name' => $strmodulenameplural,
89 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id",
90 'type' => 'misc');
92 $navlinks[] = array('name' => $instance->name,
93 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id",
94 'type' => 'misc');
96 $navlinks[] = array('name' => $streditinga,
97 'link' => "$CFG->wwwroot/course/mod.php?update=$cm->id&amp;sesskey=".sesskey(),
98 'type' => 'misc');
100 $navigation = build_navigation($navlinks);
102 print_header_simple($streditinga, '', $navigation, $focuscursor, "", false);
104 break;
106 case CONTEXT_BLOCK:
107 if ($blockinstance = get_record('block_instance', 'id', $context->instanceid)) {
108 if ($block = get_record('block', 'id', $blockinstance->blockid)) {
109 $blockname = print_context_name($context);
112 switch ($blockinstance->pagetype) {
113 case 'course-view':
114 if ($course = get_record('course', 'id', $blockinstance->pageid)) {
116 require_login($course);
118 $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
119 $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
120 $navigation = build_navigation($navlinks);
121 print_header("$straction: $blockname", $course->fullname, $navigation);
123 break;
125 case 'blog-view':
126 $strblogs = get_string('blogs','blog');
127 $navlinks[] = array('name' => $strblogs,
128 'link' => $CFG->wwwroot.'/blog/index.php',
129 'type' => 'misc');
130 $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
131 $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
132 $navigation = build_navigation($navlinks);
133 print_header("$straction: $strblogs", $SITE->fullname, $navigation);
134 break;
136 case 'tag-index':
137 $strtags = get_string('tags');
138 $navlinks[] = array('name' => $strtags,
139 'link' => $CFG->wwwroot.'/tag/index.php',
140 'type' => 'misc');
141 $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
142 $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
143 $navigation = build_navigation($navlinks);
144 print_header("$straction: $strtags", $SITE->fullname, $navigation);
145 break;
147 default:
148 $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
149 $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
150 $navigation = build_navigation($navlinks);
151 print_header("$straction: $blockname", $SITE->fullname, $navigation);
152 break;
156 break;
158 default:
159 error ('This is an unknown context (' . $context->contextlevel . ') in admin/roles/tabs.php!');
160 return false;
166 $toprow = array();
167 $inactive = array();
168 $activetwo = array();
171 if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context
173 if ($context->contextlevel == CONTEXT_MODULE) { // Only show update button if module
175 $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
176 $context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('settings'));
180 if (!empty($assignableroles)) {
181 $toprow[] = new tabobject('assign',
182 $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id,
183 get_string('localroles', 'role'),
184 get_string('showallroles', 'role'),
185 true);
188 if (!empty($overridableroles)) {
189 $toprow[] = new tabobject('override',
190 $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id,
191 get_string('overridepermissions', 'role'),
192 get_string('showallroles', 'role'),
193 true);
198 /// Here other core tabs should go (always calling tabs.php files)
199 /// All the logic to decide what to show must be self-contained in the tabs file
200 /// eg:
201 /// include_once($CFG->dirroot . '/grades/tabs.php');
203 /// Finally, we support adding some 'on-the-fly' tabs here
204 /// All the logic to decide what to show must be self-cointained in the tabs file
205 if (isset($CFG->extratabs) && !empty($CFG->extratabs)) {
206 if ($extratabs = explode(',', $CFG->extratabs)) {
207 asort($extratabs);
208 foreach($extratabs as $extratab) {
209 /// Each extra tab must be one $CFG->dirroot relative file
210 if (file_exists($CFG->dirroot . '/' . $extratab)) {
211 include_once($CFG->dirroot . '/' . $extratab);
217 $inactive[] = $currenttab;
219 $tabs = array($toprow);
221 /// If there are any secondrow defined, let's introduce it
222 if (isset($secondrow) && is_array($secondrow) && !empty($secondrow)) {
223 $tabs[] = $secondrow;
226 print_tabs($tabs, $currenttab, $inactive, $activetwo);