2023-12-06 08:33:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Programmiert durch Samuel Wolff
|
2024-01-08 11:14:17 +01:00
|
|
|
// Getestet durch: Samuel Wolff
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:19:27 +01:00
|
|
|
namespace ppb\Model;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-14 16:59:16 +01:00
|
|
|
use ppb\Library\Msg;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
class BenutzerModel extends Database
|
|
|
|
{
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-11 15:34:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Updated einen Benutzer
|
|
|
|
*
|
|
|
|
* @param $elternId Die Id des Elternaccounts
|
|
|
|
* @param $data Die gegebenen Daten
|
|
|
|
*
|
|
|
|
*/
|
2023-12-18 08:16:21 +01:00
|
|
|
public function updateBenutzer($elternId, $data)
|
|
|
|
{
|
2023-12-06 08:33:25 +01:00
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
|
2024-01-08 11:14:17 +01:00
|
|
|
$sql = "UPDATE Benutzerkonto SET";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
foreach ($data as $index => $value) {
|
2024-01-08 11:14:17 +01:00
|
|
|
$sql .= " " . $index . " = :" . $index . ",";
|
2023-12-18 08:16:21 +01:00
|
|
|
$params[":" . $index] = $value;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
2024-01-08 11:14:17 +01:00
|
|
|
$sql = substr($sql, 0, strlen($sql) - 1) . " WHERE id = :benutzerId;";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$params[":benutzerId"] = $elternId;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
try {
|
2023-12-06 08:33:25 +01:00
|
|
|
$stmt = $pdo->prepare($sql);
|
2023-12-18 08:19:27 +01:00
|
|
|
$stmt->execute($params);
|
2023-12-18 08:16:21 +01:00
|
|
|
} catch (\PDOException $e) {
|
2024-01-08 11:14:17 +01:00
|
|
|
echo $sql;
|
|
|
|
echo json_encode($params);
|
2023-12-06 08:33:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2023-12-06 08:33:25 +01:00
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2023-12-06 08:33:25 +01:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-12-11 15:34:55 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Fügt einen neuen Benutzer in der Datenbank hinzu
|
|
|
|
*
|
|
|
|
* @param $data Die gegebenen Daten
|
|
|
|
*
|
|
|
|
*/
|
2023-12-18 08:16:21 +01:00
|
|
|
public function insertBenutzer($data)
|
|
|
|
{
|
2023-12-06 08:33:25 +01:00
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2024-01-08 11:14:17 +01:00
|
|
|
$sql = "INSERT INTO Benutzerkonto (";
|
2023-12-18 08:16:21 +01:00
|
|
|
|
|
|
|
foreach ($data as $index => $value) {
|
|
|
|
$sql .= $index . ", ";
|
2024-01-08 11:14:17 +01:00
|
|
|
$params[":" . $index] = $index;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
2023-12-18 08:16:21 +01:00
|
|
|
|
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ") VALUES (";
|
|
|
|
|
2024-01-08 11:14:17 +01:00
|
|
|
foreach ($data as $index => $value) {
|
|
|
|
$sql .= ":" . $index . " ,";
|
|
|
|
$params[":" . $index] = $value;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
2023-12-18 08:16:21 +01:00
|
|
|
|
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ");";
|
|
|
|
|
2024-01-08 11:14:17 +01:00
|
|
|
echo $sql;
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
try {
|
2023-12-06 08:33:25 +01:00
|
|
|
$stmt = $pdo->prepare($sql);
|
2023-12-18 08:19:27 +01:00
|
|
|
$stmt->execute($params);
|
2023-12-18 08:16:21 +01:00
|
|
|
} catch (\PDOException $e) {
|
2024-01-17 10:58:49 +01:00
|
|
|
echo "Faulty Sql? " . $sql;
|
2023-12-06 08:33:25 +01:00
|
|
|
return false;
|
|
|
|
}
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2023-12-06 08:33:25 +01:00
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2023-12-06 08:33:25 +01:00
|
|
|
return $result;
|
|
|
|
}
|
2023-12-18 08:16:21 +01:00
|
|
|
|
2024-01-15 09:39:19 +01:00
|
|
|
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) {
|
2024-01-17 10:58:49 +01:00
|
|
|
echo "Faulty Sql? " . $sql;
|
2024-01-15 09:39:19 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
|
|
|
}
|
2024-01-18 09:31:09 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
?>
|