]> git.mjollnir.org Git - moodle.git/commitdiff
fixed isadmin so that it checks once on each page view if the user is an admin
authorgregb_cc <gregb_cc>
Thu, 1 May 2003 23:12:05 +0000 (23:12 +0000)
committergregb_cc <gregb_cc>
Thu, 1 May 2003 23:12:05 +0000 (23:12 +0000)
fixed check_gd_version to properly identify bundled gd versions (old
check_gd_version was returning 0 instead of 2 for bundled gd).

lib/moodlelib.php

index eb667a14f9e24fcba6cef303c5b31bcb8ff65cd5..dc3a52b97fc50e5abf82d23555b023f44b5bb7dc 100644 (file)
@@ -366,26 +366,32 @@ function reset_login_count() {
     $SESSION->logincount = 0;
 }
 
-
-function isadmin($userid=0) {
+function isadmin($userid=false) {
 /// Is the user an admin?
     global $USER;
+    static $admins = array();
+    static $nonadmins = array();
 
     if (empty($USER->id)) {
         return false;
     }
 
-    if (empty($userid)) {
-        if (!empty($USER->admin)) {
-            return true;
-        }
-        return record_exists("user_admins", "userid", $USER->id);
+    $checkid = $userid ? $userid : $USER->id;
+
+    if (in_array($checkid, $admins)) {
+        return true;
+    } elseif (in_array($ceckid, $nonadmins)) {
+        return false;
+    } elseif (record_exists("user_admins", "userid", $checkid)){
+        $admins[] = $checkid;
+        return true;
+    } else {
+        $nonadmins[] = $checkid;
+        return false;
     }
 
-    return record_exists("user_admins", "userid", $userid);
 }
 
-
 function isteacher($courseid, $userid=0) {
 /// Is the user a teacher or admin?
     global $USER;
@@ -1193,26 +1199,34 @@ function can_use_richtext_editor() {
 
 function check_gd_version() {
 /// Hack to find out the GD version by parsing phpinfo output
-    ob_start();
-    phpinfo(8);
-    $phpinfo = ob_get_contents();
-    ob_end_clean();
+    $gdversion = 0;
 
-    $phpinfo = explode("\n",$phpinfo);
+    if (function_exists('gd_info')){
+        $gd_info = gd_info();
+        /// THIS IS UGLY AND NEEDS TO BE IMPROVED
+        if($gd_info['GD Version'] == 'bundled (2.0 compatible)'){
+            $gdversion = 2;
+        }
+    } else {
+        ob_start();
+        phpinfo(8);
+        $phpinfo = ob_get_contents();
+        ob_end_clean();
 
-    $gdversion = 0;
+        $phpinfo = explode("\n",$phpinfo);
 
 
-    foreach ($phpinfo as $text) {
-        $parts = explode('</td>',$text);
-        foreach ($parts as $key => $val) {
-            $parts[$key] = trim(strip_tags($val));
-        }
-        if ($parts[0] == "GD Version") {
-            if (substr_count($parts[1], "2.0")) {
-                $parts[1] = "2.0";
+        foreach ($phpinfo as $text) {
+            $parts = explode('</td>',$text);
+            foreach ($parts as $key => $val) {
+                $parts[$key] = trim(strip_tags($val));
+            }
+            if ($parts[0] == "GD Version") {
+                if (substr_count($parts[1], "2.0")) {
+                    $parts[1] = "2.0";
+                }
+                $gdversion = intval($parts[1]);
             }
-            $gdversion = intval($parts[1]);
         }
     }