-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplan.php
637 lines (546 loc) · 26.6 KB
/
plan.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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
<?php
session_start();
// Include the database connection file
include 'db_connection.php';
// Check if the user is logged in
$isLoggedIn = false; // Set a default value
if (isset($_SESSION['username'])) {
$isLoggedIn = true;
}
if (isset($_GET['logout'])) {
session_unset();
session_destroy();
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0" name="viewport">
<title>Well-being App | Plan</title>
<meta content="" name="description">
<meta content="" name="keywords">
<!-- Favicons -->
<link href="assets/img/favicon.png" rel="icon">
<link href="assets/img/apple-touch-icon.png" rel="apple-touch-icon">
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
<!-- Vendor CSS Files -->
<link href="assets/vendor/animate.css/animate.min.css" rel="stylesheet">
<link href="assets/vendor/aos/aos.css" rel="stylesheet">
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
<link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
<link href="assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
<link href="assets/vendor/remixicon/remixicon.css" rel="stylesheet">
<link href="assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
<!-- Template Main CSS File -->
<link href="assets/css/style.css" rel="stylesheet">
<style>
#datePicker, #customerDropdown {
margin-bottom: 20px;
}
#selectedValues {
font-size: 18px;
padding: 10px;
border: 1px solid #ccc;
display: inline-block;
}
body {
display: flex;
flex-direction: column;
min-height: 100vh; /* This ensures that the container takes at least the full height of the viewport. */
}
#footer {
margin-top: auto; /* Pushes the footer to the bottom of the container. */
}
</style>
<!-- =======================================================
* Template Name: Anyar
* Updated: Sep 18 2023 with Bootstrap v5.3.2
* Template URL: https://bootstrapmade.com/anyar-free-multipurpose-one-page-bootstrap-theme/
* Author: BootstrapMade.com
* License: https://bootstrapmade.com/license/
======================================================== -->
</head>
<body style="background-color: #1B72BD; min-height: 100vh;">
<!-- ======= Header ======= -->
<header id="header" class="fixed-top d-flex align-items-center">
<div class="container d-flex align-items-center justify-content-between">
<h1 class="logo"><a href="index.php">Well-being App</a></h1>
<!-- Uncomment below if you prefer to use an image logo -->
<!-- <a href=index.html" class="logo"><img src="assets/img/logo.png" alt="" class="img-fluid"></a>-->
<nav id="navbar" class="navbar">
<ul>
<li><a class="nav-link scrollto" href="index.php">Home</a></li>
<li><a class="nav-link scrollto " href="index.php #services">Services</a></li>
<li><a class="nav-link active" href="plan.php">Plan</a></li>
<li><a href="medication.php">Medication</a></li>
<li><a href="biometrics.php">Biometrics</a></li>
<li><a href="appointments.php">Appointments</a></li>
<?php if (isset($_SESSION['username'])): ?>
<li><a href="plan.php?logout=true" class="nav-link">Logout</a></li>
<?php else: ?>
<li><a href="login.php" class="nav-link">Login</a></li>
<li><a href="signup.php" class="nav-link">Signup</a></li>
<?php endif; ?>
</ul>
<i class="bi bi-list mobile-nav-toggle"></i>
<!-- <li><a href="login.php">Log In</a></li>
<li><a href="signup.php">Sign Up</a></li> -->
</ul>
<i class="bi bi-list mobile-nav-toggle"></i>
</nav><!-- .navbar -->
</div>
</header><!-- End Header -->
<main id="main" style="padding-top: 100px; padding-bottom: 20px;"> <!-- Adjust the padding value as needed -->
<?php if (!isset($_SESSION['username']) ): ?>
<div class="section-title">
<h2>You need to login to access this page </h2>
</div>
<?php elseif (isset($_SESSION['username']) ): ?>
<?php if (isset($_SESSION['username']) && isset($_SESSION['login_type']) && $_SESSION['login_type'] === 'employee'): ?>
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="signup-box">
<form>
<div class="form-group">
<h4 style="color: #007bff;">Select a Date</h4>
<input type="date" class="form-control" id="datePicker">
</div>
<div class="form-group">
<h4 style="color: #007bff;">Select a Customer</h4>
<select class="form-control" id="customerDropdown"></select>
</div>
<center>
<button type="button" class="btn btn-primary" onclick="storeAndPrintValues()">Search</button>
</center>
</form>
<br>
</div>
</div>
</div>
</div>
<?php elseif (isset($_SESSION['username']) && isset($_SESSION['login_type']) && $_SESSION['login_type'] === 'customer'): ?>
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<div class="signup-box">
<form>
<div class="form-group">
<h4 style="color: #007bff;">Select a Date</h4>
<input type="date" class="form-control" id="datePicker">
</div>
<center>
<button type="button" class="btn btn-primary" onclick="storeAndPrintValues()">Search</button>
</center>
</form>
<br>
</div>
</div>
</div>
</div>
<?php endif; ?>
<div class="container">
<div class="container mt-5">
<div class="row justify-content-center">
<table class = "table table-bordered" id="displayDietPlanData">
<thead>
<tr>
<th>Diet Plan Type</th>
<th>Meal Name</th>
<th>Meal Type</th>
<th>Calories</th>
<th>Proteins</th>
<th>Carbs</th>
<th>Fat</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<div class="container">
<div class="container mt-5">
<div class="row justify-content-center">
<table class = "table table-bordered" id="displayActivityPlanData">
<thead>
<th>Activity Plan Type</th>
<th>Activity Type</th>
<th>Duration</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
<?php if (isset($_SESSION['username']) && isset($_SESSION['login_type']) && $_SESSION['login_type'] === 'employee'): ?>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="signup-box">
<h4 style="color: #007bff;">Create Diet Plan</h4>
<form id="dietPlanForm" method="post" action="">
<div class="form-group">
<label for="customer_username1" style="color: #333;">Customer:</label>
<select class="form-control" id="customer_username1" name="customer_username1" required>
<!-- Options will be dynamically populated here -->
</select>
</div>
<div class="form-group">
<label for="start_date" style="color: #333;">Plan Start Date:</label>
<input type="date" class="form-control" id="start_date" name="start_date" required>
</div>
<div class="form-group">
<label for="end_date" style="color: #333;">Plan End Date:</label>
<input type="date" class="form-control" id="end_date" name="end_date" required>
</div>
<div class="form-group">
<label for="diet_plan_type" style="color: #333;">Diet Plan Type:</label>
<select class="form-control" id="diet_plan_type" name="diet_plan_type" required>
<option value="Ketogenic">Ketogenic</option>
<option value="Intermittent">Intermittent</option>
<option value="Plant-based">Plant-based</option>
<option value="Mediterranean">Mediterranean</option>
<option value="Vegan">Vegan</option>
<option value="Vegeterian">Vegeterian</option>
<option value="Pescetarian">Pescetarian</option>
</select>
</div>
<div class="form-group">
<label for="type" style="color: #333;">Meal Type:</label>
<select class="form-control" id="type" name="type" required>
<option value="Breakfast">Breakfast</option>
<option value="Lunch">Lunch</option>
<option value="Tithe">Tithe</option>
<option value="Dinner">Dinner</option>
</select>
</div>
<div class="form-group">
<label for="meal_name" style="color: #333;">Meal Name:</label>
<input type="text" class="form-control" id="meal_name" name="meal_name" required>
</div>
<div class="form-group">
<label for="calories" style="color: #333;">Calories:</label>
<input type="text" class="form-control" id="calories" name="calories" required>
</div>
<div class="form-group">
<label for="proteins" style="color: #333;">Proteins:</label>
<input type="text" class="form-control" id="proteins" name="proteins" required>
</div>
<div class="form-group">
<label for="carbs" style="color: #333;">Carbs:</label>
<input type="text" class="form-control" id="carbs" name="carbs" required>
</div>
<div class="form-group">
<label for="fat" style="color: #333;">Fat:</label>
<input type="text" class="form-control" id="fat" name="fat" required>
</div>
<div class="form-group">
<label for="meal_date" style="color: #333;">Meal Date:</label>
<input type="date" class="form-control" id="meal_date" name="meal_date" required>
</div>
<center>
<button type="submit" class="btn btn-primary" style="background-color: #007bff; border-color: #007bff;">Create Diet Plan</button>
</center>
</form>
</div>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-lg-6">
<div class="signup-box">
<h4 style="color: #007bff;">Create Activity Plan</h4>
<form id="activityPlanForm" method="post" action="">
<div class="form-group">
<label for="customer_username2" style="color: #333;">Customer:</label>
<select class="form-control" id="customer_username2" name="customer_username2" required>
<!-- Options will be dynamically populated here -->
</select>
</div>
<div class="form-group">
<label for="start_date" style="color: #333;">Plan Start Date:</label>
<input type="date" class="form-control" id="start_date" name="start_date" required>
</div>
<div class="form-group">
<label for="end_date" style="color: #333;">Plan End Date:</label>
<input type="date" class="form-control" id="end_date" name="end_date" required>
</div>
<div class="form-group">
<label for="activity_plan_type" style="color: #333;">Activity Plan Type:</label>
<select class="form-control" id="activity_plan_type" name="activity_plan_type" required>
<option value="Cardiovascular">Cardiovascular</option>
<option value="Strength">Strength</option>
<option value="Flexibility and Stretching">Flexibility and Stretching</option>
<option value="Balance and Coordination">Balance and Coordination</option>
<option value="High-Intensity Interval Training">High-Intensity Interval Training</option>
</select>
</div>
<div class="form-group">
<label for="activity_type" style="color: #333;">Activity Type:</label>
<input type="text" class="form-control" id="activity_type" name="activity_type" required>
</div>
<div class="form-group">
<label for="duration" style="color: #333;">Activity Duration (minutes):</label>
<input type="number" id="duration" name="duration" required>
</div>
<div class="form-group">
<label for="activity_date" style="color: #333;">Activity Date:</label>
<input type="date" class="form-control" id="activity_date" name="activity_date" required>
</div>
<center>
<button type="submit" class="btn btn-primary" style="background-color: #007bff; border-color: #007bff;">Create Activity Plan</button>
</center>
</form>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script>
function populateCustomerDropdown() {
var customerDropdown = document.getElementById('customerDropdown');
// Fetch customer data from MySQL using PHP
fetch('get_customer_usernames.php')
.then(response => response.json())
.then(data => {
data.forEach(customer => {
var option = document.createElement('option');
option.value = customer.customer_username; // Use customer_username as the value
option.text = customer.name; // Display customer names
customerDropdown.add(option);
});
});
}
// Call the function to populate the dropdown
populateCustomerDropdown();
</script>
<!-- <div id="selectedValues">Selected Date: <span id="displayDate"></span>, Selected Customer: <span id="displayCustomer"></span></div> -->
<script>
// Function to update the selected date in the display box
function updateSelectedDate() {
var selectedDate = document.getElementById('datePicker').value;
}
// Function to handle button click and fetch/display data from the database
function storeAndPrintValues() {
var selectedDate = document.getElementById('datePicker').value;
var selectedCustomer;
<?php
if (isset($_SESSION['username']) && isset($_SESSION['login_type']) && $_SESSION['login_type'] === 'customer') {
echo "selectedCustomer = '" . $_SESSION['username'] . "';";
} else {
echo "selectedCustomer = document.getElementById('customerDropdown').value;";
}
?>
console.log(selectedCustomer); // Log the entire data object to the console
// Make an AJAX request to fetch data from the server
fetch('fetch_plan.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: 'selectedDate=' + encodeURIComponent(selectedDate) +
'&selectedCustomer=' + encodeURIComponent(selectedCustomer),
})
.then(response => response.json())
.then(data => {
// Update the display element with the fetched data
console.log(data); // Log the entire data object to the console
fillTable(data);
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
function fillTable(data) {
// Get the table body
var tableBody = document.getElementById('displayDietPlanData').getElementsByTagName('tbody')[0];
// Clear the existing rows in the table body
tableBody.innerHTML = '';
// Iterate through the mealName array to create rows in the HTML table
for (var i = 0; i < data.mealName.length; i++) {
// Create a new row
var row = tableBody.insertRow(-1);
// Insert cells in the row for each data attribute
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
// Fill cells with data from the data array
cell1.innerHTML = data['dietPlanType'][i];
cell2.innerHTML = data['mealName'][i];
cell3.innerHTML = data['type'][i];
cell4.innerHTML = data['calories'][i];
cell5.innerHTML = data['proteins'][i];
cell6.innerHTML = data['carbs'][i];
cell7.innerHTML = data['fat'][i];
}
var tableBody = document.getElementById('displayActivityPlanData').getElementsByTagName('tbody')[0];
// Clear the existing rows in the table body
tableBody.innerHTML = '';
// Display additional information (activity plan) outside the loop
var additionalInfoRow = tableBody.insertRow(-1);
var activityPlanCell = additionalInfoRow.insertCell(0);
var activityTypeCell = additionalInfoRow.insertCell(1);
var durationCell = additionalInfoRow.insertCell(2);
activityPlanCell.innerHTML = data['activityPlanType'];
activityTypeCell.innerHTML = data['activityType'];
durationCell.innerHTML = data['duration'];
}
// Function to fetch and display data based on selected date and customer
function fetchAndDisplayData() {
var selectedDate = document.getElementById('datePicker').value;
var selectedCustomer;
<?php
if (isset($_SESSION['username']) && isset($_SESSION['login_type']) && $_SESSION['login_type'] === 'customer') {
echo "selectedCustomer = '" . $_SESSION['username'] . "';";
} else {
echo "selectedCustomer = document.getElementById('customerDropdown').value;";
}
?>
console.log(selectedCustomer); // Log the entire data object to the console
// Fetch and display data from the database
fetch('fetch_plan.php', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
selectedDate: selectedDate,
selectedCustomer: selectedCustomer,
}),
})
.then(response => response.json())
.then(data => {
console.log(data.mealName[0]); // Outputs: "Porridge"
fillTable(data);
})
.catch(error => {
console.error('Error:', error);
});
}
// Attach functions to events
document.getElementById('datePicker').addEventListener('change', updateSelectedDate);
window.addEventListener('DOMContentLoaded', updateSelectedDate);
</script>
</main><!-- End #main -->
<!-- ======= Footer ======= -->
<footer id="footer">
<div class="container text-center">
<div class="copyright">
© Copyright <strong><span>Well-being App</span></strong>. All Rights Reserved
</div>
<div class="contact-info">
<i class="bi bi-envelope-fill"></i><a href="mailto:[email protected]">[email protected]</a>
<i class="bi bi-phone-fill phone-icon"></i> +1 5589 55488 55
</div>
<div class="credits">
<!-- All the links in the footer should remain intact. -->
<!-- You can delete the links only if you purchased the pro version. -->
<!-- Licensing information: https://bootstrapmade.com/license/ -->
<!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/anyar-free-multipurpose-one-page-bootstrap-theme/ -->
</div>
</div>
</footer><!-- End Footer -->
<div id="preloader"></div>
<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
<!-- Vendor JS Files -->
<script src="assets/vendor/aos/aos.js"></script>
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="assets/vendor/glightbox/js/glightbox.min.js"></script>
<script src="assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
<script src="assets/vendor/swiper/swiper-bundle.min.js"></script>
<script src="assets/vendor/php-email-form/validate.js"></script>
<script>
// JavaScript to handle form submission asynchronously
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("dietPlanForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the default form submission
var formData = new FormData(this);
// Use AJAX to submit the form data to the PHP script
var xhr = new XMLHttpRequest();
xhr.open("POST", "process_diet_plan.php", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Display the response from the server (e.g., success message)
console.log(xhr.responseText);
}
};
xhr.send(formData);
var form = document.getElementById("dietPlanForm");
form.reset();
});
});
</script>
<script>
// Fetch data from get_customer_usernames.php using JavaScript
fetch('get_customer_usernames.php')
.then(response => response.json())
.then(data => {
// Populate the dropdown options for Form 2
const dropdown = document.getElementById('customer_username1');
data.forEach(customer => {
const option = document.createElement('option');
option.value = customer.customer_username;
option.text = customer.name; // Use the 'name' property for display
dropdown.add(option);
});
})
.catch(error => console.error('Error fetching customer data for Form 1:', error));
</script>
<!-- JavaScript for Form 2 -->
<script>
// Fetch data from get_customer_usernames.php using JavaScript
fetch('get_customer_usernames.php')
.then(response => response.json())
.then(data => {
// Populate the dropdown options for Form 2
const dropdown = document.getElementById('customer_username2');
data.forEach(customer => {
const option = document.createElement('option');
option.value = customer.customer_username;
option.text = customer.name; // Use the 'name' property for display
dropdown.add(option);
});
})
.catch(error => console.error('Error fetching customer data for Form 2:', error));
</script>
<script>
// JavaScript to handle form submission asynchronously
document.addEventListener("DOMContentLoaded", function() {
document.getElementById("activityPlanForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent the default form submission
var formData = new FormData(this);
// Use AJAX to submit the form data to the PHP script
var xhr = new XMLHttpRequest();
xhr.open("POST", "process_activity_plan.php", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Display the response from the server (e.g., success message)
console.log(xhr.responseText);
}
};
xhr.send(formData);
var form = document.getElementById("activityPlanForm");
form.reset();
});
});
</script>
<!-- Template Main JS File -->
<script src="assets/js/main.js"></script>
</body>
</html>