From bdb2f23f70c13d8029a13b2381f633c0be702cda Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 3 Apr 2004 13:04:00 +0000 Subject: [PATCH] Started out with a small user interface fix (to use standard functions) and ended up cleaning up the code quite a bit --- mod/glossary/deleteentry.html | 13 ----- mod/glossary/deleteentry.php | 94 +++++++++++++---------------------- 2 files changed, 35 insertions(+), 72 deletions(-) delete mode 100644 mod/glossary/deleteentry.html diff --git a/mod/glossary/deleteentry.html b/mod/glossary/deleteentry.html deleted file mode 100644 index 23a524f525..0000000000 --- a/mod/glossary/deleteentry.html +++ /dev/null @@ -1,13 +0,0 @@ -
- - - - - - - - - "> - " onclick="javascript:history.go(-1);"> - -
\ No newline at end of file diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php index ca6f4001d8..2ffa4f4a1b 100644 --- a/mod/glossary/deleteentry.php +++ b/mod/glossary/deleteentry.php @@ -4,8 +4,7 @@ require_once("lib.php"); require_variable($id); // course module ID - require_variable($mode); // edit or delete - optional_variable($go); // commit the operation? + optional_variable($confirm); // commit the operation? optional_variable($entry); // entry id require_variable($prevmode); // current frame optional_variable($hook); // pivot id @@ -27,13 +26,17 @@ require_login($course->id); if (isguest()) { - error("Guests are not allowed to edit ir delete entries", $_SERVER["HTTP_REFERER"]); + error("Guests are not allowed to edit or delete entries", $_SERVER["HTTP_REFERER"]); } if (! $glossary = get_record("glossary", "id", $cm->instance)) { error("Glossary is incorrect"); } + if (!isteacher($course->id) and !$glossary->studentcanpost ) { + error("You are not allowed to edit or delete entries"); + } + $entryfields = get_record("glossary_entries", "id", $entry); $strareyousuredelete = get_string("areyousuredelete","glossary"); @@ -48,65 +51,38 @@ /// If data submitted, then process and store. - if ($mode == "edit" or $mode == "delete" ) { - echo "

"; - if ( isteacher($course->id) or $glossary->studentcanpost ) { - if ($go) { // the operation was confirmed. - if ( $mode == "delete") { - // if it is an imported entry, just delete the relation - $entry = get_record("glossary_entries","id", $entry); - if ( $entry->sourceglossaryid ) { - $entry->glossaryid = $entry->sourceglossaryid; - $entry->sourceglossaryid = 0; - if (! update_record("glossary_entries", $entry)) { - error("Could not update your glossary"); - } - } else { - if ( $entry->attachment ) { - glossary_delete_old_attachments($entry); - } - delete_records("glossary_comments", "entryid",$entry->id); - delete_records("glossary_alias", "entryid", $entry->id); - delete_records("glossary_ratings", "entryid", $entry->id); - - delete_records("glossary_entries","id", $entry->id); - } - - print_simple_box_start("center","40%", "#FFBBBB"); - echo "

$entrydeleted"; - echo "
"; - print_simple_box_end(); - } - print_footer($course); - add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry,$cm->id); - redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook"); - } else { // the operation has not been confirmed yet so ask the user to do so - if ( $mode == "delete") { - print_simple_box_start("center","40%", "#FFBBBB"); - echo "
$entryfields->concept
$strareyousuredelete"; - - ?> -
- - - - - - > - > - - "> - " onclick="javascript:history.go(-1);"> - -
-
- sourceglossaryid ) { + $entry->glossaryid = $entry->sourceglossaryid; + $entry->sourceglossaryid = 0; + if (! update_record("glossary_entries", $entry)) { + error("Could not update your glossary"); } + } else { - error("You are not allowed to edit or delete entries"); + if ( $entry->attachment ) { + glossary_delete_old_attachments($entry); + } + delete_records("glossary_comments", "entryid",$entry->id); + delete_records("glossary_alias", "entryid", $entry->id); + delete_records("glossary_ratings", "entryid", $entry->id); + delete_records("glossary_entries","id", $entry->id); } + + add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry,$cm->id); + redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entrydeleted); + + } else { // the operation has not been confirmed yet so ask the user to do so + + notice_yesno("$entryfields->concept

$strareyousuredelete

", + "deleteentry.php?id=$cm->id&mode=delete&confirm=1&entry=".s($entry)."&prevmode=$prevmode&hook=$hook", + "view.php?id=$cm->id&mode=$prevmode&hook=$hook"); + } + print_footer($course); + ?> -- 2.39.5