/source/viewFixtures.php

https://github.com/andyjdbest/Tennis-Masters---PBBG · PHP · 189 lines · 145 code · 29 blank · 15 comment · 28 complexity · 9a05de1ea630ea59d95f86f94418e95a MD5 · raw file

  1. <?php
  2. require_once 'common.php';
  3. require_once 'DBconfig.php';
  4. function checkTacticSet($tacticData,$fixID,$academyID){
  5. //print_r($tacticData);
  6. if (isset($tacticData[0][0])){
  7. foreach($tacticData as $ts) {
  8. //echo "$ts[0] = $academyID, $fixID = $ts[1]";
  9. if ($fixID == $ts[0] && $ts[1] == $academyID) {
  10. return 1;
  11. }
  12. }
  13. }
  14. return 0;
  15. }
  16. session_start();
  17. if (@$_SESSION['authenticated'] == 'true' & @$_SESSION['assigned'] == 1) {
  18. if ($_GET['academy'])
  19. {
  20. $academy = $_GET['academy'];
  21. if (ctype_digit($academy) === FALSE)
  22. {
  23. $error = 'Invalid inputs';
  24. }
  25. else {
  26. $upcomingData = array();
  27. $completedData = array();
  28. $userid = $_SESSION['userid'];
  29. $team = $_SESSION['id_team'];
  30. //fetch the fixtures data
  31. $query = "SELECT f.id_fixture, f.round_date, ft.name_fixture, CONCAT( t1.team_name, ' v ', t2.team_name ) AS fixture ,
  32. c.name AS court, f.id_winner
  33. FROM `fixtures` AS f
  34. JOIN fixture_type AS ft ON ft.id_fixture = f.fixture_type
  35. JOIN academy AS t1 ON t1.id_team = f.id_team1
  36. JOIN academy AS t2 ON t2.id_team = f.id_team2
  37. JOIN courttype AS c ON f.id_stadium = c.idcourttype
  38. WHERE (f.id_team1 = '$academy' OR f.id_team2 = '$academy') AND f.fixture_type < 3 AND f.season = '$season'
  39. GROUP BY f.id_fixture ORDER BY f.round_date";
  40. $r = mysql_query($query);
  41. while ($ob = mysql_fetch_array($r)) {
  42. $fixturedata[] = $ob;
  43. }
  44. //check if fixture is completed by checking id_winner
  45. if (isset($fixturedata[0][0])){
  46. foreach($fixturedata as $fixture) {
  47. if ($fixture[5] > 0) {
  48. $completedData[] = $fixture;
  49. }
  50. else {
  51. $upcomingData[] = $fixture;
  52. }
  53. }
  54. }
  55. $query = "SELECT m.id_fixture, m.id_team FROM match_order AS m JOIN fixtures AS f ON f.id_fixture = m.id_fixture
  56. WHERE (f.id_team1 = '$academy' OR f.id_team2 = '$academy') AND f.fixture_type < 3 AND f.season = '$season'
  57. ORDER BY f.round_date";
  58. $r = mysql_query($query);
  59. while ($row = mysql_fetch_array($r)) {
  60. $tacticdata[] = $row;
  61. }
  62. foreach($upcomingData as $up) {
  63. if (checkTacticSet($tacticdata,$up[0],$academy) == 1) {
  64. $tacticSet[] = 1;
  65. }
  66. else {
  67. $tacticSet[] = 0;
  68. }
  69. }
  70. //print_r($tacticSet);
  71. //fetch required players ids:
  72. $query = "SELECT idplayer FROM players WHERE id_team = $team";
  73. $r = mysql_query($query);
  74. while ($ob = mysql_fetch_array($r)) {
  75. $playerids[] = $ob[0];
  76. }
  77. //for player fixtures:
  78. $query = mysql_query("SELECT f.round_date, ft.name_fixture, m.id_match,
  79. CONCAT( p1.firstname, ' ', p1.lastname, ' v ', p2.firstname, ' ', p2.lastname ) AS game, c.name AS court, m.id_player1, m.id_player2,
  80. CONCAT( p1.firstname, ' ', p1.lastname) AS p1Name, CONCAT( p2.firstname, ' ', p2.lastname) AS p2name, m.id_winner, f.round
  81. FROM `matches` AS m
  82. JOIN fixtures AS f ON f.id_fixture = m.id_fixture
  83. JOIN fixture_type AS ft ON ft.id_fixture = f.fixture_type
  84. JOIN players AS p1 ON p1.idplayer = m.id_player1
  85. JOIN players AS p2 ON p2.idplayer = m.id_player2
  86. JOIN courttype AS c ON m.id_court = c.idcourttype
  87. WHERE (p1.id_team ='$academy' OR p2.id_team ='$academy') AND f.fixture_type > 3 AND f.season = '$season'");
  88. while ($arr = mysql_fetch_array($query)) {
  89. $tfixturedata[] = $arr;
  90. }
  91. if (isset($tfixturedata[0][0])){
  92. //$pfixturedata = $tfixturedata;
  93. //$index = 0;
  94. foreach($tfixturedata as $pf){
  95. //completed player fixtures
  96. if ($pf['id_winner'] > 0){
  97. $cPlayers[] = $pf;
  98. }
  99. else {
  100. $upPlayers[]= $pf;
  101. }
  102. }
  103. }
  104. //process upcoming player fixtures...
  105. if (isset($upPlayers[0][0])){
  106. $pfixturedata = $upPlayers;
  107. $index = 0;
  108. foreach($upPlayers as $pf){
  109. //if both players in the match belong to the academy
  110. if (in_array($pf['id_player1'],$playerids) && in_array($pf['id_player2'],$playerids)){
  111. $pfixturedata[$index]['playerID1'] = $pf['id_player1'];
  112. $pfixturedata[$index]['playerName1'] = $pf[7];
  113. $temp = $pf;
  114. $temp['playerID2'] = $pf['id_player2'];
  115. $temp['playerName2'] = $pf['p2name'];
  116. $pfixturedata[] = $temp;
  117. }
  118. elseif (in_array($pf['id_player1'],$playerids)) {
  119. $pfixturedata[$index]['playerID1'] = $pf['id_player1'];
  120. $pfixturedata[$index]['playerName1'] = $pf[7];
  121. }
  122. elseif (in_array($pf['id_player2'],$playerids)) {
  123. $pfixturedata[$index]['playerID2'] = $pf['id_player2'];
  124. $pfixturedata[$index]['playerName2'] = $pf['p2name'];
  125. }
  126. //print_r($pfixturedata);
  127. $index += 1;
  128. }
  129. }
  130. //print_r($pfixturedata);
  131. //for time
  132. $day = floor((mktime() - $season_start)/86400);
  133. $smarty->assign('season',$season);
  134. $smarty->assign('day',$day);
  135. $q = "SELECT COUNT(id) FROM `messages` WHERE id_receiver = {$_SESSION['userid']} AND `read` = 0 AND del_receiver = 0";
  136. $r = mysql_query($q);
  137. $rf = mysql_fetch_row($r);
  138. $_SESSION['new_mail'] = $rf[0];
  139. }
  140. $smarty->assign('idteam',$_SESSION['id_team']);
  141. $smarty->assign('idleague',$_SESSION['id_league']);
  142. $smarty->assign('uname',$_SESSION['username']);
  143. $smarty->assign('userid',$_SESSION['userid']);
  144. $smarty->assign('new_mail',$_SESSION['new_mail']);
  145. $smarty->assign('cManager',$_SESSION['countryM']);
  146. $smarty->assign('member',$_SESSION['member']);
  147. $smarty->assign('credits',$_SESSION['credits']);
  148. $smarty->assign('upcoming',$upcomingData);
  149. $smarty->assign('completed',$completedData);
  150. $smarty->assign('cPlayers',$cPlayers);
  151. $smarty->assign('uPlayers',$pfixturedata);
  152. $smarty->assign('ts',$tacticSet);
  153. $smarty->assign('id_team',stripHTML($academy));
  154. $smarty->display('viewFixtures.tpl');
  155. }
  156. }
  157. else {
  158. header("Location:index.php");
  159. }
  160. ?>