Skip to content

Instantly share code, notes, and snippets.

@SimonXIX
Last active October 8, 2018 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonXIX/feed7db6c8486e8682b76d10c438fbcd to your computer and use it in GitHub Desktop.
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.
<?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 <sb174@soas.ac.uk>
# @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 = "soas_ole_robot@soas.ac.uk";
$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