diff --git a/bulitipp/check.php b/bulitipp/check.php new file mode 100755 index 0000000..607f280 --- /dev/null +++ b/bulitipp/check.php @@ -0,0 +1,115 @@ +window.alert(`Fehler beim HTTP-Request(Z.41)! Bitte einen Admin kontaktieren! BuLi-Tipp Daten konnten nicht aktualisiert werden.`);"; +} + + +$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 ""; +} + +} + +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 ""; +} + +$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 ""; +} + +} + +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]); + + } +} \ No newline at end of file diff --git a/bulitipp/get-image.php b/bulitipp/get-image.php new file mode 100755 index 0000000..03fcd98 --- /dev/null +++ b/bulitipp/get-image.php @@ -0,0 +1,9 @@ +$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); \ No newline at end of file diff --git a/bulitipp/inc.php b/bulitipp/inc.php new file mode 100755 index 0000000..f13ffba --- /dev/null +++ b/bulitipp/inc.php @@ -0,0 +1,104 @@ + $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(); +} \ No newline at end of file diff --git a/bulitipp/liga.txt b/bulitipp/liga.txt new file mode 100755 index 0000000..56a6051 --- /dev/null +++ b/bulitipp/liga.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/bulitipp/saison.php b/bulitipp/saison.php new file mode 100755 index 0000000..c6ae6a9 --- /dev/null +++ b/bulitipp/saison.php @@ -0,0 +1,3 @@ + $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); \ No newline at end of file