177 lines
5.8 KiB
PHP
177 lines
5.8 KiB
PHP
<?php
|
|
|
|
function DatabaseShow($table, $columns = "*", $where = "", ...$values) {
|
|
include_once 'DatabaseConnect.php';
|
|
$conn = db_connect();
|
|
|
|
$sql = "SELECT $columns FROM `$table`";
|
|
|
|
if (!empty($where)) {
|
|
$sql .= " WHERE $where";
|
|
}
|
|
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
if (!$stmt) {
|
|
die("Fehler beim Prepare: " . $conn->error);
|
|
}
|
|
|
|
if (!$stmt->execute($values)) {
|
|
die("Fehler beim Execute: " . $stmt->error);
|
|
}
|
|
|
|
$result = $stmt->get_result();
|
|
return $result->fetch_all(MYSQLI_ASSOC);
|
|
}
|
|
|
|
|
|
function DatabaseInsert($table, $columns, ...$values) {
|
|
include_once 'DatabaseConnect.php';
|
|
$conn = db_connect();
|
|
|
|
$placeholders = rtrim(str_repeat("?,", count($values)), ",");
|
|
$sql = "INSERT INTO `$table` ($columns) VALUES ($placeholders)";
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
if (!$stmt) {
|
|
die("Fehler beim Prepare: " . $conn->error);
|
|
}
|
|
|
|
if (!$stmt->execute($values)) {
|
|
die("Fehler beim Execute: " . $stmt->error);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function DatabaseDelete($table, $where, ...$values) {
|
|
include_once 'DatabaseConnect.php';
|
|
$conn = db_connect();
|
|
|
|
$sql = "DELETE FROM `$table` WHERE $where";
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
if (!$stmt) {
|
|
die("Fehler beim Prepare: " . $conn->error);
|
|
}
|
|
|
|
if (!$stmt->execute($values)) {
|
|
die("Fehler beim Execute: " . $stmt->error);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function DatabaseUpdate($table, $set, $where, ...$values) {
|
|
include_once 'DatabaseConnect.php';
|
|
$conn = db_connect();
|
|
|
|
$sql = "UPDATE `$table` SET $set WHERE $where";
|
|
$stmt = $conn->prepare($sql);
|
|
|
|
if (!$stmt) {
|
|
die("Fehler beim Prepare: " . $conn->error);
|
|
}
|
|
|
|
if (!$stmt->execute($values)) {
|
|
die("Fehler beim Execute: " . $stmt->error);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
function DatabaseShowWithFK($table, $fkMap = [], $columns = "*", $where = "", ...$values) {
|
|
include_once 'DatabaseConnect.php';
|
|
$conn = db_connect();
|
|
|
|
$select = is_array($columns) ? implode(", ", $columns) : $columns;
|
|
|
|
$sql = "SELECT $select FROM `$table`";
|
|
if (!empty($where)) {
|
|
$sql .= " WHERE $where";
|
|
}
|
|
|
|
$stmt = $conn->prepare($sql);
|
|
if (!$stmt) die("Fehler beim Prepare: " . $conn->error);
|
|
|
|
if (!$stmt->execute($values)) die("Fehler beim Execute: " . $stmt->error);
|
|
|
|
$result = $stmt->get_result();
|
|
if (!$result) die("Fehler beim get_result: " . $stmt->error);
|
|
|
|
$columnsResult = [];
|
|
while ($fieldinfo = $result->fetch_field()) {
|
|
$columnsResult[] = $fieldinfo->name;
|
|
}
|
|
|
|
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
|
|
|
foreach ($rows as &$row) {
|
|
foreach ($fkMap as $fkColumn => $fkInfo) {
|
|
if (isset($row[$fkColumn]) && $row[$fkColumn] !== null) {
|
|
$fkStmt = $conn->prepare(
|
|
"SELECT {$fkInfo['value']} FROM `{$fkInfo['table']}` WHERE {$fkInfo['key']} = ?"
|
|
);
|
|
if (!$fkStmt) die("Fehler beim Prepare FK: " . $conn->error);
|
|
|
|
$fkStmt->bind_param("i", $row[$fkColumn]);
|
|
$fkStmt->execute();
|
|
$fkResult = $fkStmt->get_result();
|
|
$fkRow = $fkResult->fetch_assoc();
|
|
|
|
$row[$fkColumn] = $fkRow ? $fkRow[$fkInfo['value']] : null;
|
|
}
|
|
}
|
|
}
|
|
|
|
return [
|
|
"rows" => $rows
|
|
];
|
|
}
|
|
|
|
$Berufsschulberichte = [
|
|
"FACH_S1" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S1" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S1" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S2" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S2" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S2" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S3" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S3" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S3" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S4" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S4" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S4" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S5" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S5" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S5" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S6" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S6" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S6" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S7" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S7" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S7" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
|
|
"FACH_S8" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"LEHRER_S8" => ["table" => "Lehrer", "key" => "ID", "value" => "NAME"],
|
|
"RAUM_S8" => ["table" => "Raum", "key" => "ID", "value" => "Raum_NR"],
|
|
];
|
|
|
|
$Stundenplan = [
|
|
"MO" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"DI" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"MI" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"DO" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
"FR" => ["table" => "Fach", "key" => "ID", "value" => "Fach"],
|
|
];
|
|
|
|
$Berechtigungen = [
|
|
"BENUTZER_ID" => ["table" => "Benutzer", "key" => "ID", "value" => "ID"],
|
|
"BERECHTIGUNGEN_ID" => ["table" => "Berechtigungen", "key" => "ID", "value" => "ID"]
|
|
]; |