mod-glossary MDL-19809 Added set_url calls, replaced deprecated functions

This commit is contained in:
samhemelryk 2009-09-24 07:29:14 +00:00
parent cd4e6b1769
commit 5fa0208ec3
16 changed files with 1954 additions and 1791 deletions

View file

@ -1,38 +1,51 @@
<?php // $Id$ <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$eid = optional_param('eid', 0, PARAM_INT); // Entry ID $eid = optional_param('eid', 0, PARAM_INT); // Entry ID
$mode = optional_param('mode','approval', PARAM_ALPHA); $mode = optional_param('mode','approval', PARAM_ALPHA);
$hook = optional_param('hook','ALL', PARAM_CLEAN); $hook = optional_param('hook','ALL', PARAM_CLEAN);
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/approve.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($eid !== 0) {
} $url->param('eid', $eid);
}
if ($mode !== 'approval') {
$url->param('mode', $mode);
}
if ($hook !== 'ALL') {
$url->param('hook', $hook);
}
$PAGE->set_url($url);
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidid', 'glossary'); print_error('coursemisconf');
} }
require_login($course->id, false, $cm); if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id); require_login($course->id, false, $cm);
require_capability('mod/glossary:approve', $context);
$newentry = new object(); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$newentry->id = $eid; require_capability('mod/glossary:approve', $context);
$newentry->approved = 1;
$newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
$DB->update_record("glossary_entries", $newentry); $newentry = new object();
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid",$cm->id); $newentry->id = $eid;
redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook",get_string("entryapproved","glossary"),1); $newentry->approved = 1;
die; $newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
?>
$DB->update_record("glossary_entries", $newentry);
add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&amp;eid=$eid", "$eid",$cm->id);
redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook",get_string("entryapproved","glossary"),1);
die;
?>

View file

@ -1,4 +1,4 @@
<?php // $Id$ <?php
require_once('../../config.php'); require_once('../../config.php');
require_once('lib.php'); require_once('lib.php');
@ -6,7 +6,9 @@ require_once('comment_form.php');
$action = optional_param('action','add', PARAM_ACTION); $action = optional_param('action','add', PARAM_ACTION);
if (isguest()) { $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/comment.php', array('action'=>$action)));
if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
print_error('guestnocomment'); print_error('guestnocomment');
} }
@ -226,7 +228,7 @@ function glossary_comment_print_header($course, $cm, $glossary, $entry, $action)
$PAGE->navbar->add($strcomments, new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$cm->id,'eid'=>$entry->id))); $PAGE->navbar->add($strcomments, new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$cm->id,'eid'=>$entry->id)));
$PAGE->navbar->add($straction); $PAGE->navbar->add($straction);
$PAGE->set_title(format_string($glossary->name)); $PAGE->set_title(format_string($glossary->name));
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->header(); echo $OUTPUT->header();
/// print original glossary entry for any comment action (add, update, delete) /// print original glossary entry for any comment action (add, update, delete)

View file

@ -1,76 +1,78 @@
<?php // $Id$ <?php
/// This page prints a particular instance of glossary /// This page prints a particular instance of glossary
require_once('../../config.php'); require_once('../../config.php');
require_once('lib.php'); require_once('lib.php');
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$eid = required_param('eid', PARAM_INT); // Entry ID $eid = required_param('eid', PARAM_INT); // Entry ID
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$id,'eid'=>$eid)));
print_error('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidcousemodule'); print_error('coursemisconf');
} }
if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidentry'); print_error('invalidcousemodule');
} }
$context = get_context_instance(CONTEXT_MODULE, $cm->id); if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) {
print_error('invalidentry');
}
require_login($course->id, false, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id); require_login($course->id, false, $cm);
$strglossaries = get_string("modulenameplural", "glossary"); add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id);
$strglossary = get_string("modulename", "glossary");
$strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strcomments = get_string("comments", "glossary");
$straddcomment = get_string("addcomment", "glossary");
$PAGE->navbar->add($strcomments); $strglossaries = get_string("modulenameplural", "glossary");
$PAGE->set_title(strip_tags("$strcomments: $entry->concept")); $strglossary = get_string("modulename", "glossary");
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $strallcategories = get_string("allcategories", "glossary");
echo $OUTPUT->header(); $straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strcomments = get_string("comments", "glossary");
$straddcomment = get_string("addcomment", "glossary");
$PAGE->navbar->add($strcomments);
$PAGE->set_title(strip_tags("$strcomments: $entry->concept"));
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->header();
/// original glossary entry /// original glossary entry
echo "<div class=\"boxaligncenter\">"; echo "<div class=\"boxaligncenter\">";
glossary_print_entry($course, $cm, $glossary, $entry, "", "", false); glossary_print_entry($course, $cm, $glossary, $entry, "", "", false);
echo "</div>"; echo "</div>";
/// comments /// comments
echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." <b>\"$entry->concept\"</b>")); echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." <b>\"$entry->concept\"</b>"));
if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
echo $OUTPUT->heading("<a href=\"comment.php?action=add&amp;entryid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>"); echo $OUTPUT->heading("<a href=\"comment.php?action=add&amp;entryid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
} }
if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) { if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) {
foreach ($comments as $comment) { foreach ($comments as $comment) {
glossary_print_comment($course, $cm, $glossary, $entry, $comment); glossary_print_comment($course, $cm, $glossary, $entry, $comment);
echo '<br />'; echo '<br />';
}
} else {
echo $OUTPUT->heading(get_string("nocomments","glossary"));
} }
} else {
echo $OUTPUT->heading(get_string("nocomments","glossary"));
}
/// Finish the page /// Finish the page
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?> ?>

View file

@ -1,106 +1,119 @@
<?php // $Id$ <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); // course module ID $id = required_param('id', PARAM_INT); // course module ID
$confirm = optional_param('confirm', 0, PARAM_INT); // commit the operation? $confirm = optional_param('confirm', 0, PARAM_INT); // commit the operation?
$entry = optional_param('entry', 0, PARAM_INT); // entry id $entry = optional_param('entry', 0, PARAM_INT); // entry id
$prevmode = required_param('prevmode', PARAM_ALPHA); $prevmode = required_param('prevmode', PARAM_ALPHA);
$hook = optional_param('hook', '', PARAM_CLEAN); $hook = optional_param('hook', '', PARAM_CLEAN);
$strglossary = get_string("modulename", "glossary"); $url = new moodle_url($CFG->wwwroot.'/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode));
$strglossaries = get_string("modulenameplural", "glossary"); if ($confirm !== 0) {
$stredit = get_string("edit"); $url->param('confirm', $confirm);
$entrydeleted = get_string("entrydeleted","glossary"); }
if ($entry !== 0) {
$url->param('entry', $entry);
}
if ($hook !== '') {
$url->param('hook', $hook);
}
$PAGE->set_url($url);
$strglossary = get_string("modulename", "glossary");
$strglossaries = get_string("modulenameplural", "glossary");
$stredit = get_string("edit");
$entrydeleted = get_string("entrydeleted","glossary");
if (! $cm = get_coursemodule_from_id('glossary', $id)) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error("invalidcoursemodule"); print_error("invalidcoursemodule");
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) { if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
print_error('invalidentry'); print_error('invalidentry');
} }
require_login($course->id, false, $cm); require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$manageentries = has_capability('mod/glossary:manageentries', $context); $manageentries = has_capability('mod/glossary:manageentries', $context);
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary'); print_error('invalidid', 'glossary');
} }
$strareyousuredelete = get_string("areyousuredelete","glossary"); $strareyousuredelete = get_string("areyousuredelete","glossary");
if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here
print_error('nopermissiontodelentry'); print_error('nopermissiontodelentry');
} }
$ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways);
if (!$ineditperiod and !$manageentries) { if (!$ineditperiod and !$manageentries) {
print_error('errdeltimeexpired', 'glossary'); print_error('errdeltimeexpired', 'glossary');
} }
/// If data submitted, then process and store. /// If data submitted, then process and store.
if ($confirm and confirm_sesskey()) { // the operation was confirmed. if ($confirm and confirm_sesskey()) { // the operation was confirmed.
// if it is an imported entry, just delete the relation // if it is an imported entry, just delete the relation
if ($entry->sourceglossaryid) { if ($entry->sourceglossaryid) {
if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
}
$newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id);
$entry->glossaryid = $entry->sourceglossaryid;
$entry->sourceglossaryid = 0;
$DB->update_record('glossary_entries', $entry);
// move attachments too
$fs = get_file_storage();
if ($oldfiles = $fs->get_area_files($context->id, 'glossary_attachment', $entry->id)) {
foreach ($oldfiles as $oldfile) {
$file_record = new object();
$file_record->contextid = $newcontext->id;
$fs->create_file_from_storedfile($file_record, $oldfile);
}
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$entry->attachment = '1';
} else {
$entry->attachment = '0';
}
$DB->update_record('glossary_entries', $entry);
} else {
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$DB->delete_records("glossary_comments", array("entryid"=>$entry->id));
$DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
$DB->delete_records("glossary_ratings", array("entryid"=>$entry->id));
$DB->delete_records("glossary_entries", array("id"=>$entry->id));
} }
$newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id);
add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook", $entry->id,$cm->id); $entry->glossaryid = $entry->sourceglossaryid;
redirect("view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook"); $entry->sourceglossaryid = 0;
$DB->update_record('glossary_entries', $entry);
} else { // the operation has not been confirmed yet so ask the user to do so // move attachments too
$PAGE->set_title(format_string($glossary->name)); $fs = get_file_storage();
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary));
echo $OUTPUT->header();
$areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>";
$linkyes = 'deleteentry.php';
$linkno = 'view.php';
$optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
$optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); if ($oldfiles = $fs->get_area_files($context->id, 'glossary_attachment', $entry->id)) {
foreach ($oldfiles as $oldfile) {
$file_record = new object();
$file_record->contextid = $newcontext->id;
$fs->create_file_from_storedfile($file_record, $oldfile);
}
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$entry->attachment = '1';
} else {
$entry->attachment = '0';
}
$DB->update_record('glossary_entries', $entry);
echo $OUTPUT->footer(); } else {
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$DB->delete_records("glossary_comments", array("entryid"=>$entry->id));
$DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
$DB->delete_records("glossary_ratings", array("entryid"=>$entry->id));
$DB->delete_records("glossary_entries", array("id"=>$entry->id));
} }
?>
add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook", $entry->id,$cm->id);
redirect("view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook");
} else { // the operation has not been confirmed yet so ask the user to do so
$PAGE->set_title(format_string($glossary->name));
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->header();
$areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>";
$linkyes = 'deleteentry.php';
$linkno = 'view.php';
$optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
$optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
echo $OUTPUT->footer();
}
?>

View file

@ -1,109 +1,131 @@
<?php // $Id$ <?php
/// This page allows to edit entries categories for a particular instance of glossary /// This page allows to edit entries categories for a particular instance of glossary
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID, or $id = required_param('id', PARAM_INT); // Course Module ID, or
$usedynalink = optional_param('usedynalink', 0, PARAM_INT); // category ID $usedynalink = optional_param('usedynalink', 0, PARAM_INT); // category ID
$confirm = optional_param('confirm', 0, PARAM_INT); // confirm the action $confirm = optional_param('confirm', 0, PARAM_INT); // confirm the action
$name = optional_param('name', '', PARAM_CLEAN); // confirm the name $name = optional_param('name', '', PARAM_CLEAN); // confirm the name
$action = optional_param('action', '', PARAM_ALPHA ); // what to do $action = optional_param('action', '', PARAM_ALPHA ); // what to do
$hook = optional_param('hook', '', PARAM_ALPHANUM); // category ID $hook = optional_param('hook', '', PARAM_ALPHANUM); // category ID
$mode = optional_param('mode', '', PARAM_ALPHA); // cat $mode = optional_param('mode', '', PARAM_ALPHA); // cat
$action = strtolower($action); $action = strtolower($action);
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/editcategories.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($usedynalink !== 0) {
} $url->param('usedynalink', $usedynalink);
}
if ($confirm !== 0) {
$url->param('confirm', $confirm);
}
if ($name !== 'name') {
$url->param('name', $name);
}
if ($action !== 'action') {
$url->param('action', $action);
}
if ($hook !== 'hook') {
$url->param('hook', $hook);
}
if ($mode !== 'mode') {
$url->param('mode', $mode);
}
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { $PAGE->set_url($url);
print_error('coursemisconf');
}
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if ($hook > 0) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) { print_error('coursemisconf');
//Check it belongs to the same glossary }
if ($category->glossaryid != $glossary->id) {
print_error('invalidid', 'glossary'); if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
} print_error('invalidcoursemodule');
} else { }
print_error('invalidcategoryid');
if ($hook > 0) {
if ($category = $DB->get_record("glossary_categories", array("id"=>$hook))) {
//Check it belongs to the same glossary
if ($category->glossaryid != $glossary->id) {
print_error('invalidid', 'glossary');
} }
} else {
print_error('invalidcategoryid');
} }
}
require_login($course->id, false, $cm); require_login($course->id, false, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:managecategories', $context); require_capability('mod/glossary:managecategories', $context);
$strglossaries = get_string("modulenameplural", "glossary"); $strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary"); $strglossary = get_string("modulename", "glossary");
$PAGE->navbar->add($strglossaries, new moodle_url($CFG->wwwroot.'/mod/glossary/index.php', array('id'=>$course->id))); $PAGE->navbar->add($strglossaries, new moodle_url($CFG->wwwroot.'/mod/glossary/index.php', array('id'=>$course->id)));
$PAGE->navbar->add(format_string($glossary->name), new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id,'tab'=>'GLOSSARY_CATEGORY_VIEW'))); $PAGE->navbar->add(format_string($glossary->name), new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id,'tab'=>'GLOSSARY_CATEGORY_VIEW')));
$PAGE->navbar->add(get_string("categories","glossary")); $PAGE->navbar->add(get_string("categories","glossary"));
$PAGE->set_title(format_string($glossary->name)); $PAGE->set_title(format_string($glossary->name));
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->header(); echo $OUTPUT->header();
if ( $hook >0 ) { if ( $hook >0 ) {
if ( $action == "edit" ) { if ( $action == "edit" ) {
if ( $confirm ) { if ( $confirm ) {
$action = ""; $action = "";
$cat = new object(); $cat = new object();
$cat->id = $hook; $cat->id = $hook;
$cat->name = $name; $cat->name = $name;
$cat->usedynalink = $usedynalink; $cat->usedynalink = $usedynalink;
$DB->update_record("glossary_categories", $cat); $DB->update_record("glossary_categories", $cat);
add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id); add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id);
} else { } else {
echo "<p style=\"text-align:center\">" . get_string("edit"). " " . get_string("category","glossary") . "<span style=\"font-size:1.5em\">"; echo "<p style=\"text-align:center\">" . get_string("edit"). " " . get_string("category","glossary") . "<span style=\"font-size:1.5em\">";
$name = $category->name; $name = $category->name;
$usedynalink = $category->usedynalink; $usedynalink = $category->usedynalink;
require "editcategories.html"; require "editcategories.html";
echo $OUTPUT->footer(); echo $OUTPUT->footer();
die; die;
}
} elseif ( $action == "delete" ) {
if ( $confirm ) {
$DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
$DB->delete_records("glossary_categories", array("id"=>$hook));
echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>";
echo "</center>";
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
redirect("editcategories.php?id=$cm->id");
} else {
echo "<p style=\"text-align:center\">" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div class=\"boxaligncenter\"><b>".format_text($category->name, FORMAT_PLAIN)."</b><br/>";
$num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
if ( $num_entries ) {
print_string("deletingnoneemptycategory","glossary");
} }
echo "<p>";
} elseif ( $action == "delete" ) { print_string("areyousuredelete","glossary");
if ( $confirm ) { echo "</p>";
$DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
$DB->delete_records("glossary_categories", array("id"=>$hook));
echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div style=\"text-align:center\">" . get_string("categorydeleted","glossary") ."</div>";
echo "</center>";
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id);
redirect("editcategories.php?id=$cm->id");
} else {
echo "<p style=\"text-align:center\">" . get_string("delete"). " " . get_string("category","glossary"). "</p>";
echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div class=\"boxaligncenter\"><b>".format_text($category->name, FORMAT_PLAIN)."</b><br/>";
$num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
if ( $num_entries ) {
print_string("deletingnoneemptycategory","glossary");
}
echo "<p>";
print_string("areyousuredelete","glossary");
echo "</p>";
?> ?>
<table border="0" width="100"> <table border="0" width="100">
@ -123,49 +145,49 @@
<td align="left" style="width:50%"> <td align="left" style="width:50%">
<?php <?php
unset($options); unset($options);
$options = array ("id" => $id); $options = array ("id" => $id);
echo $OUTPUT->button(html_form::make_button("editcategories.php", $options, get_string("no"))); echo $OUTPUT->button(html_form::make_button("editcategories.php", $options, get_string("no")));
echo "</td></tr></table>"; echo "</td></tr></table>";
echo "</div>"; echo "</div>";
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
}
} }
}
} elseif ( $action == "add" ) { } elseif ( $action == "add" ) {
if ( $confirm ) { if ( $confirm ) {
$ILIKE = $DB->sql_ilike(); $ILIKE = $DB->sql_ilike();
$dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id)); $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id));
if ( $dupcategory ) { if ( $dupcategory ) {
echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary"); echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary");
echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
echo "<div style=\"text-align:center\">" . get_string("duplicatedcategory","glossary") ."</div>"; echo "<div style=\"text-align:center\">" . get_string("duplicatedcategory","glossary") ."</div>";
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
redirect("editcategories.php?id=$cm->id&amp;action=add&&amp;name=$name"); redirect("editcategories.php?id=$cm->id&amp;action=add&&amp;name=$name");
} else {
$action = "";
$cat = new object();
$cat->name = $name;
$cat->usedynalink = $usedynalink;
$cat->glossaryid = $glossary->id;
$cat->id = $DB->insert_record("glossary_categories", $cat);
add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
}
} else { } else {
echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary"). "</p>"; $action = "";
$name=""; $cat = new object();
require "editcategories.html"; $cat->name = $name;
} $cat->usedynalink = $usedynalink;
} $cat->glossaryid = $glossary->id;
if ( $action ) { $cat->id = $DB->insert_record("glossary_categories", $cat);
echo $OUTPUT->footer(); add_to_log($course->id, "glossary", "add category", "editcategories.php?id=$cm->id", $cat->id,$cm->id);
die; }
} else {
echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary"). "</p>";
$name="";
require "editcategories.html";
} }
}
if ( $action ) {
echo $OUTPUT->footer();
die;
}
?> ?>

