-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
220 lines (199 loc) · 8.53 KB
/
edit.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
include_once 'check.php';
include_once 'conf.php';
if(isset($elog)) {
echo "Nothing";
} else {
if(isset($_GET['id'])){
if($_GET['id']==$_SESSION['id'] || $_SESSION['level']==0){//Check whether I am the user or if I am Admin
$db=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB); //Connect to the db
if($db) { //If connected to the db
$sqlu="select * from transportvehicle where tid='{$_GET['id']}'"; //Select the user with the id from the url correspondig to the same from the db
$result=mysqli_query($db,$sqlu); //Result comes from query
if($row=mysqli_fetch_array($result)){ //Get the specific row with the data extracted from the specific id of the user
$name=$row['name']; //Get each field of the sql and assign them to a variable
$vnumber=$row['vnumber'];
} else {
echo "The user with id: {$_GET['id']} does not exist..."; //If the row not generated then there is no user with this id
header("refresh:2; url=index.php"); //If not found go within 2 seconds at index.php
die();
}
}
} else {
echo "You do not have authorization to this person id"; //Check if we are user or admin
header("refresh:2; url=index.php"); //If not then the go to the index page again, this person cannot enter to edit
die();
}
} else header("Location: edit.php?id={$_SESSION['id']}"); //We are at edit php with the id which we get from the url
if(isset($_POST['submit'])){ //If the user has pressed the update button, type submit
$berr=false; //No error in the beginning
if(isset($_POST['name'])){ //Check for the name
if(!ctype_alpha($_POST['name'])) { $berr=true; //Let the user see the error message
$err['name']="<p class=\"err\">Name must contain only letters</p>";
} else $name=$_POST['name']; //Else the new input is assigned to the name
}
if(isset($_POST['vnumber'])){ //The same as the surname
if(!preg_match('/^\d+$/',$_POST['vnumber'])) { $berr=true;
$err['vnumber']="<p class=\"err\">Vehicle number must be only digit</p>";
} else $vnumber=$_POST['vnumber'];
} else {$err['vnumber']="<p class=\"err\">There is no data input</p>";$berr=true;}
//Updating in the database
if(!$berr){//Process for database
$db=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB); //Connect to the db
if($db){ //Get the db and update all the records
$sql= "UPDATE transportvehicle SET name = '" . $name . "', vnumber = '" . $vnumber . "'
WHERE tid={$_GET['id']};"; //Link it to that specific id of the user we are editing
echo $sql;//For Debugging
if(mysqli_query($db,$sql)){ //If the database has generated our sql
$msg= "<h1>Successfully Updated</h1>"; //Show the user the message that we have successfully updated
header("refresh:1;url=staff.php"); //Go the the index page where the update will be visible in the table
} else {
$berr=true; //Else we have an error
$err['db']="Something happen with update in DB!!!"; //Couldnt get the desired outcome from the db
}
} else { $berr=true; //If there is no connection to the db
$err['db']="Database Connection Failed";
}
}
}
?>
<!DOCTYPE html>
<html>
<head><title>Edit Vehicle Page - <?=isset($name)?$name." ".$vnumber:""?></title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="css/adminstyle.css"/>
<link rel='stylesheet' href='https://cdn.rawgit.com/creativetimofficial/material-dashboard/31144b3f/assets/css/material-dashboard.css'>
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css'>
<style>
.err {color: red;}
#new{
margin-left: 20%;
position: absolute;
display: block;
justify-content: left;
align-items: left;
}
input{
display:block;
padding:5px;
}
</style>
</head>
<body>
<?=isset($msg)?$msg:""?>
<div class="wrapper ">
<div class="sidebar" data-color="green" data-background-color="white">
<!--
Tip 1: You can change the color of the sidebar using: data-color="purple | azure | green | orange | danger"
-->
<div class="logo">
<h3 class="simple-text logo-normal">
Welcome
</h3>
</div>
<div class="sidebar-wrapper">
<ul class="nav">
<li class="nav-item active">
<a class="nav-link" href="admin.php">
<i class="material-icons">dashboard</i>
<p>Admin's Dashboard</p>
</a>
<li class="nav-item">
<a class="nav-link" href="client.php">
<i class="material-icons">badge</i>
<p>Commuters</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="vehicle.php">
<i class="material-icons">supervisor_account</i>
<p>Vehicle</p>
</li>
<li class="nav-item">
<a class="nav-link" href="routes.php">
<i class="material-icons">supervisor_account</i>
<p>Routes</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="showadminapp.php">
<i class="material-icons">book_online</i>
<p>Bookings</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="tracking.php">
<i class="material-icons">supervisor_account</i>
<p>Tracking</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="mailer.php">
<i class="material-icons">mail_outline</i>
<p>Mailer</p>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">
<i class="material-icons">logout</i>
<p>Logout</p>
</a>
</li>
</ul>
</div>
</div>
<div class="main-panel">
<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">
<div class="container-fluid">
<div class="navbar-wrapper">
<a class="navbar-brand" href="admin.php">Dashboard</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navigation-index" aria-expanded="false" aria-label="Toggle navigation">
<span class="sr-only">Toggle navigation</span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
</button>
<div class="collapse navbar-collapse justify-content-end">
<form class="navbar-form">
<div class="input-group no-border">
<input type="text" value="" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-white btn-round btn-just-icon">
<i class="material-icons">search</i>
<div class="ripple-container"></div>
</button>
</div>
</form>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="admin.php">
<i class="material-icons">person</i>
<p class="d-lg-none d-md-block">
Account Name
</p>
</a>
</li>
</ul>
</div>
</div>
</nav>
<!--End of nav bar -->
<div id="wrap">
<div id="new">
<h1>Edit Vehicle</h1> <br>
<form method="post" action="<?=$_SERVER['PHP_SELF']?>?id=<?=isset($_GET['id'])?$_GET['id']:$_SESSION['id']?>" enctype="multipart/form-data">
Name: <input type="text "name="name"
value="<?=isset($name)?$name:""?>"></br>
<?=isset($err['name'])? $err['name']:""?>
Vehicle Number: <input type="text "name="payrate" value="<?=isset($vnumber)?$vnumber:""?>"></br>
<?=isset($err['vnumber'])? $err['vnumber']:""?>
<input type="submit" name="submit" value="Update">
<?=isset($err['db'])? $err['db']:""?>
</form>
</div>
</div>
</body>
</html>
<?php } ?>