Übernahme der Datein für weitere Bearbeitung
This commit is contained in:
parent
7402018df0
commit
9cd7882eb7
12 changed files with 66156 additions and 0 deletions
90
class/DBClass.php
Normal file
90
class/DBClass.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<!DOCTYPE html>
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Christian Brüggen
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Stellt eine Verbindung zu einer DB bereit
|
||||
*
|
||||
* @author Christian Brüggen
|
||||
*/
|
||||
class DBClass extends stdClass
|
||||
{
|
||||
|
||||
/**
|
||||
* Zeiger auf die DB
|
||||
* @var PDO
|
||||
*/
|
||||
private $pdo = null;
|
||||
|
||||
/**
|
||||
* Das Abgrage-Statement
|
||||
* @var PDOStatement
|
||||
*/
|
||||
private $stmt = null;
|
||||
|
||||
/**
|
||||
* Verbindet mit Server und DB
|
||||
* @param string $dbname Name der Datenbank
|
||||
* @param string $user Benutzername
|
||||
* @param string $passwort Passwort des Benutzers
|
||||
* @param string $host Adresse des Datenbankservers
|
||||
*/
|
||||
public function __construct($dbname, $user, $passwort, $host)
|
||||
{
|
||||
try {
|
||||
$this->pdo = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $user, $passwort);
|
||||
} catch (PDOException $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt eine SQL-Anweisung ohne Rückgabe eines Datensatzes aus
|
||||
* @param string $querystring
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function query($querystring, array $params = array())
|
||||
{
|
||||
try {
|
||||
$this->stmt = $this->pdo->prepare($querystring);
|
||||
return $this->stmt->execute($params);
|
||||
} catch (PDOException $ex) {
|
||||
$this->stmt = null;
|
||||
} catch (Exception $ex) {
|
||||
$this->stmt = null;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Führt eine SQL-Anweisung mit Rückgabe eines Datensatzes aus
|
||||
* @param string $querystring
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
public function select($querystring, array $params = array())
|
||||
{
|
||||
if ($this->query($querystring, $params)) {
|
||||
return $this->stmt->fetchAll();
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
110
class/Datenbank.php
Normal file
110
class/Datenbank.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Christian Brüggen
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
class Datenbank extends DBClass
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $passwort
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkLogin(string $name, string $passwort)
|
||||
{
|
||||
$sql = 'SELECT * FROM Test_v2 WHERE Name=:name AND Code=:passwort';
|
||||
|
||||
$params = array(
|
||||
'name' => strtolower($name),
|
||||
'passwort' => $passwort
|
||||
);
|
||||
|
||||
$result = $this->select($sql, $params);
|
||||
|
||||
if (count($result) == 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasAlredySelected(string $name)
|
||||
{
|
||||
$sql = 'SELECT * FROM Test_v2 WHERE Name=:name AND Kurs IS NOT NULL AND Kurs2 IS NOT NULL AND Kurs3 IS NOT NULL ';
|
||||
|
||||
$params = array(
|
||||
'name' => $name
|
||||
);
|
||||
|
||||
$result = $this->select($sql, $params);
|
||||
|
||||
if (count($result) == 1) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return array strings
|
||||
*/
|
||||
public function selectKurse()
|
||||
{
|
||||
$sql = 'SELECT name, stunde FROM Kurse';
|
||||
|
||||
return $this->select($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param array $kurse
|
||||
* @return boolean
|
||||
*/
|
||||
public function insertSelection(string $name, array $kurse)
|
||||
{
|
||||
if (count($kurse) == 3) {
|
||||
$sql = 'UPDATE Test_v2 SET Kurs=:kurs1, Kurs2=:kurs2, Kurs3=:kurs3 WHERE name =:name';
|
||||
|
||||
$params = array(
|
||||
'name' => $name,
|
||||
'kurs1' => $kurse[0],
|
||||
'kurs2' => $kurse[1],
|
||||
'kurs3' => $kurse[2]
|
||||
);
|
||||
|
||||
return $this->query($sql, $params);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Nichtmehr nötig
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
/*public function updateHasAlredySelected(string $name)
|
||||
{
|
||||
return true;
|
||||
}*/
|
||||
}
|
71
class/Session.php
Normal file
71
class/Session.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<!DOCTYPE html>
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Christian Brüggen
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrapper für eine Session
|
||||
*
|
||||
* @author Christian Brüggen
|
||||
*/
|
||||
class Session
|
||||
{
|
||||
/**
|
||||
* Konstrucktor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt einen Wert für einen Key im Session-Array
|
||||
* @param string $key Key
|
||||
* @param string $value Wert
|
||||
* @return string
|
||||
*/
|
||||
public function set(String $key, String $value = "")
|
||||
{
|
||||
return $_SESSION[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Wert für einen Key im Session-Array zurück
|
||||
* @param string $key Key
|
||||
* @return string
|
||||
*/
|
||||
public function get(String $key)
|
||||
{
|
||||
return $_SESSION[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Zerstört eine Session und ihre Werte
|
||||
*/
|
||||
public function destroy()
|
||||
{
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Startet eine Session
|
||||
*/
|
||||
public function start()
|
||||
{
|
||||
session_start();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue