-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlocations.php
More file actions
192 lines (165 loc) · 6.05 KB
/
locations.php
File metadata and controls
192 lines (165 loc) · 6.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
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE HTML>
<!--
Alpha by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
-->
<html>
<head>
<link rel="icon" href="images/favicon.ico" type="image/ico">
<title>Locations</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="assets/css/main.css" />
</head>
<body class="is-preload">
<div id="page-wrapper">
<!-- Header -->
<?php
session_start();
if(isset($_SESSION['logged_in'])){
include("LoggedInHeader.php");
}
else{
include("header.php");
}?>
<table id='locations-table'>
<!-- <tr><td><p>Okay oO</p>Wow</td></tr>
<tr><td>Gang!</td></tr>
<tr><td></td></tr>
<tr><td></td></tr> -->
</table>
<?php include("footer.php"); ?>
</div>
<!-- Scripts -->
<script>
function requestLocations() {
var xmlhttp = new XMLHttpRequest();
return new Promise ((resolve, reject) => {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
let data = JSON.parse(xmlhttp.responseText);
return resolve(data);
}
}
let url = "./locationsdata.php?locations=true";
xmlhttp.open("GET", url, true);
xmlhttp.send();
});
}
function requestEmployees(lid) {
var xmlhttp = new XMLHttpRequest();
return new Promise ((resolve, reject) => {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
let data = JSON.parse(xmlhttp.responseText);
return resolve(data);
}
}
let url = "./locationsdata.php?employees=true&lid=" + lid;
xmlhttp.open("GET", url, true);
xmlhttp.send();
});
}
function requestCashier(eid) {
var xmlhttp = new XMLHttpRequest();
return new Promise ((resolve, reject) => {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
let data = JSON.parse(xmlhttp.responseText);
resolve(data);
}
}
let url = "./locationsdata.php?cashier=true&eid=" + eid;
xmlhttp.open("GET", url, true);
xmlhttp.send();
});
}
function requestDriver(eid) {
var xmlhttp = new XMLHttpRequest();
return new Promise ((resolve, reject) => {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
let data = JSON.parse(xmlhttp.responseText);
resolve(data);
}
}
let url = "./locationsdata.php?driver=true&eid=" + eid;
xmlhttp.open("GET", url, true);
xmlhttp.send();
});
}
const writeTable = (locations) => {
let table = document.getElementById('locations-table');
for(let location of locations) {
let lid = location.lid;
let finalLocation = location.laddrstr + ", " + location.laddrcity + ", " + location.laddrstate + ", " + location.laddrzip;
let newTr = document.createElement('tr');
let newTd = document.createElement('td');
let address = "Address: " + finalLocation;
let addressElem = document.createElement('p');
addressElem.innerHTML = address;
let cashierElem = document.createElement('p');
cashierElem.setAttribute("id", "cashier-" + lid);
let driversElem = document.createElement('p');
driversElem.setAttribute("id", "drivers-" + lid);
newTd.appendChild(addressElem);
newTd.appendChild(cashierElem);
newTd.appendChild(driversElem);
newTr.appendChild(newTd);
table.appendChild(newTr);
}
if (locations.length == 0) {
let newTr = document.createElement('tr');
let newTd = document.createElement('td');
newTd.innerHTML = "No Locations Have Been Made.";
newTr.appendChild(newTd);
table.appendChild(newTr);
}
};
const updateTable = (lid, data) => {
let cashierElem = document.getElementById('cashier-' + lid);
let driversElem = document.getElementById('drivers-' + lid);
let drivers = []
for(let entry of data) {
if(entry.job == 'cashier') {
requestCashier(entry.eid).then((cashier) => {
let exp = cashier[0].exp;
cashierElem.innerHTML = "Cashier: " + entry.ename + ", experience: " + exp;
});
} else {
drivers.push(entry);
}
}
driversElem.innerHTML = "Drivers: ";
for(let i = 0; i < drivers.length; i++) {
requestDriver(drivers[i].eid).then((driver) => {
if (i != 0) {
driversElem.innerHTML += " ";
}
let ephone = driver[0].ephone;
driversElem.innerHTML += drivers[i].ename + ", phone-number: " + ephone;
if (i != drivers.length - 1) {
driversElem.innerHTML += ",";
}
});
}
}
requestLocations().then((locations) => {
writeTable(locations);
for(let location of locations) {
requestEmployees(location.lid).then((employees) => {
updateTable(location.lid, employees);
})
}
});
</script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/jquery.dropotron.min.js"></script>
<script src="assets/js/jquery.scrollex.min.js"></script>
<script src="assets/js/browser.min.js"></script>
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
</body>
</html>