]> git.mjollnir.org Git - moodle.git/commitdiff
adding capabilities
authortoyomoyo <toyomoyo>
Thu, 7 Sep 2006 08:57:56 +0000 (08:57 +0000)
committertoyomoyo <toyomoyo>
Thu, 7 Sep 2006 08:57:56 +0000 (08:57 +0000)
24 files changed:
backup/backup.php
backup/backup_check.html
backup/backup_execute.html
backup/backup_form.html
backup/log.php
backup/restore.php
backup/restore_check.html
backup/restore_execute.html
backup/restore_form.html
backup/restore_precheck.html
backup/restorelib.php
backup/try.php
blocks/course_list/block_course_list.php
course/delete.php
course/edit.html
course/lib.php
course/teacher.php
lib/accesslib.php
lib/db/access.php
lib/weblib.php
theme/preview.php
user/tabs.php
userpix/index.php
userpix/upgrade.php

index f0e1d36a602fc5bd96d57884524e77d49272eee0..80ab088c91f700608d6c583cccd250f33b5a6885 100644 (file)
     require_login();
 
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $id))) {
             error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
 
     if (!empty($to)) {
-        if (!isteacheredit($to)) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
             error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
@@ -95,7 +95,7 @@
     }
 
     //Print header
-    if (isadmin()) {
+    if (has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         print_header("$site->shortname: $strcoursebackup", $site->fullname,
                      "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
                       <a href=\"backup.php\">$strcoursebackup</a> -> $course->fullname ($course->shortname)");
index 1c5fab37ff768bfb61efcaba5090d0eedfc476fe..af5e194c38ecdea565728c6d5560faf7687fbad5 100644 (file)
@@ -5,17 +5,17 @@
     require_login();
 
     if (!empty($course->id)) {
-        if (!isteacheredit($course->id)) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
index 826658605fe4be1b34783b254c6c6caf321b8d7c..4276c885be3a70e39e65cbd4ec237702dea3cfc9 100644 (file)
@@ -5,7 +5,7 @@
     require_login();
 
     if (!empty($course->id)) {
-        if (!isteacheredit($course->id)) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
@@ -15,7 +15,7 @@
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
index be46e84668e415d6bead77b99a68d3eb5e1b85bf..e098dd69c645188fb5ad54925b13887ec5373921 100644 (file)
@@ -5,17 +5,17 @@
     require_login();
 
     if (!empty($course->id)) {
-        if (!isteacheredit($course->id)) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
index 8fa89ec10c23b042d78659253cba17074086caa1..456f1f2ddbc14d11c4b037e8b58f4a1cb19ce227 100644 (file)
@@ -8,9 +8,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("Only an admin can use this page");
-    }
+    require_capability('moodle/site:backup', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     if (!$site = get_site()) {
         error("Site isn't defined!");
index 9028c5d9d4e4ea940a0db39e71b2485a0df0ca3d..2bb1be7aed81be227f0ddec1cc4e2a6150f6fd1f 100644 (file)
     }
 
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
     }
 
     //Print header
-    if (isadmin()) {
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         print_header("$site->shortname: $strcourserestore", $site->fullname,
                      "<a href=\"$CFG->wwwroot/$CFG->admin/index.php\">$stradministration</a> ->
                       $strcourserestore -> ".basename($file));
index 992c8ba745cb81f58c7e7cef84121bff131b1055..e97182335fa65c8e295aa9f8373930e02d661085 100644 (file)
 
     //Check admin
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
     //    2-New course: Create the restore object and launch the execute.
 
     //If the user is a teacher and not a creator
-    if (isteacheredit($id) and !iscreator()) {
+    if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         $restore->course_id = $id;
         if ($restore->restoreto == 0) {
             $restore->deleting = true;
     }
 
     //If the user is a creator (or admin)
-    if (iscreator()) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         //Set restore->deleting as needed
         if ($restore->restoreto == 0) {
             $restore->deleting = true;
     }
 
     //Now, select the course if needed
-    if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and (iscreator())) {
+    if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if ($courses = get_courses("all","c.fullname","c.id,c.fullname,c.shortname,c.visible")) {
             print_heading(get_string("choosecourse"));
             print_simple_box_start("center");
     //Checks everything and execute restore
     } else if ((($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id != 0)) or ($restore->restoreto == 2)) {
         //Final access control check
-        if ($restore->course_id == 0 and !iscreator()) {
+        if ($restore->course_id == 0 and !has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be a creator or admin to restore into new course!");
         } else if ($restore->course_id != 0 and !isteacheredit($restore->course_id)) {
             error("You need to be an edit teacher or admin to restore into selected course!");
index ab14271c2f798a643f9235c3b37e9d40d18aa1a0..5cfe1574fd6c5f766b92a28fb7631ec1d5f22a29 100644 (file)
 
     //Check admin
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COUESE, $id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COUESE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     }
index 8eca8a675c1c0bf47f52e951cf700209a0af07ab..9197809aeef48e609d57b407f71f65794f047b7e 100644 (file)
 
     //Check admin
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COUESE, $id))) {
             error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");   
         }
     }
         }
 
     if (!isset($restore_restoreto)) {
-        if (isteacheredit($id) and !isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $restore_restoreto = 1;
         }
-        if (isadmin()) {
+        if (has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $restore_restoreto = 2;
         }
     }
@@ -157,7 +157,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
     echo "<td align=\"right\"><b>";
     echo get_string("restoreto").":</b>";
     echo "</td><td colspan=\"3\">";
-    if (isteacheredit($id) and !iscreator()) {
+    if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_COUESE, $id))) {
         $restore_restoreto_options[0] = get_string("currentcoursedeleting");
         $restore_restoreto_options[1] = get_string("currentcourseadding");
     } 
index ecf6def04ac94a7e670acdb16570c12fa2482c33..777e24c2105f057bc16861a179e41f16fbdc272f 100644 (file)
  
     //Check admin
     if (!empty($id)) {
-        if (!isteacheredit($id)) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
             if (empty($to)) {
                 error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
             } else {
-                if (!isteacheredit($to)) {
+                if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $to))) {
                     error("You need to be a teacher or admin user to use this page.", "$CFG->wwwroot/login/index.php");
                 }
             }
         }
     } else {
-        if (!isadmin()) {
+        if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");   
         }
     }
index f9696c485f1e4f8ddc7afa295f7ebf7a961d1ad9..7d3d5d569d41d6b265e31c1aceda6d508eb48d4d 100644 (file)
         //Second shot. Try to obtain any concordant category and check its publish status and editing rights
         } else if ($fcats = get_records('question_categories', $searchfield, $searchvalue, 'id', 'id, publish, course')) {
             foreach ($fcats as $fcat) {
-                if ($fcat->publish == 1 && isteacheredit($fcat->course)) {
+                if ($fcat->publish == 1 && has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $fcat->course))) {
                     $found = $fcat->id;
                     break;
                 }
index 34ad2ff407f0f01fb9029c936a391a38f284daab..967feffe3a5888bc4f4afd538445be285e9db6dd 100644 (file)
@@ -7,9 +7,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("You need to be an admin user to use this page.", "$CFG->wwwroot/login/index.php");
-    }
+    require_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     //Check site
     if (!$site = get_site()) {
index 01ded849fd53cceaeca5d6cd307aeb2e1390c526..aa7221e07722d52938d6dcdfc52d6bc2a17b5ed2 100644 (file)
@@ -80,7 +80,7 @@ class block_course_list extends block_list {
                     $this->content->items = array();
                     $this->content->icons = array();
                     $this->content->footer = get_string('nocoursesyet').'<br /><br />';
-                    if (iscreator()) {
+                    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $category->id))) {
                         $this->content->footer .= '<a href="'.$CFG->wwwroot.'/course/edit.php?category='.$category->id.'">'.get_string("addnewcourse").'</a>...';
                     }
                 }
