]> git.mjollnir.org Git - moodle.git/commitdiff
relacing deprecated functions with capability checks
authortoyomoyo <toyomoyo>
Tue, 19 Sep 2006 14:16:40 +0000 (14:16 +0000)
committertoyomoyo <toyomoyo>
Tue, 19 Sep 2006 14:16:40 +0000 (14:16 +0000)
course/edit.html
enrol/imsenterprise/importnow.php
lib/questionlib.php
mod/hotpot/index.php
mod/hotpot/mod.html
mod/hotpot/report.php
mod/hotpot/show.php
mod/resource/type/ims/resource.class.php
theme/chameleon/ui/chameleon.php
theme/chameleon/ui/css.php

index 8ac95019cb1de7b522b923107f7289ec070a1503..3015faf4604595f5ce1ecf088860d830b2af5878 100644 (file)
       helpbutton("metacourse", get_string("metacourse"));?>
     </td>
 </tr>
-<?php if (isadmin() && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { ?>
+<?php if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) && ((!empty($course->requested) && $CFG->restrictmodulesfor == 'requested') || $CFG->restrictmodulesfor == 'all')) { ?>
 <tr valign="top">
     <td align="right"><?php print_string("restrictmodules") ?>:</td>
     <td valign="top"><table cellpadding="0" border="0"><tr valign="top"><td>
index 9efc92f6e40739ddeb845d4cda97b271182b0cc5..776383a4aad02ccb7a8d2cd3f0ff99ef8de8b8dd 100644 (file)
@@ -1,15 +1,12 @@
 <?php
 require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
 require_login();
+require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
 if (!$site = get_site()) {
     redirect("index.php");
 }
 
-if (!isadmin()) {
-    error("Only the admin can use this page");
-}
-
 /// get language strings
 $str = get_strings(array('enrolments', 'users', 'administration', 'settings'));
 
index ded7b23810da25b606c6186eebbff1c057af7327..f9e92541c19e8f60d8d8de6897e5c4109f63f3c2 100644 (file)
@@ -1481,7 +1481,7 @@ function question_category_select_menu($courseid, $published = false, $only_edit
         if ($cid==$selected) {
             $seltxt = "selected=\"selected\"";
         }
-        if ((!$only_editable) || isteacheredit($category->course)) {
+        if ((!$only_editable) || has_capability('moodle/question:managecateory', get_context_instance(CONTEXT_COURSE, $category->course))) {
             echo "    <option value=\"$cid\" $seltxt>$cname</option>\n";
         }
     }
index e771d5355e865e7aab68323c67b41c3e9af1a23f..4a0051e6a27486b7e8d90722684c63ae069ef216 100644 (file)
@@ -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");
         $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';
     }
     $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)) {
             }
         }
 
-        if (isadmin()) {
+        if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             if (in_array($hotpot->id, $regradehotpots)) {
                 $report .= ' <font color="red">'.$strregraderequired.'</font>';
             }
 
         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 = '&nbsp;';
index a296bdf0d19b66ee1cec451c8e94f2b3fe1d9005..67e0506a75a9d667ef82cc04b55006685c70f3ee 100644 (file)
@@ -120,8 +120,7 @@ $text_source_options = array(
         </td>
         <td align="left"><?PHP
 
-
-            if (isadmin()) {
+            if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 $site = get_site();
                 if ($course->id==$site->id) {
                     $id = $site->id;
index 689f49887e78440ae4e7cf71a7e372a124b945c2..2ed7d2feb36ff94b8eb6d5f0c4967b16db0a9f06 100644 (file)
@@ -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')
index c7e2c4d1a405f1460364617b93601d457222c10e..6acdc341e71f391986418b2e7e9e24042f1c04c9 100644 (file)
@@ -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;
index 6d217df18a507ee27a7e9f09759fea124294bdae..38a479c8cd127e0f78be76ff3751af7fa5bb19df 100644 (file)
@@ -184,7 +184,8 @@ class resource_ims extends resource_base {
         
         /// 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 @@ class resource_ims extends resource_base {
             print_simple_box_start('center', '60%');
             echo '<p align="center">'.$errortext.'</p>';
         /// 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;
index 5a8103416a9ee225193eb75b4ad98480a196db40..4de72d9ed06f9d45dfeb0040b2530afacb1bb4eb 100644 (file)
@@ -7,7 +7,7 @@ if (isset($THEME->chameleonenabled) && $THEME->chameleonenabled) {
     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 = '';
index a05c565ebbef99b585284a76978855be9a760ee4..dd4239087d126878462da778a8ebf29f1a46f044 100644 (file)
@@ -11,7 +11,7 @@ if (empty($THEME->chameleonenabled)) {
 
 $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))) {