-
Notifications
You must be signed in to change notification settings - Fork 3
/
release-train.php
102 lines (93 loc) · 3.55 KB
/
release-train.php
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
<?php
session_start();
//To prevent user to access the page without login
if(isset($_SESSION['username'])){
if($_SESSION['username'] != 'admin1' && $_SESSION['username'] != 'admin'){
header('Location: user.php');
}
}
else{
header('Location: admin-login.php');
}
include "config/connection.php";
$errors = array('train_number' => '', 'date' => '', 'num_ac' => '', 'num_sleeper' => '', 'checks' => '');
$train_number = $date = $num_ac = $num_sleeper = $checks = '';
$admin_name = $_SESSION['username'];
if(isset($_POST['release'])){
$train_number = $_POST['train_number'];
$date = $_POST['date'];;
$num_ac = $_POST['num_ac'];
$num_sleeper = $_POST['num_sleeper'];
if(empty($train_number)){
$errors['train_number'] = 'Train Number is required';
}
if(empty($date)){
$errors['date'] = 'Date is required';
}
// INSERT INTO TRAINS
if(! array_filter($errors)){
$query1 = "INSERT INTO train VALUES ('$train_number', '$date', '$num_ac', '$num_sleeper', '$admin_name')";
if ($conn->query($query1) === TRUE) {
header('Location: admin-page.php');
$query1 = "INSERT INTO train_status VALUES ('$train_number', '$date', 0, 0)";
if ($conn->query($query1) === FALSE) {
echo $conn->error;
}
}
else{
// ERROR OF before_release_train Trigger
$errors['checks'] = $conn->error;
}
$conn->close();
}
}
$welcome_name = $_SESSION['username'] ?? 'Guest';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Release Train</title>
</head>
<?php include "template/header-name.php" ?>
<div style="margin-top:100px;">
<form action="release-train.php" method="POST">
<h3 class="heading">Release New Train</h3> <br>
<label>
<p class="label-txt">TRAIN NUMBER</p>
<input type="number" class="input" min=0 name="train_number" value="<?php echo htmlspecialchars($train_number) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['train_number'])?></p>
</label>
<label>
<p class="label-txt">DATE</p>
<input type="date" class="input" name="date" value="<?php echo htmlspecialchars($date) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['date'])?></p>
</label>
<label>
<p class="label-txt">NUMBER OF AC COACHES</p>
<input type="number" class="input" min=0 name="num_ac" value="<?php echo htmlspecialchars($num_ac) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['num_ac'])?></p>
</label>
<label>
<p class="label-txt">NUMBER OF SLEEPER COACHES</p>
<input type="number" class="input" name="num_sleeper" min=0 value="<?php echo htmlspecialchars($num_sleeper) ?>">
<div class="line-box">
<div class="line"></div>
</div>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['num_sleeper'])?></p>
</label>
<p class= "bg-danger text-white"><?php echo htmlspecialchars($errors['checks'])?></p>
<a href="admin-page.php" class="register">Back</a>
<button type="submit" name="release" value="submit">Release</button>
</form>
</div>
<?php include "template/footer.php" ?>
</html>