]> git.mjollnir.org Git - moodle.git/commitdiff
replacing deprecated calls and references to capability calls
authortoyomoyo <toyomoyo>
Wed, 20 Sep 2006 09:00:04 +0000 (09:00 +0000)
committertoyomoyo <toyomoyo>
Wed, 20 Sep 2006 09:00:04 +0000 (09:00 +0000)
17 files changed:
course/category.php
grade/exceptions.php
lib/accesslib.php
lib/db/access.php
lib/deprecatedlib.php
lib/editor/htmlarea/popups/insert_image.php
lib/editor/htmlarea/popups/link.php
lib/editor/htmlarea/popups/link_std.php
lib/editor/htmlarea/popups/preview.php
lib/editor/tinymce/tinymce.class.php
lib/weblib.php
mod/data/preset.php
mod/hotpot/view.php
mod/quiz/report/overview/report.php
mod/resource/type/ims/finder.php
mod/resource/type/ims/repository_deploy.php
user/view.php

index f25e5e05623cb57fc4e9d123d4aaa0e2c6e21d19..6bd757a899d8f1cb72e06ddecad788d27bfced0f 100644 (file)
@@ -21,7 +21,9 @@
     if (!$site = get_site()) {
         error("Site isn't defined!");
     }
-
+    
+    $context = get_context_instance(CONTEXT_COURSECAT, $id);
+    
     if ($CFG->forcelogin) {
         require_login();
     }
                      "<a href=\"index.php\">$strcategories</a> -> $category->name", "", "", true, $navbaritem);
     }
 
+/// Print link to roles
+    print('<a href="'.$CFG->wwwroot.'/admin/roles/assign.php?contextid='.$context->id.'">'.get_string('roles').'</a>');
+
 /// Print the category selector
 
     $displaylist = array();
index 3ac4a6e90602621df27085782d72be5528bb0800..90657b3eeff70ac55bd4fbd9977ca6fecdf9a347 100644 (file)
     exit;
     
 function grade_get_grade_item_exceptions($id) {
-    global $CFG;
-    global $course;
     
-    $sql = "SELECT ge.id, ge.userid FROM {$CFG->prefix}grade_exceptions ge, {$CFG->prefix}user_students us WHERE us.course=$course->id AND grade_itemid=$id AND ge.userid = us.userid AND us.course=ge.courseid";
-    $grade_exceptions = get_records_sql($sql);
-    return $grade_exceptions;
+    global $CFG, $course;
+
+    $contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id));
+    
+    $sql = "SELECT ge.id, ge.userid 
+            FROM {$CFG->prefix}grade_exceptions ge,
+                 {$CFG->prefix}role_assignments ra 
+            WHERE grade_itemid = $id 
+                  AND ge.userid = ra.userid 
+                  AND ra.contextid $contextlists";
+    
+    return get_records_sql($sql);
 }
 
 ?>
index 89c30a18e23b5355e5925121bb61be8a788c0eca..a961b709f2f99305c8d76dce9d6c63d730a359c2 100755 (executable)
@@ -1984,10 +1984,11 @@ function fetch_context_independent_capabilities() {
  * context.
  * @param obj $context
  * @param int $roleid
+ * @param bool self - if set to true, resolve till this level, else stop at immediate parent level
  * @return array
  */
 function role_context_capabilities($roleid, $context, $cap='') {
-    global $CFG; 
+    global $CFG;
     
     $contexts = get_parent_contexts($context);
     $contexts[] = $context->id;
@@ -1999,11 +2000,14 @@ function role_context_capabilities($roleid, $context, $cap='') {
         $search = '';  
     }
     
-    $SQL = "SELECT rc.* FROM {$CFG->prefix}role_capabilities rc, {$CFG->prefix}context c
-            where rc.contextid in $contexts
-            and rc.roleid = $roleid
-            and rc.contextid = c.id $search
-            ORDER BY c.aggregatelevel DESC, rc.capability DESC";
+    $SQL = "SELECT rc.* 
+            FROM {$CFG->prefix}role_capabilities rc, 
+                 {$CFG->prefix}context c
+            WHERE rc.contextid in $contexts
+                 AND rc.roleid = $roleid
+                 AND rc.contextid = c.id $search
+            ORDER BY c.aggregatelevel DESC, 
+                     rc.capability DESC";  
 
     $capabilities = array();
     
index 13fa9c6299e4055989bd6b07821694795e69750e..c590a5dcb883ac0230d0d503ab5cb9e5e8ecea24 100644 (file)
@@ -976,7 +976,20 @@ $moodle_capabilities = array(
             'admin' => CAP_ALLOW
         )
     ),
-    
+   
+    'moodle/course:useremail' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_PREVENT,
+            'admin' => CAP_ALLOW
+        )
+    ),
+      
     'moodle/course:viewhiddensections' => array(
         'captype' => 'write',
         'contextlevel' => CONTEXT_COURSE,
index b48f0e43bee31d93a2ba02efb829ba395ed7d95a..d8bac0897878c86904913299dc9319f38512ee66 100644 (file)
@@ -428,15 +428,7 @@ function remove_teacher($userid, $courseid=0) {
             }
         }
 
