]> git.mjollnir.org Git - moodle.git/commitdiff
New function document_file() for fetching documentation from language
authormoodler <moodler>
Sun, 29 Dec 2002 14:41:03 +0000 (14:41 +0000)
committermoodler <moodler>
Sun, 29 Dec 2002 14:41:03 +0000 (14:41 +0000)
packs, and a few cleanups to reduce warnings

lib/moodlelib.php

index ad0bc02defb9d63981e09120f1a89fe96b43d44c..cc4d0da8f802f68dd359b018a7e5fb9a99acca98 100644 (file)
@@ -357,7 +357,11 @@ function isadmin($userid=0) {
 /// Is the user an admin?
     global $USER;
 
-    if (!$userid) {
+    if (empty($USER)) {
+        return false;
+    }
+
+    if (empty($userid)) {
         return record_exists("user_admins", "userid", $USER->id);
     }
 
@@ -374,7 +378,7 @@ function isteacher($courseid, $userid=0) {
     }
 
     if (!$userid) {
-        return $USER->teacher[$courseid];
+        return !empty($USER->teacher[$courseid]);
     }
 
     return record_exists("user_teachers", "userid", $userid, "course", $courseid);
@@ -957,6 +961,35 @@ function get_list_of_languages() {
     return $languages;
 }
 
+function document_file($file, $include=true) {
+/// Can include a given document file (depends on second
+/// parameter) or just return info about it
+
+    global $CFG;
+
+    if (empty($file)) {
+        echo "Error 404";
+        return false;
+    }
+
+    $lang = current_language();
+    $file = clean_filename($file);
+
+    $info->filepath = "$CFG->dirroot/lang/$lang/docs/$file";
+    $info->urlpath  = "$CFG->wwwroot/lang/$lang/docs/$file";
+
+    if (!file_exists($info->filepath)) {
+        $info->filepath = "$CFG->dirroot/lang/en/docs/$file";
+        $info->urlpath  = "$CFG->wwwroot/lang/en/docs/$file";
+    }
+
+    if ($include) {
+        include($info->filepath);
+    }
+
+    return $info;
+}
+
 
 /// ENCRYPTION  ////////////////////////////////////////////////