replacing deprecated calls and references to capability calls
This commit is contained in:
+6
-1
@@ -21,7 +21,9 @@
|
||||
if (!$site = get_site()) {
|
||||
error("Site isn't defined!");
|
||||
}
|
||||
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSECAT, $id);
|
||||
|
||||
if ($CFG->forcelogin) {
|
||||
require_login();
|
||||
}
|
||||
@@ -104,6 +106,9 @@
|
||||
"<a href=\"index.php\">$strcategories</a> -> $category->name", "", "", true, $navbaritem);
|
||||
}
|
||||
|
||||
/// Print link to roles
|
||||
print('<a href="'.$CFG->wwwroot.'/admin/roles/assign.php?contextid='.$context->id.'">'.get_string('roles').'</a>');
|
||||
|
||||
/// Print the category selector
|
||||
|
||||
$displaylist = array();
|
||||
|
||||
+12
-5
@@ -132,12 +132,19 @@
|
||||
exit;
|
||||
|
||||
function grade_get_grade_item_exceptions($id) {
|
||||
global $CFG;
|
||||
global $course;
|
||||
|
||||
$sql = "SELECT ge.id, ge.userid FROM {$CFG->prefix}grade_exceptions ge, {$CFG->prefix}user_students us WHERE us.course=$course->id AND grade_itemid=$id AND ge.userid = us.userid AND us.course=ge.courseid";
|
||||
$grade_exceptions = get_records_sql($sql);
|
||||
return $grade_exceptions;
|
||||
global $CFG, $course;
|
||||
|
||||
$contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
|
||||
$sql = "SELECT ge.id, ge.userid
|
||||
FROM {$CFG->prefix}grade_exceptions ge,
|
||||
{$CFG->prefix}role_assignments ra
|
||||
WHERE grade_itemid = $id
|
||||
AND ge.userid = ra.userid
|
||||
AND ra.contextid $contextlists";
|
||||
|
||||
return get_records_sql($sql);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
+10
-6
@@ -1984,10 +1984,11 @@ function fetch_context_independent_capabilities() {
|
||||
* context.
|
||||
* @param obj $context
|
||||
* @param int $roleid
|
||||
* @param bool self - if set to true, resolve till this level, else stop at immediate parent level
|
||||
* @return array
|
||||
*/
|
||||
function role_context_capabilities($roleid, $context, $cap='') {
|
||||
global $CFG;
|
||||
global $CFG;
|
||||
|
||||
$contexts = get_parent_contexts($context);
|
||||
$contexts[] = $context->id;
|
||||
@@ -1999,11 +2000,14 @@ function role_context_capabilities($roleid, $context, $cap='') {
|
||||
$search = '';
|
||||
}
|
||||
|
||||
$SQL = "SELECT rc.* FROM {$CFG->prefix}role_capabilities rc, {$CFG->prefix}context c
|
||||
where rc.contextid in $contexts
|
||||
and rc.roleid = $roleid
|
||||
and rc.contextid = c.id $search
|
||||
ORDER BY c.aggregatelevel DESC, rc.capability DESC";
|
||||
$SQL = "SELECT rc.*
|
||||
FROM {$CFG->prefix}role_capabilities rc,
|
||||
{$CFG->prefix}context c
|
||||
WHERE rc.contextid in $contexts
|
||||
AND rc.roleid = $roleid
|
||||
AND rc.contextid = c.id $search
|
||||
ORDER BY c.aggregatelevel DESC,
|
||||
rc.capability DESC";
|
||||
|
||||
$capabilities = array();
|
||||
|
||||
|
||||
+14
-1
@@ -976,7 +976,20 @@ $moodle_capabilities = array(
|
||||
'admin' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
|
||||
'moodle/course:useremail' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
'legacy' => array(
|
||||
'guest' => CAP_PREVENT,
|
||||
'student' => CAP_PREVENT,
|
||||
'teacher' => CAP_PREVENT,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'coursecreator' => CAP_PREVENT,
|
||||
'admin' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
|
||||
'moodle/course:viewhiddensections' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
|
||||
@@ -428,15 +428,7 @@ function remove_teacher($userid, $courseid=0) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Next if the teacher is not registered as a student, but is
|
||||
/// a member of a group, remove them from the group.
|
||||
if (!isstudent($courseid, $userid)) {
|
||||
if ($groups = get_groups($courseid, $userid)) {
|
||||
foreach ($groups as $group) {
|
||||
delete_records('groups_members', 'groupid', $group->id, 'userid', $userid);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// No need to remove from groups now
|
||||
|
||||
foreach ($roles as $role) { // Unassign them from all the teacher roles
|
||||
$newreturn = role_unassign($role->id, $userid, 0, $context->id);
|
||||
|
||||
@@ -262,12 +262,12 @@ form { margin-bottom: 0px; margin-top: 0px; }
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td width="55%" valign="top"><?php
|
||||
if(isteacher($id)) {
|
||||
if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
print_string("filebrowser","editor");
|
||||
} else {
|
||||
print "";
|
||||
}?><br />
|
||||
<?php print(isteacher($id))?
|
||||
<?php has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))?
|
||||
"<iframe id=\"ibrowser\" name=\"ibrowser\" src=\"".$CFG->wwwroot."/lib/editor/htmlarea/coursefiles.php?usecheckboxes=1&id=".$course->id."\" style=\"width: 100%; height: 200px;\"></iframe>":
|
||||
"";?>
|
||||
</td>
|
||||
@@ -279,7 +279,7 @@ form { margin-bottom: 0px; margin-top: 0px; }
|
||||
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
||||
<tr>
|
||||
<td width="55%"><div class="space"></div>
|
||||
<?php if(isteacher($id)) { ?>
|
||||
<?php if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
|
||||
<table border="0" cellpadding="2" cellspacing="0">
|
||||
<tr><td><?php print_string("selection","editor");?>: </td>
|
||||
<td><form name="idelete" id="idelete">
|
||||
@@ -315,7 +315,7 @@ form { margin-bottom: 0px; margin-top: 0px; }
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="22"><?php
|
||||
if(isteacher($id)) { ?>
|
||||
if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
|
||||
<form name="cfolder" id="cfolder" action="../coursefiles.php" method="post" target="ibrowser">
|
||||
<input type="hidden" name="id" value="<?php print($course->id);?>" />
|
||||
<input type="hidden" name="wdir" value="" />
|
||||
|
||||
@@ -79,14 +79,14 @@ form { margin-bottom: 1px; margin-top: 1px; }
|
||||
<tr>
|
||||
<td width="450" valign="top"><fieldset>
|
||||
<legend><?php
|
||||
if(isteacher($id)) {
|
||||
if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
print_string("filebrowser","editor");
|
||||
} else {
|
||||
print "";
|
||||
}?></legend>
|
||||
|
||||
<div class="space"></div>
|
||||
<?php print(isteacher($id))?
|
||||
<?php print(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id)))?
|
||||
"<iframe id=\"fbrowser\" name=\"fbrowser\" src=\"../coursefiles.php?id=".$course->id."\" width=\"420\" height=\"180\"></iframe>":
|
||||
""; ?>
|
||||
<p>
|
||||
@@ -124,7 +124,7 @@ form { margin-bottom: 1px; margin-top: 1px; }
|
||||
<table border="0" cellpadding="1" cellspacing="1">
|
||||
<tr>
|
||||
<td height="22"><?php
|
||||
if(isteacher($id)) { ?>
|
||||
if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
|
||||
<form name="cfolder" id="cfolder" action="../coursefiles.php" method="post" target="fbrowser">
|
||||
<input type="hidden" name="id" value="<?php print($course->id);?>" />
|
||||
<input type="hidden" name="wdir" value="" />
|
||||
|
||||
@@ -3,10 +3,7 @@
|
||||
|
||||
$id = required_param('id', PARAM_INT);
|
||||
|
||||
if ($course = get_record("course", "id", $id)) {
|
||||
$isteacher = isteacher($course->id);
|
||||
} else {
|
||||
$isteacher = false;
|
||||
if (!$course = get_record("course", "id", $id)) {
|
||||
$course->fullname = ""; // Just to keep display happy, though browsing may fail
|
||||
}
|
||||
?>
|
||||
@@ -177,7 +174,7 @@ border-bottom: 1px solid black; letter-spacing: 2px;
|
||||
</table>
|
||||
|
||||
<div id="buttons">
|
||||
<?php if ($isteacher) {
|
||||
<?php if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
|
||||
echo "<button type=\"button\" name=\"browse\" onclick=\"return onBrowse();\">".get_string("browse","editor")."...</button>";
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -10,10 +10,7 @@
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
if (!isteacher($course->id)) {
|
||||
error("Only teachers can use this functionality");
|
||||
}
|
||||
require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
|
||||
$imagetag = clean_text('<img src="'.htmlSpecialChars(stripslashes_safe($imageurl)).'" alt="" />');
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class tinymce extends editorObject {
|
||||
$this->cfg->tinymcepopupcss : '',
|
||||
"editor_css" => !empty($this->cfg->tinymceeditorcss) ?
|
||||
$this->cfg->tinymceeditorcss : '',
|
||||
"file_browser_callback" => $isteacher ? 'moodleFileBrowser' : '',
|
||||
"file_browser_callback" => has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? 'moodleFileBrowser' : '',
|
||||
"convert_urls" => false,
|
||||
"relative_urls" => false);
|
||||
|
||||
@@ -112,7 +112,7 @@ class tinymce extends editorObject {
|
||||
$this->defaults['theme_advanced_resize_horizontal'] = true;
|
||||
}
|
||||
|
||||
$this->printdialogs = $isteacher ? true : false;
|
||||
$this->printdialogs = has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-8
@@ -3036,8 +3036,8 @@ function print_user($user, $course, $messageselect=false, $return=false) {
|
||||
static $string;
|
||||
static $datestring;
|
||||
static $countries;
|
||||
static $isteacher;
|
||||
static $isadmin;
|
||||
static $isteacher;
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
if (empty($string)) { // Cache all the strings for the rest of the page
|
||||
@@ -3063,7 +3063,6 @@ function print_user($user, $course, $messageselect=false, $return=false) {
|
||||
$datestring->secs = get_string('secs');
|
||||
|
||||
$countries = get_list_of_countries();
|
||||
|
||||
$isteacher = isteacher($course->id);
|
||||
$isadmin = isadmin();
|
||||
}
|
||||
@@ -3086,7 +3085,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
|
||||
if (!empty($user->role) and ($user->role <> $course->teacher)) {
|
||||
$output .= $string->role .': '. $user->role .'<br />';
|
||||
}
|
||||
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) {
|
||||
if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or has_capability('moodle/course:viewhiddenuserfields', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
$output .= $string->email .': <a href="mailto:'. $user->email .'">'. $user->email .'</a><br />';
|
||||
}
|
||||
if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
|
||||
@@ -3117,7 +3116,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
|
||||
$output .= '<a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.get_string('blogs','blog').'</a><br />';
|
||||
}
|
||||
|
||||
if ($isteacher) {
|
||||
if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
||||
$timemidnight = usergetmidnight(time());
|
||||
$output .= '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&user='. $user->id .'">'. $string->activity .'</a><br />';
|
||||
if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID, $user->id)) or ($isadmin and !isadmin($user->id))) { // Includes admins
|
||||
@@ -3177,11 +3176,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
|
||||
}
|
||||
}
|
||||
|
||||
static $isteacheredit;
|
||||
$context = get_context_instance(CONTEXT_COURSE, $courseid);
|
||||
if (!isset($isteacheredit)) {
|
||||
$isteacheredit = isteacheredit($courseid);
|
||||
}
|
||||
|
||||
if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
|
||||
return '';
|
||||
|
||||
+1
-1
@@ -144,7 +144,7 @@ switch ($action) {
|
||||
}
|
||||
echo "</td><td><input type='submit' value='$strchoose'></td></form>";
|
||||
echo "<td>";
|
||||
if ($preset->user == $USER->id || isadmin()) {
|
||||
if ($preset->user == $USER->id || has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
||||
echo "<form action='' method='POST'>";
|
||||
echo "<input type='hidden' name='d' value='$data->id' />";
|
||||
echo "<input type='hidden' name='action' value='confirmdelete' />";
|
||||
|
||||
+1
-10
@@ -429,16 +429,7 @@
|
||||
///////////////////////////////////
|
||||
function hotpot_feedback_teachers(&$course, &$hotpot) {
|
||||
global $CFG;
|
||||
$teachers = get_records_sql("
|
||||
SELECT
|
||||
u.*
|
||||
FROM
|
||||
{$CFG->prefix}user AS u,
|
||||
{$CFG->prefix}user_teachers AS t
|
||||
WHERE
|
||||
t.userid = u.id
|
||||
AND t.course = $course->id
|
||||
");
|
||||
$teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'mod/hotpot:grade');
|
||||
$teacherdetails = '';
|
||||
if (!empty($teachers)) {
|
||||
$details = array();
|
||||
|
||||
@@ -239,6 +239,8 @@ class quiz_report extends quiz_default_report {
|
||||
}
|
||||
echo $headers." \n";
|
||||
}
|
||||
|
||||
$contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id));
|
||||
|
||||
// Construct the SQL
|
||||
$select = 'SELECT '.$db->Concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
|
||||
@@ -248,15 +250,15 @@ class quiz_report extends quiz_default_report {
|
||||
if (!empty($currentgroup) && empty($noattempts)) {
|
||||
// we want a particular group and we only want to see students WITH attempts.
|
||||
// So join on groups_members and do an inner join on attempts.
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
|
||||
'JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
|
||||
$where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
|
||||
$where = ' WHERE ra.contextid $contextlists AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
|
||||
} else if (!empty($currentgroup) && !empty($noattempts)) {
|
||||
// We want a particular group and we want to do something funky with attempts
|
||||
// So join on groups_members and left join on attempts...
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
|
||||
'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
|
||||
$where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
|
||||
$where = ' WHERE ra.contextid $contextlists AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
|
||||
if ($noattempts == 1) {
|
||||
// noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
|
||||
$where .= ' AND qa.userid IS NULL'; // show ONLY no attempts;
|
||||
@@ -264,8 +266,8 @@ class quiz_report extends quiz_default_report {
|
||||
} else if (empty($currentgroup)) {
|
||||
// We don't care about group, and we to do something funky with attempts
|
||||
// So do a left join on attempts
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
|
||||
$where = " WHERE us.course = '$course->id'";
|
||||
$from = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
|
||||
$where = " WHERE ra.contextid $contextlists";
|
||||
if (empty($noattempts)) {
|
||||
$where .= ' AND qa.userid IS NOT NULL'; // show ONLY students with attempts;
|
||||
} else if ($noattempts == 1) {
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
ims_print_crumbtrail($directory);
|
||||
|
||||
/// If admin, add extra buttons - redeploy & help.
|
||||
if (isadmin()) {
|
||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
||||
echo " | (<a href=\"repository_deploy.php?file=$directory&all=force\">$strdeployall</a>) ";
|
||||
helpbutton("deploy", get_string("deployall", "resource"), "resource", true);
|
||||
}
|
||||
@@ -82,7 +82,7 @@
|
||||
}
|
||||
else if ($item->type == 'not deployed') {
|
||||
/// Only displays non-deployed IMS CP's if admin user.
|
||||
if (isadmin()) {
|
||||
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
|
||||
echo "<li><img src=\"images/ims.gif\" alt=\"IMS CP Package\" /> <em>$item->path - $strnotdeployed</em> (<a href=\"repository_deploy.php?file=$item->path\">$strdeploy</a>)</li>\n";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,7 @@
|
||||
require_once('repository_config.php');
|
||||
|
||||
/// Security - Admin Only
|
||||
if (!isadmin()) {
|
||||
error("Not admin!");
|
||||
}
|
||||
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))
|
||||
|
||||
$file = required_param ('file', PARAM_PATH);
|
||||
$all = optional_param ('all', '', PARAM_ALPHA);
|
||||
|
||||
+6
-5
@@ -52,7 +52,7 @@
|
||||
$currentuser = ($user->id == $USER->id);
|
||||
}
|
||||
|
||||
if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', $coursecontext)) { // Groups must be kept separate
|
||||
if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) { // Groups must be kept separate
|
||||
require_login();
|
||||
|
||||
///this is changed because of mygroupid
|
||||
@@ -64,8 +64,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$currentuser && !isteacheredit($course->id, $user->id) && !$gtrue) {
|
||||
// took the teacheredit check out because teacheredit will have moodle/site:accessallgroups capability
|
||||
// which was already checked
|
||||
if (!$currentuser && !$gtrue) {
|
||||
print_header("$personalprofile: ", "$personalprofile: ",
|
||||
"<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
|
||||
<a href=\"index.php?id=$course->id\">$participants</a>",
|
||||
@@ -175,7 +176,7 @@
|
||||
|
||||
$emailswitch = '';
|
||||
|
||||
if (isteacheredit($course->id) or $currentuser) { /// Can use the enable/disable email stuff
|
||||
if (has_capability('moodle/course:useremail', get_context_instance(CONTEXT_COURSE, $course->id)) or $currentuser) { /// Can use the enable/disable email stuff
|
||||
if (!empty($enable)) { /// Recieved a parameter to enable the email address
|
||||
set_field('user', 'emailstop', 0, 'id', $user->id);
|
||||
$user->emailstop = 0;
|
||||
@@ -186,7 +187,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if (isteacheredit($course->id)) { /// Can use the enable/disable email stuff
|
||||
if (has_capability('moodle/course:useremail', get_context_instance(CONTEXT_COURSE, $course->id))) { /// Can use the enable/disable email stuff
|
||||
if ($user->emailstop) {
|
||||
$switchparam = 'enable';
|
||||
$switchtitle = get_string('emaildisable');
|
||||
|
||||
Reference in New Issue
Block a user