Skip to content

Commit

Permalink
New function document_file() for fetching documentation from language
Browse files Browse the repository at this point in the history
packs, and a few cleanups to reduce warnings
  • Loading branch information
moodler committed Dec 29, 2002
1 parent f1dacb2 commit 9bd2c87
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions lib/moodlelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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 ////////////////////////////////////////////////

Expand Down

0 comments on commit 9bd2c87

Please sign in to comment.