Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: becb6e1c07
Fetching contributors…

Cannot retrieve contributors at this time

file 96 lines (81 sloc) 3.71 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
<?php // $Id$
    require_once("../../config.php");
    require_once("lib.php");

    $concept = optional_param('concept', '', PARAM_CLEAN);
    $courseid = optional_param('courseid', 0, PARAM_INT);
    $eid = optional_param('eid', 0, PARAM_INT); // glossary entry id
    $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);

    if ($CFG->forcelogin) {
        require_login();
    }

    if ($eid) {
        if (!$entry = get_record("glossary_entries", "id", $eid)) {
            error('Invalid entry id');
        }
        if (!$glossary = get_record('glossary','id',$entry->glossaryid)) {
            error('Invalid glossary id');
        }
        if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
            error("Could not determine which course module this belonged to!");
        }
        if (!$course = get_record("course", "id", $cm->course)) {
            error('Invalid course id');
        }
        require_course_login($course, true, $cm);
        $entry->glossaryname = $glossary->name;
        $entry->cmid = $cm->id;
        $entry->courseid = $cm->course;
        $entries = array($entry);

    } else if ($concept) {
        if (!$course = get_record("course", "id", $courseid)) {
            error('Invalid course id');
        }
        require_course_login($course);
        $entries = glossary_get_entries_search($concept, $courseid);

    } else {
        error('No valid entry specified');
    }

    if ($entries) {
        foreach ($entries as $key => $entry) {
            // Need to get the course where the entry is,
            // in order to check for visibility/approve permissions there
            if (!$entrycourse = get_record("course", "id", $entry->courseid)) {
                error('Invalid entry course id');
            }
            $modinfo = get_fast_modinfo($entrycourse);
            // make sure the entry is visible
            if (empty($modinfo->cms[$entry->cmid]->uservisible)) {
                unset($entries[$key]);
                continue;
            }
            // make sure the entry is approved (or approvable by current user)
            if (!$entry->approved and ($USER->id != $entry->userid)) {
                $context = get_context_instance(CONTEXT_MODULE, $entry->cmid);
                if (!has_capability('mod/glossary:approve', $context)) {
                    unset($entries[$key]);
                    continue;
                }
            }
            $entries[$key]->footer = "<p style=\"text-align:right\">&raquo;&nbsp;<a href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">".format_string($entry->glossaryname,true)."</a></p>";
add_to_log($entry->courseid, "glossary", "view entry", "showentry.php?eid=$entry->id", $entry->id, $entry->cmid);
}
}

if (!empty($courseid)) {
$strglossaries = get_string("modulenameplural", "glossary");
$strsearch = get_string("search");

$CFG->framename = "newwindow";
$navlinks = array();
$navlinks[] = array('name' => $strglossaries, 'link' => '', 'type' => 'activity');
$navlinks[] = array('name' => $strsearch, 'link' => '', 'type' => 'title');

$navigation = build_navigation($navlinks);

print_header(strip_tags("$course->shortname: $strglossaries $strsearch"), $course->fullname, $navigation, "", "", true, "&nbsp;", "&nbsp;");

} else {
print_header(); // Needs to be something here to allow linking back to the whole glossary
}

if ($entries) {
glossary_print_dynaentry($courseid, $entries, $displayformat);
}

close_window_button();

/// Show one reduced footer
print_footer('none');

?>
Something went wrong with that request. Please try again.