private function changePassword()
 {
     $uid = $_SESSION['session']->getUserId();
     if ($this->errno !== 0 && $this->errno !== 1) {
         return;
     }
     if (!$this->checker->checkPassword($_POST['profilPassword'])) {
         $this->errno = 3;
         $this->error = 'Das angegebene Passwort ist nicht gültig.';
         return;
     }
     if ($_POST['profilPassword'] !== $_POST['profilPwdWdh']) {
         $this->errno = 4;
         $this->error = 'Die angegebenen Passwörter stimmen nicht überein.';
         return;
     }
     $this->errno = 0;
     $this->error = '';
     $hasher = new PasswordHash(8, false);
     $pwd = $hasher->HashPassword($_POST['profilPassword']);
     $db = Database::getDbObject();
     $stmt = $db->stmt_init();
     $stmt->prepare("UPDATE `users` SET `password` = ? WHERE `id` = ?;");
     $stmt->bind_param('si', $pwd, $uid);
     $success = $stmt->execute();
     if (!$success || $stmt->errno) {
         $this->errno = $stmt->errno;
         $this->error = 'Es ist ein Datenbankfehler aufgetreten. Bitte versuchen Sie es später noch einmal.';
     }
 }
Beispiel #2
0
 private function loadFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->stmt_init();
     $stmt->prepare("SELECT `id`, `heim`, `auswaerts` FROM `spiele` WHERE `id` = ?;");
     $stmt->bind_param('i', $this->id);
     if (!$stmt->execute()) {
         throw new mysqli_sql_exception($stmt->error, $stmt->errno);
     }
     $hId = 0;
     $aId = 0;
     $stmt->bind_result($this->id, $hId, $aId);
     if (!$stmt->fetch()) {
         throw new VereinExistiertNichtException();
     }
     $this->heim = new Verein($hId);
     $this->auswaerts = new Verein($aId);
     $stmt = $db->stmt_init();
     $stmt->prepare("SELECT `heim`, `auswaerts` FROM `ergebnisse` WHERE `spiel_id` = ?;");
     $stmt->bind_param('i', $this->id);
     if (!$stmt->execute()) {
         throw new mysqli_sql_exception($stmt->error, $stmt->errno);
     }
     $hTor = null;
     $aTor = null;
     $stmt->bind_result($hTor, $aTor);
     if ($stmt->fetch()) {
         $this->heimTore = $hTor;
         $this->auswaertsTore = $aTor;
     }
     $stmt->close();
     $stmt = null;
 }
Beispiel #3
0
 /**
  * Speichert den aktuellen Tipp in der Datenbank
  * @return bool true, wenn das Speichern erfolgreich war, false sonst
  */
 public function save()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("INSERT INTO `tipps`(`uid`, `spiel_id`, `heim`, `auswaerts`)\n            VALUES(?, ?, ?, ?);");
     $stmt->bind_param('iiii', $this->user->getId(), $this->spiel->getId(), $this->heim, $this->auswaerts);
     if (!$stmt->execute()) {
         return false;
     }
     return true;
 }
Beispiel #4
0
 private function loadFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `heim`, `auswaerts` FROM `tipps` WHERE `uid` = ? AND `spiel_id` = ?");
     $stmt->bind_param('ii', $this->uid, $this->spiel_id);
     $stmt->execute();
     $stmt->store_result();
     if ($stmt->num_rows === 0) {
         throw new TippExistiertNichtException();
     }
     $stmt->bind_result($this->heim, $this->auswaerts);
     $stmt->fetch();
 }
 private function loadSpieltageFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `spieltag` FROM `spieltage`;");
     $arr = array();
     $stmt->execute();
     $stmt->store_result();
     $id = 0;
     $stmt->bind_result($id);
     while ($stmt->fetch()) {
         $arr[] = $id;
     }
     return $arr;
 }
 private function writeIntoDatabase()
 {
     $uid = $_SESSION['session']->getUserId();
     $db = Database::getDbObject();
     foreach ($this->spiele as $id => $v) {
         $stmt = $db->prepare("INSERT INTO `tipps` VALUES(?,?,?,?)\n              ON DUPLICATE KEY UPDATE `heim` = VALUES(`heim`), `auswaerts` = VALUES(`auswaerts`);");
         $stmt->bind_param('iiii', $uid, $id, $v['heimTore'], $v['auswTore']);
         if (!$stmt->execute()) {
             $this->errno = $stmt->errno;
             $this->error = 'Es ist ein Datenbankfehler aufgetreten. Bitte versuchen Sie es später noch einmal. ' . 'Sollte dieser Fehler weiterhin auftreten, wenden Sie sich bitte an einen Administrator.';
             return false;
         }
         $stmt->close();
     }
     return true;
 }
