|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 define('AJAX_SCRIPT', true); 00003 00004 require_once('../../config.php'); 00005 require_once('lib.php'); 00006 require_once($CFG->libdir . '/filelib.php'); 00007 00008 $concept = optional_param('concept', '', PARAM_CLEAN); 00009 $courseid = optional_param('courseid', 0, PARAM_INT); 00010 $eid = optional_param('eid', 0, PARAM_INT); // glossary entry id 00011 $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR); 00012 00013 $url = new moodle_url('/mod/glossary/showentry.php'); 00014 $url->param('concept', $concept); 00015 $url->param('courseid', $courseid); 00016 $url->param('eid', $eid); 00017 $url->param('displayformat', $displayformat); 00018 $PAGE->set_url($url); 00019 00020 if ($CFG->forcelogin) { 00021 require_login(); 00022 } 00023 00024 if ($eid) { 00025 $entry = $DB->get_record('glossary_entries', array('id'=>$eid), '*', MUST_EXIST); 00026 $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid), '*', MUST_EXIST); 00027 $cm = get_coursemodule_from_instance('glossary', $glossary->id, 0, false, MUST_EXIST); 00028 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 00029 require_course_login($course, true, $cm); 00030 $entry->glossaryname = $glossary->name; 00031 $entry->cmid = $cm->id; 00032 $entry->courseid = $cm->course; 00033 $entries = array($entry); 00034 00035 } else if ($concept) { 00036 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); 00037 require_course_login($course); 00038 $entries = glossary_get_entries_search($concept, $courseid); 00039 00040 } else { 00041 print_error('invalidelementid'); 00042 } 00043 00044 if ($entries) { 00045 foreach ($entries as $key => $entry) { 00046 // Need to get the course where the entry is, 00047 // in order to check for visibility/approve permissions there 00048 $entrycourse = $DB->get_record('course', array('id' => $entry->courseid), '*', MUST_EXIST); 00049 $modinfo = get_fast_modinfo($entrycourse); 00050 // make sure the entry is visible 00051 if (empty($modinfo->cms[$entry->cmid]->uservisible)) { 00052 unset($entries[$key]); 00053 continue; 00054 } 00055 // make sure the entry is approved (or approvable by current user) 00056 if (!$entry->approved and ($USER->id != $entry->userid)) { 00057 $context = get_context_instance(CONTEXT_MODULE, $entry->cmid); 00058 if (!has_capability('mod/glossary:approve', $context)) { 00059 unset($entries[$key]); 00060 continue; 00061 } 00062 } 00063 00064 $context = get_context_instance(CONTEXT_MODULE, $entry->cmid); 00065 $definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $context->id, 'mod_glossary', 'entry', $entry->id); 00066 00067 $options = new stdClass(); 00068 $options->para = false; 00069 $options->trusted = $entry->definitiontrust; 00070 $options->context = $context; 00071 $entries[$key]->definition = format_text($definition, $entry->definitionformat, $options); 00072 00073 $entries[$key]->footer = "<p style=\"text-align:right\">» <a href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">".format_string($entry->glossaryname,true)."</a></p>"; 00074 add_to_log($entry->courseid, 'glossary', 'view entry', "showentry.php?eid=$entry->id", $entry->id, $entry->cmid); 00075 } 00076 } 00077 00078 echo $OUTPUT->header(); 00079 00080 $result = new stdClass; 00081 $result->success = true; 00082 $result->entries = $entries; 00083 echo json_encode($result); 00084 00085 echo $OUTPUT->footer(); 00086