From 9bd2c8741c1fa4660ac033ffb5c9d9169a43dc83 Mon Sep 17 00:00:00 2001 From: moodler Date: Sun, 29 Dec 2002 14:41:03 +0000 Subject: [PATCH] New function document_file() for fetching documentation from language packs, and a few cleanups to reduce warnings --- lib/moodlelib.php | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index ad0bc02def..cc4d0da8f8 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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 //////////////////////////////////////////////// -- 2.39.5