index.php aktualisiert
This commit is contained in:
		
							
								
								
									
										170
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										170
									
								
								index.php
									
									
									
									
									
								
							@@ -1,136 +1,58 @@
 | 
			
		||||
<?php
 | 
			
		||||
// Datenbankverbindung herstellen
 | 
			
		||||
include_once 'config/config.php';
 | 
			
		||||
 | 
			
		||||
// Verbindung zur MySQL-Datenbank herstellen
 | 
			
		||||
$conn = new mysqli($host, $username, $password);
 | 
			
		||||
if ($conn->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 "<p>Datenbank erfolgreich erstellt.</p>";
 | 
			
		||||
 | 
			
		||||
        // 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 "<p>Tabelle 'materials' erfolgreich erstellt.</p>";
 | 
			
		||||
 | 
			
		||||
            // Speichern der Daten in der config.php-Datei
 | 
			
		||||
            $config_content = "<?php\n";
 | 
			
		||||
            $config_content .= "\$host = '$host';\n";
 | 
			
		||||
            $config_content .= "\$username = '$username';\n";
 | 
			
		||||
            $config_content .= "\$password = '$password';\n";
 | 
			
		||||
            $config_content .= "\$database = '$database';\n";
 | 
			
		||||
            $config_content .= "\$email = '$email';\n";
 | 
			
		||||
            $config_content .= "\$notification_days = $notification_days;\n"; // Hinzugefügtes Feld für die Benachrichtigungstage
 | 
			
		||||
            $config_content .= "?>";
 | 
			
		||||
 | 
			
		||||
            file_put_contents('config/config.php', $config_content);
 | 
			
		||||
 | 
			
		||||
            // Weiterleitung zur Indexseite nach erfolgreicher Installation
 | 
			
		||||
            header("Location: index.php");
 | 
			
		||||
            exit();
 | 
			
		||||
        } else {
 | 
			
		||||
            echo "<p>Fehler beim Erstellen der Tabelle: " . $conn->error . "</p>";
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        echo "<p>Fehler beim Erstellen der Datenbank: " . $conn->error . "</p>";
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // 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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
?>
 | 
			
		||||
 | 
			
		||||
<!DOCTYPE html>
 | 
			
		||||
<html lang="de">
 | 
			
		||||
<head>
 | 
			
		||||
    <meta charset="UTF-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="css/install.css">
 | 
			
		||||
	<link rel="icon" href="img/favicon.png" type="image/x-icon">
 | 
			
		||||
    <title>Viper Installer</title>
 | 
			
		||||
    <link rel="stylesheet" type="text/css" href="css/style.css">
 | 
			
		||||
    <!-- Verknüpfung zur Manifestdatei für die PWA -->
 | 
			
		||||
    <link rel="manifest" href="manifest.json">
 | 
			
		||||
    <link rel="icon" href="img/favicon.png" type="image/x-icon">
 | 
			
		||||
    <title>Materialverwaltung</title>
 | 
			
		||||
    <?php
 | 
			
		||||
    // Funktion zum Protokollieren von Ereignissen einbinden
 | 
			
		||||
    include_once 'log_event.php';
 | 
			
		||||
    ?>
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
    <div class="container">
 | 
			
		||||
        <center><img src="img/logo.png" alt="Logo"></center>
 | 
			
		||||
        <center><h1>Installer</h1></center>
 | 
			
		||||
    <header class="header">
 | 
			
		||||
        <div class="header-container">
 | 
			
		||||
            <h1>Materialverwaltung</h1>
 | 
			
		||||
            <nav>
 | 
			
		||||
                <ul>
 | 
			
		||||
                    <li><a href="index.php">Home</a></li>
 | 
			
		||||
                    <li><a href="add_material_form.php">Artikel hinzufügen</a></li>
 | 
			
		||||
                    <li><a href="article_overview.php">Artikel Übersicht</a></li>
 | 
			
		||||
					<li><a href="Material_chrome.zip">chrome Erweiterung</a></li>
 | 
			
		||||
                    <li><a href="backup_restore.php">Backup</a></li>
 | 
			
		||||
                </ul>
 | 
			
		||||
            </nav>
 | 
			
		||||
        </div>
 | 
			
		||||
    </header>
 | 
			
		||||
 | 
			
		||||
        <h2>Datenbankverbindung eingeben</h2>
 | 
			
		||||
        <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="host">Host:</label>
 | 
			
		||||
                <input type="text" id="host" name="host" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="username">Benutzername:</label>
 | 
			
		||||
                <input type="text" id="username" name="username" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="password">Passwort:</label>
 | 
			
		||||
                <input type="password" id="password" name="password" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="database">Datenbankname:</label>
 | 
			
		||||
                <input type="text" id="database" name="database" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="email">E-Mail-Adresse für Benachrichtigungen:</label>
 | 
			
		||||
                <input type="email" id="email" name="email" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="form-group">
 | 
			
		||||
                <label for="notification_days">Benachrichtigungstage vor Ablauf:</label> <!-- Neues Feld für Benachrichtigungstage -->
 | 
			
		||||
                <input type="number" id="notification_days" name="notification_days" required>
 | 
			
		||||
            </div>
 | 
			
		||||
            <input type="submit" value="Installieren">
 | 
			
		||||
        </form>
 | 
			
		||||
    <div class="welcome-container">
 | 
			
		||||
        <img src="img/Willkommen.png" alt="Welcome Image">
 | 
			
		||||
        <h2>Willkommen zur Materialverwaltung!</h2>
 | 
			
		||||
        <p>Dies ist eine einfache Anwendung zur Verwaltung von Materialien mit Ablaufdatum.</p>
 | 
			
		||||
        <p>Verwenden Sie das Menü oben, um Artikel hinzuzufügen oder die Übersicht der Artikel anzuzeigen.</p>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <?php
 | 
			
		||||
    // Skript zum Überprüfen des Ablaufdatums einbinden und ausführen
 | 
			
		||||
    include_once 'check_expiration.php';
 | 
			
		||||
    ?>
 | 
			
		||||
    
 | 
			
		||||
    <!-- Service Worker Registrierung -->
 | 
			
		||||
    <script>
 | 
			
		||||
    if ('serviceWorker' in navigator) {
 | 
			
		||||
        window.addEventListener('load', function() {
 | 
			
		||||
            navigator.serviceWorker.register('service-worker.js').then(function(registration) {
 | 
			
		||||
                console.log('Service Worker registered with scope:', registration.scope);
 | 
			
		||||
            }).catch(function(error) {
 | 
			
		||||
                console.error('Service Worker registration failed:', error);
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
    </script>
 | 
			
		||||
</body>
 | 
			
		||||
<span class="watermark">© copyright 2024 by M_Viper</span>
 | 
			
		||||
</html>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user