Beispiel #7
0
 private function loadFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT * FROM `vereine` WHERE `id` = ?;");
     $stmt->bind_param('i', $this->id);
     if (!$stmt->execute()) {
         throw new mysqli_sql_exception($stmt->error, $stmt->errno);
     }
     $logo = '';
     $stmt->bind_result($this->id, $this->name, $this->kuerzel, $logo);
     if (!$stmt->fetch()) {
         throw new VereinExistiertNichtException();
     }
     $this->logo = base64_encode($logo);
     $stmt->close();
 }
 private function loadFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `title`, `content`, `requires_login` FROM `pages` WHERE `id` = ?;");
     $stmt->bind_param('s', $this->id);
     if (!$stmt->execute()) {
         throw new mysqli_sql_exception($stmt->error, $stmt->errno);
     }
     $stmt->store_result();
     if ($stmt->num_rows === 0) {
         throw new Error404Exception();
     }
     $bool = 0;
     $stmt->bind_result($this->title, $this->ctnt, $bool);
     $stmt->fetch();
     $this->requireLogin = $bool == 1;
 }
 /**
  * Laed die naechsten $this->n Spieltage aus der Datenbank und gibt sie als Array (int)=>(DateTime) zurueck
  * ( (spieltag)=>(Tippfrist) )
  * @return DateTime[]
  * @throws SpieltagExistiertNichtException
  */
 private function loadFromDatabase()
 {
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `spieltag`, `tipp_ende` FROM `spieltage` WHERE `tipp_ende` > NOW()\n            ORDER BY `tipp_ende` ASC LIMIT ?;");
     $stmt->bind_param('i', $this->n);
     $arr = array();
     if ($stmt->execute()) {
         $st = null;
         $tippEnde = null;
         $stmt->bind_result($st, $tippEnde);
         while ($stmt->fetch()) {
             $arr[$st] = new DateTime($tippEnde);
         }
     } else {
         throw new SpieltagExistiertNichtException();
     }
     return $arr;
 }
Beispiel #10
0
 private function loadFromDatabase()
 {
     $this->spiele = array();
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `id` FROM `spiele` WHERE `spieltag` = ?;");
     $stmt->bind_param('i', $this->spieltag);
     if (!$stmt->execute()) {
         throw new mysqli_sql_exception($stmt->error, $stmt->errno);
     }
     $stmt->store_result();
     if ($stmt->num_rows === 0) {
         throw new SpieltagExistiertNichtException();
     }
     /* */
     $id = 0;
     $stmt->bind_result($id);
     while ($stmt->fetch()) {
         $this->spiele[] = new Spiel($id);
     }
     $stmt->close();
 }
 private static function writeToreIntoDatabase($spieltag)
 {
     $db = Database::getDbObject();
     $arr = self::getSpieltag($spieltag);
     foreach ($arr['matchdata'] as $spiel) {
         if (is_null($spiel['match_results'])) {
             continue;
         }
         $stmt = $db->prepare("SELECT `id` FROM `spiele` WHERE `heim` = ? AND `auswaerts` = ?;");
         $stmt->bind_param('ii', $heim, $auswaerts);
         $heim = (int) $spiel['id_team1'];
         $auswaerts = (int) $spiel['id_team2'];
         $stmt->execute();
         $stmt->store_result();
         if ($stmt->num_rows > 0) {
             $stmt->bind_result($spiel_id);
             $stmt->fetch();
             $stmt->prepare("SELECT `spiel_id` FROM `ergebnisse` WHERE `spiel_id` = ?;");
             $stmt->bind_param('i', $spiel_id);
             $stmt->execute();
             $stmt->store_result();
             if ($stmt->num_rows === 0) {
                 $heimTore = 0;
                 $auswTore = 0;
                 foreach ($spiel['match_results']['match_result'] as $res) {
                     if ($res['result_name'] === 'Endergebnis') {
                         $heimTore = $res['points_team1'];
                         $auswTore = $res['points_team2'];
                         break;
                     }
                 }
                 $stmt->prepare("INSERT INTO `ergebnisse` VALUES(?,?,?);");
                 $stmt->bind_param('iii', $spiel_id, $heimTore, $auswTore);
                 $stmt->execute();
             }
         }
     }
 }
Beispiel #12
0
 private function generateNaechstenSpieltag()
 {
     $db = Database::getDbObject();
     $query = "SELECT `spieltag` FROM `spieltage` WHERE `datum` >= CURDATE() LIMIT 1;";
     $stmt = $db->prepare($query);
     $stmt->execute();
     $stmt->store_result();
     if ($stmt->num_rows > 0) {
         $id = 0;
         $stmt->bind_result($id);
         $stmt->fetch();
         $spieltag = new Spieltag($id);
         $st = array();
         foreach ($spieltag as $v) {
             $st[] = $v;
         }
         $this->raintpl->assign('naechsterSpieltag', true);
         $this->raintpl->assign('naechsteSpiele', $st);
         $this->raintpl->assign('spieltagNaechst', $id);
     } else {
         $this->raintpl->assign('naechsterSpieltag', false);
     }
 }
