some quiz capabilities
This commit is contained in:
+3
-2
@@ -358,7 +358,9 @@ function load_user_capability($capability='', $context ='', $userid='') {
|
||||
$usercontexts = get_parent_contexts($context);
|
||||
$listofcontexts = '('.implode(',', $usercontexts).')';
|
||||
} else { // else, we load everything
|
||||
echo $userid;
|
||||
$userroles = get_records('role_assignments','userid',$userid);
|
||||
|
||||
$usercontexts = array();
|
||||
foreach ($userroles as $userrole) {
|
||||
$usercontexts[] = $userrole->contextid;
|
||||
@@ -415,10 +417,9 @@ function load_user_capability($capability='', $context ='', $userid='') {
|
||||
aggregatelevel ASC
|
||||
";
|
||||
|
||||
|
||||
$capabilities = array(); // Reinitialize.
|
||||
$rs = get_recordset_sql($SQL);
|
||||
|
||||
|
||||
if ($rs && $rs->RecordCount() > 0) {
|
||||
while (!$rs->EOF) {
|
||||
$array = $rs->fields;
|
||||
|
||||
+10
-8
@@ -58,9 +58,11 @@
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
$isteacher = isteacher($course->id);
|
||||
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $id); // course context
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
// if no questions have been set up yet redirect to edit.php
|
||||
if (!$quiz->questions and isteacheredit($course->id)) {
|
||||
if (!$quiz->questions and has_capability('mod/quiz:manage', $context) {
|
||||
redirect('edit.php?quizid='.$quiz->id);
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@
|
||||
print_header($course->shortname.': '.format_string($quiz->name), '', '', '', '', false, '', '', false, '');
|
||||
include('protect_js.php');
|
||||
} else {
|
||||
$strupdatemodule = isteacheredit($course->id)
|
||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||
? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz'))
|
||||
: "";
|
||||
print_header_simple(format_string($quiz->name), "",
|
||||
@@ -93,7 +95,7 @@
|
||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
||||
|
||||
/// Print the quiz name heading and tabs for teacher
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:preview', $context)) {
|
||||
$currenttab = 'preview';
|
||||
include('tabs.php');
|
||||
} else {
|
||||
@@ -187,7 +189,7 @@
|
||||
|
||||
/// Load attempt or create a new attempt if there is no unfinished one
|
||||
|
||||
if ($isteacher and $forcenew) { // teacher wants a new preview
|
||||
if (has_capability('mod/quiz:preview', $context) and $forcenew) { // teacher wants a new preview
|
||||
// so we set a finish time on the current attempt (if any).
|
||||
// It will then automatically be deleted below
|
||||
set_field('quiz_attempts', 'timefinish', $timestamp, 'quiz', $quiz->id, 'userid', $USER->id);
|
||||
@@ -200,7 +202,7 @@
|
||||
if (!$attempt) {
|
||||
// Check if this is a preview request from a teacher
|
||||
// in which case the previous previews should be deleted
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:preview', $context) {
|
||||
if ($oldattempts = get_records_select('quiz_attempts', "quiz = '$quiz->id'
|
||||
AND userid = '$USER->id'")) {
|
||||
delete_records('quiz_attempts', 'quiz', $quiz->id, 'userid', $USER->id);
|
||||
@@ -215,7 +217,7 @@
|
||||
// Start a new attempt and initialize the question sessions
|
||||
$attempt = quiz_create_attempt($quiz, $attemptnumber);
|
||||
// If this is an attempt by a teacher mark it as a preview
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:preview', $context)) {
|
||||
$attempt->preview = 1;
|
||||
}
|
||||
// Save the attempt
|
||||
@@ -451,7 +453,7 @@
|
||||
/// Print the quiz page ////////////////////////////////////////////////////////
|
||||
|
||||
/// Print the preview heading
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:preview', $context)) {
|
||||
print_heading(get_string('previewquiz', 'quiz', format_string($quiz->name)));
|
||||
unset($buttonoptions);
|
||||
$buttonoptions['q'] = $quiz->id;
|
||||
|
||||
@@ -30,9 +30,10 @@
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
error('This page is for teachers only');
|
||||
}
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
require_capability('mod/quiz:grade', $context);
|
||||
|
||||
// Load question
|
||||
if (! $question = get_record('question', 'id', $questionid)) {
|
||||
|
||||
+6
-5
@@ -99,12 +99,13 @@ if (self.name == 'editquestion') {
|
||||
if (! $course = get_record("course", "id", $modform->course)) {
|
||||
error("This course doesn't exist");
|
||||
}
|
||||
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $id);
|
||||
|
||||
require_login($course->id, false);
|
||||
|
||||
if (!isteacheredit($course->id)) {
|
||||
error("You can't modify this course!");
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/quiz:manage', $context);
|
||||
|
||||
if (isset($modform->instance)
|
||||
&& empty($modform->grades)) // Construct an array to hold all the grades.
|
||||
@@ -309,7 +310,7 @@ if (self.name == 'editquestion') {
|
||||
|
||||
if (isset($modform->instance) and record_exists_sql("SELECT * FROM {$CFG->prefix}quiz_attempts WHERE quiz = '$modform->instance' AND preview = '0' LIMIT 1")){
|
||||
// one column layout with table of questions used in this quiz
|
||||
$strupdatemodule = isteacheredit($course->id)
|
||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||
? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
||||
: "";
|
||||
print_header_simple($streditingquiz, '',
|
||||
@@ -346,7 +347,7 @@ if (self.name == 'editquestion') {
|
||||
}
|
||||
|
||||
// two column layout with quiz info in left column
|
||||
$strupdatemodule = isteacheredit($course->id)
|
||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||
? update_module_button($modform->cmid, $course->id, get_string('modulename', 'quiz'))
|
||||
: "";
|
||||
print_header_simple($streditingquiz, '',
|
||||
|
||||
+7
-2
@@ -57,7 +57,8 @@
|
||||
$strattempts = get_string("attempts", "quiz");
|
||||
$strusers = $course->students;
|
||||
|
||||
if (isteacher($course->id)) {
|
||||
$context = get_context_instance(CONTEXT_COURSE, $id);
|
||||
if (has_capability('mod/quiz:viewreports', $context)) {
|
||||
$gradecol = $strattempts;
|
||||
} else {
|
||||
$gradecol = $strbestgrade;
|
||||
@@ -80,6 +81,10 @@
|
||||
$currentsection = "";
|
||||
|
||||
foreach ($quizzes as $quiz) {
|
||||
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
|
||||
if (!$quiz->visible) {
|
||||
//Show dimmed if the mod is hidden
|
||||
$link = "<a class=\"dimmed\" href=\"view.php?id=$quiz->coursemodule\">".format_string($quiz->name,true)."</a>";
|
||||
@@ -103,7 +108,7 @@
|
||||
|
||||
$closequiz = $quiz->timeclose ? userdate($quiz->timeclose) : '';
|
||||
|
||||
if (isteacher($course->id)) {
|
||||
if (has_capability('mod/quiz:viewreports', $context)) {
|
||||
if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
|
||||
$a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
|
||||
$a->studentstring = $course->students;
|
||||
|
||||
+3
-5
@@ -36,13 +36,11 @@
|
||||
}
|
||||
|
||||
require_login($course->id, false);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
error("You are not allowed to use this script");
|
||||
}
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
require_capability('mod/quiz:viewre ports', $context);
|
||||
|
||||
// if no questions have been set up yet redirect to edit.php
|
||||
if (!$quiz->questions and isteacheredit($course->id)) {
|
||||
if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
|
||||
redirect('edit.php?quizid='.$quiz->id);
|
||||
}
|
||||
|
||||
|
||||
+7
-4
@@ -37,11 +37,14 @@
|
||||
}
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $id);
|
||||
$isteacher = isteacher($course->id);
|
||||
$options = quiz_get_reviewoptions($quiz, $attempt, $isteacher);
|
||||
$popup = $isteacher ? 0 : $quiz->popup; // Controls whether this is shown in a javascript-protected window.
|
||||
|
||||
if (!$isteacher) {
|
||||
// this capability is not correct, need to find the right one
|
||||
if (!has_capability('mod/quiz:manage', $context)) {
|
||||
if (!$attempt->timefinish) {
|
||||
redirect('attempt.php?q='.$quiz->id);
|
||||
}
|
||||
@@ -90,7 +93,7 @@
|
||||
/// Include Javascript protection for this page
|
||||
include('protect_js.php');
|
||||
} else {
|
||||
$strupdatemodule = isteacheredit($course->id)
|
||||
$strupdatemodule = has_capability('moodle/course:manageactivities', $coursecontext)
|
||||
? update_module_button($cm->id, $course->id, get_string('modulename', 'quiz'))
|
||||
: "";
|
||||
print_header_simple(format_string($quiz->name), "",
|
||||
@@ -101,7 +104,7 @@
|
||||
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>'; // for overlib
|
||||
|
||||
/// Print heading and tabs if this is part of a preview
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:preview', $context)) {
|
||||
if ($attempt->userid == $USER->id) { // this is the report on a preview
|
||||
$currenttab = 'preview';
|
||||
} else {
|
||||
@@ -162,7 +165,7 @@
|
||||
$picture = print_user_picture($student->id, $course->id, $student->picture, false, true);
|
||||
$table->data[] = array($picture, '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$student->id.'&course='.$course->id.'">'.fullname($student, true).'</a>');
|
||||
}
|
||||
if ($isteacher and count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) {
|
||||
if (has_capability('mod/quiz:grade', $context) and count($attempts = get_records_select('quiz_attempts', "quiz = '$quiz->id' AND userid = '$attempt->userid'", 'attempt ASC')) > 1) {
|
||||
// print list of attempts
|
||||
$attemptlist = '';
|
||||
foreach ($attempts as $at) {
|
||||
|
||||
+6
-4
@@ -28,13 +28,15 @@
|
||||
$tabs = array();
|
||||
$row = array();
|
||||
$inactive = array();
|
||||
|
||||
$row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id", get_string('info', 'quiz'));
|
||||
|
||||
if (has_capability('mod/quiz:viewreports', $context)) {
|
||||
$row[] = new tabobject('info', "$CFG->wwwroot/mod/quiz/view.php?q=$quiz->id", get_string('info', 'quiz'));
|
||||
$row[] = new tabobject('reports', "$CFG->wwwroot/mod/quiz/report.php?q=$quiz->id", get_string('results', 'quiz'));
|
||||
}
|
||||
$row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz'));
|
||||
if (has_capability('mod/quiz:manage', $context)) {
|
||||
if (has_capability('mod/quiz:viewreports', $context)) {
|
||||
$row[] = new tabobject('preview', "$CFG->wwwroot/mod/quiz/attempt.php?q=$quiz->id", get_string('preview', 'quiz'));
|
||||
}
|
||||
if (has_capability('mod/quiz:preview', $context)) {
|
||||
$row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", get_string('edit'));
|
||||
}
|
||||
|
||||
|
||||
+14
-27
@@ -35,12 +35,13 @@
|
||||
error("The course module for the quiz with id $q is missing");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
require_login($course->id, false, $cm);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
|
||||
$isteacher = isteacher($course->id);
|
||||
|
||||
// if no questions have been set up yet redirect to edit.php
|
||||
if (!$quiz->questions and isteacheredit($course->id)) {
|
||||
if (!$quiz->questions and has_capability('mod/quiz:manage', $context)) {
|
||||
redirect('edit.php?quizid='.$quiz->id);
|
||||
}
|
||||
|
||||
@@ -80,10 +81,10 @@
|
||||
// Print the main part of the page
|
||||
|
||||
// Print heading and tabs for teacher
|
||||
if ($isteacher) {
|
||||
$currenttab = 'info';
|
||||
include('tabs.php');
|
||||
}
|
||||
|
||||
$currenttab = 'info';
|
||||
include('tabs.php');
|
||||
|
||||
print_heading(format_string($quiz->name));
|
||||
|
||||
if (trim(strip_tags($quiz->intro))) {
|
||||
@@ -110,7 +111,7 @@
|
||||
|
||||
|
||||
// This is all the teacher will get
|
||||
if ($isteacher) {
|
||||
if (has_capability('mod/quiz:manage', $context)) {
|
||||
if ($a->attemptnum = count_records('quiz_attempts', 'quiz', $quiz->id, 'preview', 0)) {
|
||||
$a->studentnum = count_records_select('quiz_attempts', "quiz = '$quiz->id' AND preview = '0'", 'COUNT(DISTINCT userid)');
|
||||
$a->studentstring = $course->students;
|
||||
@@ -123,20 +124,6 @@
|
||||
exit;
|
||||
}
|
||||
|
||||
if (isguest()) {
|
||||
|
||||
$wwwroot = $CFG->wwwroot.'/login/index.php';
|
||||
if (!empty($CFG->loginhttps)) {
|
||||
$wwwroot = str_replace('http:','https:', $wwwroot);
|
||||
}
|
||||
|
||||
notice_yesno(get_string('guestsno', 'quiz').'<br /><br />'.get_string('liketologin'),
|
||||
$wwwroot, $_SERVER['HTTP_REFERER']);
|
||||
print_footer($course);
|
||||
echo '</td></tr></table>';
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
|
||||
$numattempts = count($attempts);
|
||||
} else {
|
||||
@@ -203,7 +190,7 @@
|
||||
if ($attempt->timefinish > 0) { // attempt has finished
|
||||
$timetaken = format_time($attempt->timefinish - $attempt->timestart);
|
||||
$datecompleted = userdate($attempt->timefinish);
|
||||
} else if ($available) { // The student can continue this attempt, so put appropriate link
|
||||
} else if ($available && has_capability('mod/quiz:attempt', $context)) { // The student can continue this attempt, so put appropriate link
|
||||
$timetaken = format_time(time() - $attempt->timestart);
|
||||
$datecompleted = "\n".'<script language="javascript" type="text/javascript">';
|
||||
$datecompleted .= "\n<!--\n"; // -->
|
||||
@@ -319,23 +306,23 @@
|
||||
$lastattempt = $lastattempt_obj->timefinish;
|
||||
}
|
||||
if($numattempts == 1 && $quiz->delay1) {
|
||||
if ($timenow - $quiz->delay1 > $lastattempt) {
|
||||
print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
|
||||
if (($timenow - $quiz->delay1 > $lastattempt) && has_capability('mod/quiz:attempt', $context)) {
|
||||
print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
|
||||
} else {
|
||||
$notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay1). '<b>';
|
||||
print_simple_box($notify_msg, "center");
|
||||
}
|
||||
} else if($numattempts > 1 && $quiz->delay2) {
|
||||
if ($timenow - $quiz->delay2 > $lastattempt) {
|
||||
if (($timenow - $quiz->delay2 > $lastattempt) && has_capability('mod/quiz:attempt', $context)) {
|
||||
print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
|
||||
} else {
|
||||
$notify_msg = get_string('temporaryblocked', 'quiz') . '<b>'. userdate($lastattempt + $quiz->delay2). '<b>';
|
||||
print_simple_box($notify_msg, "center");
|
||||
}
|
||||
} else {
|
||||
} elseif (has_capability('mod/quiz:attempt', $context)) {
|
||||
print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
|
||||
}
|
||||
} else {
|
||||
} elseif (has_capability('mod/quiz:attempt', $context)) {
|
||||
print_start_quiz_button($quiz, $attempts, $numattempts, $unfinished, $cm);
|
||||
}
|
||||
echo "</div>\n";
|
||||
|
||||
@@ -525,7 +525,11 @@ class default_questiontype {
|
||||
|
||||
$comment = stripslashes($state->comment);
|
||||
$commentlink = '';
|
||||
if (isset($options->questioncommentlink)) {
|
||||
|
||||
$cm = get_coursemodule_from_instance('quiz', $quiz->id);
|
||||
$context = get_context_instance(CONTEXT_MODULE, $context);
|
||||
|
||||
if (isset($options->questioncommentlink) && has_capability('mod/quiz:grade', $context)) {
|
||||
$strcomment = get_string('commentorgrade', 'quiz');
|
||||
$commentlink = '<div class="commentlink">'.link_to_popup_window ($options->questioncommentlink.'?attempt='.$state->attempt.'&question='.$question->id,
|
||||
'commentquestion', $strcomment, 450, 650, $strcomment, 'none', true).'</div>';
|
||||
|
||||
Reference in New Issue
Block a user