Server IP : 149.202.105.228 / Your IP : 216.73.216.18 Web Server : Apache System : Linux webm129.cluster030.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : atfycaf ( 116275) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/atfycaf/www/admin/ |
Upload File : |
<?php include "globalVars.php"; if (isset($_POST["dC"])) { $dateID = str_replace("fixtureDate", "", $_POST["dC"]); $newDate = $_POST["tD"]; list($matchDay, $matchMonth, $matchYear) = explode("/", $newDate); $newDate = $matchYear ."-". $matchMonth ."-". $matchDay; mysqli_query($conn, "UPDATE leagueResults SET fixtureDate = '$newDate' WHERE id = '$dateID'"); $fixtureTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE id = '$dateID'"); while ($fTQ = mysqli_fetch_array($fixtureTeamsQuery)) { $homeTeam = $fTQ["homeTeam"]; $awayTeam = $fTQ["awayTeam"]; } $trackDate = date("Y-m-d H:i:s"); $trackTitle = "$groupTitle $leagueStartDate"; mysqli_query($conn, "INSERT INTO userActions (dateCreated, adminID, pageTracking, databaseUpdated, updateDetails) VALUES ('$trackDate', '$adminID', 'admin/leagueEdit-2-playoffs-Data.php', 'leagueResults', 'The User ". addslashes($adminName) ." <$adminEmail> updated the date for fixture ID: $fixtureID (". $homeTeam ." vs ". $awayTeam .")')"); } elseif (isset($_POST["tV"])) { $matchID = $_POST["mID"]; $newVenue = $_POST["tV"]; mysqli_query($conn, "UPDATE leagueResults SET fixtureVenue = '$newVenue' WHERE id = '$matchID'"); } elseif (isset($_POST["rS"])) { $rinkScoreID = $_POST["rS"]; $thisScore = $_POST["tS"]; $homeAway = substr($rinkScoreID, 0, 4); $fixtureID = substr($rinkScoreID, 4); $mlIDQuery = mysqli_query($conn, "SELECT miniLeagueID FROM leagueResults WHERE id = '$fixtureID'"); while ($mIQ = mysqli_fetch_array($mlIDQuery)) { $miniLeagueID = $mIQ["miniLeagueID"]; } $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$miniLeagueID'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $maxRinkPtsQuery = mysqli_query($conn, "SELECT pointsRink FROM leagueConfig WHERE id = '$leagueID'"); while ($mRQ = mysqli_fetch_array($maxRinkPtsQuery)) { $maxScore = $mRQ["pointsRink"]; } if ($thisScore > $maxScore) { $thisScore = $maxScore; } if ($homeAway == "home") { $otherHomeAway = "away"; $otherInput = "away". $fixtureID; } else { $otherHomeAway = "home"; $otherInput = "home". $fixtureID; } $otherScore = $maxScore - $thisScore; mysqli_query($conn, "UPDATE leagueResults SET ". $homeAway ."RinkPts = '$thisScore', ". $otherHomeAway ."RinkPts = '$otherScore' WHERE id = '$fixtureID'"); $leagueQuery = mysqli_query($conn, "SELECT * FROM leagueConfig WHERE id = '$leagueID'"); while ($lQ = mysqli_fetch_array($leagueQuery)) { $leagueType = $lQ["leagueType"]; $lFullSDate = $lQ["startDate"]; $lStartMonth = date("F", strtotime($lFullSDate)); $lStartYear = date("Y", strtotime($lFullSDate)); $leagueStartDate = "$lStartMonth $lStartYear"; } $leagueIDQuery = mysqli_query($conn, "SELECT groupTitle FROM leagueGroups WHERE id = '$leagueType'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $groupTitle = $lIQ["groupTitle"]; } $fixtureTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE id = '$fixtureID'"); while ($fTQ = mysqli_fetch_array($fixtureTeamsQuery)) { $homeTeam = $fTQ["homeTeam"]; $awayTeam = $fTQ["awayTeam"]; } $trackDate = date("Y-m-d H:i:s"); $trackTitle = "$groupTitle $leagueStartDate"; mysqli_query($conn, "INSERT INTO userActions (dateCreated, adminID, pageTracking, databaseUpdated, updateDetails) VALUES ('$trackDate', '$adminID', 'admin/leagueEdit-2-playoffs-Data.php', 'leagueResults', 'The User ". addslashes($adminName) ." <$adminEmail> updated the Rink Points for fixture ID: $fixtureID (". $homeTeam ." vs ". $awayTeam .") in league ID: $leagueID (". addslashes($trackTitle) .")')"); $jsonArray = array("thisRScore" => $thisScore, "otherInput" => $otherInput, "otherRScore" => $otherScore); echo json_encode($jsonArray); } elseif (isset($_POST["sS"])) { $shotScoreID = $_POST["sS"]; $thisScore = $_POST["tS"]; //} elseif (isset($_GET["sS"])) { // $shotScoreID = $_GET["sS"]; // $thisScore = $_GET["tS"]; $homeAway = substr($shotScoreID, 0, 4); $fixtureID = substr($shotScoreID, 4); mysqli_query($conn, "UPDATE leagueResults SET ". $homeAway ."Score = '$thisScore' WHERE id = '$fixtureID'"); $mlIDQuery = mysqli_query($conn, "SELECT miniLeagueID FROM leagueResults WHERE id = '$fixtureID'"); while ($mIQ = mysqli_fetch_array($mlIDQuery)) { $miniLeagueID = $mIQ["miniLeagueID"]; } $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$miniLeagueID'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $leagueQuery = mysqli_query($conn, "SELECT * FROM leagueConfig WHERE id = '$leagueID'"); while ($lQ = mysqli_fetch_array($leagueQuery)) { $leagueType = $lQ["leagueType"]; $lFullSDate = $lQ["startDate"]; $lStartMonth = date("F", strtotime($lFullSDate)); $lStartYear = date("Y", strtotime($lFullSDate)); $leagueStartDate = "$lStartMonth $lStartYear"; } $leagueIDQuery = mysqli_query($conn, "SELECT groupTitle FROM leagueGroups WHERE id = '$leagueType'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $groupTitle = $lIQ["groupTitle"]; } $fixtureTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE id = '$fixtureID'"); while ($fTQ = mysqli_fetch_array($fixtureTeamsQuery)) { $homeTeam = $fTQ["homeTeam"]; $awayTeam = $fTQ["awayTeam"]; } $trackDate = date("Y-m-d H:i:s"); $trackTitle = "$groupTitle $leagueStartDate"; mysqli_query($conn, "INSERT INTO userActions (dateCreated, adminID, pageTracking, databaseUpdated, updateDetails) VALUES ('$trackDate', '$adminID', 'admin/leagueEdit-2-playoffs-Data.php', 'leagueResults', 'The User ". addslashes($adminName) ." <$adminEmail> updated the score for fixture ID: $fixtureID (". $homeTeam ." vs ". $awayTeam .") in league ID: $leagueID (". addslashes($trackTitle) .")')"); $matchCompleteQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE id = '$fixtureID'"); while ($mCQ = mysqli_fetch_array($matchCompleteQuery)) { $miniLeagueID = $mCQ["miniLeagueID"]; $weekID = $mCQ["weekID"]; $firstLegID = $mCQ["firstLegID"]; $homeTeam = $mCQ["homeTeam"]; $homeScore = $mCQ["homeScore"]; $homeRinkPts = $mCQ["homeRinkPts"]; $awayTeam = $mCQ["awayTeam"]; $awayScore = $mCQ["awayScore"]; $awayRinkPts = $mCQ["awayRinkPts"]; } if ( ($weekID == 9999) || ($weekID == 99999) ) { ///// THIS IS THE FINAL NO NEED TO DO ANYTHING \\\\\ $jsonArray = array("uFixtures" => "false"); } else { if ( ($homeScore >= 0) && ($awayScore >= 0) && ($homeRinkPts > 0 || $awayRinkPts > 0) ) { ///// MATCH COMPLETE \\\\\ $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$miniLeagueID'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $hasPlayoffQuery = mysqli_query($conn, "SELECT hasPlayoff, pointsRink FROM leagueConfig WHERE id = '$leagueID'"); while ($hPQ = mysqli_fetch_array($hasPlayoffQuery)) { $hasPlayoff = $hPQ["hasPlayoff"]; $pointsRink = $hPQ["pointsRink"]; } if ($hasPlayoff == 1 || $hasPlayoff == 3) { ///// 2 LEGS - CHECK IF BOTH COMPLETED \\\\\ if ($firstLegID == 0) { ///// THIS IS THE FIRST LEG - CHECK IF 2ND COMPLETE \\\\\ $otherLegCompleteQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE firstLegID = '$firstLegID'"); } else { $otherLegCompleteQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE id = '$firstLegID'"); } while ($oLCQ = mysqli_fetch_array($otherLegCompleteQuery)) { $otherLegHomeScore = $oLCQ["homeScore"]; $otherLegHomeRinkPts = $oLCQ["homeRinkPts"]; $otherLegAwayScore = $oLCQ["awayScore"]; $otherLegAwayRinkPts = $oLCQ["awayRinkPts"]; } if ( ($otherLegHomeScore >= 0) && ($otherLegAwayScore >= 0) && ($otherLegHomeRinkPts > 0 || $otherLegAwayRinkPts > 0) ) { ///// 2ND LEG COMPLETE - FIND THE WINNER \\\\\ $homeTeamScore = ($homeRinkPts + $homeScore) + ($otherLegAwayRinkPts + $otherLegAwayScore); $awayTeamScore = ($awayRinkPts + $awayScore) + ($otherLegHomeRinkPts + $otherLegHomeScore); if ($homeTeamScore > $awayTeamScore) { $winningTeam = $homeTeam; } elseif ($homeTeamScore == $awayTeamScore) { $winningTeam = ""; } else { $winningTeam = $awayTeam; } $roundMatchesQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$weekID' AND (miniLeagueID = '$miniLeagueID')"); if (mysqli_num_rows($roundMatchesQuery) > 4) { ///// ADVANCES TO A DRAW \\\\\ $nextWeekID = $weekID + 1; $jsonArray = array("uFixtures" => "draw", "weekID" => $nextWeekID, "teamName" => $winningTeam); } else { ///// ADD TEAM TO NEXT ROUND \\\\\ $homeOrAwayI = 0; $homeOrAwayQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$weekID' AND (miniLeagueID = '$miniLeagueID')"); while ($hAQ = mysqli_fetch_array($homeOrAwayQuery)) { $homeAwayID = $hAQ["id"]; if ($homeAwayID == $fixtureID) { break; } else { $homeOrAwayI++; } } if ($homeOrAwayI % 2 == 0) { $homeOrAway = "home"; $awayOrHome = "away"; } else { $homeOrAway = "away"; $awayOrHome = "home"; } $jsonArray = array("uFixtures" => "advance", "uTwoLegs" => "true"); $nextWeekID = $weekID + 1; $leg = 1; $nextMatchQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$nextWeekID' AND (miniLeagueID = '$miniLeagueID')"); while ($nMQ = mysqli_fetch_array($nextMatchQuery)) { $nextMatchID = $nMQ["id"]; $jsonArray["fixtureID". $leg] = $nextMatchID; if ($leg == 1) { mysqli_query($conn, "UPDATE leagueResults SET ". $homeOrAway ."Team = '$winningTeam' WHERE id = '$nextMatchID'"); $jsonArray["homeAway". $leg] = $homeOrAway; } else { mysqli_query($conn, "UPDATE leagueResults SET ". $awayOrHome ."Team = '$winningTeam' WHERE id = '$nextMatchID'"); $jsonArray["homeAway". $leg] = $awayOrHome; } $leg++; } $jsonArray["teamName"] = $winningTeam; $jsonArray["maxRink"] = $pointsRink; } } else { ///// 2ND LEG TO PLAY - DO NOTHING \\\\\ $jsonArray = array("uFixtures" => "false"); } } else { ///// ONE OFF MATCH - WINNER ADVANCES \\\\\ ///// WHO WINS THIS MATCH? \\\\\ $homeTeamScore = $homeRinkPts + $homeScore; $awayTeamScore = $awayRinkPts + $awayScore; if ($homeTeamScore > $awayTeamScore) { $winningTeam = $homeTeam; } elseif ($homeTeamScore == $awayTeamScore) { $winningTeam = ""; } else { $winningTeam = $awayTeam; } $roundMatchesQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$weekID' AND (miniLeagueID = '$miniLeagueID')"); if (mysqli_num_rows($roundMatchesQuery) > 2) { ///// ADVANCES TO A DRAW \\\\\ $nextWeekID = $weekID + 1; $jsonArray = array("uFixtures" => "draw", "weekID" => $nextWeekID, "teamName" => $winningTeam); } else { ///// ADD TEAM TO NEXT ROUND \\\\\ $homeOrAwayI = 0; $homeOrAwayQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$weekID' AND (miniLeagueID = '$miniLeagueID')"); while ($hAQ = mysqli_fetch_array($homeOrAwayQuery)) { $homeAwayID = $hAQ["id"]; if ($homeAwayID == $fixtureID) { break; } else { $homeOrAwayI++; } } if ($homeOrAwayI % 2 == 0) { $homeOrAway = "home"; } else { $homeOrAway = "away"; } $nextWeekID = $weekID + 1; $nextMatchQuery = mysqli_query($conn, "SELECT id FROM leagueResults WHERE weekID = '$nextWeekID' AND (miniLeagueID = '$miniLeagueID')"); while ($nMQ = mysqli_fetch_array($nextMatchQuery)) { $nextMatchID = $nMQ["id"]; } mysqli_query($conn, "UPDATE leagueResults SET ". $homeOrAway ."Team = '$winningTeam' WHERE id = '$nextMatchID'"); $jsonArray = array("uFixtures" => "advance", "uTwoLegs" => "false", "fixtureID" => $nextMatchID, "homeAway" => $homeOrAway, "teamName" => $winningTeam, "maxRink" => $pointsRink); } } } else { $jsonArray = array("uFixtures" => "false"); } } echo json_encode($jsonArray); } elseif (isset($_POST["updateDraw"])) { $roundID = str_replace("fixtures", "", $_POST["updateDraw"]); $miniLeagueID = $_POST["mlID"]; $teamsList = $_POST["team"]; $thisTeam = 0; $playoffsQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE miniLeagueID = ('$miniLeagueID') AND (weekID = '$roundID') ORDER BY id ASC"); while ($pQ = mysqli_fetch_array($playoffsQuery)) { $fixtureID = $pQ["id"]; $homeTeam = $teamsList[$thisTeam]; if ($homeTeam == "undefined") { $homeTeam = ""; } $thisTeam++; $awayTeam = $teamsList[$thisTeam]; if ($awayTeam == "undefined") { $awayTeam = ""; } mysqli_query($conn, "UPDATE leagueResults SET homeTeam = '". addslashes($homeTeam) ."', awayTeam = '". addslashes($awayTeam) ."' WHERE id = '$fixtureID'"); $mlIDQuery = mysqli_query($conn, "SELECT miniLeagueID FROM leagueResults WHERE id = '$fixtureID'"); while ($mIQ = mysqli_fetch_array($mlIDQuery)) { $miniLeagueID = $mIQ["miniLeagueID"]; } $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$miniLeagueID'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $leagueQuery = mysqli_query($conn, "SELECT * FROM leagueConfig WHERE id = '$leagueID'"); while ($lQ = mysqli_fetch_array($leagueQuery)) { $leagueType = $lQ["leagueType"]; $lFullSDate = $lQ["startDate"]; $lStartMonth = date("F", strtotime($lFullSDate)); $lStartYear = date("Y", strtotime($lFullSDate)); $leagueStartDate = "$lStartMonth $lStartYear"; } $leagueIDQuery = mysqli_query($conn, "SELECT groupTitle FROM leagueGroups WHERE id = '$leagueType'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $groupTitle = $lIQ["groupTitle"]; } $fixtureTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE id = '$fixtureID'"); while ($fTQ = mysqli_fetch_array($fixtureTeamsQuery)) { $homeTeam = $fTQ["homeTeam"]; $awayTeam = $fTQ["awayTeam"]; } $trackDate = date("Y-m-d H:i:s"); $trackTitle = "$groupTitle $leagueStartDate"; mysqli_query($conn, "INSERT INTO userActions (dateCreated, adminID, pageTracking, databaseUpdated, updateDetails) VALUES ('$trackDate', '$adminID', 'admin/leagueEdit-2-playoffs-Data.php', 'leagueResults', 'The User ". addslashes($adminName) ." <$adminEmail> updated the drawy for fixture ID: $fixtureID (". $homeTeam ." vs ". $awayTeam .") in league ID: $leagueID (". addslashes($trackTitle) .")')"); $thisTeam++; } if ($roundID == 99999) { $roundTitle = "Final"; } elseif ($roundID == 99998) { $roundTitle = "Semi-Finals"; } elseif ($roundID == 99997) { $roundTitle = "Quarter-Finals"; } else { $roundID = ($weekID - $lowestWeek) + 1; $roundTitle = "Round $roundID"; } $fixtureDateQuery = mysqli_query($conn, "SELECT id, miniLeagueID, fixtureDate FROM leagueResults WHERE miniLeagueID = ('$miniLeagueID') AND (weekID = '$roundID') ORDER BY id ASC LIMIT 0,1"); while ($fDQ = mysqli_fetch_array($fixtureDateQuery)) { $fixtureID = $fDQ["id"]; $fixtureMLid = $fDQ["miniLeagueID"]; $fixtureDate = date("d/m/Y", strtotime($fDQ["fixtureDate"])); } $drawnTeamsArray = array(); $playoffsSetTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE miniLeagueID = ('$miniLeagueID') AND (weekID = '$roundID') ORDER BY id ASC"); while ($pSTQ = mysqli_fetch_array($playoffsSetTeamsQuery)) { if (trim($pSTQ["homeTeam"])) { $drawnTeamsArray[] = $pSTQ["homeTeam"]; } if (trim($pSTQ["awayTeam"])) { $drawnTeamsArray[] = $pSTQ["awayTeam"]; } } ?> <h3><?php echo $roundTitle ?></h3> <div class="roundDateInp">Date: <input type="text" id="fixtureDate<?php echo $fixtureID ?>" name="fixtureDate[<?php echo $fixtureID ?>]" class="roundDate" size="50" value="<?php echo $fixtureDate ?>"></div> <div class="listTitle">Qualified Teams</div> <div class="listTitle listTitleW">Round Draw</div> <div class="playersListC"> <ul id="players<?php echo $roundID ?>" class="playersSet ui-sortable"> <?php $undrawnTeamsQuery = mysqli_query($conn, "SELECT teamName FROM leagueKnockout WHERE leagueID = '$miniLeagueID' AND (weekID = '$roundID') AND teamName NOT IN('". implode("', '", $drawnTeamsArray) ."') ORDER BY id ASC"); while ($uTQ = mysqli_fetch_array($undrawnTeamsQuery)) { $teamName = $uTQ["teamName"]; ?> <li><i class="fas fa-grip-horizontal"></i><input type="text" class="teamName" size="50" value="<?php echo $teamName ?>" readonly /></li> <?php } ?> </ul> </div> <div class="fixturesListC"> <?php $playoffsQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE miniLeagueID = '$miniLeagueID' AND (weekID = '$roundID') ORDER BY id ASC"); $noTeams = mysqli_num_rows($playoffsQuery) * 2; ?> <ul id="fixtures<?php echo $roundID ?>" class="fixtureSet ui-sortable" data-fc="<?php echo $noTeams ?>" data-mlid="<?php echo $fixtureMLid ?>"> <?php while ($pFQ = mysqli_fetch_array($playoffsQuery)) { $fixtureID = $pFQ["id"]; $weekID = $pFQ["weekID"]; $fixtureDate = date("d/m/Y", strtotime($pFQ["fixtureDate"])); $homeTeam = $pFQ["homeTeam"]; $homeScore = $pFQ["homeScore"]; $homeRinkPts = $pFQ["homeRinkPts"]; $awayTeam = $pFQ["awayTeam"]; $awayScore = $pFQ["awayScore"]; $awayRinkPts = $pFQ["awayRinkPts"]; $firstLegID = $pFQ["firstLegID"]; if ($homeScore == -1) { $homeScore = ""; $homeRinkPts = ""; } if ($awayScore == -1) { $awayScore = ""; $awayRinkPts = ""; } if (trim($homeTeam) == "") { ?> <li id="home<?php echo $fixtureID ?>" class="ui-sortable-placeholder ui-sortable-handle"></li> <?php } else { ?> <li id="home<?php echo $fixtureID ?>" class="ui-sortable-handle"><input type="text" class="teamName" size="50" value="<?php echo $homeTeam ?>" readonly /> <input type="number" class="fixtureRinkPts" placeholder="Rink Points" value="<?php echo $homeRinkPts ?>" min="0" max="<?php echo $pointsRink ?>" step="1"> <input type="number" class="kFixtureScore" placeholder="Shots" value="<?php echo $homeScore ?>" min="0" step="1"></li> <?php } if (trim($awayTeam) == "") { ?> <li id="away<?php echo $fixtureID ?>" class="ui-sortable-placeholder ui-sortable-handle"></li> <?php } else { ?> <li id="away<?php echo $fixtureID ?>" class="ui-sortable-handle"><input type="text" class="teamName" size="50" value="<?php echo $awayTeam ?>" readonly /> <input type="number" class="fixtureRinkPts" placeholder="Rink Points" value="<?php echo $awayRinkPts ?>" min="0" max="<?php echo $pointsRink ?>" step="1"> <input type="number" class="kFixtureScore" placeholder="Shots" value="<?php echo $awayScore ?>" min="0" step="1"></li> <?php } } ?> </ul> </div> <?php } elseif (isset($_POST["kSS"])) { $shotScoreID = $_POST["kSS"]; $thisScore = $_POST["kTS"]; $homeAway = substr($shotScoreID, 0, 4); $fixtureID = substr($shotScoreID, 4); mysqli_query($conn, "UPDATE leagueResults SET ". $homeAway ."Score = '$thisScore' WHERE id = '$fixtureID'"); $mlIDQuery = mysqli_query($conn, "SELECT miniLeagueID FROM leagueResults WHERE id = '$fixtureID'"); while ($mIQ = mysqli_fetch_array($mlIDQuery)) { $miniLeagueID = $mIQ["miniLeagueID"]; } $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$miniLeagueID'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $leagueQuery = mysqli_query($conn, "SELECT * FROM leagueConfig WHERE id = '$leagueID'"); while ($lQ = mysqli_fetch_array($leagueQuery)) { $leagueType = $lQ["leagueType"]; $lFullSDate = $lQ["startDate"]; $lStartMonth = date("F", strtotime($lFullSDate)); $lStartYear = date("Y", strtotime($lFullSDate)); $leagueStartDate = "$lStartMonth $lStartYear"; } $leagueIDQuery = mysqli_query($conn, "SELECT groupTitle FROM leagueGroups WHERE id = '$leagueType'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $groupTitle = $lIQ["groupTitle"]; } $fixtureTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE id = '$fixtureID'"); while ($fTQ = mysqli_fetch_array($fixtureTeamsQuery)) { $homeTeam = $fTQ["homeTeam"]; $awayTeam = $fTQ["awayTeam"]; } $trackDate = date("Y-m-d H:i:s"); $trackTitle = "$groupTitle $leagueStartDate"; mysqli_query($conn, "INSERT INTO userActions (dateCreated, adminID, pageTracking, databaseUpdated, updateDetails) VALUES ('$trackDate', '$adminID', 'admin/leagueEdit-2-playoffs-Data.php', 'leagueResults', 'The User ". addslashes($adminName) ." <$adminEmail> updated the score for fixture ID: $fixtureID (". $homeTeam ." vs ". $awayTeam .") in league ID: $leagueID (". addslashes($trackTitle) .")')"); $fixtureDateQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE id = '$fixtureID'"); while ($fDQ = mysqli_fetch_array($fixtureDateQuery)) { $fixtureID = $fDQ["id"]; $roundID = $fDQ["weekID"]; $weekID = $roundID; $fixtureMLid = $fDQ["miniLeagueID"]; $fixtureDate = date("d/m/Y", strtotime($fDQ["fixtureDate"])); $firstLegID = $fDQ["firstLegID"]; $homeTeam = $fDQ["homeTeam"]; $homeScore = $fDQ["homeScore"]; $homeRinkPts = $fDQ["homeRinkPts"]; $awayTeam = $fDQ["awayTeam"]; $awayScore = $fDQ["awayScore"]; $awayRinkPts = $fDQ["awayRinkPts"]; } if ($roundID == 99999) { $jsonArray = array("update" => "false"); } else { $roundID = $roundID + 1; if ( ($homeScore >= 0) && ($awayScore >= 0) && ($homeRinkPts > 0 || $awayRinkPts > 0) ) { $leagueIDQuery = mysqli_query($conn, "SELECT leagueID FROM leagueMiniLeagues WHERE id = '$fixtureMLid'"); while ($lIQ = mysqli_fetch_array($leagueIDQuery)) { $leagueID = $lIQ["leagueID"]; } $hasPlayoffQuery = mysqli_query($conn, "SELECT hasPlayoff, pointsRink FROM leagueConfig WHERE id = '$leagueID'"); while ($hPQ = mysqli_fetch_array($hasPlayoffQuery)) { $hasPlayoff = $hPQ["hasPlayoff"]; $pointsRink = $hPQ["pointsRink"]; } if ($hasPlayoff == 1 || $hasPlayoff == 3) { ///// 2 LEGS - CHECK IF BOTH COMPLETED \\\\\ if ($firstLegID == 0) { ///// THIS IS THE FIRST LEG - CHECK IF 2ND COMPLETE \\\\\ $otherLegCompleteQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE firstLegID = '$firstLegID'"); } else { $otherLegCompleteQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE id = '$firstLegID'"); } while ($oLCQ = mysqli_fetch_array($otherLegCompleteQuery)) { $otherLegHomeScore = $oLCQ["homeScore"]; $otherLegHomeRinkPts = $oLCQ["homeRinkPts"]; $otherLegAwayScore = $oLCQ["awayScore"]; $otherLegAwayRinkPts = $oLCQ["awayRinkPts"]; } if ( ($otherLegHomeScore >= 0) && ($otherLegAwayScore >= 0) && ($otherLegHomeRinkPts > 0 || $otherLegAwayRinkPts > 0) ) { ///// 2ND LEG COMPLETE - FIND THE WINNER \\\\\ $homeTeamScore = ($homeRinkPts + $homeScore) + ($otherLegAwayRinkPts + $otherLegAwayScore); $awayTeamScore = ($awayRinkPts + $awayScore) + ($otherLegHomeRinkPts + $otherLegHomeScore); if ($homeTeamScore > $awayTeamScore) { $winningTeam = $homeTeam; } elseif ($homeTeamScore == $awayTeamScore) { $winningTeam = ""; } else { $winningTeam = $awayTeam; } $alreadyThere = mysqli_query($conn, "SELECT id FROM leagueKnockout WHERE fixtureID = '$fixtureID'"); if (mysqli_num_rows($alreadyThere) == 0) { mysqli_query($conn, "INSERT INTO leagueKnockout (leagueID, weekID, fixtureID, teamName) VALUES ('$fixtureMLid', '$roundID', '$fixtureID', '$winningTeam')"); } else { mysqli_query($conn, "UPDATE leagueKnockout SET teamName = '$winningTeam' WHERE fixtureID = '$fixtureID'"); } } else { $jsonArray = array("update" => "false"); } } else { ///// ONE OFF MATCH - WINNER ADVANCES \\\\\ ///// WHO WINS THIS MATCH? \\\\\ $homeTeamScore = $homeRinkPts + $homeScore; $awayTeamScore = $awayRinkPts + $awayScore; if ($homeTeamScore > $awayTeamScore) { $winningTeam = $homeTeam; } elseif ($homeTeamScore == $awayTeamScore) { $winningTeam = ""; } else { $winningTeam = $awayTeam; } $alreadyThere = mysqli_query($conn, "SELECT id FROM leagueKnockout WHERE fixtureID = '$fixtureID'"); if (mysqli_num_rows($alreadyThere) == 0) { mysqli_query($conn, "INSERT INTO leagueKnockout (leagueID, weekID, fixtureID, teamName) VALUES ('$fixtureMLid', '$roundID', '$fixtureID', '$winningTeam')"); } else { mysqli_query($conn, "UPDATE leagueKnockout SET teamName = '$winningTeam' WHERE fixtureID = '$fixtureID'"); } } $jsonArray = array("update" => "true", "divID" => "round". $roundID ."Display"); if ($roundID == 99999) { $roundTitle = "Final"; } elseif ($roundID == 99998) { $roundTitle = "Semi-Finals"; } elseif ($roundID == 99997) { $roundTitle = "Quarter-Finals"; } else { $roundID = ($weekID - $lowestWeek) + 1; $roundTitle = "Round $roundID"; } $fixtureDateQuery = mysqli_query($conn, "SELECT miniLeagueID, fixtureDate FROM leagueResults WHERE id = '$fixtureID'"); while ($fDQ = mysqli_fetch_array($fixtureDateQuery)) { $fixtureMLid = $fDQ["miniLeagueID"]; $fixtureDate = date("d/m/Y", strtotime($fDQ["fixtureDate"])); } $drawnTeamsArray = array(); $playoffsSetTeamsQuery = mysqli_query($conn, "SELECT homeTeam, awayTeam FROM leagueResults WHERE miniLeagueID = ('$fixtureMLid') AND (weekID = '$roundID') ORDER BY id ASC"); while ($pSTQ = mysqli_fetch_array($playoffsSetTeamsQuery)) { if (trim($pSTQ["homeTeam"])) { $drawnTeamsArray[] = $pSTQ["homeTeam"]; } if (trim($pSTQ["awayTeam"])) { $drawnTeamsArray[] = $pSTQ["awayTeam"]; } } $roundHTML = ' <h3>'. $roundTitle .'</h3> <div class="roundDateInp">Date: <input type="text" id="fixtureDate'. $fixtureID .'" name="fixtureDate['. $fixtureID .']" class="roundDate" size="50" value="'. $fixtureDate .'"></div> <div class="listTitle">Qualified Teams</div> <div class="listTitle listTitleW">Round Draw</div> <div class="playersListC"> <ul id="players'. $roundID .'" class="playersSet ui-sortable">'; $undrawnTeamsQuery = mysqli_query($conn, "SELECT teamName FROM leagueKnockout WHERE leagueID = '$fixtureMLid' AND (weekID = '$roundID') AND teamName NOT IN('". implode("', '", $drawnTeamsArray) ."') ORDER BY id ASC"); while ($uTQ = mysqli_fetch_array($undrawnTeamsQuery)) { $teamName = $uTQ["teamName"]; $roundHTML .= ' <li><i class="fas fa-grip-horizontal"></i><input type="text" class="teamName" size="50" value="'. $teamName .'" readonly /></li>'; } $roundHTML .= ' </ul> </div> <div class="fixturesListC">'; $playoffsQuery = mysqli_query($conn, "SELECT * FROM leagueResults WHERE miniLeagueID = '$fixtureMLid' AND (weekID = '$roundID') ORDER BY id ASC"); $noTeams = mysqli_num_rows($playoffsQuery) * 2; $roundHTML .= ' <ul id="fixtures'. $roundID .'" class="fixtureSet ui-sortable" data-fc="'. $noTeams .'" data-mlid="'. $fixtureMLid .'">'; while ($pFQ = mysqli_fetch_array($playoffsQuery)) { $fixtureID = $pFQ["id"]; $weekID = $pFQ["weekID"]; $fixtureDate = date("d/m/Y", strtotime($pFQ["fixtureDate"])); $homeTeam = $pFQ["homeTeam"]; $homeScore = $pFQ["homeScore"]; $homeRinkPts = $pFQ["homeRinkPts"]; $awayTeam = $pFQ["awayTeam"]; $awayScore = $pFQ["awayScore"]; $awayRinkPts = $pFQ["awayRinkPts"]; $firstLegID = $pFQ["firstLegID"]; if ($homeScore == -1) { $homeScore = ""; $homeRinkPts = ""; } if ($awayScore == -1) { $awayScore = ""; $awayRinkPts = ""; } if (trim($homeTeam) == "") { $roundHTML .= ' <li id="home'. $fixtureID .'" class="ui-sortable-placeholder ui-sortable-handle"></li>'; } else { $roundHTML .= ' <li id="home'. $fixtureID .'" class="ui-sortable-handle"><input type="text" class="teamName" size="50" value="'. $homeTeam .'" readonly /> <input type="number" class="fixtureRinkPts" placeholder="Rink Points" value="'. $homeRinkPts .'" min="0" max="'. $pointsRink .'" step="1"> <input type="number" class="kFixtureScore" placeholder="Shots" value="'. $homeScore .'" min="0" step="1"></li>'; } if (trim($awayTeam) == "") { $roundHTML .= ' <li id="away'. $fixtureID .'" class="ui-sortable-placeholder ui-sortable-handle"></li>'; } else { $roundHTML .= ' <li id="away'. $fixtureID .'" class="ui-sortable-handle"><input type="text" class="teamName" size="50" value="'. $awayTeam .'" readonly /> <input type="number" class="fixtureRinkPts" placeholder="Rink Points" value="'. $awayRinkPts .'" min="0" max="'. $pointsRink .'" step="1"> <input type="number" class="kFixtureScore" placeholder="Shots" value="'. $awayScore .'" min="0" step="1"></li>'; } } $roundHTML .= ' </ul> </div>'; $jsonArray["divHTML"] = $roundHTML; } else { $jsonArray = array("update" => "false"); } } echo json_encode($jsonArray); } ?>