MDL-10092:
[moodle-linuxchix.git] / admin / roles / tabs.php
blob63347c24e522baf005490cc476d074e563bebde8
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_PERSONAL:
23 break;
25 case CONTEXT_USER:
26 print_header();
27 break;
29 case CONTEXT_COURSECAT:
30 $category = get_record('course_categories', 'id', $context->instanceid);
31 $strcategories = get_string("categories");
32 $strcategory = get_string("category");
33 $strcourses = get_string("courses");
35 $navlinks[] = array('name' => $strcategories,
36 'link' => "$CFG->wwwroot/course/index.php",
37 'type' => 'misc');
38 $navlinks[] = array('name' => $category->name,
39 'link' => "$CFG->wwwroot/course/category.php?id=$category->id",
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' => $course->shortname,
54 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
55 'type' => 'misc');
56 $navigation = build_navigation($navlinks);
57 print_header($streditcoursesettings, $course->fullname, $navigation);
59 break;
61 case CONTEXT_GROUP:
62 break;
64 case CONTEXT_MODULE:
65 // get module type?
66 if (!$cm = get_record('course_modules','id',$context->instanceid)) {
67 error('Bad course module ID');
69 if (!$module = get_record('modules','id',$cm->module)) { //$module->name;
70 error('Bad module ID');
72 if (!$course = get_record('course','id',$cm->course)) {
73 error('Bad course ID');
75 if (!$instance = get_record($module->name, 'id', $cm->instance)) {
76 error("The required instance of this module doesn't exist");
79 require_login($course);
81 $fullmodulename = get_string("modulename", $module->name);
82 $streditinga = get_string("editinga", "moodle", $fullmodulename);
83 $strmodulenameplural = get_string("modulenameplural", $module->name);
85 if ($module->name == "label") {
86 $focuscursor = "";
87 } else {
88 $focuscursor = "form.name";
91 $navlinks[] = array('name' => $strmodulenameplural,
92 'link' => "$CFG->wwwroot/mod/$module->name/index.php?id=$course->id",
93 'type' => 'misc');
95 $navlinks[] = array('name' => $instance->name,
96 'link' => "$CFG->wwwroot/mod/$module->name/view.php?id=$cm->id",
97 'type' => 'misc');
99 $navlinks[] = array('name' => $streditinga,
100 'link' => "$CFG->wwwroot/course/mod.php?update=$cm->id&amp;sesskey=".sesskey(),
101 'type' => 'misc');
103 $navigation = build_navigation($navlinks);
105 print_header_simple($streditinga, '', $navigation, $focuscursor, "", false);
107 break;
109 case CONTEXT_BLOCK:
110 if ($blockinstance = get_record('block_instance', 'id', $context->instanceid)) {
111 if ($block = get_record('block', 'id', $blockinstance->blockid)) {
112 $blockname = print_context_name($context);
114 // Prepare the last part of the breadcrumbs first
115 $navlinks[98] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
116 $navlinks[99] = array('name' => $straction, 'link' => null, 'type' => 'misc');
118 switch ($blockinstance->pagetype) {
119 case 'course-view':
120 if ($course = get_record('course', 'id', $blockinstance->pageid)) {
122 require_login($course);
124 if ($course->id != SITEID) {
125 $navlinks[0] = array('name' => $course->shortname,
126 'link' => "$CFG->wwwroot/course/view.php?id=$course->id",
127 'type' => 'misc');
129 $navigation = build_navigation($navlinks);
130 print_header("$straction: $blockname", $course->fullname, $navigation);
132 break;
134 case 'blog-view':
135 $strblogs = get_string('blogs','blog');
136 $navlinks[0] = array('name' => $strblogs,
137 'link' => $CFG->wwwroot.'/blog/index.php',
138 'type' => 'misc');
139 $navigation = build_navigation($navlinks);
140 print_header("$straction: $strblogs", $SITE->fullname, $navigation);
141 break;
143 default:
144 print_header("$straction: $blockname", $SITE->fullname, $navigation);
145 break;
149 break;
151 default:
152 error ('This is an unknown context (' . $context->contextlevel . ') in admin/roles/tabs.php!');
153 return false;
159 if ($context->contextlevel != CONTEXT_SYSTEM) { // Print tabs for anything except SYSTEM context
161 if ($context->contextlevel == CONTEXT_MODULE) { // only show update button if module?
163 $toprow[] = new tabobject('update', $CFG->wwwroot.'/course/mod.php?update='.
164 $context->instanceid.'&amp;return=true&amp;sesskey='.sesskey(), get_string('update'));
168 $toprow[] = new tabobject('roles', $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.
169 $context->id, get_string('roles'));
171 if (!empty($tabsmode)) {
173 if (!empty($assignableroles)) {
174 $secondrow[] = new tabobject('assign',
175 $CFG->wwwroot.'/'.$CFG->admin.'/roles/assign.php?contextid='.$context->id,
176 get_string('assignroles', 'role'),
177 get_string('showallroles', 'role'),
178 true);
181 if (!empty($overridableroles)) {
182 $secondrow[] = new tabobject('override',
183 $CFG->wwwroot.'/'.$CFG->admin.'/roles/override.php?contextid='.$context->id,
184 get_string('overrideroles', 'role'),
185 get_string('showallroles', 'role'),
186 true);
189 $inactive[] = 'roles';
190 $activetwo = array('roles');
191 $currenttab = $tabsmode;
193 } else {
194 $inactive[] = '';
195 $activetwo = array();
198 /// Here other core tabs should go (always calling tabs.php files)
199 /// All the logic to decide what to show must be self-cointained in the tabs file
200 /// ej.:
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 mus be one $CFG->dirroot relative file
210 if (file_exists($CFG->dirroot . '/' . $extratab)) {
211 include_once($CFG->dirroot . '/' . $extratab);
217 if (!empty($secondrow)) {
218 $tabs = array($toprow, $secondrow);
219 } else {
220 $tabs = array($toprow);
223 print_tabs($tabs, $currenttab, $inactive, $activetwo);