-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathJobList.php
405 lines (376 loc) · 17.6 KB
/
JobList.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<?php
require_once(__DIR__ . "/classes/database.php");
require_once(__DIR__ . "/classes/user.php");
require_once(__DIR__ . "/classes/company.php");
session_start();
if (!isset($_SESSION["user"]) || !($_SESSION["user"] instanceof User)) {
header("Location: index.php");
die(0);
}
$user = $_SESSION["user"];
if (!$user->is_authenticated()) {
header("Location: index.php");
die(0);
}
$user->get_user();
if (isset($_REQUEST["page"])) {
try {
$page = intval($_REQUEST["page"]);
}
catch (Throwable $e) {
$page = 1;
}
}
else {
$page = 1;
}
if ($page < 1) {
$page = 1;
}
$offset = 0;
const RESULTS_PER_PAGE = 20;
$offset = ($page - 1) * RESULTS_PER_PAGE;
if ($offset < 0) {
$offset = 0;
}
$jobs = array();
$pdo = Database::connect();
$query = "SELECT JobPostings.*, UserJobs.UserAccepted, UserJobs.CompanyAccepted, UserJobs.CompanySeen, Companies.Name FROM JobPostings INNER JOIN UserJobs ON JobPostings.JobID = UserJobs.JobID INNER JOIN Companies ON JobPostings.CompanyID = Companies.CompanyID WHERE UserJobs.UserID = ? AND UserJobs.UserSeen = 1 LIMIT " . RESULTS_PER_PAGE . " OFFSET " . $offset;
$statement = $pdo->prepare($query);
$statement->execute([$user->user_id]);
$jobs = $statement->fetchAll();
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Viewed Jobs - JobAssembler</title>
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
<!-- Jquery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- Leafletjs (map) -->
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin="" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
<script>
var map;
var marker;
$(function () {
map = L.map("map").setView({lat: 53.4808, lng: -2.2426}, 13);
marker = L.marker({lat: 0, lng: 0});
map.invalidateSize();
// add the OpenStreetMap tiles
L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxZoom: 19,
attribution: "© <a href=\"https://openstreetmap.org/copyright\">OpenStreetMap contributors</a>"
}).addTo(map);
// show the scale bar on the lower left corner
L.control.scale({imperial: true, metric: true}).addTo(map);
})
</script>
<script>
$(function () {
$("#jobDetailsModal").on("show.bs.modal", function (event) {
let button = $(event.relatedTarget) // Button that triggered the modal
let id = button.data("job-id") // Extract info from data-* attributes
$.ajax({
type:"GET",
url:"api/jobDetails.php?id=" + id,
success: function(data){
let modal = $(this);
$("#jobDetailsTitle").text(data["Title"]);
$("#jobDetailsText").text(data["Details"]);
if (data["CompanyImage"] != null) {
$("#jobDetailsImage").attr("src", data["CompanyImage"]);
}
else {
$("#jobDetailsImage").attr("src", "Images/Logo1.png");
}
$("#jobDetailsCompanyName").text(data["Name"]);
$("#jobDetailsCompanyDescription").text(data["Description"]);
if (data["Latitude"] != null && data["Longitude"] != null) {
$("#mapSection").show();
map.setView({lat: data["Latitude"], lng: data["Longitude"]}, 17);
marker.remove();
marker.setLatLng({lat: data["Latitude"], lng: data["Longitude"]}).bindPopup(`<a href="https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(data["Latitude"] + "," + data["Longitude"])}">Latitude: ${data["Latitude"]}, Longitude: ${data["Longitude"]}</a>`).addTo(map);
} else {
$("#mapSection").hide();
}
if (data["Salary"] == "" || data["Salary"] == null) {
$("#jobDetailsSalary").text("0");
} else {
$("#jobDetailsSalary").text(data["Salary"]);
}
console.log(data);
},
error: function(xhr){
let response = xhr.responseJSON
if (response.hasOwnProperty("message")) {
alert("Error:\n" + response["message"]);
} else {
alert("An unknown error occurred. Please try again later.")
}
}
})
});
$("#jobDetailsModal").on("shown.bs.modal", function (event) {
map.invalidateSize();
});
$("#jobUpdateModal").on("show.bs.modal", function (event) {
let button = $(event.relatedTarget) // Button that triggered the modal
let id = button.data("job-id") // Extract info from data-* attributes
console.log(id)
$.ajax({
type:"GET",
url:"api/jobDetails.php?id=" + id,
success: function(data){
$("#jobUpdateModal").data("job-id", id)
$("#jobUpdateText").text(data["Name"] + ": " + data["Title"]);
console.log(data);
},
error: function(xhr){
alert("error\n" + xhr.responseJson);
}
})
})
$("#jobUpdateAccept").on("click", function (event) {
let modal = $("#jobUpdateModal");
let id = modal.data("job-id");
$.ajax({
type:"POST",
url:"api/jobUpdating.php?userID=<?=$user->user_id?>&userAccepted=1&jobID=" + id,
success: function(data){
window.location.reload();
},
error: function(xhr){
alert("error\n" + xhr.responseJson);
}
})
}
)
$("#jobUpdateDecline").on("click", function (event) {
let modal = $("#jobUpdateModal");
let id = modal.data("job-id");
$.ajax({
type:"POST",
url:"api/jobUpdating.php?userID=<?=$user->user_id?>&userAccepted=0&jobID=" + id,
success: function(data){
window.location.reload();
},
error: function(xhr){
alert("error\n" + xhr.responseJson);
}
})
}
)
$(".report").on("click", function (event) {
console.log(event)
let id = event.target.dataset["jobId"]
$.ajax({
type:"POST",
url:"api/report.php?JobID=" + id,
success: function(data){
if (data.hasOwnProperty("message")) {
alert(data["message"]);
}
},
error: function(xhr){
alert("error\n" + xhr.responseJson);
}
})
}
)
})
</script>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
background: url("Images/pedro-lastra-Nyvq2juw4_o-unsplash.jpg") no-repeat
center fixed;
}
.container{
background: white;
position:relative;
margin-top: 100px;
margin-bottom: 50px;
border-radius: 15px;
}
.php {
color: #e9ecef;
}
/* For navbar */
/* For Logo border*/
.d-inline-block-align-top {border-radius: 5px;}
/* For DownMenu */
.navbar-text{
color: yellow;
}
.navbar-nav{
position:absolute;
right: 50px;
}
</style>
</head>
<body>
<!-- Nav bar -->
<nav class="navbar navbar-expand-sm bg-primary navbar-dark fixed-top">
<a class="navbar-brand">
<!-- Brand LOGO -->
<a class="navbar-brand">
<img src="Images/Logo1.png" width="30" height="30" class="d-inline-block-align-top" alt="Logo";>
</a>
<span class="navbar-text active" style="color: white;">
<?php
echo("You are signed in as: " . $user->username);
?>
</span>
<ul class="navbar-nav" >
<form class="form-inline">
<li class="nav-item active">
<a class="nav-link" href="EmployeeSwipeScreen.php">Home</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="userSkills.php">My Skills</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="EmployeeForm.php">Edit Details</a>
</li>
<li class="nav-item active">
<a class="btn-danger" style="margin-left: 30%; padding: 10px; white-space: nowrap;" href="api/logout.php">Log Out</a>
</li>
</form>
</ul>
</nav>
<main class="container" style="padding-top: 2rem">
<div style="text-align: right;">
<a class="btn btn-secondary" href="main.php"><i class="bi bi-arrow-left-circle-fill"></i> Back</a>
</div>
<h1 style= "font-family: Helvetica">Your viewed jobs</h1>
<h4 class="text-muted">All the jobs you have either accepted or declined can be seen here</h4>
<br/>
<table class="table">
<thead>
<tr>
<th scope="col">Company</th>
<th scope="col">Job Title</th>
<!--<th scope="col">About</th>-->
<th scope="col">Location</th>
<th scope="col">Accepted</th>
<th scope="col">Company Accepted</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
<?php if(count($jobs) == 0): ?>
<tr>
<th colspan="5" style="text-align: center;">No results found.</th>
</tr>
<?php else: ?>
<?php foreach($jobs as $num => $line): ?>
<?php
if (!$line["CompanySeen"]) {
$companyAcceptedText = "Not Seen";
$companyAcceptedStyle = "text-secondary";
}
else {
$companyAcceptedText = $line["CompanyAccepted"] ? "Accepted": "Declined";
$companyAcceptedStyle = $line["CompanyAccepted"] ? "text-success" : "text-danger";
}
?>
<tr>
<td><?= $line["Name"]?></td>
<td><?= $line["Title"]?></td>
<!--<td style="word-break:break-all;"><?= $line["Details"]?></td>-->
<td><?= $line["RemoteJob"] ? "Remote" : (is_null($line["Latitude"]) || is_null($line["Longitude"]) ? "None Given" : "See Details") ?></td>
<td class="<?= $line["UserAccepted"] ? "text-success" : "text-danger" ?>"><?= $line["UserAccepted"] ? "Accepted": "Declined"?></td>
<td class="<?= $companyAcceptedStyle ?>"><?= $companyAcceptedText?></td>
<td>
<div class="dropdown show">
<button class="btn btn-sm dropdown-toggle" href="" role="button" id="dropdownMenuLink<?=$num?>" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Options
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink<?=$num?>">
<button class="dropdown-item btn" data-toggle="modal" data-target="#jobDetailsModal" data-job-id="<?=$line["JobID"]?>">View details</button>
<button class="dropdown-item btn" data-toggle="modal" data-target="#jobUpdateModal" data-job-id="<?=$line["JobID"]?>">Change acceptance</button>
<button class="dropdown-item btn btn-danger report" data-job-id="<?=$line["JobID"]?>">Report</button>
</div>
</div>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<nav style="padding-bottom: 10px">
<ul class="pagination justify-content-center">
<li class="page-item<?=$page == 1 ? " disabled" : ""?>"><a class="page-link"<?=$page != 1 ? " href=\"?page=". $page - 1 ."\"" : ""?><?=$page == 1 ? " disabled" : ""?>>Previous</a></li>
<?php if ($page != 1): ?>
<li class="page-item"><a class="page-link" href="?page=<?=$page-1?>"><?=$page-1?></a></li>
<?php endif; ?>
<li class="page-item active"><a class="page-link"><?=$page?></a></li>
<li class="page-item"><a class="page-link" href="?page=<?=$page+1?>"><?=$page+1?></a></li>
<li class="page-item"><a class="page-link" href="?page=<?=$page+1?>">Next</a></li>
</ul>
</nav>
<div class="modal fade" tabindex="-1" role="dialog" id="jobDetailsModal" aria-labelledby="jobDetailsTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="jobDetailsTitle"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p id="jobDetailsText" style="word-break: break-word;"></p>
<p style="word-wrap: break-word"><span style="font-weight: bold">Yearly Salary:</span> £<a id="jobDetailsSalary">0</a></p>
</div>
<div class="modal-body" id="mapSection" style="border-top: 1px solid #e9ecef">
<div id="map" style="height: 200px;"></div>
</div>
<div class="modal-body" style="border-top: 1px solid #e9ecef">
<img id="jobDetailsImage" style="width: 100px; height: 100px; float: left; margin: 10px;" src="Images/Logo1.png" class="rounded float-left"/>
<div>
<h6 id="jobDetailsCompanyName">Unknown</h6>
<p id="jobDetailsCompanyDescription">Unknown</p>
</div>
</div>
<div class="modal-footer">
<!--<button type="button" class="btn btn-primary">Save changes</button>-->
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" tabindex="-1" role="dialog" id="jobUpdateModal" aria-labelledby="jobUpdateTitle" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="jobUpdateTitle">Change job acceptance</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h6 id="jobUpdateText" style="word-break: break-word;"></h6>
<p>Change job acceptance status?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" id="jobUpdateAccept">Accept job</button>
<button type="button" class="btn btn-danger" id="jobUpdateDecline">Decline job</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
</div>
</div>
</div>
</div>
</main>
</body>
</html>