some capabilities for quiz and questions, need to load them in access.php

This commit is contained in:
toyomoyo 2006-08-21 08:40:06 +00:00
parent f0da6b858e
commit 3765fd5367
5 changed files with 63 additions and 36 deletions

View File

@ -22,6 +22,7 @@
$course = get_record('course', 'id', $quiz->course);
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
//print_heading(format_string($quiz->name));
$tabs = array();
@ -29,9 +30,11 @@
$inactive = array();
$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'));
if (has_capability('mod/quiz:viewreports', $context)) {
$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 (isteacheredit($course->id)) {
if (has_capability('mod/quiz:manage', $context)) {
$row[] = new tabobject('edit', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", get_string('edit'));
}
@ -72,11 +75,22 @@
$streditingquiz = get_string("editinga", "moodle", $strquiz);
$strupdate = get_string('updatethis', 'moodle', $strquiz);
$row[] = new tabobject('editq', "$CFG->wwwroot/mod/quiz/edit.php?quizid=$quiz->id", $strquiz, $streditingquiz);
$row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$course->id", get_string('questions', 'quiz'), $streditingquestions);
$row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz'));
$row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz'));
$row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz'));
if (has_capability('moodle/question:manage', $context)) {
$row[] = new tabobject('questions', "$CFG->wwwroot/question/edit.php?courseid=$course->id", get_string('questions', 'quiz'), $streditingquestions);
}
if (has_capability('moodle/question:managecategory', $context)) {
$row[] = new tabobject('categories', "$CFG->wwwroot/question/category.php?id=$course->id", get_string('categories', 'quiz'), get_string('editqcats', 'quiz'));
}
if (has_capability('moodle/question:import', $context)) {
$row[] = new tabobject('import', "$CFG->wwwroot/question/import.php?course=$course->id", get_string('import', 'quiz'), get_string('importquestions', 'quiz'));
}
if (has_capability('moodle/question:export', $context)) {
$row[] = new tabobject('export', "$CFG->wwwroot/question/export.php?courseid=$course->id", get_string('export', 'quiz'), get_string('exportquestions', 'quiz'));
}
$tabs[] = $row;
}

View File

@ -33,12 +33,11 @@
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
$context = get_context_instance(CONTEXT_COURSE, $id);
require_login($course->id, false);
if (!isteacheredit($course->id)) {
error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
}
require_capability('moodle/question:managecategory', $context);
$qcobject = new question_category_object();
$qcobject->set_course($course);

View File

@ -27,13 +27,9 @@
if (! $course = get_record("course", "id", $courseid)) {
error("This course doesn't exist");
}
$context = get_context_instance(CONTEXT_COURSE, $courseid);
require_login($course->id, false);
if (!isteacheredit($course->id)) {
error("You can't modify this course!");
}
$SESSION->returnurl = $FULLME;
// Print basic page layout.

View File

@ -208,6 +208,8 @@ function question_category_form($course, $current, $recurse=1, $showhidden=false
function question_list($course, $categoryid, $quizid=0,
$recurse=1, $page=0, $perpage=100, $showhidden=false, $sortorder='qtype, name ASC') {
global $QTYPE_MENU, $USER, $CFG;
$context = get_context_instance(CONTEXT_COURSE, $course->id);
$qtypemenu = $QTYPE_MENU;
if ($rqp_types = get_records('question_rqp_types')) {
@ -277,13 +279,17 @@ function question_list($course, $categoryid, $quizid=0,
}
echo '<tr><td colspan="3" align="right"><font size="2">';
if (isteacheredit($category->course)) {
if (has_capability('moodle/question:import', $context)) {
echo '<a href="'.$CFG->wwwroot.'/question/import.php?category='.$category->id.'">'.$strimportquestions.'</a>';
helpbutton("import", $strimportquestions, "quiz");
echo ' | ';
}
echo "<a href=\"$CFG->wwwroot/question/export.php?category={$category->id}&amp;courseid={$course->id}\">$strexportquestions</a>";
helpbutton("export", $strexportquestions, "quiz");
if (has_capability('moodle/question:import', $context)) {
echo "<a href=\"$CFG->wwwroot/question/export.php?category={$category->id}&amp;courseid={$course->id}\">$strexportquestions</a>";
helpbutton("export", $strexportquestions, "quiz");
}
echo '</font></td></tr>';
echo '</table>';
@ -336,14 +342,20 @@ function question_list($course, $categoryid, $quizid=0,
echo "</tr>\n";
foreach ($questions as $question) {
echo "<tr>\n<td nowrap=\"nowrap\">\n";
if ($quizid) {
// add to quiz
if ($quizid && has_capability('mod/quiz:manage', $context)) {
echo "<a title=\"$straddtoquiz\" href=\"edit.php?addquestion=$question->id&amp;quizid=$quizid&amp;sesskey=$USER->sesskey\"><img
src=\"$CFG->pixpath/t/moveleft.gif\" border=\"0\" alt=\"$straddtoquiz\" /></a>&nbsp;";
}
// preview
echo "<a title=\"$strpreview\" href=\"javascript:void();\" onClick=\"openpopup('/question/preview.php?id=$question->id&quizid=$quizid','$strpreview', " .
QUESTION_PREVIEW_POPUP_OPTIONS . ", false)\"><img
src=\"$CFG->pixpath/t/preview.gif\" border=\"0\" alt=\"$strpreview\" /></a>&nbsp;";
if ($canedit) {
// edit, hide, delete question, using question capabilities, not quiz capabilieies
if (has_capability('moodle/question:manage', $context)) {
echo "<a title=\"$stredit\" href=\"$CFG->wwwroot/question/question.php?id=$question->id\"><img
src=\"$CFG->pixpath/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a>&nbsp;";
// hide-feature
@ -384,18 +396,20 @@ function question_list($course, $categoryid, $quizid=0,
echo '<a href="javascript:select_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectall.'</a> /'.
' <a href="javascript:deselect_all_in(\'TABLE\', null, \'categoryquestions\');">'.$strselectnone.'</a>'.
'</td><td align="right"><b>&nbsp;'.get_string('withselected', 'quiz').':</b></td></tr><tr><td>';
if ($quizid) {
if ($quizid && has_capability('mod/quiz:manage', $context)) {
echo "<input type=\"submit\" name=\"add\" value=\"<< $straddtoquiz\" />\n";
echo '</td><td>';
}
if ($canedit) {
// print delete and move selected question
if (has_capability('moodle/question:manage', $context)) {
echo '<input type="submit" name="deleteselected" value="'.$strdelete."\" /></td><td>\n";
echo '<input type="submit" name="move" value="'.get_string('moveto', 'quiz')."\" />\n";
question_category_select_menu($course->id, false, true, $category->id);
}
echo "</td></tr></table>";
if ($quizid) {
// add random question
if ($quizid && has_capability('mod/quiz:manage', $context)) {
for ($i=1;$i<=10; $i++) {
$randomcount[$i] = $i;
}

View File

@ -163,15 +163,19 @@ if (empty($SESSION->questioncat) or !count_records_select("question_categories",
}
// starts with category selection form
print_simple_box_start("center", "100%");
question_category_form($course, $SESSION->questioncat, $SESSION->questionrecurse, $SESSION->questionshowhidden);
print_simple_box_end();
print_spacer(5,1);
// continues with list of questions
print_simple_box_start("center", "100%");
question_list($course, $SESSION->questioncat, isset($modform->instance) ? $modform->instance : 0, $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder);
print_simple_box_end();
if (has_capability('moodle:question/managecategories', $context)) {
print_simple_box_start("center", "100%");
question_category_form($course, $SESSION->questioncat, $SESSION->questionrecurse, $SESSION->questionshowhidden);
print_simple_box_end();
print_spacer(5,1);
}
if (has_capability('moodle:question/manage', $context)) {
// continues with list of questions
print_simple_box_start("center", "100%");
question_list($course, $SESSION->questioncat, isset($modform->instance) ? $modform->instance : 0, $SESSION->questionrecurse, $page, $perpage, $SESSION->questionshowhidden, $sortorder);
print_simple_box_end();
}
?>