Tech Blog

Retrieving Due dates for selected items

This is a simple PHP script for getting and displaying the due dates, users, barcodes, and MMSids for a small sample of specific items. We use this for Chromebooks. They are very popular and we want to monitor their use so we can contact patrons with overdues promptly.

* {
  box-sizing: border-box;
/* Create two equal columns that floats next to each other */
.column {
  float: left;
  width: 200px;
  padding: 10px;
  height: 300px; /* Should be removed. Only for demonstration */
/* Clear floats after the columns */
.row:after {
  content: "";
  display: table;
  clear: both;
//These are the MMS's for the specific items being called for loan information
$mms = array("99900175377801855",
//This is the Ex Libris API for SOU, In two parts.
//Function used below to extract info about the loan dates, times, users, etc.
function get_string_between($string, $start, $end){
    $string = ' ' . $string;
    $ini = strpos($string, $start);
    if ($ini == 0) return '';
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
$t=time(); //current Unix timestamp for measuring overdues
$x = 1;  //Used for naming chromebooks 1-20
echo "<div class='row'><div class='column'>";
foreach ($mms as $value) {
$due = get_string_between($url, 'due_date>', '</due_date>');
$user = get_string_between($url, 'user_id>', '</user_id');
$mmsId = get_string_between($url, 'mms_id>', '</mms_id');
$barcode= get_string_between($url, 'barcode>', '</item');
$stamp = strtotime($due); //converts time to unix timestamp
$pacifictime=($stamp-28800); //subtracts 8 hours from GMT for Pacific Standard Time
if ($x==5 or $x==10 or $x==15) { //this is based entirely on how many items are being retrieved
echo "</div><div class='column'>";
echo "<b>Chromebook $x <br /></b>";
 if (strpos($url, 'count="0') !==false){            //when an item is not on loan the only XML retrieved  is "<item_loans total_record_count="0"/>"
  echo "Available";
echo "<br>";
echo "<br>";
 else {
echo "<b>User:</b> " . $user . "<br>";;
echo "<b>MMSid:</b> " . $mmsId . "<br>";
echo "<b>Barcode:</b> " . $barcode . "<br>";
if ($t > $stamp) {
echo "<font color='red'><b> is OVERDUE as of:</b> " . gmdate("M d Y G:i", $pacifictime) ."</b></font>";    //turns the text red to quikcly see overdues
else {
echo "<b>Due at:</b> " . gmdate("M d Y G:i", $pacifictime) ;
echo "<br>";
echo "<br>";
       ob_flush();     //these two functions make the data display as it is retrieved
echo "<p>&nbsp;</p>";
echo "<p>&nbsp;</p>";


Leave a Reply