From: samhemelryk Date: Thu, 24 Sep 2009 07:29:14 +0000 (+0000) Subject: mod-glossary MDL-19809 Added set_url calls, replaced deprecated functions X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=5fa0208ec344d07e56abf517234413440a5fd560;p=moodle.git mod-glossary MDL-19809 Added set_url calls, replaced deprecated functions --- diff --git a/mod/glossary/approve.php b/mod/glossary/approve.php index 6fbf476b96..7bfa9ba85f 100644 --- a/mod/glossary/approve.php +++ b/mod/glossary/approve.php @@ -1,38 +1,51 @@ -wwwroot.'/mod/glossary/approve.php', array('id'=>$id)); +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))) { - print_error('coursemisconf'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + 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:approve', $context); +require_login($course->id, false, $cm); - $newentry = new object(); - $newentry->id = $eid; - $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 +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:approve', $context); - $DB->update_record("glossary_entries", $newentry); - add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id); - redirect("view.php?id=$cm->id&mode=$mode&hook=$hook",get_string("entryapproved","glossary"),1); - die; -?> +$newentry = new object(); +$newentry->id = $eid; +$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); +add_to_log($course->id, "glossary", "approve entry", "showentry.php?id=$cm->id&eid=$eid", "$eid",$cm->id); +redirect("view.php?id=$cm->id&mode=$mode&hook=$hook",get_string("entryapproved","glossary"),1); +die; + +?> \ No newline at end of file diff --git a/mod/glossary/comment.php b/mod/glossary/comment.php index ecb7b13177..8ab6834123 100644 --- a/mod/glossary/comment.php +++ b/mod/glossary/comment.php @@ -1,4 +1,4 @@ -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'); } @@ -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($straction); $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(); /// print original glossary entry for any comment action (add, update, delete) diff --git a/mod/glossary/comments.php b/mod/glossary/comments.php index 84bb3f1db9..67497ccb4d 100644 --- a/mod/glossary/comments.php +++ b/mod/glossary/comments.php @@ -1,76 +1,78 @@ -set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$id,'eid'=>$eid))); - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidcousemodule'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} - if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) { - print_error('invalidentry'); - } +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidcousemodule'); +} + +if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) { + print_error('invalidentry'); +} - $context = get_context_instance(CONTEXT_MODULE, $cm->id); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_login($course->id, false, $cm); +require_login($course->id, false, $cm); - add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id); +add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id); - $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"); - $strcomments = get_string("comments", "glossary"); - $straddcomment = get_string("addcomment", "glossary"); +$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"); +$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(update_module_button($cm->id, $course->id, $strglossary)); - echo $OUTPUT->header(); +$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 - echo "
"; - glossary_print_entry($course, $cm, $glossary, $entry, "", "", false); - echo "
"; +echo "
"; +glossary_print_entry($course, $cm, $glossary, $entry, "", "", false); +echo "
"; /// comments - echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." \"$entry->concept\"")); +echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." \"$entry->concept\"")); - if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { - echo $OUTPUT->heading("id\">$straddcomment \"$straddcomment\""); - } +if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { + echo $OUTPUT->heading("id\">$straddcomment \"$straddcomment\""); +} - if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) { - foreach ($comments as $comment) { - glossary_print_comment($course, $cm, $glossary, $entry, $comment); - echo '
'; - } - } else { - echo $OUTPUT->heading(get_string("nocomments","glossary")); +if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) { + foreach ($comments as $comment) { + glossary_print_comment($course, $cm, $glossary, $entry, $comment); + echo '
'; } +} else { + echo $OUTPUT->heading(get_string("nocomments","glossary")); +} /// Finish the page - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php index 92435d3a22..766ae48368 100644 --- a/mod/glossary/deleteentry.php +++ b/mod/glossary/deleteentry.php @@ -1,106 +1,119 @@ -get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } - - if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) { - print_error('invalidentry'); - } - - require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $manageentries = has_capability('mod/glossary:manageentries', $context); - - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +wwwroot.'/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode)); +if ($confirm !== 0) { + $url->param('confirm', $confirm); +} +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)) { + print_error("invalidcoursemodule"); +} + +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} + +if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) { + print_error('invalidentry'); +} + +require_login($course->id, false, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +$manageentries = has_capability('mod/glossary:manageentries', $context); + +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidid', 'glossary'); +} + + +$strareyousuredelete = get_string("areyousuredelete","glossary"); + +if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here + print_error('nopermissiontodelentry'); +} +$ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); +if (!$ineditperiod and !$manageentries) { + print_error('errdeltimeexpired', 'glossary'); +} +/// If data submitted, then process and store. - $strareyousuredelete = get_string("areyousuredelete","glossary"); +if ($confirm and confirm_sesskey()) { // the operation was confirmed. + // if it is an imported entry, just delete the relation - if (($entry->userid != $USER->id) and !$manageentries) { // guest id is never matched, no need for special check here - print_error('nopermissiontodelentry'); - } - $ineditperiod = ((time() - $entry->timecreated < $CFG->maxeditingtime) || $glossary->editalways); - if (!$ineditperiod and !$manageentries) { - print_error('errdeltimeexpired', 'glossary'); - } + if ($entry->sourceglossaryid) { + if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { + print_error('invalidcoursemodule'); + } + $newcontext = get_context_instance(CONTEXT_MODULE, $newcm->id); -/// If data submitted, then process and store. + $entry->glossaryid = $entry->sourceglossaryid; + $entry->sourceglossaryid = 0; + $DB->update_record('glossary_entries', $entry); - if ($confirm and confirm_sesskey()) { // the operation was confirmed. - // if it is an imported entry, just delete the relation + // move attachments too + $fs = get_file_storage(); - if ($entry->sourceglossaryid) { - if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) { - 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'; + 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); } - $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)); + $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)); + } - add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id,$cm->id); - redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook"); + add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id,$cm->id); + redirect("view.php?id=$cm->id&mode=$prevmode&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(update_module_button($cm->id, $course->id, $strglossary)); - echo $OUTPUT->header(); - $areyousure = "".format_string($entry->concept)."

$strareyousuredelete

"; - $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); +} 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 = "".format_string($entry->concept)."

$strareyousuredelete

"; + $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->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); - echo $OUTPUT->footer(); - } -?> + echo $OUTPUT->footer(); +} + +?> \ No newline at end of file diff --git a/mod/glossary/editcategories.php b/mod/glossary/editcategories.php index 166200d07e..9640be99fe 100644 --- a/mod/glossary/editcategories.php +++ b/mod/glossary/editcategories.php @@ -1,109 +1,131 @@ -wwwroot.'/mod/glossary/editcategories.php', array('id'=>$id)); +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); +} + +$PAGE->set_url($url); + +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} + +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} + +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidcoursemodule'); +} + +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'); + } +} - $id = required_param('id', PARAM_INT); // Course Module ID, or - $usedynalink = optional_param('usedynalink', 0, PARAM_INT); // category ID - $confirm = optional_param('confirm', 0, PARAM_INT); // confirm the action - $name = optional_param('name', '', PARAM_CLEAN); // confirm the name +require_login($course->id, false, $cm); - $action = optional_param('action', '', PARAM_ALPHA ); // what to do - $hook = optional_param('hook', '', PARAM_ALPHANUM); // category ID - $mode = optional_param('mode', '', PARAM_ALPHA); // cat +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:managecategories', $context); - $action = strtolower($action); +$strglossaries = get_string("modulenameplural", "glossary"); +$strglossary = get_string("modulename", "glossary"); - if (! $cm = get_coursemodule_from_id('glossary', $id)) { - print_error('invalidcoursemodule'); - } +$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(get_string("categories","glossary")); +$PAGE->set_title(format_string($glossary->name)); +$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary')); +echo $OUTPUT->header(); - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } - - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidcoursemodule'); - } +if ( $hook >0 ) { - 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'); - } - } + if ( $action == "edit" ) { + if ( $confirm ) { + $action = ""; + $cat = new object(); + $cat->id = $hook; + $cat->name = $name; + $cat->usedynalink = $usedynalink; - require_login($course->id, false, $cm); + $DB->update_record("glossary_categories", $cat); + add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/glossary:managecategories', $context); + } else { + echo "

