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");
43 $navlinks[] = array('name' => $strglossaries, 'link' => "index.php?id=$course->id", 'type' => 'activity');
44 $navlinks[] = array('name' => format_string($glossary->name
), 'link' => "view.php?id=$cm->id", 'type' => 'activityinstance');
46 $navigation = build_navigation($navlinks);
48 print_header_simple(format_string($glossary->name
), "", $navigation,
49 "", "", true, update_module_button($cm->id
, $course->id
, $strglossary),
50 navmenu($course, $cm));
53 if (($entry->userid
!= $USER->id
) and !$manageentries) { // guest id is never matched, no need for special check here
54 error("You can't delete other people's entries!");
56 $ineditperiod = ((time() - $entry->timecreated
< $CFG->maxeditingtime
) ||
$glossary->editalways
);
57 if (!$ineditperiod and !$manageentries) {
58 error("You can't delete this. Time expired!");
61 /// If data submitted, then process and store.
63 if ($confirm) { // the operation was confirmed.
64 // if it is an imported entry, just delete the relation
66 if ( $entry->sourceglossaryid
) {
67 $dbentry = new stdClass
;
68 $dbentry->id
= $entry->id
;
69 $dbentry->glossaryid
= $entry->sourceglossaryid
;
70 $dbentry->sourceglossaryid
= 0;
71 if (! update_record('glossary_entries', $dbentry)) {
72 error("Could not update your glossary");
76 if ( $entry->attachment
) {
77 glossary_delete_old_attachments($entry);
79 delete_records("glossary_comments", "entryid",$entry->id
);
80 delete_records("glossary_alias", "entryid", $entry->id
);
81 delete_records("glossary_ratings", "entryid", $entry->id
);
82 delete_records("glossary_entries","id", $entry->id
);
85 add_to_log($course->id
, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id
,$cm->id
);
86 redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entrydeleted);
88 } else { // the operation has not been confirmed yet so ask the user to do so
90 notice_yesno("<b>".format_string($entry->concept
)."</b><p>$strareyousuredelete</p>",
91 "deleteentry.php?id=$cm->id&mode=delete&confirm=1&entry=".s($entry->id
)."&prevmode=$prevmode&hook=$hook",
92 "view.php?id=$cm->id&mode=$prevmode&hook=$hook");
96 print_footer($course);