/
checknotifications.php
199 lines (154 loc) · 7.06 KB
/
checknotifications.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
<?php
// check and build notifications for the index page
$stockNotiLimit = 7; // amount of days required for a stock warning to show
$deadNotiLimit = 3; // amount of days required for a deadline warning to show
$handNotiLimit = 12; // amount of hours required for a handover to show
$foodNotiLimit = 4; // number of days since a food safety check for noti
$notifications = array(); // to hold the alert
$notiLevel = array(); // this will set the class of the alert
include 'connection.php';
// Check if on duty, if so show what should be done this hour
if(isDutyNow($_SESSION['userData']['employee'])){
array_push($notifications , '<a href="floormanager.php">You\'re Duty!</a>');
array_push($notiLevel, 'success');
$dutyquery = "SELECT
task
FROM floormanagertasks
WHERE (starthour <= ".currentHour()."
AND endhour > ".currentHour().")";
$dutyresult = mysqli_query($link, $dutyquery);
if (!$dutyresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
while($dutyrow = mysqli_fetch_array($dutyresult)){
array_push($notifications , '<a href="floormanager.php">Floor Manager : '.$dutyrow['task'].'</a>');
array_push($notiLevel, 'success');
}
}
// look for sick calls not recorded on PartnerLink
$rtwquery = "SELECT id FROM `sickness` WHERE (`manager`='".$_SESSION['userData']['employee']."' AND `actioned`='0') LIMIT 1";
$rtwresult = mysqli_query($link, $rtwquery);
if (!$rtwresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
if(mysqli_num_rows($rtwresult) > 0){
array_push($notifications , '<a href="viewsickcalls.php">Record all sick calls in PartnerLink.</a>');
array_push($notiLevel, 'warning');
}
// show a handover if there's been one in the last 12 hours and user is TL or above
if($_SESSION['userData']['canrotationcheck'] == 1) {
$handquery = "SELECT * FROM `handovers` ORDER BY `id` DESC LIMIT 1";
$handresult = mysqli_query($link, $handquery);
if (!$handresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
while($handrow = mysqli_fetch_array($handresult)){
if(strtotime($handrow['time']) > strtotime('-'.$handNotiLimit.' HOURS') ){
array_push($notifications , '<a href="viewhandovers.php">Recent Handover by : '.checkPartnerFirstName($handrow['employee']).'</a>');
array_push($notiLevel, 'info');
}
}
}
// check stock watch for any notifications
$stockquery = "SELECT * FROM `stockwatch` ORDER BY `date` ASC LIMIT 5";
$stockresult = mysqli_query($link, $stockquery);
if (!$stockresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
while($stockrow = mysqli_fetch_array($stockresult)){
// check if it's within $stockNotiLimit days
if( strtotime($stockrow['date']) < strtotime('TODAY +'.$stockNotiLimit.' DAYS') ){
array_push($notifications , '<a href="viewstockwatch.php">Stock Watch [Expiring Soon] : '.$stockrow['product'].' - '.showDate($stockrow['date']).'</a>');
$level = 'warning';
// turn it red if it's really close
if( strtotime($stockrow['date']) < strtotime('TODAY +'.($stockNotiLimit/2).' DAYS') ){
$level = 'danger';
}
array_push($notiLevel, $level);
}
}
// check deadlines for any notifications, only if user is a manager
if($_SESSION['userData']['level'] < 10){
$deadquery = "SELECT * FROM `deadlines` ORDER BY `date` ASC LIMIT 5";
$deadresult = mysqli_query($link, $deadquery);
if (!$deadresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
while($deadrow = mysqli_fetch_array($deadresult)){
// check if it's within $stockNotiLimit days
if( strtotime($deadrow['date']) < strtotime('TODAY +'.$deadNotiLimit.' DAYS') ){
array_push($notifications , '<a href="viewdeadlines.php">Deadline : '.$deadrow['task'].' - '.showDate($deadrow['date']).'</a>');
$level = 'warning';
// turn it red if it's really close
if( strtotime($deadrow['date']) < strtotime('TODAY +'.($deadNotiLimit/2).' DAYS') ){
$level = 'danger';
}
array_push($notiLevel, $level);
}
}
}
// check bridge cover to see if this user is doing any
$bridgeQuery = "SELECT * FROM `bridge` WHERE `manager`='".$_SESSION['userData']['employee']."'";
$bridgeResult = mysqli_query($link, $bridgeQuery);
if (!$bridgeResult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
$bridgeCover = '';
while($bridgeRow = mysqli_fetch_array($bridgeResult)){
$time = $slots[$bridgeRow['slot']].', ';
if(substr($bridgeCover, -7, 5) == substr($time,0,5)){
// this means the end of the last slot is the same as the start of the next slot
$bridgeCover = substr($bridgeCover, 0, -7);
$time = substr($time, 8);
}
if(((substr($time, -7, 2) + 0.25) < (currentHour() + (currentMinute()/60))) && (substr($time, -5, 3) != 'End')){
// this means the current time is past the end of the slot we're checking, so don't add it.
// also a check the final time is not 'End' otherwise the last slot will never show up
$time = '';
}
$bridgeCover .= $time;
}
if(strlen($bridgeCover) > 0){
array_push($notifications , '<a href="bridgecover.php">You Have Bridge Cover : '.substr($bridgeCover, 0, -2).'</a>');
$level = 'info';
array_push($notiLevel, $level);
}
// check how long ago Food Safety checks where done
$foodquery = "SELECT `time` FROM `foodsafetychecks` ORDER BY `time` DESC LIMIT 1";
$foodresult = mysqli_query($link, $foodquery);
if (!$foodresult) {
printf("Error: %s\n", mysqli_error($link));
exit();
}
$rowCount = $foodresult->num_rows;
if($rowCount > 0){
$foodrow = mysqli_fetch_array($foodresult);
debug_to_console('foodrow: '.strtotime($foodrow['time']));
debug_to_console('Checking against: '.strtotime('TODAY -'.$foodNotiLimit.' DAYS'));
// check how long ago it was
$now = time(); // or your date as well
$your_date = strtotime($foodrow['time']);
$datediff = (round(($now - $your_date) / (60 * 60 * 24)));
debug_to_console($datediff);
// check if it's within $stockNotiLimit days
if( strtotime($foodrow['time']) < strtotime('TODAY -'.$foodNotiLimit.' DAYS') ){
array_push($notifications , '<a href="recordfoodsafetychecks.php">Food safety checks need doing, not done since : '.$deadrow['task'].' - '.showDate($foodrow['time']).'</a>');
$level = 'warning';
if($datediff > ($foodNotiLimit*2)){
$level = 'danger';
}
array_push($notiLevel, $level);
}
} else {
// no checks have been found
array_push($notifications , '<a href="viewfoodsafetychecks.php">No Food safety checks have been done.</a>');
$level = 'danger';
array_push($notiLevel, $level);
}
?>