"Wetten", "scoreboard.php" => "Punktzahlen", "table.php" => "Tabellen", "stats.php" => "Statistiken", "help.php" => "Regeln", "usermenu.php" => "Verwaltung", ); if (EnableSurvey) $Menu["survey.php"] = "Regelumfrage"; $Menu ["archive/"] = "Archiv"; $Menu ["do_logout.php"] = "Logout"; function redirect($to) { if (headers_sent()) echo "

Continue ...

\n"; else header("Location: $to"); } function InitSession($fatal=TRUE) { global $uid, $InSession; if (Maintenance) { redirect("index.php"); die; } session_start(); $uid = isset($_SESSION['uid']) ? intval($_SESSION['uid']) : 0; if (!$uid && $fatal) { redirect("index.php?reason=expired"); die; } $InSession = ($uid != 0); } function htmlescape($str) { return htmlspecialchars($str, ENT_QUOTES, "UTF-8"); } /******************************* HTML FUNCTIONS *******************************/ function IsDynamic() { // header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } function StartPage($title, $script=NULL, $callinit=FALSE) { global $InSession, $InPage, $Menu, $ME, $ThemeDir, $WMBaseDir; if ($InPage) return; $ThisPage = basename($ME); if (basename(dirname($ME)) == "archive") $ThisPage = "archive/"; if ($ThisPage == "index.php") $admlink = " onDblClick=\"location.href='adm.php';\""; $ThemeDir = isset($_GET['theme']) ? $_GET['theme'] : DefaultTheme; if ((substr($ThemeDir, 0, 4) != "http") && (substr($ThemeDir, 0, 1) != '/')) $ThemeDir = "themes/$ThemeDir"; $ThemeDir = $WMBaseDir . $ThemeDir; @header("Content-Type: text/html; charset=utf-8"); if (!$script) { $script = ""; } else if (substr($script, -3) == ".js") { $script = "\n"; } else { $script = "\n"; } if ($callinit) { $callinit = " onload=\"init()\""; } else { $callinit = ""; } echo << Wettmeister: $title $script
EOF; if ($InSession) { echo "\n"; } echo "
\n"; $InPage = TRUE; } function EndPage() { global $InPage, $Webmaster; if (!$InPage) return; $v = Version; if (Debug) $v .= " (Debug build)"; echo << EOF; } function errexit($title, $msg=NULL) { global $InPage; if (!$InPage) StartPage("Fehler: $title"); echo "

Fehler: $title

\n"; if ($msg) echo "

$msg

\n"; EndPage(); die; } function Leave($page, $reason) { redirect("$page.php?reason=$reason"); CloseDB(); die; } /**************************** DATABASE FUNCTIONS ******************************/ function InitDB() { global $dbConn, $ANY_VALUE; if ($dbConn === NULL) { $dbConn = new mysqli(DBHost, DBUser, DBPass, DBName); if ($dbConn->connect_errno) { errexit("Konnte keine Verbindung zur Datenbank herstellen", "Bitte versuchen Sie es später noch einmal."); $dbConn = NULL; } $dbConn->set_charset('utf8mb4'); mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_STRICT ^ MYSQLI_REPORT_INDEX); $ANY_VALUE = (($dbConn->server_version >= 50700) && !preg_match('/mariadb/i', $dbConn->server_info)) ? "ANY_VALUE" : ""; } } function CloseDB() { global $dbConn; if ($dbConn !== NULL) { $dbConn->close(); $dbConn = NULL; } } function DBEscape($s) { global $dbConn; return $dbConn->escape_string($s); } function Query($query, $mode=DB_ASSOC, $id_field='id') { global $dbConn; $res = $dbConn->query($query, MYSQLI_USE_RESULT); if ($res === FALSE) { if (headers_sent() or Debug) echo ""; return $res; } if ($res === TRUE) return $res; $realmode = ($mode >= DB_ASSOC) ? MYSQLI_ASSOC : MYSQLI_NUM; $array = array(); while (($row = $res->fetch_array($realmode))) { if ($mode == RESOLVE_IDS) $array[$row[$id_field]] = $row; else $array[] = $row; } $res->free(); return $array; } function QuerySingleValue($q, $default=NULL) { $q = Query($q, DB_NUM); return ($q && $q[0]) ? $q[0][0] : $default; } function DBAffectedRows() { global $dbConn; return $dbConn->affected_rows; } function StartQuery($query, $mode=DB_ASSOC) { global $dbConn, $CurrentQuery, $CurrentQueryMode; $CurrentQueryMode = ($mode >= DB_ASSOC) ? MYSQLI_ASSOC : MYSQLI_NUM; $CurrentQuery = $dbConn->query($query, MYSQLI_USE_RESULT); if ($CurrentQuery === FALSE) { if (headers_sent() or Debug) echo ""; } return $CurrentQuery; } function NextRow() { global $CurrentQuery, $CurrentQueryMode; return $CurrentQuery->fetch_array($CurrentQueryMode); } function CloseQuery() { global $CurrentQuery; $CurrentQuery->free(); } /********************** HIGH-LEVEL DATA ACCESS FUNCTIONS ***********************/ $betCacheUID = 0; function SetBet($bet_uid, $bet_mid, $goalsA=NULL, $goalsB=NULL, $mask=3) { global $betCacheUID, $betCacheData; $bet_uid = intval($bet_uid); $bet_mid = intval($bet_mid); if (($bet_uid < 1) || ($bet_mid < 1) || ($bet_mid > MatchCount)) { return; } if ($betCacheUID != $bet_uid) { $betCacheUID = $bet_uid; $betCacheData = Query("SELECT id, `match`, goalsA, goalsB FROM wm_bets WHERE user=$bet_uid", RESOLVE_IDS, 'match'); } $goalsA = (($goalsA === NULL) || ($goalsA === "")) ? NULL : intval($goalsA); $goalsB = (($goalsB === NULL) || ($goalsB === "")) ? NULL : intval($goalsB); if (Debug && !AJAX) { echo ""; } } function Histogram($q, $correct, $tclass="", $prefix="") { // $q = a query that yields at least two columns: (title, frequency, ...) // with $correct = the title of the correct answer // $prefix = additional text to put before the histogram (if not empty) $freq = Query($q, DB_NUM); if (!$freq) return FALSE; $sum = 0; $max = 0; foreach ($freq as $row) { $c = $row[1]; if ($c > $max) $max = $c; $sum += $c; } if ($sum < 1) return FALSE; echo "$prefix\n"; echo "\n"; $bscale = ($max <= 20) ? 14 : (280.0 / $max); foreach ($freq as $row) { $n = $row[0]; $c = $row[1]; $pc = intval((100.0 * $c) / $sum + 0.5); $px = intval($bscale * $c + 0.5); $cls = ($n == $correct) ? " class=\"corr\"" : ""; echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; } echo "
TippHäufigkeit
$n$c$pc%
\n"; return TRUE; } /******************************* MISC FUNCTIONS ********************************/ function GermanDate($datetime) { global $GermanMonthNames, $GermanDayNames; if (!$GermanMonthNames) { $GermanMonthNames = explode(",", ",Januar,Februar,März,April,Mai,Juni,Juli,August,September,Oktober,November,Dezember"); } if (!$GermanDayNames) { $GermanDayNames = explode(",", "Do,Fr,Sa,So,Mo,Di,Mi"); } $day = intval(substr($datetime, 8, 2)); $month = intval(substr($datetime, 5, 2)); $time = mktime(12,0,0, $month, $day, intval(substr($datetime, 0, 4))); $dow = ($time / 86400) % 7; return $GermanDayNames[$dow] . ", $day. " . $GermanMonthNames[$month]; } function GermanTime($datetime) { return substr($datetime, 11, 5); } function MatchGroup($class, $number, $group=0) { switch ($class) { case 100: return $group ? "Gruppe $group" : "Gruppenrunde"; case 8: return "Achtelfinale"; case 4: return "Viertelfinale"; case 2: return "Halbfinale"; case 1: return ($number == 1) ? "Finale" : "Spiel um Platz 3"; default: return "?$class?$number?$group?"; } } function MatchName($class, $number, $group) { switch ($class) { case 100: return "Gruppe $group"; case 8: return "Achtelfinale $number"; case 4: return "Viertelfinale $number"; case 2: return "Halbfinale $number"; case 1: return ($number == 1) ? "Finale" : "Platz 3"; default: return "?$class?$number?$group?"; } } function BonusBetGroup($class) { switch($class) { case 100: return 0; case 8: case 4: case 2: return $class; case 1: return 2; default: return -1; } } function BonusBetName($class) { switch($class) { case 0: return ChampionName . "-Tipp vor den Vorrunden"; case 8: return ChampionName . "-Tipp vor dem Achtelfinale"; case 4: return ChampionName . "-Tipp vor dem Viertelfinale"; case 2: return ChampionName . "-Tipp vor dem Halbfinale"; default: return "?"; } } function BonusBetScore($class) { switch($class) { case 0: return Bonus0; case 8: return Bonus8; case 4: return Bonus4; case 2: return Bonus2; default: return 0; } } function PutSelector($name, $list, $current=NULL, $include_null=TRUE, $null_name="", $limit=NULL) { echo ""; } function diffsgn($a, $b) { $d = $a - $b; if ($d > 0) return 1; if ($d < 0) return -1; return 0; } function int_or_null($x) { $i = "".intval($x); if (($x == "") || ($x != $i)) return "NULL"; else return $i; } function CanRegister() { $q = MatchCount; $q = Query("SELECT time - NOW() FROM wm_matches WHERE id = $q", DB_NUM); return ($q[0][0] >= 0); } function GetChampion() { $q = MatchCount; $q = Query("SELECT * FROM wm_matches WHERE id = $q"); $q = $q[0]; if (($q['goalsA'] === NULL) || ($q['goalsB'] === NULL)) return NULL; return (diffsgn($q['goalsA'], $q['goalsB']) > 0) ? $q['teamA'] : $q['teamB']; } function GenerateRandomKey($length) { $key = ""; $gamut = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"; if (function_exists('random_int')) { for ($i = 0; $i < $length; $i++) $key .= $gamut[random_int(0, 61)]; } else { mt_srand(time()); for ($i = 0; $i < $length; $i++) $key .= $gamut[mt_rand(0, 61)]; } return $key; } function MakePassword($pass) { $salt = GenerateRandomKey(16); return $salt . "-" . hash('sha256', $salt.$pass); } function CheckPassword($input, $ref) { if ($input == $ref) return 1; list($salt, $hash) = explode("-", $ref, 2); return (hash('sha256', $salt.$input) == $hash) || (md5($salt.$input) == $hash); } ?>