From: toyomoyo Date: Tue, 19 Sep 2006 09:16:24 +0000 (+0000) Subject: replacing deprecated funciton calls with capability calls X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=9c37662f222a0e15d839eaeb56c3048e151be9f4;p=moodle.git replacing deprecated funciton calls with capability calls --- diff --git a/admin/xmldb/index.php b/admin/xmldb/index.php index 3c08a6ce80..6b03c05e85 100644 --- a/admin/xmldb/index.php +++ b/admin/xmldb/index.php @@ -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'); diff --git a/calendar/lib.php b/calendar/lib.php index ba0c6bf31c..4d38d155fe 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -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; diff --git a/calendar/view.php b/calendar/view.php index 47b8fc5151..cfb04af524 100644 --- a/calendar/view.php +++ b/calendar/view.php @@ -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'); diff --git a/course/edit.php b/course/edit.php index e32f37abc8..2dd123008c 100644 --- a/course/edit.php +++ b/course/edit.php @@ -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); } diff --git a/course/search.php b/course/search.php index 8b9132ee81..84fd0106e8 100644 --- a/course/search.php +++ b/course/search.php @@ -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 "

"; } - 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); diff --git a/lib/editor/htmlarea/htmlarea.php b/lib/editor/htmlarea/htmlarea.php index 71eb4d8993..aea3a2e11d 100644 --- a/lib/editor/htmlarea/htmlarea.php +++ b/lib/editor/htmlarea/htmlarea.php @@ -1527,7 +1527,7 @@ HTMLArea.prototype._insertImage = function(image) { f_height : image.height }; this._popupDialog("dataroot.'/'.SITEID.'/maintenance.html')) { print_maintenance_message(); exit; diff --git a/mod/glossary/formats.php b/mod/glossary/formats.php index f78fd0f330..7820f16765 100644 --- a/mod/glossary/formats.php +++ b/mod/glossary/formats.php @@ -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!"); } diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 181eb3df48..06a4af9f61 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 } diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html index 2512bf7d11..e01616dc08 100644 --- a/mod/glossary/mod.html +++ b/mod/glossary/mod.html @@ -101,7 +101,7 @@ if (!isset($form->assesstimefinish)) { : diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 5d9e2c5dc7..98a2f2f6ba 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -429,7 +429,8 @@ echo '
'; echo ''; 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 '

'; print_simple_box("$sqlselect
$sqlfrom
$sqlwhere
$sqlorderby
$sqllimit","center","85%"); diff --git a/mod/scorm/coefficientconfirm.php b/mod/scorm/coefficientconfirm.php index 2930e78ea9..aaf38cb8db 100755 --- a/mod/scorm/coefficientconfirm.php +++ b/mod/scorm/coefficientconfirm.php @@ -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"); diff --git a/mod/scorm/coefficientsetting.php b/mod/scorm/coefficientsetting.php index 788420be8a..14c0428590 100755 --- a/mod/scorm/coefficientsetting.php +++ b/mod/scorm/coefficientsetting.php @@ -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"); diff --git a/user/messageselect.php b/user/messageselect.php index 91e890ef1f..73408ff8f0 100644 --- a/user/messageselect.php +++ b/user/messageselect.php @@ -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();