1<?php
2
3require_once("../../config.php");
4require_once("lib.php");
5
6$id       = required_param('id', PARAM_INT);          // course module ID
7$confirm  = optional_param('confirm', 0, PARAM_INT);  // commit the operation?
8$entry    = optional_param('entry', 0, PARAM_INT);    // entry id
9$prevmode = required_param('prevmode', PARAM_ALPHA);
10$hook     = optional_param('hook', '', PARAM_CLEAN);
11
12$url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode));
13if ($confirm !== 0) {
14    $url->param('confirm', $confirm);
15}
16if ($entry !== 0) {
17    $url->param('entry', $entry);
18}
19if ($hook !== '') {
20    $url->param('hook', $hook);
21}
22$PAGE->set_url($url);
23
24$strglossary   = get_string("modulename", "glossary");
25$strglossaries = get_string("modulenameplural", "glossary");
26$stredit       = get_string("edit");
27$entrydeleted  = get_string("entrydeleted","glossary");
28
29
30if (! $cm = get_coursemodule_from_id('glossary', $id)) {
31    print_error("invalidcoursemodule");
32}
33
34if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
35    print_error('coursemisconf');
36}
37
38if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
39    print_error('invalidentry');
40}
41
42// Permission checks are based on the course module instance so make sure it is correct.
43if ($cm->instance != $entry->glossaryid) {
44    print_error('invalidentry');
45}
46
47require_login($course, false, $cm);
48$context = context_module::instance($cm->id);
49
50if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
51    print_error('invalidid', 'glossary');
52}
53
54// Throws an exception if the user cannot delete the entry.
55mod_glossary_can_delete_entry($entry, $glossary, $context, false);
56
57/// If data submitted, then process and store.
58
59if ($confirm and confirm_sesskey()) { // the operation was confirmed.
60
61    mod_glossary_delete_entry($entry, $glossary, $cm, $context, $course, $hook, $prevmode);
62    redirect("view.php?id=$cm->id&amp;mode=$prevmode&amp;hook=$hook");
63
64} else {        // the operation has not been confirmed yet so ask the user to do so
65    $strareyousuredelete = get_string("areyousuredelete", "glossary");
66    $PAGE->navbar->add(get_string('delete'));
67    $PAGE->set_title($glossary->name);
68    $PAGE->set_heading($course->fullname);
69    echo $OUTPUT->header();
70    $areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>";
71    $linkyes    = 'deleteentry.php';
72    $linkno     = 'view.php';
73    $optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
74    $optionsno  = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
75
76    echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
77
78    echo $OUTPUT->footer();
79}
80