The following files exists in this folder. Click to view.
create_ladder.php64 lines UTF-8 Unix (LF) 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
<?php
session_start();
require_once('databaseconnection.php');
include('functions.php');
include('check_login.php');
$userId = $_SESSION['userId'];
$laddername = $_POST['laddername'];
$laddername = htmlspecialchars($laddername, ENT_QUOTES, "UTF-8");
$description = (isset($_POST['description']) && $_POST['description'] !== '') ? $description = htmlspecialchars($_POST['description'], ENT_QUOTES, "UTF-8") : NULL;
$pointsystem = $_POST['pointsystem'];
$startingpoints = (int)$_POST['startingpoints'];
$minbet = (int)$_POST['minbet'];
$minbetPercent = (isset($_POST['minbetPercent']) && $_POST['minbetPercent'] !== '') ? (int)$_POST['minbetPercent'] : NULL;
$open = $_POST['open'];
$playerroof = (isset($_POST['playerroof']) && $_POST['playerroof'] !== '') ? (int)$_POST['playerroof'] : NULL;
$startdate = (isset($_POST['startdate']) && $_POST['startdate'] !== '' && $_POST['startdate'] >= date('Y-m-d H:i:s')) ? $_POST['startdate'] : date('Y-m-d H:i:s');
$enddate = (isset($_POST['enddate']) && $_POST['enddate'] !== '' && $_POST['enddate'] > $startdate) ? $_POST['enddate'] : NULL;
//minbetTime ska läggas in i databasen som sekunder
$date = strtotime("now");
$y = (isset($_POST['y']) && $_POST['y'] !== '') ? (int)$_POST['y'] : 0; //Fick lite hjälp från ChatGPT här
$m = (isset($_POST['m']) && $_POST['m'] !== '') ? (int)$_POST['m'] : 0;
$d = (isset($_POST['d']) && $_POST['d'] !== '') ? (int)$_POST['d'] : 0;
$h = (isset($_POST['h']) && $_POST['h'] !== '') ? (int)$_POST['h'] : 0;
$i = (isset($_POST['i']) && $_POST['i'] !== '') ? (int)$_POST['i'] : 0;
$s = (isset($_POST['s']) && $_POST['s'] !== '') ? (int)$_POST['s'] : 0;
$raisetime = strtotime("+".$y." years +".$m." months +".$d." days +".$h." hours +".$i." minutes +".$s." seconds", $date);
$minbetTime = $raisetime - $date;
if ($minbetTime < 1 or $minbetPercent == NULL){
$minbetTime = NULL;
$minbetPercent = NULL;
}
$sql = "INSERT INTO Ladders (userId, laddername, description, pointsystem, startingpoints, minbet, minbetPercent, minbetTime, open, playerroof, startdate, enddate, code)
VALUES (:userId, :laddername, :description, :pointsystem, :startingpoints, :minbet, :minbetPercent, :minbetTime, :open, :playerroof, :startdate, :enddate, :code)";
$stm = $pdo->prepare($sql);
$stm->execute([
':userId' => $userId,
':laddername' => $laddername,
':description' => $description,
':pointsystem' => $pointsystem,
':startingpoints'=> $startingpoints,
':minbet' => $minbet,
':minbetPercent' => $minbetPercent,
':minbetTime' => $minbetTime,
':open' => $open,
':playerroof' => $playerroof,
':startdate' => $startdate,
':enddate' => $enddate,
':code' => '0'
]);
$lastId = $pdo->lastInsertId();
$code = generateFixedLengthCode($lastId, 6);
$sql = "UPDATE Ladders SET code = :code WHERE ladderId = :ladderId;";
$stm = $pdo->prepare($sql);
$stm->execute([':code' => $code, ':ladderId' => $lastId]);
header('location: home.php?action=editLadder');
exit();
?>