replacing deprecated funciton calls with capability calls

This commit is contained in:
toyomoyo 2006-09-19 09:16:24 +00:00
parent 285f94f506
commit 9c37662f22
15 changed files with 28 additions and 42 deletions

View File

@ -75,10 +75,7 @@
}
require_login();
if (!isadmin()) {
error('You must be an administrator to use this page.');
}
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
/// Fetch all the needed strings
$stradministration = get_string('administration');

View File

@ -1113,7 +1113,8 @@ function calendar_set_filters(&$courses, &$group, &$user, $courseeventsfrom = NU
$groupcourses = array_keys($groupeventsfrom);
}
if(isadmin() && !empty($CFG->calendar_adminseesall)) {
// XXX TODO: not sure how to replace $CFG->calendar_adminseesall
if(has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID)) && !empty($CFG->calendar_adminseesall)) {
$group = true;
}
else {
@ -1204,7 +1205,7 @@ function calendar_get_default_courses($ignoreref = false) {
}
$courses = array();
if(isadmin($USER->id)) {
if(has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
if(!empty($CFG->calendar_adminseesall)) {
$courses = get_records_sql('SELECT id, 1 FROM '.$CFG->prefix.'course');
return $courses;

View File

@ -554,7 +554,7 @@ function calendar_course_filter_selector($getvars = '') {
return '';
}
if (isadmin() && !empty($CFG->calendar_adminseesall)) {
if (has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID)) && !empty($CFG->calendar_adminseesall)) {
$courses = get_courses('all', 'c.shortname','c.id,c.shortname');
} else {
$courses = get_my_courses($USER->id, 'shortname');

View File

@ -102,7 +102,7 @@
// Update with the new data
if (update_record('course', $form)) {
add_to_log($course->id, "course", "update", "edit.php?id=$id", "");
if (isadmin()) {
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$course->restrictmodules = $form->restrictmodules;
update_restricted_mods($course,$allowedmods);
}
@ -133,7 +133,7 @@
$page = page_create_object(PAGE_COURSE_VIEW, $newcourseid);
blocks_repopulate_page($page); // Return value not checked because you can always edit later
if (isadmin()) {
if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$course = get_record("course","id",$newcourseid);
update_restricted_mods($course,$allowedmods);
}

View File

@ -39,17 +39,11 @@
// modes, set page to 0.
$page = 0;
}
$creatorediting = !empty($USER->categoryediting);
$adminediting = (isadmin() and $creatorediting);
} else {
$adminediting = false;
$creatorediting = false;
}
}
/// Editing functions
if ($adminediting) {
if (has_capablity('moodle/course:visibility', get_context_instance(CONTEXT_SITE, SITEID))) {
/// Hide or show a course
@ -70,7 +64,7 @@
}
if ($adminediting && $perpage != 99999) {
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID)) && $perpage != 99999) {
$perpage = 30;
}
@ -146,7 +140,7 @@
echo "</p></center>";
}
if (!$adminediting) {
if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
foreach ($courses as $course) {
$course->fullname = highlight("$search", $course->fullname);
$course->summary = highlight("$search", $course->summary);

View File

@ -1527,7 +1527,7 @@ HTMLArea.prototype._insertImage = function(image) {
f_height : image.height
};
this._popupDialog("<?php
if(!empty($id) and isteacher($id)) {
if(!empty($id) and has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
echo "insert_image.php?id=$id";
} else {
echo "insert_image_std.php?id=$id";

View File

@ -1479,7 +1479,7 @@ HTMLArea.prototype._insertImage = function(image) {
f_height : image.height
};
this._popupDialog("<?php
if(isteacher($id)) {
if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
echo "insert_image.php?id=$id";
} else {
echo "insert_image_std.php?id=$id";

View File

@ -1533,7 +1533,7 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) {
}
/// If the site is currently under maintenance, then print a message
if (!isadmin()) {
if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM, SITEID))) {
if (file_exists($CFG->dataroot.'/'.SITEID.'/maintenance.html')) {
print_maintenance_message();
exit;

View File

@ -9,9 +9,8 @@
$mode = optional_param('mode');
require_login();
if ( !isadmin() ) {
error("You must be an admin to use this page.");
}
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
if (!$site = get_site()) {
error("Site isn't defined!");
}

View File

@ -68,7 +68,7 @@ function glossary_add_instance($glossary) {
if ( !isset($glossary->globalglossary) ) {
$glossary->globalglossary = 0;
} elseif ( !isadmin() ) {
} elseif (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$glossary->globalglossary = 0;
}
@ -92,8 +92,9 @@ function glossary_update_instance($glossary) {
/// Given an object containing all the necessary data,
/// (defined by the form in mod.html) this function
/// will update an existing instance with new data.
global $CFG;
if ( !isadmin() ) {
global $CFG;
if (!has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
unset($glossary->globalglossary);
}
if (empty($glossary->globalglossary)) {
@ -498,7 +499,7 @@ function glossary_get_entries_search($concept, $courseid) {
//Check if the user is an admin
$bypassadmin = 1; //This means NO (by default)
if (isadmin()) {
if (has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
$bypassadmin = 0; //This means YES
}

View File

@ -101,7 +101,7 @@ if (!isset($form->assesstimefinish)) {
<!-- More rows go in here... -->
<?php
if (isadmin() ) {
if (has_capability('mod/glossary:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
?>
<tr valign="top">
<td align="right"><b><?php echo get_string("isglobal", "glossary") ?>:</b></td>

View File

@ -429,7 +429,8 @@
echo '<br />';
echo '</center>';
glossary_print_tabbed_table_end();
if ( !empty($debug) and isadmin() ) {
if (debugging() and has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
echo '<p>';
print_simple_box("$sqlselect<br /> $sqlfrom<br /> $sqlwhere<br /> $sqlorderby<br /> $sqllimit","center","85%");

View File

@ -39,10 +39,7 @@
}
require_login($course->id, false, $cm);
if (!isteacher($course->id)) {
error("You are not allowed to use this script");
}
require_capability('mod/scorm:viewgrades', get_context_instance(COTNEXT_MODULE, $cm->id));
add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id");

View File

@ -39,10 +39,7 @@
}
require_login($course->id, false, $cm);
if (!isteacher($course->id)) {
error("You are not allowed to use this script");
}
require_capability('mod/scorm:viewgrades', get_context_instance(COTNEXT_MODULE, $cm->id));
add_to_log($course->id, "scorm", "report", "cofficientsetting.php?id=$cm->id", "$scorm->id");

View File

@ -16,9 +16,8 @@
error("Invalid course id");
}
if (!isteacher($course->id)) {
error("Only teachers can use this page");
}
require_login();
require_capability('moodle/site:readallmessages', get_context_instance(CONTEXT_COURSE, $id));
if (empty($SESSION->emailto)) {
$SESSION->emailto = array();