Skip to content

Commit

Permalink
ngggh I'll do later. Fixes polling mostly and TGUI. but has SQL issues
Browse files Browse the repository at this point in the history
Column 'createdby_ip' cannot be null INSERT INTO poll_question
{ ERROR 1048 (23000): Column 'pollid' cannot be null
  • Loading branch information
BeebBeebBoob committed Jan 17, 2025
1 parent 7ccde68 commit 91f0673
Show file tree
Hide file tree
Showing 15 changed files with 573 additions and 434 deletions.
14 changes: 14 additions & 0 deletions SQL/paradise_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -733,3 +733,17 @@ CREATE TABLE IF NOT EXISTS `poll_vote` (
KEY `idx_pvote_pollid_ckey` (`pollid`,`ckey`),
KEY `idx_pvote_optionid_ckey` (`optionid`,`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DELIMITER $$
CREATE PROCEDURE `set_poll_deleted`(
IN `poll_id` INT
)
SQL SECURITY INVOKER
BEGIN
UPDATE `poll_question` SET deleted = 1 WHERE id = poll_id;
UPDATE `poll_option` SET deleted = 1 WHERE pollid = poll_id;
UPDATE `poll_vote` SET deleted = 1 WHERE pollid = poll_id;
UPDATE `poll_textreply` SET deleted = 1 WHERE pollid = poll_id;
END
$$
DELIMITER ;
14 changes: 14 additions & 0 deletions SQL/updates/33-34.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,17 @@ CREATE TABLE IF NOT EXISTS `poll_vote` (
KEY `idx_pvote_pollid_ckey` (`pollid`,`ckey`),
KEY `idx_pvote_optionid_ckey` (`optionid`,`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DELIMITER $$
CREATE PROCEDURE `set_poll_deleted`(
IN `poll_id` INT
)
SQL SECURITY INVOKER
BEGIN
UPDATE `poll_question` SET deleted = 1 WHERE id = poll_id;
UPDATE `poll_option` SET deleted = 1 WHERE pollid = poll_id;
UPDATE `poll_vote` SET deleted = 1 WHERE pollid = poll_id;
UPDATE `poll_textreply` SET deleted = 1 WHERE pollid = poll_id;
END
$$
DELIMITER ;
2 changes: 1 addition & 1 deletion code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
#define EXPLOSION_BLOCK_PROC -1

// The SQL version required by this version of the code
#define SQL_VERSION 33
#define SQL_VERSION 34

// Vending machine stuff
#define CAT_NORMAL 1
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/non-firing/titlescreen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ SUBSYSTEM_DEF(title)
<a class="menu_button" href='byond://?src=[player.UID()];game_preferences=1'>Настройки игры</a>
<hr>
<a class="menu_button" href='byond://?src=[player.UID()];sound_options=1'>Настройки громкости</a>
<a class="menu_button" href='byond://?src=[player.UID()];poll_panel=1'>Открыть текущее голосование</a>
<a class="menu_button" href='byond://?src=[player.UID()];poll_panel=1'>Открыть голосование</a>
"}
// html += "<a class="menu_button" href='byond://?src=[player.UID()];swap_server=1'>Сменить сервер</a>" // TODO: add this after regis merge
if(!viewer.prefs.discord_id || (viewer.prefs.discord_id && length(viewer.prefs.discord_id) == 32))
Expand Down
21 changes: 11 additions & 10 deletions code/modules/admin/polls/player_poll.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
*
*/
/mob/new_player/proc/handle_player_polling()
var/list/output = list("<div align='center'><B>Player polls</B><hr><table>")
var/list/output = {"<meta charset="UTF-8">"}
output += "<div align='center'><B>Player polls</B><hr><table>"
var/rs = REF(src)
for(var/p in GLOB.active_polls)
var/datum/poll_question/poll = p
if((poll.admin_only && !client.holder) || poll.future_poll)
continue
output += "<tr bgcolor='#e2e2e2'><td><a href='?src=[rs];viewpoll=[REF(poll)]'><b>[poll.question]</b></a></td></tr>"
output += "</table>"
src << browse(jointext(output, ""),"window=playerpolllist;size=500x300") // I'll do TGUI later -Beeb
src << browse(output,"window=playerpolllist;size=500x300") // I'll do TGUI later -Beeb

/**
* Redirects a player to the correct poll window based on poll type.
Expand Down Expand Up @@ -51,7 +52,7 @@
if(query_option_get_voted.NextRow())
voted_option_id = text2num(query_option_get_voted.item[1])
qdel(query_option_get_voted)
var/list/output = list("<div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>")
var/list/output = {"<meta charset="UTF-8"><div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>"}
if(poll.subtitle)
output += "[poll.subtitle]<br>"
output += "<font size='2'>Poll runs from <b>[poll.start_datetime]</b> until <b>[poll.end_datetime]</b></font><br>"
Expand All @@ -75,7 +76,7 @@
if(!voted_option_id || poll.allow_revoting)
output += "<p><input type='submit' value='Vote'></form>"
output += "</div>"
src << browse(jointext(output, ""),"window=playerpoll;size=500x250")
src << browse(output,"window=playerpoll;size=500x250")

/**
* Shows voting window for a text response type poll, listing its relevant details.
Expand All @@ -95,7 +96,7 @@
if(query_text_get_replytext.NextRow())
reply_text = query_text_get_replytext.item[1]
qdel(query_text_get_replytext)
var/list/output = list("<div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>")
var/list/output = {"<meta charset="UTF-8"><div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>"}
if(poll.subtitle)
output += "[poll.subtitle]<br>"
output += "<font size='2'>Feedback gathering runs from <b>[poll.start_datetime]</b> until <b>[poll.end_datetime]</b></font><br>"
Expand All @@ -112,7 +113,7 @@
else
output += "[reply_text]"
output += "</div>"
src << browse(jointext(output, ""),"window=playerpoll;size=500x500")
src << browse(output,"window=playerpoll;size=500x500")

/**
* Shows voting window for a rating type poll, listing its options and relevant details.
Expand All @@ -132,7 +133,7 @@
while(query_rating_get_votes.NextRow())
voted_ratings += list("[query_rating_get_votes.item[1]]" = query_rating_get_votes.item[2])
qdel(query_rating_get_votes)
var/list/output = list("<div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>")
var/list/output = {"<meta charset="UTF-8"><div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>"}
if(poll.subtitle)
output += "[poll.subtitle]<br>"
output += "<font size='2'>Poll runs from <b>[poll.start_datetime]</b> until <b>[poll.end_datetime]</b></font><br>"
Expand Down Expand Up @@ -167,7 +168,7 @@
if(!length(voted_ratings) || poll.allow_revoting)
output += "<p><input type='submit' value='Submit'></form>"
output += "</div>"
src << browse(jointext(output, ""),"window=playerpoll;size=500x500")
src << browse(output,"window=playerpoll;size=500x500")

/**
* Shows voting window for a multiple choice type poll, listing its options and relevant details.
Expand All @@ -187,7 +188,7 @@
while(query_multi_get_votes.NextRow())
voted_for += text2num(query_multi_get_votes.item[1])
qdel(query_multi_get_votes)
var/list/output = list("<div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>")
var/list/output = {"<meta charset="UTF-8"><div align='center'><B>Player poll</B><hr><b>Question: [poll.question]</b><br>"}
if(poll.subtitle)
output += "[poll.subtitle]<br>"
output += "You can select up to [poll.options_allowed] options. If you select more, the first [poll.options_allowed] will be saved.<br><font size='2'>Poll runs from <b>[poll.start_datetime]</b> until <b>[poll.end_datetime]</b></font><br>"
Expand All @@ -211,7 +212,7 @@
if(!length(voted_for) || poll.allow_revoting)
output += "<p><input type='submit' value='Vote'></form>"
output += "</div>"
src << browse(jointext(output, ""),"window=playerpoll;size=500x300")
src << browse(output,"window=playerpoll;size=500x300")

/**
* Runs some poll validation before a vote is processed.
Expand Down
16 changes: 11 additions & 5 deletions code/modules/admin/polls/poll_db.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* Also does some simple error checking to ensure the poll will be valid before creation.
*
*/
/client/proc/poll_parse(list/list_poll, datum/poll_question/poll)
/client/proc/poll_parse(datum/ui_module/poll_management_panel/our_panel, datum/poll_question/poll)
var/list_poll = our_panel.list_poll
if(!check_rights(R_SERVER))
return
if(!SSdbcore.Connect())
Expand All @@ -14,6 +15,7 @@
var/list/error_state = list()
var/new_poll = FALSE // submit_ready
var/clear_votes = FALSE
var/submit_ready = FALSE
if(!poll)
poll = new(creator = usr.client.ckey)
new_poll = TRUE
Expand Down Expand Up @@ -55,6 +57,8 @@
poll.allow_revoting = FALSE
if(list_poll["clear_votes"])
clear_votes = TRUE
if(list_poll["submitpoll"])
submit_ready = TRUE
if(poll.poll_type == POLLTYPE_MULTI)
if(text2num(list_poll["options_allowed"]))
poll.options_allowed = text2num(list_poll["options_allowed"])
Expand All @@ -66,7 +70,7 @@
error_state += "Multiple choice options allowed cannot be negative."
else
error_state += "Multiple choice poll was selected but no number of allowed options was provided."
if(new_poll && poll.poll_type != POLLTYPE_TEXT && !length(poll.options))
if(submit_ready && poll.poll_type != POLLTYPE_TEXT && !length(poll.options))
error_state += "This poll type requires at least one option."
if(error_state.len)
if(poll.edit_ready)
Expand All @@ -76,12 +80,14 @@
if(new_poll)
qdel(poll)
return
if(new_poll)
to_chat(usr, span_notice("all clear"))
if(submit_ready)
var/db = poll.edit_ready //if the poll is new it will need its options inserted for the first time
poll.save_poll_data(clear_votes)
if(!db)
poll.save_all_options()
open_poll_management(poll)
our_panel.poll = poll //set or qdel'd, no matter
SStgui.try_update_ui(usr, our_panel)

/**
* Processes topic data from poll option panel.
Expand Down Expand Up @@ -157,12 +163,12 @@
else
to_chat(usr, span_danger("Not all edits were applied because the following errors were present:\n[error_state.Join("\n")]"), confidential = TRUE)
return
to_chat(usr, span_notice("all clear"))
if(new_option)
poll.options += option
option.parent_poll = poll
if(poll.edit_ready)
option.save_option()
open_poll_management(poll)

/**
* Loads all current and future server polls and their options to store both as datums.
Expand Down
24 changes: 12 additions & 12 deletions code/modules/admin/polls/poll_list_panel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
/datum/ui_module/poll_list_panel
name = "Poll List Panel"

/datum/admins/proc/open_poll_list()
set name = "Server Poll Management"
set category = "Server"

if(!check_rights(R_SERVER))
return

var/datum/ui_module/poll_list_panel/panel_pollo = new(usr)
panel_pollo.ui_interact(usr)


/datum/ui_module/poll_list_panel/ui_state(mob/user)
return GLOB.admin_state

Expand Down Expand Up @@ -87,17 +98,6 @@
poll_list_panel()
*/

/datum/admins/proc/open_poll_list()
set name = "Server Poll Management"
set category = "Server"

if(!check_rights(R_SERVER))
return

var/datum/ui_module/poll_list_panel/panel_pollo = new(usr)

panel_pollo.ui_interact(usr)


/**
* Shows the results for a poll
Expand All @@ -108,7 +108,7 @@
if(!SSdbcore.IsConnected())
to_chat(usr, span_danger("Not connected to database. Cannot retrieve data."))
return
var/output = "<div align='center'><B>Player Poll Results</B><hr>[poll.question]<hr>"
var/output = {"<meta charset="UTF-8"><div align='center'><B>Player Poll Results</B><hr>[poll.question]<hr>"}
//Each poll type is different
switch (poll.poll_type)
//Show the options that were clicked
Expand Down
70 changes: 52 additions & 18 deletions code/modules/admin/polls/poll_management_panel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
var/run_start = TRUE // TRUE - run now , FALSE - at datetime
var/clear_votes = TRUE // Should clean votes upon updating poll

/client/proc/open_poll_management(datum/poll_question/poll, datum/tgui/ui = null)
if(!check_rights(R_SERVER))
return

var/datum/ui_module/poll_management_panel/panel_pollo = new(usr)
panel_pollo.poll = poll

panel_pollo.ui_interact(usr)

/datum/ui_module/poll_management_panel/ui_state(mob/user)
return GLOB.admin_state
Expand All @@ -28,8 +36,6 @@
.["poll_types"] = list(POLLTYPE_OPTION, POLLTYPE_TEXT, POLLTYPE_RATING, POLLTYPE_MULTI)
.["interval_types"] = list(POLL_SECOND, POLL_MINUTE, POLL_HOUR, POLL_DAY, POLL_WEEK, POLL_MONTH, POLL_YEAR)

return .

/datum/ui_module/poll_management_panel/ui_data(mob/user)
. = list()
.["has_poll"] = poll ? TRUE : FALSE
Expand All @@ -46,13 +52,17 @@
list_poll["subtitle"] = poll ? poll.subtitle : ""
list_poll["poll_votes"] = poll ? poll.poll_votes : 0
list_poll["minimum_playtime"] = poll ? poll.minimum_playtime : 0
// non-poll but needed
list_poll["run_duration"] = run_duration
list_poll["run_start"] = run_start
list_poll["clear_votes"] = clear_votes

list_poll["options"] = list()
if(poll)
var/option_count = 0
for(var/datum/poll_option/option in poll.options)
option_count++
var/list_option = list("num" = "[option_count]",
var/list/list_option = list("num" = "[option_count]",
"id" = option.option_id,
"text" = option.text,
"min_val" = option.min_val,
Expand All @@ -61,11 +71,7 @@
"desc_mid" = option.desc_mid,
"desc_max" = option.desc_max
)
list_poll["options"] += list_option
// non-poll but needed
list_poll["run_duration"] = run_duration
list_poll["run_start"] = run_start
list_poll["clear_votes"] = clear_votes
list_poll["options"] += list(list_option)
.["poll"] = list_poll

/datum/ui_module/poll_management_panel/ui_act(action, list/params, datum/tgui/ui, datum/ui_state/state)
Expand All @@ -78,9 +84,45 @@
if("clear_poll_votes")
poll.clear_poll_votes()
if("initialize_poll")
ui_client.poll_parse(list_poll)
list_poll["submitpoll"] = FALSE
list_poll["question"] = params["question"] // I'd be happy if useLocalState could connect to DM, without pull&push params
list_poll["poll_type"] = params["poll_type"] // or I'm dumb, I'm not sorry
list_poll["options_allowed"] = params["options_allowed"]
list_poll["admin_only"] = params["admin_only"]
list_poll["dont_show"] = params["dont_show"]
list_poll["allow_revoting"] = params["allow_revoting"]
list_poll["interval"] = params["interval"]
list_poll["duration"] = params["duration"]
list_poll["start_datetime"] = params["start_datetime"]
list_poll["end_datetime"] = params["end_datetime"]
list_poll["subtitle"] = params["subtitle"]
list_poll["poll_votes"] = params["poll_votes"]
list_poll["minimum_playtime"] = params["minimum_playtime"]
// non-poll
list_poll["run_duration"] = params["run_duration"]
list_poll["run_start"] = params["run_start"]
list_poll["clear_votes"] = params["clear_votes"]
ui_client.poll_parse(src)
if("submit_poll")
ui_client.poll_parse(list_poll, poll)
list_poll["submitpoll"] = TRUE
list_poll["question"] = params["question"]
list_poll["poll_type"] = params["poll_type"]
list_poll["options_allowed"] = params["options_allowed"]
list_poll["admin_only"] = params["admin_only"]
list_poll["dont_show"] = params["dont_show"]
list_poll["allow_revoting"] = params["allow_revoting"]
list_poll["interval"] = params["interval"]
list_poll["duration"] = params["duration"]
list_poll["start_datetime"] = params["start_datetime"]
list_poll["end_datetime"] = params["end_datetime"]
list_poll["subtitle"] = params["subtitle"]
list_poll["poll_votes"] = params["poll_votes"]
list_poll["minimum_playtime"] = params["minimum_playtime"]
// non-poll
list_poll["run_duration"] = params["run_duration"]
list_poll["run_start"] = params["run_start"]
list_poll["clear_votes"] = params["clear_votes"]
ui_client.poll_parse(src, poll)
if("add_poll_option")
open_poll_option(poll)
if("edit_poll_option")
Expand All @@ -94,11 +136,3 @@
option.delete_option()
break

/client/proc/open_poll_management(datum/poll_question/poll)
if(!check_rights(R_SERVER))
return

var/datum/ui_module/poll_management_panel/panel_pollo = new(usr)
panel_pollo.poll = poll

panel_pollo.ui_interact(usr)
2 changes: 1 addition & 1 deletion code/modules/admin/polls/poll_option.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
GLOB.poll_options += src

/datum/poll_option/Destroy()
parent_poll.options -= src
parent_poll?.options -= src
parent_poll = null
GLOB.poll_options -= src
return ..()
Expand Down
Loading

0 comments on commit 91f0673

Please sign in to comment.