-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_guest.php
More file actions
180 lines (174 loc) · 7.05 KB
/
main_guest.php
File metadata and controls
180 lines (174 loc) · 7.05 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
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
<?php
session_start();
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] != true) {
header("location: index.php");
exit;
} else {
include 'config.php';
$username = $_SESSION['username'];
$query1 = "SELECT city, state, country, zipcode FROM `Address` WHERE address_id = (SELECT a.address_id FROM `Guests` AS g, `Guest_address` AS a WHERE a.g_id=g.g_id AND g.username='$username');";
$query1 .= "SELECT first_name, last_name FROM `Guests` WHERE username = '$username';";
$res1 = mysqli_multi_query($conn, $query1);
$i = 0;
do {
if ($result = mysqli_store_result($conn)) {
while ($row = mysqli_fetch_row($result)) {
if ($i == 0) {
$city = $row[0];
$state = $row[1];
$country = $row[2];
$zipcode = $row[3];
} else if ($i == 1) {
$first_name = $row[0];
$last_name = $row[1];
}
$i++;
}
}
} while (mysqli_more_results($conn) && mysqli_next_result($conn));
$query2 = "SELECT contact_no FROM `Guests_contact` WHERE g_id = (SELECT g.g_id FROM `Guests` AS g WHERE g.username = '$username');";
$res2 = mysqli_query($conn, $query2);
$contacts = mysqli_num_rows($res2);
if ($contacts == 1) {
while($row = mysqli_fetch_assoc($res2)) {
$contact_no1 = $row["contact_no"];
}
} else if ($contacts == 2) {
$i = 0;
while ($row = mysqli_fetch_assoc($res2)) {
if ($i == 0) {
$contact_no1 = $row["contact_no"];
} else if ($i == 1) {
$contact_no2 = $row["contact_no"];
}
$i++;
}
}
$query3 = "SELECT email_id FROM `Guests_email` WHERE g_id = (SELECT g.g_id FROM `Guests` AS g WHERE g.username = '$username');";
$res3 = mysqli_query($conn, $query3);
$emails = mysqli_num_rows($res3);
if ($emails == 1) {
while($row = mysqli_fetch_assoc($res3)) {
$email1 = $row["email_id"];
}
} else if ($emails == 2) {
$i = 0;
while ($row = mysqli_fetch_assoc($res3)) {
if ($i == 0) {
$email1 = $row["email_id"];
} else if ($i == 1) {
$email2 = $row["email_id"];
}
$i++;
}
}
$name = $first_name." ".$last_name;
$address = $city.", ".$state.", ".$country.", ".$zipcode;
if ($contacts == 1) {
$contact = $contact_no1;
} else {
$contact = $contact_no1.", ".$contact_no2;
}
if ($emails == 1) {
$email = $email1;
} else {
$email = $email1.", ".$email2;
}
// code for services part
// serv_ids : (hard-coded, can be altered later)
// tea_or_coffee = 0
// lunch_or_dinner = 1
// other_room_service = 2
$servs = [
'tea_or_coffee' => 0,
'lunch_or_dinner' => 1,
'other_room_service' => 2,
];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (!empty($_POST['serv']) && is_array($_POST['serv'])) {
$services_selected = $_POST['serv'];
$service = $services_selected[0];
$n = count($services_selected);
$sql = "INSERT INTO `Service_used` (`g_id`, `serv_id`) VALUES ((SELECT g.g_id FROM `Guests` AS g WHERE g.username='$username'), '$servs[$service]');";
for ($i = 1; $i < $n; $i++) {
$service = $services_selected[$i];
$sql .= "INSERT INTO `Service_used` (`g_id`, `serv_id`) VALUES ((SELECT g.g_id FROM `Guests` AS g WHERE g.username='$username'), '$servs[$service]');";
}
$res = mysqli_multi_query($conn, $sql);
}
}
}
?>
<!DOCTYPE html>
<html lang="en" style="height: 100%;">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="main.css">
<title>Main</title>
</head>
<body style="background-color: rgb(0, 0, 0); height: 100%;">
<div class="container" style="height: 100%;">
<div class="profile">
<h3>Profile Information - <?php echo $_SESSION['user']; ?></h3>
<hr/>
<div class="col-25">
<h4>Name</h4>
</div>
<div class="col-75">
<h4><?php echo $name; ?></h4>
</div>
<div class="col-25">
<h4>Contact</h4>
</div>
<div class="col-75">
<h4><?php echo $contact; ?></h4>
</div>
<div class="col-25">
<h4>Email-Id</h4>
</div>
<div class="col-75">
<h4><?php echo $email; ?></h4>
</div>
<div class="col-25">
<h4>Address</h4>
</div>
<div class="col-75">
<h4><?php echo $address; ?></h4>
</div>
</div>
<div class="foot">
<div class="service">
<form action="main_guest.php" method="post">
<h3>Service booking</h3>
<input type="checkbox" name="serv[]" value="tea_or_coffee">
<label>Tea or Coffee</label><br>
<input type="checkbox" name="serv[]" value="lunch_or_dinner">
<label>Lunch or Dinner</label><br>
<input type="checkbox" name="serv[]" value="other_room_service">
<label>Other room service</label><br>
<input type="submit" name="create" value="Book" class="serv_book">
</form>
</div>
<div class="buttons">
<div class="form1">
<div class="update_bt">
<button onclick="location.href = 'update_profile.php';" class="update">Update profile</button>
</div>
</div>
<div class="form2">
<div class="booking_bt">
<button onclick="location.href = 'booking.php';" class="booking">Booking</button>
</div>
</div>
<div class="form3">
<div class="logout_bt">
<button onclick="location.href = 'logout.php';" class="logout">Logout</button>
</div>
</div>
</div>
</div>
</div>
</body>
</html>