105 lines
4.3 KiB
PHP
105 lines
4.3 KiB
PHP
<!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">
|
|
<title>Materialverwaltung Installer</title>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Materialverwaltung Installer</h1>
|
|
|
|
<?php
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
// Formulardaten abrufen
|
|
$host = $_POST["host"];
|
|
$username = $_POST["username"];
|
|
$password = $_POST["password"];
|
|
$database = $_POST["database"];
|
|
$email = $_POST["email"];
|
|
|
|
// Verbindung zur MySQL-Datenbank herstellen
|
|
$conn = new mysqli($host, $username, $password);
|
|
if ($conn->connect_error) {
|
|
die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error);
|
|
}
|
|
|
|
// 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
|
|
)";
|
|
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 .= "?>";
|
|
|
|
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();
|
|
}
|
|
?>
|
|
|
|
<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 Materialbenachrichtigungen:</label>
|
|
<input type="email" id="email" name="email" required>
|
|
</div>
|
|
<input type="submit" value="Installieren">
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|