check.php auf 30 Spieltage begrenzt zum Debuggen, Tippen optimiert mit ein paar QoL Features, updaten von Tipps hinzugefügt

This commit is contained in:
R40fendt
2025-08-22 19:00:11 +02:00
parent 72ec423120
commit 27862a9f3d
5 changed files with 103 additions and 18 deletions

View File

@@ -67,7 +67,7 @@ if ($responseData!=null) {
$spieltag=getmaxspieltag()+1; $spieltag=getmaxspieltag()+1;
if($spieltag<=34){ if($spieltag<=29){
$response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false); $response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false);

View File

@@ -31,6 +31,7 @@ if(isset($headers['Authorization'])) {
} }
$payload = JWT::decode($token, new Key($secret, 'HS256')); $payload = JWT::decode($token, new Key($secret, 'HS256'));
$userid= $payload->id;
if($payload->exp < time()){ if($payload->exp < time()){
die("Token abgelaufen"); die("Token abgelaufen");
@@ -51,10 +52,15 @@ foreach($tipps as $tipp){
$paarungsid = $tipp['paarung']["id"]; $paarungsid = $tipp['paarung']["id"];
$score1 = $tipp['heim']; $score1 = $tipp['heim'];
$score2 = $tipp['gast']; $score2 = $tipp['gast'];
mysqli_execute_query($db_id,"INSERT INTO `buli-tipp` (`spieltag`,`paarung`,`score1`,`score2`) VALUES (?,?,?,?);",[$spieltag,$paarungsid,$score1,$score2]); $update=!mysqli_execute_query($db_id,"SELECT COUNT(*) AS anzahl FROM `buli-tipps` WHERE `spieltag`=? AND user=?;",[$spieltag,$userid])->fetch_assoc()["anzahl"]==0;
$tippids[] = mysqli_insert_id($db_id); if(!$update){
mysqli_execute_query($db_id,"INSERT INTO `buli-tipp` (`spieltag`,`paarung`,`score1`,`score2`) VALUES (?,?,?,?);",[$spieltag,$paarungsid,$score1,$score2]);
$tippids[] = mysqli_insert_id($db_id);
}
else
mysqli_execute_query($db_id,"UPDATE `buli-tipp` AS bt JOIN `buli-tipps` AS bts ON bt.id IN (bts.tipp1, bts.tipp2, bts.tipp3, bts.tipp4, bts.tipp5, bts.tipp6, bts.tipp7, bts.tipp8, bts.tipp9) SET bt.score1=?, bt.score2=? WHERE bt.spieltag=? AND bt.paarung=? AND bts.user=?;",[$score1,$score2,$spieltag,$paarungsid,$userid]);
} }
array_push($tippids, $spieltag); array_push($tippids, $spieltag);
array_push($tippids, $payload->id); array_push($tippids, $payload->id);
mysqli_execute_query($db_id,"INSERT INTO `buli-tipps` (`tipp1`, `tipp2`, `tipp3`, `tipp4`, `tipp5`, `tipp6`, `tipp7`, `tipp8`, `tipp9`, `spieltag`, `user`) VALUES (?,?,?,?,?,?,?,?,?,?,?);",$tippids); if(!$update) mysqli_execute_query($db_id,"INSERT INTO `buli-tipps` (`tipp1`, `tipp2`, `tipp3`, `tipp4`, `tipp5`, `tipp6`, `tipp7`, `tipp8`, `tipp9`, `spieltag`, `user`) VALUES (?,?,?,?,?,?,?,?,?,?,?);",$tippids);

View File

@@ -6,26 +6,28 @@ include("./check.php");
if(!isset($_GET["spieltag"])) die("GET spieltag fehlt"); if(!isset($_GET["spieltag"])) die("GET spieltag fehlt");
$spieltag = $_GET["spieltag"]; $spieltag = $_GET["spieltag"];
if($spieltag==""||$spieltag=="null") die('{"error":"GET spieltag leer"}');
$data=[]; $data=[];
foreach(srowforeach("SELECT `user`, `tipp1`, `tipp2`, `tipp3`, `tipp4`, `tipp5`, `tipp6`, `tipp7`, `tipp8`, `tipp9` from `buli-tipps` where `spieltag`=?;",[$spieltag]) as $key=>$tippquery){ if(deadline($spieltag))
$userid=$tippquery[0]; foreach(srowforeach("SELECT `user`, `tipp1`, `tipp2`, `tipp3`, `tipp4`, `tipp5`, `tipp6`, `tipp7`, `tipp8`, `tipp9` from `buli-tipps` where `spieltag`=?;",[$spieltag]) as $key=>$tippquery){
$tippids=[$tippquery[1],$tippquery[2],$tippquery[3],$tippquery[4],$tippquery[5],$tippquery[6],$tippquery[7],$tippquery[8],$tippquery[9]]; $userid=$tippquery[0];
foreach($tippids as $tippid){ $tippids=[$tippquery[1],$tippquery[2],$tippquery[3],$tippquery[4],$tippquery[5],$tippquery[6],$tippquery[7],$tippquery[8],$tippquery[9]];
$tipp=srowforeach("SELECT `paarung`, `score1`, `score2` FROM `buli-tipp` WHERE `id` = ?",[$tippid]); foreach($tippids as $tippid){
$tipp=srowforeach("SELECT `paarung`, `score1`, `score2` FROM `buli-tipp` WHERE `id` = ?",[$tippid]);
array_push($data, [ array_push($data, [
"user" => $userid, "user" => $userid,
"tipp" => [ "tipp" => [
"paarungsid" => $tipp[0][0], "paarungsid" => $tipp[0][0],
"heim" => $tipp[0][1], "heim" => $tipp[0][1],
"gast" => $tipp[0][2] "gast" => $tipp[0][2]
] ]
]); ]);
}
} }
}

53
bulitipp/tippsuser.php Executable file
View File

@@ -0,0 +1,53 @@
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Authorization");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
require '../vendor/autoload.php';
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
include("jwtsecret.php");
include("../../mysqlverbinden.php");
$headers = getallheaders();
if(isset($headers['Authorization'])) {
$authHeader = $headers['Authorization'];
if (preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
$token = $matches[1];
} else {
die("Invalid Authorization header format");
}
} else {
die("Authorization header not found");
}
try{
$payload = JWT::decode($token, new Key($secret, 'HS256'));
}catch (Exception $e) {
die("{}");
}
$userid= $payload->id;
if($payload->exp < time()){
die("Token abgelaufen");
}
if(!isset($_GET["spieltag"])) die("GET spieltag fehlt");
$spieltag = $_GET["spieltag"];
$data=[];
for($i=0;$i<9;$i++){
$tipp=mysqli_execute_query($db_id,"SELECT `paarung`, `score1`, `score2` FROM `buli-tipp` AS bt JOIN `buli-tipps` AS bts ON bts.tipp".($i+1)."=bt.id WHERE bt.`spieltag`=? AND bts.user=?;",[$spieltag,$userid])->fetch_assoc();
array_push($data,$tipp);
}
echo json_encode($data, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);

24
bulitipp/zeitzutippen.php Executable file
View File

@@ -0,0 +1,24 @@
<?php
header("Access-Control-Allow-Origin: *");
include("../../mysqlverbinden.php");
include("../rowforeach.php");
include("inc.php");
$query=srowforeach("SELECT deadline from `buli-paarungen` where spieltag=? ORDER BY `deadline` ASC;", [getmaxspieltag()+1]);
if(count($query)>0){
$unixtime = date_create_from_format('Y-m-d H:i:s', $query[0][0])->getTimestamp()-time();
$hours=(int) date("H", $unixtime);
$days=date("d", $unixtime)-1;
}
$days=0;
$data=[
"spieltag" => getmaxspieltag()+1,
"deadline" => $query[0][0],
"unixtime" => $unixtime,
"hours" => $hours,
"days" => $days
];
echo json_encode($data,JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);