PageRenderTime 157ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/admin_league.php

https://bitbucket.org/DarkMantis/pfb
PHP | 308 lines | 181 code | 62 blank | 65 comment | 31 complexity | 5bf4bb0017f1d0b5c368cbbdf0e6101d MD5 | raw file
  1. <?php
  2. //*******************************************************
  3. //
  4. // File: admin_league.php
  5. // Author: Gavin Uttley
  6. // Date: 02-AUG-2004
  7. // Purpose: provide admin function league management
  8. //
  9. // Revisions: 02-AUG-2004 - Initial
  10. //
  11. //
  12. //
  13. //*******************************************************
  14. if(defined("__DEBUG__")) {
  15. print_r($_POST);
  16. }
  17. include("fixtures.inc.php");
  18. include("db.php");
  19. $tid = $_REQUEST['tid'];
  20. $lid = $_REQUEST['lid'];
  21. $generate = $_REQUEST['generate'];
  22. $season_name = $_REQUEST['season_name'];
  23. $date_start = $_REQUEST['date_start'];
  24. $end_season = $_REQUEST['end_season'];
  25. $sid = $_REQUEST['sid'];
  26. $action = $_REQUEST['action'];
  27. $reset = $_REQUEST['reset'];
  28. $approve = $_REQUEST['approve'];
  29. if((isset($_REQUEST['lid'])) & (isset($_REQUEST['generate'])) & ( isset($_REQUEST['season_name']) ) ) {
  30. generate_league($lid, $date_start, $season_name);
  31. }
  32. if(isset($_REQUEST['end_season'])) {
  33. //
  34. // update the season id
  35. //
  36. //$db->sql_query("update leagues set season_id=0 where league_id=$lid");
  37. //
  38. // Update the stadium upgrades
  39. //
  40. $sql = "select * from teams where league_id=$lid";
  41. $teams = $db->sql_query($sql);
  42. while($team = $db->sql_fetchrow($teams)) {
  43. $sql = "update stadiums set upgrade_type=0, train_upgrade=0 where team_id = " . $team["team_id"];
  44. $db->sql_query($sql) or die($db->sql_error());
  45. }
  46. //
  47. // Set the ended flag
  48. //
  49. $sql = "update seasons set season_ended=1 where season_id=$sid";
  50. $db->sql_query($sql) or die($db->sql_error());
  51. //
  52. // secondly lets clear any goals/points for teams in this league
  53. //
  54. $sql = "update teams set league_goals_against=0, league_goals_for=0, league_points=0 where league_id=$lid";
  55. $db->sql_query($sql) or die($db->sql_error());
  56. }
  57. if(isset($_REQUEST['reset'])) {
  58. //
  59. // firstly remove any fixtures for this league
  60. //
  61. $sql = "Delete from fixtures where league_id=$reset and season_id=$sid";
  62. $db->sql_query($sql) or die($db->sql_error());
  63. //
  64. // set the current leagues season = 0
  65. //
  66. //$sql = "update leagues set season_id=0 where league_id=$lid";
  67. //$db->sql_query($sql) or die($db->sql_error());
  68. //
  69. // remove the season from the db
  70. //
  71. $sql = "delete from seasons where season_id=$lid";
  72. $db->sql_query($sql) or die($db->sql_error());
  73. $sql = "update teams set league_goals_against=0, league_goals_for=0, league_points=0 where league_id=$lid";
  74. $db->sql_query($sql) or die($db->sql_error());
  75. }
  76. if(isset($_REQUEST['approve'])) {
  77. //
  78. // Set team is_enabled=false
  79. //
  80. $sql = "update teams set is_enabled=0 where league_id=$approve";
  81. $db->sql_query($sql) or die($db->sql_error());
  82. }
  83. if(isset($_REQUEST['action'])) {
  84. //
  85. // add team to league
  86. //
  87. if($action == "add") {
  88. $sql = "Update teams set league_id=$lid where team_id=$tid";
  89. $db->sql_query($sql) or die($db->sql_error());
  90. //header("Location: index.php?page=admin_league&lid=$lid");
  91. }
  92. //
  93. // remove team form league
  94. //
  95. if($action == "remove") {
  96. $sql = "Update teams set league_id=0 where team_id=$tid";
  97. $db->sql_query($sql) or die($db->sql_error());
  98. //header("Location: index.php?page=admin_league&lid=$lid");
  99. }
  100. }
  101. $league = $db->sql_singlerow("select * from leagues where league_id=$lid");
  102. $seasons = $db->sql_query("select * from seasons where league_id=" . $league['league_id']);
  103. $season = $db->sql_fetchrow($seasons);
  104. //*******************************************************
  105. // list previous seasons
  106. //
  107. $sql = "select * from seasons where league_id=$lid and season_ended=1 order by season_id";
  108. $seasons = $db->sql_query($sql) or die($db->sql_error());
  109. table_open("30%");
  110. table_row_open();
  111. table_header("Completed Seasons", "center", 1);
  112. table_row_close();
  113. while ($old_season = $db->sql_fetchrow($seasons)) {
  114. table_row_open();
  115. table_data("<a href=\"index.php?page=view_season&sid=". $old_season['season_id'] ."\">" . $old_season['season_name'] . "</a>", "center");
  116. table_row_close();
  117. }
  118. table_close();
  119. $db->sql_freeresult($seasons);
  120. //*******************************************************
  121. // list teams in the league
  122. //
  123. $sql = "Select * from teams where team_id<>0 and league_id=$lid";
  124. $teams = $db->sql_query($sql) or die($db->sql_error());
  125. table_open("30%");
  126. table_row_open();
  127. table_header("Assigned Teams", "center", 2);
  128. table_row_close();
  129. $team_idx=0;
  130. while ($team = $db->sql_fetchrow($teams)) {
  131. table_row_open();
  132. table_data("<a href=\"index.php?page=admin_userview&tid=". $team['team_id'] ."\">" . $team['team_name'] . "</a>", "center");
  133. table_data("<a href=\"index.php?page=admin_league&action=remove&lid=$lid&tid=". $team['team_id'] ."\">Remove</a>" , "center");
  134. table_row_close();
  135. $team_idx++;
  136. }
  137. table_close();
  138. $db->sql_freeresult($teams);
  139. table_open("30%");
  140. table_row_open();
  141. table_header("Friendlies", "center", 2);
  142. table_row_close();
  143. table_row_open();
  144. table_data("<a href=\"index.php?page=admin_friendlies&lid=$lid\">create friendly match</a>");
  145. table_data("&nbsp;");
  146. table_row_close();
  147. table_close();
  148. //*******************************************************
  149. // now we can list all fixtures that have been generated
  150. //
  151. table_open("75%");
  152. //
  153. // check to see if season ended
  154. //
  155. $seasons = $db->sql_query("select * from seasons where league_id=" . $league['league_id']);
  156. $ended = $season['season_ended'] || ($db->sql_numrows($seasons) == 0);
  157. if($ended) {
  158. $form="<form name=\"fixture_add_$league_id\" method=\"post\" >League start date (must be a saturday) in YYYY-MM-DD format:
  159. <input type=\"textbox\" name=\"date_start\"><br>
  160. Season name: <input type=\"textbox\" name=\"season_name\"><br>
  161. <input type=\"hidden\" name=\"lid\" value=\"".$league['league_id']."\">
  162. <input type=\"hidden\" name=\"generate\" value=\"1\">
  163. <input type=\"submit\" value=\"Generate fixtures\"></form>";
  164. } else {
  165. $form = '';
  166. }
  167. $sql = "SELECT MAX(season_id) as season_id FROM seasons WHERE league_id = '" . $league['league_id'] . "' AND season_ended != 1";
  168. $season = $db->sql_singlerow($sql);
  169. if ($season['season_id']) {
  170. $reset_tag = "";
  171. $sql = "select * from fixtures where league_id=". $league['league_id'] . " and season_id=". $season['season_id'];
  172. $res = $db->sql_query($sql);
  173. if($db->sql_numrows($res) == 0) {
  174. if(!$ended) {
  175. $reset_tag = "&nbsp;<a href=\"index.php?page=admin_league&sid=".$season['season_id']."&reset=1&lid=". $league['league_id'] ." \">Reset matches</a>";
  176. } else {
  177. $reset_tag = '';
  178. }
  179. } else {
  180. if(!$ended) {
  181. $reset_tag = "&nbsp;<a href=\"index.php?page=admin_league&sid=".$season['season_id']."&end_season=1&lid=". $league['league_id'] ." \">End Season</a>";
  182. } else {
  183. $reset_tag = '';
  184. }
  185. }
  186. }
  187. table_row_open();
  188. table_header("Fixture List for league: " . $league['league_name'] . " season: " . $season['season_name'] . "$reset_tag", "center", 6);
  189. table_row_close();
  190. table_row_open();
  191. table_header($form, "right", 6);
  192. table_row_close();
  193. table_row_open();
  194. table_header("Fixture ID", "left");
  195. table_header("Home team", "center");
  196. table_header("Away team", "center");
  197. table_header("Venue", "center");
  198. table_header("Fixture date", "center");
  199. table_header("Result", "center");
  200. table_row_close();
  201. //
  202. // enumerate the fixtures table
  203. //
  204. if ($season['season_id']) {
  205. $sql = "select * from fixtures where season_id=" . $season['season_id'] . " order by fixture_date";
  206. $fixtures = $db->sql_query($sql);
  207. while($fixture = $db->sql_fetchrow($fixtures)) {
  208. table_row_open();
  209. table_data($fixture['fixture_id'], "left");
  210. table_data(team_name($fixture['team_id_home']), "center");
  211. table_data(team_name($fixture['team_id_away']), "center");
  212. table_data(stadium_name($fixture['team_id_home']), "center");
  213. table_data($fixture['fixture_date'], "center");
  214. if(fixtureHasPlayed($fixture['fixture_id'])) {
  215. $result = '';
  216. } else {
  217. $result = $fixture['goals_home'] . " - " . $fixture['goals_away'];
  218. }
  219. table_data($result, "center");
  220. table_row_close();
  221. }
  222. table_row_open();
  223. table_data("&nbsp;", "center", 4);
  224. table_row_close();
  225. table_close();
  226. }
  227. //*******************************************************
  228. // list unassigned teams with a list box of leagues
  229. //
  230. if($ended) {
  231. $sql = 'Select * from teams where team_id<>0 and league_id=0';
  232. $teams = $db->sql_query($sql) or die($db->sql_error());
  233. table_open("30%");
  234. table_row_open();
  235. table_header("Unassigned Teams", "center", 2);
  236. table_row_close();
  237. $team_idx=0;
  238. while ($team = $db->sql_fetchrow($teams)) {
  239. table_row_open();
  240. table_data("<a href=\"index.php?page=admin_userview&tid=". $team['team_id'] ."\">" . $team['team_name'] . "</a>", "center");
  241. table_data("<a href=\"index.php?page=admin_league&action=add&lid=$lid&tid=". $team['team_id'] ."\">Add</a>" , "center");
  242. }
  243. table_close();
  244. $db->sql_freeresult($teams);
  245. }
  246. ?>