-
Notifications
You must be signed in to change notification settings - Fork 6
/
header.php
184 lines (165 loc) · 7.65 KB
/
header.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
<!-- Navbar -->
<nav class="navbar navbar-inverse site-header">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#topNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand nav-img" href="index.php"><img src="images/bus_logo.png" alt="" height="20px" width="20px">eBus</a>
</div>
<div class="collapse navbar-collapse" id="topNavbar">
<ul class="nav navbar-nav">
<li
<?php
if(isset($_SESSION['page']) && $_SESSION['page'] == 'index'){
echo(' class="active"');
}
?> ><a href="index.php">Home</a></li>
<li><a href="#">Page 1</a></li>
</ul>
<?php
if (isset($_SESSION['passenger_id']) && $_SESSION['page'] == 'profile') {
echo('
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="profile.php"><span class="glyphicon glyphicon-user"></span> Profile</a></li>
<li><a href="logout.php"><span class="glyphicon glyphicon-off"></span> Log out</a></li>
</ul>
');
} elseif ($_SESSION['page'] == 'login' || $_SESSION['page'] == 'signup') {
// Show nothing
}else {
echo('
<ul class="nav navbar-nav navbar-right">
<li><a href="#" data-toggle="modal" data-target="#signUpModal"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="#" data-toggle="modal" data-target="#logInModal"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
');
}
?>
<!-- Modals -->
<div id="signUpModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-md">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Sign Up</h4>
</div>
<div class="modal-body">
<form method="post" action="" class="form-horizontal">
<div class="form-group">
<div class="col-sm-12">
<input type="email" class="form-control" name="semail" placeholder="Enter email" maxlength="20" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="password" class="form-control" name="spassword" placeholder="Enter Password" maxlength="30" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="password" class="form-control" name="cpassword" placeholder="Confirm Password" maxlength="30" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-4">
<input type="text" class="form-control" name="fname" placeholder="First Name" maxlength="20" required>
</div>
<div class="col-sm-4">
<input type="text" class="form-control" name="mname" placeholder="Middle Name" maxlength="20">
</div>
<div class="col-sm-4">
<input type="text" class="form-control" name="lname" placeholder="Last Name" maxlength="20" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<input type="number" class="form-control" name="mobile" placeholder="Enter Mobile Number" maxlength="10" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-2 col-sm-offset-5">
<button type="submit" name="signup" class="btn btn-primary">Sign Up</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" name="signup" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div> <!-- /modal-content -->
</div>
</div> <!-- /signup modal -->
<div id="logInModal" class="modal fade" role="dialog">
<div class="modal-dialog modal-sm">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Log In</h4>
</div>
<form method="post" action="">
<div class="modal-body">
<div class="form-group">
<input type="email" class="form-control" name="lemail" placeholder="Enter email" maxlength="20" required>
</div>
<div class="form-group">
<input type="password" class="form-control" name="lpassword" placeholder="Enter Password" maxlength="30" required>
</div>
<div class="modal-footer">
<button type="submit" name="login" class="btn btn-primary">Log In</button>
</div>
</form>
</div> <!-- /modal-content -->
</div>
</div> <!-- /login modal -->
</div>
</div>
</nav> <!-- /navbar -->
<?php
// Login section
if (isset($_POST['login'])) {
if (!empty($_POST['lemail']) && !empty($_POST['lpassword'])) {
$email = mysqli_real_escape_string($conn, $_POST['lemail']);
$password = mysqli_real_escape_string($conn, $_POST['lpassword']);
$query = "SELECT passenger_id,email FROM passengers WHERE email='$email' AND password='$password'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$count = mysqli_num_rows($result);
if ($count == 1) {
$_SESSION['passenger_id'] = $row['passenger_id'];
header('Location: profile.php');
}else{
$_SESSION['message'] = "It seems you typed invalid credentials. Please <a href=\"login.php\">try again</a>.";
$_SESSION['type'] = "error";
header('Location: info.php');
}
}
}
// Signup section
if (isset($_POST['signup'])) {
if (!empty($_POST['semail']) && !empty($_POST['spassword']) && !empty($_POST['cpassword']) && !empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['mobile'])) {
$email = mysqli_real_escape_string($conn, $_POST['semail']);
$password = mysqli_real_escape_string($conn, $_POST['spassword']);
$cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);
$fname = mysqli_real_escape_string($conn, $_POST['fname']);
$mname = mysqli_real_escape_string($conn, $_POST['mname']);
$lname = mysqli_real_escape_string($conn, $_POST['lname']);
$mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
$query = "INSERT INTO passengers(email, fname, mname, lname, password, mobile) VALUES('".$email."', '".$fname."', '".$mname."', '".$lname."', '".$password."',". $mobile .")";
$result = mysqli_query($conn, $query);
if (false===$result) {
$_SESSION['message'] = "Something went wrong.<br />Error details: ". mysqli_error($conn) ."<br />Please <a href=\"signup.php\">try again</a>.";
$_SESSION['type'] = 'error';
header('Location: info.php');
}else{
$_SESSION['message'] = "You've successfully registered. You can <a href=\"login.php\">login</a>.";
$_SESSION['type'] = 'success';
header('Location: info.php');
}
}
}
?>