Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. <?php
  2. /**
  3. * Plugin Name: League of Legends Competitions
  4. * Plugin URI: http://Gl0rix.net
  5. * Description: A pluging that manages League of Legends Competitions.
  6. * Version: 1
  7. * Author: vav17
  8. * Author URI: http://vav17.com
  9. * License: LoLCompetitions All rights reserved!
  10. */
  11.  
  12. ?>
  13. <link rel="stylesheet" href="http://gl0rix.net/wp-content/plugins/LoLCompetitions/stylesheet.css" type="text/css"/>
  14. <script src="http://gl0rix.net/wp-content/plugins/LoLCompetitions/functions.js" type="text/javascript"></script>
  15. <?php
  16.  
  17.  
  18.  
  19. add_action( 'admin_menu', 'my_plugin_menu' );
  20.  
  21. function my_plugin_menu() {
  22. add_menu_page('LoL Competition', 'LoL Competition', 'manage_options', 'lol_competitions.php', 'show_teams', 'http://i.imgur.com/KfpaPNC.png');
  23. }
  24.  
  25. function show_teams(){
  26. global $wpdb;
  27. $spelers = get_users('role=speler');
  28. $captains = get_users('role=captain');
  29. print_r($spelers);
  30. if($_POST["action"] != ""){
  31. $_POST["action"]($_POST["id"]);
  32. }
  33. //if($_POST["action"] == ""){
  34. //teams
  35. $result = $wpdb->get_results( "SELECT * FROM tbl_teams");
  36. ?>
  37. <?php
  38. echo '<div id="show_teams_div"><table id="show_teams_table">
  39. <td>
  40. <form action="" method="post" name="frm_actions">
  41. <input type="hidden" name="action" value="add_team" />
  42. <input type="submit" value="Add Team" />
  43. </form>
  44. </td>
  45. <td>
  46. <form action="" method="post" name="frm_actions" id="frm_removeAll" onsubmit="return removeCheck()">
  47. <input type="hidden" name="action" value="remove_all_teams" />
  48. <input type="submit" value="Remove all" />
  49. </form>
  50. </td>
  51. <tr>
  52. <th>rank</th>
  53. <th>Team ID</th>
  54. <th>Team Name</th>
  55. <th></th>
  56. <th></th>
  57. </tr>';
  58. $i = 1;
  59. foreach ( $result as $r ){
  60. echo '<tr>
  61. <td>' . $i . '</td>
  62. <td>' . $r->team_id . '</td>
  63. <td>' . $r->team_name . '</td>';
  64. if( current_user_can( 'manage_options' ) ) {
  65. echo '
  66. <td><form action="" method="post" name="frm_actions">
  67. <input type="hidden" name="action" value="edit_team" />
  68. <input type="hidden" name="id" value="' . $r->team_id . '" />
  69. <input type="submit" value="Edit" />
  70. </form></td>';
  71. echo '
  72. <td><form action="" method="post" name="frm_actions" onsubmit="return confirm(\'Are you sure you want to delete this team?\')">
  73. <input type="hidden" name="action" value="remove_team" />
  74. <input type="hidden" name="id" value="' . $r->team_id . '" />
  75. <input type="submit" value="Remove" />
  76. </form></td>';
  77. }
  78. echo '</tr>';
  79. $i++;
  80. }
  81. echo "</table>";
  82. //}else{
  83. //$_POST["action"]($_POST["id"]);
  84. //}
  85. echo "</div>";
  86. }
  87.  
  88. function edit_team($id){
  89. global $wpdb;
  90. echo '<h2>Edit team with id '.$id.'</h2>';
  91. $result = $wpdb->get_results( "SELECT * FROM tbl_teams where team_id = '" . $id . "'");
  92. foreach ( $result as $r ){
  93. $team_name = $r->team_name;
  94. }
  95. ?>
  96. <form action="" method="post" name="frm_edit_team">
  97. <input type="hidden" name="action" value="save_team" />
  98. <input type="hidden" name="id" value="<?php echo $id;?>" />
  99. Team Name: <input type="text" name="team_name" value="<?php echo $team_name;?>" />
  100. <input type="submit" value="Save" />
  101. </form>
  102. <?php
  103. }
  104.  
  105. function remove_team($id){
  106. global $wpdb;
  107. $sql= "DELETE FROM tbl_teams WHERE team_id='".$id."'";
  108. $wpdb->query($sql);
  109. echo 'Team Removed<br/>';
  110. echo '<script>window.location.href="?page=lol_competitions.php"</script>';
  111. }
  112.  
  113. function remove_all_teams(){
  114. global $wpdb;
  115. $sql= "TRUNCATE TABLE tbl_teams";
  116. $wpdb->query($sql);
  117. echo 'Removed all teams!<br/>';
  118. echo '<script>window.location.href="?page=lol_competitions.php"</script>';
  119. }
  120.  
  121. function add_team(){
  122. echo '<h2>Add team</h2>';
  123. ?>
  124. <form action="" method="post" name="frm_add_team">
  125. <input type="hidden" name="action" value="save_team" />
  126. Team Name: <input type="text" name="team_name" />
  127. <input type="submit" value="Add" />
  128. </form>
  129. <?php
  130. }
  131.  
  132. function check_team_exists($team_name){
  133. global $wpdb;
  134. $total = $wpdb->get_var("SELECT count(*) AS TOTAL FROM tbl_teams where team_name='" . $team_name . "'");
  135. return $total;
  136. }
  137.  
  138. function save_team($id){
  139. global $wpdb;
  140. $execute = "false";
  141. if($id != ""){
  142. //team bijwerken
  143. if(check_team_exists($_POST["team_name"]) != 1){
  144. $sql = "UPDATE tbl_teams SET team_name='" . $_POST["team_name"] . "' WHERE team_id='" . $id . "' ";
  145. $execute = "true";
  146. }else{
  147. $execute = "false";
  148. }
  149. }else{
  150. //team toevoegen
  151. if(check_team_exists($_POST["team_name"]) != 1){
  152. $sql = "INSERT INTO tbl_teams (team_name) VALUES ('" . $_POST["team_name"] . "')";
  153. $execute = "true";
  154. }else{
  155. $execute = "false";
  156. }
  157. }
  158. if($execute == "true"){
  159. $wpdb->query($sql);
  160. echo 'Team saved<br/>';
  161. echo '<script>window.location.href="?page=lol_competitions.php"</script>';
  162. }else{
  163. echo 'Team already exists';
  164. add_team();
  165. }
  166. }
  167. //global $wpdb;
  168. //$query = "SELECT * FROM tbl_teams";
  169. //$wpdb->query($query);
  170.  
  171. //echo "No clue why I'm here tho...hbkkjlk";
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement