-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
734 lines (647 loc) · 23 KB
/
profile.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
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
<?php
session_start();
// Check if the user is already logged in
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
// Connect to the database
$dsn = 'mysql:host=localhost;dbname=fitfuelhub_db';
$username = 'root';
$password = '';
try {
$db = new PDO($dsn, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Database Error: ' . $e->getMessage();
die();
}
// Retrieve user data from the database
$query = "SELECT * FROM user WHERE user_id = :user_id";
$stmt = $db->prepare($query);
$stmt->execute([':user_id' => $_SESSION['user_id']]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
// Assign user data to variables
$fullName = $user['username'];
$email = $user['email'];
$gender = $user['sex'];
$birthday = $user['birthday'];
$height = $user['height'];
$weight = $user['weight'];
$joinDate = $user['created_at'];
$profile_picture = $user['profile_picture'];
if (isset($_COOKIE['custom_meal'])) {
$cookieData = json_decode($_COOKIE['custom_meal'], true);
} else {
$cookieData['calories'] = 0;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $user['username']; ?></title>
</head>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color:white;
}
.navbar {
background: linear-gradient(to right, black, #222831);
padding: 10px;
display: flex;
align-items: center;
}
.navbar .logo {
margin-right: auto;
padding: 5px;
}
.login-button:hover {
background-color: #424953;
}
.profile {
padding:0px;
background-color:white;
}
.container {
display: flex;
width: 95%;
margin: 10px auto;
border-radius: 8px;
}
.left-portion {
flex: 80%;
background-color: #f0f0f0;
padding:0px;
}
.right-portion {
flex: 20%;
padding: 20px;
margin-left:20px;
}
.profile-header {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #222831;
color: #fff;
padding: 15px;
border-top-left-radius: 8px;
}
.profile-header h1 {
font-size: 32px;
margin: 0;
}
.profile-info {
margin-top: 30px;
text-align:left;
margin-left:22px;
}
.profile-info h2 {
font-size: 28px;
margin-bottom: 10px;
}
.profile-info p {
font-size: 18px;
margin: 5px 0;
color: #333; /* Text color */
line-height: 1.6; /* Line height for better readability */
}
.profile-picture img {
width: 100%;
border-radius: 50%;
object-fit: cover;
border: 5px solid #222831;
box-shadow: 0 4px 8px brown;
}
.navbar button {
border-radius: 0px;
background-color: inherit;
color: #fff;
padding:fit-content 50px;
border: none;
cursor: pointer;
font-size: 20px;
float:right;
}
.navbar button:hover{
background-color: #424953;
}
.profile-buttons {
background-color: #222831;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 18px;
margin-bottom: 5px;
width:95%;
}
.logo{
height:128px;
}
.health-bar {
margin-top:10px;
width: 300px;
height: 30px;
border-radius:14px;
border: 2px solid #000;
position: relative;
}
.health-value {
color:black;
position: absolute;
top: 120%;
left: 50%;
transform: translateX(-50%);
cursor:default;
}
.health-fill {
border-radius:10px;
height: 100%;
background: linear-gradient(to left, black, darkred);
box-shadow:0px 0px 15px red;
}
.sidebuttons {
position: absolute;
right: 350px;
top: 50%;
transform: translateY(-50%);
display: flex;
flex-direction: column;
width:250px;
}
.sideButtons {
margin-bottom: 10px;
border-radius:2px;
font-size:30px;
background: linear-gradient(to left, black, #222831);
color:white;
}
.hoverable-btn {
padding:10px 0px;
margin-bottom: 10px;
border-radius:2px;
font-size:30px;
width: inherit; /* Set your desired width for the buttons on hover */
transition: width 0.3s ease; /* Add transition for smooth width change */
background: linear-gradient(to left, #222831, black);
color:white;
}
.hoverable-btn:hover {
width: 290px; /* Set your desired width for the buttons on hover */
}.popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1;
}
.popup-content {
background-color: #f9f9f9;
margin: 20% auto;
padding: 20px;
border: 1px solid #888;
width: 60%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #000;
}
/* Adjust popup size and position as needed */
@media screen and (max-width: 600px) {
.popup-content {
width: 80%;
}
}
.radio-container {
max-width: 550px;
}
.radio-wrapper {
margin-bottom: 20px;
}
.radio-button {
display: flex;
align-items: center;
cursor: pointer;
transition: all 0.2s ease-in-out;
}
.radio-button:hover {
transform: translateY(-2px);
}
.radio-button input[type="radio"] {
display: none;
}
.radio-checkmark {
display: inline-block;
position: relative;
width: 16px;
height: 16px;
margin-right: 10px;
border: 2px solid #333;
border-radius: 50%;
}
.radio-checkmark:before {
content: "";
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #333;
transition: all 0.2s ease-in-out;
}
.radio-button input[type="radio"]:checked ~ .radio-checkmark:before {
transform: translate(-50%, -50%) scale(1);
}
.radio-label {
color:gray;
font-size: 16px;
font-weight: 600;
}
.popup {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1;
}
.popup-content {
background-color: #f9f9f9;
margin: 20% auto;
padding: 20px;
border: 1px solid #888;
width:fit-content;
align-items:center;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: #000;
}
#updateForm{
width:300px;
}
#updateForm label{
width:300px;
text-align:center;
margin-bottom:10px;
}
#updateForm input{
width:290px;
text-align:center;
font-size:20px;
}
</style>
<body>
<div id="activityLevelPopup" class="popup">
<div class="popup-content">
<span class="close" onclick="closeActivityLevelPopup()">×</span>
<div class="radio-container">
<div class="radio-wrapper">
<label class="radio-button">
<input type="radio" name="activity_level" id="activity_sedentary" value="1">
<span class="radio-checkmark"></span>
<span class="radio-label">Sedentary (little to no exercise)</span>
</label>
</div>
<div class="radio-wrapper">
<label class="radio-button">
<input type="radio" name="activity_level" id="activity_light" value="2">
<span class="radio-checkmark"></span>
<span class="radio-label">Lightly active (light exercise/sports 1-3 days/week)</span>
</label>
</div>
<div class="radio-wrapper">
<label class="radio-button">
<input type="radio" name="activity_level" id="activity_moderate" value="3">
<span class="radio-checkmark"></span>
<span class="radio-label">Moderately active (moderate exercise/sports 3-5 days/week)</span>
</label>
</div>
<div class="radio-wrapper">
<label class="radio-button">
<input type="radio" name="activity_level" id="activity_very_active" value="4">
<span class="radio-checkmark"></span>
<span class="radio-label">Very active (hard exercise/sports 6-7 days a week)</span>
</label>
</div>
<div class="radio-wrapper">
<label class="radio-button">
<input type="radio" name="activity_level" id="activity_extra_active" value="5">
<span class="radio-checkmark"></span>
<span class="radio-label">Extra active (very hard exercise/sports & physical job or training)</span>
</label>
</div>
</div>
<button style="float:center;"onclick="applyActivityLevel()">Apply</button>
</div>
</div>
<script>
var Weight = <?php echo $weight ?>;
var Height = <?php echo $height ?>;
var Age = <?php echo $birthday ?>;
var Gender = "<?php echo $gender ?>";
console.log(Gender);
var hm = Height / 100;
var BMI = Weight / (hm * hm);
console.log(BMI.toFixed(2));
</script>
<nav class="navbar">
<a href="home.php" class="logo">
<img class="logo" src="images/logo.png" alt="FitHub Logo">
</a>
<a href="meal-maker.php">
<button><i class="fas fa-utensils"></i> Make A Meal</button>
</a>
<a href="recipes.php">
<button><i class="fas fa-book-open"></i> Recipes</button>
</a>
<a href="#">
<button><i class="fas fa-dumbbell"></i> Training</button>
</a>
<h2 style="color:white;cursor:default;font-size:16px;margin-left:100px;margin-right:40px;">Connected as <?php echo $user['username']; ?></h2>
</nav>
<main class="profile">
<div class="container">
<div class="left-portion">
<div class="profile-header">
<h1 style="margin-left:12px;"><?php echo $fullName; ?></h1>
<p>Date Joined: <?php echo $joinDate; ?></p>
</div>
<div class="profile-info">
<h2 style="font-size:24px;">Daily Calories Goal :
<span id="result">Choose Your Activity Level</span></input>
<div class="health-bar">
<div class="health-fill" id="healthBar"></div>
<div class="health-value"><?php echo $cookieData['calories'] ?> Kcal</div>
</div>
</div>
<div style="text-align: left;margin-left:20px;">
</div>
</div>
<div class="sidebuttons">
<button class="hoverable-btn"><?php echo $weight; ?> Kg</button>
<button class="hoverable-btn"><?php echo $height; ?> Cm</button>
<button class="sideButtons"><?php echo $gender; ?></button>
<button class="sideButtons"> <?php echo $birthday;?> Years</button>
</div>
<div id="updatePopup" class="popup">
<div class="popup-content">
<span class="close" onclick="closePopup()">×</span>
<form id="updateForm" action="update-info.php" method="POST">
<label for="weightInput">Weight:</label>
<input type="number" id="weightInput" name="weight" step="0.01" placeholder="Enter new weight (kg)" value="<?php echo $weight; ?>">
<label for="heightInput">Height:</label>
<input type="number" id="heightInput" name="height" step="0.01" placeholder="Enter new height (cm)" value="<?php echo $height; ?>">
<button type="submit">Update</button>
</form>
</div>
</div>
<div class="right-portion">
<div class="profile-picture">
<img id="profileImg" src="<?php echo "images/profiles/$profile_picture"; ?>" alt="User Profile Picture">
<form action="upload_profile_picture.php" method="POST" enctype="multipart/form-data">
<input type="file" id="profileInput" name="profile_picture" accept="image/*" style="display: none;">
<button style="background-color:darkred;" type="submit" class="profile-buttons"><strong><i class="fas fa-upload"></i> Apply Profile Picture</strong></button>
</form>
</div>
<div>
<button id="weightBtn" class="profile-buttons"><strong><i class="fas fa-dumbbell"></i> Update Weight</strong></button>
<button class="profile-buttons" onclick="openActivityLevelPopup()"><strong><i class="fas fa-fire"></i> Activity Level</strong></div>
<button class="profile-buttons"><strong><i class="fas fa-cog"></i> Settings</strong></button>
<button class ="profile-buttons"><a href="logout.php" class="profile-buttons"><strong><i class="fas fa-sign-out-alt"></i> Log Out</strong></a></button>
</div>
</div>
</main>
<section style="background-color: #f0f0f0;">
<div style="background-color: #222831;width: 100%;text-align:center;color:white;margin-top:100px;">
<h1>Analytics</h1>
<p style="font-size:20px;">Here you can find Your weekly progress wether you are on a caloric surplus or a protein diet, Just click on calories label to show detailed values of other macronutrients</p>
</div>
<div style="width: 80%; margin: 0 auto;background-color: #fff;">
<canvas id="myChart"></canvas>
<div class="right-portion">
<div>
<button id="addDataButton">Update The Chart </button>
</div>
<script>
var days = 0; // Initialize days for the label button
var currentDate = new Date();
var currentDayNumber = currentDate.getDay();
var daysOfWeek = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var labels = [];
// Loop through the days of the week
for (var i = 0; i < 7; i++) {
var dayIndex = (currentDayNumber + i) % 7;
labels.push(daysOfWeek[dayIndex]);
}
var chartData = {
labels: labels,
datasets: [
{
label: "Calories",
data: getStoredData("calories") || [], // Retrieve stored data or initialize with empty array
borderColor: "red",
yAxisID: 'y', // Use the main y-axis
fill: false
},
{
label: "Carbohydrates",
data: getStoredData("carbohydrates") || [], // Retrieve stored data or initialize with empty array
borderColor: "green",
yAxisID: 'y1', // Use the main y-axis
fill: false
},
{
label: "Fat",
data: getStoredData("fat") || [], // Retrieve stored data or initialize with empty array
borderColor: "gold",
yAxisID: 'y1', // Use the main y-axis
fill: false
},
{
label: "Proteins",
data: getStoredData("protein") || [], // Retrieve stored data or initialize with empty array
borderColor: "rgba(75, 192, 192, 1)",
yAxisID: 'y1', // Use the main y-axis
fill: false
}
]
};
var ctx = document.getElementById('myChart').getContext('2d');
var myLineChart = new Chart(ctx, {
type: 'line',
data: chartData,
options: {
scales: {
y: {
type: 'linear', // Use linear scale for the main y-axis
position: 'left',
beginAtZero: true // You can adjust other scale options here
},y1: {
type: 'linear', // Use linear scale for the second y-axis
position: 'right',
beginAtZero: true // You can adjust other scale options here
}
}
}
});
var addDataButton = document.getElementById('addDataButton');
console.log("button is On");
addDataButton.addEventListener('click', function() {
var lastClickTimestamp = localStorage.getItem('lastClickTimestamp');
var currentTime = new Date().getTime();
var oneDayInMilliseconds = 0; // One day in milliseconds
// Check if a day has passed since the last click
if (1) {
// Update the chart data and store it in localStorage
chartData.datasets[0].data.push(<?php echo $cookieData['calories']; ?>);
chartData.datasets[1].data.push(<?php echo $cookieData['carbohydrates']; ?>);
chartData.datasets[2].data.push(<?php echo $cookieData['fat']; ?>);
chartData.datasets[3].data.push(<?php echo $cookieData['protein']; ?>);
// Store the updated data in localStorage
storeData("calories", chartData.datasets[0].data);
storeData("carbohydrates", chartData.datasets[1].data);
storeData("fat", chartData.datasets[2].data);
storeData("protein", chartData.datasets[3].data);
// Store the current timestamp as the last click timestamp
localStorage.setItem('lastClickTimestamp', currentTime);
myLineChart.update();
} else {
console.log("You can only add data once per day.");
}
});
function storeData(key, data) {
localStorage.setItem(key, JSON.stringify(data));
}
function getStoredData(key) {
var storedData = localStorage.getItem(key);
return storedData ? JSON.parse(storedData) : null;
}
</script>
</section>
</body>
<script>
// Get references to the profile picture element and the file input element
const profileImg = document.getElementById('profileImg');
const profileInput = document.getElementById('profileInput');
// Trigger the click event of the file input when the profile picture is clicked
profileImg.addEventListener('click', () => {
profileInput.click();
});
// Update the profile picture preview when a new image is selected
profileInput.addEventListener('change', () => {
const file = profileInput.files[0];
if (file) {
const reader = new FileReader();
reader.onload = () => {
profileImg.src = reader.result;
};
reader.readAsDataURL(file);
}
});
</script>
<script>
function updateHealthBar(calories, totalCalories) {
const healthBar = document.getElementById('healthBar');
if (healthBar) {
const percentage = (calories / totalCalories) * 100;
// Limit the health bar width to the totalCalories percentage
const limitedPercentage = Math.min(percentage, 100);
healthBar.style.width = limitedPercentage + '%';
} else {
console.error('healthBar element not found.');
}
}
// Function to open the activity level popup
function openActivityLevelPopup() {
const popup = document.getElementById('activityLevelPopup');
popup.style.display = 'block';
}
// Function to close the activity level popup
function closeActivityLevelPopup() {
const popup = document.getElementById('activityLevelPopup');
popup.style.display = 'none';
}
// Function to apply the selected activity level and update the calorie goal
function applyActivityLevel() {
// Get the selected activity level value
const activityLevelRadios = document.getElementsByName('activity_level');
let selectedActivityLevel;
for (const radio of activityLevelRadios) {
if (radio.checked) {
selectedActivityLevel = parseFloat(radio.value);
break;
}
}
// Calculate the total daily calorie goal based on the selected activity level
const totalCalories = BMR * selectedActivityLevel;
// Display the result
const resultElement = document.getElementById('result');
resultElement.textContent = `${totalCalories.toFixed(2)} calories`;
updateHealthBar(<?php echo $cookieData['calories']?>, totalCalories); // The first argument is just a placeholder for calories
// Close the popup after applying the selected activity level
closeActivityLevelPopup();
}
</script>
<script>
// Function to open the popup
function openPopup() {
const popup = document.getElementById('updatePopup');
popup.style.display = 'block';
}
// Function to close the popup
function closePopup() {
const popup = document.getElementById('updatePopup');
popup.style.display = 'none';
}
// Add event listener for weight button click
document.getElementById('weightBtn').addEventListener('click', () => {
openPopup();
});
// Add event listener for height button click
document.getElementById('heightBtn').addEventListener('click', () => {
openPopup();
});
</script>
<script>
var BMR = 0;
//Daily Calorie goal
if(Gender == 'Male'){
//BMR for Males
BMR = 88.362 + (13.397 * Weight) + (4.799 * Height) - (5.677 * Age);
}else{
//BMR For Females
BMR = 447.362 + (9.247 * Weight) + (3.098 * Height) - (4.330 * Age);
}
console.log("BMR = " + BMR.toFixed(2));
</script>
</html>