148 lines
3.1 KiB
PHP
148 lines
3.1 KiB
PHP
<?php
|
|
|
|
// Programmiert durch Samuel Wolff
|
|
// Getestet durch: Samuel Wolff
|
|
|
|
namespace ppb\Model;
|
|
|
|
use ppb\Library\Msg;
|
|
|
|
class BenutzerModel extends Database
|
|
{
|
|
|
|
|
|
/**
|
|
*
|
|
* Updated einen Benutzer
|
|
*
|
|
* @param $elternId Die Id des Elternaccounts
|
|
* @param $data Die gegebenen Daten
|
|
*
|
|
*/
|
|
public function updateBenutzer($elternId, $data)
|
|
{
|
|
$pdo = $this->linkDB();
|
|
|
|
$params = array();
|
|
|
|
$sql = "UPDATE Benutzerkonto SET";
|
|
|
|
foreach ($data as $index => $value) {
|
|
$sql .= " " . $index . " = :" . $index . ",";
|
|
$params[":" . $index] = $value;
|
|
}
|
|
|
|
$sql = substr($sql, 0, strlen($sql) - 1) . " WHERE id = :benutzerId;";
|
|
|
|
$params[":benutzerId"] = $elternId;
|
|
|
|
try {
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
} catch (\PDOException $e) {
|
|
echo $sql;
|
|
echo json_encode($params);
|
|
return false;
|
|
}
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
*
|
|
* Fügt einen neuen Benutzer in der Datenbank hinzu
|
|
*
|
|
* @param $data Die gegebenen Daten
|
|
*
|
|
*/
|
|
public function insertBenutzer($data)
|
|
{
|
|
$pdo = $this->linkDB();
|
|
|
|
$params = array();
|
|
|
|
$sql = "INSERT INTO Benutzerkonto (";
|
|
|
|
foreach ($data as $index => $value) {
|
|
$sql .= $index . ", ";
|
|
$params[":" . $index] = $index;
|
|
}
|
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ") VALUES (";
|
|
|
|
foreach ($data as $index => $value) {
|
|
$sql .= ":" . $index . " ,";
|
|
$params[":" . $index] = $value;
|
|
}
|
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ");";
|
|
|
|
echo $sql;
|
|
|
|
try {
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
} catch (\PDOException $e) {
|
|
echo "Faulty Sql? " . $sql;
|
|
return false;
|
|
}
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
return $result;
|
|
}
|
|
|
|
public function nextId()
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
$sql = "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 'Benutzerkonto'; ";
|
|
|
|
try {
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute();
|
|
} catch (\PDOException $e) {
|
|
echo "Faulty Sql? " . $sql;
|
|
return false;
|
|
}
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
public function anmeldeVersuch()
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
$params = array();
|
|
|
|
$params[":Benutzername"] = $_GET["Benutzername"];
|
|
$params[":passwort"] = $_GET["passwort"];
|
|
|
|
$sql = "SELECT * FROM Benutzerkonto WHERE name = :Benutzername AND passwort = :passwort";
|
|
|
|
try {
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
} catch (\PDOException $e) {
|
|
return false;
|
|
}
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
if (count($result) > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
?>
|