/** * Get Item Statuses * * This is responsible for printing the holdings information for a * collection of records in XML format. * * @access public * @author Chris Delis <*****@*****.**> */ function GetItemStatuses() { global $configArray; require_once ROOT_DIR . '/CatalogConnection.php'; // Try to find a copy that is available $catalog = new CatalogConnection($configArray['Catalog']['driver']); $result = $catalog->getStatuses($_GET['id']); // In order to detect IDs missing from the status response, create an // array with a key for every requested ID. We will clear keys as we // encounter IDs in the response -- anything left will be problems that // need special handling. $missingIds = array_flip($_GET['id']); // Loop through all the status information that came back foreach ($result as $record) { // If we encountered errors, skip those problem records. if (PEAR_Singleton::isError($record)) { continue; } $available = false; $location = ''; $recordId = ''; $reserve = ''; $callnumber = ''; if (count($record)) { foreach ($record as $info) { if ($recordId == '') { $recordId = $info['id']; } if ($reserve == '') { $reserve = $info['reserve']; } if ($callnumber == '') { $callnumber = $info['callnumber']; } // Find an available copy if ($info['availability']) { $available = true; } // Has multiple locations? if ($location != 'Multiple Locations') { if ($location != '') { if ($info['location'] != $location) { $location = 'Multiple Locations'; } else { $location = htmlspecialchars($info['location']); } } else { $location = htmlspecialchars($info['location']); } } } // The current ID is not missing -- remove it from the missing list. unset($missingIds[$recordId]); echo ' <item id="' . htmlspecialchars($recordId) . '">'; if ($available) { echo ' <availability>true</availability>'; } else { echo ' <availability>false</availability>'; } echo ' <location>' . htmlspecialchars($location) . '</location>'; echo ' <reserve>' . htmlspecialchars($reserve) . '</reserve>'; echo ' <callnumber>' . htmlspecialchars($callnumber) . '</callnumber>'; echo ' </item>'; } } // If any IDs were missing, send back appropriate dummy data foreach ($missingIds as $missingId => $junk) { echo ' <item id="' . htmlspecialchars($missingId) . '">'; echo ' <availability>false</availability>'; echo ' <location>Unknown</location>'; echo ' <reserve>N</reserve>'; echo ' <callnumber></callnumber>'; echo ' </item>'; } }