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
10 $prevmode = required_param('prevmode');
11 $hook = optional_param('hook', '', PARAM_CLEAN
);
13 $strglossary = get_string("modulename", "glossary");
14 $strglossaries = get_string("modulenameplural", "glossary");
15 $stredit = get_string("edit");
16 $entrydeleted = get_string("entrydeleted","glossary");
19 if (! $cm = get_coursemodule_from_id('glossary', $id)) {
20 error("Course Module ID was incorrect");
23 if (! $course = get_record("course", "id", $cm->course
)) {
24 error("Course is misconfigured");
27 if (! $entry = get_record("glossary_entries","id", $entry)) {
28 error("Entry ID was incorrect");
31 require_login($course->id
, false, $cm);
32 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
33 $manageentries = has_capability('mod/glossary:manageentries', $context);
35 if (! $glossary = get_record("glossary", "id", $cm->instance
)) {
36 error("Glossary is incorrect");
40 $strareyousuredelete = get_string("areyousuredelete","glossary");
42 $navigation = build_navigation('', $cm);
43 print_header_simple(format_string($glossary->name
), "", $navigation,
44 "", "", true, update_module_button($cm->id
, $course->id
, $strglossary),
45 navmenu($course, $cm));
47 if (($entry->userid
!= $USER->id
) and !$manageentries) { // guest id is never matched, no need for special check here
48 error("You can't delete other people's entries!");
50 $ineditperiod = ((time() - $entry->timecreated
< $CFG->maxeditingtime
) ||
$glossary->editalways
);
51 if (!$ineditperiod and !$manageentries) {
52 error("You can't delete this. Time expired!");
55 /// If data submitted, then process and store.
57 if ($confirm) { // the operation was confirmed.
58 // if it is an imported entry, just delete the relation
60 if ( $entry->sourceglossaryid
) {
61 $dbentry = new stdClass
;
62 $dbentry->id
= $entry->id
;
63 $dbentry->glossaryid
= $entry->sourceglossaryid
;
64 $dbentry->sourceglossaryid
= 0;
65 if (! update_record('glossary_entries', $dbentry)) {
66 error("Could not update your glossary");
70 if ( $entry->attachment
) {
71 glossary_delete_old_attachments($entry);
73 delete_records("glossary_comments", "entryid",$entry->id
);
74 delete_records("glossary_alias", "entryid", $entry->id
);
75 delete_records("glossary_ratings", "entryid", $entry->id
);
76 delete_records("glossary_entries","id", $entry->id
);
79 add_to_log($course->id
, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id
,$cm->id
);
80 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entrydeleted);
82 } else { // the operation has not been confirmed yet so ask the user to do so
84 notice_yesno("<b>".format_string($entry->concept
)."</b><p>$strareyousuredelete</p>",
85 "deleteentry.php?id=$cm->id&mode=delete&confirm=1&entry=".s($entry->id
)."&prevmode=$prevmode&hook=$hook",
86 "view.php?id=$cm->id&mode=$prevmode&hook=$hook");
90 print_footer($course);