From b294ceeec80e663938b929bea559567a48e8b3b8 Mon Sep 17 00:00:00 2001 From: kknobloch Date: Mon, 21 Apr 2025 21:34:26 +0200 Subject: [PATCH] --- config/config.php | 18 ++++ core/App.php | 23 +++++ core/Database.php | 26 +++++ core/Request.php | 58 +++++++++++ nbproject/project.properties | 7 ++ nbproject/project.xml | 9 ++ src/controller/MainController.php | 25 +++++ src/model/AnschriftModel.php | 74 +++++++++++++ src/model/BankverbindungModel.php | 33 ++++++ src/model/HotelModel.php | 131 ++++++++++++++++++++++++ src/view/home.php | 2 + src/view/hotel_edit.php | 83 +++++++++++++++ src/view/hotel_edit_adresse.php | 102 ++++++++++++++++++ src/view/hotel_edit_rechnung.php | 109 ++++++++++++++++++++ src/view/hotel_edit_rechnung_archiv.php | 43 ++++++++ src/view/hotels.php | 71 +++++++++++++ src/view/templates/footer.php | 3 + src/view/templates/header.php | 77 ++++++++++++++ web/assets/css/vwl.css | 8 ++ web/index.php | 10 ++ web/login.php | 60 +++++++++++ web/logout.php | 5 + 22 files changed, 977 insertions(+) create mode 100644 config/config.php create mode 100644 core/App.php create mode 100644 core/Database.php create mode 100644 core/Request.php create mode 100644 nbproject/project.properties create mode 100644 nbproject/project.xml create mode 100644 src/controller/MainController.php create mode 100644 src/model/AnschriftModel.php create mode 100644 src/model/BankverbindungModel.php create mode 100644 src/model/HotelModel.php create mode 100644 src/view/home.php create mode 100644 src/view/hotel_edit.php create mode 100644 src/view/hotel_edit_adresse.php create mode 100644 src/view/hotel_edit_rechnung.php create mode 100644 src/view/hotel_edit_rechnung_archiv.php create mode 100644 src/view/hotels.php create mode 100644 src/view/templates/footer.php create mode 100644 src/view/templates/header.php create mode 100644 web/assets/css/vwl.css create mode 100644 web/index.php create mode 100644 web/login.php create mode 100644 web/logout.php diff --git a/config/config.php b/config/config.php new file mode 100644 index 0000000..991b5cc --- /dev/null +++ b/config/config.php @@ -0,0 +1,18 @@ + '127.0.0.1', + 'dbname' => 'vwl', + 'user' => 'root', + 'password' => '', + 'charset' => 'utf8mb4' +]; +/* +return [ + 'host' => '148.251.96.181', + 'dbname' => 'c1vwl', + 'user' => 'c1gutscheinserver', + 'password' => 'SommerNacht!2025', + 'charset' => 'utf8mb4' +]; +*/ \ No newline at end of file diff --git a/core/App.php b/core/App.php new file mode 100644 index 0000000..1466dec --- /dev/null +++ b/core/App.php @@ -0,0 +1,23 @@ +method = $_GET['page']; + } + + require_once '../src/controller/' . $this->controller . '.php'; + $this->controller = new $this->controller; + + if (!method_exists($this->controller, $this->method)) { + $this->method = 'home'; + } + + call_user_func_array([$this->controller, $this->method], $this->params); + } +} diff --git a/core/Database.php b/core/Database.php new file mode 100644 index 0000000..52bbb0c --- /dev/null +++ b/core/Database.php @@ -0,0 +1,26 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC + ]); + } catch (PDOException $e) { + die("Datenbankverbindung fehlgeschlagen: " . $e->getMessage()); + } + } + + return self::$pdo; + } +} diff --git a/core/Request.php b/core/Request.php new file mode 100644 index 0000000..660b197 --- /dev/null +++ b/core/Request.php @@ -0,0 +1,58 @@ + + + org.netbeans.modules.php.project + + + vwlsupport + + + diff --git a/src/controller/MainController.php b/src/controller/MainController.php new file mode 100644 index 0000000..c7f89a2 --- /dev/null +++ b/src/controller/MainController.php @@ -0,0 +1,25 @@ +db = Database::connect(); + $this->frmFields = $this->dbFields; // Standard-Feldmapping + } + + public function findById($id): ?array { + $stmt = $this->db->prepare("SELECT * FROM vwl_anschrift WHERE id = :id"); + $stmt->execute(['id' => $id]); + return $stmt->fetch(PDO::FETCH_ASSOC) ?: null; + } + + public function update($id, $formData, $rgAnschrift = false) { + $formFields = $rgAnschrift ? $this->rgFrmFields : $this->frmFields; + $data = $this->mapFormToDbFields($formData, $formFields); + + if (empty($data)) { + return false; + } + + if (empty($id)) { + return $this->insertData($data); + } + + return $this->updateData($id, $data); + } + + private function insertData(array $data): int { + $fields = array_keys($data); + $placeholders = array_map(fn($f) => ":$f", $fields); + $sql = "INSERT INTO vwl_anschrift (" . implode(', ', $fields) . ") VALUES (" . implode(', ', $placeholders) . ")"; + $stmt = $this->db->prepare($sql); + $stmt->execute($data); + return (int)$this->db->lastInsertId(); + } + + private function updateData($id, array $data): int { + $assignments = array_map(fn($f) => "$f = :$f", array_keys($data)); + $sql = "UPDATE vwl_anschrift SET " . implode(', ', $assignments) . " WHERE id = :id"; + $stmt = $this->db->prepare($sql); + $data['id'] = $id; + $stmt->execute($data); + return $id; + } + + private function mapFormToDbFields(array $formData, array $formFields): array { + $mapped = []; + foreach ($this->dbFields as $i => $dbField) { + $formField = $formFields[$i] ?? null; + if ($formField && isset($formData[$formField])) { + $mapped[$dbField] = $formData[$formField]; + } + } + return $mapped; + } +} diff --git a/src/model/BankverbindungModel.php b/src/model/BankverbindungModel.php new file mode 100644 index 0000000..04090d9 --- /dev/null +++ b/src/model/BankverbindungModel.php @@ -0,0 +1,33 @@ +prepare("SELECT * FROM vwl_bankverbindung WHERE id = :id"); + $stmt->execute(['id' => $id]); + return $stmt->fetch(PDO::FETCH_ASSOC); + } + + public static function update($id, $data) + { + $pdo = Database::connect(); + $stmt = $pdo->prepare(" + UPDATE vwl_bankverbindung SET + bank = :bank, + iban = :iban, + bic = :bic, + inhaber = :inhaber + WHERE id = :id + "); + $stmt->execute([ + 'bank' => $data['bank'], + 'iban' => $data['iban'], + 'bic' => $data['bic'], + 'inhaber' => $data['inhaber'], + 'id' => $data['bankid'] + ]); + } +} diff --git a/src/model/HotelModel.php b/src/model/HotelModel.php new file mode 100644 index 0000000..3e27249 --- /dev/null +++ b/src/model/HotelModel.php @@ -0,0 +1,131 @@ +db = Database::connect(); + $this->mdlAnschr = new AnschriftModel(); + } + + public function getHotelById($id) { + $stmt = $this->db->prepare("SELECT * FROM vwl_hotel WHERE id = ?"); + $stmt->execute([$id]); + return $stmt->fetch(); + } + + public function getAnschriftById($id) { + $stmt = $this->db->prepare("SELECT * FROM vwl_anschrift WHERE id = ?"); + $stmt->execute([$id]); + return $stmt->fetch(); + } + + public function getBankverbindungById($id) { + $stmt = $this->db->prepare("SELECT * FROM vwl_bankverbindung WHERE id = ?"); + $stmt->execute([$id]); + return $stmt->fetch(); + } + + public function updateHotel($data) { + + $fieldsToUpdate = array_intersect_key($data, array_flip($this->allowedFields)); + if (empty($fieldsToUpdate)) { + return false; + } + + // Baue SQL-Statement + $setParts = []; + foreach ($fieldsToUpdate as $field => $value) { + $setParts[] = "`$field` = :$field"; + } + $sql = "UPDATE vwl_hotel SET " . implode(', ', $setParts) . " WHERE id = :id"; + + $stmt = $this->db->prepare($sql); + + // Bind-Werte + $fieldsToUpdate['id'] = $data['id']; + return $stmt->execute($fieldsToUpdate); + } + + public function findByIdWithRelations($id) { + $stmt = $this->db->prepare(" + SELECT * FROM vwl_hotel WHERE id = :id + "); + $stmt->execute(['id' => $id]); + $hotel = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($hotel) { + $hotel['anschrift'] = $this->mdlAnschr->findById($hotel['anschriftid']); + $hotel['bankverbindung'] = BankverbindungModel::findById($hotel['bankid']); + $hotel['rg_anschrift'] = $this->mdlAnschr->findById($hotel['rg_anschriftid']); + $hotel['rg_bankverbindung'] = BankverbindungModel::findById($hotel['rg_bankid']); + } + + return $hotel; + } + + public function getRechnungen($id) { + $stmt = $this->db->prepare(" + SELECT r.*, h.hotelnummer + FROM vwl_hotel_rechnung r + JOIN vwl_hotel h ON r.hotelid = h.id + WHERE h.id = :hotelid + ORDER BY r.rechnungsdatum DESC + "); + + $stmt->execute(['hotelid' => $id]); + $stmt->fetchAll(); + } + + public function updateWithRelations($id, $data) { + $this->db->beginTransaction(); + try { + // 1. Anschrift aktualisieren + + $subid = $this->mdlAnschr->update($data['anschriftid'], $data, false); + if(empty($subid) == false) { + $data['anschriftid'] = $subid; + } + // 1.1 Rechungsanschrift aktualisieren + $subidRg = $this->mdlAnschr->update($data['rg_anschriftid'], $data, true); + if(empty($subidRg) == false) { + $data['rg_anschriftid'] = $subidRg; + } + + // 2. Bankverbindung aktualisieren + BankverbindungModel::update($data['bankid'], $data); + + // 3. Hotel aktualisieren + $fieldsToUpdate = array_intersect_key($data, array_flip($this->allowedFields)); + if (empty($fieldsToUpdate)) { + return false; + } + + $this->updateHotel($data); + + $this->db->commit(); + return true; + } catch (Exception $e) { + $this->db->rollBack(); + return false; + } + } + + + + +} diff --git a/src/view/home.php b/src/view/home.php new file mode 100644 index 0000000..7e3ae7d --- /dev/null +++ b/src/view/home.php @@ -0,0 +1,2 @@ +

