mirror of
https://github.com/ParadiseSS13/Paradise.git
synced 2026-07-18 10:33:30 +01:00
Improve View Flagged Books admin verb
This changes the "View Flagged Books" admin verb into a datum/browser UI. You can see all the books that have been flagged from here, review them, and remove the flagged status or delete them. Also refactors pencode into some __HELPER procs, and adds a "reverse-pencode" proc. It's not perfect, due to the complexity of HTML and my unwillingness to use BYONDregex, but it's good enough to get the general idea of the formatting across. It's used for the new "view book" panel.
This commit is contained in:
@@ -3019,6 +3019,59 @@
|
||||
else
|
||||
error_viewer.showTo(usr, null, href_list["viewruntime_linear"])
|
||||
|
||||
// Library stuff
|
||||
else if(href_list["library_book_id"])
|
||||
var/isbn = href_list["library_book_id"]
|
||||
|
||||
if(href_list["view_library_book"])
|
||||
var/DBQuery/query_view_book = dbcon.NewQuery("SELECT content, title FROM [format_table_name("library")] WHERE id=[isbn]")
|
||||
if(!query_view_book.Execute())
|
||||
var/err = query_view_book.ErrorMsg()
|
||||
log_game("SQL ERROR viewing book. Error : \[[err]\]\n")
|
||||
return
|
||||
|
||||
var/content = ""
|
||||
var/title = ""
|
||||
while(query_view_book.NextRow())
|
||||
content = query_view_book.item[1]
|
||||
title = html_encode(query_view_book.item[2])
|
||||
|
||||
var/dat = "<pre><code>"
|
||||
dat += "[html_encode(html_to_pencode(content))]"
|
||||
dat += "</code></pre>"
|
||||
|
||||
var/datum/browser/popup = new(usr, "admin_view_book", "[title]", 700, 400)
|
||||
popup.set_content(dat)
|
||||
popup.open(0)
|
||||
|
||||
log_admin("[key_name(usr)] has viewed the book [isbn].")
|
||||
message_admins("[key_name_admin(usr)] has viewed the book [isbn].")
|
||||
return
|
||||
|
||||
else if(href_list["unflag_library_book"])
|
||||
var/DBQuery/query_unflag_book = dbcon.NewQuery("UPDATE [format_table_name("library")] SET flagged = 0 WHERE id=[isbn]")
|
||||
if(!query_unflag_book.Execute())
|
||||
var/err = query_unflag_book.ErrorMsg()
|
||||
log_game("SQL ERROR unflagging book. Error : \[[err]\]\n")
|
||||
return
|
||||
|
||||
log_admin("[key_name(usr)] has unflagged the book [isbn].")
|
||||
message_admins("[key_name_admin(usr)] has unflagged the book [isbn].")
|
||||
|
||||
else if(href_list["delete_library_book"])
|
||||
var/DBQuery/query_delbook = dbcon.NewQuery("DELETE FROM [format_table_name("library")] WHERE id=[isbn]")
|
||||
if(!query_delbook.Execute())
|
||||
var/err = query_delbook.ErrorMsg()
|
||||
log_game("SQL ERROR deleting book. Error : \[[err]\]\n")
|
||||
return
|
||||
|
||||
log_admin("[key_name(usr)] has deleted the book [isbn].")
|
||||
message_admins("[key_name_admin(usr)] has deleted the book [isbn].")
|
||||
|
||||
// Refresh the page
|
||||
src.view_flagged_books()
|
||||
|
||||
|
||||
/proc/admin_jump_link(var/atom/target)
|
||||
if(!target) return
|
||||
// The way admin jump links handle their src is weirdly inconsistent...
|
||||
|
||||
@@ -29,13 +29,36 @@
|
||||
to_chat(src, "Only administrators may use this command.")
|
||||
return
|
||||
|
||||
holder.view_flagged_books()
|
||||
|
||||
/datum/admins/proc/view_flagged_books()
|
||||
if(!usr.client.holder)
|
||||
return
|
||||
|
||||
var/dat = "<table><tr><th>ISBN</th><th>Title</th><th>Total Flags</th><th>Options</th></tr>"
|
||||
|
||||
var/DBQuery/query = dbcon.NewQuery("SELECT id, title, flagged FROM [format_table_name("library")] WHERE flagged > 0 ORDER BY flagged DESC")
|
||||
if(!query.Execute())
|
||||
var/err = query.ErrorMsg()
|
||||
log_game("SQL ERROR getting flagged books. Error : \[[err]\]\n")
|
||||
return
|
||||
|
||||
var/i
|
||||
for(i = 0, query.NextRow(), i++)
|
||||
to_chat(usr, "[add_zero(query.item[1], 4)] ([query.item[2]]) - flagged [query.item[3]] times.")
|
||||
to_chat(usr, "[i] flagged books total.")
|
||||
var/books = 0
|
||||
while(query.NextRow())
|
||||
books++
|
||||
var/isbn = query.item[1]
|
||||
dat += "<tr><td>[add_zero(isbn, 4)]</td><td>[query.item[2]]</td><td>[query.item[3]]</td><td>"
|
||||
dat += "<a href='?_src_=holder;library_book_id=[isbn];view_library_book=1;'>View Content</a>"
|
||||
dat += "<a href='?_src_=holder;library_book_id=[isbn];unflag_library_book=1;'>Unflag</a>"
|
||||
dat += "<a href='?_src_=holder;library_book_id=[isbn];delete_library_book=1;'>Delete</a>"
|
||||
dat += "</td>"
|
||||
|
||||
dat += "</table>"
|
||||
|
||||
if(!books)
|
||||
dat = "<h1>No flagged books! :)</h1>"
|
||||
|
||||
var/datum/browser/popup = new(usr, "admin_view_flagged_books", "Flagged Books", 700, 400)
|
||||
popup.set_content(dat)
|
||||
popup.open(0)
|
||||
|
||||
|
||||
@@ -199,62 +199,8 @@
|
||||
update_icon()
|
||||
|
||||
|
||||
/obj/item/weapon/paper/proc/parsepencode(var/t, var/obj/item/weapon/pen/P, mob/user as mob, var/iscrayon = 0)
|
||||
// t = sanitize(copytext(t),1,MAX_MESSAGE_LEN)
|
||||
|
||||
t = replacetext(t, "\[center\]", "<center>")
|
||||
t = replacetext(t, "\[/center\]", "</center>")
|
||||
t = replacetext(t, "\[br\]", "<BR>")
|
||||
t = replacetext(t, "\[b\]", "<B>")
|
||||
t = replacetext(t, "\[/b\]", "</B>")
|
||||
t = replacetext(t, "\[i\]", "<I>")
|
||||
t = replacetext(t, "\[/i\]", "</I>")
|
||||
t = replacetext(t, "\[u\]", "<U>")
|
||||
t = replacetext(t, "\[/u\]", "</U>")
|
||||
t = replacetext(t, "\[large\]", "<font size=\"4\">")
|
||||
t = replacetext(t, "\[/large\]", "</font>")
|
||||
t = replacetext(t, "\[sign\]", "<font face=\"[signfont]\"><i>[user ? user.real_name : "Anonymous"]</i></font>")
|
||||
t = replacetext(t, "\[field\]", "<span class=\"paper_field\"></span>")
|
||||
|
||||
t = replacetext(t, "\[h1\]", "<H1>")
|
||||
t = replacetext(t, "\[/h1\]", "</H1>")
|
||||
t = replacetext(t, "\[h2\]", "<H2>")
|
||||
t = replacetext(t, "\[/h2\]", "</H2>")
|
||||
t = replacetext(t, "\[h3\]", "<H3>")
|
||||
t = replacetext(t, "\[/h3\]", "</H3>")
|
||||
|
||||
if(!iscrayon)
|
||||
t = replacetext(t, "\[*\]", "<li>")
|
||||
t = replacetext(t, "\[hr\]", "<HR>")
|
||||
t = replacetext(t, "\[small\]", "<font size = \"1\">")
|
||||
t = replacetext(t, "\[/small\]", "</font>")
|
||||
t = replacetext(t, "\[list\]", "<ul>")
|
||||
t = replacetext(t, "\[/list\]", "</ul>")
|
||||
t = replacetext(t, "\[table\]", "<table border=1 cellspacing=0 cellpadding=3 style='border: 1px solid black;'>")
|
||||
t = replacetext(t, "\[/table\]", "</td></tr></table>")
|
||||
t = replacetext(t, "\[grid\]", "<table>")
|
||||
t = replacetext(t, "\[/grid\]", "</td></tr></table>")
|
||||
t = replacetext(t, "\[row\]", "</td><tr>")
|
||||
t = replacetext(t, "\[cell\]", "<td>")
|
||||
t = replacetext(t, "\[logo\]", "<img src = ntlogo.png>")
|
||||
|
||||
t = "<font face=\"[deffont]\" color=[P ? P.colour : "black"]>[t]</font>"
|
||||
else // If it is a crayon, and he still tries to use these, make them empty!
|
||||
t = replacetext(t, "\[*\]", "")
|
||||
t = replacetext(t, "\[hr\]", "")
|
||||
t = replacetext(t, "\[small\]", "")
|
||||
t = replacetext(t, "\[/small\]", "")
|
||||
t = replacetext(t, "\[list\]", "")
|
||||
t = replacetext(t, "\[/list\]", "")
|
||||
t = replacetext(t, "\[table\]", "")
|
||||
t = replacetext(t, "\[/table\]", "")
|
||||
t = replacetext(t, "\[row\]", "")
|
||||
t = replacetext(t, "\[cell\]", "")
|
||||
t = replacetext(t, "\[logo\]", "")
|
||||
|
||||
t = "<font face=\"[crayonfont]\" color=[P ? P.colour : "black"]><b>[t]</b></font>"
|
||||
|
||||
t = copytext(t, 1, MAX_PAPER_MESSAGE_LEN)
|
||||
/obj/item/weapon/paper/proc/parsepencode(var/t, var/obj/item/weapon/pen/P, mob/user as mob)
|
||||
t = pencode_to_html(t, usr, P, deffont, signfont, crayonfont)
|
||||
|
||||
//Count the fields
|
||||
var/laststart = 1
|
||||
@@ -303,12 +249,10 @@
|
||||
//var/t = strip_html_simple(input("Enter what you want to write:", "Write", null, null) as message, MAX_MESSAGE_LEN)
|
||||
var/t = input("Enter what you want to write:", "Write", null, null) as message
|
||||
var/obj/item/i = usr.get_active_hand() // Check to see if he still got that darn pen, also check if he's using a crayon or pen.
|
||||
var/iscrayon = 0
|
||||
add_hiddenprint(usr) // No more forging nasty documents as someone else, you jerks
|
||||
if(!istype(i, /obj/item/weapon/pen))
|
||||
if(!istype(i, /obj/item/toy/crayon))
|
||||
return
|
||||
iscrayon = 1
|
||||
|
||||
|
||||
// if paper is not in usr, then it must be near them, or in a clipboard or folder, which must be in or near usr
|
||||
@@ -326,8 +270,7 @@
|
||||
return
|
||||
*/
|
||||
t = html_encode(t)
|
||||
t = replacetext(t, "\n", "<BR>")
|
||||
t = parsepencode(t, i, usr, iscrayon) // Encode everything from pencode to html
|
||||
t = parsepencode(t, i, usr) // Encode everything from pencode to html
|
||||
|
||||
if(id!="end")
|
||||
addtofield(text2num(id), t) // He wants to edit a field, let him.
|
||||
|
||||
Reference in New Issue
Block a user