if (empty($to)) {
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
} else {
- if (!isteacheredit($to)) {
+ if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
}
}
print_heading(get_string("choosecourse"));
print_simple_box_start("center");
foreach ($courses as $course) {
- if (!isteacheredit($course->id)) {
+ if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $course->id))) {
continue;
}
if (empty($course->visible)) {
//Final access control check
if ($restore->course_id == 0 and !has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
error("You need to be a creator or admin to restore into new course!");
- } else if ($restore->course_id != 0 and !isteacheredit($restore->course_id)) {
+ } else if ($restore->course_id != 0 and !has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $restore->course_id))) {
error("You need to be an edit teacher or admin to restore into selected course!");
}
$show_continue_button = true;
/// First work out whether we can post to this group and if so, include a link
- if (isteacheredit($COURSE->id)) { /// Teachers can always post
+ if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $COURSE->id))) { /// Teachers can always post
$visiblegroups = -1;
$text .= '<div align="center" class="newlink"><a href="'.$CFG->wwwroot.'/mod/forum/post.php?forum='.$forum->id.'">'.
echo '<input type="checkbox" name="c'.$acourse->id.'" />';
$abletomovecourses = true;
- } else if (isteacheredit($acourse->id)) {
+ } else if (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $acourse->id))) {
echo '<td>';
echo '<a title="'.$strsettings.'" href="'.$CFG->wwwroot.'/course/edit.php?id='.$acourse->id.'">'.
'<img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" alt="'.$strsettings.'" /></a> ';
error("Course is misconfigured");
}
- if (!isteacheredit($course->id)) {
- error('Only editing teachers can use this script');
- }
+ require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
$strreset = get_string('reset');
$strresetcourse = get_string('resetcourse');
if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
print_heading($strcustomscales);
- if (isteacheredit($course->id)) {
+ if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo "<p align=\"center\">(";
print_string("scalestip");
echo ")</p>";
<?php // $Id$
// Script to assign students to courses
-
+ //deprecated, should use admin/roles/assign.php now
require_once("../config.php");
define("MAX_USERS_PER_PAGE", 5000);
require_login($course->id);
- if (! isteacheredit($course->id) ) {
- error("You need to be a teacher with editing privileges");
- }
+ require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id));
function html_footer() {
global $course, $choose;
} else if ($icon == "zip.gif") {
$edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=unzip&sesskey=$USER->sesskey&choose=$choose\">$strunzip</a> ";
$edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$fileurl&action=listzip&sesskey=$USER->sesskey&choose=$choose\">$strlist</a> ";
- if (!empty($CFG->backup_version) and isteacheredit($id)) {
+ if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
$edittext .= "<a href=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=restore&sesskey=$USER->sesskey&choose=$choose\">$strrestore</a> ";
}
}
if (in_array($CFG->prefix.'user_teachers', $dbtables)) {
if ($userteachers = get_records('user_teachers')) {
foreach ($userteachers as $teacher) {
+ // populate the user_lastaccess table
+ unset($access);
+ $access->timeaccess = $teacher->timeaccess;
+ $access->userid = $teacher->userid;
+ $access->courseid = $teacher->course;
+ insert_record('user_lastaccess', $access);
+ // assign the default student role
$coursecontext = get_context_instance(CONTEXT_COURSE, $teacher->course); // needs cache
if ($teacher->editall) { // editting teacher
role_assign($editteacherrole, $teacher->userid, 0, $coursecontext->id);
*/
if (in_array($CFG->prefix.'user_students', $dbtables)) {
if ($userstudents = get_records('user_students')) {
- foreach ($userstudents as $student) {
+ foreach ($userstudents as $student) {
+ // populate the user_lastaccess table
+ unset($access);
+ $access->timeaccess = $student->timeaccess;
+ $access->userid = $student->userid;
+ $access->courseid = $student->course;
+ insert_record('user_lastaccess', $access);
+ // assign the default student role
$coursecontext = get_context_instance(CONTEXT_COURSE, $student->course);
role_assign($studentrole, $student->userid, 0, $coursecontext->id);
}
require_login($course->id);
- if (! isteacheredit($course->id) ) {
- error("Only teachers can edit files");
- }
+ require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id));
function html_footer() {
echo "\n\n</body>\n</html>";
if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
return true;
}
- return isteacheredit($this->id);
+ return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $this->id));
}
// Is the user actually editing this page right now? This would have something
function user_allowed_editing() {
$this->init_full();
- return isteacheredit($this->modulerecord->course);
+ return has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_COURSE, $this->modulerecord->course));
}
function user_is_editing() {
continue;
}
$question = $questions[$qnum];
- $canedit = isteacheredit($question->course);
+ $canedit = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $question->course));
echo "<td>";
if ($count != 0) {
// Print the header
$strquizzes = get_string("modulenameplural", "quiz");
- $streditquestions = isteacheredit($course->id)
+ $streditquestions = has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $course->id))
? "<form target=\"_parent\" method=\"get\" "
." action=\"$CFG->wwwroot/question/edit.php\">"
."<input type=\"hidden\" name=\"courseid\" "
"", "", true, update_module_button($cm->id, $course->id, $this->strresource),
navmenu($course, $cm));
- if (isteacheredit($course->id)) {
+ if (has_capabilities('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
echo "<div align=\"right\"><img src=\"$CFG->pixpath/i/files.gif\" height=\"16\" width=\"16\" alt=\"\" /> ".
"<a href=\"$CFG->wwwroot/files/index.php?id={$course->id}&wdir=/{$resource->reference}$subdir\">".
get_string("editfiles")."...</a></div>";
/// Security Constraints (sesskey and isteacheredit)
if (!confirm_sesskey()) {
error(get_string('confirmsesskeybad', 'error'));
- } else if (!isteacheredit($courseid)) {
+ } else if (!has_capabilities('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
error(get_string('onlyeditingteachers', 'error'));
}
/// If there are any error, show it instead of the resource page
if ($errorcode) {
- if (!isteacheredit($course->id)) {
+ if (!has_capabilities('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) {
/// Resource not available page
$errortext = get_string('resourcenotavailable','resource');
} else {
// TODO: generalise this to any activity
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
- $strupdatemodule = isteacheredit($course->id)
+ $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
: "";
print_header_simple(get_string('editcategories', 'quiz'), '',
$strquizzes = get_string('modulenameplural', 'quiz');
$streditingquestions = get_string('editquestions', "quiz");
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
- $strupdatemodule = isteacheredit($course->id)
+ $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
: "";
print_header_simple($streditingquestions, '',
echo '<table><tr>';
// check if editing of this category is allowed
- if (isteacheredit($category->course)) {
+ if (has_capability('moodle/question:managecateory', $context)) {
echo "<td valign=\"top\"><b>$strcreatenewquestion:</b></td>";
echo '<td valign="top" align="right">';
popup_form ("$CFG->wwwroot/question/question.php?category=$category->id&qtype=", $qtypemenu, "addquestion",
print_paging_bar($totalnumber, $page, $perpage,
"edit.php?courseid={$course->id}&perpage=$perpage&");
- $canedit = isteacheredit($category->course);
+ $canedit = has_capability('moodle/question:manage', $context);
echo '<form method="post" action="edit.php?courseid='.$course->id.'">';
echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
require_login($course->id, false);
- if (!isteacheredit($course->id)) {
- error( $txt->onlyteachersimport );
- }
+ require_capability('moodle/question:import', get_context_instance(CONTEXT_COURSE, $course->id));
// ensure the files area exists for this course
make_upload_directory( "$course->id" );
//==========
if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
- $strupdatemodule = isteacheredit($course->id)
+ $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
? update_module_button($SESSION->modform->cmid, $course->id, $txt->modulename)
: "";
print_header_simple($txt->importquestions, '',
if (!$tocategory = get_record('question_categories', 'id', $tocategoryid)) {
error('Invalid category');
}
- if (!isteacheredit($tocategory->course)) {
+ if (!has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $tocategory->course))){
error(get_string('categorynoedit', 'quiz', $tocategory->name), 'edit.php?courseid=$course->id');
}
foreach ($_POST as $key => $value) { // Parse input for question ids
}
require_login($course->id, false);
-
- if (!isteacheredit($course->id)) {
- error("Only the teacher can import quiz questions!");
- }
+ require_capability('moodle/question:import', get_context_instance(CONTEXT_COURSE, $course->id));
$DATASET_TYPES = array('1' => get_string('literal', 'quiz'),
'2' => get_string('file', 'quiz'),
// For editing teachers print a link to an editing popup window
$editlink = '';
- if (isteacheredit($cmoptions->course)) {
+ if (has_capability('moodle/question:manage', get_context_instance(CONTEXT_COURSE, $cmoptions->course))) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" alt="'.$stredit.'" />';
$editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true);
if (!empty($isteacher)) {
// get minimum lastaccess for this course and display a dropbox to filter by lastaccess going back this far.
- $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0');
-
+ // this might not work anymore because you always going to get yourself as the most recent entry? added $USER!=$user ch
+ $minlastaccess = get_field_sql('SELECT min(timeaccess) FROM '.$CFG->prefix.'user_lastaccess WHERE courseid = '.$course->id.' AND timeaccess != 0 AND userid!='.$USER->id);
$lastaccess0exists = record_exists('user_lastaccess','courseid',$course->id,'timeaccess',0);
$now = usergetmidnight(time());
$timeaccess = array();