PageRenderTime 38ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/leaguetable.php

https://bitbucket.org/DarkMantis/pfb
PHP | 282 lines | 210 code | 65 blank | 7 comment | 28 complexity | 9438c3abcff459d1baa7d89b3d0fc6ec MD5 | raw file
  1. <?php
  2. global $db;
  3. if($_POST['lid']) {
  4. $lid = $_POST['lid'];
  5. }
  6. else {
  7. $team = new Team2();
  8. $team->load($_COOKIE['team_id']);
  9. $lid = $team->league_id;
  10. }
  11. if($lid == '') {
  12. $league_name = $_COOKIE['league_name'];
  13. $lid = $_COOKIE['league_id'];
  14. $season_id = $_COOKIE['season_id'];
  15. }
  16. if($lid != '' && $lid != 0) {
  17. $sql = "Select * from leagues where league_id=$lid";
  18. $league = $db->sql_singlerow($sql) or die($db->sql_error());
  19. $league_name = $league['league_name'];
  20. $league_id = $lid;
  21. $sql = "SELECT *
  22. FROM seasons
  23. WHERE league_id= $lid
  24. ORDER BY season_id DESC
  25. LIMIT 1";
  26. $season = $db->sql_singlerow($sql) or die($db->sql_error());
  27. $season_id = $season['season_id'];
  28. }
  29. else {
  30. echo "You are not yet been allocated to aleague. Please try again soon";
  31. }
  32. if($season_id == 0 && $lid != 0) {
  33. die("<br><br><center>No Current Season</center>");
  34. }
  35. if($season_id) {
  36. $season = $db->sql_singlerow("select * from seasons where season_id=$season_id");
  37. table_open("75%");
  38. table_row_open();
  39. table_header($league_name . " - " . $season['season_name'], "center", 10);
  40. table_row_close();
  41. table_row_open();
  42. table_header("Position", "center");
  43. table_header("Team", "center");
  44. table_header("Played", "center");
  45. table_header("Won", "center");
  46. table_header("Drawn", "center");
  47. table_header("Lost", "center");
  48. table_header("Goals For", "center");
  49. table_header("Goals Against", "center");
  50. table_header("Difference", "center");
  51. table_header("Points", "center");
  52. table_row_close();
  53. if(!isset($_COOKIE['league_id'])) {
  54. die();
  55. }
  56. $sql = "Select team_id, team_name, league_goals_for, league_goals_against, league_points ";
  57. $sql .= "from teams where league_id=$league_id ";
  58. $sql .= "order by league_points desc, (league_goals_for - league_goals_against) desc, league_goals_for desc, team_name";
  59. $teams = $db->sql_query($sql) or die($db->sql_error());
  60. $row=0;
  61. while ($team = $db->sql_fetchrow($teams)) {
  62. //$row+= 1;
  63. $sql = "Select Count(*) as cnt from fixtures where (team_id_home=". $team["team_id"] ." or team_id_away=". $team['team_id'] .") and league_id=$league_id and season_id=$season_id and attendance>0";
  64. $played = $db->sql_singlerow($sql);
  65. table_row_open();
  66. $sql = "Select count(*) as cnt_home from fixtures where (goals_home > goals_away) and team_id_home=". $team["team_id"] . " and league_id=$league_id and season_id=$season_id and attendance>0";
  67. $home = $db->sql_singlerow($sql);
  68. $home_won = $home['cnt_home'];
  69. $sql = "Select count(*) as cnt_away from fixtures where (goals_away > goals_home) and team_id_away=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
  70. $away = $db->sql_singlerow($sql);
  71. $away_won = $away['cnt_away'];
  72. $sql = "Select count(*) as cnt_home from fixtures where (goals_home < goals_away) and team_id_home=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
  73. $home = $db->sql_singlerow($sql);
  74. $home_lost = $home['cnt_home'];
  75. $sql = "Select count(*) as cnt_away from fixtures where (goals_away < goals_home) and team_id_away=". $team["team_id"]. " and league_id=$league_id and season_id=$season_id and attendance>0";
  76. $away = $db->sql_singlerow($sql);
  77. $away_lost = $away['cnt_away'];
  78. $sql = "Select count(*) as cnt from fixtures where (goals_away = goals_home) and (team_id_away=". $team["team_id"] . " or team_id_home=". $team["team_id"] . ") and league_id=$league_id and season_id=$season_id and attendance>0";
  79. $draw = $db->sql_singlerow($sql);
  80. $drawn = $draw['cnt'];
  81. table_data($row, "center");
  82. $url="<a href=\"index.php?page=teamview&tid=". $team['team_id'] ."\">". $team['team_name'] ."</a>";
  83. table_data($url, "center");
  84. table_data($played['cnt'], "center");
  85. table_data($home_won + $away_won, "center");
  86. table_data($drawn, "center");
  87. table_data($home_lost + $away_lost, "center");
  88. table_data($team['league_goals_for'], "center");
  89. table_data($team['league_goals_against'], "center");
  90. table_data($team['league_goals_for'] - $team['league_goals_against'], "center");
  91. table_data($team['league_points'], "center");
  92. table_row_close();
  93. }
  94. table_close();
  95. echo "<br><br>";
  96. if(isset($_COOKIE['season_id'])) {
  97. //*******************************
  98. // league stats
  99. //
  100. table_open("75%");
  101. table_row_open();
  102. table_header("League Statistics", "center", 12);
  103. table_row_close();
  104. table_row_open();
  105. table_header("Top Scorers", "center", 2);
  106. table_header("Passes Completed %", "center", 2);
  107. table_header("Interceptions Completed %", "center", 2);
  108. table_header("Dribbles Completed % ", "center", 2);
  109. table_header("Tackles Completed % ", "center", 2);
  110. table_row_close();
  111. $scorers_sql = "select player_name, p.player_id, count(goal_id) as goals from players p ";
  112. $scorers_sql .= "inner join history_goals h on h.player_id = p.player_id ";
  113. $scorers_sql .= "inner join fixtures f on f.fixture_id = h.fixture_id ";
  114. $scorers_sql .= "where f.season_id=$season_id group by h.player_id ";
  115. $scorers_sql .= "order by goals desc, p.player_name asc ";
  116. $scorers = $db->sql_query($scorers_sql);
  117. $passers_sql = "select player_id, player_name, ((";
  118. $passers_sql .= "(select count(*) from history_passes, fixtures ";
  119. $passers_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
  120. $passers_sql .= "and history_passes.player_id = players.player_id ";
  121. $passers_sql .= "and pass_completed=1 and season_id=$season_id) / ";
  122. $passers_sql .= "(select count(*) from history_passes, fixtures ";
  123. $passers_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
  124. $passers_sql .= "and history_passes.player_id = players.player_id and season_id=$season_id) ) * 100) as pert ";
  125. $passers_sql .= "from players order by pert desc ";
  126. $passers = $db->sql_query($passers_sql);
  127. $intercept_sql = "select player_id, player_name, ((";
  128. $intercept_sql .= "(select count(*) from history_passes, fixtures ";
  129. $intercept_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
  130. $intercept_sql .= "and history_passes.opponent_id = players.player_id ";
  131. $intercept_sql .= "and pass_completed=0 and season_id=$season_id) / ";
  132. $intercept_sql .= "(select count(*) from history_passes, fixtures ";
  133. $intercept_sql .= "where fixtures.fixture_id = history_passes.fixture_id ";
  134. $intercept_sql .= "and history_passes.opponent_id = players.player_id and season_id=$season_id)) * 100) as pert ";
  135. $intercept_sql .= "from players order by pert desc ";
  136. $intercepters = $db->sql_query($intercept_sql);
  137. $tacklers_sql = "select player_id, player_name, ((";
  138. $tacklers_sql .= "(select count(*) from history_tackles, fixtures ";
  139. $tacklers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
  140. $tacklers_sql .= "and history_tackles.player_id = players.player_id ";
  141. $tacklers_sql .= "and successful=1 and season_id=$season_id) / ";
  142. $tacklers_sql .= "(select count(*) from history_tackles, fixtures ";
  143. $tacklers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
  144. $tacklers_sql .= "and history_tackles.player_id = players.player_id and season_id=$season_id)) * 100) as pert ";
  145. $tacklers_sql .= "from players order by pert desc";
  146. $tacklers = $db->sql_query($tacklers_sql);
  147. $dribblers_sql = "select player_id, player_name, ((";
  148. $dribblers_sql .= "(select count(*) from history_tackles, fixtures ";
  149. $dribblers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
  150. $dribblers_sql .= "and history_tackles.tackled_player_id = players.player_id ";
  151. $dribblers_sql .= "and successful=0 and season_id=$season_id) / ";
  152. $dribblers_sql .= "(select count(*) from history_tackles, fixtures ";
  153. $dribblers_sql .= "where fixtures.fixture_id = history_tackles.fixture_id ";
  154. $dribblers_sql .= "and history_tackles.tackled_player_id = players.player_id and season_id=$season_id)) * 100) as pert ";
  155. $dribblers_sql .= "from players order by pert desc";
  156. $dribblers = $db->sql_query($dribblers_sql);
  157. for($i=0; $i < 10; $i++) {
  158. $scorer = $db->sql_fetchrow($scorers);
  159. $passer = $db->sql_fetchrow($passers);
  160. while(($passer['pert'] > 95) | ($passer['pert'] == '')) {
  161. if(!$passer = $db->sql_fetchrow($passers)) {
  162. break;
  163. }
  164. }
  165. $intercepter = $db->sql_fetchrow($intercepters);
  166. while(($intercepter['pert'] > 95) | ($intercepter['pert'] == '')) {
  167. if(!$intercepter = $db->sql_fetchrow($intercepters)) {
  168. break;
  169. }
  170. }
  171. $tackler = $db->sql_fetchrow($tacklers);
  172. while(($tackler['pert'] > 95) | ($tackler['pert'] == '')) {
  173. if(!$tackler = $db->sql_fetchrow($tacklers)) {
  174. break;
  175. }
  176. }
  177. $dribbler = $db->sql_fetchrow($dribblers);
  178. while(($dribbler['pert'] > 95) | ($dribbler['pert'] == '')) {
  179. if(!$dribbler = $db->sql_fetchrow($dribblers)) {
  180. break;
  181. }
  182. }
  183. table_row_open();
  184. table_data("<a href='index.php?page=player&player_id=". $scorer['player_id'] ."'>" . $scorer['player_name'] . "</a>", "left");
  185. table_data($scorer['goals'], "center");
  186. table_data("<a href='index.php?page=player&player_id=". $passer['player_id'] ."'>" . $passer['player_name'] . "</a>", "left");
  187. table_data($passer['pert'], "center");
  188. table_data("<a href='index.php?page=player&player_id=". $intercepter['player_id'] ."'>" . $intercepter['player_name'] . "</a>", "left");
  189. table_data($intercepter['pert'], "center");
  190. table_data("<a href='index.php?page=player&player_id=". $dribbler['player_id'] ."'>" . $dribbler['player_name'] . "</a>", "left");
  191. table_data($dribbler['pert'], "center");
  192. table_data("<a href='index.php?page=player&player_id=". $tackler['player_id'] ."'>" . $tackler['player_name'] . "</a>", "left");
  193. table_data($tackler['pert'], "center");
  194. table_row_close();
  195. }
  196. table_close();
  197. echo "<br><br>";
  198. }
  199. //*******************************
  200. // link to other leagues
  201. //
  202. $sql = "Select * from leagues where league_id<> $league_id";
  203. $leagues = $db->sql_query($sql) or die($db->sql_error());
  204. if($db->sql_numrows($sql)){
  205. table_open("75%");
  206. table_row_open();
  207. table_header("Other Leagues", "center", 10);
  208. table_row_close();
  209. while ($league = $db->sql_fetchrow($leagues)) {
  210. table_row_open();
  211. table_data("<a href='index.php?page=leaguetable&lid=". $league['league_id'] ."'>".$league['league_name']."</a>", "center");
  212. table_row_close();
  213. }
  214. table_close();
  215. }
  216. }
  217. ?>