-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_timescale.php
More file actions
109 lines (93 loc) · 4.28 KB
/
edit_timescale.php
File metadata and controls
109 lines (93 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
session_start();
require_once __DIR__ . '/includes/Auth.php';
require_once __DIR__ . '/includes/Database.php';
if (!isset($_SESSION['username'])) {
header("Location: login.php");
exit;
}
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
try {
$pdo = Database::connect();
$stmt = $pdo->prepare("SELECT * FROM timescales WHERE id_timescale = ?");
$stmt->execute([$id]);
$timescale = $stmt->fetch();
if (!$timescale) {
throw new Exception("Time scale does not exist.");
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$process = trim($_POST['process']);
$activity = $_POST['activity'];
$timescale_val = $_POST['timescale'];
$start = trim($_POST['start']);
$end = trim($_POST['end']);
$stmt = $pdo->prepare("
UPDATE timescales
SET process = ?, activity = ?, timescale = ?, start = ?, end = ?
WHERE id_timescale = ?
");
$stmt->execute([$process, $activity, $timescale_val, $start, $end, $id]);
header("Location: geosite.php?fid=" . intval($_GET['fid']));
exit;
}
} catch (Exception $e) {
$error = "An error occured: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<title>Edit time scale</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="page-container">
<h1>Edit time scale</h1>
<?php if (!empty($error)): ?>
<p class="form-message error"><?= htmlspecialchars($error) ?></p>
<?php endif; ?>
<?php if (!empty($timescale)): ?>
<form method="post" class="responsive-form">
<input type="hidden" name="id_timescale" value="<?= htmlspecialchars($timescale['id_timescale']) ?>">
<div class="form-grid">
<div class="form-group full-width">
<label>Process:</label>
<input type="text" name="process" value="<?= htmlspecialchars($timescale['process']) ?>" required>
</div>
<div class="form-group">
<label>Is active:</label>
<select name="activity" required>
<option value="active" <?= $timescale['activity'] === 'active' ? 'selected' : '' ?>>Active</option>
<option value="passive" <?= $timescale['activity'] === 'passive' ? 'selected' : '' ?>>Passive</option>
</select>
</div>
<div class="form-group">
<label>Time scale:</label>
<select name="timescale" required>
<option value="million-year" <?= $timescale['timescale'] === 'million-year' ? 'selected' : '' ?>>Million-year</option>
<option value="hundred thousand-year" <?= $timescale['timescale'] === 'hundred thousand-year' ? 'selected' : '' ?>>Hundred thousand-year</option>
<option value="thousand-year" <?= $timescale['timescale'] === 'thousand-year' ? 'selected' : '' ?>>Thousand-year</option>
<option value="century" <?= $timescale['timescale'] === 'century' ? 'selected' : '' ?>>Century</option>
<option value="year" <?= $timescale['timescale'] === 'year' ? 'selected' : '' ?>>Year</option>
<option value="present" <?= $timescale['timescale'] === 'present' ? 'selected' : '' ?>>Present</option>
</select>
</div>
<div class="form-group">
<label>Begin:</label>
<input type="text" name="start" value="<?= htmlspecialchars($timescale['start']) ?>" required>
</div>
<div class="form-group">
<label>End:</label>
<input type="text" name="end" value="<?= htmlspecialchars($timescale['end']) ?>" required>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn-link">💾 Save changes</button>
<a href="javascript:history.back()" class="btn-link">⬅ Return</a>
</div>
</form>
<?php endif; ?>
</div>
</body>
</html>