View sourcecode

The following files exists in this folder. Click to view.

create_ladder.php

64 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
    session_start
();
    require_once(
'databaseconnection.php');
    include(
'functions.php');
    include(
'check_login.php');

    
$userId $_SESSION['userId'];
    
$laddername $_POST['laddername'];
    
$laddername htmlspecialchars($laddernameENT_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 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($lastId6);

    
$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();

?>