-
Notifications
You must be signed in to change notification settings - Fork 0
/
bestworker.php
432 lines (399 loc) · 15.2 KB
/
bestworker.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
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Worker Management</title>
<!-- Add Bootstrap CSS link -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- slider stylesheet -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.min.css" />
<!-- bootstrap core css -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
<!-- font awesome style -->
<link rel="stylesheet" type="text/css" href="css/font-awesome.min.css" />
<!-- Custom styles for this template -->
<link href="css/style.css" rel="stylesheet" />
<!-- responsive style -->
<link href="css/responsive.css" rel="stylesheet" />
<style>
.error-message {
color: red;
}
</style>
</head>
<body>
<div class="hero_area">
<!-- header section strats -->
<header class="header_section">
<div class="header_top">
<div class="container-fluid">
<div class="contact_nav">
<a href="">
<i class="fa fa-phone" aria-hidden="true"></i>
<span>
Call : +968 91111111
</span>
</a>
<a href="">
<i class="fa fa-envelope" aria-hidden="true"></i>
<span>
Email : [email protected]
</span>
</a>
</div>
</div>
</div>
<div class="header_bottom">
<div class="container-fluid">
<nav class="navbar navbar-expand-lg custom_nav-container ">
<a class="navbar-brand" href="index.html">
<span>
<img src="./images/logo.png" style="height: 50px;" alt="">
</span>
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class=""> </span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ">
<li class="nav-item ">
<a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="schedule.php">schedule an appointment</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html"> About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="funpage.html">funpage</a>
</li>
<li class="nav-item">
<a class="nav-link" href="service.html">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="Questionnairepage.php">Questionnaire page</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="bestworker.php">best worker</a>
</li>
<li class="nav-item">
<a class="nav-link" href="billCalculator.html">Bill Calculator</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact Us</a>
</li>
</ul>؛
</div>
</nav>
</div>
</div>
</header>
<!-- end header section -->
</div>
<div style="padding-bottom: 2cm;" class="container mt-5">
<?php
class Worker {
public $name;
public $pos;
public $perf;
public $review;
function __construct($name, $pos, $perf, $review) {
$this->name = $name;
$this->pos = $pos;
$this->perf = $perf;
$this->review = $review;
}
function get_name() {
return $this->name;
}
function get_pos() {
return $this->pos;
}
function get_perf() {
return $this->perf;
}
function get_review() {
return $this->review;
}
}
?>
<!-- Worker Table -->
<table class="table table-bordered" id="workerTable">
<thead class="thead-dark">
<tr>
<th>Name</th>
<th>Position</th>
<th>Performance</th>
<th>User Review</th> <!-- New Column for User Review -->
</tr>
</thead>
<tbody id="workerTableBody" style="text-align: center;">
<?php
$server_name = "ulsq0qqx999wqz84.chr7pe7iynqr.eu-west-1.rds.amazonaws.com"; $username = "xe2ge1qqbdrgxdx6";
$password = "inio92922tfakvh4"; $dbname = "seklrqnnhsqij64j";
$conn = mysqli_connect($server_name, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: ".
mysqli_connect_error());
}
$sql = "SELECT * FROM seklrqnnhsqij64j.workers";
// if search for worker.
if (isset($_POST["search"])) {
if ($_POST["search"] != "") {
$sql .= " where name='".$_POST["search"]."'";
}}
// end if search for worker.
$workers = array();//array of Worker object.
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_assoc($result)){
// push worker objects to workers array
array_push($workers, new Worker($row["name"], $row["position"], $row["performance"], $row["review"]));
}
}
// add workers to the table
foreach ($workers as $worker) {
echo "<tr>".
"<td>". $worker->get_name() ."</td>".
"<td>". $worker->get_pos() ."</td>".
"<td>". $worker->get_perf() ."/10</td>".
"<td>". $worker->get_review() ."</td>".
"</tr>";
}
?>
</tbody>
</table>
<!-- Form for adding a worker -->
<form id="addWorkerForm" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<div class="form-group">
<label for="workerName">Name:</label>
<input type="text" class="form-control" id="workerName" name="name" required>
<div class="error-message">
<?php
// name validation
$isnamed = true;
if (isset($_POST["name"])){
if (strlen($_POST["name"]) > 25){
echo "name < 26";
$isnamed = false;
}
}
?>
</div>
</div>
<div class="form-group">
<label for="workerPosition">Position:</label>
<input type="text" class="form-control" id="workerPosition" name="pos" required>
<div class="error-message">
<?php
// Position validation
$ispos = true;
if (isset($_POST["pos"])){
if (strlen($_POST["pos"]) > 25){
echo "Position < 26";
$ispos = false;
}
}
?>
</div>
</div>
<div class="form-group">
<label for="workerPerformance">Performance:</label>
<input type="number" class="form-control" id="workerPerformance" name="perf" required>
<div class="error-message">
<?php
// Performance validation
$isperf = true;
if (isset($_POST["perf"])){
if (!is_numeric($_POST["perf"])){// if empty
echo "not valid";
$isperf = false;
}
//if out of range
if (is_numeric($_POST["perf"]) and (0 > $_POST["perf"] or $_POST["perf"] > 10)){
echo "perforamne must in range 0-10";
$isperf = false;
}
}
?>
</div>
</div>
<div class="form-group">
<label for="userReview">User Review:</label>
<textarea class="form-control" id="userReview" name="review" rows="2" required></textarea>
</div>
<input type="submit" class="btn btn-primary" value="Add Worker">
</form>
<?php
// add new worker review
if (!$isnamed or !$ispos or !$isperf){
exit();
}
if (isset($_POST["name"])) {
$worker = new Worker($_POST["name"], $_POST["pos"], $_POST['perf'], $_POST['review']);
$sql = "insert into workers (name, position, performance, review) values
(\"{$worker->get_name()}\", \"{$worker->get_pos()}\" , {$worker->get_perf()}, \"{$worker->get_review()}\")";
$result = mysqli_query($conn, $sql);
// end add new worker review
}
?>
<!-- Form for searching for a worker -->
<form id="searchWorkerForm" method="post" action="<?php echo $_SERVER["PHP_SELF"] ?>">
<div class="form-group">
<label for="searchName">Search by Name:</label>
<input type="text" class="form-control" id="searchName" name="search">
</div>
<input class="btn btn-info" type="submit" value="Search Worker">
</form>
</div>
<section class="info_section">
<div class="container">
<h4>
Get In Touch
</h4>
<div class="row">
<div class="col-lg-10 mx-auto">
<div class="info_items">
<div class="row">
<div class="col-md-4">
<a href="">
<div class="item ">
<div class="img-box ">
<i class="fa fa-map-marker" aria-hidden="true"></i>
</div>
<p>
6Th alkhod, Al seeb, Muscat
</p>
</div>
</a>
</div>
<div class="col-md-4">
<a href="">
<div class="item ">
<div class="img-box ">
<i class="fa fa-phone" aria-hidden="true"></i>
</div>
<p>
+968 91111111
</p>
</div>
</a>
</div>
<div class="col-md-4">
<a href="">
<div class="item ">
<div class="img-box">
<i class="fa fa-envelope" aria-hidden="true"></i>
</div>
<p>
</p>
</div>
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="social-box">
<h4>
Follow Us
</h4>
<div class="box">
<a href="">
<i class="fa fa-facebook" aria-hidden="true"></i>
</a>
<a href="">
<i class="fa fa-twitter" aria-hidden="true"></i>
</a>
<a href="">
<i class="fa fa-youtube" aria-hidden="true"></i>
</a>
<a href="">
<i class="fa fa-instagram" aria-hidden="true"></i>
</a>
</div>
</div>
</section>
<!-- end info_section -->
<!-- footer section -->
<footer class="footer_section">
<div class="container">
<p>
© <span id="displayDateYear"></span> SkyTech 2023 C
</p>
</div>
</footer>
<!-- footer section -->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js">
</script>
<script src="js/custom.js"></script>
<!-- Add Bootstrap JS and Popper.js scripts (required for some Bootstrap features) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
// Object type for a worker
function Worker(name, position, performance, userReview) {
this.name = name;
this.position = position;
this.performance = performance;
this.userReview = userReview;
}
// Array to store worker information
let workersArray = [];
function before(){
const tableBody = document.getElementById('workerTableBody');
for (let i = 0; i < tableBody.rows.length; i++){
const row = tableBody.rows[i].cells;
let name = row[0].innerHTML;
let pos = row[1].innerHTML;
let strs = row[2].innerHTML;
let message = row[3].innerHTML;
workersArray.push(new Worker(name, pos, strs, message));
}
}
before();
// Function to dynamically display information in a table
function displayTable(dataArray) {
const tableBody = document.getElementById('workerTableBody');
tableBody.innerHTML = ''; // Clear existing rows
dataArray.forEach(worker => {
const row = tableBody.insertRow();
row.insertCell(0).textContent = worker.name;
row.insertCell(1).textContent = worker.position;
row.insertCell(2).textContent = worker.performance;
row.insertCell(3).textContent = worker.userReview;
});
}
// Function to add a worker to the array and update the table
function addWorker() {
const name = document.getElementById('workerName').value;
const position = document.getElementById('workerPosition').value;
const performance = document.getElementById('workerPerformance').value;
const userReview = document.getElementById('userReview').value;
const worker = new Worker(name, position, performance, userReview);
workersArray.push(worker);
displayTable(workersArray);
// Reset the form
document.getElementById('addWorkerForm').reset();
}
// Function to search for a worker by name
function searchWorker() {
const searchName = document.getElementById('searchName').value.toLowerCase();
// Search in the array
const foundWorker = workersArray.find(worker => worker.name.toLowerCase() === searchName);
if (foundWorker) {
displayTable([foundWorker]);
} else {
alert('Worker not found!');
}
}
</script>
</body>
</html>