forked from manikge/SLRTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_train.php
181 lines (162 loc) · 11.4 KB
/
update_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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php require_once("initialize.php"); ?>
<?php before_every_protected_page();
if(!accessble(2)){ redirect_to("index.php"); }
?>
<?php require_once('functions/header.php');?>
<?php
$message = "";
$smessage = "";
$fstep = True;
$nxtstep = False;
$train = NULL;
if(request_is_post() && request_is_same_domain()) {
if(!csrf_token_is_valid() || !csrf_token_is_recent()) {
$message = "Sorry, request was not valid.";
} else {
$a = $_POST['submit'];
if($a == "Select"){
$train_name = sql_prep($_POST['train_name']);
if(has_exclusion_from($train_name, trains_list())) {
$message = "train must be valid.";
} else{
$fstep = False;
$nxtstep = True;
$train = trainid_for_name($train_name);
}
} elseif($a == "Update"){
$id = $_POST['id'];
$name = sql_prep($_POST['train_name']);
$type = $_POST['types'];
$first_class = $_POST['first_class'];
$second_class = $_POST['second_class'];
$third_class = $_POST['third_class'];
$canteen = $_POST['canteen'];
$query = "UPDATE trains ";
$query .= "SET name = '{$name}', type = {$type}, first_class = {$first_class}, ";
$query .= "second_class = {$second_class}, third_class = {$third_class}, canteen = {$canteen} ";
$query .= "WHERE id = {$id}";
$result = mysql_query($query);
confirm_query($result);
if ($result) {
$smessage = "Success!";
$fstep = True;
$nxtstep = False;
} else{
$message = "Sorry, request was not valid.";
$fstep = False;
$nxtstep = True;
}
}
}
}
?>
<datalist id="browsers2">
<?php
$list = trains_list();
foreach ($list as $row) {
echo "<option value=\"{$row}\">";
}
?>
</datalist>
<section style="min-height: 200px;" id="content" class="right-sidebar clearfix">
<!-- INTRO -->
<header class="page-heading clearfix">
<div class="container">
<!-- PAGE TITLE -->
<div id="page-title">
<h1 class="page-title">Update a Train</h1>
</div>
<!-- / PAGE TITLE -->
</div>
</header>
<!-- / INTRO -->
<div class="container">
<!-- PAGE DESCRIPTION -->
<div class="page-description">
<h1>Pricing Tables</h1>
<hr>
<p>pick a plan that best fits your needs</p>
</div>
<!-- / PAGE DESCRIPTION -->
<article>
<div>
<?php
if($message != "") {
$u = "<div class=\"error-box\"><div class=\"message-box\">
<p><strong>Error!</strong> ". h($message) ."</p></div></div>";
echo $u;
$message = "";
} if($smessage != "") {
$u = "<div class=\"success-box\" style=\"width: 700px;margin: auto;\"><div class=\"message-box\" style=\"padding: 5px;\">
<p>". h($smessage) ."</p></div></div>";
echo $u;
$smessage = "";
}
?>
</div>
<div>
<?php
if($fstep){
$k = "<form action=\"update_train.php\" method=\"post\" autocomplete=\"off\">";
$k .= csrf_token_tag();
$k .= "<table class=\"detail2\"><col style=\"width: 200px;\"><col style=\"width: 400px;\"><tbody>";
$k .= "<tr class=\"parent1\"><td>Select a Train: <span class=\"colored\">*</span></td>";
$k .= "<td><input list=\"browsers2\" type=\"text\" name=\"train_name\" maxlength=\"30\" value=\"\" required autofocus/></td></tr>";
$k .= "<tr class=\"parent1\"><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Select\" /></td></tr>";
$k .= "</tbody></table></form>";
echo $k;
}
if($nxtstep){
$tid = $train['id'];
$tname = $train['name'];
$ttype = $train['type'];
$tfc = $train['first_class'];
$tsc = $train['second_class'];
$ttc = $train['third_class'];
$tcan = $train['canteen'];
$r = "<form action=\"update_train.php\" method=\"post\" autocomplete=\"off\">";
$r .= csrf_token_tag();
$r .= "<input type=\"hidden\" name=\"id\" value=\"".$tid."\" />";
$r .= "<table class=\"detail2\"><col style=\"width: 200px;\"><col style=\"width: 400px;\"><tbody>";
$r .= "<tr class=\"parent1\"><td>Train Name: <span class=\"colored\">*</span></td><td><input type=\"text\" name=\"train_name\" maxlength=\"30\" value=\"".$tname."\" required autofocus/></td></tr>";
$r .= "<tr class=\"parent1\"><td>Train Type: <span class=\"colored\">*</span></td><td style=\"font-size: 130%;\">";
if($ttype == 1){
$r .= "<input type=\"radio\" name=\"types\" value=\"1\" checked=\"checked\" required autofocus/> Express <input type=\"radio\" name=\"types\" value=\"2\" required autofocus/> Slow <input type=\"radio\" name=\"types\" value=\"3\" required autofocus/> Inter City</td></tr>";
} elseif($ttype == 2){
$r .= "<input type=\"radio\" name=\"types\" value=\"1\" required autofocus/> Express <input type=\"radio\" name=\"types\" value=\"2\" checked=\"checked\" required autofocus/> Slow <input type=\"radio\" name=\"types\" value=\"3\" required autofocus/> Inter City</td></tr>";
} else{
$r .= "<input type=\"radio\" name=\"types\" value=\"1\" required autofocus/> Express <input type=\"radio\" name=\"types\" value=\"2\" required autofocus/> Slow <input type=\"radio\" name=\"types\" value=\"3\" checked=\"checked\" required autofocus/> Inter City</td></tr>";
}
$r .= "<tr class=\"parent1\"><td>First Class: <span class=\"colored\">*</span></td><td style=\"font-size: 130%;\">";
if($tfc == 1){
$r .= "<input type=\"radio\" name=\"first_class\" value=\"1\" checked=\"checked\" required autofocus/> Yes <input type=\"radio\" name=\"first_class\" value=\"0\" required autofocus/> No</td></tr>";
}else{
$r .= "<input type=\"radio\" name=\"first_class\" value=\"1\" required autofocus/> Yes <input type=\"radio\" name=\"first_class\" value=\"0\" checked=\"checked\" required autofocus/> No</td></tr>";
}
$r .= "<tr class=\"parent1\"><td>Second Class: <span class=\"colored\">*</span></td><td style=\"font-size: 130%;\">";
if($tsc == 1){
$r .= "<input type=\"radio\" name=\"second_class\" value=\"1\" checked=\"checked\" required autofocus/> Yes <input type=\"radio\" name=\"second_class\" value=\"0\" required autofocus/> No</td></tr>";
}else{
$r .= "<input type=\"radio\" name=\"second_class\" value=\"1\" required autofocus/> Yes <input type=\"radio\" name=\"second_class\" value=\"0\" checked=\"checked\" required autofocus/> No</td></tr>";
}
$r .= "<tr class=\"parent1\"><td>Third Class: <span class=\"colored\">*</span></td><td style=\"font-size: 130%;\">";
if($ttc == 1){
$r .= "<input type=\"radio\" name=\"third_class\" value=\"1\" checked=\"checked\" required autofocus/> Yes <input type=\"radio\" name=\"third_class\" value=\"0\" required autofocus/> No</td></tr>";
}else{
$r .= "<input type=\"radio\" name=\"third_class\" value=\"1\" required autofocus/> Yes <input type=\"radio\" name=\"third_class\" value=\"0\" checked=\"checked\" required autofocus/> No</td></tr>";
}
$r .= "<tr class=\"parent1\"><td>Canteen: <span class=\"colored\">*</span></td><td style=\"font-size: 130%;\">";
if($tcan == 1){
$r .= "<input type=\"radio\" name=\"canteen\" value=\"1\" checked=\"checked\" required autofocus/> Yes <input type=\"radio\" name=\"canteen\" value=\"0\" required autofocus/> No</td></tr>";
}else{
$r .= "<input type=\"radio\" name=\"canteen\" value=\"1\" required autofocus/> Yes <input type=\"radio\" name=\"canteen\" value=\"0\" checked=\"checked\" required autofocus/> No</td></tr>";
}
$r .= "<tr class=\"parent1\"><td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"Update\" /></td></tr></tbody></table></form>";
echo $r;
}
?>
</div>
</article>
</div>
</section>
<?php require_once('functions/footer.php');?>