BuLi-Tipp hinzugefügt
This commit is contained in:
115
bulitipp/check.php
Executable file
115
bulitipp/check.php
Executable file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
include("../../mysqlverbinden.php");
|
||||
include("../rowforeach.php");
|
||||
include("inc.php");
|
||||
|
||||
$bundesliga = file_get_contents("liga.txt");
|
||||
$year = file_get_contents("saison.txt");
|
||||
|
||||
$reload=false;
|
||||
|
||||
// Paarungen holen
|
||||
// HTTP-Request ausführen
|
||||
$spieltag=getmaxtippspieltag()+1;
|
||||
if($spieltag<=34){
|
||||
$response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false);
|
||||
|
||||
if ($response === false) {
|
||||
echo "<script>window.alert(`Fehler beim HTTP-Request(Z.41)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
||||
}
|
||||
|
||||
|
||||
$responseData = json_decode($response, true); // Response auswerten
|
||||
if ($responseData!=null) {
|
||||
// Response-Data ist ok
|
||||
// Wochentag und Uhrzeit überprüfen, also auch überprüfen, ob die Daten schon aktuell sind
|
||||
$aktuell = false;
|
||||
foreach ($responseData as $key => $match) {
|
||||
|
||||
// Datum in UTC einlesen
|
||||
$date = new DateTime($match["matchDateTimeUTC"], new DateTimeZone('UTC'));
|
||||
|
||||
// In die Zeitzone Berlin konvertieren
|
||||
$date->setTimezone(new DateTimeZone('Europe/Berlin'));
|
||||
|
||||
|
||||
$diff = time()-$date->getTimestamp();
|
||||
|
||||
if ($diff >= -60 * 60 * 24 * 21) {
|
||||
$aktuell = true;
|
||||
}
|
||||
|
||||
}
|
||||
if ($aktuell) {
|
||||
// Daten sind aktuell genug, Paarungen in die Datenbank einfügen
|
||||
$spieltag=getmaxtippspieltag()+1;
|
||||
foreach ($responseData as $key => $match) {
|
||||
|
||||
$deadline = new DateTime($match["matchDateTimeUTC"], new DateTimeZone('UTC'));
|
||||
|
||||
// In die Zeitzone Berlin konvertieren
|
||||
$deadline->setTimezone(new DateTimeZone('Europe/Berlin'));
|
||||
|
||||
$heim=$match["team1"]["shortName"];
|
||||
$gast=$match["team2"]["shortName"];
|
||||
|
||||
|
||||
mysqli_execute_query($db_id,"INSERT INTO `buli-paarungen` (`heim`,`gast`,`spieltag`,`deadline`) VALUES (?,?,?,?);",[$heim,$gast,$spieltag,$deadline->format('Y-m-d H:i:s')]);
|
||||
$reload=true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Response ist kein JSON
|
||||
// echo "<script>window.alert(`JSON-Response ungültig (Z.84)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($spieltag>=34){
|
||||
$spieltag=getmaxspieltag()+1;
|
||||
if(srowforeach("SELECT COUNT(*) from `buli-results` where spieltag=?;",[$spieltag-1])[0][0]<9) $spieltag--;
|
||||
$response = file_get_contents("https://api.openligadb.de/getmatchdata/bl".$bundesliga."/".$year."/".$spieltag, false);
|
||||
|
||||
|
||||
if ($response === false) {
|
||||
// echo "<script>window.alert(`Fehler beim HTTP-Request (Z.15)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
||||
}
|
||||
|
||||
$responseData = json_decode($response, true); // Response auswerten
|
||||
if ($responseData) {
|
||||
// Response-Data ist ok
|
||||
foreach ($responseData as $key => $match) {
|
||||
if ($match["matchIsFinished"]) {
|
||||
// Spiel beendet, Ergebnisse in die Datenbank eintragen
|
||||
$heim=$match["team1"]["shortName"];
|
||||
$gast=$match["team2"]["shortName"];
|
||||
$paarungsquery=srowforeach("SELECT `id` from `buli-paarungen` where spieltag=? AND heim=? AND gast=?;",[$spieltag,$heim,$gast]);
|
||||
if(count($paarungsquery)==0) continue;
|
||||
|
||||
|
||||
$paarungsid=$paarungsquery[0][0];
|
||||
$score1=$match["matchResults"][1]["pointsTeam1"];
|
||||
$score2=$match["matchResults"][1]["pointsTeam2"];
|
||||
mysqli_execute_query($db_id,"INSERT INTO `buli-results` (paarung, score1,score2, spieltag) VALUES (?,?,?,?);",[$paarungsid,$score1,$score2,$spieltag]);
|
||||
$reload=true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Response ist kein JSON
|
||||
// echo "<script>window.alert(`JSON-Response ungültig (Z.29)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);</script>";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(srowforeach("SELECT COUNT(`id`) from `buli-icons`;",[])[0][0]<9){
|
||||
mysqli_execute_query($db_id,"TRUNCATE `buli-icons`;",[]);
|
||||
$responseDataTeams=json_decode(file_get_contents("https://api.openligadb.de/getavailableteams/bl".$bundesliga."/".$year, false),true);
|
||||
|
||||
foreach($responseDataTeams as $key => $value){
|
||||
$iconurl=$value["teamIconUrl"];
|
||||
$name=$value["shortName"];
|
||||
$image=file_get_contents($iconurl,false);
|
||||
mysqli_execute_query($db_id,"INSERT INTO `buli-icons` (`team`,`img`) VALUES (?,?);",[$name,$image]);
|
||||
|
||||
}
|
||||
}
|
||||
9
bulitipp/get-image.php
Executable file
9
bulitipp/get-image.php
Executable file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
include("./check.php");
|
||||
|
||||
if(!isset($_GET["team"])) die("GET team fehlt");
|
||||
$team=$_GET["team"];
|
||||
|
||||
header("Content-Type: img/png");
|
||||
|
||||
echo srowforeach("SELECT `img` from `buli-icons` where `team`=?;",[$team])[0][0];
|
||||
15
bulitipp/get-users.php
Executable file
15
bulitipp/get-users.php
Executable file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
include("./check.php");
|
||||
|
||||
$data=[];
|
||||
|
||||
foreach(srowforeach("SELECT `id`, `kuerzel`, `username` from `buli-user`;",[]) as $key=>$value){
|
||||
$data[$key]["id"]=$value[0];
|
||||
$data[$key]["kuerzel"]=$value[1];
|
||||
$data[$key]["name"]=$value[2];
|
||||
}
|
||||
|
||||
$result=["reload"=>$reload,"data"=>$data];
|
||||
|
||||
echo json_encode($result, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||||
104
bulitipp/inc.php
Executable file
104
bulitipp/inc.php
Executable file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
function getTipp($name, $spieltag, $paarungid)
|
||||
{
|
||||
$userid=srowforeach("SELECT `id` from `buli-user` where username=?;",[$name])[0][0];
|
||||
$tippQueryResult = srowforeach("SELECT `tipp1`,`tipp2`,`tipp3`,`tipp4`,`tipp5`,`tipp6`,`tipp7`,`tipp8`,`tipp9` from `buli-tipps` where user=? AND spieltag=?;", [$userid, $spieltag]);
|
||||
if (count($tippQueryResult) == 0)
|
||||
return null;
|
||||
|
||||
$tippids=$tippQueryResult[0];
|
||||
$paarungen=srowforeach("SELECT `id` from `buli-paarungen` where `spieltag`=?;",[$spieltag]);
|
||||
|
||||
$i=0;
|
||||
foreach($tippids as $key => $value){
|
||||
if($paarungid==$paarungen[$i][0]){
|
||||
// return [0] heim, [1] gast
|
||||
return srowforeach("SELECT `score1`,`score2` from `buli-tipp` where `id`=?;",[$value])[0];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
function getResult($paarungid,$spieltag){
|
||||
return srowforeach("SELECT score1, score2 from `buli-results` where `paarung`=? AND spieltag=?;", [$paarungid, $spieltag])[0];
|
||||
}
|
||||
|
||||
function ps($name, $spieltag, $paarungid)
|
||||
{
|
||||
$punkte = getResult($paarungid,$spieltag);
|
||||
$punktetipp = getTipp($name, $spieltag, $paarungid);
|
||||
|
||||
if ($punktetipp == null){
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($punkte == $punktetipp)
|
||||
return 3;
|
||||
|
||||
$differenz = $punkte[0] - $punkte[1];
|
||||
|
||||
$differenztipp = $punktetipp[0] - $punktetipp[1];
|
||||
|
||||
if ($differenz == $differenztipp)
|
||||
return 2;
|
||||
|
||||
if ($punktetipp[0] == $punktetipp[1] || $punkte[0] == $punkte[1]) {
|
||||
// Unentschieden
|
||||
return 0;
|
||||
}
|
||||
|
||||
$siegertipp = $punktetipp[0] > $punktetipp[1]; // true, wenn der Sieger der 1. ist
|
||||
$sieger = $punkte[0] > $punkte[1]; // true, wenn der Sieger der 1. ist
|
||||
|
||||
if ($sieger == $siegertipp)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function ts($name, $spieltag)
|
||||
{
|
||||
$punkte = 0;
|
||||
|
||||
foreach (srowforeach("SELECT `paarung` from `buli-results` where spieltag=?;", [$spieltag]) as $key => $value) {
|
||||
$punkte += ps($name, $spieltag, $value[0]);
|
||||
}
|
||||
return $punkte;
|
||||
}
|
||||
|
||||
function gs($name, $spieltagmax)
|
||||
{
|
||||
$punkte = 0;
|
||||
|
||||
for ($i = 0; $i < $spieltagmax; $i++) {
|
||||
$punkte += ts($name, $i+1);
|
||||
}
|
||||
|
||||
return $punkte;
|
||||
}
|
||||
|
||||
function getmaxspieltag()
|
||||
{
|
||||
$maxspieltag = 0;
|
||||
foreach (srowforeach("SELECT spieltag from `buli-results`;", []) as $key => $value) {
|
||||
if ($value[0] > $maxspieltag)
|
||||
$maxspieltag = $value[0];
|
||||
}
|
||||
return $maxspieltag;
|
||||
}
|
||||
function getmaxtippspieltag()
|
||||
{
|
||||
$maxspieltag = 0;
|
||||
foreach (srowforeach("SELECT spieltag from `buli-paarungen`;", []) as $key => $value) {
|
||||
if ($value[0] > $maxspieltag)
|
||||
$maxspieltag = $value[0];
|
||||
}
|
||||
return $maxspieltag;
|
||||
}
|
||||
|
||||
|
||||
function deadline($spieltag)
|
||||
{ // Gibt true zurück, wenn die Deadline überschritten ist.
|
||||
$deadline = srowforeach("SELECT deadline from `buli-paarungen` where spieltag=? ORDER BY `deadline` ASC;", [$spieltag])[0][0];
|
||||
date_default_timezone_set('Europe/Berlin');
|
||||
|
||||
return date_create_from_format('Y-m-d H:i:s', $deadline)->getTimestamp() < time();
|
||||
}
|
||||
1
bulitipp/liga.txt
Executable file
1
bulitipp/liga.txt
Executable file
@@ -0,0 +1 @@
|
||||
1
|
||||
3
bulitipp/saison.php
Executable file
3
bulitipp/saison.php
Executable file
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
echo file_get_contents("saison.txt");
|
||||
1
bulitipp/saison.txt
Executable file
1
bulitipp/saison.txt
Executable file
@@ -0,0 +1 @@
|
||||
2024
|
||||
18
bulitipp/ts.php
Executable file
18
bulitipp/ts.php
Executable file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
include("./check.php");
|
||||
|
||||
$users=srowforeach("SELECT `username`, `id` FROM `buli-user`;",[]);
|
||||
|
||||
$data=[];
|
||||
for($i=0;$i<getmaxspieltag();$i++){
|
||||
$spieltag=$i+1;
|
||||
$data[$i]=[];
|
||||
foreach ($users as $key => $value) {
|
||||
$user=$value[0];
|
||||
$userid=$value[1];
|
||||
$data[$i][]=["points"=>ts($user,$spieltag),"user"=>["id"=>$userid,"name"=>$user]];
|
||||
}
|
||||
}
|
||||
$result=["reload"=>$reload, "data"=>$data];
|
||||
echo json_encode($result, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
|
||||
Reference in New Issue
Block a user