<?php
class foo {
public $name;
}
$con = mysql_connect(“localhost”,“root”,“”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
else
{
mysql_select_db(“worldcat”, $con);
// echo ‘Connected’;
$result = mysql_query(“SELECT OCLCNumber FROM worldcat limit 1”);
//$obj = mysql_fetch_object($result, ‘foo’);
echo “<table border=‘1’>
<tr>
<th>BarCode</th>
<th>CatalogKey</th>
<th>OCLCNumber</th>
<th>LibraryCounts</th>
<th>PublicationYear</th>
</tr>”;
//echo 'ISBN' . "--> " . 'CatalogKey'. "-->" .'OCLCNumber'. "-->" .'LibraryCounts';
// echo "<br />";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['BarCode'] . "</td>";
echo "<td>" . $row['CatalogKey'] . "</td>";
echo "<td>" . $row['OCLCNumber'] . "</td>";
echo "<td>" . $row['LibraryCounts'] . "</td>";
echo "<td>" . $row['PublicationYear'] . "</td>";
echo "</tr>";
}
}
$WorldCatAPIKey = ‘p0rR7Cc19hXVPEH14NrLdsE9KMvUNMx3zRn8ql9zxQeCIIQxbby1X2433EfMFFMsOvKllzi2OBPGMrt3’; // My current WorldCat Search API Key
if( strlen($_REQUEST[‘OCLCNumber’]) > 0 and strlen($_REQUEST[‘Location’]) > 0) {
$searchURL = “http://www.worldcat.org/webservices/catalog/content/libraries/{$_REQUEST[‘OCLCNumber’]}?location=” . urlencode($_REQUEST[‘Location’]) ;
/** We likely don’t need the ‘startLibrary’, ‘maximumLibraries’, or ‘libType’ parameters in the requests :
these are to limit the number of libraries from which we retrieve results, and we want to include all
libraries within the specified location.
$searchURL .= ‘&startLibrary=’. $_REQUEST[StartLibrary];
$searchURL .= ‘&maximumLibraries=’. $_REQUEST[MaximumLibraries];
$searchURL .= ‘libtype=’. $_REQUEST[LibType];
*/
$searchURL .= ‘&wskey=’. $WorldCatAPIKey;
$xml = simplexml_load_file($searchURL); //Converts the well-formed XML document in the given file to an object
// Calculate the library counts
$xml->registerXPathNamespace(“marc”, “http://www.loc.gov/MARC21/slim”); // Registers a namespace context for the next XPath query
// Go get the Library Locations in the search results
$xml->registerXPathNamespace(“marc”, “http://www.loc.gov/MARC21/slim”);
$location_ids = “”;
$locations = $xml->xpath("//marc:record/marc:datafield[@tag='020']/marc:subfield[@code='a']"); // TODO : Set correct Marc Datafield for location
foreach ((array)$locations as $location) {
if (strlen($location) > 1) {
if (strpos($location[0], " ") > 0) {
$location_ids = $location_ids . substr($location, 0, strpos($location, " "));
} else {
$location_ids = $location_ids = $location_ids . $location[0];
}
if ($location != end($locations)) {
$location_ids = $location_ids . ',';
}
}
}
foreach($xml->xpath('//marc:record') as $publication ) {
$publication['xmlns:marc'] = 'http://www.loc.gov/MARC21/slim';
$field = simplexml_load_string($publication->asXML());
$barcode = $field->xpath("marc:datafield[@tag='020']/marc:subfield[@code='a']"); // TODO : Set correct Marc Datafield for barcode
$location = $field->xpath("marc:datafield[@tag='260']/marc:subfield[@code='b']"); // // TODO : Set correct Marc Datafield for location
$sumloc = array_sum($location); // Calculate the sum of values in the location array
$publication_date = $field->xpath("marc:datafield[@tag='260']/marc:subfield[@code='c']");
$publication_year=date("Y", strtotime("$publication_date")); // Extracting the full numeric representation of the publication year (4 digits) from publication_date
if (strpos($location[0], " ") > 0) {
$location_1 = substr($location[0], 0, strpos($location[0], " "));
} else {
$location_1 = $location[0];
}
$oclcnumber = $field->xpath("marc:controlfield[@tag='001']");
}
}
?>