noticed same vote option cant be multiple times in a vote, fixed cause dazkhar absolutely wanted 2 yes in one poll hihi

This commit is contained in:
jenzur 2020-04-14 15:25:33 +02:00
parent e13734e869
commit ae389a90f9

View File

@ -13,6 +13,7 @@ int admin_editing[MAXPLAYERS + 1];
int server_port; int server_port;
char admin_table_edit[generic_length]; char admin_table_edit[generic_length];
char admin_table_coloumn_edit[generic_length]; char admin_table_coloumn_edit[generic_length];
char admin_table_info[generic_length];
Database database_connection; Database database_connection;
Database database_hlstats_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]; char info[generic_length];
menu.GetItem(selection, info, sizeof(info)); 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"); rs2.FetchRow();
Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); rs2.FetchString(0, admin_table_info, sizeof(admin_table_info));
admin_editing[iclient4] = 8; if (StrContains(admin_table_coloumn_edit, "rewrite") != -1)
} {
else if (StrContains(admin_table_coloumn_edit, "remove") != -1) PrintToChat(iclient4, "Rewrite the option into chat. Type exit to abort");
{ Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info);
mysql_remove_poll_option(iclient4, info, admin_table_edit); admin_editing[iclient4] = 8;
} }
else if (StrContains(admin_table_coloumn_edit, "add command option to") != -1) else if (StrContains(admin_table_coloumn_edit, "remove") != -1)
{ {
PrintToChat(iclient4, "Write the command related to option %s into the chat. Type exit to abort", info); mysql_remove_poll_option(iclient4, poll_id, admin_table_edit, admin_table_info);
Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info); }
admin_editing[iclient4] = 9; 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: case MenuAction_End:
{ {
@ -352,12 +363,12 @@ public Action cmd_say(int client_say, int args)
case 8: case 8:
{ {
mysql_rewrite_poll_option(client_say, info); 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; admin_editing[client_say] = 0;
} }
case 9: 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); PrintToChat(client_say, "Added %s as command option", info);
admin_editing[client_say] = 0; admin_editing[client_say] = 0;
} }
@ -614,22 +625,15 @@ public void mysql_vote_poll(int client, char []table_name)
delete rs_vote; 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; DBResultSet rs_add;
char query_remove[generic_length]; 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); Format(query_remove, sizeof(query_remove), "ALTER TABLE unloze_css_polls.`%s` DROP `%i`", target_table, poll_id);
mysql_exec_prepared_statement(query_remove); 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; delete rs_add;
editpoll(client, target_table); 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) public void mysql_rewrite_poll_option(int client, char []info)
{ {
char query_rewrite[generic_length]; 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); mysql_exec_prepared_statement(query_rewrite);
} }
@ -695,10 +701,12 @@ public void mysql_playtime_requirement(int client, char []info)
int playtime; int playtime;
rs.FetchRow(); rs.FetchRow();
playtime = rs.FetchInt(0); playtime = rs.FetchInt(0);
PrintToChat(client, "playtime required: %i", playtime); //PrintToChat(client, "playtime required: %i", playtime);
admin_editing[client] = 7; admin_editing[client] = 7;
Menu menu = new Menu(editpollmenu, MENU_ACTIONS_ALL); 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("0", "0 hours playtime requirement");
menu.AddItem("5", "5 hours playtime requirement"); menu.AddItem("5", "5 hours playtime requirement");
menu.AddItem("10", "10 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; delete rs;
return; return;
} }
char table_names[generic_length][64];
int index;
if (rs.RowCount > 0) if (rs.RowCount > 0)
{ {
//skip steam_auth row which is always first //skip steam_auth row which is always first
rs.FetchRow(); 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]; char pollchoice[generic_length];
switch(selection) 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_coloumn_edit, sizeof(admin_table_coloumn_edit), pollchoice);
Format(admin_table_edit, sizeof(admin_table_edit), info); 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); menu_poll_options.SetTitle("Select which option to %s in poll %s", pollchoice, info);
for (int i = 0; i < index; i++) while (rs.FetchRow())
menu_poll_options.AddItem(table_names[i], table_names[i]); {
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.ExitButton = true;
menu_poll_options.Display(client, MENU_TIME_FOREVER); menu_poll_options.Display(client, MENU_TIME_FOREVER);
} }