#define LIBRARY_MENU_MAIN 1 #define LIBRARY_MENU_CKEY 2 #define LIBRARY_MENU_REPORTS 3 USER_VERB(library_manager, R_ADMIN, "Manage Library", "Manage Flagged Books and Perform Maintenance on the Library System", VERB_CATEGORY_ADMIN) var/datum/ui_module/library_manager/L = new() L.ui_interact(client.mob) SSblackbox.record_feedback("tally", "admin_verb", 1, "Manage Library") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! /datum/ui_module/library_manager name = "Library Manager" ///Where we will store our cachedbook datums var/list/cached_books = list() ///list of assoc lists detailing each invidual reports, can contain multiple reports for same book var/list/reports = list() ///TGUI page we are currently on var/page_state = LIBRARY_MENU_MAIN ///Ckey's books we are viewing var/selected_ckey ///information for the book we are opening in browserui var/datum/cachedbook/view_book ///browserui helper variable for turning pages in book var/view_book_page = 0 /datum/ui_module/library_manager/ui_state(mob/user) return GLOB.admin_state /datum/ui_module/library_manager/ui_interact(mob/user, datum/tgui/ui = null) ui = SStgui.try_update_ui(user, src, ui) if(!ui) ui = new(user, src, "LibraryManager", name) ui.autoupdate = TRUE ui.open() /datum/ui_module/library_manager/ui_data(mob/user) var/list/data = list() data["pagestate"] = page_state data["booklist"] = cached_books data["ckey"] = selected_ckey ? selected_ckey : "ERROR" data["reports"] = reports data["modal"] = ui_modal_data(src) return data /datum/ui_module/library_manager/ui_act(action, params, datum/tgui/ui) if(..()) return . = TRUE if(ui_act_modal(action, params)) return switch(action) if("view_reported_books") reports = list() for(var/datum/cachedbook/CB in GLOB.library_catalog.get_flagged_books()) for(var/datum/flagged_book/report as anything in CB.reports) if(!report) continue var/datum/library_category/report_category = GLOB.library_catalog.get_report_category_by_id(report.category_id) var/report_info = list( "reporter_ckey" = report.reporter, "uploader_ckey" = CB.ckey, "id" = CB.id, "title" = CB.title, "author" = CB.author, "report_description" = report_category.description, ) reports += list(report_info) page_state = LIBRARY_MENU_REPORTS if("delete_book") if(text2num(params["bookid"])) //make sure this is actually a number if(GLOB.library_catalog.remove_book_by_id(text2num(params["bookid"]))) log_and_message_admins("has deleted book [params["bookid"]].") if("view_book") if(params["bookid"]) view_book_by_id(text2num(params["bookid"]), ui.user) if("unflag_book") if(params["bookid"]) if(GLOB.library_catalog.unflag_book_by_id(text2num(params["bookid"]))) log_and_message_admins("has unflagged book [params["bookid"]].") if("return") page_state = LIBRARY_MENU_MAIN /datum/ui_module/library_manager/proc/ui_act_modal(action, list/params) . = TRUE var/id = params["id"] // The modal's ID var/list/arguments = istext(params["arguments"]) ? json_decode(params["arguments"]) : params["arguments"] switch(ui_modal_act(src, action, params)) if(UI_MODAL_OPEN) switch(id) if("specify_ssid_delete") ui_modal_input(src, id, "Please input a book SSID:", null, arguments) if("specify_ckey_search") ui_modal_input(src, id, "Please input a CKEY:", null, arguments) if("specify_ckey_delete") ui_modal_input(src, id, "Please input a CKEY:", null, arguments) else return FALSE if(UI_MODAL_ANSWER) var/answer = params["answer"] switch(id) if("specify_ssid_delete") if(!answer || !text2num(answer)) return var/confirm = tgui_alert(usr, "You are about to delete book [text2num(answer)]", "Confirm Deletion", list("Yes", "No")) if(confirm != "Yes") return //we don't need to sanitize b/c removeBookyByID uses id=:id instead of like statemetns if(GLOB.library_catalog.remove_book_by_id(text2num(answer))) log_and_message_admins("has deleted the book [text2num(answer)].") if("specify_ckey_search") if(!answer) return var/datum/library_user_data/search_terms = new() search_terms.search_ckey = paranoid_sanitize(answer) selected_ckey = paranoid_sanitize(answer) cached_books = list() for(var/datum/cachedbook/CB in GLOB.library_catalog.get_book_by_range(1, 10, search_terms)) var/list/book_data = list( "id" = CB.id, "title" = CB.title, "author" = CB.author, "rating" = CB.rating, "summary" = CB.summary, "ckey" = CB.ckey, "reports" = CB.reports, ) cached_books += list(book_data) page_state = LIBRARY_MENU_CKEY if("specify_ckey_delete") if(!answer) return var/sanitized_answer = paranoid_sanitize(answer) //the last thing we want happening is someone deleting every book with "%%" var/confirm //We want to be absolutely certain an admin wants to do this confirm = tgui_alert(usr, "You are about to mass delete potentially up to 10 books", "Confirm Deletion", list("Yes", "No")) if(confirm != "Yes") return if(GLOB.library_catalog.remove_books_by_ckey(sanitized_answer)) log_and_message_admins("has deleted all books uploaded by [answer].") else return FALSE else return FALSE /datum/ui_module/library_manager/proc/view_book_by_id(bookid, mob/user) if(!view_book || view_book.id != bookid) view_book = GLOB.library_catalog.get_book_by_id(bookid) view_book_page = 0 view_book(user) /* * #View Book * * Internal proc for viewing library books as an admin. This absolutely must stay as BrowserUI even though the rest of * the library manager is TGUI. This is because of TGUI sanitization issues. */ /datum/ui_module/library_manager/proc/view_book(mob/user) if(!view_book || !length(view_book.content)) return var/dat = "" //First, we're going to choose/generate our header buttons for switching pages and store it in var/dat var/header_left = "
" var/header_right = "" if(length(view_book.content)) //No need to have page switching buttons if there's no pages if(view_book_page < length(view_book.content)) header_right = "