]> git.mjollnir.org Git - moodle.git/commitdiff
adding capabilities
authortoyomoyo <toyomoyo>
Fri, 8 Sep 2006 08:46:26 +0000 (08:46 +0000)
committertoyomoyo <toyomoyo>
Fri, 8 Sep 2006 08:46:26 +0000 (08:46 +0000)
23 files changed:
backup/restorelib.php
course/category.php
course/index.php
course/lib.php
course/pending.php
course/report/log/lib.php
course/report/stats/lib.php
course/report/stats/report.php
filter/algebra/filter.php
filter/tex/filter.php
index.php
lib/datalib.php
lib/db/access.php
lib/pagelib.php
lib/statslib.php
lib/weblib.php
login/change_password.php
login/change_password_form.html
login/index.php
message/history.php
message/search.html
message/send.php
my/pagelib.php

index 7d3d5d569d41d6b265e31c1aceda6d508eb48d4d..f1f37afc585e4f63ae165b5afcba7cb4a7c2e79a 100644 (file)
             $course = get_record("course","id",$restore->course_id); 
             fix_course_sortorder();
             //Make the user a teacher if the course hasn't teachers (bug 2381)
-            if (!isadmin()) {
+            if (!has_capability('moodle/site:restore', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 if (!$checktea = get_records('user_teachers','course', $restore->course_id)) {
                     //Add the teacher to the course
                     $status = add_teacher($USER->id, $restore->course_id);
index 6298381e94ae287bebfdb072585e6a96fbe045eb..ca3d215bc9fb3db59c4741abc8f9ab860358faa3 100644 (file)
@@ -37,7 +37,7 @@
         $navbaritem = update_category_button($category->id);
 
         $creatorediting = !empty($USER->categoryediting);
-        $adminediting = (isadmin() and $creatorediting);
+        $adminediting = (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and $creatorediting);
 
     } else {
         if (!$category->visible) {
@@ -49,7 +49,7 @@
     }
 
 
-    if (isadmin()) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         /// Rename the category if requested
         if (!empty($rename) and confirm_sesskey()) {
             $category->name = $rename;
 
 
     echo '<center>';
-    if (isadmin() and $numcourses > 1) {           /// Print button to re-sort courses by name
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID)) and $numcourses > 1) {           /// Print button to re-sort courses by name
         unset($options);
         $options['id'] = $category->id;
         $options['resort'] = 'name';
index 93ff5b72ecffb13383507ca3b62607bc6ceaf9e8..7a79f85403fa77dbdb6fe82fb4eeff6e2d98ee7b 100644 (file)
@@ -25,7 +25,7 @@
         require_login();
     }
 
-    if (isadmin()) {
+    if (has_capability('moodle/category:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if ($categoryedit !== -1) {
             $USER->categoryediting = $categoryedit;
         }
         }
 
         echo "<center>";
-        if (isloggedin() and !isguest() and !isadmin() and !iscreator()) {  // Print link to request a new course
+        
+        /// I am not sure this context in the next has_capability call is correct. 
+        if (isloggedin() and !isguest() and !has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {  // Print link to request a new course
             print_single_button("request.php", NULL, get_string("courserequest"), "get");
         }
         if (iscreator()) {       // Print link to create a new course
             print_single_button("edit.php", NULL, get_string("addnewcourse"), "get");
         }
-        if (isadmin() and !empty($CFG->enablecourserequests)) {
+        if (has_capability('moodle/site:approvecourse' get_context_instance(CONTEXT_SYSTEM, SITEID)),  and !empty($CFG->enablecourserequests)) {
             print_single_button('pending.php',NULL, get_string('coursespending'),"get");
         }
         echo "</center>";
index d5b99996d4897e5edfbd55cabcd0e02b2c62e68c..927b6aaf3b305855cfe55d2d26539c3527a35eb7 100644 (file)
@@ -43,7 +43,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
             $users[$guest->id] = fullname($guest);
         }
 
-        if (isadmin()) {
+        if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             if ($ccc = get_records("course", "", "", "fullname")) {
                 foreach ($ccc as $cc) {
                     if ($cc->category) {
@@ -144,7 +144,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
         echo "<center>";
         echo "<table>";
 
-        if (isadmin()) {
+        if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
             choose_from_menu ($courses, "id", $course->id, "");
             echo "</td></tr>";
@@ -2090,7 +2090,9 @@ function course_allowed_module($course,$mod) {
     if (empty($course->restrictmodules)) {
         return true;
     }
-    if (isadmin()) {
+    
+    // i am not sure this capability is correct
+    if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         return true;
     }
     if (is_numeric($mod)) {
index a02022b6620d1dbc9ca3737a9e4f3324f92d18ae..a454792b3f44bdfd67626dd66efe9dbd96b0b285 100644 (file)
@@ -8,9 +8,7 @@
 
     require_login();
 
-    if (!isadmin()) {
-        error("Only the admin can use this page");
-    }
+    require_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     $approve      = optional_param('approve', 0, PARAM_INT);
     $reject       = optional_param('reject', 0, PARAM_INT);
index 3a984c0eb3ee8a1f3eeb81d0eef55b27b9ad5d8a..df7f124283c54ad67856cc473675400ff55909b9 100644 (file)
@@ -10,7 +10,8 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
     if ($numcourses < COURSE_MAX_COURSES_PER_DROPDOWN && !$showcourses) {
         $showcourses = 1;
     }
-   
+    
+    $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
    
     /// Setup for group handling.
@@ -55,7 +56,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
         }
     }
 
-    if (isadmin() && $showcourses) {
+    if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) {
         if ($ccc = get_records("course", "", "", "fullname","id,fullname,category")) {
             foreach ($ccc as $cc) {
                 if ($cc->category) {
@@ -102,7 +103,7 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
         }
     }
 
-    if (isadmin() && !$course->category) {
+    if (has_capability('moodle/site:viewreports', $sitecontext) && !$course->category) {
         $activities["site_errors"] = get_string("siteerrors");
         if ($modid === "site_errors") {
             $selectedactivity = "site_errors";
@@ -156,14 +157,14 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate='today'
     echo "<input type=\"hidden\" name=\"chooselog\" value=\"1\" />\n";
     echo "<input type=\"hidden\" name=\"showusers\" value=\"$showusers\" />\n";
     echo "<input type=\"hidden\" name=\"showcourses\" value=\"$showcourses\" />\n";
-    if (isadmin() && $showcourses) { 
+    if (has_capability('moodle/site:viewreports', $sitecontext) && $showcourses) { 
         choose_from_menu ($courses, "id", $course->id, "");
     } else {
         //        echo '<input type="hidden" name="id" value="'.$course->id.'" />';
         $courses = array();
         $courses[$course->id] = $course->fullname . ((empty($course->category)) ? ' (Site) ' : '');
         choose_from_menu($courses,"id",$course->id,false);
-        if (isadmin()) {
+        if (has_capability('moodle/site:viewreports', $sitecontext)) {
             $a->url = "$CFG->wwwroot/course/report/log/index.php?chooselog=0&group=$selectedgroup&user=$selecteduser"
                 ."&id=$course->id&date=$selecteddate&modid=$selectedactivity&showcourses=1&showusers=$showusers";
             print_string('logtoomanycourses','moodle',$a);
index be2f16efb418ab93be7735b9e8c63787b8c69604..b8ec0a97422c63de50f2184d8f24660d7faa32d0 100644 (file)
@@ -21,7 +21,7 @@
         $options = array();
         $options[STATS_MODE_GENERAL] = get_string('statsmodegeneral');
         $options[STATS_MODE_DETAILED] = get_string('statsmodedetailed');
-        if (isadmin()) {
+        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $options[STATS_MODE_RANKED] = get_string('reports');
         }
 
index f25bf74db05f8c64a0e25c38aa010fdbc332fd3b..cfbc8122900324604028965518084028cb6a91cd 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+    // all queries on teacher table will break (i mean already broken)
+
     $courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname');
     $courseoptions = array();
 
@@ -24,7 +26,7 @@
             $param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string.
             $sql =  'SELECT DISTINCT s.userid,s.roleid,u.firstname,u.lastname,u.idnumber  FROM '.$CFG->prefix.'stats_user_'.$param->table.' s JOIN '.$CFG->prefix.'user u ON u.id = s.userid '
                 .'WHERE courseid = '.$course->id.' AND timeend >= '.$param->timeafter  . ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '');
-            if (!isadmin()) {
+            if (!has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 $sql .= ' AND (s.roleid = 1 OR s.userid = '.$USER->id .")";
             }
             $sql .= " ORDER BY s.roleid ";
@@ -47,7 +49,7 @@
             $users[$u->userid] = $role.' - '.fullname($u,true);
         }
         if (empty($time)) {
-            if (isadmin()) {
+            if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 $sql = 'SELECT t.userid,u.firstname,u.lastname,u.idnumber,1 AS roleid FROM '.$CFG->prefix.'user_teachers t JOIN '.$CFG->prefix.'user u ON u.id = t.userid WHERE course = '.$course->id;
                 $moreusers = get_records_sql($sql);
                 foreach ($moreusers as $u) {
index f4dd3bd7971da11dabc77524120e2489b721e49e..faa3e3e32066f2cd2b06742dc893a29817f77681 100644 (file)
@@ -67,7 +67,7 @@ function string_file_picture_algebra($imagefile, $tex= "", $height="", $width=""
     $width = "width=\"$width\"";
   }
   if ($imagefile) {
-    if (!file_exists("$CFG->dataroot/$CFG->algebrafilterdir/$imagefile") && isadmin()) {
+    if (!file_exists("$CFG->dataroot/$CFG->algebrafilterdir/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
       $output .= "<a href=\"$CFG->wwwroot/$CFG->algebrafilterdir/algebradebug.php\">";
     } else {
       $output .= "<a target=\"popup\" title=\"TeX\" href=";
index c29220ee2533fca447a5cb9e397b586e6eff44ee..2eab2a7b3732f351945f5eeb2a7850b48a9ca10c 100644 (file)
@@ -60,7 +60,7 @@ function string_file_picture_tex($imagefile, $tex= "", $height="", $width="", $a
         $width = "width=\"$width\"";
     }
     if ($imagefile) {
-        if (!file_exists("$CFG->dataroot/$CFG->texfilterdir/$imagefile") && isadmin()) {
+        if (!file_exists("$CFG->dataroot/$CFG->texfilterdir/$imagefile") && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
           $output .= "<a href=\"$CFG->wwwroot/$CFG->texfilterdir/texdebug.php\">";
         } else {
           $output .= "<a target=\"popup\" title=\"TeX\" href=";
index 242c947c6262569f62e089bfbaa9ca4f14c2d268..f81fc3922b8e0364427b81fb6434526e9667b0c3 100644 (file)
--- a/index.php
+++ b/index.php
@@ -48,7 +48,7 @@
         require_login();
     }
 
-    if (isadmin()) {
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if (moodle_needs_upgrading()) {
             redirect($CFG->wwwroot .'/'. $CFG->admin .'/index.php');
         }
 
             case FRONTPAGECOURSELIST:
 
-                if (isloggedin() and !isadmin() and !isguest() and empty($CFG->disablemycourses)) {
+                if (isloggedin() and !has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest() and empty($CFG->disablemycourses)) {
                     print_heading_block(get_string('mycourses'));
                     print_my_moodle();
-                } else if ((!isadmin() and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
+                } else if ((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) and !isguest()) or (count_records('course') <= FRONTPAGECOURSELIMIT)) {
                     // admin should not see list of courses when there are too many of them
                     print_heading_block(get_string('availablecourses'));
                     print_courses(0, '100%', true);
     echo '</td>';
 
     // The right column
-    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || isadmin()) {
+    if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing || has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
-        if (isadmin()) {
+        if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             echo '<div align="center">'.update_course_icon($SITE->id).'</div>';
             echo '<br />';
         }
index 8bf1395cd49448d4f43269b3d4ea1820fe948b83..3303a6e6e0ade7a7cf79596e2a1cc8a92f5b8251 100644 (file)
@@ -1734,7 +1734,7 @@ function count_login_failures($mode, $username, $lastlogin) {
 
     $select = 'module=\'login\' AND action=\'error\' AND time > '. $lastlogin;
 
-    if (isadmin()) {    // Return information about all accounts
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {    // Return information about all accounts
         if ($count->attempts = count_records_select('log', $select)) {
             $count->accounts = count_records_select('log', $select, 'COUNT(DISTINCT info)');
             return $count;
index 7ea3b1e2069879bf9bb6551eb3cd75c9853558d2..56157dc8552f0fbeee79ab79bf958029d2289abb 100644 (file)
@@ -88,6 +88,34 @@ $moodle_capabilities = array(
         )
     ),
     
+    'moodle/site:readallmessages' => array(
+    
+        'captype' => 'read',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_PREVENT,
+            'coursecreator' => CAP_PREVENT,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'moodle/site:approvecourse' => array(
+    
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_SYSTEM,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_PREVENT,
+            'coursecreator' => CAP_PREVENT,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
     'moodle/site:import' => array(
     
         'captype' => 'write',
index 3a19602f9537eb53d5b94e42ed61e6e09b26369e..3fa66ce5e2180066b8f90f43f674af6c0bc64144 100644 (file)
@@ -301,7 +301,7 @@ class page_base {
 
     // is this  page always editable, regardless of anything else?
     function edit_always() {
-        return (isadmin() &&  defined('ADMIN_STICKYBLOCKS'));
+        return (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) &&  defined('ADMIN_STICKYBLOCKS'));
     }
 }
 
@@ -352,7 +352,7 @@ class page_course extends page_base {
     // When is a user said to have "editing rights" in this page? This would have something
     // to do with roles, in the future.
     function user_allowed_editing() {
-        if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+        if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return isteacheredit($this->id);
@@ -361,7 +361,7 @@ class page_course extends page_base {
     // Is the user actually editing this page right now? This would have something
     // to do with roles, in the future.
     function user_is_editing() {
-        if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+        if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return isediting($this->id);
index 48e939d40f10f03b05b96925bf09f4608bcd13bf..47a8d974d699340cace4795d83d87f272c87686a 100644 (file)
@@ -820,13 +820,13 @@ function stats_get_report_options($courseid,$mode) {
     case STATS_MODE_DETAILED:
         $reportoptions[STATS_REPORT_USER_ACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ACTIVITY);
         $reportoptions[STATS_REPORT_USER_ALLACTIVITY] = get_string('statsreport'.STATS_REPORT_USER_ALLACTIVITY);
-        if (isadmin()) {
+        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $site = get_site();
             $reportoptions[STATS_REPORT_USER_LOGINS] = get_string('statsreport'.STATS_REPORT_USER_LOGINS);
         }
         break;
     case STATS_MODE_RANKED:
-        if (isadmin()) {
+        if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $reportoptions[STATS_REPORT_ACTIVE_COURSES] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES);
             $reportoptions[STATS_REPORT_ACTIVE_COURSES_WEIGHTED] = get_string('statsreport'.STATS_REPORT_ACTIVE_COURSES_WEIGHTED);
             $reportoptions[STATS_REPORT_PARTICIPATORY_COURSES] = get_string('statsreport'.STATS_REPORT_PARTICIPATORY_COURSES);
index 48cb54800faefadf63313b5adac7bc108b8d83e3..01ce4f0649aa123df4502229b6d86dc62a7a6c72 100644 (file)
@@ -2109,7 +2109,7 @@ function print_header ($title='', $heading='', $navigation='', $focus='',
                     } else {
                         $menu .= get_string('failedloginattemptsall', '', $count);
                     }
-                    if (isadmin()) {
+                    if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                         $menu .= ' (<a href="'.$CFG->wwwroot.'/course/report/log/index.php'.
                                              '?chooselog=1&amp;id=1&amp;modid=site_errors">'.get_string('logs').'</a>)';
                     }
@@ -2635,7 +2635,7 @@ function print_navigation ($navigation, $return=false) {
         }
         $navigation = '<li title="'.$nav_text.'"><img src="'.$CFG->pixpath.'/a/r_breadcrumb.gif" class="resize" alt="" /> '
             .str_replace('->', '</li><li title="'.$nav_text.'"><img src="'.$CFG->pixpath.'/a/r_breadcrumb.gif" class="resize" alt="" /> ', $navigation)."</li>\n";
-        $output .= '<li class="first"><a target="'. $CFG->framename .'" href="'. $CFG->wwwroot.((!isadmin() && !empty($USER->id) && !empty($CFG->mymoodleredirect) && !isguest())
+        $output .= '<li class="first"><a target="'. $CFG->framename .'" href="'. $CFG->wwwroot.((!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID)) && !empty($USER->id) && !empty($CFG->mymoodleredirect) && !isguest())
                                                                        ? '/my' : '') .'/">'. $site->shortname ."</a></li>\n". $navigation;
         $output .= "</ul>\n";  
     }
index 3ed48e204d986b5a177b7a22ce7316937dfb91f8..845783ce780d5cafd0511db6b8e5fe4474eac803 100644 (file)
@@ -140,10 +140,10 @@ function validate_form($frm, &$err) {
     if (empty($frm->username)){
         $err->username = get_string('missingusername');
     } else {
-        if (!isadmin() and empty($frm->password)){
+        if (!has_capability('moodle/user:update',get_context_instance(CONTEXT_SYSTEM, SITEID)) and empty($frm->password)){
             $err->password = get_string('missingpassword');
         } else {  
-            if (!isadmin()) {
+            if (!has_capability('moodle/user:update',get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 //require non adminusers to give valid password
                 if(!$validpw) {
                     $err->password = get_string('wrongpassword');
@@ -169,7 +169,7 @@ function validate_form($frm, &$err) {
         if ($frm->newpassword1 <> $frm->newpassword2) {
             $err->newpassword2 = get_string('passwordsdiffer');
         } else {
-            if(!isadmin() and ($frm->password === $frm->newpassword1)){
+            if(!has_capability('moodle/user:update',get_context_instance(CONTEXT_SYSTEM, SITEID)) and ($frm->password === $frm->newpassword1)){
                 $err->newpassword1 = get_string('mustchangepassword');
             }
         }
index 38af4fec1953a37e543b8a336e20a010fa0d3386..c9a924c1cdf4f3f57487f1293b1df2419780394e 100644 (file)
@@ -26,7 +26,7 @@
 <tr valign="top">\r
     <td><?php print_string("username") ?>:</td>\r
     <td>\r
-    <?php if (isadmin() || empty($frm->username)) { ?>\r
+    <?php if (has_capability('moodle/user:update',get_context_instance(CONTEXT_SYSTEM, SITEID)) || empty($frm->username)) { ?>\r
         <input type="text" name="username" size="25" value="<?php p($frm->username) ?>" alt="<?php print_string("username") ?>" />\r
     <?php } else { ?>\r
         <input type="hidden" name="username" value="<?php p($frm->username)?>" />  <?php p($frm->username)?>\r
@@ -35,7 +35,7 @@
     </td>\r
 </tr>\r
 \r
-<?php if (!isadmin()) { ?>\r
+<?php if (!ihas_capability('moodle/user:update',get_context_instance(CONTEXT_SYSTEM, SITEID))) { ?>\r
     <tr valign="top">\r
         <td><?php print_string("oldpassword") ?>:</td>\r
         <td><input type="password" name="password" size="25" value="<?php p($frm->password) ?>" alt="<?php print_string("password") ?>" />\r
index 6c1c47b8cb6c7e2ccc4d5f7f7eac6bc83e49b5e2..26d35670fe2937b9901c6b4fa386e607e941e706 100644 (file)
             }
 
           /// Go to my-moodle page instead of homepage if mymoodleredirect enabled
-            if (!isadmin() and !empty($CFG->mymoodleredirect) and !isguest()) {
+            if (!has_capability('moodle/site:config',get_context_instance(CONTEXT_SYSTEM, SITEID)) and !empty($CFG->mymoodleredirect) and !isguest()) {
                 if ($urltogo == $CFG->wwwroot or $urltogo == $CFG->wwwroot.'/' or $urltogo == $CFG->wwwroot.'/index.php') {
                     $urltogo = $CFG->wwwroot.'/my/';
                 }
index 8954763fdc3e93cae2918ad240b433ff524e0f67..322cf2358e43507eba8cc087ab8a20d0e024b762 100644 (file)
@@ -20,7 +20,7 @@
         error("User ID 1 was incorrect");
     }
 
-    if (isadmin()) {             // Able to see any discussion
+    if (has_capability('moodle/site:readmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) {             // Able to see any discussion
         $userid2 = optional_param('user2', $USER->id, PARAM_INT);
         if (! $user2 = get_record("user", "id", $userid2)) {  // Check
             error("User ID 2 was incorrect");
index 84fd00c57e52b482e0f058e9d7f9308998432c51..0d14aac0216565e5efa2459d5db63383f82a7a93 100644 (file)
@@ -43,7 +43,7 @@
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('onlyfromme', 'message') ?>" value="fromme" /><?php print_string('onlyfromme', 'message') ?></td></tr>
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" checked="checked" name="keywordsoption" alt="<?php print_string('allmine', 'message') ?>" value="allmine" /><?php print_string('allmine', 'message') ?></td></tr>
     
-    <?php if (isadmin()) { ?>
+    <?php if (has_capability('moodle/site:readmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) { ?>
     <tr><td>&nbsp;</td><td colspan="2"><input type="radio" name="keywordsoption" alt="<?php print_string('allusers', 'message') ?>" value="allusers" /><?php print_string('allusers', 'message') ?></td></tr>
     <?php } ?>
 
index 0ff850cd0f5ad0c102e2d5081fc478e66e858085..eed40347f09153fdec99558b854f90dbae753ab8 100644 (file)
@@ -46,7 +46,7 @@
 
 /// Check that the user is not blocking us!!
     if ($contact = get_record('message_contacts', 'userid', $user->id, 'contactid', $USER->id)) {
-        if ($contact->blocked and !isadmin()) {
+        if ($contact->blocked and !has_capability('moodle/site:readmessages', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             print_heading(get_string('userisblockingyou', 'message'));
             exit;
         }
index 2195da844c4447d7ca88858cf6b1b58ac4a33a58..a126458a07e5580d548008c77d069992ec249a60 100644 (file)
@@ -12,7 +12,7 @@ class page_my_moodle extends page_base {
         page_id_and_class($id,$class);
         if ($id == PAGE_MY_MOODLE) {
             return true;
-        } else if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+        } else if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return false;
@@ -20,7 +20,7 @@ class page_my_moodle extends page_base {
 
     function user_is_editing() {
         global $USER;
-        if (isadmin() && defined('ADMIN_STICKYBLOCKS')) {
+        if (has_capability('moodle/site:manageblocks', get_context_instance(CONTEXT_SYSTEM, SITEID)) && defined('ADMIN_STICKYBLOCKS')) {
             return true;
         }
         return (!empty($USER->editing));