FSCash/html/new_aktie.php

119 lines
3.3 KiB
PHP

<?php
require 'config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: index.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<title>Neue Aktie erfassen</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
$data_saved = "nix";
$debug = "";
$currentDate = date('Y-m-d');
// save-Logik
if (!empty($_POST)) {
$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("
INSERT INTO aktien (WKNISIN, user_id, Aktie, kaufdatum, kaufpreis, anzahl)
VALUES (:WKNISIN, :user_id, :Aktie, :kaufdatum, :kaufpreis, :anzahl)
");
$stmt->bindParam(':WKNISIN', $WKNISIN);
$stmt->bindParam(':Aktie', $Aktie);
$stmt->bindParam(':kaufdatum', $kaufdatum);
$stmt->bindParam(':kaufpreis', $kaufpreis);
$stmt->bindParam(':anzahl', $anzahl);
$stmt->bindParam(':user_id', $_SESSION['user_id']);
$stmt->execute();
$data_saved = "true";
} catch (PDOException $e) {
$data_saved = "Fehler: " . $e->getMessage();
}
}
?>
<?php if ($data_saved == "true"): ?>
<div id="data-notice" class="data-notice success">
Aktie erfolgreich gespeichert! 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="rep-month.php">Report Monat</a></li>
<li><a href="logout.php" class="logout">Logout</a></li>
</ul>
</nav>
<form action="new_aktie.php" method="post" class="form-container">
<div class="form-group">
<label for="WKNISIN">WKN/ISIN</label>
<input type="text" name="WKNISIN" placeholder="WKN oder ISIN" required>
</div>
<div class="form-group">
<label for="Aktie">Aktie</label>
<input type="text" name="Aktie" placeholder="Name der Aktie" required>
</div>
<div class="form-group">
<label for="kaufdatum">Kaufdatum</label>
<input type="date" name="kaufdatum" value="<?php echo $currentDate; ?>" required>
</div>
<div class="form-group">
<label for="kaufpreis">Kaufpreis</label>
<input type="number" name="kaufpreis" step="0.01" placeholder="Kaufpreis" required>
</div>
<div class="form-group">
<label for="anzahl">Anzahl</label>
<input type="number" name="anzahl" step="0.0001" placeholder="Anzahl" required>
</div>
<button type="submit" class="btn-xr">Speichern</button>
</form>
</div>
<script src="assets/js/script.js"></script>
</body>
</html>