From 9ce384ba1e9778c410f8ea24993d77e7daa5ca2a Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Tue, 19 Sep 2006 14:16:40 +0000 Subject: [PATCH] relacing deprecated functions with capability checks --- course/edit.html | 2 +- enrol/imsenterprise/importnow.php | 5 +---- lib/questionlib.php | 2 +- mod/hotpot/index.php | 10 +++++----- mod/hotpot/mod.html | 3 +-- mod/hotpot/report.php | 4 ++-- mod/hotpot/show.php | 2 +- mod/resource/type/ims/resource.class.php | 5 +++-- theme/chameleon/ui/chameleon.php | 2 +- theme/chameleon/ui/css.php | 2 +- 10 files changed, 17 insertions(+), 20 deletions(-) diff --git a/course/edit.html b/course/edit.html index 8ac95019cb1de..3015faf460459 100644 --- a/course/edit.html +++ b/course/edit.html @@ -413,7 +413,7 @@ helpbutton("metacourse", get_string("metacourse"));?> -requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { ?> +requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { ?> :
diff --git a/enrol/imsenterprise/importnow.php b/enrol/imsenterprise/importnow.php index 9efc92f6e4073..776383a4aad02 100644 --- a/enrol/imsenterprise/importnow.php +++ b/enrol/imsenterprise/importnow.php @@ -1,15 +1,12 @@ course)) { + if ((!$only_editable) || has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $category->course))) { echo " \n"; } } diff --git a/mod/hotpot/index.php b/mod/hotpot/index.php index e771d5355e865..4a0051e6a2748 100644 --- a/mod/hotpot/index.php +++ b/mod/hotpot/index.php @@ -81,7 +81,7 @@ } $hotpotids = implode(',', $hotpotids); - if (isadmin()) { + if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // get regrade settings, if any $regrade = optional_param("regrade"); @@ -248,7 +248,7 @@ $select .= " AND a.userid='$USER->id'"; } $usejoin = 1; - if (isadmin() && $usejoin) { + if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID)) && $usejoin) { // join attempts table and details table $tables .= ",{$CFG->prefix}hotpot_details AS d"; $fields .= ',COUNT(DISTINCT d.id) AS detailcount'; @@ -259,7 +259,7 @@ } $totals = get_records_sql("SELECT $fields FROM $tables WHERE $select GROUP BY a.hotpot"); - if (isadmin() && empty($usejoin)) { + if (ihas_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID)) && empty($usejoin)) { foreach ($hotpots as $hotpot) { $totals[$hotpot->id]->detailcount = 0; if ($ids = get_records('hotpot_attempts', 'hotpot', $hotpot->id)) { @@ -368,7 +368,7 @@ } } - if (isadmin()) { + if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID))) { if (in_array($hotpot->id, $regradehotpots)) { $report .= ' '.$strregraderequired.''; } @@ -393,7 +393,7 @@ array_push($data, $quizname, $quizclose, $bestscore, $report); - if (isadmin()) { + if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID))) { if (empty($totals[$hotpot->id]->detailcount)) { // no details records for this hotpot, so disable regrade $regradebutton = ' '; diff --git a/mod/hotpot/mod.html b/mod/hotpot/mod.html index a296bdf0d19b6..67e0506a75a9d 100644 --- a/mod/hotpot/mod.html +++ b/mod/hotpot/mod.html @@ -120,8 +120,7 @@ id==$site->id) { $id = $site->id; diff --git a/mod/hotpot/report.php b/mod/hotpot/report.php index 689f49887e784..2ed7d2feb36ff 100644 --- a/mod/hotpot/report.php +++ b/mod/hotpot/report.php @@ -48,7 +48,7 @@ // assemble array of form data $formdata = array( 'mode' => $mode, - 'reportcourse' => isadmin() ? optional_param('reportcourse', get_user_preferences('hotpot_reportcourse', 'this')) : 'this', + 'reportcourse' => has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_SYSTEM, SITEID)) ? optional_param('reportcourse', get_user_preferences('hotpot_reportcourse', 'this')) : 'this', 'reportusers' => has_capability('mod/hotpot:viewreport',$context) ? optional_param('reportusers', get_user_preferences('hotpot_reportusers', 'all')) : 'this', 'reportattempts' => optional_param('reportattempts', get_user_preferences('hotpot_reportattempts', 'all')), 'reportformat' => optional_param('reportformat', 'htm'), @@ -457,7 +457,7 @@ function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) { $menus['mode'][$name] = get_string("report$name", $module); } } - if (isadmin()) { + if (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $menus['reportcourse'] = array( 'this' => get_string('thiscourse', 'hotpot'), // $course->shortname, 'all' => get_string('allmycourses', 'hotpot') diff --git a/mod/hotpot/show.php b/mod/hotpot/show.php index c7e2c4d1a405f..6acdc341e71f3 100644 --- a/mod/hotpot/show.php +++ b/mod/hotpot/show.php @@ -12,7 +12,7 @@ if (!has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $params->course))) { error("You are not allowed to view this page!"); } - if (isadmin()) { + if (has_capability('mod/hotpot:viewreport', get_context_instance(CONTEXT_SYSTEM, SITEID))) { $params->location = optional_param('location', HOTPOT_LOCATION_COURSEFILES); } else { $params->location = HOTPOT_LOCATION_COURSEFILES; diff --git a/mod/resource/type/ims/resource.class.php b/mod/resource/type/ims/resource.class.php index 6d217df18a507..38a479c8cd127 100644 --- a/mod/resource/type/ims/resource.class.php +++ b/mod/resource/type/ims/resource.class.php @@ -184,7 +184,8 @@ function check4errors($file, $course, $resource) { /// If teacheredit, make, hash check. It's the md5 of the name of the file /// plus its size and modification date - if (isteacheredit($course->id)) { + /// not sure if this capability is suitable + if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!$this->checkpackagehash($file, $course, $resource)) { return 4; } @@ -360,7 +361,7 @@ function display() { print_simple_box_start('center', '60%'); echo '

'.$errortext.'

'; /// If errors were 3 or 4 and isteacheredit(), show the deploy button - if (isteacheredit($course->id) && ($errorcode == 3 || $errorcode == 4)) { + if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) && ($errorcode == 3 || $errorcode == 4)) { $link = 'type/ims/deploy.php'; $options['courseid'] = $course->id; $options['cmid'] = $cm->id; diff --git a/theme/chameleon/ui/chameleon.php b/theme/chameleon/ui/chameleon.php index 5a8103416a9ee..4de72d9ed06f9 100644 --- a/theme/chameleon/ui/chameleon.php +++ b/theme/chameleon/ui/chameleon.php @@ -7,7 +7,7 @@ if (isset($course->id)) { $chameleon_courseparam = '?id=' . $course->id; if (!$chameleon_isadmin) { - $chameleon_isteacher = (isteacheredit($course->id) && isset($CFG->coursetheme)); + $chameleon_isteacher = (has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id)) && isset($CFG->coursetheme)); } } else { $chameleon_courseparam = ''; diff --git a/theme/chameleon/ui/css.php b/theme/chameleon/ui/css.php index a05c565ebbef9..dd4239087d126 100644 --- a/theme/chameleon/ui/css.php +++ b/theme/chameleon/ui/css.php @@ -11,7 +11,7 @@ $chameleon_id = isset($_GET['id']) ? (int) $_GET['id'] : 0; if ($chameleon_id != 0 && !empty($CFG->allowcoursethemes) && !empty($THEME->chameleonteachereditenabled)) { - if (!isteacheredit($chameleon_id)) { + if (!has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $chameleon_id))) { die('CHAMELEON_ERROR Either you are not logged in or you are not allowed to edit this theme'); } } else if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {