3 require_once("../../config.php");
4 require_once("lib.php");
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
);
12 $url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode));
14 $url->param('confirm', $confirm);
17 $url->param('entry', $entry);
20 $url->param('hook', $hook);
24 $strglossary = get_string("modulename", "glossary");
25 $strglossaries = get_string("modulenameplural", "glossary");
26 $stredit = get_string("edit");
27 $entrydeleted = get_string("entrydeleted","glossary");
30 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
31 throw new \
moodle_exception("invalidcoursemodule");
34 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
35 throw new \
moodle_exception('coursemisconf');
38 if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
39 throw new \
moodle_exception('invalidentry');
42 // Permission checks are based on the course module instance so make sure it is correct.
43 if ($cm->instance
!= $entry->glossaryid
) {
44 throw new \
moodle_exception('invalidentry');
47 require_login($course, false, $cm);
48 $context = context_module
::instance($cm->id
);
50 if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance
))) {
51 throw new \
moodle_exception('invalidid', 'glossary');
54 // Throws an exception if the user cannot delete the entry.
55 mod_glossary_can_delete_entry($entry, $glossary, $context, false);
57 /// If data submitted, then process and store.
59 if ($confirm and confirm_sesskey()) { // the operation was confirmed.
61 mod_glossary_delete_entry($entry, $glossary, $cm, $context, $course, $hook, $prevmode);
62 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook");
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 $PAGE->activityheader
->disable();
70 echo $OUTPUT->header();
71 $areyousure = "<b>".format_string($entry->concept
)."</b><p>$strareyousuredelete</p>";
72 $linkyes = 'deleteentry.php';
74 $optionsyes = array('id'=>$cm->id
, 'entry'=>$entry->id
, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
75 $optionsno = array('id'=>$cm->id
, 'mode'=>$prevmode, 'hook'=>$hook);
77 echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
79 echo $OUTPUT->footer();