-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_TDEE.php
87 lines (75 loc) · 2.18 KB
/
display_TDEE.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
<?php
session_start();
if(isset($_POST['weight']) ){
$weight = $_POST['weight'];
$height = $_POST['height'];
$age = $_POST['age'];
$activityLevel = doubleval($_POST['activityLevel'] );
$REE = 66 + (6.2 * $weight) + (12.7 * $height) - (6.76 * $age);
$TDEE = $REE * $activityLevel;
$gain_TDEE = $TDEE + ($TDEE * 0.20);
$lose_TDEE = $TDEE - ($TDEE * 0.20);
echo "Your REE is: $REE <br>
Your TDEE is: $TDEE <br>
Meaning that in order to lose weight you should eat: $gain_TDEE <br>
Meaning that in order to gain weight you should eat: $lose_TDEE <br>";
$protein = $weight * 0.825;
$fat = (($TDEE * 0.25) / 9);
$pro_cal = $protein * 4;
$fat_cal = $fat * 9;
$new_cal = $TDEE - $pro_cal - $fat_cal;
$carb = ($new_cal / 4);
$total_cal = ($pro_cal ) + ($fat_cal ) + ($carb);
?>
<table class = 'table table-bordered sortable'>
<tr>
<th>Calories</th>
<th>Fat (grams)</th>
<th>Carbs (grams)</th>
<th>Protein (grams) </th>
</tr>
<tr>
<td><?php echo number_format($TDEE,2) ?></td>
<td><?php echo number_format($fat,2) ?></td>
<td><?php echo number_format($carb,2)?></td>
<td><?php echo number_format($protein,2)?></td>
</tr>
</table>
<?php
if(isset($_SESSION['user'])){ ?>
<div class ='form-group'>
Save these macros
<input type='submit' id = 'SubmitMacros' class = 'page-scroll btn btn-default btn-xl sr-button' value='Save_Macros'>
</div>
<script>
document.getElementById("SubmitMacros").onclick = function() {myFunction_Macros()};
function myFunction_Macros(){
console.log('myfunction');
var cal = <?php json_encode($TDEE) ?>;
var fat = <?php json_encode($fat) ?>;
var carb = <?php json_encode($carb) ?>;
var prot = <?php json_encode($protein) ?>;
$.ajax({
url: "saveMacrostoDB.php",
type: "POST",
data: { 'cal':cal,
'fat':fat,
'carb':carb,
'prot':prot
}
}).done(function( msg ) {
alert(msg);
});
}
</script>
<?php } //if isset
else {
echo "user not logged in rn";
}
?>
<?php
}
else {
echo "WEight is not set";
}
?>