diff --git a/mod/glossary/approve.php b/mod/glossary/approve.php index 6fbf476b965..7bfa9ba85f1 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 ecb7b131770..8ab68341234 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 84bb3f1db92..67497ccb4d7 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'); +} - $context = get_context_instance(CONTEXT_MODULE, $cm->id); +if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) { + print_error('invalidentry'); +} - require_login($course->id, false, $cm); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); - add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id); +require_login($course->id, false, $cm); - $strglossaries = get_string("modulenameplural", "glossary"); - $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"); +add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id); - $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(); +$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($OUTPUT->update_module_button($cm->id, 'glossary')); +echo $OUTPUT->header(); /// original glossary entry - echo "
$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); + // move attachments too + $fs = get_file_storage(); - echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno)); + if ($oldfiles = $fs->get_area_files($context->id, 'glossary_attachment', $entry->id)) { + foreach ($oldfiles as $oldfile) { + $file_record = new object(); + $file_record->contextid = $newcontext->id; + $fs->create_file_from_storedfile($file_record, $oldfile); + } + $fs->delete_area_files($context->id, 'glossary_attachment', $entry->id); + $entry->attachment = '1'; + } else { + $entry->attachment = '0'; + } + $DB->update_record('glossary_entries', $entry); - echo $OUTPUT->footer(); + } else { + $fs = get_file_storage(); + $fs->delete_area_files($context->id, 'glossary_attachment', $entry->id); + $DB->delete_records("glossary_comments", array("entryid"=>$entry->id)); + $DB->delete_records("glossary_alias", array("entryid"=>$entry->id)); + $DB->delete_records("glossary_ratings", array("entryid"=>$entry->id)); + $DB->delete_records("glossary_entries", array("id"=>$entry->id)); } -?> + + add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&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($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->footer(); +} + +?> \ No newline at end of file diff --git a/mod/glossary/editcategories.php b/mod/glossary/editcategories.php index 166200d07ea..9640be99fe0 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); +} - if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); - } +$PAGE->set_url($url); - if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) { - print_error('invalidcoursemodule'); - } +if (! $cm = get_coursemodule_from_id('glossary', $id)) { + 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'); +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'); } +} - require_login($course->id, false, $cm); +require_login($course->id, false, $cm); - $context = get_context_instance(CONTEXT_MODULE, $cm->id); - require_capability('mod/glossary:managecategories', $context); +$context = get_context_instance(CONTEXT_MODULE, $cm->id); +require_capability('mod/glossary:managecategories', $context); - $strglossaries = get_string("modulenameplural", "glossary"); - $strglossary = get_string("modulename", "glossary"); +$strglossaries = get_string("modulenameplural", "glossary"); +$strglossary = get_string("modulename", "glossary"); - $PAGE->navbar->add($strglossaries, new moodle_url($CFG->wwwroot.'/mod/glossary/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(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(); +$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 ( $hook >0 ) { +if ( $hook >0 ) { - if ( $action == "edit" ) { - if ( $confirm ) { - $action = ""; - $cat = new object(); - $cat->id = $hook; - $cat->name = $name; - $cat->usedynalink = $usedynalink; + if ( $action == "edit" ) { + if ( $confirm ) { + $action = ""; + $cat = new object(); + $cat->id = $hook; + $cat->name = $name; + $cat->usedynalink = $usedynalink; - $DB->update_record("glossary_categories", $cat); - add_to_log($course->id, "glossary", "edit 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); - } else { - echo "" . get_string("edit"). " " . get_string("category","glossary") . "";
+ } else {
+ echo " " . get_string("edit"). " " . get_string("category","glossary") . "";
- $name = $category->name;
- $usedynalink = $category->usedynalink;
- require "editcategories.html";
- echo $OUTPUT->footer();
- die;
+ $name = $category->name;
+ $usedynalink = $category->usedynalink;
+ require "editcategories.html";
+ echo $OUTPUT->footer();
+ die;
+ }
+
+ } elseif ( $action == "delete" ) {
+ if ( $confirm ) {
+ $DB->delete_records("glossary_entries_categories", array("categoryid"=>$hook));
+ $DB->delete_records("glossary_categories", array("id"=>$hook));
+
+ echo $OUTPUT->box_start('generalbox boxaligncenter errorboxcontent boxwidthnarrow');
+ echo " " . get_string("delete"). " " . get_string("category","glossary"). " " . get_string("delete"). " " . get_string("category","glossary"). " ";
- print_string("areyousuredelete","glossary");
- echo " ";
+ print_string("areyousuredelete","glossary");
+ echo " " . get_string("add"). " " . get_string("category","glossary");
+} 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("add"). " " . get_string("category","glossary"). " " . get_string("add"). " " . get_string("category","glossary"). "
";
+
+ $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 "
";
-
- $num_entries = $DB->count_records("glossary_entries_categories", array("categoryid"=>$category->id));
- if ( $num_entries ) {
- print_string("deletingnoneemptycategory","glossary");
- }
- echo "
@@ -123,49 +145,49 @@
";
- echo "
$id);
- echo $OUTPUT->button(html_form::make_button("editcategories.php", $options, get_string("no")));
- echo "