-        /// Next if the teacher is not registered as a student, but is
-        /// a member of a group, remove them from the group.
-        if (!isstudent($courseid, $userid)) {
-            if ($groups = get_groups($courseid, $userid)) {
-                foreach ($groups as $group) {
-                    delete_records('groups_members', 'groupid', $group->id, 'userid', $userid);
-                }
-            }
-        }
+        /// No need to remove from groups now
 
         foreach ($roles as $role) {    // Unassign them from all the teacher roles
             $newreturn = role_unassign($role->id, $userid, 0, $context->id);
index ecbfd127c41f3c763f1de224e2547f2398799ceb..b4c1d0c0af0b4fe35466508ecdd0867a253a39bb 100644 (file)
@@ -262,12 +262,12 @@ form { margin-bottom: 0px; margin-top: 0px; }
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td width="55%" valign="top"><?php
-      if(isteacher($id)) {
+      if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
           print_string("filebrowser","editor");
       } else {
           print "";
       }?><br />
-      <?php print(isteacher($id))?
+      <?php has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))?
       "<iframe id=\"ibrowser\" name=\"ibrowser\" src=\"".$CFG->wwwroot."/lib/editor/htmlarea/coursefiles.php?usecheckboxes=1&id=".$course->id."\" style=\"width: 100%; height: 200px;\"></iframe>":
       "";?>
       </td>
@@ -279,7 +279,7 @@ form { margin-bottom: 0px; margin-top: 0px; }
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
       <tr>
         <td width="55%"><div class="space"></div>
-        <?php if(isteacher($id)) { ?>
+        <?php if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
         <table border="0" cellpadding="2" cellspacing="0">
           <tr><td><?php print_string("selection","editor");?>: </td>
           <td><form name="idelete" id="idelete">
@@ -315,7 +315,7 @@ form { margin-bottom: 0px; margin-top: 0px; }
     </tr>
     <tr>
       <td height="22"><?php
-      if(isteacher($id)) { ?>
+      if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
           <form name="cfolder" id="cfolder" action="../coursefiles.php" method="post" target="ibrowser">
           <input type="hidden" name="id" value="<?php print($course->id);?>" />
           <input type="hidden" name="wdir" value="" />
index 5cd2a60e1f0b88b3bf7822df968e6602fefe49d5..48995ca14940c44c7f23b086d2beaf0a2afa3ef9 100644 (file)
@@ -79,14 +79,14 @@ form { margin-bottom: 1px; margin-top: 1px; }
     <tr>
       <td width="450" valign="top"><fieldset>
         <legend><?php
-        if(isteacher($id)) {
+        if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
             print_string("filebrowser","editor");
         } else {
             print "";
         }?></legend>
 
         <div class="space"></div>
-        <?php print(isteacher($id))?
+        <?php print(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id)))?
         "<iframe id=\"fbrowser\" name=\"fbrowser\" src=\"../coursefiles.php?id=".$course->id."\" width=\"420\" height=\"180\"></iframe>":
         ""; ?>
         <p>
