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.

<style>
* {
  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;
}
</style>
 
<?php
 
//These are the MMS's for the specific items being called for loan information
$mms = array("99900175377801855",
"99900183577701855",
"99900261277801855",
"99900183577501855",
"99900183577401855",
"99900183577301855",
"99900204275401855",
"99900203876601855",
"99900204376001855",
"99900204377301855",
"99900204375901855",
"99900204376101855",
"99900204376401855",
"99900204377201855",
"99900204376301855",
"99900204376201855",
"99900262878101855",
"99900262878001855",
"99900263277701855",
"99900264476401855"); 
 
//This is the Ex Libris API for SOU, In two parts.
$api1="https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs/";
$api2="/loans?apikey=yourkeyhere";
 
//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) {
$url=file_get_contents("{$api1}{$value}{$api2}");
$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>";
 
$x++;
 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
       flush();
 
}
echo "<p>&nbsp;</p>";
echo "<p>&nbsp;</p>";
 
?>

 

Leave a Reply