Startseite

+

Willkommen auf der Startseite deiner Anwendung!

diff --git a/src/view/hotel_edit.php b/src/view/hotel_edit.php new file mode 100644 index 0000000..b113acb --- /dev/null +++ b/src/view/hotel_edit.php @@ -0,0 +1,83 @@ +updateWithRelations($hotelId, $data); + + if ($success) { + $message = '
✅ Daten erfolgreich gespeichert.
'; + } else { + $message = '
❌ Fehler beim Speichern der Daten.
'; + } +} + +// Daten neu laden nach dem Speichern (oder beim ersten Aufruf) +$hotel = $hotelModel->findByIdWithRelations($hotelId); +$anschrift = $hotel['anschrift']; +$bankverbindung = $hotel['bankverbindung']; +$rganschrift = $hotel['rg_anschrift'] ?? []; +$rgbankverbindung = $hotel['rg_bankverbindung']; +$rechnungen = $hotelModel->getRechnungen($hotelId); +?> +

Hotel:

+ +
+ + + + + + + + + +
+ +
+ +
+ + +
+ +
+ + +
+ +
+
+ + + +
+ diff --git a/src/view/hotel_edit_adresse.php b/src/view/hotel_edit_adresse.php new file mode 100644 index 0000000..6950e0f --- /dev/null +++ b/src/view/hotel_edit_adresse.php @@ -0,0 +1,102 @@ +
+
+
+ + +
+
+ + +
+
+ +
+ > + +
+
+
+ +
+ > + +
+
+
+ + +
+
+ +
Anschrift
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ +
Bankverbindung
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ + +
+
diff --git a/src/view/hotel_edit_rechnung.php b/src/view/hotel_edit_rechnung.php new file mode 100644 index 0000000..4368053 --- /dev/null +++ b/src/view/hotel_edit_rechnung.php @@ -0,0 +1,109 @@ +
+
Rechnungsanschrift
+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
Umsatzsteuer
+
+ +
+ + +
+ + +
+ +
+ > + + + > + + + > + +
+
+
+
Provision
+
+ +
+ + +
+ + +
+ +
+ > + + + > + +
+
+
+ +
Rechnungslauf
+ + +
diff --git a/src/view/hotel_edit_rechnung_archiv.php b/src/view/hotel_edit_rechnung_archiv.php new file mode 100644 index 0000000..a70ec52 --- /dev/null +++ b/src/view/hotel_edit_rechnung_archiv.php @@ -0,0 +1,43 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
RechnungsnummerRechnungsdatumZeitraumRechnungsbetragAktionen
+ + PDF + +
+ + + +
+
Keine Rechnungen vorhanden.
+
diff --git a/src/view/hotels.php b/src/view/hotels.php new file mode 100644 index 0000000..729c996 --- /dev/null +++ b/src/view/hotels.php @@ -0,0 +1,71 @@ +query("SELECT id, hotelnummer, hotelname, rg_vondatum, rg_bisdatum, status FROM vwl_hotel ORDER BY hotelname"); +$hotels = $stmt->fetchAll(); +?> + +

Hotel-Liste

+
+ + + + + + + + + + + + + + + + + + + + + +
Hotel-Nr + Name + + Von-DatumBis-DatumStatus
format('d.m.Y') : '' ?>format('d.m.Y') : '' ?>
+
+ + diff --git a/src/view/templates/footer.php b/src/view/templates/footer.php new file mode 100644 index 0000000..3f49c95 --- /dev/null +++ b/src/view/templates/footer.php @@ -0,0 +1,3 @@ + + + diff --git a/src/view/templates/header.php b/src/view/templates/header.php new file mode 100644 index 0000000..2220191 --- /dev/null +++ b/src/view/templates/header.php @@ -0,0 +1,77 @@ + SESSION_TIMEOUT)) { + session_unset(); + session_destroy(); + header("Location: login.php?timeout=1"); + exit; +} + +// Zeit der letzten Aktivität aktualisieren +$_SESSION['last_activity'] = time(); + +$username = $_SESSION['user'] ?? 'Gast'; +?> + + + + + <?= $pageTitle ?? "Seite" ?> | Meine Anwendung + + + + + + + + +
+
Meine Anwendung
+
+
Angemeldet als:
+
+ + + +
diff --git a/web/assets/css/vwl.css b/web/assets/css/vwl.css new file mode 100644 index 0000000..7faa4c6 --- /dev/null +++ b/web/assets/css/vwl.css @@ -0,0 +1,8 @@ +/* + Created on : 13.04.2025, 12:22:35 + Author : KNOB023 +*/ +body { + font-family: 'Calibri', sans-serif; +} + diff --git a/web/index.php b/web/index.php new file mode 100644 index 0000000..48a8505 --- /dev/null +++ b/web/index.php @@ -0,0 +1,10 @@ +Ihre Sitzung ist abgelaufen. Bitte melden Sie sich erneut an.
'; +} + +session_start(); +require_once '../core/Database.php'; + +$pdo = Database::connect(); + +$error = null; + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $username = $_POST['username']; + $password = $_POST['password']; + + $stmt = $pdo->prepare("SELECT * FROM vwl_internal_user WHERE vwlusername = :username LIMIT 1"); + $stmt->execute(['username' => $username]); + $user = $stmt->fetch(); + + if ($user && password_verify($password, $user['vwlpassword'])) { + $_SESSION['user'] = $user['vwlusername']; + header("Location: index.php"); + exit; + } else { + $error = "Ungültiger Benutzername oder Passwort."; + } +} +?> + + + + + Login + + + +
+
+
+
+

Login

+ +
+ +
+ + +
+
+ + +
+ +
+
+
+
+ + diff --git a/web/logout.php b/web/logout.php new file mode 100644 index 0000000..7649023 --- /dev/null +++ b/web/logout.php @@ -0,0 +1,5 @@ +