Skip to content

Commit

Permalink
replacing deprecated funciton calls with capability calls
Browse files Browse the repository at this point in the history
  • Loading branch information
toyomoyo committed Sep 19, 2006
1 parent 285f94f commit 9c37662
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 42 deletions.
5 changes: 1 addition & 4 deletions admin/xmldb/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
5 changes: 3 additions & 2 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion calendar/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions course/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
14 changes: 4 additions & 10 deletions course/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -70,7 +64,7 @@

}

if ($adminediting && $perpage != 99999) {
if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID)) && $perpage != 99999) {
$perpage = 30;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/htmlarea/htmlarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ function (str, l1, l2, l3) {
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";
Expand Down
2 changes: 1 addition & 1 deletion lib/editor/htmlarea/htmlarea_bak.php
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,7 @@ function (str, l1, l2, l3) {
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";
Expand Down
2 changes: 1 addition & 1 deletion lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions mod/glossary/formats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down
9 changes: 5 additions & 4 deletions mod/glossary/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion mod/glossary/mod.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

<!-- 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>
Expand Down
3 changes: 2 additions & 1 deletion mod/glossary/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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%");

Expand Down
5 changes: 1 addition & 4 deletions mod/scorm/coefficientconfirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 1 addition & 4 deletions mod/scorm/coefficientsetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
5 changes: 2 additions & 3 deletions user/messageselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9c37662

Please sign in to comment.