View file

@ -1,51 +1,63 @@
<?php // $Id$ <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$mode= optional_param('mode', '', PARAM_ALPHA); // term entry cat date letter search author approval $mode= optional_param('mode', '', PARAM_ALPHA); // term entry cat date letter search author approval
$hook= optional_param('hook', '', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode $hook= optional_param('hook', '', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode
$cat = optional_param('cat',0, PARAM_ALPHANUM); $cat = optional_param('cat',0, PARAM_ALPHANUM);
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/export.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($cat !== 0) {
} $url->param('cat', $cat);
}
if ($mode !== '') {
$url->param('mode', $mode);
}
if ($hook !== '') {
$url->param('hook', $hook);
}
$PAGE->set_url($url);
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidid', 'glossary'); print_error('coursemisconf');
} }
require_login($course->id, false, $cm); if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id); require_login($course->id, false, $cm);
require_capability('mod/glossary:export', $context);
$strglossaries = get_string("modulenameplural", "glossary"); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$strglossary = get_string("modulename", "glossary"); require_capability('mod/glossary:export', $context);
$strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strexportfile = get_string("exportfile", "glossary");
$strexportentries = get_string('exportentriestoxml', 'glossary');
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/export.php', array('id'=>$cm->id))); $strglossaries = get_string("modulenameplural", "glossary");
$PAGE->navbar->add($strexportentries); $strglossary = get_string("modulename", "glossary");
$PAGE->set_title(format_string($glossary->name)); $strallcategories = get_string("allcategories", "glossary");
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strexportfile = get_string("exportfile", "glossary");
$strexportentries = get_string('exportentriestoxml', 'glossary');
echo $OUTPUT->header(); $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/export.php', array('id'=>$cm->id)));
echo $OUTPUT->heading($strexportentries); $PAGE->navbar->add($strexportentries);
echo $OUTPUT->box_start('glossarydisplay generalbox'); $PAGE->set_title(format_string($glossary->name));
?> $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->header();
echo $OUTPUT->heading($strexportentries);
echo $OUTPUT->box_start('glossarydisplay generalbox');
?>
<form action="exportfile.php" method="post"> <form action="exportfile.php" method="post">
<table border="0" cellpadding="6" cellspacing="6" width="100%"> <table border="0" cellpadding="6" cellspacing="6" width="100%">
<tr><td align="center"> <tr><td align="center">

View file

@ -1,112 +1,123 @@
<?php // $Id$ <?php
require_once('../../config.php');
require_once('lib.php');
$id = required_param('id', PARAM_INT); // Entry ID require_once('../../config.php');
$confirm = optional_param('confirm', 0, PARAM_BOOL); // export confirmation require_once('lib.php');
$prevmode = required_param('prevmode', PARAM_ALPHA);
$hook = optional_param('hook', '', PARAM_CLEAN);
if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id))) { $id = required_param('id', PARAM_INT); // Entry ID
print_error('invalidentry'); $confirm = optional_param('confirm', 0, PARAM_BOOL); // export confirmation
} $prevmode = required_param('prevmode', PARAM_ALPHA);
$hook = optional_param('hook', '', PARAM_CLEAN);
if ($entry->sourceglossaryid) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/exportentry.php', array('id'=>$id,'prevmode'=>$prevmode));
//already exported if ($confirm !== 0) {
if (!$cm = get_coursemodule_from_id('glossary', $entry->sourceglossaryid)) { $url->param('confirm', $confirm);
print_error('invalidcoursemodule'); }
} if ($hook !== 'ALL') {
redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id); $url->param('hook', $hook);
} }
$PAGE->set_url($url);
if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { if (!$entry = $DB->get_record('glossary_entries', array('id'=>$id))) {
print_error('invalidentry');
}
if ($entry->sourceglossaryid) {
//already exported
if (!$cm = get_coursemodule_from_id('glossary', $entry->sourceglossaryid)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
redirect('view.php?id='.$cm->id.'&amp;mode=entry&amp;hook='.$entry->id);
}
if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) { if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) {
print_error('invalidid', 'glossary'); print_error('invalidcoursemodule');
} }
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) {
print_error('coursemisconf'); print_error('invalidid', 'glossary');
} }
require_course_login($course->id, true, $cm); if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id); print_error('coursemisconf');
require_capability('mod/glossary:export', $context); }
$returnurl = "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=".urlencode($hook); require_course_login($course->id, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:export', $context);
if (!$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1))) { $returnurl = "view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=".urlencode($hook);
//main glossary not present
redirect($returnurl);
}
if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) { if (!$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1))) {
print_error('invalidcoursemodule'); //main glossary not present
} redirect($returnurl);
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id); if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) {
$maincontext = get_context_instance(CONTEXT_MODULE, $maincm->id); print_error('invalidcoursemodule');
}
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { $context = get_context_instance(CONTEXT_MODULE, $cm->id);
print_error('coursemisconf'); $maincontext = get_context_instance(CONTEXT_MODULE, $maincm->id);
}
if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
print_error('coursemisconf');
}
$strglossaries = get_string('modulenameplural', 'glossary'); $strglossaries = get_string('modulenameplural', 'glossary');
$entryalreadyexist = get_string('entryalreadyexist','glossary'); $entryalreadyexist = get_string('entryalreadyexist','glossary');
$entryexported = get_string('entryexported','glossary'); $entryexported = get_string('entryexported','glossary');
if (!$mainglossary->allowduplicatedentries) { if (!$mainglossary->allowduplicatedentries) {
if ($DB->get_record('glossary_entries', array('glossaryid'=>$mainglossary->id, 'lower(concept)'=>moodle_strtolower($entry->concept)))) { if ($DB->get_record('glossary_entries', array('glossaryid'=>$mainglossary->id, 'lower(concept)'=>moodle_strtolower($entry->concept)))) {
$PAGE->set_title(format_string($glossary->name));
echo $OUTPUT->header();
echo $OUTPUT->notification(get_string('errconceptalreadyexists', 'glossary'));
echo $OUTPUT->continue_button($returnurl);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
die;
}
}
if (!data_submitted() or !$confirm or !confirm_sesskey()) {
$PAGE->set_title(format_string($glossary->name)); $PAGE->set_title(format_string($glossary->name));
echo $OUTPUT->header(); echo $OUTPUT->header();
echo '<div class="boxaligncenter">'; echo $OUTPUT->notification(get_string('errconceptalreadyexists', 'glossary'));
$areyousure = '<h2>'.format_string($entry->concept).'</h2><p align="center">'.get_string('areyousureexport','glossary').'<br /><b>'.format_string($mainglossary->name).'</b>?'; echo $OUTPUT->continue_button($returnurl);
$linkyes = 'exportentry.php'; echo $OUTPUT->box_end();
$linkno = 'view.php';
$optionsyes = array('id'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
$optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
echo '</div>';
echo $OUTPUT->footer(); echo $OUTPUT->footer();
die; die;
} else {
$entry->glossaryid = $mainglossary->id;
$entry->sourceglossaryid = $glossary->id;
$DB->update_record('glossary_entries', $entry);
// move attachments too
$fs = get_file_storage();
if ($oldfiles = $fs->get_area_files($context->id, 'glossary_attachment', $entry->id)) {
foreach ($oldfiles as $oldfile) {
$file_record = new object();
$file_record->contextid = $maincontext->id;
$fs->create_file_from_storedfile($file_record, $oldfile);
}
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$entry->attachment = '1';
} else {
$entry->attachment = '0';
}
$DB->update_record('glossary_entries', $entry);
redirect ($returnurl);
} }
?> }
if (!data_submitted() or !$confirm or !confirm_sesskey()) {
$PAGE->set_title(format_string($glossary->name));
echo $OUTPUT->header();
echo '<div class="boxaligncenter">';
$areyousure = '<h2>'.format_string($entry->concept).'</h2><p align="center">'.get_string('areyousureexport','glossary').'<br /><b>'.format_string($mainglossary->name).'</b>?';
$linkyes = 'exportentry.php';
$linkno = 'view.php';
$optionsyes = array('id'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
$optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
echo '</div>';
echo $OUTPUT->footer();
die;
} else {
$entry->glossaryid = $mainglossary->id;
$entry->sourceglossaryid = $glossary->id;
$DB->update_record('glossary_entries', $entry);
// move attachments too
$fs = get_file_storage();
if ($oldfiles = $fs->get_area_files($context->id, 'glossary_attachment', $entry->id)) {
foreach ($oldfiles as $oldfile) {
$file_record = new object();
$file_record->contextid = $maincontext->id;
$fs->create_file_from_storedfile($file_record, $oldfile);
}
$fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
$entry->attachment = '1';
} else {
$entry->attachment = '0';
}
$DB->update_record('glossary_entries', $entry);
redirect ($returnurl);
}
?>

View file

@ -1,35 +1,45 @@
<?php // $Id$ <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
// disable moodle specific debug messages // disable moodle specific debug messages
disable_debugging(); disable_debugging();
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$l = optional_param('l','', PARAM_ALPHANUM); $l = optional_param('l','', PARAM_ALPHANUM);
$cat = optional_param('cat',0, PARAM_ALPHANUM); $cat = optional_param('cat',0, PARAM_ALPHANUM);
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/exportfile.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($l !== '') {
} $url->param('l', $l);
}
if ($cat !== 0) {
$url->param('cat', $cat);
}
$PAGE->set_url($url);
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidid', 'glossary'); print_error('coursemisconf');
} }
require_login($course->id, false, $cm); if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
$context = get_context_instance(CONTEXT_MODULE, $cm->id); }
require_capability('mod/glossary:export', $context);
require_login($course->id, false, $cm);
$filename = clean_filename(strip_tags(format_string($glossary->name,true)).'.xml');
$content = glossary_generate_export_file($glossary,$l,$cat); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/glossary:export', $context);
send_file($content, $filename, 0, 0, true, true);
?> $filename = clean_filename(strip_tags(format_string($glossary->name,true)).'.xml');
$content = glossary_generate_export_file($glossary,$l,$cat);
send_file($content, $filename, 0, 0, true, true);
?>

View file

