-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliblenderstat.php
executable file
·267 lines (215 loc) · 14.8 KB
/
liblenderstat.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
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$("#datepicker").datepicker();
$("#datepicker2").datepicker();
});
</script>
<?php
// liblenderstat.php####
require '/var/www/seal_script/seal_function.php';
// Connect to database
require '/var/www/seal_script/seal_db.inc';
$db = mysqli_connect($dbhost, $dbuser, $dbpass);
mysqli_select_db($db, $dbname);
if (($_SERVER['REQUEST_METHOD'] == 'POST') || ( isset($_GET{'page'})) ) {
$startdate = date('Y-m-d', strtotime('-7 days'));
$enddated = $_REQUEST["enddate"];
$startdated = $_REQUEST["startdate"];
$libname = $_REQUEST["libname"];
$loc = $field_loc_location_code;
$libname=$_REQUEST["libname"];
if (strlen($libname) >0) {
$loc = $libname;
}
$reg = '~(0[1-9]|1[012])[-/](0[1-9]|[12][0-9]|3[01])[-/](19|20)\d\d~';
//checking if date is in the correct format
if((!preg_match($reg, $startdated))||(!preg_match($reg, $enddated))) {
echo "<h1 style=color:red;>Date is not in the correct format of mm/dd/yyyy </h1>";
}else{
$loc = mysqli_real_escape_string($db, $loc);
$startdate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $startdated)));
$enddate = date('Y-m-d H:i:s', strtotime(str_replace('-', '/', $enddated)));
// Get total requests received
$GETREQUESTCOUNTSQLL= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' ";
$retval = mysqli_query($db, $GETREQUESTCOUNTSQLL);
if (!$retval) {
// There was an error in the query
die('Error: ' . mysqli_error($db));
} else {
if (mysqli_num_rows($retval) == 0) {
// No results were found, display an error message
echo "No results found.";
} else {
$row_cnt = mysqli_num_rows($retval);
// Get total filled requests
$FINDFILL= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' and Fill =1 ";
$retfilled = mysqli_query($db, $FINDFILL);
$row_fill = mysqli_num_rows($retfilled);
// Get percentage fill
$percentfill = $row_fill/$row_cnt;
$percent_friendly_fill = number_format($percentfill * 100, 2) . '%';
// Get total not filled requests
$FINDNOTFILL= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' and Fill =0 ";
$retnotfilled = mysqli_query($db, $FINDNOTFILL);
$row_notfill = mysqli_num_rows($retnotfilled);
// Get percentage fill
$percentnotfill = $row_notfill/$row_cnt;
$percent_friendly_notfill = number_format($percentnotfill * 100, 2) . '%';
// Get total requests expired
$FINDEXPIRE= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' and Fill =4 ";
$retexpire = mysqli_query($db, $FINDEXPIRE);
$row_expire = mysqli_num_rows($retexpire);
// Get percentage fill
$percentexpire = $row_expire/$row_cnt;
$percent_friendly_expire = number_format($percentexpire * 100, 2) . '%';
// Get total requests not answered
$FINDNOANSW= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' and Fill =3 ";
$retnoansw = mysqli_query($db, $FINDNOANSW);
$row_noansw = mysqli_num_rows($retnoansw);
// Get percentage fill
$percentnoansw = $row_noansw/$row_cnt;
$percent_friendly_noansw = number_format($percentnoansw * 100, 2) . '%';
// Get total requests canceled
$CANANSW= "SELECT * FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' and Fill =6 ";
$canansw = mysqli_query($db, $CANANSW);
$row_cancel = mysqli_num_rows($canansw);
// Get percentage fill
$percentcancel = $row_cancel/$row_cnt;
$percent_friendly_cancel = number_format($percentcancel * 100, 2) . '%';
// Get the library name
$libnames= "SELECT Name FROM `$sealLIB` WHERE `LOC` LIKE '$loc' ";
$libnameq = mysqli_query($db, $libnames);
while($row = $libnameq->fetch_assoc()) {
$libname = $row["Name"];
}
// Stats overall in the time frame chosen
echo "<h3>From $startdated to $enddated </3>";
echo "<h4>Lender request statistics for ".$libname." </h4>";
echo "Total Requests received ".$row_cnt." <br>";
echo "Number of Requests Filled: ".$row_fill." (".$percent_friendly_fill.")<br>";
echo "Number of Requests Not Filled: ".$row_notfill." (".$percent_friendly_notfill.")<br>";
echo "Number of Requests Expired: ".$row_expire." (".$percent_friendly_expire.")<br>";
echo "Number of Requests Canceled: ".$row_cancel." (".$percent_friendly_cancel.")<br>";
echo "Number of Requests Not Answered Yet: ".$row_noansw." (".$percent_friendly_noansw.")<br><br>";
echo "<hr><h3>Break down of requests</h3>";
// Find which systems they sent request to
$reqsystem=" SELECT distinct (`ReqSystem` ) FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' ";
//debug
// echo "the sql".$reqsystem."<br>";
$reqsystemq = mysqli_query($db, $reqsystem);
// loop through the results of destination systems
while ($row = mysqli_fetch_assoc($reqsystemq)) {
$reqsysvar= $row['ReqSystem'];
$reqsystemcount=" SELECT `itype` FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' ";
$reqsystemcountq = mysqli_query($db, $reqsystemcount);
// Count the number of requests to that system
$reqnum_rows = mysqli_num_rows($reqsystemcountq);
// Get percentage
$percentreqnum_rows = $reqnum_rows/$row_cnt;
$percent_friendly_reqnum = number_format($percentreqnum_rows * 100, 2) . '%';
// translate system code to text name
if (strcmp($reqsysvar, 'MH')==0) {
$reqsysvartxt = "Mid Hudson Library System";
}else if (strcmp($reqsysvar, 'RC')==0) {
$reqsysvartxt = "Ramapo Catskill Library System";
}else if (strcmp($reqsysvar, 'DU')==0) {
$reqsysvartxt = "Dutchess BOCES";
}else if (strcmp($reqsysvar, 'OU')==0) {
$reqsysvartxt = "Orange Ulster BOCES";
}else if (strcmp($reqsysvar, 'RB')==0) {
$reqsysvartxt = "Rockland BOCES";
}else if (strcmp($reqsysvar, 'SB')==0) {
$reqsysvartxt = "Sullivan BOCES";
}else if (strcmp($reqsysvar, 'UB')==0) {
$reqsysvartxt = "Ulster BOCES";
}else{
$reqsysvartxt = "SENYLRC Group";
}
echo " ".$reqnum_rows." (".$percent_friendly_reqnum.") overall requests were made from <strong> ".$reqsysvartxt."</strong><br>";
// Find which item types were requests
$reqtitype=" SELECT distinct (`itype` ) FROM `$sealSTAT` WHERE `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00' ";
$reqtitypeq = mysqli_query($db, $reqtitype);
// loop through the results of items from that destination
while ($row2 = mysqli_fetch_assoc($reqtitypeq)) {
$reqsysitype= $row2['itype'];
// Remove any white space
$reqitemcount=" SELECT `fill` FROM `$sealSTAT` WHERE `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqitemcountq = mysqli_query($db, $reqitemcount);
// Count the number of requests to that system
$reqnumitype_rows = mysqli_num_rows($reqitemcountq);
// Get percentage
$percenttypesys_rows = $reqnumitype_rows/$reqnum_rows;
$percent_friendly_typesys = number_format($percenttypesys_rows * 100, 2) . '%';
echo "   ".$reqnumitype_rows." (".$percent_friendly_typesys.") of the requests from ".$reqsysvartxt." were <strong>".$reqsysitype."</strong><br>";
// Find what the fill rate is
$reqtitemcountfill=" SELECT `fill` FROM `$sealSTAT` WHERE Fill='1' and `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqtitemcountfillq = mysqli_query($db, $reqtitemcountfill);
// Count the number of fills
$reqnumfilled_rows = mysqli_num_rows($reqtitemcountfillq);
// Get percentage
$percent1_rows =$reqnumfilled_rows/ $reqnumitype_rows;
$percent_friendly_1 = number_format($percent1_rows * 100, 2) . '%';
echo "       $reqnumfilled_rows (".$percent_friendly_1.") were filled<br>";
// Find what the unfill rate is
$reqitemcountunfill=" SELECT `fill` FROM `$sealSTAT` WHERE Fill='0' and `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqitemcountunfillq = mysqli_query($db, $reqitemcountunfill);
// Count the number of unfilled
$reqnumunfilled_rows = mysqli_num_rows($reqitemcountunfillq);
// Get percentage
$percent2_rows =$reqnumunfilled_rows/ $reqnumitype_rows;
$percent_friendly_2 = number_format($percent2_rows * 100, 2) . '%';
echo "      $reqnumunfilled_rows (". $percent_friendly_2.") were not filled<br>";
// Find what the expire rate is
$reqitemcountexfill=" SELECT `fill` FROM `$sealSTAT` WHERE Fill='4' and `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqitemcountexfillq = mysqli_query($db, $reqitemcountexfill);
// Count the number of expired requests
$reqnumexfilled_rows = mysqli_num_rows($reqitemcountexfillq);
// Get percentage
$percent3_rows =$reqnumexfilled_rows/ $reqnumitype_rows;
$percent_friendly_3 = number_format($percent3_rows * 100, 2) . '%';
echo "      $reqnumexfilled_rows (". $percent_friendly_3.") were expired<br>";
// Find what the cancel rate is
$reqitemcountcanfill=" SELECT `fill` FROM `$sealSTAT` WHERE Fill='6' and `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqitemcountcanfillq = mysqli_query($db, $reqitemcountcanfill);
// Count the number of canceled requests
$reqnumcanfilled_rows = mysqli_num_rows($reqitemcountcanfillq);
// Get percentage
$percent4_rows =$reqnumcanfilled_rows/ $reqnumitype_rows ;
$percent_friendly_4 = number_format($percent4_rows * 100, 2) . '%';
echo "      $reqnumcanfilled_rows (". $percent_friendly_4.") were canceled<br>";
// Find the numbered not answer yet
$reqitemcountnoanswfill=" SELECT `fill` FROM `$sealSTAT` WHERE Fill='3' and `Itype`='$reqsysitype' and `Destination` LIKE '$loc' and `ReqSystem`='$reqsysvar' and `Timestamp` >= '$startdate 00:00:00' and `Timestamp` <= '$enddate 00:00:00'";
$reqitemcountnoanswfillq = mysqli_query($db, $reqitemcountnoanswfill);
// Count the number of requests not answered yet
$reqnumnoanswfilled_rows = mysqli_num_rows($reqitemcountnoanswfillq);
// Get percentage
$percent5_rows =$reqnumnoanswfilled_rows/ $reqnumitype_rows ;
$percent_friendly_5 = number_format($percent5_rows * 100, 2) . '%';
echo "      $reqnumnoanswfilled_rows (". $percent_friendly_5.") of requests not answered<br>";
echo "<br>";
}
echo "<br><hr><br>";
}
} //end check for 0 results
}// end if (!$retval)
}//end date format check
}else{
if (isset($_GET['loc'])) { $loc = $_GET['loc'];
}else{$loc='null';
}
?>
<h2>Enter your desired date range:</h2>
<form action="/liblenderstat?<?php echo $_SERVER['QUERY_STRING'];?>" method="post">
Start Date:
<input id="datepicker" name="startdate"/>
End Date:
<input id="datepicker2" name="enddate"/>
<br><br>
<input type="submit" value="Submit">
</form>
<?php
}
?>