2009-09-24 07:29:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once("../../config.php");
|
|
|
|
require_once("lib.php");
|
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT); // course module ID
|
|
|
|
$confirm = optional_param('confirm', 0, PARAM_INT); // commit the operation?
|
|
|
|
$entry = optional_param('entry', 0, PARAM_INT); // entry id
|
|
|
|
$prevmode = required_param('prevmode', PARAM_ALPHA);
|
|
|
|
$hook = optional_param('hook', '', PARAM_CLEAN);
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/mod/glossary/deleteentry.php', array('id'=>$id,'prevmode'=>$prevmode));
|
2009-09-24 07:29:14 +00:00
|
|
|
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)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception("invalidcoursemodule");
|
2009-09-24 07:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('coursemisconf');
|
2009-09-24 07:29:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (! $entry = $DB->get_record("glossary_entries", array("id"=>$entry))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidentry');
|
2009-09-24 07:29:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-17 11:26:29 +08:00
|
|
|
// Permission checks are based on the course module instance so make sure it is correct.
|
|
|
|
if ($cm->instance != $entry->glossaryid) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidentry');
|
2019-05-17 11:26:29 +08:00
|
|
|
}
|
|
|
|
|
2012-04-22 17:41:47 +02:00
|
|
|
require_login($course, false, $cm);
|
2012-07-27 13:25:24 +08:00
|
|
|
$context = context_module::instance($cm->id);
|
2009-09-24 07:29:14 +00:00
|
|
|
|
|
|
|
if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('invalidid', 'glossary');
|
2009-09-24 07:29:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 14:01:59 +02:00
|
|
|
// Throws an exception if the user cannot delete the entry.
|
|
|
|
mod_glossary_can_delete_entry($entry, $glossary, $context, false);
|
2003-09-16 03:07:21 +00:00
|
|
|
|
2009-09-24 07:29:14 +00:00
|
|
|
/// If data submitted, then process and store.
|
2004-04-03 13:04:00 +00:00
|
|
|
|
2009-09-24 07:29:14 +00:00
|
|
|
if ($confirm and confirm_sesskey()) { // the operation was confirmed.
|
2014-03-28 15:02:46 +08:00
|
|
|
|
2020-09-25 14:01:59 +02:00
|
|
|
mod_glossary_delete_entry($entry, $glossary, $cm, $context, $course, $hook, $prevmode);
|
2009-09-24 07:29:14 +00:00
|
|
|
redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook");
|
2004-04-03 13:04:00 +00:00
|
|
|
|
2009-09-24 07:29:14 +00:00
|
|
|
} else { // the operation has not been confirmed yet so ask the user to do so
|
2020-09-25 14:01:59 +02:00
|
|
|
$strareyousuredelete = get_string("areyousuredelete", "glossary");
|
2010-05-28 06:38:17 +00:00
|
|
|
$PAGE->navbar->add(get_string('delete'));
|
2014-02-05 14:47:23 +08:00
|
|
|
$PAGE->set_title($glossary->name);
|
2010-05-28 06:38:17 +00:00
|
|
|
$PAGE->set_heading($course->fullname);
|
2021-09-21 16:17:17 +08:00
|
|
|
$PAGE->activityheader->disable();
|
2009-09-24 07:29:14 +00:00
|
|
|
echo $OUTPUT->header();
|
|
|
|
$areyousure = "<b>".format_string($entry->concept)."</b><p>$strareyousuredelete</p>";
|
|
|
|
$linkyes = 'deleteentry.php';
|
|
|
|
$linkno = 'view.php';
|
|
|
|
$optionsyes = array('id'=>$cm->id, 'entry'=>$entry->id, 'confirm'=>1, 'sesskey'=>sesskey(), 'prevmode'=>$prevmode, 'hook'=>$hook);
|
|
|
|
$optionsno = array('id'=>$cm->id, 'mode'=>$prevmode, 'hook'=>$hook);
|
2008-08-17 21:27:43 +00:00
|
|
|
|
2009-09-24 07:29:14 +00:00
|
|
|
echo $OUTPUT->confirm($areyousure, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
|
2008-08-17 21:27:43 +00:00
|
|
|
|
2009-09-24 07:29:14 +00:00
|
|
|
echo $OUTPUT->footer();
|
|
|
|
}
|