Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / mod / quiz / tabs.php
blob6ae842873b01762dc06eefae8922143e1c16e727
1 <?php // $Id$
2 /**
3 * Sets up the tabs used by the quiz pages based on the users capabilites.
5 * @author Tim Hunt and others.
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
7 * @package quiz
8 */
10 if (empty($quiz)) {
11 error('You cannot call this script in that way');
13 if (!isset($currenttab)) {
14 $currenttab = '';
16 if (!isset($cm)) {
17 $cm = get_coursemodule_from_instance('quiz', $quiz->id);
21 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
23 if (!isset($contexts)){
24 $contexts = new question_edit_contexts($context);
26 $tabs = array();
27 $row = array();
28 $inactive = array();
29 $activated = array();
31 if (has_capability('mod/quiz:view', $context)) {
32 $row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id", get_string('info', 'quiz'));
34 if (has_capability('mod/quiz:viewreports', $context)) {
35 $row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('results', 'quiz'));
37 if (has_capability('mod/quiz:preview', $context)) {
38 $row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz'));
40 if (has_capability('mod/quiz:manage', $context)) {
41 $row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", get_string('edit'));
44 if ($currenttab == 'info' && count($row) == 1) {
45 // Don't show only an info tab (e.g. to students).
46 } else {
47 $tabs[] = $row;
50 if ($currenttab == 'reports' and isset($mode)) {
51 $activated[] = 'reports';
53 // Standard reports we want to show first.
54 $reportlist = array ('overview', 'regrade', 'grading', 'analysis');
55 // Reports that are restricted by capability.
56 $reportrestrictions = array(
57 'regrade' => 'mod/quiz:grade',
58 'grading' => 'mod/quiz:grade'
61 $allreports = get_list_of_plugins("mod/quiz/report");
62 foreach ($allreports as $report) {
63 if (!in_array($report, $reportlist)) {
64 $reportlist[] = $report;
68 $row = array();
69 $currenttab = '';
70 foreach ($reportlist as $report) {
71 if (!isset($reportrestrictions[$report]) || has_capability($reportrestrictions[$report], $context)) {
72 $row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&amp;mode=$report",
73 get_string($report, 'quiz_'.$report));
74 if ($report == $mode) {
75 $currenttab = $report;
79 $tabs[] = $row;
82 if ($currenttab == 'edit' and isset($mode)) {
83 $activated[] = 'edit';
85 $row = array();
86 $currenttab = $mode;
88 $strquiz = get_string('modulename', 'quiz');
89 $streditingquiz = get_string("editinga", "moodle", $strquiz);
91 if (has_capability('mod/quiz:manage', $context) && $contexts->have_one_edit_tab_cap('editq')) {
92 $row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?".$thispageurl->get_query_string(), $strquiz, $streditingquiz);
94 questionbank_navigation_tabs($row, $contexts, $thispageurl->get_query_string());
95 $tabs[] = $row;
99 if (!$quiz->questions) {
100 $inactive += array('info', 'reports', 'preview');
103 print_tabs($tabs, $currenttab, $inactive, $activated);