@ -1,255 +1,262 @@
<?php // $Id$ <?php
/// This file allows to manage the default behaviour of the display formats
require_once("../../config.php"); /// This file allows to manage the default behaviour of the display formats
require_once($CFG->libdir.'/adminlib.php');
require_once("lib.php");
$id = required_param('id', PARAM_INT); require_once("../../config.php");
$mode = optional_param('mode', '', PARAM_ACTION); require_once($CFG->libdir.'/adminlib.php');
require_once("lib.php");
admin_externalpage_setup('managemodules'); // this is hacky, tehre should be a special hidden page for it $id = required_param('id', PARAM_INT);
$mode = optional_param('mode', '', PARAM_ACTION);
if ( !$displayformat = $DB->get_record("glossary_formats", array("id"=>$id))) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/formats.php', array('id'=>$id));
print_error('invalidglossaryformat', 'glossary'); if ($mode !== '') {
} $url->param('mode', $mode);
}
$PAGE->set_url($url);
$form = data_submitted(); admin_externalpage_setup('managemodules'); // this is hacky, tehre should be a special hidden page for it
if ( $mode == 'visible' ) {
if ( $displayformat ) {
if ( $displayformat->visible ) {
$displayformat->visible = 0;
} else {
$displayformat->visible = 1;
}
$DB->update_record("glossary_formats",$displayformat);
}
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
die;
} elseif ( $mode == 'edit' and $form) {
$displayformat->popupformatname = $form->popupformatname; if ( !$displayformat = $DB->get_record("glossary_formats", array("id"=>$id))) {
$displayformat->showgroup = $form->showgroup; print_error('invalidglossaryformat', 'glossary');
$displayformat->defaultmode = $form->defaultmode; }
$displayformat->defaulthook = $form->defaulthook;
$displayformat->sortkey = $form->sortkey;
$displayformat->sortorder = $form->sortorder;
$DB->update_record("glossary_formats",$displayformat); $form = data_submitted();
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header"); if ( $mode == 'visible' ) {
die; if ( $displayformat ) {
} if ( $displayformat->visible ) {
$displayformat->visible = 0;
$strmodulename = get_string("modulename", "glossary");
$strdisplayformats = get_string("displayformats","glossary");
admin_externalpage_print_header();
echo $OUTPUT->heading($strmodulename . ': ' . get_string("displayformats","glossary"));
echo $OUTPUT->box(get_string("configwarning", 'admin'), "generalbox boxaligncenter boxwidthnormal");
echo "<br />";
$yes = get_string("yes");
$no = get_string("no");
echo '<form method="post" action="formats.php" id="form">';
echo '<table width="90%" align="center" class="generalbox">';
?>
<tr>
<td colspan="3" align="center"><strong>
<?php echo get_string('displayformat'.$displayformat->name,'glossary'); ?>
</strong></td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('popupformat','glossary'); ?></td>
<td>
<?php
//get and update available formats
$recformats = glossary_get_available_formats();
$formats = array();
//Take names
foreach ($recformats as $format) {
$formats[$format->name] = get_string("displayformat$format->name", "glossary");
}
//Sort it
asort($formats);
echo $OUTPUT->select(html_select::make($formats,'popupformatname',$displayformat->popupformatname));
?>
</td>
<td width="60%">
<?php print_string("cnfrelatedview", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultmode','glossary'); ?></td>
<td>
<select size="1" name="defaultmode">
<?php
$sletter = '';
$scat = '';
$sauthor = '';
$sdate = '';
switch ( strtolower($displayformat->defaultmode) ) {
case 'letter':
$sletter = ' selected="selected" ';
break;
case 'cat':
$scat = ' selected="selected" ';
break;
case 'date':
$sdate = ' selected="selected" ';
break;
case 'author':
$sauthor = ' selected="selected" ';
break;
}
?>
<option value="letter" <?php p($sletter)?>><?php print_string("letter", "glossary"); ?></option>
<option value="cat" <?php p($scat)?>><?php print_string("cat", "glossary"); ?></option>
<option value="date" <?php p($sdate)?>><?php print_string("date", "glossary"); ?></option>
<option value="author" <?php p($sauthor)?>><?php print_string("author", "glossary"); ?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfdefaultmode", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaulthook','glossary'); ?></td>
<td>
<select size="1" name="defaulthook">
<?php
$sall = '';
$sspecial = '';
$sallcategories = '';
$snocategorised = '';
switch ( strtolower($displayformat->defaulthook) ) {
case 'all':
$sall = ' selected="selected" ';
break;
case 'special':
$sspecial = ' selected="selected" ';
break;
case '0':
$sallcategories = ' selected="selected" ';
break;
case '-1':
$snocategorised = ' selected="selected" ';
break;
}
?>
<option value="ALL" <?php p($sall)?>><?php p(get_string("allentries","glossary"))?></option>
<option value="SPECIAL" <?php p($sspecial)?>><?php p(get_string("special","glossary"))?></option>
<option value="0" <?php p($sallcategories)?>><?php p(get_string("allcategories","glossary"))?></option>
<option value="-1" <?php p($snocategorised)?>><?php p(get_string("notcategorised","glossary"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfdefaulthook", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultsortkey','glossary'); ?></td>
<td>
<select size="1" name="sortkey">
<?php
$sfname = '';
$slname = '';
$supdate = '';
$screation = '';
switch ( strtolower($displayformat->sortkey) ) {
case 'firstname':
$sfname = ' selected="selected" ';
break;
case 'lastname':
$slname = ' selected="selected" ';
break;
case 'creation':
$screation = ' selected="selected" ';
break;
case 'update':
$supdate = ' selected="selected" ';
break;
}
?>
<option value="CREATION" <?php p($screation)?>><?php p(get_string("sortbycreation","glossary"))?></option>
<option value="UPDATE" <?php p($supdate)?>><?php p(get_string("sortbylastupdate","glossary"))?></option>
<option value="FIRSTNAME" <?php p($sfname)?>><?php p(get_string("firstname"))?></option>
<option value="LASTNAME" <?php p($slname)?>><?php p(get_string("lastname"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfsortkey", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultsortorder','glossary'); ?></td>
<td>
<select size="1" name="sortorder">
<?php
$sasc = '';
$sdesc = '';
switch ( strtolower($displayformat->sortorder) ) {
case 'asc':
$sasc = ' selected="selected" ';
break;
case 'desc':
$sdesc = ' selected="selected" ';
break;
}
?>
<option value="asc" <?php p($sasc)?>><?php p(get_string("ascending","glossary"))?></option>
<option value="desc" <?php p($sdesc)?>><?php p(get_string("descending","glossary"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfsortorder", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string("includegroupbreaks", "glossary"); ?>:</td>
<td>
<select size="1" name="showgroup">
<?php
$yselected = "";
$nselected = "";
if ($displayformat->showgroup) {
$yselected = " selected=\"selected\" ";
} else { } else {
$nselected = " selected=\"selected\" "; $displayformat->visible = 1;
} }
?> $DB->update_record("glossary_formats",$displayformat);
<option value="1" <?php echo $yselected ?>><?php p($yes)?></option> }
<option value="0" <?php echo $nselected ?>><?php p($no)?></option> redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
</select> die;
</td> } elseif ( $mode == 'edit' and $form) {
<td width="60%">
<?php print_string("cnfshowgroup", "glossary") ?><br /><br />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="<?php print_string("savechanges") ?>" /></td>
</tr>
<input type="hidden" name="id" value="<?php p($id) ?>" />
<input type="hidden" name="mode" value="edit" />
<?php
echo '</table></form>'; $displayformat->popupformatname = $form->popupformatname;
$displayformat->showgroup = $form->showgroup;
$displayformat->defaultmode = $form->defaultmode;
$displayformat->defaulthook = $form->defaulthook;
$displayformat->sortkey = $form->sortkey;
$displayformat->sortorder = $form->sortorder;
echo $OUTPUT->footer(); $DB->update_record("glossary_formats",$displayformat);
redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header");
die;
}
$strmodulename = get_string("modulename", "glossary");
$strdisplayformats = get_string("displayformats","glossary");
admin_externalpage_print_header();
echo $OUTPUT->heading($strmodulename . ': ' . get_string("displayformats","glossary"));
echo $OUTPUT->box(get_string("configwarning", 'admin'), "generalbox boxaligncenter boxwidthnormal");
echo "<br />";
$yes = get_string("yes");
$no = get_string("no");
echo '<form method="post" action="formats.php" id="form">';
echo '<table width="90%" align="center" class="generalbox">';
?> ?>
<tr>
<td colspan="3" align="center"><strong>
<?php echo get_string('displayformat'.$displayformat->name,'glossary'); ?>
</strong></td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('popupformat','glossary'); ?></td>
<td>
<?php
//get and update available formats
$recformats = glossary_get_available_formats();
$formats = array();
//Take names
foreach ($recformats as $format) {
$formats[$format->name] = get_string("displayformat$format->name", "glossary");
}
//Sort it
asort($formats);
echo $OUTPUT->select(html_select::make($formats,'popupformatname',$displayformat->popupformatname));
?>
</td>
<td width="60%">
<?php print_string("cnfrelatedview", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultmode','glossary'); ?></td>
<td>
<select size="1" name="defaultmode">
<?php
$sletter = '';
$scat = '';
$sauthor = '';
$sdate = '';
switch ( strtolower($displayformat->defaultmode) ) {
case 'letter':
$sletter = ' selected="selected" ';
break;
case 'cat':
$scat = ' selected="selected" ';
break;
case 'date':
$sdate = ' selected="selected" ';
break;
case 'author':
$sauthor = ' selected="selected" ';
break;
}
?>
<option value="letter" <?php p($sletter)?>><?php print_string("letter", "glossary"); ?></option>
<option value="cat" <?php p($scat)?>><?php print_string("cat", "glossary"); ?></option>
<option value="date" <?php p($sdate)?>><?php print_string("date", "glossary"); ?></option>
<option value="author" <?php p($sauthor)?>><?php print_string("author", "glossary"); ?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfdefaultmode", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaulthook','glossary'); ?></td>
<td>
<select size="1" name="defaulthook">
<?php
$sall = '';
$sspecial = '';
$sallcategories = '';
$snocategorised = '';
switch ( strtolower($displayformat->defaulthook) ) {
case 'all':
$sall = ' selected="selected" ';
break;
case 'special':
$sspecial = ' selected="selected" ';
break;
case '0':
$sallcategories = ' selected="selected" ';
break;
case '-1':
$snocategorised = ' selected="selected" ';
break;
}
?>
<option value="ALL" <?php p($sall)?>><?php p(get_string("allentries","glossary"))?></option>
<option value="SPECIAL" <?php p($sspecial)?>><?php p(get_string("special","glossary"))?></option>
<option value="0" <?php p($sallcategories)?>><?php p(get_string("allcategories","glossary"))?></option>
<option value="-1" <?php p($snocategorised)?>><?php p(get_string("notcategorised","glossary"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfdefaulthook", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultsortkey','glossary'); ?></td>
<td>
<select size="1" name="sortkey">
<?php
$sfname = '';
$slname = '';
$supdate = '';
$screation = '';
switch ( strtolower($displayformat->sortkey) ) {
case 'firstname':
$sfname = ' selected="selected" ';
break;
case 'lastname':
$slname = ' selected="selected" ';
break;
case 'creation':
$screation = ' selected="selected" ';
break;
case 'update':
$supdate = ' selected="selected" ';
break;
}
?>
<option value="CREATION" <?php p($screation)?>><?php p(get_string("sortbycreation","glossary"))?></option>
<option value="UPDATE" <?php p($supdate)?>><?php p(get_string("sortbylastupdate","glossary"))?></option>
<option value="FIRSTNAME" <?php p($sfname)?>><?php p(get_string("firstname"))?></option>
<option value="LASTNAME" <?php p($slname)?>><?php p(get_string("lastname"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfsortkey", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string('defaultsortorder','glossary'); ?></td>
<td>
<select size="1" name="sortorder">
<?php
$sasc = '';
$sdesc = '';
switch ( strtolower($displayformat->sortorder) ) {
case 'asc':
$sasc = ' selected="selected" ';
break;
case 'desc':
$sdesc = ' selected="selected" ';
break;
}
?>
<option value="asc" <?php p($sasc)?>><?php p(get_string("ascending","glossary"))?></option>
<option value="desc" <?php p($sdesc)?>><?php p(get_string("descending","glossary"))?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfsortorder", "glossary") ?><br /><br />
</td>
</tr>
<tr valign="top">
<td align="right" width="20%"><?php print_string("includegroupbreaks", "glossary"); ?>:</td>
<td>
<select size="1" name="showgroup">
<?php
$yselected = "";
$nselected = "";
if ($displayformat->showgroup) {
$yselected = " selected=\"selected\" ";
} else {
$nselected = " selected=\"selected\" ";
}
?>
<option value="1" <?php echo $yselected ?>><?php p($yes)?></option>
<option value="0" <?php echo $nselected ?>><?php p($no)?></option>
</select>
</td>
<td width="60%">
<?php print_string("cnfshowgroup", "glossary") ?><br /><br />
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="<?php print_string("savechanges") ?>" /></td>
</tr>
<input type="hidden" name="id" value="<?php p($id) ?>" />
<input type="hidden" name="mode" value="edit" />
<?php
echo '</table></form>';
echo $OUTPUT->footer();
?>

View file

@ -1,357 +1,378 @@
<?php // $Id$ <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("$CFG->dirroot/course/lib.php"); require_once("$CFG->dirroot/course/lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$step = optional_param('step', 0, PARAM_INT); $step = optional_param('step', 0, PARAM_INT);
$dest = optional_param('dest', 'current', PARAM_ALPHA); // current | new $dest = optional_param('dest', 'current', PARAM_ALPHA); // current | new
$file = optional_param('file', '', PARAM_FILE); // file to import $file = optional_param('file', '', PARAM_FILE); // file to import
$catsincl = optional_param('catsincl', 0, PARAM_INT); // Import Categories too? $catsincl = optional_param('catsincl', 0, PARAM_INT); // Import Categories too?
$mode = optional_param('mode', 'letter', PARAM_ALPHA ); $mode = optional_param('mode', 'letter', PARAM_ALPHA );
$hook = optional_param('hook', 'ALL', PARAM_ALPHANUM); $hook = optional_param('hook', 'ALL', PARAM_ALPHANUM);
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/import.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($step !== 0) {
} $url->param('step', $step);
}
if ($dest !== 'current') {
$url->param('dest', $dest);
}
if ($file !== '') {
$url->param('file', $file);
}
if ($catsincl !== 0) {
$url->param('catsincl', $catsincl);
}
if ($mode !== 'letter') {
$url->param('mode', $mode);
}
if ($hook !== 'ALL') {
$url->param('hook', $hook);
}
$PAGE->set_url($url);
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidid', 'glossary'); print_error('coursemisconf');
} }
require_login($course->id, false, $cm); if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id); require_login($course->id, false, $cm);
require_capability('mod/glossary:import', $context);
if ($dest != 'new' and $dest != 'current') { $context = get_context_instance(CONTEXT_MODULE, $cm->id);
$dest = 'current'; require_capability('mod/glossary:import', $context);
}
$strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary");
$strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strimportentries = get_string('importentriesfromxml', 'glossary');
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/import.php', array('id'=>$cm->id, 'mode'=>$mode, 'hook'=>$hook))); if ($dest != 'new' and $dest != 'current') {
$PAGE->navbar->add($strimportentries); $dest = 'current';
$PAGE->set_title(format_string($glossary->name)); }
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary");
echo $OUTPUT->header(); $strallcategories = get_string("allcategories", "glossary");
echo $OUTPUT->heading($strimportentries); $straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search");
$strimportentries = get_string('importentriesfromxml', 'glossary');
if ( !$step ) { $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/import.php', array('id'=>$cm->id, 'mode'=>$mode, 'hook'=>$hook)));
echo $OUTPUT->box_start('glossarydisplay generalbox'); $PAGE->navbar->add($strimportentries);
include("import.html"); $PAGE->set_title(format_string($glossary->name));
echo $OUTPUT->box_end(); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
echo $OUTPUT->footer(); echo $OUTPUT->header();
exit; echo $OUTPUT->heading($strimportentries);
}
$form = data_submitted(); if ( !$step ) {
$file = $_FILES["file"]; echo $OUTPUT->box_start('glossarydisplay generalbox');
include("import.html");
echo $OUTPUT->box_end();
require_once($CFG->dirroot.'/lib/uploadlib.php'); echo $OUTPUT->footer();
$um = new upload_manager('file',false,false,$course,false,0); exit;
}
if (!$um->preprocess_files()) { $form = data_submitted();
echo $OUTPUT->box_start('glossarydisplay generalbox'); $file = $_FILES["file"];
echo $OUTPUT->continue_button('import.php?id='.$id);
echo $OUTPUT->box_end();
echo $OUTPUT->footer(); require_once($CFG->dirroot.'/lib/uploadlib.php');
die(); $um = new upload_manager('file',false,false,$course,false,0);
}
if ($xml = glossary_read_imported_file($file['tmp_name']) ) { if (!$um->preprocess_files()) {
echo $OUTPUT->box_start('glossarydisplay generalbox');
echo $OUTPUT->continue_button('import.php?id='.$id);
echo $OUTPUT->box_end();
$importedentries = 0; echo $OUTPUT->footer();
$importedcats = 0; die();
$entriesrejected = 0; }
$rejections = '';
if ($dest == 'new') {
// If the user chose to create a new glossary
$xmlglossary = $xml['GLOSSARY']['#']['INFO'][0]['#'];
if ( $xmlglossary['NAME'][0]['#'] ) { if ($xml = glossary_read_imported_file($file['tmp_name']) ) {
unset($glossary);
$glossary->name = ($xmlglossary['NAME'][0]['#']);
$glossary->course = $course->id;
$glossary->globalglossary = ($xmlglossary['GLOBALGLOSSARY'][0]['#']);
$glossary->intro = ($xmlglossary['INTRO'][0]['#']);
$glossary->showspecial = ($xmlglossary['SHOWSPECIAL'][0]['#']);
$glossary->showalphabet = ($xmlglossary['SHOWALPHABET'][0]['#']);
$glossary->showall = ($xmlglossary['SHOWALL'][0]['#']);
$glossary->timecreated = time();
$glossary->timemodified = time();
// Setting the default values if no values were passed $importedentries = 0;
if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) { $importedcats = 0;
$glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']); $entriesrejected = 0;
} else { $rejections = '';
$glossary->entbypage = $CFG->glossary_entbypage; if ($dest == 'new') {
} // If the user chose to create a new glossary
if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) { $xmlglossary = $xml['GLOSSARY']['#']['INFO'][0]['#'];
$glossary->allowduplicatedentries = ($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']);
} else {
$glossary->allowduplicatedentries = $CFG->glossary_dupentries;
}
if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) {
$glossary->displayformat = ($xmlglossary['DISPLAYFORMAT'][0]['#']);
} else {
$glossary->displayformat = 2;
}
if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) {
$glossary->allowcomments = ($xmlglossary['ALLOWCOMMENTS'][0]['#']);
} else {
$glossary->allowcomments = $CFG->glossary_allowcomments;
}
if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) {
$glossary->usedynalink = ($xmlglossary['USEDYNALINK'][0]['#']);
} else {
$glossary->usedynalink = $CFG->glossary_linkentries;
}
if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) {
$glossary->defaultapproval = ($xmlglossary['DEFAULTAPPROVAL'][0]['#']);
} else {
$glossary->defaultapproval = $CFG->glossary_defaultapproval;
}
// Include new glossary and return the new ID if ( $xmlglossary['NAME'][0]['#'] ) {
if ( !$glossary->id = glossary_add_instance($glossary) ) { unset($glossary);
echo $OUTPUT->notification("Error while trying to create the new glossary."); $glossary->name = ($xmlglossary['NAME'][0]['#']);
echo '</center>'; $glossary->course = $course->id;
glossary_print_tabbed_table_end(); $glossary->globalglossary = ($xmlglossary['GLOBALGLOSSARY'][0]['#']);
echo $OUTPUT->footer(); $glossary->intro = ($xmlglossary['INTRO'][0]['#']);
exit; $glossary->showspecial = ($xmlglossary['SHOWSPECIAL'][0]['#']);
} else { $glossary->showalphabet = ($xmlglossary['SHOWALPHABET'][0]['#']);
//The instance has been created, so lets do course_modules $glossary->showall = ($xmlglossary['SHOWALL'][0]['#']);
//and course_sections $glossary->timecreated = time();
$mod->groupmode = $course->groupmode; /// Default groupmode the same as course $glossary->timemodified = time();
$mod->instance = $glossary->id; // Setting the default values if no values were passed
// course_modules and course_sections each contain a reference if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) {
// to each other, so we have to update one of them twice. $glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']);
if (! $currmodule = $DB->get_record("modules", array("name"=>'glossary'))) {
print_error('modulenotexist', 'debug', '', 'Glossary');
}
$mod->module = $currmodule->id;
$mod->course = $course->id;
$mod->modulename = 'glossary';
$mod->section = 0;
if (! $mod->coursemodule = add_course_module($mod) ) {
print_error('cannotaddcoursemodule');
}
if (! $sectionid = add_mod_to_section($mod) ) {
print_error('cannotaddcoursemoduletosection');
}
//We get the section's visible field status
$visible = $DB->get_field("course_sections", "visible", array("id"=>$sectionid));
$DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule));
$DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule));
add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
add_to_log($course->id, $mod->modulename, "add",
"view.php?id=$mod->coursemodule",
"$mod->instance", $mod->coursemodule);
rebuild_course_cache($course->id);
echo $OUTPUT->box(get_string("newglossarycreated","glossary"),'generalbox boxaligncenter boxwidthnormal');
echo '<p>';
}
} else { } else {
$glossary->entbypage = $CFG->glossary_entbypage;
}
if ( isset($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']) ) {
$glossary->allowduplicatedentries = ($xmlglossary['ALLOWDUPLICATEDENTRIES'][0]['#']);
} else {
$glossary->allowduplicatedentries = $CFG->glossary_dupentries;
}
if ( isset($xmlglossary['DISPLAYFORMAT'][0]['#']) ) {
$glossary->displayformat = ($xmlglossary['DISPLAYFORMAT'][0]['#']);
} else {
$glossary->displayformat = 2;
}
if ( isset($xmlglossary['ALLOWCOMMENTS'][0]['#']) ) {
$glossary->allowcomments = ($xmlglossary['ALLOWCOMMENTS'][0]['#']);
} else {
$glossary->allowcomments = $CFG->glossary_allowcomments;
}
if ( isset($xmlglossary['USEDYNALINK'][0]['#']) ) {
$glossary->usedynalink = ($xmlglossary['USEDYNALINK'][0]['#']);
} else {
$glossary->usedynalink = $CFG->glossary_linkentries;
}
if ( isset($xmlglossary['DEFAULTAPPROVAL'][0]['#']) ) {
$glossary->defaultapproval = ($xmlglossary['DEFAULTAPPROVAL'][0]['#']);
} else {
$glossary->defaultapproval = $CFG->glossary_defaultapproval;
}
// Include new glossary and return the new ID
if ( !$glossary->id = glossary_add_instance($glossary) ) {
echo $OUTPUT->notification("Error while trying to create the new glossary."); echo $OUTPUT->notification("Error while trying to create the new glossary.");
echo '</center>';
glossary_print_tabbed_table_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
exit; exit;
} else {
//The instance has been created, so lets do course_modules
//and course_sections
$mod->groupmode = $course->groupmode; /// Default groupmode the same as course
$mod->instance = $glossary->id;
// course_modules and course_sections each contain a reference
// to each other, so we have to update one of them twice.
if (! $currmodule = $DB->get_record("modules", array("name"=>'glossary'))) {
print_error('modulenotexist', 'debug', '', 'Glossary');
}
$mod->module = $currmodule->id;
$mod->course = $course->id;
$mod->modulename = 'glossary';
$mod->section = 0;
if (! $mod->coursemodule = add_course_module($mod) ) {
print_error('cannotaddcoursemodule');
}
if (! $sectionid = add_mod_to_section($mod) ) {
print_error('cannotaddcoursemoduletosection');
}
//We get the section's visible field status
$visible = $DB->get_field("course_sections", "visible", array("id"=>$sectionid));
$DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule));
$DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule));
add_to_log($course->id, "course", "add mod",
"../mod/$mod->modulename/view.php?id=$mod->coursemodule",
"$mod->modulename $mod->instance");
add_to_log($course->id, $mod->modulename, "add",
"view.php?id=$mod->coursemodule",
"$mod->instance", $mod->coursemodule);
rebuild_course_cache($course->id);
echo $OUTPUT->box(get_string("newglossarycreated","glossary"),'generalbox boxaligncenter boxwidthnormal');
echo '<p>';
} }
} else {
echo $OUTPUT->notification("Error while trying to create the new glossary.");
echo $OUTPUT->footer();
exit;
}
}
$xmlentries = $xml['GLOSSARY']['#']['INFO'][0]['#']['ENTRIES'][0]['#']['ENTRY'];
for($i = 0; $i < sizeof($xmlentries); $i++) {
// Inserting the entries
$xmlentry = $xmlentries[$i];
unset($newentry);
$newentry->concept = trim($xmlentry['#']['CONCEPT'][0]['#']);
$newentry->definition = trusttext_strip($xmlentry['#']['DEFINITION'][0]['#']);
if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) {
$newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#'];
} else {
$newentry->casesensitive = $CFG->glossary_casesensitive;
} }
$xmlentries = $xml['GLOSSARY']['#']['INFO'][0]['#']['ENTRIES'][0]['#']['ENTRY']; $permissiongranted = 1;
for($i = 0; $i < sizeof($xmlentries); $i++) { if ( $newentry->concept and $newentry->definition ) {
// Inserting the entries if ( !$glossary->allowduplicatedentries ) {
$xmlentry = $xmlentries[$i]; // checking if the entry is valid (checking if it is duplicated when should not be)
unset($newentry); if ( $newentry->casesensitive ) {
$newentry->concept = trim($xmlentry['#']['CONCEPT'][0]['#']); $dupentry = $DB->get_record("glossary_entries", array("concept"=>$newentry->concept, "glossaryid"=>$glossary->id));
$newentry->definition = trusttext_strip($xmlentry['#']['DEFINITION'][0]['#']); } else {
if ( isset($xmlentry['#']['CASESENSITIVE'][0]['#']) ) { $dupentry = $DB->get_record("glossary_entries", array("lower(concept)"=>moodle_strtolower($newentry->concept)), array("glossaryid"=>$glossary->id));
$newentry->casesensitive = $xmlentry['#']['CASESENSITIVE'][0]['#']; }
if ($dupentry) {
$permissiongranted = 0;
}
}
} else {
$permissiongranted = 0;
}
if ($permissiongranted) {
$newentry->glossaryid = $glossary->id;
$newentry->sourceglossaryid = 0;
$newentry->approved = 1;
$newentry->userid = $USER->id;
$newentry->teacherentry = 1;
$newentry->format = $xmlentry['#']['FORMAT'][0]['#'];
$newentry->timecreated = time();
$newentry->timemodified = time();
// Setting the default values if no values were passed
if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) {
$newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#'];
} else { } else {
$newentry->casesensitive = $CFG->glossary_casesensitive; $newentry->usedynalink = $CFG->glossary_linkentries;
}
if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) {
$newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#'];
} else {
$newentry->fullmatch = $CFG->glossary_fullmatch;
} }
$permissiongranted = 1; if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) ) {
if ( $newentry->concept and $newentry->definition ) { $importedentries++;
if ( !$glossary->allowduplicatedentries ) {
// checking if the entry is valid (checking if it is duplicated when should not be) $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES
if ( $newentry->casesensitive ) { for($k = 0; $k < sizeof($xmlaliases); $k++) {
$dupentry = $DB->get_record("glossary_entries", array("concept"=>$newentry->concept, "glossaryid"=>$glossary->id)); /// Importing aliases
} else { $xmlalias = $xmlaliases[$k];
$dupentry = $DB->get_record("glossary_entries", array("lower(concept)"=>moodle_strtolower($newentry->concept)), array("glossaryid"=>$glossary->id)); $aliasname = $xmlalias['#']['NAME'][0]['#'];
}
if ($dupentry) { if (!empty($aliasname)) {
$permissiongranted = 0; $newalias = new object();
$newalias->entryid = $newentry->id;
$newalias->alias = trim($aliasname);
$newalias->id = $DB->insert_record("glossary_alias",$newalias);
} }
} }
} else {
$permissiongranted = 0;
}
if ($permissiongranted) {
$newentry->glossaryid = $glossary->id;
$newentry->sourceglossaryid = 0;
$newentry->approved = 1;
$newentry->userid = $USER->id;
$newentry->teacherentry = 1;
$newentry->format = $xmlentry['#']['FORMAT'][0]['#'];
$newentry->timecreated = time();
$newentry->timemodified = time();
// Setting the default values if no values were passed if ( $catsincl ) {
if ( isset($xmlentry['#']['USEDYNALINK'][0]['#']) ) { // If the categories must be imported...
$newentry->usedynalink = $xmlentry['#']['USEDYNALINK'][0]['#']; $xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
} else { for($k = 0; $k < sizeof($xmlcats); $k++) {
$newentry->usedynalink = $CFG->glossary_linkentries; $xmlcat = $xmlcats[$k];
}
if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) {
$newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#'];
} else {
$newentry->fullmatch = $CFG->glossary_fullmatch;
}
if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) ) { $newcat = new object();
$importedentries++; $newcat->name = $xmlcat['#']['NAME'][0]['#'];
$newcat->usedynalink = $xmlcat['#']['USEDYNALINK'][0]['#'];
$xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES if ( !$category = $DB->get_record("glossary_categories", array("glossaryid"=>$glossary->id,"name"=>$newcat->name))) {
for($k = 0; $k < sizeof($xmlaliases); $k++) { // Create the category if it does not exist
/// Importing aliases $category = new object();
$xmlalias = $xmlaliases[$k]; $category->name = $newcat->name;
$aliasname = $xmlalias['#']['NAME'][0]['#']; $category->glossaryid = $glossary->id;
$category->id = $DB->insert_record("glossary_categories",$category);
if (!empty($aliasname)) { $importedcats++;
$newalias = new object(); }
$newalias->entryid = $newentry->id; if ( $category ) {
$newalias->alias = trim($aliasname); // inserting the new relation
$newalias->id = $DB->insert_record("glossary_alias",$newalias); $entrycat = new opbject();
$entrycat->entryid = $newentry->id;
$entrycat->categoryid = $category->id;
$DB->insert_record("glossary_entries_categories",$entrycat);
} }
} }
if ( $catsincl ) {
// If the categories must be imported...
$xmlcats = @$xmlentry['#']['CATEGORIES'][0]['#']['CATEGORY']; // ignore missing CATEGORIES
for($k = 0; $k < sizeof($xmlcats); $k++) {
$xmlcat = $xmlcats[$k];
$newcat = new object();
$newcat->name = $xmlcat['#']['NAME'][0]['#'];
$newcat->usedynalink = $xmlcat['#']['USEDYNALINK'][0]['#'];
if ( !$category = $DB->get_record("glossary_categories", array("glossaryid"=>$glossary->id,"name"=>$newcat->name))) {
// Create the category if it does not exist
$category = new object();
$category->name = $newcat->name;
$category->glossaryid = $glossary->id;
$category->id = $DB->insert_record("glossary_categories",$category);
$importedcats++;
}
if ( $category ) {
// inserting the new relation
$entrycat = new opbject();
$entrycat->entryid = $newentry->id;
$entrycat->categoryid = $category->id;
$DB->insert_record("glossary_entries_categories",$entrycat);
}
}
}
} else {
$entriesrejected++;
// add to exception report (can't insert new record)
$rejections .= "<tr><td>$newentry->concept</td>" .
"<td>" . get_string("cantinsertrec","glossary"). "</td></tr>";
} }
} else { } else {
$entriesrejected++; $entriesrejected++;
if ( $newentry->concept and $newentry->definition ) { // add to exception report (can't insert new record)
// add to exception report (duplicated entry)) $rejections .= "<tr><td>$newentry->concept</td>" .
$rejections .= "<tr><td>$newentry->concept</td>" . "<td>" . get_string("cantinsertrec","glossary"). "</td></tr>";
"<td>" . get_string("duplicateentry","glossary"). "</td></tr>"; }
} else { } else {
// add to exception report (no concept or definition found)) $entriesrejected++;
$rejections .= "<tr><td>---</td>" . if ( $newentry->concept and $newentry->definition ) {
"<td>" . get_string("noconceptfound","glossary"). "</td></tr>"; // add to exception report (duplicated entry))
} $rejections .= "<tr><td>$newentry->concept</td>" .
"<td>" . get_string("duplicateentry","glossary"). "</td></tr>";
} else {
// add to exception report (no concept or definition found))
$rejections .= "<tr><td>---</td>" .
"<td>" . get_string("noconceptfound","glossary"). "</td></tr>";
} }
} }
// processed entries
echo $OUTPUT->box_start('glossarydisplay generalbox');
echo '<table class="glossaryimportexport">';
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("totalentries","glossary");
echo ':</td>';
echo '<td width="50%" align="left">';
echo $importedentries + $entriesrejected;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("importedentries","glossary");
echo ':</td>';
echo '<td width="50%" align="left">';
echo $importedentries;
if ( $entriesrejected ) {
echo ' <small>(' . get_string("rejectedentries","glossary") . ": $entriesrejected)</small>";
}
echo '</td>';
echo '</tr>';
if ( $catsincl ) {
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("importedcategories","glossary");
echo ':</td>';
echo '<td width="50%">';
echo $importedcats;
echo '</td>';
echo '</tr>';
}
echo '</table><hr />';
// rejected entries
if ($rejections) {
echo '<table class="glossaryimportexport">';
echo '<tr><td align="center" colspan="2" width="100%"><strong>' . get_string("rejectionrpt","glossary") . '</strong></tr>';
echo $rejections;
echo '</table><hr />';
}
/// Print continue button, based on results
if ($importedentries) {
echo $OUTPUT->continue_button('view.php?id='.$id);
} else {
echo $OUTPUT->continue_button('import.php?id='.$id);
}
echo $OUTPUT->box_end();
} else {
notice(get_string('errorparsingxml', 'glossary'));
} }
// processed entries
echo $OUTPUT->box_start('glossarydisplay generalbox');
echo '<table class="glossaryimportexport">';
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("totalentries","glossary");
echo ':</td>';
echo '<td width="50%" align="left">';
echo $importedentries + $entriesrejected;
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("importedentries","glossary");
echo ':</td>';
echo '<td width="50%" align="left">';
echo $importedentries;
if ( $entriesrejected ) {
echo ' <small>(' . get_string("rejectedentries","glossary") . ": $entriesrejected)</small>";
}
echo '</td>';
echo '</tr>';
if ( $catsincl ) {
echo '<tr>';
echo '<td width="50%" align="right">';
echo get_string("importedcategories","glossary");
echo ':</td>';
echo '<td width="50%">';
echo $importedcats;
echo '</td>';
echo '</tr>';
}
echo '</table><hr />';
// rejected entries
if ($rejections) {
echo '<table class="glossaryimportexport">';
echo '<tr><td align="center" colspan="2" width="100%"><strong>' . get_string("rejectionrpt","glossary") . '</strong></tr>';
echo $rejections;
echo '</table><hr />';
}
/// Print continue button, based on results
if ($importedentries) {
echo $OUTPUT->continue_button('view.php?id='.$id);
} else {
echo $OUTPUT->continue_button('import.php?id='.$id);
}
echo $OUTPUT->box_end();
} else {
notice(get_string('errorparsingxml', 'glossary'));
}
/// Finish the page /// Finish the page
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?> ?>