index 5ba165baca134d4d739458e52313a83187d04948..c0f6fc332fafaeb71f7d0fefc42a205955b1dd9f 100644 (file)
@@ -8,9 +8,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("You must be an administrator to use this page.");
-    }
+    require_capability('moodle/course:delete', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     if (!$site = get_site()) {
         error("Site not found!");
index 06a163abfe17a1e83fc9d5d0aae9bda7fb45cedb..71bfcf3506ba52bc649ac3098ec1b145e6492e88 100644 (file)
@@ -54,7 +54,7 @@
 ?>
 <form method="post" action="edit.php" name="form">
 <table cellpadding="9" cellspacing="0" >
-<?php if (iscreator()) { ?>
+<?php if (has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $form->category))) { ?>
 <tr valign="top">
     <td align="right"><?php  print_string("category") ?>:</td>
     <td><?php
     <td><input type="submit" value="<?php  print_string("savechanges") ?>" /></td>
 </tr>
 </table>
-<?php if(!iscreator()) { ?>
+<?php if(!has_capability('moodle/course:create', get_context_instance(CONTEXT_COURSECAT, $form->category))) { ?>
 <input type="hidden" name="category" value="<?php echo $form->category ?>" />
 <?php } ?>
 <input type="hidden" name="id" value="<?php echo $form->id ?>" />
index e6b8e9c9998081d330d8470da1550d2f4549da76..d5b99996d4897e5edfbd55cabcd0e02b2c62e68c 100644 (file)
@@ -1332,7 +1332,7 @@ function print_whole_category_list($category=NULL, $displaylist=NULL, $parentsli
     }
 
     if ($category) {
-        if ($category->visible or iscreator()) {
+        if ($category->visible or has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             print_category_info($category, $depth, $files);
         } else {
             return;  // Don't bother printing children of invisible categories
index 464dcac85438b98b0dc5181f756542e2a0316924..142ca2e75919637f1208cc002bbbf04860ef3308 100644 (file)
@@ -1,6 +1,8 @@
 <?php // $Id$
       // Admin-only script to assign teachers to courses
 
+    /// This page is deprecated
+
     require_once("../config.php");
 
     define("MAX_USERS_PER_PAGE", 50);
index 4f282ed0ec34df9d17a8dbff5f651471bc596228..a1eef0a522c9a6c49f0e9cd63af41c807ad760fb 100755 (executable)
@@ -1041,12 +1041,26 @@ function create_role($name, $description, $legacy='') {
     
     $role->name = $name;
     $role->description = $description;
-                                
+    
+    $context = get_context_instance(CONTEXT_SYSTEM, SITEID);                           
+    
     if ($id = insert_record('role', $role)) {
-        if ($legacy) {
-            $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
+        if ($legacy) {        
             assign_capability($legacy, CAP_ALLOW, $id, $context->id);            
         }
+        
+        /// By default, users with role:manage at site level
+        /// should be able to assign users to this new role, and override this new role's capabilities
+        
+        // find all admin roles
+        $adminroles = get_roles_with_capability('moodle/role:manage', CAP_ALLOW, $context);
+        // foreach admin role
+        foreach ($adminroles as $arole) {
+            // write allow_assign and allow_overrid
+            allow_assign($arole->id, $id);
+            allow_override($arole->id, $id);  
+        }
+        
         return $id;
     } else {
         return false;  
@@ -1054,7 +1068,6 @@ function create_role($name, $description, $legacy='') {
   
 }
 
-
 /**
  * Function to write context specific overrides, or default capabilities.
  * @param module - string name
@@ -1109,15 +1122,27 @@ function unassign_capability($capability, $roleid, $contextid=NULL) {
  *                      either CAP_ALLOW, CAP_PREVENT or CAP_PROHIBIT
  * @return array or role objects
  */
-function get_roles_with_capability($capability, $permission=NULL) {
-    
+function get_roles_with_capability($capability, $permission=NULL, $context='') {
+
     global $CFG;
     
+    if ($context) {
+        if ($contexts = get_parent_contexts($context)) {
+            $listofcontexts = '('.implode(',', $contexts).')';
+        } else {
+            $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
+            $listofcontexts = '('.$sitecontext->id.')'; // must be site  
+        }  
+        $contextstr = "AND (rc.contextid = '.$context->id.' OR  rc.contextid IN $listofcontexts)";
+    } else {
+        $contextstr = '';
+    }
+    
     $selectroles = "SELECT r.* 
                       FROM {$CFG->prefix}role AS r,
                            {$CFG->prefix}role_capabilities AS rc
                      WHERE rc.capability = '$capability'
-                       AND rc.roleid = r.id";
+                       AND rc.roleid = r.id $contextstr";
 
     if (isset($permission)) {
         $selectroles .= " AND rc.permission = '$permission'";
@@ -2008,7 +2033,7 @@ function get_users_by_capability($context, $capability, $fields='u.*', $sort='',
     global $CFG;
     
     // first get all roles with this capability in this context, or above
-    $possibleroles = get_roles_with_capability($capability, CAP_ALLOW);
+    $possibleroles = get_roles_with_capability($capability, CAP_ALLOW, $context);
     $validroleids = array();
     foreach ($possibleroles as $prole) {
         $caps = role_context_capabilities($prole->id, $context, $capability); // resolved list
@@ -2017,6 +2042,7 @@ function get_users_by_capability($context, $capability, $fields='u.*', $sort='',
         }
     }
     
+    /// the following few lines may not be needed
     if ($usercontexts = get_parent_contexts($context)) {
         $listofcontexts = '('.implode(',', $usercontexts).')';
     } else {
@@ -2028,7 +2054,7 @@ function get_users_by_capability($context, $capability, $fields='u.*', $sort='',
     
     $select = ' SELECT '.$fields;
     $from   = ' FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id ';
-    $where  = ' WHERE (ra.contextid = '.$context->id.' OR ra.contextid in '.$listofcontexts.') AND u.deleted = 0 AND ra.roleid in '.$roleids.' ';    
+    $where  = ' WHERE (ra.contextid = '.$context->id.' OR ra.contextid in '.$listofcontexts.') AND u.deleted = 0 AND ra.roleid in '.$roleids.' ';
 
     return get_records_sql($select.$from.$where.$sort, $limitfrom, $limitnum);  
 
index 8471940c6c64ed3f29887ac79e83488ea0755c00..7ea3b1e2069879bf9bb6551eb3cd75c9853558d2 100644 (file)
@@ -716,6 +716,19 @@ $moodle_capabilities = array(
         )
     ),
     
+    'moodle/user:editprofile' => array(
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_USERID,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_PREVENT,
+            'coursecreator' => CAP_PREVENT,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
     'moodle/question:import' => array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_COURSE,
index 083a1388e90c661e93af58c78b1c29d34ecffaf4..24e4867cdc93f2588ae78fbc11a4caea1b195f8f 100644 (file)
@@ -3003,6 +3003,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
     static $isteacher;
     static $isadmin;
 
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (empty($string)) {     // Cache all the strings for the rest of the page
 
         $string->email       = get_string('email');
@@ -3044,7 +3045,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
     $output .= print_user_picture($user->id, $course->id, $user->picture, true, true);
     $output .= '</td>';
     $output .= '<td class="content">';
-    $output .= '<div class="username">'.fullname($user, $isteacher).'</div>';
+    $output .= '<div class="username">'.fullname($user, has_capability('moodle/site:viewfullnames', $context)).'</div>';
     $output .= '<div class="info">';
     if (!empty($user->role) and ($user->role <> $course->teacher)) {
         $output .= $string->role .': '. $user->role .'<br />';
@@ -3141,16 +3142,16 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
     }
 
     static $isteacheredit;
-
+    $context = get_context_instance(CONTEXT_COURSE, $courseid);
     if (!isset($isteacheredit)) {
         $isteacheredit = isteacheredit($courseid);
     }
 
-    if ($group->hidepicture and !$isteacheredit) {
+    if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
         return '';
     }
 
-    if ($link or $isteacheredit) {
+    if ($link or has_capability('moodle/site:accessallgroups', $context)) {
         $output = '<a href="'. $CFG->wwwroot .'/user/index.php?id='. $courseid .'&amp;group='. $group->id .'">';
     } else {
         $output = '';
@@ -3171,7 +3172,7 @@ function print_group_picture($group, $courseid, $large=false, $return=false, $li
                        ' border="0" width="'.$size.'" height="'.$size.'" alt="" title="'.s($group->name).'"/>';
         }
     }
-    if ($link or $isteacheredit) {
+    if ($link or has_capability('moodle/site:accessallgroups', $context)) {
         $output .= '</a>';
     }
 
@@ -3664,7 +3665,7 @@ function update_course_icon($courseid) {
 
     global $CFG, $USER;
 
-    if (isteacheredit($courseid)) {
+    if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
         if (!empty($USER->editing)) {
             $string = get_string('turneditingoff');
             $edit = '0';
@@ -3717,7 +3718,7 @@ function update_module_button($moduleid, $courseid, $string) {
     global $CFG, $USER;
 
 
-    if (isteacheredit($courseid)) {
+    if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_MODULE, $moduleid))) {
         $string = get_string('updatethis', '', $string);
         return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/mod.php\">".
                "<input type=\"hidden\" name=\"update\" value=\"$moduleid\" />".
@@ -3741,7 +3742,7 @@ function update_module_button($moduleid, $courseid, $string) {
 function update_category_button($categoryid) {
     global $CFG, $USER;
 
-    if (iscreator()) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_COURSECAT, $categoryid))) {
         if (!empty($USER->categoryediting)) {
             $string = get_string('turneditingoff');
             $edit = 'off';
@@ -3767,7 +3768,7 @@ function update_category_button($categoryid) {
 function update_categories_button() {
     global $CFG, $USER;
 
-    if (isadmin()) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if (!empty($USER->categoryediting)) {
             $string = get_string('turneditingoff');
             $categoryedit = 'off';
@@ -3790,7 +3791,8 @@ function update_categories_button() {
 function update_categories_search_button($search,$page,$perpage) {
     global $CFG, $USER;
 
-    if (isadmin()) {
+    // not sure if this capability is the best  here
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if (!empty($USER->categoryediting)) {
             $string = get_string("turneditingoff");
             $edit = "off";
@@ -3821,7 +3823,7 @@ function update_categories_search_button($search,$page,$perpage) {
 function update_group_button($courseid, $groupid) {
     global $CFG, $USER;
 
-    if (isteacheredit($courseid)) {
+    if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_GROUP, $groupid))) {
         $string = get_string('editgroupprofile');
         return "<form target=\"$CFG->framename\" method=\"get\" action=\"$CFG->wwwroot/course/group.php\">".
                '<input type="hidden" name="id" value="'. $courseid .'" />'.
@@ -3843,7 +3845,7 @@ function update_group_button($courseid, $groupid) {
 function update_groups_button($courseid) {
     global $CFG, $USER;
 
-    if (isteacheredit($courseid)) {
+    if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $courseid))) {
         if (!empty($USER->groupsediting)) {
             $string = get_string('turneditingoff');
             $edit = 'off';
@@ -3969,7 +3971,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
         if ($mod->section > 0 and $section <> $mod->section) {
             $thissection = $sections[$mod->section];
 
-            if ($thissection->visible or !$course->hiddensections or $isteacher) {
+            if ($thissection->visible or !$course->hiddensections or has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 $thissection->summary = strip_tags(format_string($thissection->summary,true));
                 if ($course->format == 'weeks' or empty($thissection->summary)) {
                     $menu[] = '-------------- '. $strsection ." ". $mod->section .' --------------';
@@ -3986,7 +3988,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
         $section = $mod->section;
 
         //Only add visible or teacher mods to jumpmenu
-        if ($mod->visible or $isteacher) {
+        if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id))) {
             $url = $mod->mod .'/view.php?id='. $mod->cm;
             if ($flag) { // the current mod is the "next" mod
                 $nextmod = $mod;
@@ -4012,7 +4014,7 @@ function navmenu($course, $cm=NULL, $targetwindow='self') {
             $previousmod = $mod;
         }
     }
-    if ($selectmod and $isteacher) {
+    if ($selectmod and has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id))) {
         $logslink = "<td><a target=\"$CFG->framename\" href=".
                     "\"$CFG->wwwroot/course/report/log/index.php?chooselog=1&amp;user=0&amp;date=0&amp;id=$course->id&amp;modid=$selectmod->cm\">".
                     "<img border=\"0\" height=\"16\" width=\"16\" src=\"$CFG->pixpath/i/log.gif\" alt=\"\" /></a></td>";
@@ -4098,7 +4100,7 @@ function navmenulist($course, $sections, $modinfo, $isteacher, $strsection, $str
         $section = $mod->section;
 
         //Only add visible or teacher mods to jumpmenu
-        if ($mod->visible or $isteacher) {
+        if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id))) {
             $url = $mod->mod .'/view.php?id='. $mod->cm;
             if ($flag) { // the current mod is the "next" mod
                 $nextmod = $mod;
index 819151ba64a22dbe4c4258c2d0a452983d38b0c1..dbd44096efc454a01f126fb7d8c9a0dd13cbb4d5 100644 (file)
@@ -14,9 +14,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("You must be an administrator to change themes.");
-    }
+    require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     $CFG->theme = $preview;
 
index 0299c007e8ff2d5b9745d890d61b391688259e25..f50bd124c6e22d6ba109c7585198979d63a1ec83 100644 (file)
@@ -96,7 +96,7 @@
             $mainadmin->id = 0; /// Weird - no primary admin!
         }
         if ((!empty($USER->id) and ($USER->id == $user->id) and !isguest()) or
-            (isadmin() and ($user->id != $mainadmin->id)) ) {
+            (has_capability('moodle/user:editprofile', get_context_instance(CONTEXT_USERID, $user->id)) and ($user->id != $mainadmin->id)) ) {
 
             if(empty($CFG->loginhttps)) {
                 $wwwroot = $CFG->wwwroot;
index a744cfb56747924551f6f6adf81e45139ccb89cd..3340d97fe0b70c7b73b9c623dc5698579a7a6a3e 100644 (file)
     require_login();
 
 /// Remove the following three lines if you want everyone to access it
-    if (!isadmin()) {
-        error("Currently only the administrator can access this page!");
-    }
+    require_capability('moodle/site:config', get_context_instance(CONTEXT_SITE, SITEID));
 
-    
     if (!$users = get_records("user", "picture", "1", "lastaccess DESC", "id,firstname,lastname")) {
         error("no users!");
     }
index 95e6b124b02d573354119254bc076fcfc878c636..da197e5748c2a6c31c0f187a7bc846fa0f25f740 100644 (file)
@@ -7,10 +7,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("Currently only the administrator can access this page!");
-    }
-
+    require_capability('moodle/site:config', get_context_instance(CONTEXT_SITE, SITEID));
     
     if (!$users = get_records("user", "picture", "1", "lastaccess DESC", "id,firstname,lastname")) {
         error("no users!");