Beispiel #13
0
 public function checkPermanentLogin()
 {
     if (!isset($_COOKIE['login_token'])) {
         return;
     }
     $regex = '/^[0-9a-f]{64}[0-9]{1,5}$/';
     if (!preg_match($regex, $_COOKIE['login_token'])) {
         return;
     }
     $series = substr($_COOKIE['login_token'], 0, 32);
     $token = substr($_COOKIE['login_token'], 32, 32);
     $uid = (int) substr($_COOKIE['login_token'], 64);
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `token`, `valid` FROM `login_token` WHERE `uid` = ? AND `series` = ?;");
     $stmt->bind_param('is', $uid, $series);
     if (!$stmt->execute()) {
         return;
     }
     $stmt->store_result();
     if ($stmt->num_rows < 1) {
         return;
     }
     $dbtoken = null;
     $valid = null;
     $stmt->bind_result($dbtoken, $valid);
     $stmt->fetch();
     if ($token === $dbtoken) {
         // valid: Login user
         $valid = new DateTime($valid);
         $now = new DateTime();
         if ($valid < $now) {
             $stmt = $db->prepare("DELETE FROM `login_token` WHERE `uid` = ? AND `series` = ?;");
             $stmt->bind_param('is', $uid, $series);
             $stmt->execute();
         } else {
             $username = User::getNameById($uid);
             $user = new User($username);
             $this->login = true;
             $this->userName = $user->getName();
             $newtoken = $this->token();
             $stmt = $db->prepare("UPDATE `login_token` SET `token` = ? WHERE `uid` = ? AND `series` = ?;");
             $stmt->bind_param('sis', $newtoken, $uid, $series);
             if ($stmt->execute()) {
                 $exp = $valid->format('U');
                 setcookie('login_token', $series . $token . $newtoken, $exp, TIPPSPIEL_CONF_PATH, TIPPSPIEL_CONF_DOMAIN, false, true);
             }
         }
     } else {
         // invalid: inform the user
         $this->errno = 1;
         $this->error = 'Anscheinend wurde Ihr Login-Cookie gestohlen. Aus Sicherheitsgründen wurden Sie ausgelogt' . '. Sollte dieser Fehler weiterhin auftreten, überprüfen Sie bitte Ihren Rechner auf Schadprogramme.';
         $stmt = $db->prepare("DELETE FROM `login_token` WHERE `uid` = ?;");
         $stmt->bind_param('i', $uid);
         $stmt->execute();
     }
 }
Beispiel #14
0
 /**
  * Gibt die Punkte als mehrdimensionales Array zurueck TODO: Struktur des Arrays beschreiben
  * @return array Die Punkte
  */
 public function getPunkteDetail()
 {
     $gesamtPkt = 0;
     $gesamtAnzahl = 0;
     $ergebnisPunkte = 0;
     $differenzPunkte = 0;
     $siegerPunkte = 0;
     $falschAnzahl = 0;
     $db = Database::getDbObject();
     $stmt = $db->prepare("SELECT `spiel_id` FROM `tipps` WHERE `uid` = ?;");
     $stmt->bind_param('i', $this->id);
     if ($stmt->execute()) {
         if ($stmt->store_result()) {
             $spiel_id = 0;
             $stmt->bind_result($spiel_id);
             while ($stmt->fetch()) {
                 $tipp = new DbTipp($this->getId(), $spiel_id);
                 if ($tipp->getPunkte() === TIPPSPIEL_CONF_ERGEBNIS_KORREKT) {
                     $ergebnisPunkte += TIPPSPIEL_CONF_ERGEBNIS_KORREKT;
                 } else {
                     if ($tipp->getPunkte() === TIPPSPIEL_CONF_DIFFERENZ_KORREKT) {
                         $differenzPunkte += TIPPSPIEL_CONF_DIFFERENZ_KORREKT;
                     } else {
                         if ($tipp->getPunkte() === TIPPSPIEL_CONF_SIEGER_KORREKT) {
                             $siegerPunkte += TIPPSPIEL_CONF_SIEGER_KORREKT;
                         } else {
                             if ($tipp->getPunkte() === 0) {
                                 $falschAnzahl++;
                             }
                         }
                     }
                 }
                 $gesamtAnzahl++;
                 $gesamtPkt += $tipp->getPunkte();
             }
         }
     }
     return array('gesamt' => array('anzahl' => $gesamtAnzahl, 'punkte' => $gesamtPkt), 'ergebnis' => array('anzahl' => $ergebnisPunkte / TIPPSPIEL_CONF_ERGEBNIS_KORREKT, 'punkte' => $ergebnisPunkte), 'differenz' => array('anzahl' => $differenzPunkte / TIPPSPIEL_CONF_DIFFERENZ_KORREKT, 'punkte' => $differenzPunkte), 'sieger' => array('anzahl' => $siegerPunkte / TIPPSPIEL_CONF_SIEGER_KORREKT, 'punkte' => $siegerPunkte), 'falsch' => array('anzahl' => $falschAnzahl));
 }