]> git.mjollnir.org Git - moodle.git/commitdiff
replacing iscreator() calls with capabilty
authortoyomoyo <toyomoyo>
Tue, 12 Sep 2006 08:56:10 +0000 (08:56 +0000)
committertoyomoyo <toyomoyo>
Tue, 12 Sep 2006 08:56:10 +0000 (08:56 +0000)
16 files changed:
backup/restore_form.html
course/category.php
course/index.php
course/loginas.php
course/search.php
course/teacher.php
lang/en_utf8/docs/coding.html
lib/accesslib.php
lib/datalib.php
lib/weblib.php
question/editlib.php
question/import.php
question/type/rqp/types.php
theme/chameleon/ui/chameleon.php
theme/chameleon/ui/css.php
user/view.php

index 9197809aeef48e609d57b407f71f65794f047b7e..7c5b0ae91382c8fd9ebf3527371ae12fb6e732ea 100644 (file)
@@ -161,7 +161,7 @@ function selectItemInCheckboxByName(formId, checkName, checked ) {
         $restore_restoreto_options[0] = get_string("currentcoursedeleting");
         $restore_restoreto_options[1] = get_string("currentcourseadding");
     } 
-    if (iscreator()) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         $restore_restoreto_options[0] = get_string("existingcoursedeleting");
         $restore_restoreto_options[1] = get_string("existingcourseadding");
         $restore_restoreto_options[2] = get_string("newcourse"); 
index ca3d215bc9fb3db59c4741abc8f9ab860358faa3..dee217456dd93b64f2bb7ffbc935626c5a87bcde 100644 (file)
@@ -30,7 +30,7 @@
         error("Category not known!");
     }
 
