diff --git a/unloze_poll_votes/scripting/unloze_ingame_poll_css_redux.sp b/unloze_poll_votes/scripting/unloze_ingame_poll_css_redux.sp index df844889..71182a36 100644 --- a/unloze_poll_votes/scripting/unloze_ingame_poll_css_redux.sp +++ b/unloze_poll_votes/scripting/unloze_ingame_poll_css_redux.sp @@ -13,6 +13,7 @@ int admin_editing[MAXPLAYERS + 1]; int server_port; char admin_table_edit[generic_length]; char admin_table_coloumn_edit[generic_length]; +char admin_table_info[generic_length]; Database database_connection; Database database_hlstats_connection; @@ -203,22 +204,32 @@ public int menu_edit_poll_options(Menu menu, MenuAction action, int iclient4, in { char info[generic_length]; menu.GetItem(selection, info, sizeof(info)); - if (StrContains(admin_table_coloumn_edit, "rewrite") != -1) + int poll_id = StringToInt(info); + DBResultSet rs2; + char query_edit3[generic_length]; + Format(query_edit3, sizeof(query_edit3), "SELECT poll_option_text FROM unloze_css_polls.poll_text pt WHERE pt.poll_id = %i", poll_id); + if ((rs2 = SQL_Query(database_connection, query_edit3)) != null && rs2.RowCount > 0) { - PrintToChat(iclient4, "Rewrite the option into chat. Type exit to abort"); - Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); - admin_editing[iclient4] = 8; - } - else if (StrContains(admin_table_coloumn_edit, "remove") != -1) - { - mysql_remove_poll_option(iclient4, info, admin_table_edit); - } - else if (StrContains(admin_table_coloumn_edit, "add command option to") != -1) - { - PrintToChat(iclient4, "Write the command related to option %s into the chat. Type exit to abort", info); - Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); - admin_editing[iclient4] = 9; + rs2.FetchRow(); + rs2.FetchString(0, admin_table_info, sizeof(admin_table_info)); + if (StrContains(admin_table_coloumn_edit, "rewrite") != -1) + { + PrintToChat(iclient4, "Rewrite the option into chat. Type exit to abort"); + Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); + admin_editing[iclient4] = 8; + } + else if (StrContains(admin_table_coloumn_edit, "remove") != -1) + { + mysql_remove_poll_option(iclient4, poll_id, admin_table_edit, admin_table_info); + } + else if (StrContains(admin_table_coloumn_edit, "add command option to") != -1) + { + PrintToChat(iclient4, "Write the command related to option %s into the chat. Type exit to abort", info); + Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); + admin_editing[iclient4] = 9; + } } + delete rs2; } case MenuAction_End: { @@ -352,12 +363,12 @@ public Action cmd_say(int client_say, int args) case 8: { mysql_rewrite_poll_option(client_say, info); - PrintToChat(client_say, "Rewrote %s into %s", admin_table_coloumn_edit, info); + PrintToChat(client_say, "Rewrote %s into %s", admin_table_info, info); admin_editing[client_say] = 0; } case 9: { - mysql_add_poll_option_command(client_say, info, admin_table_coloumn_edit); + mysql_add_poll_option_command(client_say, info, admin_table_info); PrintToChat(client_say, "Added %s as command option", info); admin_editing[client_say] = 0; } @@ -614,22 +625,15 @@ public void mysql_vote_poll(int client, char []table_name) delete rs_vote; } -public void mysql_remove_poll_option(int client, char []coloumn_info, char []target_table) +public void mysql_remove_poll_option(int client, int poll_id, char []target_table, char []coloumn_text) { DBResultSet rs_add; char query_remove[generic_length]; - Format(query_remove, sizeof(query_remove), "SELECT poll_id from unloze_css_polls.poll_text WHERE poll_option_text = '%s'", coloumn_info); - if ((rs_add = SQL_Query(database_connection, query_remove)) == null) - { - delete rs_add; - return; - } - int poll_id; - rs_add.FetchRow(); - poll_id = rs_add.FetchInt(0); Format(query_remove, sizeof(query_remove), "ALTER TABLE unloze_css_polls.`%s` DROP `%i`", target_table, poll_id); mysql_exec_prepared_statement(query_remove); - PrintToChat(client, "removed Option %s from poll %s", coloumn_info, target_table); + Format(query_remove, sizeof(query_remove), "DELETE FROM unloze_css_polls.poll_text WHERE poll_id = %i", poll_id); + mysql_exec_prepared_statement(query_remove); + PrintToChat(client, "removed Option %s from poll %s", coloumn_text, target_table); delete rs_add; editpoll(client, target_table); } @@ -666,7 +670,9 @@ public void mysql_add_poll_option_command(int client, char []command, char []col public void mysql_rewrite_poll_option(int client, char []info) { char query_rewrite[generic_length]; - Format(query_rewrite, sizeof(query_rewrite), "ALTER TABLE unloze_css_polls.`poll_text` SET poll_option_text = '%s' WHERE poll_option_text = '%s'", info, admin_table_coloumn_edit); + int poll_id = StringToInt(admin_table_coloumn_edit); + Format(query_rewrite, sizeof(query_rewrite), "UPDATE unloze_css_polls.`poll_text` SET poll_option_text = '%s' WHERE poll_id = %i", info, poll_id); + //PrintToChat(client, "query_rewrite: %s", query_rewrite); mysql_exec_prepared_statement(query_rewrite); } @@ -695,10 +701,12 @@ public void mysql_playtime_requirement(int client, char []info) int playtime; rs.FetchRow(); playtime = rs.FetchInt(0); - PrintToChat(client, "playtime required: %i", playtime); + //PrintToChat(client, "playtime required: %i", playtime); admin_editing[client] = 7; Menu menu = new Menu(editpollmenu, MENU_ACTIONS_ALL); - menu.SetTitle("Poll %s has playtime requirement: %i", "", info, playtime); + char menu_title[generic_length]; + Format(menu_title, sizeof(menu_title), "Poll %s has playtime requirement: %i", info, playtime); + menu.SetTitle(menu_title); menu.AddItem("0", "0 hours playtime requirement"); menu.AddItem("5", "5 hours playtime requirement"); menu.AddItem("10", "10 hours playtime requirement"); @@ -725,24 +733,10 @@ public void mysql_edit_poll(int client, char []info, int selection) delete rs; return; } - char table_names[generic_length][64]; - int index; if (rs.RowCount > 0) { //skip steam_auth row which is always first rs.FetchRow(); - DBResultSet rs1; - while (rs.FetchRow()) - { - int poll_id = rs.FetchInt(0); - Format(query_edit2, sizeof(query_edit2), "SELECT poll_option_text FROM unloze_css_polls.poll_text where poll_id = %i", poll_id); - if ((rs1 = SQL_Query(database_connection, query_edit2)) == null) - continue; - rs1.FetchRow(); - rs1.FetchString(0, table_names[index], sizeof(table_names)); - index++; - } - delete rs1; char pollchoice[generic_length]; switch(selection) { @@ -761,10 +755,24 @@ public void mysql_edit_poll(int client, char []info, int selection) } Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), pollchoice); Format(admin_table_edit, sizeof(admin_table_edit), info); - Menu menu_poll_options = new Menu(menu_edit_poll_options, MENU_ACTIONS_ALL); + + Menu menu_poll_options = new Menu(menu_edit_poll_options); menu_poll_options.SetTitle("Select which option to %s in poll %s", pollchoice, info); - for (int i = 0; i < index; i++) - menu_poll_options.AddItem(table_names[i], table_names[i]); + while (rs.FetchRow()) + { + DBResultSet rs1; + char table_names[generic_length]; + char table_column_poll_ids[generic_length]; + int poll_id = rs.FetchInt(0); + IntToString(poll_id, table_column_poll_ids, sizeof(table_column_poll_ids)); + Format(query_edit2, sizeof(query_edit2), "SELECT poll_option_text FROM unloze_css_polls.poll_text where poll_id = %i", poll_id); + if ((rs1 = SQL_Query(database_connection, query_edit2)) == null) + continue; + rs1.FetchRow(); + rs1.FetchString(0, table_names, sizeof(table_names)); + menu_poll_options.AddItem(table_column_poll_ids, table_names); + delete rs1; + } menu_poll_options.ExitButton = true; menu_poll_options.Display(client, MENU_TIME_FOREVER); }