-
Notifications
You must be signed in to change notification settings - Fork 0
/
renew.php
executable file
·253 lines (240 loc) · 14 KB
/
renew.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
<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
// renew.php###
require '/var/www/seal_script/seal_function.php';
$reqnumb = $_REQUEST["num"];
$renewNote = $_REQUEST["renewNote"];
$duedate = $_REQUEST["duedate"];
$renewNoteLender = $_REQUEST["renewNoteLender"];
if (isset($_REQUEST['a'])) {
$renanswer = $_REQUEST['a'];
} elseif (isset($_POST['a'])) {
$renanswer = $_POST['a'];
} else {
$renanswer = '';
}
$timestamp = date("Y-m-d H:i:s");
$todaydate = date("Y-m-d");
// 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);
$renewNote = mysqli_real_escape_string($db, $renewNote);
$renewNoteLender = mysqli_real_escape_string($db, $renewNoteLender);
$renanswer = mysqli_real_escape_string($db, $renanswer);
$wholename = mysqli_real_escape_string($db, $wholename);
// Answers
// 1 renew is approved
// 2 renew is not approved
// 3 request a renew
// 4 is to let the lender edit the due date
if ($renanswer == '1') {
// This is for approving the renew
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "UPDATE `$sealSTAT` SET `renewNoteLender` ='$renewNoteLender', `renewAnswer` ='1', `renewTimeStamp` = '$timestamp', `renewAccountLender` = '" . $wholename . "', `DueDate` = '$duedate' WHERE `illNUB` = '$reqnumb'";
if (mysqli_query($db, $sql)) {
echo "The renew request has been approved, <a href='/lender-history'>click here to go back to lender history</a>";
// Get the borrower email
$GETREQEMAIL = "SELECT title,requesterEMAIL FROM `$sealSTAT` WHERE `illNUB` = '" . $reqnumb . "'";
$result = mysqli_query($db, $GETREQEMAIL);
$value = mysqli_fetch_object($result);
$reqemail = $value->requesterEMAIL;
$title = $value->title;
// Message for the destination library
$messagedest = "Your renewal request for ILL# " . $reqnumb . " for " . $title . " has been approved with a due date of " . $duedate . " <br><br>Title:" . $title . "<br>";
if (strlen($renewNoteLender) > 1) {
$messagedest .= "Lender Note:" . $renewNoteLender . " <br>";
}
// Set email subject for renewal
$subject = "SEAL Renewal Approved: for ILL# $reqnumb";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
// SEND EMAIL to Detestation Library
// Check if $destemailarray is a string and convert it to an array if needed
if (!is_array($destemailarray)) {
// Assuming $destemailarray is a comma-separated string, convert it to an array
$destemailarray = explode(',', $destemailarray);
}
$email_to = implode(',', $destemailarray);
$headers = "From: Southeastern SEAL <donotreply@senylrc.org>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$messagedest = preg_replace('/(?<!\r)\n/', "\r\n", $messagedest);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to meg at seal for development
//$reqemail="spalding@senylrc.org";
mail($reqemail, $subject, $messagedest, $headers, "-f donotreply@senylrc.org");
} else {
echo "Was not able to make updates, please contact Southeastern of this error";
}
} else {
echo "<form action=" . $_SERVER['REDIRECT_URL'] . " method='post'>";
echo "<input type='hidden' name='a' value= '1'>";
echo "<input type='hidden' name='num' value= '" . $reqnumb . "'>";
echo "New Due Date: <input id='datepicker' name='duedate'/><br>";
echo "Renew notes:<br> <textarea name='renewNoteLender' rows='10' cols='30' maxlength='255'></textarea><br><br> ";
echo "<input type='submit' value='Submit'>";
echo "</form>";
}
} elseif ($renanswer == '2') {
// this is for rejecting the renew
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "UPDATE `$sealSTAT` SET `renewNoteLender` ='$renewNoteLender', `renewAnswer` ='2', `renewTimeStamp` = '$timestamp', `renewAccountLender` = '" . $wholename . "' WHERE `illNUB` = '$reqnumb'";
if (mysqli_query($db, $sql)) {
echo "The renew request has been rejected, <a href='/lender-history'>click here to go back to lender history</a>";
// Get the borrower's email
$GETREQEMAIL = "SELECT title,requesterEMAIL FROM `$sealSTAT` WHERE `illNUB` = '" . $reqnumb . "'";
$result = mysqli_query($db, $GETREQEMAIL);
$value = mysqli_fetch_object($result);
$reqemail = $value->requesterEMAIL;
$title = $value->title;
// Message for the destination library
$messagedest = "Your renewal request for ILL# " . $reqnumb . " for " . $title . " has been denied; please return the book to the lender by the original due date. <br><br>";
if (strlen($renewNoteLender) > 1) {
$messagedest .= "Lender Note:" . $renewNoteLender . " <br>";
}
// Set email subject for renewal
$subject = "SEAL Renewal Denied: for ILL# $reqnumb";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
// SEND EMAIL to Detestation Library
// Check if $destemailarray is a string and convert it to an array if needed
if (!is_array($destemailarray)) {
// Assuming $destemailarray is a comma-separated string, convert it to an array
$destemailarray = explode(',', $destemailarray);
}
$email_to = implode(',', $destemailarray);
$headers = "From: Southeastern SEAL <donotreply@senylrc.org>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$messagedest = preg_replace('/(?<!\r)\n/', "\r\n", $messagedest);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to meg at seal for development
//$reqemail="spalding@senylrc.org";
mail($reqemail, $subject, $messagedest, $headers, "-f donotreply@senylrc.org");
} else {
echo "Was not able to make updates, please contact Southeastern of this error";
}
} else {
echo "<form action=" . $_SERVER['REDIRECT_URL'] . " method='post'>";
echo "<input type='hidden' name='a' value= '2'>";
echo "<input type='hidden' name='num' value= '" . $reqnumb . "'>";
echo "Comments about request:<br> <textarea name='renewNoteLender' rows='10' cols='30' maxlength='255'></textarea><br><br> ";
echo "<input type='submit' value='Submit'>";
echo "</form>";
}
} elseif ($renanswer == '4') {
// This will allow the lender to edit the due date
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "UPDATE `$sealSTAT` SET `renewTimeStamp` = '$timestamp', `renewAccountLender` = '" . $wholename . "', `DueDate` = '$duedate' WHERE `illNUB` = '$reqnumb'";
if (mysqli_query($db, $sql)) {
echo "The due date has been updated, <a href='/lender-history'>click here to go back to lender history</a>";
// Get the borrower email
$GETREQEMAIL = "SELECT Title,requesterEMAIL FROM `$sealSTAT` WHERE `illNUB` = '" . $reqnumb . "'";
$result = mysqli_query($db, $GETREQEMAIL);
$value = mysqli_fetch_object($result);
$reqemail = $value->requesterEMAIL;
$title = $value->Title;
// Message for the destination library
$messagedest = "The lender has changed the due date for ILL# " . $reqnumb . "<br> Title: " . $title . " <br>New Due Date: " . $duedate . ", please return the book to the lender by that date. <br><br>";
// Set email subject for renewal
$subject = "SEAL Due Date Modify: for ILL# $reqnumb";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
// SEND EMAIL to Detestation Library
// Check if $destemailarray is a string and convert it to an array if needed
if (!is_array($destemailarray)) {
// Assuming $destemailarray is a comma-separated string, convert it to an array
$destemailarray = explode(',', $destemailarray);
}
$email_to = implode(',', $destemailarray);
$headers = "From: Southeastern SEAL <donotreply@senylrc.org>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$messagedest = preg_replace('/(?<!\r)\n/', "\r\n", $messagedest);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to meg at seal for development
//$reqemail="spalding@senylrc.org";
mail($reqemail, $subject, $messagedest, $headers, "-f donotreply@senylrc.org");
} else {
echo "Was not able to receive the item, please contact Southeastern of this error";
}
} else {
// Get the current due date
$sqlduedate = "SELECT DueDate FROM `$sealSTAT` WHERE `illNUB` = '" . $reqnumb . "' LIMIT 1 ";
$result = mysqli_query($db, $sqlduedate);
$value = mysqli_fetch_object($result);
echo "<h2>Edit Due Date For ILL #: " . $reqnumb . " <br>Current due date: " . $value->DueDate . "</h2>";
echo "<form action=" . $_SERVER['REDIRECT_URL'] . " method='post'>";
echo "<input type='hidden' name='a' value= '4'>";
echo "<input type='hidden' name='num' value= '" . $reqnumb . "'>";
echo "Due Date: <input id='datepicker' name='duedate'/><br>";
echo "<input type='submit' value='Submit'>";
echo "</form>";
}
} elseif ($renanswer == '3') {
// This is for the borrower to request a renewed
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$sql = "UPDATE `$sealSTAT` SET `renewTimeStamp` = '" . $timestamp . "', `renewAccountRequester` = '" . $wholename . "', `renewNote` = '$renewNote' WHERE `illNUB` = '$reqnumb'";
if (mysqli_query($db, $sql)) {
echo "Renew request for ILL " . $reqnumb . " has been sent, <br><a href='/requesthistory'>click here to go back to request history</a>";
// Get the Lending ID for the request
$sqlrenew = "SELECT RequesterEMAIL,Title,Destination FROM `$sealSTAT` WHERE `illNUB` = '" . $reqnumb . "' LIMIT 1 ";
$result = mysqli_query($db, $sqlrenew);
$value = mysqli_fetch_object($result);
$lenderid = $value->Destination;
$title = $value->Title;
$reqemail = $value->RequesterEMAIL;
// Get the Destination Name
$GETLISTSQLDEST = "SELECT `Name`, `ill_email` FROM `$sealLIB` where loc = '$lenderid' 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 a comma for PHP mail
$destemailarray = explode(';', $destemail);
$destemail_to = implode(',', $destemailarray);
// Message for the destination library
$messagedest = $field_your_institution . " has requested a renewal for ILL# " . $reqnumb . "<br>Title: " . $title . "<br><br>
<br>
How do you wish to answer the renewal? <a href='http://seal.senylrc.org/renew?num=$reqnumb&a=1' >Approved</a> <a href='http://seal.senylrc.org/renew?num=$reqnumb&a=2' >Deny</a>
<Br>
<hr style='width:200px;text-align:left;margin-left:0'>
<br> This is an automated message from the SEAL. Responses to this email will be sent back to Southeastern New York Library Resources Council staff. If you would like to contact the other library in this ILL transaction, email " . $reqemail . ".";
// Set email subject for renewal
$subject = "SEAL Renew Request: from " . $field_your_institution . " ILL# $reqnumb";
$subject = html_entity_decode($subject, ENT_QUOTES, 'UTF-8');
// SEND EMAIL to Detestation Library
$email_to = implode(',', $destemailarray);
$headers = "From: Southeastern SEAL <donotreply@senylrc.org>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$messagedest = preg_replace('/(?<!\r)\n/', "\r\n", $messagedest);
$headers = preg_replace('/(?<!\r)\n/', "\r\n", $headers);
//mail has been sent to meg at seal for development
//$destemail_to="spalding@senylrc.org";
mail($destemail_to, $subject, $messagedest, $headers, "-f donotreply@senylrc.org");
} else {
// email error function here
echo "Was not able to renew item due to a technical issue, please let Southeastern know this error occurred";
}
} else {
echo "<h2>Renew ILL: " . $reqnumb . "</h2>";
echo "<form action=" . $_SERVER['REDIRECT_URL'] . " method='post'>";
echo "<input type='hidden' name='a' value= '3'>";
echo "<input type='hidden' name='num' value= '" . $reqnumb . "'>";
echo "Reason for Renew:<br> <textarea name='renewNote' rows='10' cols='30' maxlength='255'></textarea><br><br> ";
echo "<input type='submit' value='Submit'>";
echo "</form>";
}
} else {
echo "I am not sure what to do";
}
?>