Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Plugin Name: League of Legends Competitions
- * Plugin URI: http://Gl0rix.net
- * Description: A pluging that manages League of Legends Competitions.
- * Version: 1
- * Author: vav17
- * Author URI: http://vav17.com
- * License: LoLCompetitions All rights reserved!
- */
- ?>
- <link rel="stylesheet" href="http://gl0rix.net/wp-content/plugins/LoLCompetitions/stylesheet.css" type="text/css"/>
- <script src="http://gl0rix.net/wp-content/plugins/LoLCompetitions/functions.js" type="text/javascript"></script>
- <?php
- add_action( 'admin_menu', 'my_plugin_menu' );
- function my_plugin_menu() {
- add_menu_page('LoL Competition', 'LoL Competition', 'manage_options', 'lol_competitions.php', 'show_teams', 'http://i.imgur.com/KfpaPNC.png');
- }
- function show_teams(){
- global $wpdb;
- $spelers = get_users('role=speler');
- $captains = get_users('role=captain');
- print_r($spelers);
- if($_POST["action"] != ""){
- $_POST["action"]($_POST["id"]);
- }
- //if($_POST["action"] == ""){
- //teams
- $result = $wpdb->get_results( "SELECT * FROM tbl_teams");
- ?>
- <?php
- echo '<div id="show_teams_div"><table id="show_teams_table">
- <td>
- <form action="" method="post" name="frm_actions">
- <input type="hidden" name="action" value="add_team" />
- <input type="submit" value="Add Team" />
- </form>
- </td>
- <td>
- <form action="" method="post" name="frm_actions" id="frm_removeAll" onsubmit="return removeCheck()">
- <input type="hidden" name="action" value="remove_all_teams" />
- <input type="submit" value="Remove all" />
- </form>
- </td>
- <tr>
- <th>rank</th>
- <th>Team ID</th>
- <th>Team Name</th>
- <th></th>
- <th></th>
- </tr>';
- $i = 1;
- foreach ( $result as $r ){
- echo '<tr>
- <td>' . $i . '</td>
- <td>' . $r->team_id . '</td>
- <td>' . $r->team_name . '</td>';
- if( current_user_can( 'manage_options' ) ) {
- echo '
- <td><form action="" method="post" name="frm_actions">
- <input type="hidden" name="action" value="edit_team" />
- <input type="hidden" name="id" value="' . $r->team_id . '" />
- <input type="submit" value="Edit" />
- </form></td>';
- echo '
- <td><form action="" method="post" name="frm_actions" onsubmit="return confirm(\'Are you sure you want to delete this team?\')">
- <input type="hidden" name="action" value="remove_team" />
- <input type="hidden" name="id" value="' . $r->team_id . '" />
- <input type="submit" value="Remove" />
- </form></td>';
- }
- echo '</tr>';
- $i++;
- }
- echo "</table>";
- //}else{
- //$_POST["action"]($_POST["id"]);
- //}
- echo "</div>";
- }
- function edit_team($id){
- global $wpdb;
- echo '<h2>Edit team with id '.$id.'</h2>';
- $result = $wpdb->get_results( "SELECT * FROM tbl_teams where team_id = '" . $id . "'");
- foreach ( $result as $r ){
- $team_name = $r->team_name;
- }
- ?>
- <form action="" method="post" name="frm_edit_team">
- <input type="hidden" name="action" value="save_team" />
- <input type="hidden" name="id" value="<?php echo $id;?>" />
- Team Name: <input type="text" name="team_name" value="<?php echo $team_name;?>" />
- <input type="submit" value="Save" />
- </form>
- <?php
- }
- function remove_team($id){
- global $wpdb;
- $sql= "DELETE FROM tbl_teams WHERE team_id='".$id."'";
- $wpdb->query($sql);
- echo 'Team Removed<br/>';
- echo '<script>window.location.href="?page=lol_competitions.php"</script>';
- }
- function remove_all_teams(){
- global $wpdb;
- $sql= "TRUNCATE TABLE tbl_teams";
- $wpdb->query($sql);
- echo 'Removed all teams!<br/>';
- echo '<script>window.location.href="?page=lol_competitions.php"</script>';
- }
- function add_team(){
- echo '<h2>Add team</h2>';
- ?>
- <form action="" method="post" name="frm_add_team">
- <input type="hidden" name="action" value="save_team" />
- Team Name: <input type="text" name="team_name" />
- <input type="submit" value="Add" />
- </form>
- <?php
- }
- function check_team_exists($team_name){
- global $wpdb;
- $total = $wpdb->get_var("SELECT count(*) AS TOTAL FROM tbl_teams where team_name='" . $team_name . "'");
- return $total;
- }
- function save_team($id){
- global $wpdb;
- $execute = "false";
- if($id != ""){
- //team bijwerken
- if(check_team_exists($_POST["team_name"]) != 1){
- $sql = "UPDATE tbl_teams SET team_name='" . $_POST["team_name"] . "' WHERE team_id='" . $id . "' ";
- $execute = "true";
- }else{
- $execute = "false";
- }
- }else{
- //team toevoegen
- if(check_team_exists($_POST["team_name"]) != 1){
- $sql = "INSERT INTO tbl_teams (team_name) VALUES ('" . $_POST["team_name"] . "')";
- $execute = "true";
- }else{
- $execute = "false";
- }
- }
- if($execute == "true"){
- $wpdb->query($sql);
- echo 'Team saved<br/>';
- echo '<script>window.location.href="?page=lol_competitions.php"</script>';
- }else{
- echo 'Team already exists';
- add_team();
- }
- }
- //global $wpdb;
- //$query = "SELECT * FROM tbl_teams";
- //$wpdb->query($query);
- //echo "No clue why I'm here tho...hbkkjlk";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement