-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_employee.php
More file actions
182 lines (175 loc) · 7.1 KB
/
main_employee.php
File metadata and controls
182 lines (175 loc) · 7.1 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
181
182
<?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 `Employee` AS g, `Emp_address` AS a WHERE a.emp_id=g.emp_id AND g.username='$username');";
$query1 .= "SELECT first_name, last_name FROM `Employee` 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 `Emp_contact` WHERE emp_id = (SELECT g.emp_id FROM `Employee` 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 `Emp_email` WHERE emp_id = (SELECT g.emp_id FROM `Employee` 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 department part
// dept_ids : (hard-coded, can be altered later)
// waiter = 0
// room_service = 1
// manager = 2
// bartender = 3
$servs = [
'waiter' => 0,
'room_service' => 1,
'manager' => 2,
'bartender' => 3
];
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 `Emp_dept` (`emp_id`, `dept_id`) VALUES ((SELECT g.emp_id FROM `Employee` AS g WHERE g.username='$username'), '$servs[$service]');";
for ($i = 1; $i < $n; $i++) {
$service = $services_selected[$i];
$sql .= "INSERT INTO `Emp_dept` (`emp_id`, `dept_id`) VALUES ((SELECT g.emp_id FROM `Employee` 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="dept">
<div class="service">
<form action="main_employee.php" method="post">
<h3>Choose your department</h3>
<input type="checkbox" name="serv[]" value="waiter">
<label>Waiter</label><br>
<input type="checkbox" name="serv[]" value="room_service">
<label>Room service</label><br>
<input type="checkbox" name="serv[]" value="manager">
<label>Manager</label><br>
<input type="checkbox" name="serv[]" value="bartender">
<label>Bartender</label><br>
<input type="submit" name="create" value="Submit" class="serv_book">
</form>
</div>
</div>
<div class="buttons" style="margin-left: 700px;">
<div class="form1">
<div class="update_bt">
<button onclick="location.href = 'update_profile.php';" class="update">Update profile</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>