View file

@ -1,134 +1,136 @@
<?php // $Id$ <?php
/// This page lists all the instances of glossary in a particular course /// This page lists all the instances of glossary in a particular course
/// Replace glossary with the name of your module /// Replace glossary with the name of your module
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("$CFG->libdir/rsslib.php"); require_once("$CFG->libdir/rsslib.php");
require_once("$CFG->dirroot/course/lib.php"); require_once("$CFG->dirroot/course/lib.php");
$id = required_param('id', PARAM_INT); // course $id = required_param('id', PARAM_INT); // course
if (!$course = $DB->get_record('course', array('id'=>$id))) { $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/index.php', array('id'=>$id)));
print_error('invalidcourseid');
}
require_course_login($course); if (!$course = $DB->get_record('course', array('id'=>$id))) {
$context = get_context_instance(CONTEXT_COURSE, $course->id); print_error('invalidcourseid');
}
add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", ""); require_course_login($course);
$context = get_context_instance(CONTEXT_COURSE, $course->id);
add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", "");
/// Get all required strings /// Get all required strings
$strglossarys = get_string("modulenameplural", "glossary"); $strglossarys = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary"); $strglossary = get_string("modulename", "glossary");
$strrss = get_string("rss"); $strrss = get_string("rss");
/// Print the header /// Print the header
$PAGE->navbar->add($strglossarys, "index.php?id=$course->id"); $PAGE->navbar->add($strglossarys, "index.php?id=$course->id");
$PAGE->set_title($strglossarys); $PAGE->set_title($strglossarys);
echo $OUTPUT->header(); echo $OUTPUT->header();
/// Get all the appropriate data /// Get all the appropriate data
if (! $glossarys = get_all_instances_in_course("glossary", $course)) { if (! $glossarys = get_all_instances_in_course("glossary", $course)) {
notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id"); notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id");
die; die;
} }
/// Print the list of instances (your module will probably extend this) /// Print the list of instances (your module will probably extend this)
$timenow = time(); $timenow = time();
$strname = get_string("name"); $strname = get_string("name");
$strweek = get_string("week"); $strweek = get_string("week");
$strtopic = get_string("topic"); $strtopic = get_string("topic");
$strentries = get_string("entries", "glossary"); $strentries = get_string("entries", "glossary");
$table = new html_table(); $table = new html_table();
if ($course->format == "weeks") { if ($course->format == "weeks") {
$table->head = array ($strweek, $strname, $strentries); $table->head = array ($strweek, $strname, $strentries);
$table->align = array ("CENTER", "LEFT", "CENTER"); $table->align = array ("CENTER", "LEFT", "CENTER");
} else if ($course->format == "topics") { } else if ($course->format == "topics") {
$table->head = array ($strtopic, $strname, $strentries); $table->head = array ($strtopic, $strname, $strentries);
$table->align = array ("CENTER", "LEFT", "CENTER"); $table->align = array ("CENTER", "LEFT", "CENTER");
} else {
$table->head = array ($strname, $strentries);
$table->align = array ("LEFT", "CENTER");
}
if ($show_rss = (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
$CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds)) {
$table->head[] = $strrss;
$table->align[] = "CENTER";
}
$currentsection = "";
foreach ($glossarys as $glossary) {
if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) {
// Show dimmed if the mod is hidden.
$link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else if ($glossary->visible) {
// Show normal if the mod is visible.
$link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else { } else {
$table->head = array ($strname, $strentries); // Don't show the glossary.
$table->align = array ("LEFT", "CENTER"); continue;
}
$printsection = "";
if ($glossary->section !== $currentsection) {
if ($glossary->section) {
$printsection = $glossary->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $glossary->section;
} }
if ($show_rss = (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) && // TODO: count only approved if not allowed to see them
$CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds)) {
$table->head[] = $strrss; $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id));
$table->align[] = "CENTER";
//If this glossary has RSS activated, calculate it
if ($show_rss) {
$rsslink = '';
if ($glossary->rsstype and $glossary->rssarticles) {
//Calculate the tolltip text
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
if (empty($USER->id)) {
$userid = 0;
} else {
$userid = $USER->id;
}
//Get html code for RSS link
$rsslink = rss_get_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
}
} }
$currentsection = ""; if ($course->format == "weeks" or $course->format == "topics") {
$linedata = array ($printsection, $link, $count);
foreach ($glossarys as $glossary) { } else {
if (!$glossary->visible && has_capability('moodle/course:viewhiddenactivities', $context)) { $linedata = array ($link, $count);
// Show dimmed if the mod is hidden.
$link = "<a class=\"dimmed\" href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else if ($glossary->visible) {
// Show normal if the mod is visible.
$link = "<a href=\"view.php?id=$glossary->coursemodule\">".format_string($glossary->name,true)."</a>";
} else {
// Don't show the glossary.
continue;
}
$printsection = "";
if ($glossary->section !== $currentsection) {
if ($glossary->section) {
$printsection = $glossary->section;
}
if ($currentsection !== "") {
$table->data[] = 'hr';
}
$currentsection = $glossary->section;
}
// TODO: count only approved if not allowed to see them
$count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id));
//If this glossary has RSS activated, calculate it
if ($show_rss) {
$rsslink = '';
if ($glossary->rsstype and $glossary->rssarticles) {
//Calculate the tolltip text
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name));
if (empty($USER->id)) {
$userid = 0;
} else {
$userid = $USER->id;
}
//Get html code for RSS link
$rsslink = rss_get_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
}
}
if ($course->format == "weeks" or $course->format == "topics") {
$linedata = array ($printsection, $link, $count);
} else {
$linedata = array ($link, $count);
}
if ($show_rss) {
$linedata[] = $rsslink;
}
$table->data[] = $linedata;
} }
echo "<br />"; if ($show_rss) {
$linedata[] = $rsslink;
}
echo $OUTPUT->table($table); $table->data[] = $linedata;
}
echo "<br />";
echo $OUTPUT->table($table);
/// Finish the page /// Finish the page
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?> ?>

