This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.php
157 lines (154 loc) · 6.38 KB
/
home.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
<?php require 'common.php'; ?>
<?php
if(empty($_SESSION['user'])) {
header("Location: login.php");
die("Redirecting to login.php");
}
?>
<!DOCTYPE html>
<html>
<?php include_once 'header.html' ?>
<body>
<?php include_once 'navbar.php' ?>
<div class="main main-raised" style="padding-top:100px;">
<div class="container">
<div class="card">
<div class="content">
<h1>Hey <b><?php echo $_SESSION['user']['name']?></b> <small>It's <b><span id="date"></span>.</b></small></h1>
</div>
</div>
<?php
include_once "fetchpaneldata.php";
include_once "fetchtagdata.php";
$panel_data = fetchPanelData(false, null);
$tag_data = fetchTagData(false, null);
?>
<div class="card">
<div class="content">
<div class="row">
<div class="col-sm-4">
<img class="img-responsive" src="img/control-panel.png">
</div>
<div class="col-sm-8">
<?php
if (count($panel_data) > 0){
if ($panel_data[0]["name"]){
echo "<h1>".$panel_data[0]["name"]."</h1>";
}
else{
echo "<h1>Control Panel <b>#".$panel_data[0]["uid"]."</b></h1>";
}
$tags_active = 0;
$tags_spoiling = 0;
$spoiling_tags = [];
for ($j = 0; $j < count($tag_data); $j++){
if ($tag_data[$j]["controluid"] == $panel_data[0]["uid"]){
$tags_active += 1;
if ($tag_data[$j]["expiry_date"] - time() <= 259200 && $tag_data[$j]["expiry_date"] - time() > 0){
$tags_spoiling += 1;
array_push($spoiling_tags, $tag_data[$j]);
}
}
}
echo "<h3><b>".$tags_active."</b> Active Tags</h3>";
echo "<h3 class=\"text-warning\"><b>".$tags_spoiling."</b> Tags Spoiling Soon</h3>";
}
else{
echo "<h1>You don't have any registered panels.</h1>";
echo "<h2>Register your panels <a href=\"#\">here.</a></h2>";
}
?>
</div>
</div>
<div class="text-center">
<h3><a href="panels.php">View Control Panels</a></h3>
</div>
</div>
</div>
<div class="card">
<div class="content">
<h2>Spoiling Soon</h2>
<?php
if (count($spoiling_tags) > 0){
for ($i = 0; $i < count($spoiling_tags); $i++){
if (($i+1) % 3 == 0){
echo "<div class=\"row\">";
}
echo "<div class=\"col-sm-4\">
<div class=\"card card-product\">
<div class=\"content\">
<a data-toggle=\"collapse\" href=\"#tag-detail-" . ($i+1) . "\" aria-expanded=\"false\" aria-controls=\"tag-detail-" . ($i+1) . "\">";
echo "<img class=\"img-responsive\" src=\"img/tags/" . $spoiling_tags[$i]['pattern'] . ".png\" alt=\"Tag Image\" style=\"max-width:50%;margin-left: auto;margin-right: auto;\"/>";
echo "</a>";
echo "<div class=\"text-center\">";
echo "<h2>" . $spoiling_tags[$i]['name'] . "</h2>";
//calculate state based upon expiry date
if ($spoiling_tags[$i]['expiry_date'] > 0){ //if expiry date entered
$compare_date = $spoiling_tags[$i]['expiry_date'];
} else { //if expiry date not entered
//TODO get food lifespan from database, add number to check-in date to get compare date
}
if (time() > $compare_date){
$text_color = "danger";
$text = "Spoiled";
} else if (($compare_date - time()) < 259200){
$text_color = "warning";
$text = "Spoiling Soon";
} else {
$text_color = "success";
$text = "Fresh";
}
echo "<h3 class=\"text-" . $text_color . "\">" . $text . "</h3>";
echo "<a data-toggle=\"collapse\" href=\"#tag-detail-" . ($i+1) . "\" aria-expanded=\"false\" aria-controls=\"tag-detail-" . ($i+1) . "\">
More Information <i class=\"material-icons\">keyboard_arrow_down</i>
</a>
<div class=\"collapse\" id=\"tag-detail-" . ($i+1) . "\">";
// Day Calculation Code Block
$days = ceil(($compare_date - time())/86400);
if ($days >= 0){
echo "<h3>Spoiling in: <br> <b>" . $days . " Day" . ($days > 1 ? "s":"") . "</b></h3>";
}
else{
echo "<h3 class=\"text-danger\">Spoiled for ". $days * -1 . " Day" . ($days < -1 ? "s":"") . "</h3>";
}
echo "<h4>" . $spoiling_tags[$i]['category'] . "</h4>";
if (!$spoiling_tags[$i]['fridge_freezer']){
$text_color = "info";
$text = "Refrigerated";
} else {
$text_color = "primary";
$text = "Frozen";
}
echo "<h4 class=\"text-" . $text_color . "\">" . $text . "</h4>";
echo "<p>" . $spoiling_tags[$i]['description'] . "</p>";
echo "</div>
</div>
</div>
</div>
</div>";
if (($i+1) % 3 == 0){
echo "</div>";
}
}
}
else{
echo "<h1>No tags spoiling. Fresh!</h1>";
}
?>
<div class="text-center">
<h3><a href="tags.php">View More Tags</a></h3>
</div>
</div>
</div>
</div>
</div>
<?php include_once 'footer.html' ?>
<script src="js/moment.js"></script>
<script>
$("#date").html(moment().format('MMMM Do, h:mm a'));
window.setInterval(function(){
$("#date").html(moment().format('MMMM Do, h:mm a'));
}, 1000);
</script>
</body>
</html>