" . get_string("edit"). " " . get_string("category","glossary") . ""; - $strglossaries = get_string("modulenameplural", "glossary"); - $strglossary = get_string("modulename", "glossary"); + $name = $category->name; + $usedynalink = $category->usedynalink; + require "editcategories.html"; + echo $OUTPUT->footer(); + die; + } - $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(get_string("categories","glossary")); - $PAGE->set_title(format_string($glossary->name)); - $PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); - echo $OUTPUT->header(); + } elseif ( $action == "delete" ) { + if ( $confirm ) { + $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook)); + $DB->delete_records("glossary_categories", array("id"=>$hook)); - if ( $hook >0 ) { + echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); + echo "

" . get_string("categorydeleted","glossary") ."
"; + echo ""; + echo $OUTPUT->box_end(); + echo $OUTPUT->footer(); - if ( $action == "edit" ) { - if ( $confirm ) { - $action = ""; - $cat = new object(); - $cat->id = $hook; - $cat->name = $name; - $cat->usedynalink = $usedynalink; + add_to_log($course->id, "glossary", "delete category", "editcategories.php?id=$cm->id", $hook,$cm->id); - $DB->update_record("glossary_categories", $cat); - add_to_log($course->id, "glossary", "edit category", "editcategories.php?id=$cm->id", $hook,$cm->id); + redirect("editcategories.php?id=$cm->id"); + } else { + echo "

" . get_string("delete"). " " . get_string("category","glossary"). "

"; - } else { - echo "

" . get_string("edit"). " " . get_string("category","glossary") . ""; + echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); + echo "

".format_text($category->name, FORMAT_PLAIN)."
"; - $name = $category->name; - $usedynalink = $category->usedynalink; - require "editcategories.html"; - echo $OUTPUT->footer(); - die; + $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id)); + if ( $num_entries ) { + print_string("deletingnoneemptycategory","glossary"); } - - } 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 "
" . get_string("categorydeleted","glossary") ."
"; - echo ""; - 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 "

" . get_string("delete"). " " . get_string("category","glossary"). "

"; - - echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); - echo "
".format_text($category->name, FORMAT_PLAIN)."
"; - - $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id)); - if ( $num_entries ) { - print_string("deletingnoneemptycategory","glossary"); - } - echo "

"; - print_string("areyousuredelete","glossary"); - echo "

"; + echo "

"; + print_string("areyousuredelete","glossary"); + echo "

"; ?> @@ -123,49 +145,49 @@
$id); - echo $OUTPUT->button(html_form::make_button("editcategories.php", $options, get_string("no"))); - echo "
"; - echo "
"; - echo $OUTPUT->box_end(); - } + unset($options); + $options = array ("id" => $id); + echo $OUTPUT->button(html_form::make_button("editcategories.php", $options, get_string("no"))); + echo ""; + echo "
"; + echo $OUTPUT->box_end(); } + } + +} elseif ( $action == "add" ) { + if ( $confirm ) { + $ILIKE = $DB->sql_ilike(); + $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id)); + if ( $dupcategory ) { + echo "

" . get_string("add"). " " . get_string("category","glossary"); + + echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); + echo "

" . get_string("duplicatedcategory","glossary") ."
"; + echo $OUTPUT->box_end(); + + redirect("editcategories.php?id=$cm->id&action=add&&name=$name"); - } elseif ( $action == "add" ) { - if ( $confirm ) { - $ILIKE = $DB->sql_ilike(); - $dupcategory = $DB->get_records_sql("SELECT * FROM {glossary_categories} WHERE name $ILIKE ? AND glossaryid=?", array($name, $glossary->id)); - if ( $dupcategory ) { - echo "

" . get_string("add"). " " . get_string("category","glossary"); - - echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow'); - echo "

" . get_string("duplicatedcategory","glossary") ."
"; - echo $OUTPUT->box_end(); - - redirect("editcategories.php?id=$cm->id&action=add&&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 { - echo "

" . get_string("add"). " " . get_string("category","glossary"). "

"; - $name=""; - require "editcategories.html"; + $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 { + echo "

" . get_string("add"). " " . get_string("category","glossary"). "

"; + $name=""; + require "editcategories.html"; } +} - if ( $action ) { - echo $OUTPUT->footer(); - die; - } +if ( $action ) { + echo $OUTPUT->footer(); + die; +} ?> diff --git a/mod/glossary/export.php b/mod/glossary/export.php index 94804cc765..e669f91a70 100644 --- a/mod/glossary/export.php +++ b/mod/glossary/export.php @@ -1,51 +1,63 @@ -wwwroot.'/mod/glossary/export.php', array('id'=>$id)); +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))) { - print_error('coursemisconf'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} + +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidid', 'glossary'); +} - require_login($course->id, false, $cm); +require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/glossary:export', $context); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:export', $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"); - $strexportfile = get_string("exportfile", "glossary"); - $strexportentries = get_string('exportentriestoxml', 'glossary'); +$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"); +$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))); - $PAGE->navbar->add($strexportentries); - $PAGE->set_title(format_string($glossary->name)); - $PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/export.php', array('id'=>$cm->id))); +$PAGE->navbar->add($strexportentries); +$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'); - ?> +echo $OUTPUT->header(); +echo $OUTPUT->heading($strexportentries); +echo $OUTPUT->box_start('glossarydisplay generalbox'); +?>
diff --git a/mod/glossary/exportentry.php b/mod/glossary/exportentry.php index bee7a4dc87..2d63c3e024 100644 --- a/mod/glossary/exportentry.php +++ b/mod/glossary/exportentry.php @@ -1,112 +1,123 @@ -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'); - } - redirect('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id); - } - - if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { +wwwroot.'/mod/glossary/exportentry.php', array('id'=>$id,'prevmode'=>$prevmode)); +if ($confirm !== 0) { + $url->param('confirm', $confirm); +} +if ($hook !== 'ALL') { + $url->param('hook', $hook); +} +$PAGE->set_url($url); + +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'); } + redirect('view.php?id='.$cm->id.'&mode=entry&hook='.$entry->id); +} - if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +if (!$cm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { + print_error('invalidcoursemodule'); +} - if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { - print_error('coursemisconf'); - } +if (!$glossary = $DB->get_record('glossary', array('id'=>$cm->instance))) { + print_error('invalidid', 'glossary'); +} - require_course_login($course->id, true, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/glossary:export', $context); +if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { + print_error('coursemisconf'); +} - $returnurl = "view.php?id=$cm->id&mode=$prevmode&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))) { - //main glossary not present - redirect($returnurl); - } +$returnurl = "view.php?id=$cm->id&mode=$prevmode&hook=".urlencode($hook); - if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) { - print_error('invalidcoursemodule'); - } +if (!$mainglossary = $DB->get_record('glossary', array('course'=>$cm->course, 'mainglossary'=>1))) { + //main glossary not present + redirect($returnurl); +} - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - $maincontext = get_context_instance(CONTEXT_MODULE, $maincm->id); +if (!$maincm = get_coursemodule_from_instance('glossary', $mainglossary->id)) { + print_error('invalidcoursemodule'); +} - if (!$course = $DB->get_record('course', array('id'=>$cm->course))) { - print_error('coursemisconf'); - } +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +$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'); - $entryalreadyexist = get_string('entryalreadyexist','glossary'); - $entryexported = get_string('entryexported','glossary'); - if (!$mainglossary->allowduplicatedentries) { - 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; - } - } +$strglossaries = get_string('modulenameplural', 'glossary'); +$entryalreadyexist = get_string('entryalreadyexist','glossary'); +$entryexported = get_string('entryexported','glossary'); - if (!data_submitted() or !$confirm or !confirm_sesskey()) { +if (!$mainglossary->allowduplicatedentries) { + 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 '
'; - $areyousure = '

'.format_string($entry->concept).'

'.get_string('areyousureexport','glossary').'
'.format_string($mainglossary->name).'?'; - $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 '

'; + echo $OUTPUT->notification(get_string('errconceptalreadyexists', 'glossary')); + echo $OUTPUT->continue_button($returnurl); + echo $OUTPUT->box_end(); 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'; + } +} + +if (!data_submitted() or !$confirm or !confirm_sesskey()) { + $PAGE->set_title(format_string($glossary->name)); + echo $OUTPUT->header(); + echo '
'; + $areyousure = '

'.format_string($entry->concept).'

'.get_string('areyousureexport','glossary').'
'.format_string($mainglossary->name).'?'; + $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 '

'; + 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); } - $DB->update_record('glossary_entries', $entry); - - redirect ($returnurl); + $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); +} + +?> \ No newline at end of file diff --git a/mod/glossary/exportfile.php b/mod/glossary/exportfile.php index 12f4c301bc..5589bbf48b 100644 --- a/mod/glossary/exportfile.php +++ b/mod/glossary/exportfile.php @@ -1,35 +1,45 @@ -wwwroot.'/mod/glossary/exportfile.php', array('id'=>$id)); +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))) { - print_error('coursemisconf'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} - require_login($course->id, false, $cm); - - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/glossary:export', $context); - - $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); -?> +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidid', 'glossary'); +} + +require_login($course->id, false, $cm); + +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:export', $context); + +$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); + +?> \ No newline at end of file diff --git a/mod/glossary/formats.php b/mod/glossary/formats.php index fdda0f4c09..a336e3376c 100644 --- a/mod/glossary/formats.php +++ b/mod/glossary/formats.php @@ -1,255 +1,262 @@ -libdir.'/adminlib.php'); - require_once("lib.php"); +/// This file allows to manage the default behaviour of the display formats - $id = required_param('id', PARAM_INT); - $mode = optional_param('mode', '', PARAM_ACTION); +require_once("../../config.php"); +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))) { - print_error('invalidglossaryformat', 'glossary'); - } +$url = new moodle_url($CFG->wwwroot.'/mod/glossary/formats.php', array('id'=>$id)); +if ($mode !== '') { + $url->param('mode', $mode); +} +$PAGE->set_url($url); - $form = data_submitted(); - 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) { +admin_externalpage_setup('managemodules'); // this is hacky, tehre should be a special hidden page for it - $displayformat->popupformatname = $form->popupformatname; - $displayformat->showgroup = $form->showgroup; - $displayformat->defaultmode = $form->defaultmode; - $displayformat->defaulthook = $form->defaulthook; - $displayformat->sortkey = $form->sortkey; - $displayformat->sortorder = $form->sortorder; +if ( !$displayformat = $DB->get_record("glossary_formats", array("id"=>$id))) { + print_error('invalidglossaryformat', 'glossary'); +} +$form = data_submitted(); +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; } + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header"); + die; +} elseif ( $mode == 'edit' and $form) { - $strmodulename = get_string("modulename", "glossary"); - $strdisplayformats = get_string("displayformats","glossary"); + $displayformat->popupformatname = $form->popupformatname; + $displayformat->showgroup = $form->showgroup; + $displayformat->defaultmode = $form->defaultmode; + $displayformat->defaulthook = $form->defaulthook; + $displayformat->sortkey = $form->sortkey; + $displayformat->sortorder = $form->sortorder; - admin_externalpage_print_header(); + $DB->update_record("glossary_formats",$displayformat); + redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=modsettingglossary#glossary_formats_header"); + die; +} - echo $OUTPUT->heading($strmodulename . ': ' . get_string("displayformats","glossary")); +$strmodulename = get_string("modulename", "glossary"); +$strdisplayformats = get_string("displayformats","glossary"); - echo $OUTPUT->box(get_string("configwarning", 'admin'), "generalbox boxaligncenter boxwidthnormal"); - echo "
"; +admin_externalpage_print_header(); - $yes = get_string("yes"); - $no = get_string("no"); +echo $OUTPUT->heading($strmodulename . ': ' . get_string("displayformats","glossary")); - echo ''; - echo ''; - ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - '; - - echo $OUTPUT->footer(); +echo ''; +echo '
- name,'glossary'); ?> -
- box(get_string("configwarning", 'admin'), "generalbox boxaligncenter boxwidthnormal"); +echo "
"; - $formats = array(); +$yes = get_string("yes"); +$no = get_string("no"); - //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)); - ?> -
-

-
- - -

-
- - -

-
- - -

-
- - -

-
: - - -

-
- " />
'; ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +'; + +echo $OUTPUT->footer(); +?> \ No newline at end of file diff --git a/mod/glossary/import.php b/mod/glossary/import.php index 759ee38e90..ea530c1695 100644 --- a/mod/glossary/import.php +++ b/mod/glossary/import.php @@ -1,357 +1,378 @@ -dirroot/course/lib.php"); +require_once("../../config.php"); +require_once("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); - $dest = optional_param('dest', 'current', PARAM_ALPHA); // current | new - $file = optional_param('file', '', PARAM_FILE); // file to import - $catsincl = optional_param('catsincl', 0, PARAM_INT); // Import Categories too? +$step = optional_param('step', 0, PARAM_INT); +$dest = optional_param('dest', 'current', PARAM_ALPHA); // current | new +$file = optional_param('file', '', PARAM_FILE); // file to import +$catsincl = optional_param('catsincl', 0, PARAM_INT); // Import Categories too? - $mode = optional_param('mode', 'letter', PARAM_ALPHA ); - $hook = optional_param('hook', 'ALL', PARAM_ALPHANUM); +$mode = optional_param('mode', 'letter', PARAM_ALPHA ); +$hook = optional_param('hook', 'ALL', PARAM_ALPHANUM); - if (! $cm = get_coursemodule_from_id('glossary', $id)) { - print_error('invalidcoursemodule'); - } +$url = new moodle_url($CFG->wwwroot.'/mod/glossary/import.php', array('id'=>$id)); +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))) { - print_error('coursemisconf'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + 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:import', $context); +require_login($course->id, false, $cm); - if ($dest != 'new' and $dest != 'current') { - $dest = 'current'; - } - $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))); - $PAGE->navbar->add($strimportentries); - $PAGE->set_title(format_string($glossary->name)); - $PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); - - echo $OUTPUT->header(); - echo $OUTPUT->heading($strimportentries); - - if ( !$step ) { - echo $OUTPUT->box_start('glossarydisplay generalbox'); - include("import.html"); - echo $OUTPUT->box_end(); - - echo $OUTPUT->footer(); - exit; - } +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:import', $context); - $form = data_submitted(); - $file = $_FILES["file"]; +if ($dest != 'new' and $dest != 'current') { + $dest = 'current'; +} +$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))); +$PAGE->navbar->add($strimportentries); +$PAGE->set_title(format_string($glossary->name)); +$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary')); + +echo $OUTPUT->header(); +echo $OUTPUT->heading($strimportentries); + +if ( !$step ) { + echo $OUTPUT->box_start('glossarydisplay generalbox'); + include("import.html"); + echo $OUTPUT->box_end(); - require_once($CFG->dirroot.'/lib/uploadlib.php'); - $um = new upload_manager('file',false,false,$course,false,0); + echo $OUTPUT->footer(); + exit; +} - if (!$um->preprocess_files()) { - echo $OUTPUT->box_start('glossarydisplay generalbox'); - echo $OUTPUT->continue_button('import.php?id='.$id); - echo $OUTPUT->box_end(); +$form = data_submitted(); +$file = $_FILES["file"]; - echo $OUTPUT->footer(); - die(); - } +require_once($CFG->dirroot.'/lib/uploadlib.php'); +$um = new upload_manager('file',false,false,$course,false,0); - if ($xml = glossary_read_imported_file($file['tmp_name']) ) { - - $importedentries = 0; - $importedcats = 0; - $entriesrejected = 0; - $rejections = ''; - if ($dest == 'new') { - // If the user chose to create a new glossary - $xmlglossary = $xml['GLOSSARY']['#']['INFO'][0]['#']; - - if ( $xmlglossary['NAME'][0]['#'] ) { - 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 - if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) { - $glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']); - } 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; - } +if (!$um->preprocess_files()) { + echo $OUTPUT->box_start('glossarydisplay generalbox'); + echo $OUTPUT->continue_button('import.php?id='.$id); + echo $OUTPUT->box_end(); - // 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 ''; - glossary_print_tabbed_table_end(); - echo $OUTPUT->footer(); - 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 + echo $OUTPUT->footer(); + die(); +} - $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 ($xml = glossary_read_imported_file($file['tmp_name']) ) { + + $importedentries = 0; + $importedcats = 0; + $entriesrejected = 0; + $rejections = ''; + if ($dest == 'new') { + // If the user chose to create a new glossary + $xmlglossary = $xml['GLOSSARY']['#']['INFO'][0]['#']; + + if ( $xmlglossary['NAME'][0]['#'] ) { + 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 + if ( isset($xmlglossary['ENTBYPAGE'][0]['#']) ) { + $glossary->entbypage = ($xmlglossary['ENTBYPAGE'][0]['#']); + } 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; + } - 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; + // 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 ''; + glossary_print_tabbed_table_end(); + echo $OUTPUT->footer(); + 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 - if (! $mod->coursemodule = add_course_module($mod) ) { - print_error('cannotaddcoursemodule'); - } + $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 (! $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)); + 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; - $DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule)); - $DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule)); + if (! $mod->coursemodule = add_course_module($mod) ) { + print_error('cannotaddcoursemodule'); + } - 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); + 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)); - rebuild_course_cache($course->id); + $DB->set_field("course_modules", "visible", $visible, array("id"=>$mod->coursemodule)); + $DB->set_field("course_modules", "section", $sectionid, array("id"=>$mod->coursemodule)); - echo $OUTPUT->box(get_string("newglossarycreated","glossary"),'generalbox boxaligncenter boxwidthnormal'); - echo '

'; - } - } else { - echo $OUTPUT->notification("Error while trying to create the new glossary."); - echo $OUTPUT->footer(); - exit; + 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 '

'; } + } 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']; + 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; + } - $permissiongranted = 1; - if ( $newentry->concept and $newentry->definition ) { - if ( !$glossary->allowduplicatedentries ) { - // checking if the entry is valid (checking if it is duplicated when should not be) - if ( $newentry->casesensitive ) { - $dupentry = $DB->get_record("glossary_entries", array("concept"=>$newentry->concept, "glossaryid"=>$glossary->id)); - } else { - $dupentry = $DB->get_record("glossary_entries", array("lower(concept)"=>moodle_strtolower($newentry->concept)), array("glossaryid"=>$glossary->id)); - } - 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]['#']; + $permissiongranted = 1; + if ( $newentry->concept and $newentry->definition ) { + if ( !$glossary->allowduplicatedentries ) { + // checking if the entry is valid (checking if it is duplicated when should not be) + if ( $newentry->casesensitive ) { + $dupentry = $DB->get_record("glossary_entries", array("concept"=>$newentry->concept, "glossaryid"=>$glossary->id)); } else { - $newentry->usedynalink = $CFG->glossary_linkentries; + $dupentry = $DB->get_record("glossary_entries", array("lower(concept)"=>moodle_strtolower($newentry->concept)), array("glossaryid"=>$glossary->id)); } - if ( isset($xmlentry['#']['FULLMATCH'][0]['#']) ) { - $newentry->fullmatch = $xmlentry['#']['FULLMATCH'][0]['#']; - } else { - $newentry->fullmatch = $CFG->glossary_fullmatch; + 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 { + $newentry->usedynalink = $CFG->glossary_linkentries; + } + 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) ) { - $importedentries++; + if ( $newentry->id = $DB->insert_record("glossary_entries",$newentry) ) { + $importedentries++; - $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES - for($k = 0; $k < sizeof($xmlaliases); $k++) { - /// Importing aliases - $xmlalias = $xmlaliases[$k]; - $aliasname = $xmlalias['#']['NAME'][0]['#']; + $xmlaliases = @$xmlentry['#']['ALIASES'][0]['#']['ALIAS']; // ignore missing ALIASES + for($k = 0; $k < sizeof($xmlaliases); $k++) { + /// Importing aliases + $xmlalias = $xmlaliases[$k]; + $aliasname = $xmlalias['#']['NAME'][0]['#']; - if (!empty($aliasname)) { - $newalias = new object(); - $newalias->entryid = $newentry->id; - $newalias->alias = trim($aliasname); - $newalias->id = $DB->insert_record("glossary_alias",$newalias); - } + if (!empty($aliasname)) { + $newalias = new object(); + $newalias->entryid = $newentry->id; + $newalias->alias = trim($aliasname); + $newalias->id = $DB->insert_record("glossary_alias",$newalias); } + } - 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); - } + 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 .= "

" . - ""; } } else { $entriesrejected++; - if ( $newentry->concept and $newentry->definition ) { - // add to exception report (duplicated entry)) - $rejections .= "" . - ""; - } else { - // add to exception report (no concept or definition found)) - $rejections .= "" . - ""; - } + // add to exception report (can't insert new record) + $rejections .= "" . + ""; + } + } else { + $entriesrejected++; + if ( $newentry->concept and $newentry->definition ) { + // add to exception report (duplicated entry)) + $rejections .= "" . + ""; + } else { + // add to exception report (no concept or definition found)) + $rejections .= "" . + ""; } } - // processed entries - echo $OUTPUT->box_start('glossarydisplay generalbox'); - echo '
+ name,'glossary'); ?> +
+ name] = get_string("displayformat$format->name", "glossary"); + } + //Sort it + asort($formats); + + echo $OUTPUT->select(html_select::make($formats,'popupformatname',$displayformat->popupformatname)); + ?> + +

+
+ + +

+
+ + +

+
+ + +

+
+ + +

+
: + + +

