The following files exists in this folder. Click to view.
end_match.php50 lines ASCII Unix (LF)
<?php
session_start();
require_once('databaseconnection.php');
include('functions.php');
include('check_login.php');
$sql = "SELECT * FROM Matches WHERE matchId = :matchId;";
$stm = $pdo->prepare($sql);
$stm->execute(array('matchId' => $_GET['matchId']));
$match = $stm->fetch(PDO::FETCH_ASSOC);
//Validating player
$sql = "SELECT playerId FROM Players WHERE userId = :userId;";
$stm = $pdo->prepare($sql);
$stm->execute(array('userId' => $_SESSION['userId']));
$res = $stm->fetchAll(PDO::FETCH_ASSOC);
$exit = TRUE;
foreach($res as $a){
if ((int)$match['defenderId'] == (int)$a['playerId'] or (int)$match['challengerId'] == (int)$a['playerId'] && $match['status'] == 'accepted'){
if ((int)$match['challengerId'] == (int)$a['playerId']){
$winnerId = $match['defenderId'];
}
else{
$winnerId = $match['challengerId'];
}
$exit = FALSE;
validateladdertime($match['defenderId'], 'yes');
}
}
if ($exit == TRUE){
header('location: home.php');
exit();
}
$sql = "UPDATE Matches SET winnerId = :winnerId, status = :status WHERE matchId = :matchId;";
$stm = $pdo->prepare($sql);
$stm->execute([
':winnerId' => $winnerId,
':status' => 'won',
':matchId' => $match['matchId']]);
if(isset($_GET['openladder'])){
header('location: home.php?openladder='.$_GET['openladder'].'');
exit();
}
header('location: home.php?');
exit();
?>