-    if (iscreator()) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if ($categoryedit !== -1) {
             $USER->categoryediting = $categoryedit;
         }
     if ($subcategories = get_records("course_categories", "parent", $category->id, "sortorder ASC")) {
         $firstentry = true;
         foreach ($subcategories as $subcategory) {
-            if ($subcategory->visible or iscreator()) {
+            if ($subcategory->visible or has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
                 $subcategorieswereshown = true;
                 if ($firstentry) {
                     echo '<table align="center" border="0" cellspacing="2" cellpadding="4" class="generalbox">';
index 70b4283b2a10e6821878bf8192dfcb1d9512a205..6fbd3808bcd6798e6f08516d641dd1247ea5811e 100644 (file)
@@ -63,7 +63,7 @@
         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
+        if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {       // Print link to create a new course
             print_single_button("edit.php", NULL, get_string("addnewcourse"), "get");
         }
         if (has_capability('moodle/site:approvecourse', get_context_instance(CONTEXT_SYSTEM, SITEID))  and !empty($CFG->enablecourserequests)) {
index 623df4527aef1a2f49b8f0053fe3eabb1207a291..e0ade43c1ab2569d87704024f0ca75f1a4c7481e 100644 (file)
         }
     }
 
-    if ($course->category and !isstudent($course->id, $user) and !isadmin()) {
+    if ($course->category and !has_capability('moodle/course:view', get_context_instance(CONTEXT_COURSE, $course->id), $user) and !isadmin()) {
         error("This student is not in this course!");
     }
 
-    if (iscreator($user)) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID, $user))) {
         error("You can not login as this person!");
     }
 
index c8be73d923d42ce3f75f3b4a0044bd517cc0f372..8b9132ee81a21c6597fb1e3113be666dbd0a6496 100644 (file)
@@ -31,7 +31,7 @@
         require_login();
     }
 
-    if (iscreator()) {
+    if (has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         if ($edit !== -1) {
             $USER->categoryediting = $edit;
             // If the edit mode we are leaving has higher per page than the one we are entering,
 
     $searchform = print_course_search($search, true, "navbar");
 
-    if (!empty($courses) && iscreator()) {
+    if (!empty($courses) && has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         $searchform .= update_categories_search_button($search,$page,$perpage);
     }
  
index 142ca2e75919637f1208cc002bbbf04860ef3308..fb228a911f82b2ecb3081cda1c5e577fba3ce7d0 100644 (file)
@@ -18,7 +18,7 @@
         error("Course ID was incorrect (can't find it)");
     }
 
-    if (!(isteacheredit($course->id) and iscreator()) and 
+    if (!(isteacheredit($course->id) and has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) and 
         !(isteacheredit($course->id) and !empty($CFG->teacherassignteachers) ) ) {
         error("You must be an administrator or course creator to use this page.");
     }
index 06dbae3086cea680ed8696c19b172a825a626aaf..6bea20efe1ebb14771d50648325cda99afc5273a 100644 (file)
@@ -27,7 +27,7 @@
     add your own if necessary.</li>
   <li class="spaced">Each file should include the main config.php file.</li>
   <li class="spaced">Each file should check that the user is authenticated correctly, 
-    using require_login() and isadmin(), isteacher(), iscreator() or isstudent().</li>
+    using the correct has_capability() or required_capability() checks.</li>
   <li class="spaced">All access to databases should use the functions in lib/datalib.php 
     whenever possible - this allows compatibility across a wide range of databases. 
     You should find that almost anything is possible using these functions. If you must write SQL code then make sure it is: cross-platform; restricted to specific functions 
index e390dc47c1c2ba16f2c83c32f3788b28a4d669bc..516f6afb3fc5e933768c137bf5b7d910ce27838a 100755 (executable)
@@ -1805,7 +1805,7 @@ function get_role_context_capability($contextid, $capability, $capabilities) {
  * @param $capabilityname - e.g. mod/choice:readresponses
  */
 function get_capability_string($capabilityname) {
-
+    
     // Typical capabilityname is mod/choice:readresponses
 
     $names = split('/', $capabilityname);
index dcb263228ef2c7294480101fa3427cf4459830b5..6e7c8d23a0035c1c773b51cb065c8c948b2fa8c6 100644 (file)
@@ -502,7 +502,7 @@ function get_courses($categoryid="all", $sort="c.sortorder ASC", $fields="c.*")
         $sqland = "AND ";
     }
     if (!empty($USER->id)) {  // May need to check they are a teacher
-        if (!iscreator()) {
+        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $visiblecourses = "$sqland ((c.visible > 0) OR t.userid = '$USER->id')";
             $teachertable = "LEFT JOIN {$CFG->prefix}user_teachers t ON t.course = c.id";
         }
@@ -555,7 +555,7 @@ function get_courses_page($categoryid="all", $sort="c.sortorder ASC", $fields="c
         $sqland = "AND ";
     }
     if (!empty($USER) and !empty($USER->id)) {  // May need to check they are a teacher
-        if (!iscreator()) {
+        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
             $visiblecourses = "$sqland ((c.visible > 0) OR t.userid = '$USER->id')";
             $teachertable = "LEFT JOIN {$CFG->prefix}user_teachers t ON t.course=c.id";
         }
@@ -726,7 +726,7 @@ function get_categories($parent='none', $sort='sortorder ASC') {
         $categories = get_records('course_categories', 'parent', $parent, $sort);
     }
     if ($categories) {  /// Remove unavailable categories from the list
-        $creator = iscreator();
+        $creator = has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID));
         foreach ($categories as $key => $category) {
             if (!$category->visible) {
                 if (!$creator) {
@@ -1248,12 +1248,15 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user
             if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;};
             
             /// since we are quering the log table for lastaccess time now, can stop doing this? tables are gone
-            if (isstudent($courseid)) {
-                $db->Execute('UPDATE '. $CFG->prefix .'user_students SET timeaccess = \''. $timenow .'\' '.
-                             'WHERE course = \''. $courseid .'\' AND userid = \''. $userid .'\'');
-            } else if (isteacher($courseid, false, false)) {
-                $db->Execute('UPDATE '. $CFG->prefix .'user_teachers SET timeaccess = \''. $timenow .'\' '.
-                             'WHERE course = \''. $courseid .'\' AND userid = \''. $userid .'\'');
+            if (!$record = get_record('user_lastaccess', 'userid', $userid, 'courseid', $courseid)) {
+                $record = new object;
+                $record->userid = $userid;
+                $record->courseid = $courseid;
+                $record->timeaccess = $timenow;
+                return insert_record('user_lastaccess', $record);  
+            } else {
+                $record->timeaccess = $timenow;
+                return update_record('user_lastaccess', $record);
             }
         }
     }
index 0e66df55cfe5ccbf4bf25dadbbc2ab07a3047758..27229b2ac7f9e5c0fd96e7ababb713e2ec75568c 100644 (file)
@@ -3085,7 +3085,7 @@ function print_user($user, $course, $messageselect=false, $return=false) {
     if ($isteacher) {
         $timemidnight = usergetmidnight(time());
         $output .= '<a href="'. $CFG->wwwroot .'/course/user.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->activity .'</a><br />';
-        if (!iscreator($user->id) or ($isadmin and !isadmin($user->id))) {  // Includes admins
+        if (!has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID, $user->id)) or ($isadmin and !isadmin($user->id))) {  // Includes admins
             if ($course->category and isteacheredit($course->id) and isstudent($course->id, $user->id)) {  // Includes admins
                 $output .= '<a href="'. $CFG->wwwroot .'/course/unenrol.php?id='. $course->id .'&amp;user='. $user->id .'">'. $string->unenrol .'</a><br />';
             }
index 962d24c3716dfbc01262256309cd7be53bf2d66b..1b2b26162ea16294c1f8985c6e7ebd3cc939c17e 100644 (file)
@@ -106,7 +106,7 @@ function question_category_menu($courseid, $published=false) {
         $publish = "OR publish = '1'";
     }
 
-    if (!isadmin()) {
+    if (!has_capability('moodle/course:managequestions', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
         $categories = get_records_select("question_categories", "course = '$courseid' $publish", 'parent, sortorder, name ASC');
     } else {
         $categories = get_records_select("question_categories", '', 'parent, sortorder, name ASC');
index af8c87614f402b74dd9357e2ac4eac8abbb0c0ea..32b18bcc1f7cf433a74d970660bb956f7a87a025 100644 (file)
     print_heading_with_help($txt->importquestions, "import", "quiz");
 
     /// Get all the existing categories now
-    if (isadmin()) { // the admin can import into all categories
+    if (has_capability('moodle/course:managequestions', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // the admin can import into all categories
         if (!$categories = get_records_select("question_categories", "course = '{$course->id}' OR publish = '1'", "parent, sortorder, name ASC")) {
             error("Could not find any question categories!"); // Something is really wrong
         }
index 47be8a0629b7bd8a649c6a12b22bda6f45d983c2..4b26ed2dd24d437b9a93ebece715d9542c5a2ecc 100644 (file)
@@ -13,9 +13,7 @@
 
     // Check user admin
     require_login();
-    if (!isadmin()) {
-        error('You need to be an admin user to use this page.', $CFG->wwwroot . '/login/index.php');
-    }
+    require_capability('moodle/course:managequestions', get_context_instance(CONTEXT_SYSTEM, SITEID));
 
     if (!$site = get_site()) {
         error('Site isn\'t defined!');
index 779c0ddc0b3120cbe9d70b3e9cdcc1e1b41f307d..5a8103416a9ee225193eb75b4ad98480a196db40 100644 (file)
@@ -2,7 +2,7 @@
 
    
 if (isset($THEME->chameleonenabled) && $THEME->chameleonenabled) {
-    $chameleon_isadmin = isadmin();
+    $chameleon_isadmin = has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID));
     $chameleon_isteacher = false;
     if (isset($course->id)) {
         $chameleon_courseparam = '?id=' . $course->id;
index ee73c892b09ec53f3252249afcd5c2872ec6d566..a05c565ebbef99b585284a76978855be9a760ee4 100644 (file)
@@ -14,7 +14,7 @@ if ($chameleon_id != 0 && !empty($CFG->allowcoursethemes) && !empty($THEME->cham
     if (!isteacheredit($chameleon_id)) {
         die('CHAMELEON_ERROR Either you are not logged in or you are not allowed to edit this theme');
     }
-} else if (!isadmin()) {
+} else if (!has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
     die('CHAMELEON_ERROR Either you are not logged in or you are not allowed to edit this theme');
 }
 
index 6c916939b23e25e37b9939d57fd6a41558186d8c..3e9de03c35cb6c5706ae7afb42f5a7c668044592 100644 (file)
         echo "</form></td>";
     }
 */
-    if ((isadmin() and !isadmin($user->id)) or (isteacher($course->id) and isstudent($course->id, $user->id) and ($USER->id != $user->id) and !iscreator($user->id))) {
+    if ((isadmin() 
+        and !isadmin($user->id)) or 
+        (isteacher($course->id) 
+        and isstudent($course->id, $user->id) 
+        and ($USER->id != $user->id) 
+        and !has_capability('moodle/course:create', get_context_instance(CONTEXT_SYSTEM, SITEID,$user->id)))) {
+          
         echo "<td nowrap=\"nowrap\"><form action=\"../course/loginas.php\" method=\"get\">";
         echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
         echo "<input type=\"hidden\" name=\"user\" value=\"$user->id\" />";