+
+ " />
$newentry->concept" . get_string("cantinsertrec","glossary"). "
$newentry->concept" . get_string("duplicateentry","glossary"). "
---" . get_string("noconceptfound","glossary"). "
$newentry->concept" . get_string("cantinsertrec","glossary"). "
$newentry->concept" . get_string("duplicateentry","glossary"). "
---" . get_string("noconceptfound","glossary"). "
'; - echo ''; - echo ''; - echo ''; - echo ''; + } + // processed entries + echo $OUTPUT->box_start('glossarydisplay generalbox'); + echo '
'; - echo get_string("totalentries","glossary"); - echo ':'; - echo $importedentries + $entriesrejected; - echo '
'; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + if ( $catsincl ) { echo ''; echo ''; - echo ''; echo ''; - if ( $catsincl ) { - echo ''; - echo ''; - echo ''; - echo ''; - } - echo '
'; + echo get_string("totalentries","glossary"); + echo ':'; + echo $importedentries + $entriesrejected; + echo '
'; + echo get_string("importedentries","glossary"); + echo ':'; + echo $importedentries; + if ( $entriesrejected ) { + echo ' (' . get_string("rejectedentries","glossary") . ": $entriesrejected)"; + } + echo '
'; - echo get_string("importedentries","glossary"); + echo get_string("importedcategories","glossary"); echo ':'; - echo $importedentries; - if ( $entriesrejected ) { - echo ' (' . get_string("rejectedentries","glossary") . ": $entriesrejected)"; - } + echo ''; + echo $importedcats; echo '
'; - echo get_string("importedcategories","glossary"); - echo ':'; - echo $importedcats; - echo '

'; + } + echo '

'; - // rejected entries - if ($rejections) { - echo ''; - echo ''; - echo $rejections; - echo '
' . get_string("rejectionrpt","glossary") . '

'; - } - /// 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(); + // rejected entries + if ($rejections) { + echo ''; + echo ''; + echo $rejections; + echo '
' . get_string("rejectionrpt","glossary") . '

'; + } +/// Print continue button, based on results + if ($importedentries) { + echo $OUTPUT->continue_button('view.php?id='.$id); } else { - notice(get_string('errorparsingxml', 'glossary')); + echo $OUTPUT->continue_button('import.php?id='.$id); } + echo $OUTPUT->box_end(); +} else { + notice(get_string('errorparsingxml', 'glossary')); +} /// Finish the page - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/mod/glossary/index.php b/mod/glossary/index.php index e4c30a4101..77706b2d12 100644 --- a/mod/glossary/index.php +++ b/mod/glossary/index.php @@ -1,134 +1,136 @@ -libdir/rsslib.php"); - require_once("$CFG->dirroot/course/lib.php"); +require_once("../../config.php"); +require_once("lib.php"); +require_once("$CFG->libdir/rsslib.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))) { - print_error('invalidcourseid'); - } +$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/index.php', array('id'=>$id))); + +if (!$course = $DB->get_record('course', array('id'=>$id))) { + print_error('invalidcourseid'); +} - require_course_login($course); - $context = get_context_instance(CONTEXT_COURSE, $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", ""); +add_to_log($course->id, "glossary", "view all", "index.php?id=$course->id", ""); /// Get all required strings - $strglossarys = get_string("modulenameplural", "glossary"); - $strglossary = get_string("modulename", "glossary"); - $strrss = get_string("rss"); +$strglossarys = get_string("modulenameplural", "glossary"); +$strglossary = get_string("modulename", "glossary"); +$strrss = get_string("rss"); /// Print the header - $PAGE->navbar->add($strglossarys, "index.php?id=$course->id"); - $PAGE->set_title($strglossarys); - echo $OUTPUT->header(); +$PAGE->navbar->add($strglossarys, "index.php?id=$course->id"); +$PAGE->set_title($strglossarys); +echo $OUTPUT->header(); /// Get all the appropriate data - if (! $glossarys = get_all_instances_in_course("glossary", $course)) { - notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id"); - die; - } +if (! $glossarys = get_all_instances_in_course("glossary", $course)) { + notice(get_string('thereareno', 'moodle', $strglossarys), "../../course/view.php?id=$course->id"); + die; +} /// Print the list of instances (your module will probably extend this) - $timenow = time(); - $strname = get_string("name"); - $strweek = get_string("week"); - $strtopic = get_string("topic"); - $strentries = get_string("entries", "glossary"); - - $table = new html_table(); - - if ($course->format == "weeks") { - $table->head = array ($strweek, $strname, $strentries); - $table->align = array ("CENTER", "LEFT", "CENTER"); - } else if ($course->format == "topics") { - $table->head = array ($strtopic, $strname, $strentries); - $table->align = array ("CENTER", "LEFT", "CENTER"); +$timenow = time(); +$strname = get_string("name"); +$strweek = get_string("week"); +$strtopic = get_string("topic"); +$strentries = get_string("entries", "glossary"); + +$table = new html_table(); + +if ($course->format == "weeks") { + $table->head = array ($strweek, $strname, $strentries); + $table->align = array ("CENTER", "LEFT", "CENTER"); +} else if ($course->format == "topics") { + $table->head = array ($strtopic, $strname, $strentries); + $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 = "coursemodule\">".format_string($glossary->name,true).""; + } else if ($glossary->visible) { + // Show normal if the mod is visible. + $link = "coursemodule\">".format_string($glossary->name,true).""; } else { - $table->head = array ($strname, $strentries); - $table->align = array ("LEFT", "CENTER"); + // Don't show the glossary. + continue; } - - 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 = "coursemodule\">".format_string($glossary->name,true).""; - } else if ($glossary->visible) { - // Show normal if the mod is visible. - $link = "coursemodule\">".format_string($glossary->name,true).""; - } else { - // Don't show the glossary. - continue; + $printsection = ""; + if ($glossary->section !== $currentsection) { + if ($glossary->section) { + $printsection = $glossary->section; } - $printsection = ""; - if ($glossary->section !== $currentsection) { - if ($glossary->section) { - $printsection = $glossary->section; - } - if ($currentsection !== "") { - $table->data[] = 'hr'; - } - $currentsection = $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); - } - } + // TODO: count only approved if not allowed to see them - if ($course->format == "weeks" or $course->format == "topics") { - $linedata = array ($printsection, $link, $count); - } else { - $linedata = array ($link, $count); - } + $count = $DB->count_records_sql("SELECT COUNT(*) FROM {glossary_entries} WHERE (glossaryid = ? OR sourceglossaryid = ?)", array($glossary->id, $glossary->id)); - if ($show_rss) { - $linedata[] = $rsslink; + //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); } + } - $table->data[] = $linedata; + if ($course->format == "weeks" or $course->format == "topics") { + $linedata = array ($printsection, $link, $count); + } else { + $linedata = array ($link, $count); } - echo "
"; + if ($show_rss) { + $linedata[] = $rsslink; + } + + $table->data[] = $linedata; +} + +echo "
"; - echo $OUTPUT->table($table); +echo $OUTPUT->table($table); /// Finish the page - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/mod/glossary/print.php b/mod/glossary/print.php index c7e7f77403..090bd7bbda 100644 --- a/mod/glossary/print.php +++ b/mod/glossary/print.php @@ -1,185 +1,206 @@ -wwwroot.'/mod/glossary/print.php', array('id'=>$id)); +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 (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); +} + +if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); +} + +if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { + print_error('invalidid', 'glossary'); +} + +if ( !$entriesbypage = $glossary->entbypage ) { + $entriesbypage = $CFG->glossary_entbypage; +} + +echo $OUTPUT->header(); + +require_course_login($course, true, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); - global $CFG; +/// Loading the textlib singleton instance. We are going to need it. +$textlib = textlib_get_instance(); - require_once("../../config.php"); - require_once("lib.php"); +if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) { + notice(get_string('printviewnotallowed', 'glossary')); +} - $id = required_param('id', PARAM_INT); // Course Module ID - $sortorder = optional_param('sortorder', 'asc', PARAM_ALPHA); // Sorting order - $offset = optional_param('offset', 0, PARAM_INT); // number of entries to bypass - $displayformat = optional_param('displayformat',-1, PARAM_INT); +/// setting the default values for the display mode of the current glossary +/// only if the glossary is viewed by the first time +if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { + $printpivot = $dp->showgroup; + if ( $mode == '' and $hook == '' and $show == '') { + $mode = $dp->defaultmode; + $hook = $dp->defaulthook; + $sortkey = $dp->sortkey; + $sortorder = $dp->sortorder; + } +} else { + $printpivot = 1; + if ( $mode == '' and $hook == '' and $show == '') { + $mode = 'letter'; + $hook = 'ALL'; + } +} - $mode = required_param('mode', PARAM_ALPHA); // mode to show the entries - $hook = optional_param('hook','ALL', PARAM_ALPHANUM); // what to show - $sortkey = optional_param('sortkey','UPDATE', PARAM_ALPHA); // Sorting key +if ( $displayformat == -1 ) { + $displayformat = $glossary->displayformat; +} - if (! $cm = get_coursemodule_from_id('glossary', $id)) { - print_error('invalidcoursemodule'); +/// stablishing flag variables +if ( $sortorder = strtolower($sortorder) ) { + if ($sortorder != 'asc' and $sortorder != 'desc') { + $sortorder = ''; } - - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); +} +if ( $sortkey = strtoupper($sortkey) ) { + if ($sortkey != 'CREATION' and + $sortkey != 'UPDATE' and + $sortkey != 'FIRSTNAME' and + $sortkey != 'LASTNAME' + ) { + $sortkey = ''; } +} - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +switch ( $mode = strtolower($mode) ) { +case 'entry': /// Looking for a certain entry id + $tab = GLOSSARY_STANDARD_VIEW; +break; - if ( !$entriesbypage = $glossary->entbypage ) { - $entriesbypage = $CFG->glossary_entbypage; +case 'cat': /// Looking for a certain cat + $tab = GLOSSARY_CATEGORY_VIEW; + if ( $hook > 0 ) { + $category = $DB->get_record("glossary_categories", array("id"=>$hook)); } +break; - echo $OUTPUT->header(); - - require_course_login($course, true, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); +case 'approval': /// Looking for entries waiting for approval + $tab = GLOSSARY_APPROVAL_VIEW; + if ( !$hook and !$sortkey and !$sortorder) { + $hook = 'ALL'; + } +break; -/// Loading the textlib singleton instance. We are going to need it. - $textlib = textlib_get_instance(); +case 'term': /// Looking for entries that include certain term in its concept, definition or aliases + $tab = GLOSSARY_STANDARD_VIEW; +break; - if (!has_capability('mod/glossary:manageentries', $context) and !$glossary->allowprintview) { - notice(get_string('printviewnotallowed', 'glossary')); +case 'date': + $tab = GLOSSARY_DATE_VIEW; + if ( !$sortkey ) { + $sortkey = 'UPDATE'; } - -/// setting the default values for the display mode of the current glossary -/// only if the glossary is viewed by the first time - if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { - $printpivot = $dp->showgroup; - if ( $mode == '' and $hook == '' and $show == '') { - $mode = $dp->defaultmode; - $hook = $dp->defaulthook; - $sortkey = $dp->sortkey; - $sortorder = $dp->sortorder; - } - } else { - $printpivot = 1; - if ( $mode == '' and $hook == '' and $show == '') { - $mode = 'letter'; - $hook = 'ALL'; - } + if ( !$sortorder ) { + $sortorder = 'desc'; } +break; - if ( $displayformat == -1 ) { - $displayformat = $glossary->displayformat; +case 'author': /// Looking for entries, browsed by author + $tab = GLOSSARY_AUTHOR_VIEW; + if ( !$hook ) { + $hook = 'ALL'; } - -/// stablishing flag variables - if ( $sortorder = strtolower($sortorder) ) { - if ($sortorder != 'asc' and $sortorder != 'desc') { - $sortorder = ''; - } + if ( !$sortkey ) { + $sortkey = 'FIRSTNAME'; } - if ( $sortkey = strtoupper($sortkey) ) { - if ($sortkey != 'CREATION' and - $sortkey != 'UPDATE' and - $sortkey != 'FIRSTNAME' and - $sortkey != 'LASTNAME' - ) { - $sortkey = ''; - } + if ( !$sortorder ) { + $sortorder = 'asc'; } +break; - switch ( $mode = strtolower($mode) ) { - case 'entry': /// Looking for a certain entry id - $tab = GLOSSARY_STANDARD_VIEW; - 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'; +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; +} + +include_once("sql.php"); + +$entriesshown = 0; +$currentpivot = ''; +if ( $hook == 'SPECIAL' ) { + $alphabet = explode(",", get_string("alphabet")); +} + +$site = $DB->get_record("course", array("id"=>1)); +echo '

' . userdate(time()) . '

'; +echo get_string("site") . ': ' . format_string($site->fullname) . '
'; +echo get_string("course") . ': ' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')
'; +echo get_string("modulename","glossary") . ': ' . format_string($glossary->name, true) . ''; +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); } - 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; - } + // If there's group break + if ( $currentpivot != $upperpivot ) { - include_once("sql.php"); + // print the group break if apply + if ( $printpivot ) { + $currentpivot = $upperpivot; - $entriesshown = 0; - $currentpivot = ''; - if ( $hook == 'SPECIAL' ) { - $alphabet = explode(",", get_string("alphabet")); - } - - $site = $DB->get_record("course", array("id"=>1)); - echo '

' . userdate(time()) . '

'; - echo get_string("site") . ': ' . format_string($site->fullname) . '
'; - echo get_string("course") . ': ' . format_string($course->fullname) . ' ('. format_string($course->shortname) . ')
'; - echo get_string("modulename","glossary") . ': ' . format_string($glossary->name, true) . ''; - 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 "

".clean_text($pivottoshow)."

" ; + $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); } - } - glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true); + echo "

".clean_text($pivottoshow)."

" ; + } } + + glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,false,true); } +} - echo $OUTPUT->footer(); -?> +echo $OUTPUT->footer(); +?> \ No newline at end of file diff --git a/mod/glossary/rate.php b/mod/glossary/rate.php index 83d892e2b4..1c6c3f3685 100644 --- a/mod/glossary/rate.php +++ b/mod/glossary/rate.php @@ -8,6 +8,8 @@ $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))) { print_error('invalidid', 'glossary'); } diff --git a/mod/glossary/report.php b/mod/glossary/report.php index 533d81b993..4e4ffda3a2 100644 --- a/mod/glossary/report.php +++ b/mod/glossary/report.php @@ -1,87 +1,94 @@ -get_record('glossary_entries', array('id'=>$id))) { - print_error('invalidentry'); - } - - if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) { - 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'); - } - - require_login($course, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - - if (!$glossary->assessed) { - print_error('nopermissiontorate'); - } - - if (!has_capability('mod/glossary:manageentries', $context) and $USER->id != $entry->userid) { - print_error('nopermissiontoviewresult', 'glossary'); - } - - switch ($sort) { - case 'firstname': $sqlsort = "u.firstname ASC"; break; - case 'rating': $sqlsort = "r.rating ASC"; break; - default: $sqlsort = "r.time ASC"; - } - - $scalemenu = make_grades_menu($glossary->scale); - - $strratings = get_string('ratings', 'glossary'); - $strrating = get_string('rating', 'glossary'); - $strname = get_string('name'); - $strtime = get_string('time'); - - $PAGE->set_title("$strratings: $entry->concept"); - echo $OUTPUT->header(); - - if (!$ratings = glossary_get_ratings($entry->id, $sqlsort)) { - print_error('ratingno', 'glossary'); - - } else { - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - foreach ($ratings as $rating) { - if (has_capability('mod/glossary:manageentries', $context)) { - echo ''; - } else { - echo ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo "\n"; +require_once("../../config.php"); +require_once("lib.php"); + +$id = required_param('id', PARAM_INT); +$sort = optional_param('sort', '', PARAM_ALPHA); + +$url = new moodle_url($CFG->wwwroot.'/mod/glossary/report.php', array('id'=>$id)); +if ($sort !== '') { + $url->param('sort', $sort); +} +$PAGE->set_url($url); + +if (! $entry = $DB->get_record('glossary_entries', array('id'=>$id))) { + print_error('invalidentry'); +} + +if (! $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) { + 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'); +} + +require_login($course, false, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); + +if (!$glossary->assessed) { + print_error('nopermissiontorate'); +} + +if (!has_capability('mod/glossary:manageentries', $context) and $USER->id != $entry->userid) { + print_error('nopermissiontoviewresult', 'glossary'); +} + +switch ($sort) { + case 'firstname': $sqlsort = "u.firstname ASC"; break; + case 'rating': $sqlsort = "r.rating ASC"; break; + default: $sqlsort = "r.time ASC"; +} + +$scalemenu = make_grades_menu($glossary->scale); + +$strratings = get_string('ratings', 'glossary'); +$strrating = get_string('rating', 'glossary'); +$strname = get_string('name'); +$strtime = get_string('time'); + +$PAGE->set_title("$strratings: $entry->concept"); +echo $OUTPUT->header(); + +if (!$ratings = glossary_get_ratings($entry->id, $sqlsort)) { + print_error('ratingno', 'glossary'); + +} else { + echo "
 id&sort=firstname\">$strnameid&sort=rating\">$strratingid&sort=time\">$strtime
'; - $userpic = moodle_user_picture::make($rating, $glossary->course); - $userpic->link = true; - echo $OUTPUT->user_picture($userpic); - echo ''.fullname($rating).''.$scalemenu[$rating->rating].''.userdate($rating->time).'
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + foreach ($ratings as $rating) { + if (has_capability('mod/glossary:manageentries', $context)) { + echo ''; + } else { + echo ''; } - echo "
 id&sort=firstname\">$strnameid&sort=rating\">$strratingid&sort=time\">$strtime
"; - echo "
"; + echo ''; + $userpic = moodle_user_picture::make($rating, $glossary->course); + $userpic->link = true; + echo $OUTPUT->user_picture($userpic); + echo ''; + echo ''.fullname($rating).''; + echo ''.$scalemenu[$rating->rating].''; + echo ''.userdate($rating->time).''; + echo "\n"; } + echo ""; + echo "
"; +} + +echo $OUTPUT->close_window_button(); +echo $OUTPUT->footer(); - echo $OUTPUT->close_window_button(); - echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/mod/glossary/showentry.php b/mod/glossary/showentry.php index 9861568654..3fc116dfb1 100644 --- a/mod/glossary/showentry.php +++ b/mod/glossary/showentry.php @@ -1,70 +1,86 @@ -forcelogin) { - require_login(); - } +$concept = optional_param('concept', '', PARAM_CLEAN); +$courseid = optional_param('courseid', 0, PARAM_INT); +$eid = optional_param('eid', 0, PARAM_INT); // glossary entry id +$displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR); + +$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 ($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 ($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 = "

» 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)."

"; // Could not get this to work satisfactorily in all cases - Martin - $entries[$key]->footer = "

» wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">".format_string($entry->glossaryname,true)."

"; - add_to_log($entry->courseid, "glossary", "view entry", "showentry.php?eid=$entry->id", $entry->id, $entry->cmid); - } +if ($entries) { + foreach ($entries as $key => $entry) { + //$entries[$key]->footer = "

» 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)."

"; // Could not get this to work satisfactorily in all cases - Martin + $entries[$key]->footer = "

» wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">".format_string($entry->glossaryname,true)."