@@ -124,7 +124,7 @@ form { margin-bottom: 1px; margin-top: 1px; }
     <table border="0" cellpadding="1" cellspacing="1">
     <tr>
       <td height="22"><?php
-      if(isteacher($id)) { ?>
+      if(has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) { ?>
           <form name="cfolder" id="cfolder" action="../coursefiles.php" method="post" target="fbrowser">
           <input type="hidden" name="id" value="<?php print($course->id);?>" />
           <input type="hidden" name="wdir" value="" />
index f30fddfa916106713394240df8cf6be0cea4e0be..eb8080ee8db818e35e6432f12bf0cf91eebdcb27 100644 (file)
@@ -3,10 +3,7 @@
 
     $id = required_param('id', PARAM_INT);
 
-    if ($course = get_record("course", "id", $id)) {
-        $isteacher = isteacher($course->id);
-    } else {
-        $isteacher = false;
+    if (!$course = get_record("course", "id", $id)) {
         $course->fullname = "";   // Just to keep display happy, though browsing may fail
     }
 ?>
@@ -177,7 +174,7 @@ border-bottom: 1px solid black; letter-spacing: 2px;
 </table>
 
 <div id="buttons">
-  <?php if ($isteacher) {
+  <?php if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $id))) {
             echo "<button type=\"button\" name=\"browse\" onclick=\"return onBrowse();\">".get_string("browse","editor")."...</button>";
         }
   ?>
index 553eda90b0478c6fbd797a3b2ba83360aa7e028e..f4e02e152183ae36569fe4d791f751b56fb9e874 100644 (file)
     }
 
     require_login($course->id);
-
-    if (!isteacher($course->id)) {
-        error("Only teachers can use this functionality");
-    }
+    require_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id));
 
     $imagetag = clean_text('<img src="'.htmlSpecialChars(stripslashes_safe($imageurl)).'" alt="" />');
 
index 17e1222a1a9d4df95b89d1af87c8fc02d6fe3def..ab89d9b3c946f94e5f6f1f137949ecb2c6261aed 100644 (file)
@@ -95,7 +95,7 @@ class tinymce extends editorObject {
                               $this->cfg->tinymcepopupcss : '',
             "editor_css"   => !empty($this->cfg->tinymceeditorcss) ?
                               $this->cfg->tinymceeditorcss : '',
-            "file_browser_callback" => $isteacher ? 'moodleFileBrowser' : '',
+            "file_browser_callback" => has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? 'moodleFileBrowser' : '',
             "convert_urls"  => false,
             "relative_urls" => false);
 
@@ -112,7 +112,7 @@ class tinymce extends editorObject {
                 $this->defaults['theme_advanced_resize_horizontal'] = true;
             }
 
