diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 160d644585d..d3594d87fa6 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -279,6 +279,9 @@ CREATE TABLE `poll_question` ( `endtime` datetime NOT NULL, `question` varchar(255) NOT NULL, `adminonly` tinyint(1) DEFAULT '0', + `multiplechoiceoptions` int(2) DEFAULT NULL, + `createdby_ckey` varchar(45) NULL DEFAULT NULL, + `createdby_ip` varchar(45) NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/SQL/paradise_schema_prefixed.sql b/SQL/paradise_schema_prefixed.sql index c0c4bca3553..4a61245cf83 100644 --- a/SQL/paradise_schema_prefixed.sql +++ b/SQL/paradise_schema_prefixed.sql @@ -279,6 +279,9 @@ CREATE TABLE `SS13_poll_question` ( `endtime` datetime NOT NULL, `question` varchar(255) NOT NULL, `adminonly` tinyint(1) DEFAULT '0', + `multiplechoiceoptions` int(2) DEFAULT NULL, + `createdby_ckey` varchar(45) NULL DEFAULT NULL, + `createdby_ip` varchar(45) NULL DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index b8f87c52582..12e10619a0a 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -1,10 +1,7 @@ //admin verb groups - They can overlap if you so wish. Only one of each verb will exist in the verbs list regardless var/list/admin_verbs_default = list( -// /datum/admins/proc/show_player_panel, /*shows an interface for individual players, with various links (links require additional flags*/ /client/proc/deadmin_self, /*destroys our own admin datum so we can play as a regular player*/ /client/proc/hide_verbs, /*hides all our adminverbs*/ -// /client/proc/check_antagonists, /*shows all antags*/ -// /client/proc/deadchat /*toggles deadchat on/off*/ /client/proc/cmd_mentor_check_new_players ) var/list/admin_verbs_admin = list( @@ -162,7 +159,8 @@ var/list/admin_verbs_possess = list( /proc/release ) var/list/admin_verbs_permissions = list( - /client/proc/edit_admin_permissions + /client/proc/edit_admin_permissions, + /client/proc/create_poll ) var/list/admin_verbs_rejuv = list( /client/proc/respawn_character, @@ -182,7 +180,6 @@ var/list/admin_verbs_mod = list( /datum/admins/proc/show_player_panel, /client/proc/jobbans, /client/proc/debug_variables /*allows us to -see- the variables of any instance in the game. +VAREDIT needed to modify*/ -// /client/proc/cmd_admin_subtle_message /*send an message to somebody as a 'voice in their head'*/ ) var/list/admin_verbs_mentor = list( diff --git a/code/modules/admin/create_poll.dm b/code/modules/admin/create_poll.dm new file mode 100644 index 00000000000..5a20904da8f --- /dev/null +++ b/code/modules/admin/create_poll.dm @@ -0,0 +1,125 @@ +/client/proc/create_poll() + set name = "Create Server Poll" + set category = "Server" + if(!check_rights(R_PERMISSIONS)) + return + if(!dbcon.IsConnected()) + src << "Failed to establish database connection." + return + var/polltype = input("Choose poll type.","Poll Type") in list("Single Option","Text Reply","Rating","Multiple Choice") + var/choice_amount = 0 + switch(polltype) + if("Single Option") + polltype = "OPTION" + if("Text Reply") + polltype = "TEXT" + if("Rating") + polltype = "NUMVAL" + if("Multiple Choice") + polltype = "MULTICHOICE" + choice_amount = input("How many choices should be allowed?","Select choice amount") as num + var/starttime = SQLtime() + var/endtime = input("Set end time for poll as format YYYY-MM-DD HH:MM:SS. All times in server time. HH:MM:SS is optional and 24-hour. Must be later than starting time for obvious reasons.", "Set end time", SQLtime()) as text + if(!endtime) + return + endtime = sanitizeSQL(endtime) + var/DBQuery/query_validate_time = dbcon.NewQuery("SELECT STR_TO_DATE('[endtime]','%Y-%c-%d %T')") + if(!query_validate_time.Execute()) + var/err = query_validate_time.ErrorMsg() + log_game("SQL ERROR validating endtime. Error : \[[err]\]\n") + return + if(query_validate_time.NextRow()) + endtime = query_validate_time.item[1] + if(!endtime) + src << "Datetime entered is invalid." + return + var/DBQuery/query_time_later = dbcon.NewQuery("SELECT DATE('[endtime]') < NOW()") + if(!query_time_later.Execute()) + var/err = query_time_later.ErrorMsg() + log_game("SQL ERROR comparing endtime to NOW(). Error : \[[err]\]\n") + return + if(query_time_later.NextRow()) + var/checklate = text2num(query_time_later.item[1]) + if(checklate) + src << "Datetime entered is not later than current server time." + return + var/adminonly + switch(alert("Admin only poll?",,"Yes","No","Cancel")) + if("Yes") + adminonly = 1 + if("No") + adminonly = 0 + else + return + var/sql_ckey = sanitizeSQL(ckey) + var/question = input("Write your question","Question") as message + if(!question) + return + question = sanitizeSQL(question) + var/DBQuery/query_polladd_question = dbcon.NewQuery("INSERT INTO [format_table_name("poll_question")] (polltype, starttime, endtime, question, adminonly, multiplechoiceoptions, createdby_ckey, createdby_ip) VALUES ('[polltype]', '[starttime]', '[endtime]', '[question]', '[adminonly]', '[choice_amount]', '[sql_ckey]', '[address]')") + if(!query_polladd_question.Execute()) + var/err = query_polladd_question.ErrorMsg() + log_game("SQL ERROR adding new poll question to table. Error : \[[err]\]\n") + return + var/pollid = 0 + var/DBQuery/query_get_id = dbcon.NewQuery("SELECT id FROM [format_table_name("poll_question")] WHERE question = '[question]' AND starttime = '[starttime]' AND endtime = '[endtime]' AND createdby_ckey = '[sql_ckey]' AND createdby_ip = '[address]'") + if(!query_get_id.Execute()) + var/err = query_get_id.ErrorMsg() + log_game("SQL ERROR obtaining id from poll_question table. Error : \[[err]\]\n") + return + if(query_get_id.NextRow()) + pollid = query_get_id.item[1] + if(polltype == "TEXT") + return + var/add_option = 1 + while(add_option) + var/option = input("Write your option","Option") as message + if(!option) + return + option = sanitizeSQL(option) + var/percentagecalc + switch(alert("Calculate option results as percentage?",,"Yes","No","Cancel")) + if("Yes") + percentagecalc = 1 + if("No") + percentagecalc = 0 + else + return + var/minval = 0 + var/maxval = 0 + var/descmin = "" + var/descmid = "" + var/descmax = "" + if(polltype == "NUMVAL") + minval = input("Set minimum rating value.","Minimum rating") as num + if(!minval) + return + maxval = input("Set maximum rating value.","Maximum rating") as num + if(!maxval) + return + if(minval >= maxval) + src << "Minimum rating value can't be more than maximum rating value" + return + descmin = input("Optional: Set description for minimum rating","Minimum rating description") as message + if(descmin) + descmin = sanitizeSQL(descmin) + descmid = input("Optional: Set description for median rating","Median rating description") as message + if(descmid) + descmid = sanitizeSQL(descmid) + descmax = input("Optional: Set description for maximum rating","Maximum rating description") as message + if(descmax) + descmax = sanitizeSQL(descmax) + var/DBQuery/query_polladd_option = dbcon.NewQuery("INSERT INTO [format_table_name("poll_option")] (pollid, text, percentagecalc, minval, maxval, descmin, descmid, descmax) VALUES ('[pollid]', '[option]', '[percentagecalc]', '[minval]', '[maxval]', '[descmin]', '[descmid]', '[descmax]')") + if(!query_polladd_option.Execute()) + var/err = query_polladd_option.ErrorMsg() + log_game("SQL ERROR adding new poll option to table. Error : \[[err]\]\n") + return + switch(alert(" ",,"Add option","Finish","Cancel")) + if("Add option") + add_option = 1 + if("Finish") + log_admin("[key_name(usr)] has created a new server poll. Poll type: [polltype] - Question: [question]") + message_admins("[key_name_admin(usr)] has created a new server poll. Poll type: [polltype] - Question: [question]") + add_option = 0 + else + return diff --git a/code/modules/mob/new_player/poll.dm b/code/modules/mob/new_player/poll.dm index 576422e3b05..7be517eb2d9 100644 --- a/code/modules/mob/new_player/poll.dm +++ b/code/modules/mob/new_player/poll.dm @@ -289,7 +289,7 @@ output += "" - src << browse(output,"window=playerpoll;size=500x250") + src << browse(output,"window=playerpoll;size=600x250") return /mob/new_player/proc/vote_on_poll(var/pollid = -1, var/optionid = -1, var/multichoice = 0) diff --git a/paradise.dme b/paradise.dme index 81669c187d9..c34538d17d3 100644 --- a/paradise.dme +++ b/paradise.dme @@ -895,6 +895,7 @@ #include "code\modules\admin\buildmode.dm" #include "code\modules\admin\create_mob.dm" #include "code\modules\admin\create_object.dm" +#include "code\modules\admin\create_poll.dm" #include "code\modules\admin\create_turf.dm" #include "code\modules\admin\holder2.dm" #include "code\modules\admin\IsBanned.dm"