"; + 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 (!empty($courseid)) { + $course = $DB->get_record("course", array("id"=>$courseid)); + if ($course->id != SITEID) { + require_login($courseid); + } - $strglossaries = get_string("modulenameplural", "glossary"); - $strsearch = get_string("search"); + $strglossaries = get_string("modulenameplural", "glossary"); + $strsearch = get_string("search"); - $CFG->framename = "newwindow"; + $CFG->framename = "newwindow"; - $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 - } + $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); - } +if ($entries) { + glossary_print_dynaentry($courseid, $entries, $displayformat); +} - echo $OUTPUT->close_window_button(); +echo $OUTPUT->close_window_button(); /// Show one reduced footer - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); -?> +?> \ No newline at end of file diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 43524b40dc..6c33f455f7 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -1,527 +1,529 @@ -libdir/rsslib.php"); - - $id = optional_param('id', 0, PARAM_INT); // Course Module ID - $g = optional_param('g', 0, PARAM_INT); // Glossary ID - - $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 - - $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 - $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... - $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) - $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 - - if (!empty($id)) { - if (! $cm = get_coursemodule_from_id('glossary', $id)) { - print_error('invalidcoursemodule'); - } - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidid', 'glossary'); - } +require_once("../../config.php"); +require_once("lib.php"); +require_once("$CFG->libdir/rsslib.php"); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID +$g = optional_param('g', 0, PARAM_INT); // Glossary ID + +$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 + +$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 +$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... +$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) +$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 + +if (!empty($id)) { + if (! $cm = get_coursemodule_from_id('glossary', $id)) { + print_error('invalidcoursemodule'); + } + if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { + print_error('coursemisconf'); + } + 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 { +} 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'); +} - require_course_login($course->id, true, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); +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. - $textlib = textlib_get_instance(); +$textlib = textlib_get_instance(); /// redirecting if adding a new entry - if ($tab == GLOSSARY_ADDENTRY_VIEW ) { - redirect("edit.php?cmid=$cm->id&mode=$mode"); - } +if ($tab == GLOSSARY_ADDENTRY_VIEW ) { + redirect("edit.php?cmid=$cm->id&mode=$mode"); +} /// setting the defaut number of entries per page if not set - if ( !$entriesbypage = $glossary->entbypage ) { - $entriesbypage = $CFG->glossary_entbypage; - } +if ( !$entriesbypage = $glossary->entbypage ) { + $entriesbypage = $CFG->glossary_entbypage; +} /// If we have received a page, recalculate offset - if ($page != 0 && $offset == 0) { - $offset = $page * $entriesbypage; - } +if ($page != 0 && $offset == 0) { + $offset = $page * $entriesbypage; +} /// setting the default values for the display mode of the current glossary /// only if the glossary is viewed by the first time - if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { - /// Based on format->defaultmode, we build the defaulttab to be showed sometimes - switch ($dp->defaultmode) { - case 'cat': - $defaulttab = GLOSSARY_CATEGORY_VIEW; - break; - case 'date': - $defaulttab = GLOSSARY_DATE_VIEW; - break; - case 'author': - $defaulttab = GLOSSARY_AUTHOR_VIEW; - break; - default: - $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'; - } +if ( $dp = $DB->get_record('glossary_formats', array('name'=>$glossary->displayformat)) ) { +/// Based on format->defaultmode, we build the defaulttab to be showed sometimes + switch ($dp->defaultmode) { + case 'cat': + $defaulttab = GLOSSARY_CATEGORY_VIEW; + break; + case 'date': + $defaulttab = GLOSSARY_DATE_VIEW; + break; + case 'author': + $defaulttab = GLOSSARY_AUTHOR_VIEW; + break; + default: + $defaulttab = GLOSSARY_STANDARD_VIEW; } - - if ( $displayformat == -1 ) { - $displayformat = $glossary->displayformat; +/// 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; } - - if ( $show ) { - $mode = 'term'; - $hook = $show; - $show = ''; +} else { + $defaulttab = GLOSSARY_STANDARD_VIEW; + $printpivot = 1; + if ( $mode == '' and $hook == '' and $show == '') { + $mode = 'letter'; + $hook = 'ALL'; } +} + +if ( $displayformat == -1 ) { + $displayformat = $glossary->displayformat; +} + +if ( $show ) { + $mode = 'term'; + $hook = $show; + $show = ''; +} /// Processing standard security processes - if ($course->id != SITEID) { - require_login($course->id); - } - if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { - echo $OUTPUT->header(); - notice(get_string("activityiscurrentlyhidden")); - } - add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id); +if ($course->id != SITEID) { + require_login($course->id); +} +if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $context)) { + echo $OUTPUT->header(); + notice(get_string("activityiscurrentlyhidden")); +} +add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id&tab=$tab", $glossary->id, $cm->id); /// stablishing flag variables - if ( $sortorder = strtolower($sortorder) ) { - if ($sortorder != 'asc' and $sortorder != 'desc') { - $sortorder = ''; - } +if ( $sortorder = strtolower($sortorder) ) { + if ($sortorder != 'asc' and $sortorder != 'desc') { + $sortorder = ''; } - if ( $sortkey = strtoupper($sortkey) ) { - if ($sortkey != 'CREATION' and - $sortkey != 'UPDATE' and - $sortkey != 'FIRSTNAME' and - $sortkey != 'LASTNAME' - ) { - $sortkey = ''; - } +} +if ( $sortkey = strtoupper($sortkey) ) { + if ($sortkey != 'CREATION' and + $sortkey != 'UPDATE' and + $sortkey != 'FIRSTNAME' and + $sortkey != 'LASTNAME' + ) { + $sortkey = ''; } +} - switch ( $mode = strtolower($mode) ) { - case 'search': /// looking for terms containing certain word(s) - $tab = GLOSSARY_STANDARD_VIEW; +switch ( $mode = strtolower($mode) ) { +case 'search': /// looking for terms containing certain word(s) + $tab = GLOSSARY_STANDARD_VIEW; - //Clean a bit the search string - $hook = trim(strip_tags($hook)); + //Clean a bit the search string + $hook = trim(strip_tags($hook)); - break; +break; - case 'entry': /// Looking for a certain entry id - $tab = GLOSSARY_STANDARD_VIEW; - if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) { - $displayformat = $dp->popupformatname; - } - break; +case 'entry': /// Looking for a certain entry id + $tab = GLOSSARY_STANDARD_VIEW; + if ( $dp = $DB->get_record("glossary_formats", array("name"=>$glossary->displayformat)) ) { + $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 '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 '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 '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 '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 '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; +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; +switch ( $tab ) { +case GLOSSARY_IMPORT_VIEW: +case GLOSSARY_EXPORT_VIEW: +case GLOSSARY_APPROVAL_VIEW: + $showcommonelements = 0; +break; - default: - $showcommonelements = 1; - break; - } +default: + $showcommonelements = 1; +break; +} /// Printing the heading - $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"); - $strwaitingapproval = get_string('waitingapproval', 'glossary'); +$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"); +$strwaitingapproval = get_string('waitingapproval', 'glossary'); /// If we are in approval mode, prit special header - $PAGE->set_title(format_string($glossary->name)); - $PAGE->set_button(update_module_button($cm->id, $course->id, $strglossary)); - $url = new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id)); - if (isset($mode)) { - $url->param('mode', $mode); - } - $PAGE->set_url($url); - if ($tab == GLOSSARY_APPROVAL_VIEW) { - require_capability('mod/glossary:approve', $context); - $PAGE->navbar->add($strwaitingapproval); - echo $OUTPUT->header(); - echo $OUTPUT->heading($strwaitingapproval); - } else { /// Print standard header - echo $OUTPUT->header(); - } +$PAGE->set_title(format_string($glossary->name)); +$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary')); +$url = new moodle_url($CFG->wwwroot.'/mod/glossary/view.php', array('id'=>$cm->id)); +if (isset($mode)) { + $url->param('mode', $mode); +} +$PAGE->set_url($url); +if ($tab == GLOSSARY_APPROVAL_VIEW) { + require_capability('mod/glossary:approve', $context); + $PAGE->navbar->add($strwaitingapproval); + echo $OUTPUT->header(); + echo $OUTPUT->heading($strwaitingapproval); +} else { /// Print standard header + echo $OUTPUT->header(); +} /// All this depends if whe have $showcommonelements - if ($showcommonelements) { - /// To calculate available options - $availableoptions = ''; - - /// Decide about to print the import link - if (has_capability('mod/glossary:import', $context)) { - $availableoptions = '' . - '' . - get_string('importentries', 'glossary') . '' . - ''; +if ($showcommonelements) { +/// To calculate available options + $availableoptions = ''; + +/// Decide about to print the import link + if (has_capability('mod/glossary:import', $context)) { + $availableoptions = '' . + '' . + get_string('importentries', 'glossary') . '' . + ''; + } +/// Decide about to print the export link + if (has_capability('mod/glossary:export', $context)) { + if ($availableoptions) { + $availableoptions .= ' / '; } - /// Decide about to print the export link - if (has_capability('mod/glossary:export', $context)) { + $availableoptions .='' . + '' . + get_string('exportentries', 'glossary') . '' . + ''; + } + +/// 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) { - $availableoptions .= ' / '; + $availableoptions .= '
'; } $availableoptions .='' . - '' . - get_string('exportentries', 'glossary') . '' . + '' . + get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')' . ''; } + } - /// 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) { - $availableoptions .= '
'; - } - $availableoptions .='' . - '' . - get_string('waitingapproval', 'glossary') . ' ('.$hiddenentries.')' . - ''; - } - } - - /// Start to print glossary controls +/// Start to print glossary controls // print_box_start('glossarycontrol clearfix'); - echo '
'; - echo $availableoptions; - - /// 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) && - $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) { - - $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true)); - if (empty($USER->id)) { - $userid = 0; - } else { - $userid = $USER->id; - } + echo '
'; + echo $availableoptions; + +/// 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) && + $CFG->enablerssfeeds && $CFG->glossary_enablerssfeeds && $glossary->rsstype && $glossary->rssarticles) { + + $tooltiptext = get_string("rsssubscriberss","glossary",format_string($glossary->name,true)); + if (empty($USER->id)) { + $userid = 0; + } else { + $userid = $USER->id; + } // print_box_start('rsslink'); - echo ''; - rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext); - echo ''; + echo ''; + rss_print_link($course->id, $userid, "glossary", $glossary->id, $tooltiptext); + echo ''; // print_box_end(); - } + } - /// The print icon - if ( $showcommonelements and $mode != 'search') { - if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) { +/// The print icon + if ( $showcommonelements and $mode != 'search') { + if (has_capability('mod/glossary:manageentries', $context) or $glossary->allowprintview) { // print_box_start('printicon'); - echo ''; - echo " id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">\""."; - echo ''; + echo ''; + echo " id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&offset=$offset\">\""."; + echo ''; // print_box_end(); - } } - /// End glossary controls + } +/// End glossary controls // print_box_end(); /// glossarycontrol - echo '
'; + echo '
'; // print_box(' ', 'clearer'); - } +} /// Info box - if ($glossary->intro && $showcommonelements) { - echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro'); - } +if ($glossary->intro && $showcommonelements) { + echo $OUTPUT->box(format_module_intro('glossary', $glossary, $cm->id), 'generalbox', 'intro'); +} /// Search box - if ($showcommonelements ) { - echo '
'; +if ($showcommonelements ) { + echo ''; - echo ''; - echo '
'; + echo ''; + echo '
'; - echo ' '; - if ($mode == 'search') { - echo ' '; - } else { - echo ' '; - } - if ($fullsearch || $mode != 'search') { - $fullsearchchecked = 'checked="checked"'; - } else { - $fullsearchchecked = ''; - } - echo ''; - echo ''; - echo ''; - echo ''; - echo '
'; + echo ' '; + if ($mode == 'search') { + echo ' '; + } else { + echo ' '; + } + if ($fullsearch || $mode != 'search') { + $fullsearchchecked = 'checked="checked"'; + } else { + $fullsearchchecked = ''; + } + echo ''; + echo ''; + echo ''; + echo ''; + echo '
'; - echo '
'; + echo ''; - echo '
'; - } + echo '
'; +} /// Show the add entry button if allowed - if (has_capability('mod/glossary:write', $context) && $showcommonelements ) { - echo '
'; - echo "
wwwroot/mod/glossary/edit.php\">"; - echo '
'; - echo "id\" />"; - echo ''; - echo '
'; - echo '
'; - echo "
\n"; - } +if (has_capability('mod/glossary:write', $context) && $showcommonelements ) { + echo '
'; + echo "
wwwroot/mod/glossary/edit.php\">"; + echo '
'; + echo "id\" />"; + echo ''; + echo '
'; + echo '
'; + echo "
\n"; +} - echo '
'; +echo '
'; - require("tabs.php"); +require("tabs.php"); - require("sql.php"); +require("sql.php"); /// printing the entries - $entriesshown = 0; - $currentpivot = ''; - $ratingsmenuused = NULL; - $paging = NULL; - - if ($allentries) { +$entriesshown = 0; +$currentpivot = ''; +$ratingsmenuused = NULL; +$paging = NULL; - //Decide if we must show the ALL link in the pagebar - $specialtext = ''; - if ($glossary->showall) { - $specialtext = get_string("allentries","glossary"); - } +if ($allentries) { - //Build paging bar - $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,'  ', $specialtext, -1); + //Decide if we must show the ALL link in the pagebar + $specialtext = ''; + if ($glossary->showall) { + $specialtext = get_string("allentries","glossary"); + } - echo '
'; - echo $paging; - echo '
'; + //Build paging bar + $paging = glossary_get_paging_bar($count, $page, $entriesbypage, "view.php?id=$id&mode=$mode&hook=".urlencode($hook)."&sortkey=$sortkey&sortorder=$sortorder&fullsearch=$fullsearch&",9999,10,'  ', $specialtext, -1); - $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 '
'; + echo $paging; + echo '
'; - echo "
"; - echo "
"; - echo "id\" />"; + $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; - 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); - } + echo ""; + echo "
"; + echo "id\" />"; + } - // if there's a group break - if ( $currentpivot != $upperpivot ) { + foreach ($allentries as $entry) { - // print the group break if apply - if ( $printpivot ) { - $currentpivot = $upperpivot; + // 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); + } - echo '
'; - echo ''; + // if there's a group break + if ( $currentpivot != $upperpivot ) { - echo ''; - $pivottoshow = $currentpivot; - if ( isset($entry->userispivot) ) { - // printing the user icon if defined (only when browsing authors) - echo ''; + $pivottoshow = $currentpivot; + if ( isset($entry->userispivot) ) { + // printing the user icon if defined (only when browsing authors) + echo '
'; + // print the group break if apply + if ( $printpivot ) { + $currentpivot = $upperpivot; - $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 ''; - } + echo '
'; + echo ''; - echo $OUTPUT->heading($pivottoshow); - echo "
\n"; + echo '
'; + $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 ''; } - } - $concept = $entry->concept; - $definition = $entry->definition; - - /// 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; + echo $OUTPUT->heading($pivottoshow); + echo "
\n"; + } + } - /// and finally print the entry. + $concept = $entry->concept; + $definition = $entry->definition; - if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) { - $ratingsmenuused = true; + /// 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]); + } } - - $entriesshown++; + $strippedsearch = implode(' ', $searchterms); // Rebuild the string + $entry->highlight = $strippedsearch; } - } - if ( !$entriesshown ) { - echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide"); - } - - if ($ratingsmenuused) { + /// and finally print the entry. - echo "
"; - 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 ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) { + $ratingsmenuused = true; } - echo "
"; - } - if (!empty($formsent)) { - // close the form properly if used - echo "
"; - echo ""; + $entriesshown++; } +} +if ( !$entriesshown ) { + echo $OUTPUT->box(get_string("noentries","glossary"), "generalbox boxaligncenter boxwidthwide"); +} + + +if ($ratingsmenuused) { - if ( $paging ) { - echo '
'; - echo '
'; - echo $paging; - echo '
'; + echo "
"; + 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)); + } } - echo '
'; - glossary_print_tabbed_table_end(); + echo "
"; +} + +if (!empty($formsent)) { + // close the form properly if used + echo "
"; + echo ""; +} + +if ( $paging ) { + echo '
'; + echo '
'; + echo $paging; + echo '
'; +} +echo '
'; +glossary_print_tabbed_table_end(); /// Finish the page - echo $OUTPUT->footer(); +echo $OUTPUT->footer(); /// Mark as viewed - $completion=new completion_info($course); - $completion->set_module_viewed($cm); -?> +$completion=new completion_info($course); +$completion->set_module_viewed($cm); + +?> \ No newline at end of file