-            $this->printdialogs = $isteacher ? true : false;
+            $this->printdialogs = has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $courseid)) ? true : false;
     }
 
     /**
index 65da4f2063914c81fb342bf5cbbfe16fdceacb45..8b8d6b10a914df5e57d04f5bc3dc540b496af6db 100644 (file)
@@ -3036,8 +3036,8 @@ function print_user($user, $course, $messageselect=false, $return=false) {
     static $string;
     static $datestring;
     static $countries;
-    static $isteacher;
     static $isadmin;
+    static $isteacher;
 
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
     if (empty($string)) {     // Cache all the strings for the rest of the page
@@ -3063,7 +3063,6 @@ function print_user($user, $course, $messageselect=false, $return=false) {
         $datestring->secs    = get_string('secs');
 
         $countries = get_list_of_countries();
-
         $isteacher = isteacher($course->id);
         $isadmin   = isadmin();
     }
@@ -3086,7 +3085,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
     if (!empty($user->role) and ($user->role <> $course->teacher)) {
         $output .= $string->role .': '. $user->role .'<br />';
     }
-    if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or $isteacher) {
+    if ($user->maildisplay == 1 or ($user->maildisplay == 2 and $course->category and !isguest()) or has_capability('moodle/course:viewhiddenuserfields', get_context_instance(CONTEXT_COURSE, $course->id))) {
         $output .= $string->email .': <a href="mailto:'. $user->email .'">'. $user->email .'</a><br />';
     }
     if (($user->city or $user->country) and (!isset($hiddenfields['city']) or !isset($hiddenfields['country']))) {
@@ -3117,7 +3116,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
         $output .= '<a href="'.$CFG->wwwroot.'/blog/index.php?userid='.$user->id.'">'.get_string('blogs','blog').'</a><br />';
     }
 
-    if ($isteacher) {
+    if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $course->id))) {
         $timemidnight = usergetmidnight(time());
         $output .= '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->activity .'</a><br />';
         if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID, $user->id)) or ($isadmin and !isadmin($user->id))) {  // Includes admins
@@ -3177,11 +3176,7 @@ 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 !has_capability('moodle/course:managegroups', $context)) {
         return '';
index d38ab83e40a5d30f1b4ec3fcc37ca6271e64ea87..cf0b55f130cfba3de616e81acaea9c0208f37e5d 100644 (file)
@@ -144,7 +144,7 @@ switch ($action) {
         }
         echo "</td><td><input type='submit' value='$strchoose'></td></form>";
         echo "<td>";
-        if ($preset->user == $USER->id || isadmin()) {
+        if ($preset->user == $USER->id || has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             echo "<form action='' method='POST'>";
             echo "<input type='hidden' name='d' value='$data->id' />";
             echo "<input type='hidden' name='action' value='confirmdelete' />";
index 8e2d76f789675dbabed4551871abc1e2247e3a6b..af1a0d31fdd87946b36a289293878f15cace6623 100644 (file)
 ///////////////////////////////////
 function hotpot_feedback_teachers(&$course, &$hotpot) {
     global $CFG;
-    $teachers = get_records_sql("
-        SELECT 
-            u.*
-        FROM 
-            {$CFG->prefix}user AS u, 
-            {$CFG->prefix}user_teachers AS t
-        WHERE 
-            t.userid = u.id
-            AND t.course = $course->id 
-    ");
+    $teachers = get_users_by_capability(get_context_instance(CONTEXT_COURSE, $course->id), 'mod/hotpot:grade');
     $teacherdetails = '';
     if (!empty($teachers)) {
         $details = array();
index f657d0d8cdbf0cbe72572e7ca21ade2272ff1630..febf8c1a606714f547445eea94dd0db300a43170 100644 (file)
@@ -239,6 +239,8 @@ class quiz_report extends quiz_default_report {
             }
             echo $headers." \n";
         }
+        
+        $contextlists = get_related_contexts_string(get_context_instance(CONTEXT_COURSE, $course->id));
 
         // Construct the SQL
         $select = 'SELECT '.$db->Concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, '.
@@ -248,15 +250,15 @@ class quiz_report extends quiz_default_report {
             if (!empty($currentgroup) && empty($noattempts)) {
                 // we want a particular group and we only want to see students WITH attempts.
                 // So join on groups_members and do an inner join on attempts.
-                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
+                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
                     'JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
-                $where = ' WHERE  us.course = '.$course->id.' AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';                
+                $where = ' WHERE ra.contextid $contextlists AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';                
             } else if (!empty($currentgroup) && !empty($noattempts)) {
                 // We want a particular group and we want to do something funky with attempts
                 // So join on groups_members and left join on attempts... 
-                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
+                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id JOIN '.$CFG->prefix.'groups_members gm ON u.id = gm.userid '.
                     'LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
-                $where = ' WHERE us.course = '.$course->id.' AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
+                $where = ' WHERE ra.contextid $contextlists AND gm.groupid = '.$currentgroup.' AND qa.preview = 0';
                 if ($noattempts == 1) {
                     // noattempts = 1 means only no attempts, so make the left join ask for only records where the right is null (no attempts)
                     $where .= ' AND qa.userid IS NULL'; // show ONLY no attempts;
@@ -264,8 +266,8 @@ class quiz_report extends quiz_default_report {
             } else if (empty($currentgroup)) {
                 // We don't care about group, and we to do something funky with attempts
                 // So do a left join on attempts
-                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'user_students us ON us.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
-                $where = " WHERE us.course = '$course->id'";
+                $from  = 'FROM '.$CFG->prefix.'user u JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON u.id = qa.userid AND qa.quiz = '.$quiz->id;
+                $where = " WHERE ra.contextid $contextlists";
                 if (empty($noattempts)) {
                     $where .= ' AND qa.userid IS NOT NULL'; // show ONLY students with attempts;
                 } else if ($noattempts == 1) {
index d05b46210d021faa220a82d4b5d6b7f21f9bfa61..554864a65347ffb3ce1b00096ce11f7476c89ee9 100644 (file)
@@ -62,7 +62,7 @@
     ims_print_crumbtrail($directory);
     
 /// If admin, add extra buttons - redeploy & help.
-    if (isadmin()) {
+    if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         echo " | (<a href=\"repository_deploy.php?file=$directory&all=force\">$strdeployall</a>) ";
         helpbutton("deploy", get_string("deployall", "resource"), "resource", true);
     }
@@ -82,7 +82,7 @@
             }
             else if ($item->type == 'not deployed') {
             /// Only displays non-deployed IMS CP's if admin user.
-                if (isadmin()) {
+                if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                     echo "<li><img src=\"images/ims.gif\" alt=\"IMS CP Package\" /> <em>$item->path - $strnotdeployed</em> (<a href=\"repository_deploy.php?file=$item->path\">$strdeploy</a>)</li>\n";
                 }
             }
index 0e5599c41bb7f586aeb88f19febce63ef5258062..c007db4084dc765ff76848adec8d95f5c2544ca3 100644 (file)
@@ -46,9 +46,7 @@
     require_once('repository_config.php');
     
     /// Security - Admin Only  
-    if (!isadmin()) {
-        error("Not admin!");    
-    }
+    require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))
         
     $file       = required_param ('file', PARAM_PATH);
     $all        = optional_param ('all', '', PARAM_ALPHA);
index 72523c5c8e6f3fe31e7263ac393e327ff31db9d4..dd21c9747159b30d4388e51c286e9d8d8fc96e08 100644 (file)
@@ -52,7 +52,7 @@
        $currentuser = ($user->id == $USER->id);
     }
 
-    if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', $coursecontext)) {   // Groups must be kept separate
+    if (groupmode($course) == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $coursecontext)) {   // Groups must be kept separate
         require_login();
 
         ///this is changed because of mygroupid
@@ -64,8 +64,9 @@
                 }
             }
         }
-        
-        if (!$currentuser && !isteacheredit($course->id, $user->id) && !$gtrue) {
+        // took the teacheredit check out because teacheredit will have moodle/site:accessallgroups capability
+        // which was already checked
+        if (!$currentuser && !$gtrue) {
             print_header("$personalprofile: ", "$personalprofile: ",
                          "<a href=\"../course/view.php?id=$course->id\">$course->shortname</a> ->
                           <a href=\"index.php?id=$course->id\">$participants</a>",
 
         $emailswitch = '';
 
-        if (isteacheredit($course->id) or $currentuser) {   /// Can use the enable/disable email stuff
+        if (has_capability('moodle/course:useremail', get_context_instance(CONTEXT_COURSE, $course->id)) or $currentuser) {   /// Can use the enable/disable email stuff
             if (!empty($enable)) {     /// Recieved a parameter to enable the email address
                 set_field('user', 'emailstop', 0, 'id', $user->id);
                 $user->emailstop = 0;
             }
         }
 
-        if (isteacheredit($course->id)) {   /// Can use the enable/disable email stuff
+        if (has_capability('moodle/course:useremail', get_context_instance(CONTEXT_COURSE, $course->id))) {   /// Can use the enable/disable email stuff
             if ($user->emailstop) {
                 $switchparam = 'enable';
                 $switchtitle = get_string('emaildisable');