-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.php
261 lines (177 loc) · 6.75 KB
/
scan.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
<?
session_start();
include('functions.php');
//session_register('beginMeal');
//check if the last 'new meal' time has been retrieved.
connectDB();
if(isset($_COOKIE['chocolateChip'])){
if($_COOKIE['chocolateChip'] == 'no meal'){
header("Location:mealAdmin.php?e=1");
} elseif(strtotime($_COOKIE['chocolateChip']) <= time()-(60*60*5)){
header("Location:mealAdmin.php?e=3");
}
} else {
$query = "SELECT mealTime, mealId from meal order by mealId desc limit 1;";
$results = mysql_query($query);
while($dummy = mysql_fetch_row($results)){
if(!empty($dummy)){
$begin = $dummy;
}
}
$mealtime = $begin[0];
$mealId = $begin[1];
if(empty($mealtime)){
$mealtime = 'no meal';
}
setcookie('chocolateChip',$mealtime,time()+1800);
setcookie('mealId',$mealId, time()+1800);
//echo 'the cookie got set<BR><BR>';
}
//check if id has been submitted
$mealId = $_COOKIE['mealId'];
if(!empty($_POST['comp']))
$comp = $_POST['comp'];
else
$comp = false;
if(!empty($_POST['barcode'])){
$studentId = $_POST['barcode'];
if($studentId > 100000){
$query = "SELECT studentmeals.tranId FROM studentmeals
JOIN students ON (students.studentId = studentmeals.studentId)
WHERE students.studentId = '$studentId' and studentmeals.mealId = '$mealId'";
$hadMeal = runShortQuery($query);
$sql = "SELECT mealplan, lastname, firstname from students where studentId = '$studentId' limit 1";
$results = mysql_query($sql);
while($dummy = mysql_fetch_assoc($results)){
if(!empty($dummy)){
$mealPlan = $dummy;
}
}
//Read the pictures directory since php is itself case insensitive.
$dir = opendir("../studentpics");
$pic = '';
while($file = readdir($dir)){
//check for the student id in the file name, and then just use that instead.
$found = strpos($file, $studentId);
if($found !== false){
//set up the picture and exit.
$pic = "../studentpics/".$file;
break;
}
}
//close the directory to make things happy.
closedir($dir);
//If we didnt' find the picture file, show the no pic image.
if($pic == ''){
$pic = "../studentpics/noImageAvailable.jpg";
}
if(!empty($hadMeal)){
$alert = "The student number ".$studentId." has already had this meal.<br><br><img src='../studentpics/".$pic."' height='350px' width='350px' >";
} elseif(empty($mealPlan['mealplan'])) {
$alert = "Student needs to pay. NO MEAL PLAN.<br><br><img src='../studentpics/".$pic."' height='350px' width='350px' >";
}else{
$mealId = $_COOKIE['mealId'];
$query = "INSERT INTO studentmeals(mealId, studentId) VALUES ('$mealId', '$studentId')";
mysql_query($query);
if(mysql_error()){
$alert = 'Contact the tech department at x1250'."\n\r".mysql_error();
} else {
$alert = "Have a nice meal. Student ID has been logged."."<BR><BR>"."<font size='+3'>".ucfirst($mealPlan['firstname'])." ".ucfirst($mealPlan['lastname'])."</font> <br><br><img src='../studentpics/".$pic."' height='350px' width='350px' >";
}
}
}else {
$sql = "SELECT sm.tranId FROM studentmeals as sm
JOIN faculty as f ON (f.facultyId = sm.studentId)
WHERE f.facultyId = '$studentId' and sm.mealId = '$mealId'";
connectDB();
$hadMeal = runShortQuery($sql);
//echo ' asdfa '. $hadMeal;
//TODO: Do I need to add error checking for the same person eating the same meal twice or is that allowed?
$remainQuery = "SELECT meals, fname, lname FROM faculty where facultyId = '$studentId'";
$res = mysql_query($remainQuery);
echo mysql_error();
$remaining = mysql_fetch_assoc($res);
if($comp == false){
if($remaining['meals'] == 0){
$alert = "Faculty must pay: NO MEALS remaining.";
}
else {
$left = $remaining['meals'] - 1;
$update = "UPDATE faculty SET meals = '$left' WHERE facultyId = '$studentId'";
mysql_query($update);
if(mysql_error()){
$alert = 'Contact the tech department at x1250'."\n\r".mysql_error();
}
$mealId = $_COOKIE['mealId'];
$query = "INSERT INTO studentmeals(mealId, studentId) VALUES ('$mealId', '$studentId')";
mysql_query($query);
if(mysql_error()){
$alert = 'Contact the tech department at x1250'."\n\r".mysql_error();
}else{
if($left < 5){
if ($left==0)$left="NO MEALS";
$alert = "Enjoy your meal. WARNING: $left remain! Add more meals soon."."<BR><BR>"."<font size='+3'>".ucfirst($remaining['fname'])." ".ucfirst($remaining['lname'])."</font><br><br>";
}
else $alert = "Enjoy your meal. Faculty meal has been logged."."<BR><BR>"."<font size='+3'>".ucfirst($remaining['fname'])." ".ucfirst($remaining['lname'])."</font><br><br>Left: $left";
}
}
}else{
$mealId = $_COOKIE['mealId'];
$query = "INSERT INTO studentmeals(mealId, studentId) VALUES ('$mealId', '$studentId')";
mysql_query($query);
if(mysql_error()){
$alert = 'Contact the tech department at x1250'."\n\r".mysql_error();
}else{
$alert = "Enjoy your meal. Faculty meal has been logged."."<BR><BR>"."<font size='+3'>".ucfirst($remaining['fname'])." ".ucfirst($remaining['lname'])."</font><br><br>Left: $remaining[meals]";
}
}
}
}else if($comp != false){
$insert = "insert into studentmeals(mealId, studentId) values ('$mealId', 0000)";
mysql_query($insert);
echo mysql_error();
}
?>
<head>
<script type="text/javascript">
<!--
function focusing(){
document.getElementById('barcode').focus();
}
function redirect(){
window.location = 'mealAdmin.php?e=2'
}
function markComp(){
//var x = confirm("Are you sure you want to make this meal complimentary?")
//alert(x)
//if(x == true){
document.getElementById('comp').value = 1;
// document.getElementById('scanForm').submit();
//}
//return false;
}
function submitting(){
if(document.getElementById('comp').checked == true){
var x = confirm("Are you sure you want to make this meal coplimentary?")
if(x == false){
document.getElementById('comp').value = 0;
return false
}else{
return true
}
}
}
document.getElementById("comp").value = 0;
//-->
</script>
<title>Get -a- Meal</title>
</head>
<body onLoad="javascript:focusing();setTimeout('redirect()',(1000*60*30));">
<form id="scanForm" action="scan.php" method="post" onSubmit="return submitting();">
<BR><BR><BR>
<center><b>Scan ID:</b><BR><input type="text" id="barcode" name="barcode"></center>
<center><input type="checkbox" value="1" name="comp" id="comp"> Complimentary</center>
</form>
<br>
<center><b><font color="red"><?=$alert?></font></b></center>
</body>