2009-11-04 11:58:30 +00:00
|
|
|
<?php
|
2006-02-09 13:57:22 +00:00
|
|
|
/**
|
2007-03-22 11:46:15 +00:00
|
|
|
* Sets up the tabs used by the quiz pages based on the users capabilites.
|
|
|
|
*
|
|
|
|
* @author Tim Hunt and others.
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
|
|
|
|
* @package quiz
|
|
|
|
*/
|
2009-07-21 07:08:08 +00:00
|
|
|
global $DB, $OUTPUT;
|
2007-03-22 11:46:15 +00:00
|
|
|
if (empty($quiz)) {
|
2008-06-27 18:04:48 +00:00
|
|
|
if (empty($attemptobj)) {
|
|
|
|
print_error('cannotcallscript');
|
|
|
|
}
|
|
|
|
$quiz = $attemptobj->get_quiz();
|
2008-07-10 17:23:56 +00:00
|
|
|
$cm = $attemptobj->get_cm();
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
|
|
|
if (!isset($currenttab)) {
|
|
|
|
$currenttab = '';
|
|
|
|
}
|
|
|
|
if (!isset($cm)) {
|
|
|
|
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
|
|
|
}
|
2007-08-09 21:51:09 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2007-08-09 21:51:09 +00:00
|
|
|
if (!isset($contexts)){
|
|
|
|
$contexts = new question_edit_contexts($context);
|
|
|
|
}
|
2007-03-22 11:46:15 +00:00
|
|
|
$tabs = array();
|
|
|
|
$row = array();
|
|
|
|
$inactive = array();
|
|
|
|
$activated = array();
|
2008-11-20 06:59:11 +00:00
|
|
|
$stredit=get_string('edit');
|
2007-03-22 11:46:15 +00:00
|
|
|
if (has_capability('mod/quiz:view', $context)) {
|
2008-07-10 17:23:56 +00:00
|
|
|
$row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?id=$cm->id", get_string('info', 'quiz'));
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
|
|
|
if (has_capability('mod/quiz:viewreports', $context)) {
|
2007-09-04 13:28:50 +00:00
|
|
|
$row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('results', 'quiz'));
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
|
|
|
if (has_capability('mod/quiz:preview', $context)) {
|
2008-11-20 06:59:11 +00:00
|
|
|
$strpreview = get_string('preview', 'quiz');
|
2009-12-16 21:50:45 +00:00
|
|
|
$row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/startattempt.php?cmid=$cm->id&sesskey=" . sesskey(), "<img src=\"" . $OUTPUT->pix_url('t/preview') . "\" class=\"iconsmall\" alt=\"$strpreview\" /> $strpreview", $strpreview);
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
2007-10-23 16:15:46 +00:00
|
|
|
if (has_capability('mod/quiz:manage', $context)) {
|
2009-12-16 21:50:45 +00:00
|
|
|
$row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", "<img src=\"" . $OUTPUT->pix_url('t/edit') . "\" class=\"iconsmall\" alt=\"$stredit\" /> $stredit",$stredit);
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
2010-03-08 16:01:38 +00:00
|
|
|
if (has_capability('mod/quiz:manageoverrides', $context)) {
|
|
|
|
$row[] = new tabobject('overrides', "$CFG->wwwroot/mod/quiz/overrides.php?cmid=$cm->id", get_string('overrides', 'quiz'));
|
|
|
|
}
|
2007-01-26 06:59:16 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
if ($currenttab == 'info' && count($row) == 1) {
|
|
|
|
// Don't show only an info tab (e.g. to students).
|
|
|
|
} else {
|
2008-11-25 12:11:27 +00:00
|
|
|
//$reports is passed in from report.php
|
2007-03-22 11:46:15 +00:00
|
|
|
$tabs[] = $row;
|
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
if ($currenttab == 'reports' and isset($mode)) {
|
|
|
|
$activated[] = 'reports';
|
2007-09-04 13:28:50 +00:00
|
|
|
|
2005-05-06 06:24:04 +00:00
|
|
|
|
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
$row = array();
|
|
|
|
$currenttab = '';
|
2008-11-25 12:11:27 +00:00
|
|
|
|
|
|
|
$reportlist = quiz_report_list($context);
|
2009-11-04 11:58:30 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
foreach ($reportlist as $report) {
|
2008-11-25 12:11:27 +00:00
|
|
|
$row[] = new tabobject($report, "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id&mode=$report",
|
|
|
|
get_string($report, 'quiz_'.$report));
|
|
|
|
if ($report == $mode) {
|
|
|
|
$currenttab = $report;
|
2005-05-06 06:24:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-22 11:46:15 +00:00
|
|
|
$tabs[] = $row;
|
|
|
|
}
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
if ($currenttab == 'edit' and isset($mode)) {
|
|
|
|
$activated[] = 'edit';
|
2006-02-09 13:57:22 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
$row = array();
|
|
|
|
$currenttab = $mode;
|
2006-03-01 09:30:21 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
$strquiz = get_string('modulename', 'quiz');
|
|
|
|
$streditingquiz = get_string("editinga", "moodle", $strquiz);
|
2007-09-04 13:28:50 +00:00
|
|
|
|
2007-10-23 16:15:46 +00:00
|
|
|
if (has_capability('mod/quiz:manage', $context) && $contexts->have_one_edit_tab_cap('editq')) {
|
2008-11-20 06:59:11 +00:00
|
|
|
$row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?cmid=$cm->id", $stredit, $streditingquiz);
|
|
|
|
$row[] = new tabobject('reorder', "$CFG->wwwroot/mod/quiz/edit.php?reordertool=1&cmid=$cm->id", get_string('orderandpaging','quiz'), $streditingquiz);
|
2007-08-09 21:51:09 +00:00
|
|
|
}
|
2010-01-17 10:54:13 +00:00
|
|
|
//questionbank_navigation_tabs($row, $contexts, $thispageurl->params());
|
2007-03-22 11:46:15 +00:00
|
|
|
$tabs[] = $row;
|
2007-09-04 13:28:50 +00:00
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
}
|
2006-02-09 13:57:22 +00:00
|
|
|
|
2010-03-08 16:01:38 +00:00
|
|
|
if ($currenttab == 'overrides' and isset($mode)) {
|
|
|
|
$activated[] = 'overrides';
|
|
|
|
|
|
|
|
$row = array();
|
|
|
|
$currenttab = $mode;
|
|
|
|
|
|
|
|
$strgroup = get_string('groupoverrides', 'quiz');
|
2010-05-10 22:15:17 +00:00
|
|
|
if (empty($groups)) {
|
|
|
|
$inactive[] = 'group';
|
|
|
|
}
|
2010-03-08 16:01:38 +00:00
|
|
|
$struser = get_string('useroverrides', 'quiz');
|
|
|
|
|
2010-05-10 22:15:17 +00:00
|
|
|
$row[] = new tabobject('group', "$CFG->wwwroot/mod/quiz/overrides.php?cmid=$cm->id&mode=group", $strgroup);
|
2010-03-08 16:01:38 +00:00
|
|
|
$row[] = new tabobject('user', "$CFG->wwwroot/mod/quiz/overrides.php?cmid=$cm->id&mode=user", $struser);
|
|
|
|
$tabs[] = $row;
|
2010-05-10 22:15:17 +00:00
|
|
|
|
2010-03-08 16:01:38 +00:00
|
|
|
}
|
|
|
|
|
2008-04-22 15:19:50 +00:00
|
|
|
if (!$quiz->questions) {
|
|
|
|
$inactive += array('info', 'reports', 'preview');
|
|
|
|
}
|
|
|
|
|
2007-03-22 11:46:15 +00:00
|
|
|
print_tabs($tabs, $currenttab, $inactive, $activated);
|
2005-05-06 06:24:04 +00:00
|
|
|
|
2009-11-04 11:58:30 +00:00
|
|
|
|