PageRenderTime 45ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/manage_vote_sites.php

https://gitlab.com/Tamm/RFCP
PHP | 280 lines | 267 code | 13 blank | 0 comment | 68 complexity | 49f01bf2a0ecf77e7c258141c4dbfc66 MD5 | raw file
  1. <?php
  2. if (!empty($loadingmodules))
  3. {
  4. $file = basename(__FILE__);
  5. $moduleCategory = "Edit";
  6. $moduleLabel = "Manage Vote Sites";
  7. $permission = "restricted";
  8. return;
  9. }
  10. if ($this_script == $script_name)
  11. {
  12. if ($userdata -> has_permission($action))
  13. {
  14. $gen = isset($_GET['page_gen']) ? $_GET['page_gen'] : "1";
  15. $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : "";
  16. $links = array ();
  17. $links[] = "<a href='./" . $script_name . "?action=" . $_GET['action'] . "'>View Sites</a>";
  18. $links[] = "<a href='./" . $script_name . "?action=" . $_GET['action'] . "&page=addedit'>Add Site</a>";
  19. if ($page == "")
  20. {
  21. $active_index = 0;
  22. }
  23. else if ($page == "addedit")
  24. {
  25. $active_index = 1;
  26. }
  27. else if ($page == "delete" || $page == "delete_site")
  28. {
  29. $active_index = 2;
  30. $links[] = "<a href='#'>Delete Item</a>";
  31. }
  32. $out .= generate_module_nav_html($links, $active_index);
  33. $attempt = get_vote_sites();
  34. if (empty($page))
  35. {
  36. $out .= "<table class=\"tborder\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">";
  37. $out .= "<tr>";
  38. $out .= "<td class=\"thead\" style=\"text-align: center;\" nowrap>ID</td>";
  39. $out .= "<td class=\"thead\" nowrap>Site Name</td>";
  40. $out .= "<td class=\"thead\" nowrap>Site Image</td>";
  41. $out .= "<td class=\"thead\" nowrap>Reset Time</td>";
  42. $out .= "<td class=\"thead\" colspan=\"2\" nowrap>Options</td>";
  43. $out .= "</tr>";
  44. if ($attempt["error"] == True)
  45. {
  46. $out .= get_notification_html($attempt["errorMessage"], ERROR);
  47. }
  48. foreach ($attempt["rows"] as $key => $row)
  49. {
  50. $out .= "<tr>";
  51. $out .= "<td valign=\"top\" style=\"text-align: center;\" nowrap>" . $row['vote_id'] . "</td>";
  52. $out .= "<td valign=\"top\" nowrap>" . $row['vote_site_name'] . "</td>";
  53. $out .= "<td valign=\"top\" style=\"text-align: center;\" width=\"1\" nowrap><a href=\"" . $row['vote_site_url'] . "\"><img src=\"" . $row['vote_site_image'] . "\" width=\"50\" /></a></td>";
  54. $out .= "<td valign=\"top\" nowrap>" . $row['vote_reset_time'] . "s</td>";
  55. $out .= "<td style=\"text-align: center;\" nowrap><a href=\"" . $script_name . "?action=" . $_GET['action'] . "&page=addedit&vote_id=" . $row['vote_id'] . "\" style=\"text-decoration: none;\">Edit</a></td>";
  56. $out .= "<td style=\"text-align: center;\" nowrap><a href=\"" . $script_name . "?action=" . $_GET['action'] . "&page=delete&vote_id=" . $row['vote_id'] . "\" style=\"text-decoration: none;\">Delete</a></td>";
  57. $out .= "</tr>";
  58. }
  59. if (count($attempt["rows"]) <= 0)
  60. {
  61. $out .= "<tr>";
  62. $out .= "<td colspan=\"7\" style=\"text-align: center; font-weight: bold;\">No vote for NC sites have been added.</td>";
  63. $out .= "</tr>";
  64. }
  65. $out .= "</table>";
  66. }
  67. else
  68. {
  69. if ($page == "addedit")
  70. {
  71. $display_form = true;
  72. $do_process = 0;
  73. $exit_process = false;
  74. $exit_text = "";
  75. $add_submit = isset($_POST['add_submit']) ? 1 : 0;
  76. $edit_submit = isset($_POST['edit_submit']) ? 1 : 0;
  77. $vote_id = isset($_REQUEST['vote_id']) && ctype_digit($_REQUEST['vote_id']) ? $_REQUEST['vote_id'] : "";
  78. $vote_site_name = isset($_POST['vote_site_name']) ? antiject($_POST['vote_site_name']) : "";
  79. $vote_site_url = isset($_POST['vote_site_url']) ? antiject($_POST['vote_site_url']) : "";
  80. $vote_site_image = isset($_POST['vote_site_image']) ? antiject($_POST['vote_site_image']) : "";
  81. $vote_reset_time = isset($_POST['vote_reset_time']) ? antiject($_POST['vote_reset_time']) : "43200";
  82. $messages = array ();
  83. if ($add_submit == 1 || $edit_submit == 1)
  84. {
  85. $do_process = 1;
  86. }
  87. if ($vote_id != "")
  88. {
  89. $page_mode = "edit_submit";
  90. $submit_name = "Update Site";
  91. $this_mode_title = "Edit Site";
  92. $disable = " disabled";
  93. if ($do_process == 0)
  94. {
  95. if (!array_key_exists($vote_id, $attempt["rows"]))
  96. {
  97. $display_form = false;
  98. $out .= get_notification_html("Could not find vote site", ERROR);
  99. }
  100. else
  101. {
  102. $info = $attempt["rows"][$vote_id];
  103. $vote_site_name = $info['vote_site_name'];
  104. $vote_site_url = $info['vote_site_url'];
  105. $vote_site_image = $info['vote_site_image'];
  106. $vote_reset_time = $info['vote_reset_time'];
  107. }
  108. }
  109. }
  110. else
  111. {
  112. $page_mode = "add_submit";
  113. $submit_name = "Add site";
  114. $this_mode_title = "Adding a new vote site";
  115. $disable = "";
  116. }
  117. if ($do_process == 1)
  118. {
  119. if ($vote_site_name == "")
  120. {
  121. $messages[] = "You have not filled in a name for this site";
  122. }
  123. if ($vote_reset_time == "")
  124. {
  125. $messages[] = "You have not filled in a reset time (in seconds)";
  126. }
  127. if (!ctype_digit($vote_reset_time))
  128. {
  129. $messages[] = "Invalid reset time given";
  130. }
  131. if (!filter_var($vote_site_url, FILTER_VALIDATE_URL))
  132. {
  133. $messages[] = "You have entered an invalid website url (make sure you include http://)";
  134. }
  135. if (!filter_var($vote_site_image, FILTER_VALIDATE_URL))
  136. {
  137. $messages[] = "You have entered an invalid image url (make sure you include http://)";
  138. }
  139. }
  140. if (count($messages) > 0)
  141. {
  142. $out .= get_notification_html($messages, ERROR);
  143. }
  144. else if ($add_submit == 1)
  145. {
  146. $add_site = add_vote_site($vote_site_name, $vote_site_url, $vote_site_image, $vote_reset_time);
  147. if ($add_site["error"] == True)
  148. {
  149. $out .= get_notification_html($add_site["errorMessage"], ERROR);
  150. }
  151. else
  152. {
  153. $out .= get_notification_html("Successfully added the site " . $vote_site_name, SUCCESS);
  154. gamecp_log(0, $userdata -> username, "ADMIN - VOTE SITES - ADDED - Site Name: {$vote_site_name}", 1);
  155. $display_form = false;
  156. $redirect = CUSTOM_PAGE_SHORT;
  157. $redirecturl = "./" . $script_name . "?action=" . $_GET['action'];
  158. }
  159. }
  160. else if ($edit_submit == 1)
  161. {
  162. $update_site = update_vote_site($vote_id, $vote_site_name, $vote_site_url, $vote_site_image, $vote_reset_time);
  163. if ($update_site["error"] == True)
  164. {
  165. $out .= get_notification_html($update_site["errorMessage"], ERROR);
  166. }
  167. else
  168. {
  169. $out .= get_notification_html("Successfully updated the site " . $vote_site_name, SUCCESS);
  170. gamecp_log(0, $userdata -> username, "ADMIN - VOTE SITES - UPDATED - Site ID: {$vote_id}", 1);
  171. $display_form = false;
  172. $redirect = CUSTOM_PAGE_SHORT;
  173. $redirecturl = "./" . $script_name . "?action=" . $_GET['action'];
  174. }
  175. }
  176. if ($display_form == true)
  177. {
  178. $out .= "<form class=\"ink-form\" method=\"post\">";
  179. $out .= "<table class=\"ink-form\" cellpadding=\"3\" cellspacing=\"1\" border=\"0\" width=\"100%\">";
  180. $out .= "<tr>";
  181. $out .= "<td class=\"thead\" colspan=\"2\">" . $this_mode_title . "</td>";
  182. $out .= "</tr>";
  183. $out .= "<tr>";
  184. $out .= "<td width=\"1\" nowrap>Site Name:</td>";
  185. $out .= "<td><input type=\"text\" name=\"vote_site_name\" value=\"" . $vote_site_name . "\"/></td>";
  186. $out .= "</tr>";
  187. $out .= "<tr>";
  188. $out .= "<td width=\"1\" nowrap>Reset Time:</td>";
  189. $out .= "<td><input type=\"text\" name=\"vote_reset_time\" value=\"" . $vote_reset_time . "\"/> (seconds)</td>";
  190. $out .= "</tr>";
  191. $out .= "<tr>";
  192. $out .= "<td width=\"1\" nowrap>Site URL:</td>";
  193. $out .= "<td><input type=\"text\" name=\"vote_site_url\" value=\"" . $vote_site_url . "\" size=\"50\"/></td>";
  194. $out .= "</tr>";
  195. $out .= "<tr>";
  196. $out .= "<td width=\"1\" nowrap>Site Image URL:</td>";
  197. $out .= "<td><input type=\"text\" name=\"vote_site_image\" value=\"" . $vote_site_image . "\" size=\"50\"/></td>";
  198. $out .= "</tr>";
  199. $out .= "<tr>";
  200. $out .= "<td colspan=\"2\" nowrap>";
  201. $out .= "<input name=\"vote_id\" type=\"hidden\" value=\"" . $vote_id . "\"/>";
  202. $out .= "<input name=\"page\" type=\"hidden\" value=\"addedit\"/>";
  203. $out .= "<input class=\"ink-button\" name=\"" . $page_mode . "\" type=\"submit\" value=\"" . $submit_name . "\"/></td>";
  204. $out .= "</tr>";
  205. $out .= "</table>";
  206. $out .= "</form>";
  207. }
  208. }
  209. else if ($page == "delete")
  210. {
  211. $vote_id = isset($_GET['vote_id']) && ctype_digit($_GET['vote_id']) ? $_GET['vote_id'] : "";
  212. if (!array_key_exists($vote_id, $attempt["rows"]))
  213. {
  214. $out .= get_notification_html("No site found", ERROR);
  215. }
  216. else
  217. {
  218. $out .= "<form class=\"ink-form\" method=\"post\">";
  219. $out .= "<p style=\"text-align: center; font-weight: bold;\">Are you sure you want to DELETE the site: <u>" . antiject($attempt["rows"][$vote_id]['vote_site_name']) . "</u> (ID: " . $vote_id . ")?</p>";
  220. $out .= "<p style=\"text-align: center;\"><input type=\"hidden\" name=\"vote_id\" value=\"" . $vote_id . "\"/><input type=\"hidden\" name=\"page\" value=\"delete_site\"/><input type=\"submit\" name=\"yes\" value=\"Yes\"/> <input type=\"submit\" name=\"no\" value=\"No\"/></p>";
  221. $out .= "</form>";
  222. }
  223. }
  224. else if ($page == "delete_site")
  225. {
  226. $yes = isset($_POST['yes']) ? "1" : "0";
  227. $no = isset($_POST['no']) ? "1" : "0";
  228. $vote_id = isset($_POST['vote_id']) && ctype_digit($_POST['vote_id']) ? $_POST['vote_id'] : "";
  229. if ($no != 1 && $vote_id != "")
  230. {
  231. if (!array_key_exists($vote_id, $attempt["rows"]))
  232. {
  233. $out .= get_notification_html("No site found", ERROR);
  234. }
  235. else
  236. {
  237. delete_vote_site($vote_id);
  238. $out .= get_notification_html("Successfully deleted the site " . $attempt["rows"][$vote_id]['vote_site_name'], SUCCESS);
  239. gamecp_log(2, $userdata -> username, "ADMIN - VOTE SITES - DELETED - Site Name: " . antiject($attempt["rows"][$vote_id]['vote_site_name']) . " | ID: " . $vote_id, 1);
  240. $redirect = CUSTOM_PAGE_SHORT;
  241. $redirecturl = "./" . $script_name . "?action=" . $_GET['action'];
  242. }
  243. }
  244. else
  245. {
  246. $redirect = CUSTOM_PAGE_SHORT;
  247. $redirecturl = "./" . $script_name . "?action=" . $_GET['action'];
  248. }
  249. }
  250. else
  251. {
  252. $out .= get_notification_html(PAGE_NOT_FOUND, ERROR);
  253. $redirect = INDEX_PAGE_SHORT;
  254. }
  255. }
  256. }
  257. else
  258. {
  259. $out .= get_notification_html(INVALID_PERMISSION, ERROR);
  260. $redirect = INDEX_PAGE_SHORT;
  261. }
  262. }
  263. else
  264. {
  265. $out .= get_notification_html(INVALID_LOAD, ERROR);
  266. $redirect = INDEX_PAGE_SHORT;
  267. }