Last active
October 8, 2018 15:19
-
-
Save SimonXIX/feed7db6c8486e8682b76d10c438fbcd to your computer and use it in GitHub Desktop.
Script to renew checked-out items on the Open Library Environment ILS. Just for personal use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# @name: renew_items.php | |
# @version: 0.3 | |
# @creation_date: 2017-07-27 | |
# @license: GNU General Public License version 3 (GPLv3) <https://www.gnu.org/licenses/gpl-3.0.en.html> | |
# @author: Simon Barron <[email protected]> | |
# @purpose: Renew items for a user in OLE | |
?> | |
<?php | |
function renewItems(){ | |
$baseurl = 'https://xxxxxxxxxxxxxx:8443/olefs/circulation?'; | |
$service = 'lookupUser'; | |
$barcode = 'xxxxxxxxxxxxxx'; | |
$operator_id = 'xxxxxxxxxxxxxx'; | |
$fullurl = $baseurl . 'service=' . $service . '&patronBarcode=' . $barcode . '&operatorId=' . $operator_id; | |
#GET user information inc. loans using cURL | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $fullurl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
$user_xml = new SimpleXMLElement($response); | |
foreach ($user_xml->oleCheckedOutItems->checkedOutItems->checkedOutItem as $item){ | |
$service = 'renewItem'; | |
$item_barcode = $item->itemId; | |
$fullurl = $baseurl . 'service=' . $service . '&patronBarcode=' . $barcode . '&operatorId=' . $operator_id . '&itemBarcode=' . $item_barcode; | |
#POST renewal request using cURL | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $fullurl); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_HEADER, FALSE); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
#send a response email to the user | |
$to = $user_xml->patronEmail->emailAddress; | |
$from = "[email protected]"; | |
$subject = "Your weekly renewals"; | |
$message = "Hi,". "<br /><br />" . "We tried to renew your books this week and it either succeeded or failed..." . "<br /><br />" . $response . "<br /><br />" . "Kind regards," . "<br /><br />" . "Soas's OLE Robot"; | |
$headers = 'MIME-Version: 1.0' . "\r\n"; | |
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; | |
$headers .= "From:" . $from; | |
mail($to,$subject,$message,$headers); | |
} | |
} | |
renewItems(); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment