/admin_league.php
PHP | 308 lines | 181 code | 62 blank | 65 comment | 31 complexity | 5bf4bb0017f1d0b5c368cbbdf0e6101d MD5 | raw file
- <?php
- //*******************************************************
- //
- // File: admin_league.php
- // Author: Gavin Uttley
- // Date: 02-AUG-2004
- // Purpose: provide admin function league management
- //
- // Revisions: 02-AUG-2004 - Initial
- //
- //
- //
- //*******************************************************
-
- if(defined("__DEBUG__")) {
- print_r($_POST);
- }
-
- include("fixtures.inc.php");
- include("db.php");
-
-
- $tid = $_REQUEST['tid'];
- $lid = $_REQUEST['lid'];
- $generate = $_REQUEST['generate'];
- $season_name = $_REQUEST['season_name'];
- $date_start = $_REQUEST['date_start'];
- $end_season = $_REQUEST['end_season'];
- $sid = $_REQUEST['sid'];
- $action = $_REQUEST['action'];
- $reset = $_REQUEST['reset'];
- $approve = $_REQUEST['approve'];
-
-
- if((isset($_REQUEST['lid'])) & (isset($_REQUEST['generate'])) & ( isset($_REQUEST['season_name']) ) ) {
- generate_league($lid, $date_start, $season_name);
- }
-
-
- if(isset($_REQUEST['end_season'])) {
- //
- // update the season id
- //
- //$db->sql_query("update leagues set season_id=0 where league_id=$lid");
- //
- // Update the stadium upgrades
- //
- $sql = "select * from teams where league_id=$lid";
- $teams = $db->sql_query($sql);
- while($team = $db->sql_fetchrow($teams)) {
- $sql = "update stadiums set upgrade_type=0, train_upgrade=0 where team_id = " . $team["team_id"];
- $db->sql_query($sql) or die($db->sql_error());
- }
-
- //
- // Set the ended flag
- //
- $sql = "update seasons set season_ended=1 where season_id=$sid";
- $db->sql_query($sql) or die($db->sql_error());
- //
- // secondly lets clear any goals/points for teams in this league
- //
- $sql = "update teams set league_goals_against=0, league_goals_for=0, league_points=0 where league_id=$lid";
- $db->sql_query($sql) or die($db->sql_error());
-
-
-
- }
-
- if(isset($_REQUEST['reset'])) {
- //
- // firstly remove any fixtures for this league
- //
- $sql = "Delete from fixtures where league_id=$reset and season_id=$sid";
- $db->sql_query($sql) or die($db->sql_error());
- //
- // set the current leagues season = 0
- //
- //$sql = "update leagues set season_id=0 where league_id=$lid";
- //$db->sql_query($sql) or die($db->sql_error());
- //
- // remove the season from the db
- //
- $sql = "delete from seasons where season_id=$lid";
- $db->sql_query($sql) or die($db->sql_error());
-
- $sql = "update teams set league_goals_against=0, league_goals_for=0, league_points=0 where league_id=$lid";
- $db->sql_query($sql) or die($db->sql_error());
- }
-
- if(isset($_REQUEST['approve'])) {
- //
- // Set team is_enabled=false
- //
- $sql = "update teams set is_enabled=0 where league_id=$approve";
- $db->sql_query($sql) or die($db->sql_error());
- }
-
- if(isset($_REQUEST['action'])) {
- //
- // add team to league
- //
- if($action == "add") {
- $sql = "Update teams set league_id=$lid where team_id=$tid";
- $db->sql_query($sql) or die($db->sql_error());
-
- //header("Location: index.php?page=admin_league&lid=$lid");
- }
- //
- // remove team form league
- //
- if($action == "remove") {
- $sql = "Update teams set league_id=0 where team_id=$tid";
- $db->sql_query($sql) or die($db->sql_error());
-
- //header("Location: index.php?page=admin_league&lid=$lid");
- }
- }
-
-
- $league = $db->sql_singlerow("select * from leagues where league_id=$lid");
- $seasons = $db->sql_query("select * from seasons where league_id=" . $league['league_id']);
- $season = $db->sql_fetchrow($seasons);
-
- //*******************************************************
- // list previous seasons
- //
- $sql = "select * from seasons where league_id=$lid and season_ended=1 order by season_id";
- $seasons = $db->sql_query($sql) or die($db->sql_error());
-
- table_open("30%");
- table_row_open();
- table_header("Completed Seasons", "center", 1);
- table_row_close();
-
- while ($old_season = $db->sql_fetchrow($seasons)) {
- table_row_open();
- table_data("<a href=\"index.php?page=view_season&sid=". $old_season['season_id'] ."\">" . $old_season['season_name'] . "</a>", "center");
- table_row_close();
- }
- table_close();
- $db->sql_freeresult($seasons);
-
- //*******************************************************
- // list teams in the league
- //
- $sql = "Select * from teams where team_id<>0 and league_id=$lid";
- $teams = $db->sql_query($sql) or die($db->sql_error());
-
- table_open("30%");
- table_row_open();
- table_header("Assigned Teams", "center", 2);
- table_row_close();
-
- $team_idx=0;
-
- while ($team = $db->sql_fetchrow($teams)) {
- table_row_open();
- table_data("<a href=\"index.php?page=admin_userview&tid=". $team['team_id'] ."\">" . $team['team_name'] . "</a>", "center");
- table_data("<a href=\"index.php?page=admin_league&action=remove&lid=$lid&tid=". $team['team_id'] ."\">Remove</a>" , "center");
- table_row_close();
-
- $team_idx++;
- }
- table_close();
- $db->sql_freeresult($teams);
-
-
- table_open("30%");
- table_row_open();
- table_header("Friendlies", "center", 2);
- table_row_close();
-
- table_row_open();
- table_data("<a href=\"index.php?page=admin_friendlies&lid=$lid\">create friendly match</a>");
- table_data(" ");
- table_row_close();
- table_close();
- //*******************************************************
- // now we can list all fixtures that have been generated
- //
-
- table_open("75%");
-
- //
- // check to see if season ended
- //
-
-
- $seasons = $db->sql_query("select * from seasons where league_id=" . $league['league_id']);
-
- $ended = $season['season_ended'] || ($db->sql_numrows($seasons) == 0);
-
- if($ended) {
- $form="<form name=\"fixture_add_$league_id\" method=\"post\" >League start date (must be a saturday) in YYYY-MM-DD format:
- <input type=\"textbox\" name=\"date_start\"><br>
- Season name: <input type=\"textbox\" name=\"season_name\"><br>
- <input type=\"hidden\" name=\"lid\" value=\"".$league['league_id']."\">
- <input type=\"hidden\" name=\"generate\" value=\"1\">
- <input type=\"submit\" value=\"Generate fixtures\"></form>";
- } else {
- $form = '';
- }
-
- $sql = "SELECT MAX(season_id) as season_id FROM seasons WHERE league_id = '" . $league['league_id'] . "' AND season_ended != 1";
- $season = $db->sql_singlerow($sql);
-
- if ($season['season_id']) {
-
- $reset_tag = "";
- $sql = "select * from fixtures where league_id=". $league['league_id'] . " and season_id=". $season['season_id'];
- $res = $db->sql_query($sql);
-
- if($db->sql_numrows($res) == 0) {
- if(!$ended) {
- $reset_tag = " <a href=\"index.php?page=admin_league&sid=".$season['season_id']."&reset=1&lid=". $league['league_id'] ." \">Reset matches</a>";
- } else {
- $reset_tag = '';
- }
- } else {
- if(!$ended) {
- $reset_tag = " <a href=\"index.php?page=admin_league&sid=".$season['season_id']."&end_season=1&lid=". $league['league_id'] ." \">End Season</a>";
- } else {
- $reset_tag = '';
- }
- }
- }
-
-
- table_row_open();
- table_header("Fixture List for league: " . $league['league_name'] . " season: " . $season['season_name'] . "$reset_tag", "center", 6);
- table_row_close();
- table_row_open();
- table_header($form, "right", 6);
- table_row_close();
-
- table_row_open();
- table_header("Fixture ID", "left");
- table_header("Home team", "center");
- table_header("Away team", "center");
- table_header("Venue", "center");
- table_header("Fixture date", "center");
- table_header("Result", "center");
- table_row_close();
-
- //
- // enumerate the fixtures table
- //
-
-
- if ($season['season_id']) {
- $sql = "select * from fixtures where season_id=" . $season['season_id'] . " order by fixture_date";
- $fixtures = $db->sql_query($sql);
-
- while($fixture = $db->sql_fetchrow($fixtures)) {
- table_row_open();
-
- table_data($fixture['fixture_id'], "left");
- table_data(team_name($fixture['team_id_home']), "center");
- table_data(team_name($fixture['team_id_away']), "center");
- table_data(stadium_name($fixture['team_id_home']), "center");
- table_data($fixture['fixture_date'], "center");
-
- if(fixtureHasPlayed($fixture['fixture_id'])) {
- $result = '';
- } else {
- $result = $fixture['goals_home'] . " - " . $fixture['goals_away'];
- }
-
- table_data($result, "center");
-
- table_row_close();
- }
- table_row_open();
- table_data(" ", "center", 4);
- table_row_close();
-
- table_close();
- }
-
- //*******************************************************
- // list unassigned teams with a list box of leagues
- //
-
-
- if($ended) {
-
- $sql = 'Select * from teams where team_id<>0 and league_id=0';
- $teams = $db->sql_query($sql) or die($db->sql_error());
-
- table_open("30%");
- table_row_open();
- table_header("Unassigned Teams", "center", 2);
- table_row_close();
-
- $team_idx=0;
-
- while ($team = $db->sql_fetchrow($teams)) {
- table_row_open();
- table_data("<a href=\"index.php?page=admin_userview&tid=". $team['team_id'] ."\">" . $team['team_name'] . "</a>", "center");
- table_data("<a href=\"index.php?page=admin_league&action=add&lid=$lid&tid=". $team['team_id'] ."\">Add</a>" , "center");
- }
- table_close();
-
- $db->sql_freeresult($teams);
- }
-
- ?>