View file

@ -1,185 +1,206 @@
<?php // $Id$ <?php
global $CFG; global $CFG;
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); // Course Module ID $id = required_param('id', PARAM_INT); // Course Module ID
$sortorder = optional_param('sortorder', 'asc', PARAM_ALPHA); // Sorting order $sortorder = optional_param('sortorder', 'asc', PARAM_ALPHA); // Sorting order
$offset = optional_param('offset', 0, PARAM_INT); // number of entries to bypass $offset = optional_param('offset', 0, PARAM_INT); // number of entries to bypass
$displayformat = optional_param('displayformat',-1, PARAM_INT); $displayformat = optional_param('displayformat',-1, PARAM_INT);
$mode = required_param('mode', PARAM_ALPHA); // mode to show the entries $mode = required_param('mode', PARAM_ALPHA); // mode to show the entries
$hook = optional_param('hook','ALL', PARAM_ALPHANUM); // what to show $hook = optional_param('hook','ALL', PARAM_ALPHANUM); // what to show
$sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key
if (! $cm = get_coursemodule_from_id('glossary', $id)) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/print.php', array('id'=>$id));
print_error('invalidcoursemodule'); if ($sortorder !== 'asc') {
} $url->param('sortorder', $sortorder);
}
if ($offset !== 0) {
$url->param('offset', $offset);
}
if ($displayformat !== -1) {
$url->param('displayformat', $displayformat);
}
if ($sortkey !== 'UPDATE') {
$url->param('sortkey', $sortkey);
}
if ($mode !== 'letter') {
$url->param('mode', $mode);
}
if ($hook !== 'ALL') {
$url->param('hook', $hook);
}
$PAGE->set_url($url);
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('coursemisconf'); print_error('invalidcoursemodule');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('invalidid', 'glossary'); print_error('coursemisconf');
} }
if ( !$entriesbypage = $glossary->entbypage ) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
$entriesbypage = $CFG->glossary_entbypage; print_error('invalidid', 'glossary');
} }
echo $OUTPUT->header(); if ( !$entriesbypage = $glossary->entbypage ) {
$entriesbypage = $CFG->glossary_entbypage;
}
require_course_login($course, true, $cm); echo $OUTPUT->header();
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_course_login($course, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Loading the textlib singleton instance. We are going to need it. /// Loading the textlib singleton instance. We are going to need it.
$textlib = textlib_get_instance(); $textlib = textlib_get_instance();
if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) { if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) {
notice(get_string('printviewnotallowed', 'glossary')); notice(get_string('printviewnotallowed', 'glossary'));
} }
/// setting the default values for the display mode of the current glossary /// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time /// only if the glossary is viewed by the first time
if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
$printpivot = $dp->showgroup; $printpivot = $dp->showgroup;
if ( $mode == '' and $hook == '' and $show == '') { if ( $mode == '' and $hook == '' and $show == '') {
$mode = $dp->defaultmode; $mode = $dp->defaultmode;
$hook = $dp->defaulthook; $hook = $dp->defaulthook;
$sortkey = $dp->sortkey; $sortkey = $dp->sortkey;
$sortorder = $dp->sortorder; $sortorder = $dp->sortorder;
}
} else {
$printpivot = 1;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = 'letter';
$hook = 'ALL';
}
} }
} else {
$printpivot = 1;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = 'letter';
$hook = 'ALL';
}
}
if ( $displayformat == -1 ) { if ( $displayformat == -1 ) {
$displayformat = $glossary->displayformat; $displayformat = $glossary->displayformat;
} }
/// stablishing flag variables /// stablishing flag variables
if ( $sortorder = strtolower($sortorder) ) { if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != 'asc' and $sortorder != 'desc') { if ($sortorder != 'asc' and $sortorder != 'desc') {
$sortorder = ''; $sortorder = '';
}
} }
if ( $sortkey = strtoupper($sortkey) ) { }
if ($sortkey != 'CREATION' and if ( $sortkey = strtoupper($sortkey) ) {
$sortkey != 'UPDATE' and if ($sortkey != 'CREATION' and
$sortkey != 'FIRSTNAME' and $sortkey != 'UPDATE' and
$sortkey != 'LASTNAME' $sortkey != 'FIRSTNAME' and
) { $sortkey != 'LASTNAME'
$sortkey = ''; ) {
} $sortkey = '';
} }
}
switch ( $mode = strtolower($mode) ) { switch ( $mode = strtolower($mode) ) {
case 'entry': /// Looking for a certain entry id case 'entry': /// Looking for a certain entry id
$tab = GLOSSARY_STANDARD_VIEW; $tab = GLOSSARY_STANDARD_VIEW;
break; break;
case 'cat': /// Looking for a certain cat case 'cat': /// Looking for a certain cat
$tab = GLOSSARY_CATEGORY_VIEW; $tab = GLOSSARY_CATEGORY_VIEW;
if ( $hook > 0 ) { if ( $hook > 0 ) {
$category = $DB->get_record("glossary_categories", array("id"=>$hook)); $category = $DB->get_record("glossary_categories", array("id"=>$hook));
}
break;
case 'approval': /// Looking for entries waiting for approval
$tab = GLOSSARY_APPROVAL_VIEW;
if ( !$hook and !$sortkey and !$sortorder) {
$hook = 'ALL';
}
break;
case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
$tab = GLOSSARY_STANDARD_VIEW;
break;
case 'date':
$tab = GLOSSARY_DATE_VIEW;
if ( !$sortkey ) {
$sortkey = 'UPDATE';
}
if ( !$sortorder ) {
$sortorder = 'desc';
}
break;
case 'author': /// Looking for entries, browsed by author
$tab = GLOSSARY_AUTHOR_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
if ( !$sortkey ) {
$sortkey = 'FIRSTNAME';
}
if ( !$sortorder ) {
$sortorder = 'asc';
}
break;
case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
default:
$tab = GLOSSARY_STANDARD_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
break;
} }
break;
include_once("sql.php"); case 'approval': /// Looking for entries waiting for approval
$tab = GLOSSARY_APPROVAL_VIEW;
$entriesshown = 0; if ( !$hook and !$sortkey and !$sortorder) {
$currentpivot = ''; $hook = 'ALL';
if ( $hook == 'SPECIAL' ) {
$alphabet = explode(",", get_string("alphabet"));
} }
break;
$site = $DB->get_record("course", array("id"=>1)); case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
echo '<p style="text-align:right"><span style="font-size:0.75em">' . userdate(time()) . '</span></p>'; $tab = GLOSSARY_STANDARD_VIEW;
echo get_string("site") . ': <strong>' . format_string($site->fullname) . '</strong><br />'; break;
echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />';
echo get_string("modulename","glossary") . ': <strong>' . format_string($glossary->name, true) . '</strong>';
if ( $allentries ) {
foreach ($allentries as $entry) {
// Setting the pivot for the current entry case 'date':
$pivot = $entry->glossarypivot; $tab = GLOSSARY_DATE_VIEW;
$upperpivot = $textlib->strtoupper($pivot); if ( !$sortkey ) {
// Reduce pivot to 1cc if necessary $sortkey = 'UPDATE';
if ( !$fullpivot ) { }
$upperpivot = $textlib->substr($upperpivot, 0, 1); if ( !$sortorder ) {
} $sortorder = 'desc';
}
// If there's group break break;
if ( $currentpivot != $upperpivot ) {
// print the group break if apply case 'author': /// Looking for entries, browsed by author
if ( $printpivot ) { $tab = GLOSSARY_AUTHOR_VIEW;
$currentpivot = $upperpivot; if ( !$hook ) {
$hook = 'ALL';
}
if ( !$sortkey ) {
$sortkey = 'FIRSTNAME';
}
if ( !$sortorder ) {
$sortorder = 'asc';
}
break;
$pivottoshow = $currentpivot; case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
if ( isset($entry->userispivot) ) { default:
// printing the user icon if defined (only when browsing authors) $tab = GLOSSARY_STANDARD_VIEW;
$user = $DB->get_record("user", array("id"=>$entry->userid)); if ( !$hook ) {
$pivottoshow = fullname($user); $hook = 'ALL';
} }
break;
}
echo "<p class='mdl-align'><strong>".clean_text($pivottoshow)."</strong></p>" ; include_once("sql.php");
$entriesshown = 0;
$currentpivot = '';
if ( $hook == 'SPECIAL' ) {
$alphabet = explode(",", get_string("alphabet"));
}
$site = $DB->get_record("course", array("id"=>1));
echo '<p style="text-align:right"><span style="font-size:0.75em">' . userdate(time()) . '</span></p>';
echo get_string("site") . ': <strong>' . format_string($site->fullname) . '</strong><br />';
echo get_string("course") . ': <strong>' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')</strong><br />';
echo get_string("modulename","glossary") . ': <strong>' . format_string($glossary->name, true) . '</strong>';
if ( $allentries ) {
foreach ($allentries as $entry) {
// Setting the pivot for the current entry
$pivot = $entry->glossarypivot;
$upperpivot = $textlib->strtoupper($pivot);
// Reduce pivot to 1cc if necessary
if ( !$fullpivot ) {
$upperpivot = $textlib->substr($upperpivot, 0, 1);
}
// If there's group break
if ( $currentpivot != $upperpivot ) {
// print the group break if apply
if ( $printpivot ) {
$currentpivot = $upperpivot;
$pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors)
$user = $DB->get_record("user", array("id"=>$entry->userid));
$pivottoshow = fullname($user);
} }
echo "<p class='mdl-align'><strong>".clean_text($pivottoshow)."</strong></p>" ;
} }
glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true);
} }
}
echo $OUTPUT->footer(); glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true);
?> }
}
echo $OUTPUT->footer();
?>

View file

@ -8,6 +8,8 @@
$glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from $glossaryid = required_param('glossaryid', PARAM_INT); // The forum the rated posts are from
$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/rate.php', array('glossaryid'=>$glossaryid)));
if (!$glossary = $DB->get_record('glossary', array('id'=>$glossaryid))) { if (!$glossary = $DB->get_record('glossary', array('id'=>$glossaryid))) {
print_error('invalidid', 'glossary'); print_error('invalidid', 'glossary');
} }

View file

@ -1,87 +1,94 @@
<?php // $Id$ <?php
// For a given entry, shows a report of all the ratings it has // For a given entry, shows a report of all the ratings it has
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$sort = optional_param('sort', '', PARAM_ALPHA); $sort = optional_param('sort', '', PARAM_ALPHA);
if (! $entry = $DB->get_record('glossary_entries', array('id'=>$id))) { $url = new moodle_url($CFG->wwwroot.'/mod/glossary/report.php', array('id'=>$id));
print_error('invalidentry'); if ($sort !== '') {
} $url->param('sort', $sort);
}
$PAGE->set_url($url);
if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) { if (! $entry = $DB->get_record('glossary_entries', array('id'=>$id))) {
print_error('invalidid', 'glossary'); print_error('invalidentry');
} }
if (! $course = $DB->get_record('course', array('id'=>$glossary->course))) { if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
print_error('invalidcourseid'); print_error('invalidid', 'glossary');
} }
if (! $cm = get_coursemodule_from_instance('glossary', $glossary->id, $course->id)) { if (! $course = $DB->get_record('course', array('id'=>$glossary->course))) {
print_error('invalidcoursemodule'); print_error('invalidcourseid');
} }
require_login($course, false, $cm); if (! $cm = get_coursemodule_from_instance('glossary', $glossary->id, $course->id)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id); print_error('invalidcoursemodule');
}
if (!$glossary->assessed) { require_login($course, false, $cm);
print_error('nopermissiontorate'); $context = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if (!has_capability('mod/glossary:manageentries', $context) and $USER->id != $entry->userid) { if (!$glossary->assessed) {
print_error('nopermissiontoviewresult', 'glossary'); print_error('nopermissiontorate');
} }
switch ($sort) { if (!has_capability('mod/glossary:manageentries', $context) and $USER->id != $entry->userid) {
case 'firstname': $sqlsort = "u.firstname ASC"; break; print_error('nopermissiontoviewresult', 'glossary');
case 'rating': $sqlsort = "r.rating ASC"; break; }
default: $sqlsort = "r.time ASC";
}
$scalemenu = make_grades_menu($glossary->scale); switch ($sort) {
case 'firstname': $sqlsort = "u.firstname ASC"; break;
case 'rating': $sqlsort = "r.rating ASC"; break;
default: $sqlsort = "r.time ASC";
}
$strratings = get_string('ratings', 'glossary'); $scalemenu = make_grades_menu($glossary->scale);
$strrating = get_string('rating', 'glossary');
$strname = get_string('name');
$strtime = get_string('time');
$PAGE->set_title("$strratings: $entry->concept"); $strratings = get_string('ratings', 'glossary');
echo $OUTPUT->header(); $strrating = get_string('rating', 'glossary');
$strname = get_string('name');
$strtime = get_string('time');
if (!$ratings = glossary_get_ratings($entry->id, $sqlsort)) { $PAGE->set_title("$strratings: $entry->concept");
print_error('ratingno', 'glossary'); echo $OUTPUT->header();
} else { if (!$ratings = glossary_get_ratings($entry->id, $sqlsort)) {
echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">"; print_error('ratingno', 'glossary');
echo "<tr>";
echo "<th class=\"header\" scope=\"col\">&nbsp;</th>"; } else {
echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$entry->id&amp;sort=firstname\">$strname</a></th>"; echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$entry->id&amp;sort=rating\">$strrating</a></th>"; echo "<tr>";
echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$entry->id&amp;sort=time\">$strtime</a></th>"; echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
echo "</tr>"; echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$entry->id&amp;sort=firstname\">$strname</a></th>";
foreach ($ratings as $rating) { echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$entry->id&amp;sort=rating\">$strrating</a></th>";
if (has_capability('mod/glossary:manageentries', $context)) { echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$entry->id&amp;sort=time\">$strtime</a></th>";
echo '<tr class="teacher">'; echo "</tr>";
} else { foreach ($ratings as $rating) {
echo '<tr>'; if (has_capability('mod/glossary:manageentries', $context)) {
} echo '<tr class="teacher">';
echo '<td class="picture">'; } else {
$userpic = moodle_user_picture::make($rating, $glossary->course); echo '<tr>';
$userpic->link = true;
echo $OUTPUT->user_picture($userpic);
echo '</td>';
echo '<td class="author"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$rating->id.'&amp;course='.$glossary->course.'">'.fullname($rating).'</a></td>';
echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->time).'</td>';
echo "</tr>\n";
} }
echo "</table>"; echo '<td class="picture">';
echo "<br />"; $userpic = moodle_user_picture::make($rating, $glossary->course);
$userpic->link = true;
echo $OUTPUT->user_picture($userpic);
echo '</td>';
echo '<td class="author"><a href="'.$CFG->wwwroot.'/user/view.php?id='.$rating->id.'&amp;course='.$glossary->course.'">'.fullname($rating).'</a></td>';
echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating].'</td>';
echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->time).'</td>';
echo "</tr>\n";
} }
echo "</table>";
echo "<br />";
}
echo $OUTPUT->close_window_button(); echo $OUTPUT->close_window_button();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?>
?>

View file

@ -1,70 +1,86 @@
<?php // $Id$ <?php
require_once("../../config.php");
require_once("lib.php");
$concept = optional_param('concept', '', PARAM_CLEAN); require_once("../../config.php");
$courseid = optional_param('courseid', 0, PARAM_INT); require_once("lib.php");
$eid = optional_param('eid', 0, PARAM_INT); // glossary entry id
$displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
if ($CFG->forcelogin) { $concept = optional_param('concept', '', PARAM_CLEAN);
require_login(); $courseid = optional_param('courseid', 0, PARAM_INT);
$eid = optional_param('eid', 0, PARAM_INT); // glossary entry id
$displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
$url = new moodle_url($CFG->wwwroot.'/mod/glossary/showentry.php');
if ($concept !== '') {
$url->param('concept', $concept);
}
if ($courseid !== 0) {
$url->param('courseid', $courseid);
}
if ($eid !== 0) {
$url->param('eid', $eid);
}
if ($displayformat !== -1) {
$url->param('displayformat', $displayformat);
}
$PAGE->set_url($url);
if ($CFG->forcelogin) {
require_login();
}
if ($eid) {
$entry = $DB->get_record("glossary_entries", array("id"=>$eid));
$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
$entry->glossaryname = format_string($glossary->name,true);
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
print_error("invalidcoursemodule");
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
}
$entry->cmid = $cm->id;
$entry->courseid = $cm->course;
$entries[] = $entry;
} else if ($concept) {
$entries = glossary_get_entries_search($concept, $courseid);
} else {
print_error('invalidentry');
}
if ($entries) {
foreach ($entries as $key => $entry) {
//$entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a onClick=\"if (window.opener) {window.opener.location.href='$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid'; return false;} else {openpopup('/mod/glossary/view.php?g=$entry->glossaryid', 'glossary', 'menubar=1,location=1,toolbar=1,scrollbars=1,directories=1,status=1,resizable=1', 0); return false;}\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\" target=\"_blank\">".format_string($entry->glossaryname,true)."</a></p>"; // Could not get this to work satisfactorily in all cases - Martin
$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)) {
$course = $DB->get_record("course", array("id"=>$courseid));
if ($course->id != SITEID) {
require_login($courseid);
} }
if ($eid) { $strglossaries = get_string("modulenameplural", "glossary");
$entry = $DB->get_record("glossary_entries", array("id"=>$eid)); $strsearch = get_string("search");
$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid));
$entry->glossaryname = format_string($glossary->name,true);
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id)) {
print_error("invalidcoursemodule");
}
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $cm->id))) {
redirect($CFG->wwwroot.'/course/view.php?id='.$cm->course, get_string('activityiscurrentlyhidden'));
}
$entry->cmid = $cm->id;
$entry->courseid = $cm->course;
$entries[] = $entry;
} else if ($concept) {
$entries = glossary_get_entries_search($concept, $courseid);
} else {
print_error('invalidentry');
}
if ($entries) { $CFG->framename = "newwindow";
foreach ($entries as $key => $entry) {
//$entries[$key]->footer = "<p align=\"right\">&raquo;&nbsp;<a onClick=\"if (window.opener) {window.opener.location.href='$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid'; return false;} else {openpopup('/mod/glossary/view.php?g=$entry->glossaryid', 'glossary', 'menubar=1,location=1,toolbar=1,scrollbars=1,directories=1,status=1,resizable=1', 0); return false;}\" href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\" target=\"_blank\">".format_string($entry->glossaryname,true)."</a></p>"; // Could not get this to work satisfactorily in all cases - Martin
$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)) { $PAGE->navbar->add($strglossaries);
$course = $DB->get_record("course", array("id"=>$courseid)); $PAGE->navbar->add($strsearch);
if ($course->id != SITEID) { $PAGE->set_title(strip_tags("$course->shortname: $strglossaries $strsearch"));
require_login($courseid); $PAGE->set_heading($course->fullname);
} echo $OUTPUT->header();
} else {
echo $OUTPUT->header(); // Needs to be something here to allow linking back to the whole glossary
}
$strglossaries = get_string("modulenameplural", "glossary"); if ($entries) {
$strsearch = get_string("search"); glossary_print_dynaentry($courseid, $entries, $displayformat);
}
$CFG->framename = "newwindow"; echo $OUTPUT->close_window_button();
$PAGE->navbar->add($strglossaries);
$PAGE->navbar->add($strsearch);
$PAGE->set_title(strip_tags("$course->shortname: $strglossaries $strsearch"));
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();
} else {
echo $OUTPUT->header(); // Needs to be something here to allow linking back to the whole glossary
}
if ($entries) {
glossary_print_dynaentry($courseid, $entries, $displayformat);
}
echo $OUTPUT->close_window_button();
/// Show one reduced footer /// Show one reduced footer
echo $OUTPUT->footer(); echo $OUTPUT->footer();
?> ?>

View file

@ -1,527 +1,529 @@
<?php // $Id$ <?php
/// This page prints a particular instance of glossary /// This page prints a particular instance of glossary
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once("$CFG->libdir/rsslib.php"); require_once("$CFG->libdir/rsslib.php");
$id = optional_param('id', 0, PARAM_INT); // Course Module ID $id = optional_param('id', 0, PARAM_INT); // Course Module ID
$g = optional_param('g', 0, PARAM_INT); // Glossary ID $g = optional_param('g', 0, PARAM_INT); // Glossary ID
$tab = optional_param('tab', GLOSSARY_NO_VIEW, PARAM_ALPHA); // browsing entries by categories? $tab = optional_param('tab', GLOSSARY_NO_VIEW, PARAM_ALPHA); // browsing entries by categories?
$displayformat = optional_param('displayformat',-1, PARAM_INT); // override of the glossary display format $displayformat = optional_param('displayformat',-1, PARAM_INT); // override of the glossary display format
$mode = optional_param('mode', '', PARAM_ALPHA); // term entry cat date letter search author approval $mode = optional_param('mode', '', PARAM_ALPHA); // term entry cat date letter search author approval
$hook = optional_param('hook', '', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode $hook = optional_param('hook', '', PARAM_CLEAN); // the term, entry, cat, etc... to look for based on mode
$fullsearch = optional_param('fullsearch', 0,PARAM_INT); // full search (concept and definition) when searching? $fullsearch = optional_param('fullsearch', 0,PARAM_INT); // full search (concept and definition) when searching?
$sortkey = optional_param('sortkey', '', PARAM_ALPHA);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME... $sortkey = optional_param('sortkey', '', PARAM_ALPHA);// Sorted view: CREATION | UPDATE | FIRSTNAME | LASTNAME...
$sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA); // it defines the order of the sorting (ASC or DESC) $sortorder = optional_param('sortorder', 'ASC', PARAM_ALPHA); // it defines the order of the sorting (ASC or DESC)
$offset = optional_param('offset', 0,PARAM_INT); // entries to bypass (for paging purposes) $offset = optional_param('offset', 0,PARAM_INT); // entries to bypass (for paging purposes)
$page = optional_param('page', 0,PARAM_INT); // Page to show (for paging purposes) $page = optional_param('page', 0,PARAM_INT); // Page to show (for paging purposes)
$show = optional_param('show', '', PARAM_ALPHA); // [ concept | alias ] => mode=term hook=$show $show = optional_param('show', '', PARAM_ALPHA); // [ concept | alias ] => mode=term hook=$show
if (!empty($id)) { if (!empty($id)) {
if (! $cm = get_coursemodule_from_id('glossary', $id)) { if (! $cm = get_coursemodule_from_id('glossary', $id)) {
print_error('invalidcoursemodule'); print_error('invalidcoursemodule');
} }
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf'); print_error('coursemisconf');
} }
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
print_error('invalidid', 'glossary');
}
} else if (!empty($g)) {
if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
print_error('invalidid', 'glossary');
}
if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) {
print_error('invalidcourseid');
}
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) {
print_error('invalidcoursemodule');
}
$id = $cm->id;
} else {
print_error('invalidid', 'glossary'); print_error('invalidid', 'glossary');
} }
require_course_login($course->id, true, $cm); } else if (!empty($g)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id); if (! $glossary = $DB->get_record("glossary", array("id"=>$g))) {
print_error('invalidid', 'glossary');
}
if (! $course = $DB->get_record("course", array("id"=>$glossary->course))) {
print_error('invalidcourseid');
}
if (!$cm = get_coursemodule_from_instance("glossary", $glossary->id, $course->id)) {
print_error('invalidcoursemodule');
}
$id = $cm->id;
} else {
print_error('invalidid', 'glossary');
}
require_course_login($course->id, true, $cm);
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
/// Loading the textlib singleton instance. We are going to need it. /// Loading the textlib singleton instance. We are going to need it.
$textlib = textlib_get_instance(); $textlib = textlib_get_instance();
/// redirecting if adding a new entry /// redirecting if adding a new entry
if ($tab == GLOSSARY_ADDENTRY_VIEW ) { if ($tab == GLOSSARY_ADDENTRY_VIEW ) {
redirect("edit.php?cmid=$cm->id&amp;mode=$mode"); redirect("edit.php?cmid=$cm->id&amp;mode=$mode");
} }
/// setting the defaut number of entries per page if not set /// setting the defaut number of entries per page if not set
if ( !$entriesbypage = $glossary->entbypage ) { if ( !$entriesbypage = $glossary->entbypage ) {
$entriesbypage = $CFG->glossary_entbypage; $entriesbypage = $CFG->glossary_entbypage;
} }
/// If we have received a page, recalculate offset /// If we have received a page, recalculate offset
if ($page != 0 && $offset == 0) { if ($page != 0 && $offset == 0) {
$offset = $page * $entriesbypage; $offset = $page * $entriesbypage;
} }
/// setting the default values for the display mode of the current glossary /// setting the default values for the display mode of the current glossary
/// only if the glossary is viewed by the first time /// only if the glossary is viewed by the first time
if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) {
/// Based on format->defaultmode, we build the defaulttab to be showed sometimes /// Based on format->defaultmode, we build the defaulttab to be showed sometimes
switch ($dp->defaultmode) { switch ($dp->defaultmode) {
case 'cat': case 'cat':
$defaulttab = GLOSSARY_CATEGORY_VIEW; $defaulttab = GLOSSARY_CATEGORY_VIEW;
break; break;
case 'date': case 'date':
$defaulttab = GLOSSARY_DATE_VIEW; $defaulttab = GLOSSARY_DATE_VIEW;
break; break;
case 'author': case 'author':
$defaulttab = GLOSSARY_AUTHOR_VIEW; $defaulttab = GLOSSARY_AUTHOR_VIEW;
break; break;
default: default:
$defaulttab = GLOSSARY_STANDARD_VIEW; $defaulttab = GLOSSARY_STANDARD_VIEW;
}
/// Fetch the rest of variables
$printpivot = $dp->showgroup;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = $dp->defaultmode;
$hook = $dp->defaulthook;
$sortkey = $dp->sortkey;
$sortorder = $dp->sortorder;
}
} else {
$defaulttab = GLOSSARY_STANDARD_VIEW;
$printpivot = 1;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = 'letter';
$hook = 'ALL';
}
} }
/// Fetch the rest of variables
$printpivot = $dp->showgroup;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = $dp->defaultmode;
$hook = $dp->defaulthook;
$sortkey = $dp->sortkey;
$sortorder = $dp->sortorder;
}
} else {
$defaulttab = GLOSSARY_STANDARD_VIEW;
$printpivot = 1;
if ( $mode == '' and $hook == '' and $show == '') {
$mode = 'letter';
$hook = 'ALL';
}
}
if ( $displayformat == -1 ) { if ( $displayformat == -1 ) {
$displayformat = $glossary->displayformat; $displayformat = $glossary->displayformat;
} }
if ( $show ) { if ( $show ) {
$mode = 'term'; $mode = 'term';
$hook = $show; $hook = $show;
$show = ''; $show = '';
} }
/// Processing standard security processes /// Processing standard security processes
if ($course->id != SITEID) { if ($course->id != SITEID) {
require_login($course->id); require_login($course->id);
} }
if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) {
echo $OUTPUT->header(); echo $OUTPUT->header();
notice(get_string("activityiscurrentlyhidden")); notice(get_string("activityiscurrentlyhidden"));
} }
add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&amp;tab=$tab", $glossary->id, $cm->id); add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&amp;tab=$tab", $glossary->id, $cm->id);
/// stablishing flag variables /// stablishing flag variables
if ( $sortorder = strtolower($sortorder) ) { if ( $sortorder = strtolower($sortorder) ) {
if ($sortorder != 'asc' and $sortorder != 'desc') { if ($sortorder != 'asc' and $sortorder != 'desc') {
$sortorder = ''; $sortorder = '';
}
} }
if ( $sortkey = strtoupper($sortkey) ) { }
if ($sortkey != 'CREATION' and if ( $sortkey = strtoupper($sortkey) ) {
$sortkey != 'UPDATE' and if ($sortkey != 'CREATION' and
$sortkey != 'FIRSTNAME' and $sortkey != 'UPDATE' and
$sortkey != 'LASTNAME' $sortkey != 'FIRSTNAME' and
) { $sortkey != 'LASTNAME'
$sortkey = ''; ) {
} $sortkey = '';
} }
}
switch ( $mode = strtolower($mode) ) { switch ( $mode = strtolower($mode) ) {
case 'search': /// looking for terms containing certain word(s) case 'search': /// looking for terms containing certain word(s)
$tab = GLOSSARY_STANDARD_VIEW; $tab = GLOSSARY_STANDARD_VIEW;
//Clean a bit the search string //Clean a bit the search string
$hook = trim(strip_tags($hook)); $hook = trim(strip_tags($hook));
break; break;
case 'entry': /// Looking for a certain entry id case 'entry': /// Looking for a certain entry id
$tab = GLOSSARY_STANDARD_VIEW; $tab = GLOSSARY_STANDARD_VIEW;
if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) { if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) {
$displayformat = $dp->popupformatname; $displayformat = $dp->popupformatname;
}
break;
case 'cat': /// Looking for a certain cat
$tab = GLOSSARY_CATEGORY_VIEW;
if ( $hook > 0 ) {
$category = $DB->get_record("glossary_categories", array("id"=>$hook));
}
break;
case 'approval': /// Looking for entries waiting for approval
$tab = GLOSSARY_APPROVAL_VIEW;
if ( !$hook and !$sortkey and !$sortorder) {
$hook = 'ALL';
}
break;
case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
$tab = GLOSSARY_STANDARD_VIEW;
break;
case 'date':
$tab = GLOSSARY_DATE_VIEW;
if ( !$sortkey ) {
$sortkey = 'UPDATE';
}
if ( !$sortorder ) {
$sortorder = 'desc';
}
break;
case 'author': /// Looking for entries, browsed by author
$tab = GLOSSARY_AUTHOR_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
if ( !$sortkey ) {
$sortkey = 'FIRSTNAME';
}
if ( !$sortorder ) {
$sortorder = 'asc';
}
break;
case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
default:
$tab = GLOSSARY_STANDARD_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
break;
} }
break;
switch ( $tab ) { case 'cat': /// Looking for a certain cat
case GLOSSARY_IMPORT_VIEW: $tab = GLOSSARY_CATEGORY_VIEW;
case GLOSSARY_EXPORT_VIEW: if ( $hook > 0 ) {
case GLOSSARY_APPROVAL_VIEW: $category = $DB->get_record("glossary_categories", array("id"=>$hook));
$showcommonelements = 0;
break;
default:
$showcommonelements = 1;
break;
} }
break;
case 'approval': /// Looking for entries waiting for approval
$tab = GLOSSARY_APPROVAL_VIEW;
if ( !$hook and !$sortkey and !$sortorder) {
$hook = 'ALL';
}
break;
case 'term': /// Looking for entries that include certain term in its concept, definition or aliases
$tab = GLOSSARY_STANDARD_VIEW;
break;
case 'date':
$tab = GLOSSARY_DATE_VIEW;
if ( !$sortkey ) {
$sortkey = 'UPDATE';
}
if ( !$sortorder ) {
$sortorder = 'desc';
}
break;
case 'author': /// Looking for entries, browsed by author
$tab = GLOSSARY_AUTHOR_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
if ( !$sortkey ) {
$sortkey = 'FIRSTNAME';
}
if ( !$sortorder ) {
$sortorder = 'asc';
}
break;
case 'letter': /// Looking for entries that begin with a certain letter, ALL or SPECIAL characters
default:
$tab = GLOSSARY_STANDARD_VIEW;
if ( !$hook ) {
$hook = 'ALL';
}
break;
}
switch ( $tab ) {
case GLOSSARY_IMPORT_VIEW:
case GLOSSARY_EXPORT_VIEW:
case GLOSSARY_APPROVAL_VIEW:
$showcommonelements = 0;
break;
default:
$showcommonelements = 1;
break;
}
/// Printing the heading /// Printing the heading
$strglossaries = get_string("modulenameplural", "glossary"); $strglossaries = get_string("modulenameplural", "glossary");
$strglossary = get_string("modulename", "glossary"); $strglossary = get_string("modulename", "glossary");
$strallcategories = get_string("allcategories", "glossary"); $strallcategories = get_string("allcategories", "glossary");
$straddentry = get_string("addentry", "glossary"); $straddentry = get_string("addentry", "glossary");
$strnoentries = get_string("noentries", "glossary"); $strnoentries = get_string("noentries", "glossary");
$strsearchconcept = get_string("searchconcept", "glossary"); $strsearchconcept = get_string("searchconcept", "glossary");
$strsearchindefinition = get_string("searchindefinition", "glossary"); $strsearchindefinition = get_string("searchindefinition", "glossary");
$strsearch = get_string("search"); $strsearch = get_string("search");
$strwaitingapproval = get_string('waitingapproval', 'glossary'); $strwaitingapproval = get_string('waitingapproval', 'glossary');
/// If we are in approval mode, prit special header /// If we are in approval mode, prit special header
$PAGE->set_title(format_string($glossary->name)); $PAGE->set_title(format_string($glossary->name));
$PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
$url = new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id)); $url = new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id));
if (isset($mode)) { if (isset($mode)) {
$url->param('mode', $mode); $url->param('mode', $mode);
} }
$PAGE->set_url($url); $PAGE->set_url($url);
if ($tab == GLOSSARY_APPROVAL_VIEW) { if ($tab == GLOSSARY_APPROVAL_VIEW) {
require_capability('mod/glossary:approve', $context); require_capability('mod/glossary:approve', $context);
$PAGE->navbar->add($strwaitingapproval); $PAGE->navbar->add($strwaitingapproval);
echo $OUTPUT->header(); echo $OUTPUT->header();
echo $OUTPUT->heading($strwaitingapproval); echo $OUTPUT->heading($strwaitingapproval);
} else { /// Print standard header } else { /// Print standard header
echo $OUTPUT->header(); echo $OUTPUT->header();
} }
/// All this depends if whe have $showcommonelements /// All this depends if whe have $showcommonelements
if ($showcommonelements) { if ($showcommonelements) {
/// To calculate available options /// To calculate available options
$availableoptions = ''; $availableoptions = '';
/// Decide about to print the import link /// Decide about to print the import link
if (has_capability('mod/glossary:import', $context)) { if (has_capability('mod/glossary:import', $context)) {
$availableoptions = '<span class="helplink">' . $availableoptions = '<span class="helplink">' .
'<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' . '<a href="' . $CFG->wwwroot . '/mod/glossary/import.php?id=' . $cm->id . '"' .
' title="' . s(get_string('importentries', 'glossary')) . '">' . ' title="' . s(get_string('importentries', 'glossary')) . '">' .
get_string('importentries', 'glossary') . '</a>' . get_string('importentries', 'glossary') . '</a>' .
'</span>'; '</span>';
}
/// Decide about to print the export link
if (has_capability('mod/glossary:export', $context)) {
if ($availableoptions) {
$availableoptions .= '&nbsp;/&nbsp;';
} }
/// Decide about to print the export link $availableoptions .='<span class="helplink">' .
if (has_capability('mod/glossary:export', $context)) { '<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id .
'&amp;mode='.$mode . '&amp;hook=' . urlencode($hook) . '"' .
' title="' . s(get_string('exportentries', 'glossary')) . '">' .
get_string('exportentries', 'glossary') . '</a>' .
'</span>';
}
/// Decide about to print the approval link
if (has_capability('mod/glossary:approve', $context)) {
/// Check we have pending entries
if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id, 'approved'=>0))) {
if ($availableoptions) { if ($availableoptions) {
$availableoptions .= '&nbsp;/&nbsp;'; $availableoptions .= '<br />';
} }
$availableoptions .='<span class="helplink">' . $availableoptions .='<span class="helplink">' .
'<a href="' . $CFG->wwwroot . '/mod/glossary/export.php?id=' . $cm->id . '<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id .
'&amp;mode='.$mode . '&amp;hook=' . urlencode($hook) . '"' . '&amp;mode=approval' . '"' .
' title="' . s(get_string('exportentries', 'glossary')) . '">' . ' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
get_string('exportentries', 'glossary') . '</a>' . get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
'</span>'; '</span>';
} }
}
/// Decide about to print the approval link /// Start to print glossary controls
if (has_capability('mod/glossary:approve', $context)) {
/// Check we have pending entries
if ($hiddenentries = $DB->count_records('glossary_entries', array('glossaryid'=>$glossary->id, 'approved'=>0))) {
if ($availableoptions) {
$availableoptions .= '<br />';
}
$availableoptions .='<span class="helplink">' .
'<a href="' . $CFG->wwwroot . '/mod/glossary/view.php?id=' . $cm->id .
'&amp;mode=approval' . '"' .
' title="' . s(get_string('waitingapproval', 'glossary')) . '">' .
get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')</a>' .
'</span>';
}
}
/// Start to print glossary controls
// print_box_start('glossarycontrol clearfix'); // print_box_start('glossarycontrol clearfix');
echo '<div class="glossarycontrol" style="text-align: right">'; echo '<div class="glossarycontrol" style="text-align: right">';
echo $availableoptions; echo $availableoptions;
/// If rss are activated at site and glossary level and this glossary has rss defined, show link /// If rss are activated at site and glossary level and this glossary has rss defined, show link
if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) && if (isset($CFG->enablerssfeeds) && isset($CFG->glossary_enablerssfeeds) &&
$CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) { $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) {
$tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true)); $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true));
if (empty($USER->id)) { if (empty($USER->id)) {
$userid = 0; $userid = 0;
} else { } else {
$userid = $USER->id; $userid = $USER->id;
} }
// print_box_start('rsslink'); // print_box_start('rsslink');
echo '<span class="wrap rsslink">'; echo '<span class="wrap rsslink">';
rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext); rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext);
echo '</span>'; echo '</span>';
// print_box_end(); // print_box_end();
} }
/// The print icon /// The print icon
if ( $showcommonelements and $mode != 'search') { if ( $showcommonelements and $mode != 'search') {
if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) { if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) {
// print_box_start('printicon'); // print_box_start('printicon');
echo '<span class="wrap printicon">'; echo '<span class="wrap printicon">';
echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;offset=$offset\"><img class=\"icon\" src=\"print.gif\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>"; echo " <a title =\"". get_string("printerfriendly","glossary") ."\" href=\"print.php?id=$cm->id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;offset=$offset\"><img class=\"icon\" src=\"print.gif\" alt=\"". get_string("printerfriendly","glossary") . "\" /></a>";
echo '</span>'; echo '</span>';
// print_box_end(); // print_box_end();
}
} }
/// End glossary controls }
/// End glossary controls
// print_box_end(); /// glossarycontrol // print_box_end(); /// glossarycontrol
echo '</div>'; echo '</div>';
// print_box('&nbsp;', 'clearer'); // print_box('&nbsp;', 'clearer');
} }
/// Info box /// Info box
if ($glossary->intro && $showcommonelements) { if ($glossary->intro && $showcommonelements) {
echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro'); echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro');
} }
/// Search box /// Search box
if ($showcommonelements ) { if ($showcommonelements ) {
echo '<form method="post" action="view.php">'; echo '<form method="post" action="view.php">';
echo '<table class="boxaligncenter" width="70%" border="0">'; echo '<table class="boxaligncenter" width="70%" border="0">';
echo '<tr><td align="center" class="glossarysearchbox">'; echo '<tr><td align="center" class="glossarysearchbox">';
echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> '; echo '<input type="submit" value="'.$strsearch.'" name="searchbutton" /> ';
if ($mode == 'search') { if ($mode == 'search') {
echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> '; echo '<input type="text" name="hook" size="20" value="'.s($hook).'" alt="'.$strsearch.'" /> ';
} else { } else {
echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> '; echo '<input type="text" name="hook" size="20" value="" alt="'.$strsearch.'" /> ';
}
if ($fullsearch || $mode != 'search') {
$fullsearchchecked = 'checked="checked"';
} else {
$fullsearchchecked = '';
}
echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />';
echo '<input type="hidden" name="mode" value="search" />';
echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo '<label for="fullsearch">'.$strsearchindefinition.'</label>';
echo '</td></tr></table>';
echo '</form>';
echo '<br />';
} }
if ($fullsearch || $mode != 'search') {
$fullsearchchecked = 'checked="checked"';
} else {
$fullsearchchecked = '';
}
echo '<input type="checkbox" name="fullsearch" id="fullsearch" value="1" '.$fullsearchchecked.' />';
echo '<input type="hidden" name="mode" value="search" />';
echo '<input type="hidden" name="id" value="'.$cm->id.'" />';
echo '<label for="fullsearch">'.$strsearchindefinition.'</label>';
echo '</td></tr></table>';
echo '</form>';
echo '<br />';
}
/// Show the add entry button if allowed /// Show the add entry button if allowed
if (has_capability('mod/glossary:write', $context) && $showcommonelements ) { if (has_capability('mod/glossary:write', $context) && $showcommonelements ) {
echo '<div class="singlebutton glossaryaddentry">'; echo '<div class="singlebutton glossaryaddentry">';
echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">"; echo "<form id=\"newentryform\" method=\"get\" action=\"$CFG->wwwroot/mod/glossary/edit.php\">";
echo '<div>'; echo '<div>';
echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />"; echo "<input type=\"hidden\" name=\"cmid\" value=\"$cm->id\" />";
echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />'; echo '<input type="submit" value="'.get_string('addentry', 'glossary').'" />';
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
echo "</div>\n"; echo "</div>\n";
} }
echo '<br />'; echo '<br />';
require("tabs.php"); require("tabs.php");
require("sql.php"); require("sql.php");
/// printing the entries /// printing the entries
$entriesshown = 0; $entriesshown = 0;
$currentpivot = ''; $currentpivot = '';
$ratingsmenuused = NULL; $ratingsmenuused = NULL;
$paging = NULL; $paging = NULL;
if ($allentries) { if ($allentries) {
//Decide if we must show the ALL link in the pagebar //Decide if we must show the ALL link in the pagebar
$specialtext = ''; $specialtext = '';
if ($glossary->showall) { if ($glossary->showall) {
$specialtext = get_string("allentries","glossary"); $specialtext = get_string("allentries","glossary");
}
//Build paging bar
$paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;fullsearch=$fullsearch&amp;",9999,10,'&nbsp;&nbsp;', $specialtext, -1);
echo '<div class="paging">';
echo $paging;
echo '</div>';
$ratings = NULL;
$ratingsmenuused = false;
if ($glossary->assessed and isloggedin() and !isguestuser()) {
$ratings = new object();
if ($ratings->scale = make_grades_menu($glossary->scale)) {
$ratings->assesstimestart = $glossary->assesstimestart;
$ratings->assesstimefinish = $glossary->assesstimefinish;
}
if ($glossary->assessed == 2 and !has_capability('mod/glossary:rate', $context)) {
$ratings->allow = false;
} else {
$ratings->allow = true;
}
$formsent = 1;
echo "<form method=\"post\" action=\"rate.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"glossaryid\" value=\"$glossary->id\" />";
}
foreach ($allentries as $entry) {
// Setting the pivot for the current entry
$pivot = $entry->glossarypivot;
$upperpivot = $textlib->strtoupper($pivot);
// Reduce pivot to 1cc if necessary
if ( !$fullpivot ) {
$upperpivot = $textlib->substr($upperpivot, 0, 1);
} }
//Build paging bar // if there's a group break
$paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&amp;mode=$mode&amp;hook=".urlencode($hook)."&amp;sortkey=$sortkey&amp;sortorder=$sortorder&amp;fullsearch=$fullsearch&amp;",9999,10,'&nbsp;&nbsp;', $specialtext, -1); if ( $currentpivot != $upperpivot ) {
echo '<div class="paging">'; // print the group break if apply
echo $paging; if ( $printpivot ) {
echo '</div>'; $currentpivot = $upperpivot;
echo '<div>';
echo '<table cellspacing="0" class="glossarycategoryheader">';
echo '<tr>';
$pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors)
echo '<th align="left">';
$user = $DB->get_record("user", array("id"=>$entry->userid));
echo $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id));
$pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
} else {
echo '<th >';
}
echo $OUTPUT->heading($pivottoshow);
echo "</th></tr></table></div>\n";
$ratings = NULL;
$ratingsmenuused = false;
if ($glossary->assessed and isloggedin() and !isguestuser()) {
$ratings = new object();
if ($ratings->scale = make_grades_menu($glossary->scale)) {
$ratings->assesstimestart = $glossary->assesstimestart;
$ratings->assesstimefinish = $glossary->assesstimefinish;
} }
if ($glossary->assessed == 2 and !has_capability('mod/glossary:rate', $context)) {
$ratings->allow = false;
} else {
$ratings->allow = true;
}
$formsent = 1;
echo "<form method=\"post\" action=\"rate.php\">";
echo "<div>";
echo "<input type=\"hidden\" name=\"glossaryid\" value=\"$glossary->id\" />";
} }
foreach ($allentries as $entry) { $concept = $entry->concept;
$definition = $entry->definition;
// Setting the pivot for the current entry
$pivot = $entry->glossarypivot;
$upperpivot = $textlib->strtoupper($pivot);
// Reduce pivot to 1cc if necessary
if ( !$fullpivot ) {
$upperpivot = $textlib->substr($upperpivot, 0, 1);
}
// if there's a group break
if ( $currentpivot != $upperpivot ) {
// print the group break if apply
if ( $printpivot ) {
$currentpivot = $upperpivot;
echo '<div>';
echo '<table cellspacing="0" class="glossarycategoryheader">';
echo '<tr>';
$pivottoshow = $currentpivot;
if ( isset($entry->userispivot) ) {
// printing the user icon if defined (only when browsing authors)
echo '<th align="left">';
$user = $DB->get_record("user", array("id"=>$entry->userid));
echo $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id));
$pivottoshow = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
} else {
echo '<th >';
}
echo $OUTPUT->heading($pivottoshow);
echo "</th></tr></table></div>\n";
/// highlight the term if necessary
if ($mode == 'search') {
//We have to strip any word starting by + and take out words starting by -
//to make highlight works properly
$searchterms = explode(' ', $hook); // Search for words independently
foreach ($searchterms as $key => $searchterm) {
if (preg_match('/^\-/',$searchterm)) {
unset($searchterms[$key]);
} else {
$searchterms[$key] = preg_replace('/^\+/','',$searchterm);
}
//Avoid highlight of <2 len strings. It's a well known hilight limitation.
if (strlen($searchterm) < 2) {
unset($searchterms[$key]);
} }
} }
$strippedsearch = implode(' ', $searchterms); // Rebuild the string
$entry->highlight = $strippedsearch;
}
$concept = $entry->concept; /// and finally print the entry.
$definition = $entry->definition;
/// highlight the term if necessary if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) {
if ($mode == 'search') { $ratingsmenuused = true;
//We have to strip any word starting by + and take out words starting by - }
//to make highlight works properly
$searchterms = explode(' ', $hook); // Search for words independently
foreach ($searchterms as $key => $searchterm) {
if (preg_match('/^\-/',$searchterm)) {
unset($searchterms[$key]);
} else {
$searchterms[$key] = preg_replace('/^\+/','',$searchterm);
}
//Avoid highlight of <2 len strings. It's a well known hilight limitation.
if (strlen($searchterm) < 2) {
unset($searchterms[$key]);
}
}
$strippedsearch = implode(' ', $searchterms); // Rebuild the string
$entry->highlight = $strippedsearch;
}
/// and finally print the entry. $entriesshown++;
}
}
if ( !$entriesshown ) {
echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide");
}
if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) {
$ratingsmenuused = true;
}
$entriesshown++; if ($ratingsmenuused) {
echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />";
if ($glossary->scale < 0) {
if ($scale = $DB->get_record("scale", array("id"=>abs($glossary->scale)))) {
echo $OUTPUT->help_button(help_button::make_scale_menu($course->id, $scale));
} }
} }
if ( !$entriesshown ) { echo "</div>";
echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide"); }
}
if (!empty($formsent)) {
// close the form properly if used
echo "</div>";
echo "</form>";
}
if ($ratingsmenuused) { if ( $paging ) {
echo '<hr />';
echo "<div class=\"boxaligncenter\"><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\" />"; echo '<div class="paging">';
if ($glossary->scale < 0) { echo $paging;
if ($scale = $DB->get_record("scale", array("id"=>abs($glossary->scale)))) { echo '</div>';
echo $OUTPUT->help_button(help_button::make_scale_menu($course->id, $scale)); }
} echo '<br />';
} glossary_print_tabbed_table_end();
echo "</div>";
}
if (!empty($formsent)) {
// close the form properly if used
echo "</div>";
echo "</form>";
}
if ( $paging ) {
echo '<hr />';
echo '<div class="paging">';
echo $paging;
echo '</div>';
}
echo '<br />';
glossary_print_tabbed_table_end();
/// Finish the page /// Finish the page
echo $OUTPUT->footer(); echo $OUTPUT->footer();
/// Mark as viewed /// Mark as viewed
$completion=new completion_info($course); $completion=new completion_info($course);
$completion->set_module_viewed($cm); $completion->set_module_viewed($cm);
?>
?>