From ef2e9fc71d8e1dbca11de49eb4c6c4e69b615886 Mon Sep 17 00:00:00 2001 From: M_Viper Date: Tue, 27 Feb 2024 20:56:16 +0000 Subject: [PATCH] index.php aktualisiert --- index.php | 152 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 123 insertions(+), 29 deletions(-) diff --git a/index.php b/index.php index 3965c30..416ddeb 100644 --- a/index.php +++ b/index.php @@ -1,42 +1,136 @@ +connect_error) { + die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error); +} + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + // Formulardaten abrufen + $host = $_POST["host"]; + $username = $_POST["username"]; + $password = $_POST["password"]; + $database = $_POST["database"]; + $email = $_POST["email"]; + $notification_days = $_POST["notification_days"]; // Hinzugefügtes Feld für die Benachrichtigungstage + + // Datenbank erstellen + $sql_create_db = "CREATE DATABASE IF NOT EXISTS $database"; + if ($conn->query($sql_create_db) === TRUE) { + echo "

Datenbank erfolgreich erstellt.

"; + + // Datenbank auswählen + $conn->select_db($database); + + // Tabelle erstellen + $sql_create_table = "CREATE TABLE IF NOT EXISTS materials ( + id INT AUTO_INCREMENT PRIMARY KEY, + item_name VARCHAR(255) NOT NULL, + manufacturer VARCHAR(255) NOT NULL, + location VARCHAR(255) NOT NULL, + amount_should INT NOT NULL, + amount_is INT NOT NULL, + expiration_date DATE NOT NULL, + barcode VARCHAR(255) NOT NULL, + image VARCHAR(255), + email VARCHAR(255) NOT NULL, + notification_days INT NOT NULL DEFAULT 0 + )"; + if ($conn->query($sql_create_table) === TRUE) { + echo "

Tabelle 'materials' erfolgreich erstellt.

"; + + // Speichern der Daten in der config.php-Datei + $config_content = ""; + + file_put_contents('config/config.php', $config_content); + + // Weiterleitung zur Indexseite nach erfolgreicher Installation + header("Location: index.php"); + exit(); + } else { + echo "

Fehler beim Erstellen der Tabelle: " . $conn->error . "

"; + } + } else { + echo "

Fehler beim Erstellen der Datenbank: " . $conn->error . "

"; + } + + // Datenbankverbindung schließen + $conn->close(); + + // Aktuellen Pfad ermitteln + $current_path = getcwd(); + + // Pfad zur PHP-Datei, die den Cron-Job ausführt + $cron_script_path = $current_path . '/notification_cron.php'; + + // Crontab-Zeile erstellen (hier: Täglich um 13 Uhr) + $cron_job = '0 13 * * * /usr/bin/php ' . $cron_script_path; + + // Crontab einrichten + exec('crontab -l', $existing_cron_jobs); // Aktuelle Crontab abrufen + if (!in_array($cron_job, $existing_cron_jobs)) { + $existing_cron_jobs[] = $cron_job; // Neuen Cron-Job hinzufügen + $new_cron_tab = implode("\n", $existing_cron_jobs); // Crontab zusammenführen + file_put_contents('/tmp/crontab.txt', $new_cron_tab); // Temporäre Crontab-Datei erstellen + exec('crontab /tmp/crontab.txt'); // Neue Crontab-Datei einrichten + unlink('/tmp/crontab.txt'); // Temporäre Crontab-Datei löschen + } +} +?> + - + - Materialverwaltung - + Viper Installer -
-
-

Materialverwaltung

- -
-
+
+
Logo
+

Installer

-
- Welcome Image -

Willkommen zur Materialverwaltung!

-

Dies ist eine einfache Anwendung zur Verwaltung von Materialien mit Ablaufdatum.

-

Verwenden Sie das Menü oben, um Artikel hinzuzufügen oder die Übersicht der Artikel anzuzeigen.

+

Datenbankverbindung eingeben

+
"> +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
- - © copyright 2024 by M_Viper