-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrespond.php
executable file
·266 lines (233 loc) · 11.6 KB
/
respond.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
<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();
});
</script>
<?php
$illsystemhost = $_SERVER["SERVER_NAME"];
// Get values
$reqnumb=$_REQUEST["num"];
if (isset($_REQUEST['a'])) { $reqanswer = $_REQUEST['a'];
}else{ $reqanswer='';
}
// Connect to database
require '/var/www/seal_script/seal_db.inc';
$db = mysqli_connect($dbhost, $dbuser, $dbpass);
mysqli_select_db($db, $dbname);
// Escape values for security
$reqnumb = mysqli_real_escape_string($db, $reqnumb);
$reqanswer = mysqli_real_escape_string($db, $reqanswer);
// Process any notes from the lender#############################
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$respnote=$_REQUEST["respondnote"];
$resfill=$_REQUEST["fill"];
$duedate=$_REQUEST["duedate"];
$nofillreason=$_REQUEST["nofillreason"];
$shipmethod=$_REQUEST["shipmethod"];
// Escape values for security
$respnote = mysqli_real_escape_string($db, $respnote);
$resfill = mysqli_real_escape_string($db, $resfill);
$todaydate = date("Y-m-d");
$sqlupdate = "UPDATE `$sealSTAT` SET `emailsent` = '1', `Fill` = '$resfill' , `responderNOTE` = '$respnote',`shipMethod`='$shipmethod',`DueDate`='$duedate',`ReasonNotFilled`='$nofillreason',`fillNofillDate` = '$todaydate' WHERE `illNUB` = '$reqnumb'";
if (mysqli_query($db, $sqlupdate)) {
echo "Thank you. Your response has been recorded to the request.<br><a href='/lender-history'>Click here to view your lender history</a><br>";
// Setup the note data to be in email
$respnote=stripslashes($respnote);
if (strlen($respnote)>0) { $respnote="The lending library has noted the following <br> $respnote";
}
$sqlselect="select responderNOTE,requesterEMAIL,Title,Destination from `$sealSTAT` where illNUB='$reqnumb' LIMIT 1 ";
$result = mysqli_query($db, $sqlselect);
$row = mysqli_fetch_array($result);
$title =$row['Title'];
$requesterEMAIL=$row['requesterEMAIL'];
$destlib=$row['Destination'];
// Get the Destination Name
$GETLISTSQLDEST="SELECT`Name`, `ill_email` FROM `$sealLIB` where loc like '$destlib' limit 1";
$resultdest=mysqli_query($db, $GETLISTSQLDEST);
while ($rowdest = mysqli_fetch_assoc($resultdest)) {
$destlib=$rowdest["Name"];
$destemail=$rowdest["ill_email"];
}
// In case the ILL email for the destination library is more than one, break it down to comma for php mail
$destemailarray = explode(';', $destemail);
$destemail_to = implode(',', $destemailarray);
$headers = "From: Southeastern SEAL <[email protected]>\r\n" ;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
// sending filled email#####
if ($resfill=='1') {
// Setting up email notification
if($shipmethod=="usps") { $shiptxt='US Mail';
}
if($shipmethod=="mhls") { $shiptxt='Mid-Hudson Courier';
}
if($shipmethod=="rcls") { $shiptxt='RCLS Courier';
}
if($shipmethod=="empire") { $shiptxt='Empire Delivery';
}
if($shipmethod=="ups") { $shiptxt='UPS';
}
if($shipmethod=="fedex") { $shiptxt='FedEx';
}
if($shipmethod=="other") { $shiptxt='Other';
}
if($shipmethod=="") { $shiptxt='';
}
$message = "Your ILL request $reqnumb for $title will be filled by $destlib <br>Due Date: $duedate<br><br>Shipped via: $shiptxt<br><br>$respnote ".
"<br><br>Please email <b>".$destemail_to."</b> for future communications regarding this request ";
// Setup php email headers
$to=$requesterEMAIL;
$subject = "ILL Request Filled ILL# $reqnumb ";
// SEND requester an email to let them know the request will be filled
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to zack at SENYLRC for development
//$to="[email protected]";
mail($to, $subject, $message, $headers, "-f [email protected]");
// Sending not filledmessage#########
}else{
// Setting up email notification
if ($nofillreason=='20') {
$reasontxt='In Use';
}
if ($nofillreason=='21') {
$reasontxt='Lost';
}
if ($nofillreason=='22') {
$reasontxt='Non-Circulating';
}
if ($nofillreason=='23') {
$reasontxt='Not on shelf';
}
if ($nofillreason=='24') {
$reasontxt='Poor condition';
}
if ($nofillreason=='25') {
$reasontxt='Too New';
}
$message = "Your ILL request $reqnumb for $title can not be filled by $destlib.<br>".
"Reason request can not be filled: $reasontxt".
"<br><br>$respnote<br><br> <a href='http://".$illsystemhost."'>Would you like to try a different library</a>?";
// Setup php email headers
$to=$requesterEMAIL;
$subject = "ILL Request Not Filled ILL# $reqnumb ";
// SEND requester an email to let them know the request will be filled
$message = preg_replace('/(?<!\r)\n/', "\r\n", $message);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to zack at SENYLRC for development
//$to="[email protected]";
mail($to, $subject, $message, $headers, "-f [email protected]");
}
}else{
echo "Unable to record answer for ILL request $reqnumb please call SENYLRC to report this error";
}
// No notes but answering yes or no to ILL request#########
}else{
// The Request will be filled##############################################
if ($reqanswer=='1') {
echo "Please click the submit button to confirm you will fill the request.<br> Thank You.<br><br>";
echo "<h6>Recommend shipping methods</h6>";
//echo "<b>This is an experimental feature, if unsure please verify correct shipping method</b>";
//try to recommend delivery options
//get the library ID with this transaction
$LibInLISTSQL="SELECT `Requester LOC`, `Destination` FROM `$sealSTAT` WHERE `illNUB` = '$reqnumb'";
//for testing
//echo $LibInLISTSQL;
$LibGETLIST = mysqli_query($db, $LibInLISTSQL);
$GETLISTCOUNT = '1';
$Librow = mysqli_fetch_assoc($LibGETLIST);
$reqlib = $Librow["Requester LOC"];
$destlib = $Librow["Destination"];
$destlib = strtolower($destlib);
//we need to find out the lending options
$getlenderoptions="SELECT lbsyscourier,lbUSPS,lbEmpire,lbCommCourier FROM `$sealLIB` WHERE `loc` ='$destlib'";
// for testing
// echo $getlenderoptions."<br>";
$GETLISTlendOPT = mysqli_query($db, $getlenderoptions);
$GETLISTCOUNT = '1';
$rowlendopt = mysqli_fetch_assoc($GETLISTlendOPT);
$lbsyscourier1 = $rowlendopt["lbsyscourier"];
$lbUSPS1 = $rowlendopt["lbUSPS"];
$lbEmpire1 = $rowlendopt["lbEmpire"];
$lbCommCourier1 = $rowlendopt["lbCommCourier"];
//we need to find out the borrower options
$getborrowptions="SELECT lbsyscourier,lbUSPS,lbEmpire,lbCommCourier FROM `$sealLIB` WHERE `loc` ='$reqlib'";
// for testing
//echo $getborrowptions."<br>";
$GETLISTborrowOPT = mysqli_query($db, $getborrowptions);
$GETLISTCOUNT = '1';
$rowborrowdopt = mysqli_fetch_assoc($GETLISTborrowOPT);
$lbsyscourier2 = $rowborrowdopt["lbsyscourier"];
$lbUSPS2 = $rowborrowdopt["lbUSPS"];
$lbEmpire2 = $rowborrowdopt["lbEmpire"];
$lbCommCourier2 = $rowborrowdopt["lbCommCourier"];
$illdelmes='0';
if (($lbEmpire1 === "Yes") && ($lbEmpire2 === "Yes")) {
echo "<p class='green-text'>OK to ship via Empire Library Delivery</p>";
$illdelmes++;
}
if (($lbsyscourier1 === "Yes") && ($lbsyscourier2=== "Yes")) {
echo "<p class='green-text'>OK to ship via Public Library System Courier</p>";
$illdelmes++;
}
if (($lbUSPS1 === "Yes")&&($lbUSPS2 ==="Yes")) {
echo "<p class='green-text'>OK to ship via US Mail</p>";
$illdelmes++;
}
if (($lbCommCourier1 === "Yes")&&($lbCommCourier2 === "Yes")) {
echo "<p class='green-text'>OK to ship via Commercial Courier like FedEx or UPS</p>";
$illdelmes++;
}
if ($illdelmes<1) {
echo "<p class='red-text'>Contact the borrowing library to discuss an appropriate delivery method. More delivery information can also be found on the <a target='_blank' href='https://libguides.senylrc.org/SEAL/Delivery'>SEAL libguide</a></p>";
}
?>
<br><br><h4>Please note the delivery method, tracking info, special handling, etc</h4>
<form action="/respond" method="post">
<input type='hidden' name='num' value= '<?php echo $reqnumb ?>' '>
<input type='hidden' name='fill' value='1'>
<input type='hidden' name='nofillreason' value='0'>
<textarea name='respondnote' rows="4" cols="50"></textarea><br>
Due Date:
<input id="datepicker" name="duedate"/><br>
Ship Method:
<select name="shipmethod">
<option value=""></option>
<option value="usps">US Mail</option>
<option value="mhls">Mid-Hudson Courier</option>
<option value="rcls">RCLS Courier</option>
<option value="empire">Empire Delivery</option>
<option value="ups">UPS</option>
<option value="fedex">FedEx</option>
<option value="other">Other</option></select><br>
<input type="submit" value="Submit">
</form>
<?php
// The request will not be filled###########################
}else{
echo "Please click the submit button to confirm you can not fill the request";
?>
<br><br><h4>Would you like to add a note about the decline?<br> </h4>
<form action="/respond" method="post">
<input type='hidden' name='num' value= '<?php echo $reqnumb ?>' '>
<input type='hidden' name='fill' value='0'>
<select name="nofillreason">
<option value="0">Reason</option>
<option value="20">In Use</option>
<option value="21">Lost</option>
<option value="22">Non-Circulating Format</option>
<option value="23">Not on shelf</option>
<option value="24">Poor condition</option>
<option value="25">Too New</option>
</select><br><br>
<textarea name='respondnote' rows="4" cols="50"></textarea><br>
<input type="submit" value="Submit">
</form>
<?php
}// End if statement of yes or no#####
}// End if statement if we are updating the note box####
mysqli_close($db);
?>