161 lines
4.7 KiB
PHP
161 lines
4.7 KiB
PHP
<?php
|
|
require 'config.php';
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// Prüfen, ob die ID im GET-Parameter vorhanden ist
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
header('Location: aktien.php');
|
|
exit;
|
|
}
|
|
|
|
$aktie_id = (int)$_GET['id'];
|
|
$aktie = null;
|
|
$data_saved = "nix";
|
|
|
|
// Daten des Eintrags laden
|
|
try {
|
|
$stmtAktie = $pdo->prepare("
|
|
SELECT * FROM aktien
|
|
WHERE id = :id
|
|
");
|
|
$stmtAktie->bindParam(':id', $aktie_id, PDO::PARAM_INT);
|
|
$stmtAktie->execute();
|
|
$aktie = $stmtAktie->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$aktie) {
|
|
header('Location: aktien.php');
|
|
exit;
|
|
}
|
|
} catch (PDOException $e) {
|
|
$data_saved = "Fehler: Aktie konnte nicht geladen werden.";
|
|
}
|
|
|
|
// Lösch-Logik
|
|
if (isset($_POST['delete'])) {
|
|
try {
|
|
$stmt = $pdo->prepare("DELETE FROM aktien WHERE id = :id");
|
|
$stmt->bindParam(':id', $aktie_id, PDO::PARAM_INT);
|
|
$stmt->execute();
|
|
echo '<meta http-equiv="refresh" content="5;url=aktien.php">Aktie wurde gelöscht. Weiterleitung…'; exit;
|
|
} catch (PDOException $e) {
|
|
$data_saved = "Fehler: " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Speicher-Logik
|
|
if (!empty($_POST) && !isset($_POST['delete'])) {
|
|
$WKNISIN = isset($_POST['WKNISIN']) ? trim($_POST['WKNISIN']) : '';
|
|
$Aktie = isset($_POST['Aktie']) ? trim($_POST['Aktie']) : '';
|
|
$kaufdatum = isset($_POST['kaufdatum']) ? trim($_POST['kaufdatum']) : '';
|
|
$kaufpreis = isset($_POST['kaufpreis']) ? (float)$_POST['kaufpreis'] : 0.0;
|
|
$anzahl = isset($_POST['anzahl']) ? (float)$_POST['anzahl'] : 0.0;
|
|
|
|
try {
|
|
$stmt = $pdo->prepare("
|
|
UPDATE aktien
|
|
SET
|
|
WKNISIN = :WKNISIN,
|
|
Aktie = :Aktie,
|
|
kaufdatum = :kaufdatum,
|
|
kaufpreis = :kaufpreis,
|
|
anzahl = :anzahl
|
|
WHERE id = :id
|
|
");
|
|
$stmt->bindParam(':id', $aktie_id, PDO::PARAM_INT);
|
|
$stmt->bindParam(':WKNISIN', $WKNISIN);
|
|
$stmt->bindParam(':Aktie', $Aktie);
|
|
$stmt->bindParam(':kaufdatum', $kaufdatum);
|
|
$stmt->bindParam(':kaufpreis', $kaufpreis);
|
|
$stmt->bindParam(':anzahl', $anzahl);
|
|
|
|
$stmt->execute();
|
|
$data_saved = "true";
|
|
} catch (PDOException $e) {
|
|
$data_saved = "Fehler: " . $e->getMessage();
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=0.8">
|
|
<title>Aktie bearbeiten</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
<style>
|
|
.data-notice {
|
|
display: none;
|
|
padding: 10px;
|
|
margin: 10px 0;
|
|
border-radius: 4px;
|
|
text-align: center;
|
|
}
|
|
.data-notice.success {
|
|
background-color: #4CAF50;
|
|
color: white;
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php if ($data_saved == "true"): ?>
|
|
<div id="data-notice" class="data-notice success">
|
|
Aktie erfolgreich aktualisiert! Sie werden in 5 Sekunden weitergeleitet ...
|
|
</div>
|
|
<script>
|
|
setTimeout(function() {
|
|
window.location.href = 'aktien.php';
|
|
}, 5000);
|
|
</script>
|
|
<?php elseif ($data_saved != "nix"): ?>
|
|
<div id="data-notice" class="data-notice error">
|
|
<?php echo $data_saved; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="container">
|
|
|
|
<!-- Navigation -->
|
|
<nav class="nav">
|
|
<button class="hamburger">☰</button>
|
|
<ul class="nav-list">
|
|
<li><a href="dashboard.php">Start</a></li>
|
|
<li><a href="aktien.php">Aktien</a></li>
|
|
<li><a href="logout.php" class="logout">Logout</a></li>
|
|
</ul>
|
|
</nav>
|
|
|
|
<form action="edit_aktie.php?id=<?= $aktie_id ?>" method="post" class="form-container">
|
|
<div class="form-group">
|
|
<label for="WKNISIN">WKN/ISIN</label>
|
|
<input type="text" name="WKNISIN" value="<?= htmlspecialchars($aktie['WKNISIN']) ?>" placeholder="WKN oder ISIN" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="Aktie">Aktie</label>
|
|
<input type="text" name="Aktie" value="<?= htmlspecialchars($aktie['Aktie']) ?>" placeholder="Name der Aktie" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="kaufdatum">Kaufdatum</label>
|
|
<input type="date" name="kaufdatum" value="<?= htmlspecialchars($aktie['kaufdatum']) ?>" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="kaufpreis">Kaufpreis</label>
|
|
<input type="number" name="kaufpreis" step="0.01" value="<?= htmlspecialchars($aktie['kaufpreis']) ?>" placeholder="Kaufpreis" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="anzahl">Anzahl</label>
|
|
<input type="number" name="anzahl" step="0.0001" value="<?= htmlspecialchars($aktie['anzahl']) ?>" placeholder="Anzahl" required>
|
|
</div>
|
|
<div class="button-group">
|
|
<button type="submit" name="delete" class="btn-xr1l" style="background-color: #d9534f;">Löschen</button>
|
|
<button type="submit" class="btn-xr">Speichern</button>
|
|
</div>
|
|
</form>
|
|
|
|
</div>
|
|
<script src="assets/js/script.js"></script>
|
|
</body>
|
|
</html>
|