changeset 42:3f400072bf14

merge, involved ediff3 wrt getAmazonInfo.php
author Charlie Root
date Sat, 05 Jan 2019 06:21:12 -0500
parents 0578c6e438d3 (current diff) 2c0c95bd97a6 (diff)
children dbc006408d2b
files xml/getAmazonInfo.php
diffstat 18 files changed, 1306 insertions(+), 899 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Sat Jan 05 06:21:12 2019 -0500
@@ -0,0 +1,2 @@
+test
+~$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/503.html	Sat Jan 05 06:21:12 2019 -0500
@@ -0,0 +1,34 @@
+<!DOCTYPE html><html>
+  <head>
+    <meta name="fragment" content="!">
+<meta name="viewport" content="width=device-width, user-scalable=no" />
+<meta http-equiv="content-type" content="text/html; charset=UTF-8">
+<META NAME="Description" CONTENT="YourNextRead recommends your next
+	      book. YourNextRead provides a book recommendation system
+	      showing aggregated book reviews, updated by real peoples
+	      opinions, in a simple visual map, helping you to decide
+	      'What Should I Read Next?'. Perfect for both bookworms
+	      and casual readers!">
+<title>YourNextRead: Site temporarily unavailable</title>
+</head>
+  <body>
+    <div id="fb-root"></div>
+	<script type="text/javascript">
+			var obj =   new Object;
+			obj.height=960;
+			FB.Canvas.setSize(obj);
+        </script>
+    <img src="http://www.yournextread.com/images/topleft.gif" alt="YourNextRead"/>
+<img src="http://www.yournextread.com/images/YNR_icon.png"/><img src="http://www.yournextread.com/images/topRightCorner.png"/>
+    <h1>Site temporarily unavailable</h1>
+    <p>Please check back in an hour or so.</p>
+
+
+    <hr>
+    <address><a href="mailto:root@markup.co.uk">root</a></address>
+<!-- Created: Tue Jan  1 07:04:01 EST 2019 -->
+<!-- hhmts start -->
+Last modified: Tue Jan  1 08:16:45 EST 2019
+<!-- hhmts end -->
+  </body>
+</html>
--- a/ca/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/ca/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -60,7 +60,7 @@
 	{
 	echo "<head>";
 	echo "<meta name=\"fragment\" content=\"!\">";
-	
+	echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />";
     echo "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">";
 	echo "<link type=\"text/css\" rel=\"stylesheet\" href=\"../Books.css\">";
 	
@@ -140,8 +140,25 @@
 				{
 					$bookDetails = getAmazonDet($isbn,1,'ca'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					    $bookXML->Items->Item[0]->ItemAttributes)
+					  { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					    if ($attrs->Title) {
+					      $title = $attrs->Title; }
+					    else {
+					      $title ="[no Title]";
+					    }
+					    if ($attrs->Author) {
+					      $author = $attrs->Author;
+					    }
+					    else {
+					      $author ="[no Author]";
+					    }
+					  }
+					else {
+					  $title ="[no Title]";
+					  $author = "[no Author]";
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
@@ -166,8 +183,21 @@
 					{					
 						$bookLDetails = getAmazonDet($linkedISBN,1,'ca'); 
 						$bookLXML = new SimpleXMLElement($bookLDetails);
-						$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-						$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+						if ($bookLXML->Items &&
+						    $bookLXML->Items->Item[0] &&
+						    $bookLXML->Items->Item[0]->ItemAttributes) {
+						  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+						  if ($attrs->Title) {
+						    $titleL = $attrs->Title; }
+						  else {
+						    $titleL = ""; }
+						  if ($attrs->Author) {
+						    $authorL = $attrs->Author; }
+						  else {
+						    $authorL = ""; }
+						}
+						else {
+						  $titleL = ""; }
 					}
 					if($titleL != "")
 					{
@@ -204,6 +234,7 @@
 					echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>";
 					echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>";
 				}
+				
 				echo "</head>";
 				
 				echo "<body>";				
@@ -222,7 +253,7 @@
 				catch(Exception $e)
 				{
 				  echo 'Message: ' .$e->getMessage();
-				}	
+				}
 			}
 		}
 		else
@@ -252,6 +283,7 @@
 				echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>";
 				echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>";
 			}
+			
 			echo "</head>";
 
 			echo "<body>";
@@ -271,7 +303,7 @@
 			FB.Canvas.setSize(obj);
 			</script>";
 		}
-	}
+	}	
 	?>
   
     <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/de/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/de/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -124,7 +124,7 @@
 				$ret = 1;
 				$countryCode = 3;
 				
-								include "../../private/db.php"; 
+				include "../../private/db.php"; 
 				$query = "CALL b_getBookInfo('$isbn', $countryCode)";
 				//echo $query;
 				$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
@@ -138,10 +138,27 @@
 				}		
 				else
 				{
-					$bookDetails = getAmazonDet($isbn,1,'ca'); 
+					$bookDetails = getAmazonDet($isbn,1,'de'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					    $bookXML->Items->Item[0]->ItemAttributes)
+					  { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					    if ($attrs->Title) {
+					      $title = $attrs->Title; }
+					    else {
+					      $title ="[no Title]";
+					    }
+					    if ($attrs->Author) {
+					      $author = $attrs->Author;
+					    }
+					    else {
+					      $author ="[no Author]";
+					    }
+					  }
+					else {
+					  $title ="[no Title]";
+					  $author = "[no Author]";
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
@@ -166,8 +183,21 @@
 					{					
 						$bookLDetails = getAmazonDet($linkedISBN,1,'de'); 
 						$bookLXML = new SimpleXMLElement($bookLDetails);
-						$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-						$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+						if ($bookLXML->Items &&
+						    $bookLXML->Items->Item[0] &&
+						    $bookLXML->Items->Item[0]->ItemAttributes) {
+						  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+						  if ($attrs->Title) {
+						    $titleL = $attrs->Title; }
+						  else {
+						    $titleL = ""; }
+						  if ($attrs->Author) {
+						    $authorL = $attrs->Author; }
+						  else {
+						    $authorL = ""; }
+						}
+						else {
+						  $titleL = ""; }
 					}
 					if($titleL != "")
 					{
@@ -273,7 +303,7 @@
 			FB.Canvas.setSize(obj);
 			</script>";
 		}
-	}
+	}	
 	?>
   
     <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/fr/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/fr/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -117,7 +117,7 @@
 			}
 			else
 			{
-			try{
+				try{
 				$isbn = substr($isbn, 5); 
 				$chars = explode("/",$isbn);
 				$isbn = $chars[0];
@@ -140,8 +140,25 @@
 				{
 					$bookDetails = getAmazonDet($isbn,1,'fr'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					    $bookXML->Items->Item[0]->ItemAttributes)
+					  { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					    if ($attrs->Title) {
+					      $title = $attrs->Title; }
+					    else {
+					      $title ="[no Title]";
+					    }
+					    if ($attrs->Author) {
+					      $author = $attrs->Author;
+					    }
+					    else {
+					      $author ="[no Author]";
+					    }
+					  }
+					else {
+					  $title ="[no Title]";
+					  $author = "[no Author]";
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
@@ -166,8 +183,21 @@
 					{					
 						$bookLDetails = getAmazonDet($linkedISBN,1,'fr'); 
 						$bookLXML = new SimpleXMLElement($bookLDetails);
-						$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-						$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+						if ($bookLXML->Items &&
+						    $bookLXML->Items->Item[0] &&
+						    $bookLXML->Items->Item[0]->ItemAttributes) {
+						  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+						  if ($attrs->Title) {
+						    $titleL = $attrs->Title; }
+						  else {
+						    $titleL = ""; }
+						  if ($attrs->Author) {
+						    $authorL = $attrs->Author; }
+						  else {
+						    $authorL = ""; }
+						}
+						else {
+						  $titleL = ""; }
 					}
 					if($titleL != "")
 					{
@@ -245,13 +275,13 @@
 			</noscript>";
 			if($iPhone && !$iPad)
 			{
-					echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />";
-					echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../booksMob/books.nocache.js\"></script>";
+				echo "<meta name=\"viewport\" content=\"width=device-width, user-scalable=no\" />";
+				echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../booksMob/books.nocache.js\"></script>";
 			}
 			else
 			{
-					echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>";
-					echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>";
+				echo "<script type=\"text/javascript\" language=\"javascript\" src=\"../raphael-min.js\"></script>";
+				echo $launchScript;//"<script type=\"text/javascript\" language=\"javascript\" src=\"../books/books.nocache.js\"></script>";
 			}
 			
 			echo "</head>";
@@ -273,7 +303,7 @@
 			FB.Canvas.setSize(obj);
 			</script>";
 		}
-	}
+	}	
 	?>
   
     <iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
--- a/geoiptest.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/geoiptest.php	Sat Jan 05 06:21:12 2019 -0500
@@ -1,8 +1,19 @@
 <html>
 <body>
 <?php
+if (isset($_SERVER["GEOIP_COUNTRY_NAME"])) {
 $country_name = $_SERVER["GEOIP_COUNTRY_NAME"];
-print "Country: " . $country_name;
+ }
+ else {
+$country_name = $_SERVER["REDIRECT_GEOIP_COUNTRY_NAME"];
+ }
+if (isset($_SERVER["GEOIP_COUNTRY_CODE"])) {
+$country_code = $_SERVER["GEOIP_COUNTRY_CODE"];
+ }
+ else {
+$country_code = $_SERVER["REDIRECT_GEOIP_COUNTRY_CODE"];
+ }
+print "Country: $country_name , code: $country_code";
 ?>
 </body>
 </html>
--- a/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -1,31 +1,42 @@
-<?php 
-		$country_code = $_SERVER["GEOIP_COUNTRY_CODE"];	  
-		switch($country_code){
-		/* case "CA":
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/ca/" );
-			break;
-		case "DE":
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/de/" );
-			break;
-		case "FR":
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/fr/" );
-			break;			
-		case "GB":
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/uk/" );
-			break;
-		case "US":
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/us/" );
-			break;	*/
-		default:
-			Header( "HTTP/1.1 301 Moved Permanently" );
-			Header ("Location: http://www.yournextread.com/us/" );
-			break;	
-		}	  
+<?php
+
+if (isset($_SERVER["GEOIP_COUNTRY_CODE"])) {
+$country_code = $_SERVER["GEOIP_COUNTRY_CODE"];
+ }
+elseif (isset($_SERVER["REDIRECT_GEOIP_COUNTRY_CODE"])) {
+$country_code = $_SERVER["REDIRECT_GEOIP_COUNTRY_CODE"];
+ }
+ else {$country_code = "US" ; }
+file_put_contents('/var/ywww/debug/phpDebug',
+		  "cc: $country_code\n",
+		  FILE_APPEND);
+   
+switch($country_code) {
+ case "CA":
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/ca/" );
+   break;
+ case "DE":
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/de/" );
+   break;
+ case "FR":
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/fr/" );
+   break;			
+ case "GB":
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/uk/" );
+   break;
+ case "US":
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/us/" );
+   break;
+ default:
+   Header( "HTTP/1.1 301 Moved Permanently" );
+   Header ("Location: http://www.yournextread.com/us/" );
+   break;	
+ }	  
 	?>
 <html>
 		  <head>
@@ -35,5 +46,6 @@
         <meta name="google-site-verification" content="0XCtbGM_bvOH363P2XE6DVjh-APTICOREquY8F38T84" />
 </HEAD>
 <body>
+<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=322bafc0-69fa-4664-8e1c-0b9159259748"></script>
 </body>
 
--- a/php/read/aws_signed_request.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/php/read/aws_signed_request.php	Sat Jan 05 06:21:12 2019 -0500
@@ -3,6 +3,49 @@
 //20090627/Jaap van Ganswijk: This is a modified version, see the
 //return statement some lines before the end of the last function.
 
+
+$Aassociates_id=array(
+		      'uk' => 'bookwhack-21',
+		      'us' => 'your02b-20',
+		      'ca' => 'book009-20',
+		      'de' => 'book04c-21',
+		      'fr' => 'book07f-21',
+		      );
+
+$Aserver=array(
+	       'ca' => array(
+			     'ext' => 'ca'                      ,  //Canadian normal server
+			     'nor' => 'http://www.amazon.ca'    ,  //Canadian normal server
+			     'xml' => 'http://xml.amazon.com'   ,  //Canadian xml server
+			     ),
+	       'de' => array(
+			     'ext' => 'de'                      ,  //German normal server
+			     'nor' => 'http://www.amazon.de'    ,  //German normal server
+			     'xml' => 'http://xml-eu.amazon.com',  //German xml server
+			     ),
+	       'fr' => array(
+			     'ext' => 'fr'                      ,  //French normal server
+			     'nor' => 'http://www.amazon.fr'    ,  //French normal server
+			     'xml' => 'http://xml-eu.amazon.com',  //French xml server
+			     ),
+	       'jp' => array(
+			     'ext' => 'jp'                      ,  //Japanese normal server, not co.jp!
+			     'nor' => 'http://www.amazon.co.jp' ,  //Japanese normal server
+			     'xml' => 'http://xml.amazon.com'   ,  //Japanese xml server
+			     ),
+	       'uk' => array(
+			     'ext' => 'co.uk'                   ,  //UK normal server
+			     'nor' => 'http://www.amazon.co.uk' ,  //UK normal server
+			     'xml' => 'http://xml-eu.amazon.com',  //UK xml server
+			     ),
+	       'us' => array(
+			     'ext' => 'com'                     ,  //USA normal server
+			     'nor' => 'http://www.amazon.com'   ,  //USA normal server
+			     'xml' => 'http://xml.amazon.com'   ,  //USA xml server
+			     ),
+	       );
+
+
 if (!function_exists("aws_signed_request")) {
 function aws_signed_request($region, $params, $public_key, $private_key)
 {
--- a/php/read/getAllSavedBooks.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/php/read/getAllSavedBooks.php	Sat Jan 05 06:21:12 2019 -0500
@@ -32,6 +32,7 @@
 
 $prevListName = "";
 
+if ($results) {
 while($line = mysqli_fetch_assoc($results)) {
 
 	$listName = htmlspecialchars(trim($line["SavedListName"]));
@@ -58,12 +59,14 @@
 		
 	$savedBooks++;
 }
-	
-	if($savedBooks != 0)
-	{
-		$output .=  "</ListDetails>";
-		$output .=  "</List>";
-	}
+ $results->free();
+ }
+mysqli_close($link);	
+if($savedBooks != 0)
+  {
+    $output .=  "</ListDetails>";
+    $output .=  "</List>";
+  }
 $output .=  "</results>";
 
 if(isset($ret))
@@ -71,7 +74,7 @@
 else
 	echo $output;
 
-mysqli_close($link);
+
 
 
 ?>
\ No newline at end of file
--- a/php/read/getBookDetails.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/php/read/getBookDetails.php	Sat Jan 05 06:21:12 2019 -0500
@@ -69,6 +69,7 @@
 	if ( mysqli_num_rows( $res ) > 0 )
 	{
 		$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
+		mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
 		$timestamp=$rows['Timestamp'];
 		//echo $timestamp;
 		date_default_timezone_set('UTC');
@@ -97,256 +98,253 @@
 			$output .=  "<ProductGroup>Book</ProductGroup>";
 		}
 	}
-	mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
-	include "../../../private/db.php";
+	else {
+	  mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+	}
 	
 	if($proceed == true)
-	{
-		include "aws_signed_request.php"; 
-		//book does not exist already so look up all the info from browse nodes....
+	  {
+	    include "aws_signed_request.php";
+	    include_once "../../xml/doAmazonRequest.inc";
+	    file_put_contents('/var/ywww/debug/phpDebug',
+			      "nbd proceeding: $isbn\n",
+			      FILE_APPEND);
+
+	    //book does not exist already so look up all the info from browse nodes....
+
+	    $Adefault=array(
+			    'language'           =>'en',           //what language to render the page in
+			    'locale'             =>'us',           //which server's products? available: ca,de,fr,jp,uk,us
+			    'page'               =>1,              //first page to show (we are counting from 1 not 0)
+			    'operation'          =>'ItemLookup',   //what to do?	//ItemSearch
+			    'searchparameter'    =>'ItemId',       //what kind of search?
+			    'searchindex'     => 'Books',
+			    'searchparameterdata'=>$isbn,  //what to search for?
+			    'search' =>$isbn,
+			    //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
+			    'show_array'         =>false,          //debug: show complete incoming array? You can use this to see what other information Amazon is sending
+			    'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
+			    'show_xml'           =>false,          //debug: show incoming XML code from Amazon?
+			    );
+	    //change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
+
+	    $Aassociates_id=array(
+				  'uk' => 'bookwhack-21',
+				  'us' => 'your02b-20',
+				  'ca' => 'book009-20',
+				  'de' => 'book04c-21',
+				  'fr' => 'book07f-21',
+				  );
 
-		$Adefault=array(
-		  'language'           =>'en',           //what language to render the page in
-		  'locale'             =>'us',           //which server's products? available: ca,de,fr,jp,uk,us
-		  'page'               =>1,              //first page to show (we are counting from 1 not 0)
-		  'operation'          =>'ItemLookup',   //what to do?	//ItemSearch
-		  'searchparameter'    =>'ItemId',       //what kind of search?
-		  'searchindex'     => 'Books',
-		  'searchparameterdata'=>$isbn,  //what to search for?
-		  'search' =>$isbn,
-		  //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
-		  'show_array'         =>false,          //debug: show complete incoming array? You can use this to see what other information Amazon is sending
-		  'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
-		  'show_xml'           =>false,          //debug: show incoming XML code from Amazon?
-		);
-		//change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
+	    $Aserver=array(
+			   'ca' => array(
+					 'ext' => 'ca'                      ,  //Canadian normal server
+					 'nor' => 'http://www.amazon.ca'    ,  //Canadian normal server
+					 'xml' => 'http://xml.amazon.com'   ,  //Canadian xml server
+					 ),
+			   'de' => array(
+					 'ext' => 'de'                      ,  //German normal server
+					 'nor' => 'http://www.amazon.de'    ,  //German normal server
+					 'xml' => 'http://xml-eu.amazon.com',  //German xml server
+					 ),
+			   'fr' => array(
+					 'ext' => 'fr'                      ,  //French normal server
+					 'nor' => 'http://www.amazon.fr'    ,  //French normal server
+					 'xml' => 'http://xml-eu.amazon.com',  //French xml server
+					 ),
+			   'jp' => array(
+					 'ext' => 'jp'                      ,  //Japanese normal server, not co.jp!
+					 'nor' => 'http://www.amazon.co.jp' ,  //Japanese normal server
+					 'xml' => 'http://xml.amazon.com'   ,  //Japanese xml server
+					 ),
+			   'uk' => array(
+					 'ext' => 'co.uk'                   ,  //UK normal server
+					 'nor' => 'http://www.amazon.co.uk' ,  //UK normal server
+					 'xml' => 'http://xml-eu.amazon.com',  //UK xml server
+					 ),
+			   'us' => array(
+					 'ext' => 'com'                     ,  //USA normal server
+					 'nor' => 'http://www.amazon.com'   ,  //USA normal server
+					 'xml' => 'http://xml.amazon.com'   ,  //USA xml server
+					 ),
+			   );
 
-		$Aassociates_id=array(
-		  'uk' => 'bookwhack-21',
-		  'us' => 'your02b-20',
-		  'ca' => 'book009-20',
-		  'de' => 'book04c-21',
-		  'fr' => 'book07f-21',
-		);
+	    //for all parameters see if the user has overruled it or use the default
+	    foreach ($Adefault as $i=>$d) {
+	      $$i=isset($_GET[$i])?$_GET[$i]:$d;
+	    }
 
-		$Aserver=array(
-		  'ca' => array(
-			'ext' => 'ca'                      ,  //Canadian normal server
-			'nor' => 'http://www.amazon.ca'    ,  //Canadian normal server
-			'xml' => 'http://xml.amazon.com'   ,  //Canadian xml server
-		  ),
-		  'de' => array(
-			'ext' => 'de'                      ,  //German normal server
-			'nor' => 'http://www.amazon.de'    ,  //German normal server
-			'xml' => 'http://xml-eu.amazon.com',  //German xml server
-		  ),
-		  'fr' => array(
-			'ext' => 'fr'                      ,  //French normal server
-			'nor' => 'http://www.amazon.fr'    ,  //French normal server
-			'xml' => 'http://xml-eu.amazon.com',  //French xml server
-		  ),
-		  'jp' => array(
-			'ext' => 'jp'                      ,  //Japanese normal server, not co.jp!
-			'nor' => 'http://www.amazon.co.jp' ,  //Japanese normal server
-			'xml' => 'http://xml.amazon.com'   ,  //Japanese xml server
-		  ),
-		  'uk' => array(
-			'ext' => 'co.uk'                   ,  //UK normal server
-			'nor' => 'http://www.amazon.co.uk' ,  //UK normal server
-			'xml' => 'http://xml-eu.amazon.com',  //UK xml server
-		  ),
-		  'us' => array(
-			'ext' => 'com'                     ,  //USA normal server
-			'nor' => 'http://www.amazon.com'   ,  //USA normal server
-			'xml' => 'http://xml.amazon.com'   ,  //USA xml server
-		  ),
-		);
-		$public_key ="AKIAIHTNWC7L6LOUY4LQ";
-		$private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde";			
+	    $parameters=array(
+			      'Operation'       =>$operation              ,
+			      'Keywords'        =>urlencode($search)      ,
+			      "$searchparameter"=>$searchparameterdata    ,
+			      'ItemPage'        =>$page                   ,  //which page?
+			      'AssociateTag'    =>$Aassociates_id[$locale],
+			      'ResponseGroup'   =>'ItemAttributes,Images,SalesRank,BrowseNodes'
+			      );
 
-		//for all parameters see if the user has overruled it or use the default
-		foreach ($Adefault as $i=>$d) {
-		  $$i=isset($_GET[$i])?$_GET[$i]:$d;
-		}
+	    if ($searchindex!='Books') {
+	      $parameters['SearchIndex']=$searchindex;
+	    }
 
-		  $parameters=array(
-			'Operation'       =>$operation              ,
-			'Keywords'        =>urlencode($search)      ,
-			"$searchparameter"=>$searchparameterdata    ,
-			'ItemPage'        =>$page                   ,  //which page?
-			'AssociateTag'    =>$Aassociates_id[$locale],
-			'ResponseGroup'   =>'ItemAttributes,Images,SalesRank,BrowseNodes'
-		  );
-
-		  if ($searchindex!='Books') {
-		    // HST did this
-		    // Used to be in $parameters init above, but
-		    // that caused an error:
-		    // If idType equals ASIN, SearchIndex cannot be present
-		    //'SearchIndex'     =>$searchindex      ,  //Books for example.
-		      $parameters['SearchIndex']=$searchindex;
-		  }
-
-
-		$ext=$Aserver[$locale]['ext'];  
-		$file_data=$ext;
-		ksort($parameters);
-		foreach ($parameters as $i=>$d) {
-		  $file_data.='&'.$i.'='.$d;
-		}
-
-		$url=aws_signed_request($ext,$parameters,$public_key,$private_key);  
-		//echo $url;
-
-		$crl = curl_init();
-		$timeout = 5;
-		curl_setopt ($crl, CURLOPT_URL,$url);
-		curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); 
-		curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
-		curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
-		$out = curl_exec($crl);
-		curl_close($crl);
-
-		//echo $out;
+	    try {
+	      $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,6,'d');
+	      //use this xml to pull out the necessary information and save it
+	      set_error_handler(function () {
+		  global $out,$isbn;
+		  file_put_contents('/var/ywww/debug/phpDebug',
+				    "Caught one bd: ".$isbn,
+				    FILE_APPEND);
+		  file_put_contents('/var/ywww/debug/phpDebug',
+				    print_r($out, TRUE)."\n",
+				    FILE_APPEND);
+		} );
+	      include "../../../private/db.php";
+	
+	      $title="";
+	      $author="";
+	      $binding="";
+	      $dewey="";
+	      $imageURL="";
+	      $salesRank="";
+	      $pubDate="";
+	      $publisher="";
+	
+	      $title = $xml->Items->Item->ItemAttributes->Title;
+	      $author = $xml->Items->Item->ItemAttributes->Author;
+	      $binding = $xml->Items->Item->ItemAttributes->Binding;
+	      $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
+	      if($dewey == "")
+		$dewey = "null";
+	      $imageURL = $xml->Items->Item->MediumImage->URL;
+	      $salesRank = $xml->Items->Item->SalesRank;
+	      $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
+	      $publisher = $xml->Items->Item->ItemAttributes->Publisher;
+	      restore_error_handler();
+	      if ($publisher and strlen($publisher)>30) {
+		$publisher=substr($publisher,0,30);
+	      }
+	      if ($author and strlen($author)>30) {
+		$author=substr($author,0,30);
+	      }
+	      if ($title and strlen($title)>100) {
+		$title=substr($title,0,100);
+	      }
+	      $publisher=mysqli_real_escape_string($link,$publisher);
+	      $author=mysqli_real_escape_string($link,$author);
+	      $title=mysqli_real_escape_string($link,$title);
+	      if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
+	      if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
+	      if (strlen($pubDate)==0) {
+		$pubDate="null";
+	      }
+	      else {
+		$pubDate="\"$pubDate\"";
+	      }
+	      /*echo $title;
+	       echo $author;
+	       echo $binding;
+	       echo $dewey;
+	       echo $imageURL;
+	       echo $salesRank;
+	       echo $pubDate;
+	       echo $publisher;*/
 		
-		if (preg_match("<Error>",$out)) {
-		  $xml = new SimpleXMLElement($out);	
-		  $resName=$xml->getName();
-		  $code=$xml->Error->Code;
-		  file_put_contents('/var/ywww/debug/phpDebug',"Losing gBD: $resName, $code\n",FILE_APPEND);
-		  if ($code=='RequestThrottled') {
-		    usleep(200000); // Try to reduce throttling until we get a 
-		    // principled solution in place
-		  }
-		  else {
-		    file_put_contents('/var/ywww/debug/phpDebug',"parms bd: ".
-				      print_r($parameters,TRUE)."\n",FILE_APPEND);
-		    if ($code=="") {
-		      file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$out\n",FILE_APPEND);
-		    }
-		  }
-		}
-		else {
-		  $xml = new SimpleXMLElement($out);
-		  //use this xml to pull out the necessary information and save it
-		  set_error_handler(function () {
-		      global $out,$isbn;
-		      file_put_contents('/var/ywww/debug/phpDebug',
-					"Caught one bd: ".$isbn,
-					FILE_APPEND);
-		      file_put_contents('/var/ywww/debug/phpDebug',
-					print_r($out, TRUE)."\n",
-					FILE_APPEND);
-		    } );
-	
-		  $title="";
-		  $author="";
-		  $binding="";
-		  $dewey="";
-		  $imageURL="";
-		  $salesRank="";
-		  $pubDate="";
-		  $publisher="";
-	
-		  $title = $xml->Items->Item->ItemAttributes->Title;
-		  $author = $xml->Items->Item->ItemAttributes->Author;
-		  $binding = $xml->Items->Item->ItemAttributes->Binding;
-		  $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
-		  if($dewey == "")
-		    $dewey = "null";
-		  $imageURL = $xml->Items->Item->MediumImage->URL;
-		  $salesRank = $xml->Items->Item->SalesRank;
-		  $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
-		  $publisher = $xml->Items->Item->ItemAttributes->Publisher;
-		  restore_error_handler();
-		  /*echo $title;
-		   echo $author;
-		   echo $binding;
-		   echo $dewey;
-		   echo $imageURL;
-		   echo $salesRank;
-		   echo $pubDate;
-		   echo $publisher;*/
-		
+	      $genreID = "";
+	      $genre = "";		
+	      $genArr = array();
+	      $g1 = "null";
+	      $g2 = "null";
+	      $g3 = "null";
+	      if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){		
+		for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){					
+		  //sexy recursive function
+		  findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
+			
+		  if($genre != "")
+		    $genArr[strval($genreID)] = strval($genre);
+		  //$genArr[$i] = array(strval($genreID) => strval($genre));
+
+		  //echo $genre;
+		  //echo $genreID;
+			
+		  $genre = "";
 		  $genreID = "";
-		  $genre = "";		
-		  $genArr = array();
-		  $g1 = "null";
-		  $g2 = "null";
-		  $g3 = "null";
-		  if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){		
-		    for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){					
-		      //sexy recursive function
-		      findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
-			
-		      if($genre != "")
-			$genArr[strval($genreID)] = strval($genre);
-		      //$genArr[$i] = array(strval($genreID) => strval($genre));
-
-		      //echo $genre;
-		      //echo $genreID;
-			
-		      $genre = "";
-		      $genreID = "";
-		    }
+		}
 		
-		    $g1 = "null";
-		    $g2 = "null";
-		    $g3 = "null";
-		    $loop = 1;
+		$g1 = "null";
+		$g2 = "null";
+		$g3 = "null";
+		$loop = 1;
 		
-		    foreach ($genArr as $key => $value) {
-		      //echo "$key => $value";
-		      $queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
-		      //echo $queryG;
-		      $resG = mysqli_query($link, $queryG);
+		foreach ($genArr as $key => $value) {
+		  //echo "$key => $value";
+		  if ($key>2047) {
+		    //HST added
+		    break;
+		  }
+		  $queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
+		  //echo $queryG;
+		  $resG = mysqli_query($link, $queryG);
+			
+		  switch ($loop) {
+		  case 1:
+		    $g1 = $key;
+		    break;
+		  case 2:
+		    $g2 = $key;
+		    break;
+		  case 3:
+		    $g3 = $key;
+		    break;
+		  }
 			
-		      switch ($loop) {
-		      case 1:
-			$g1 = $key;
-			break;
-		      case 2:
-			$g2 = $key;
-			break;
-		      case 3:
-			$g3 = $key;
-			break;
-		      }
-			
-		      $loop++;
-		    }
-		  }
+		  $loop++;
+		}
+	      }
+		  
+	      if($salesRank == "")
+		$salesRank = "null";
+		
+	      mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+	      include "../../../private/db.php";
 		
-		  if($salesRank == "")
-		    $salesRank = "null";
-		
-		  mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
-		  include "../../../private/db.php";
+	      $title = strtr($title, '"', "'");	
+	      $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,\"$publisher\",$g1,$g2,$g3,$loc)";	
+	      //echo $queryInsert;
 		
-		  $title = strtr($title, '"', "'");	
-		  $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";	
-		  //echo $queryInsert;
-		
-		  $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
-		  mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
+	      $res = mysqli_query($link, $queryInsert);
+	      if (!$res) {
+		$err=mysqli_error( $link );
+		mysqli_close($link);
+		file_put_contents('/var/ywww/debug/phpDebug',
+				  "anb failed: $err, $pubDate, $g2, $publisher, $title\n",
+				  FILE_APPEND);
+		exit($err);
+	      }
+	      mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
 
 		
-		  $output .=  "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
-		  $output .=  "<Title>" . htmlspecialchars($title) . "</Title>";
-		  $output .=  "<Author>" . htmlspecialchars($author) . "</Author>";
-		  $output .=  "<Binding>" . htmlspecialchars($binding) . "</Binding>";
-		  $output .=  "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
-		  $output .=  "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
-		  $output .=  "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
-		  $output .=  "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
-		  $output .=  "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
-		  $output .=  "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
-		  $output .=  "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
-		  $output .=  "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";	
-		  $output .=  "<ProductGroup>Book</ProductGroup>";
-		}
-	}
-	
+	      $output .=  "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
+	      $output .=  "<Title>" . htmlspecialchars($title) . "</Title>";
+	      $output .=  "<Author>" . htmlspecialchars($author) . "</Author>";
+	      $output .=  "<Binding>" . htmlspecialchars($binding) . "</Binding>";
+	      $output .=  "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
+	      $output .=  "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
+	      $output .=  "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
+	      $output .=  "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
+	      $output .=  "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
+	      $output .=  "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
+	      $output .=  "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
+	      $output .=  "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";	
+	      $output .=  "<ProductGroup>Book</ProductGroup>";
+	    }
+	    catch (Exception $e) {
+	      file_put_contents('/var/ywww/debug/phpDebug',
+				"gBD: dAR failed:".$e->getMessage()."\n",
+				FILE_APPEND);
+	    }
+	  }
 	$output .=  "</BookDetails>";
 	
 	echo $output;
--- a/php/read/similar.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/php/read/similar.php	Sat Jan 05 06:21:12 2019 -0500
@@ -106,8 +106,26 @@
         curl_setopt ($crl, CURLOPT_URL,$url);
         curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
+	$gotit=0;
+	  $semaphore = new SyncSemaphore("Amazon");
+	  $gotit = $semaphore->lock(1000);
+	  if (!$gotit) {
+	    file_put_contents('/var/ywww/debug/phpDebug',
+			      "Got it: ".(int)$gotit." 4\n",FILE_APPEND);
+	    $gotit = $semaphore->lock(1000);
+	    file_put_contents('/var/ywww/debug/phpDebug',
+		        "Got it: ".(int)$gotit." 4a\n",FILE_APPEND);
+	  }
         $ret = curl_exec($crl);
         curl_close($crl);
+	usleep(500000);
+	if ($gotit) {
+	  $semaphore->unlock();
+	}
+	else {
+	  file_put_contents('/var/ywww/debug/phpDebug',
+			    "Unlocking 4\n",FILE_APPEND);
+	}
         //echo $ret;
 		
 $xml = new SimpleXMLElement($ret);
--- a/php/read/updateLink.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/php/read/updateLink.php	Sat Jan 05 06:21:12 2019 -0500
@@ -6,7 +6,10 @@
 echo $change;
 $dir = strval($_GET['dir']);
 echo $dir;
-$userID = strval($_GET['userID']);
+$userID="";
+if (isset($_GET['userID'])) {
+    $userID = strval($_GET['userID']);
+  }
 echo $userID;
 
 include "../../../private/db.php";  
--- a/uk/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/uk/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -127,21 +127,45 @@
 				include "../../private/db.php"; 
 				$query = "CALL b_getBookInfo('$isbn', $countryCode)";
 				//echo $query;
-				$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
+				$res = mysqli_query($link, $query);
+				if (!$res) {
+				  $err=mysqli_error( $link );
+				  mysqli_close($link);
+				  exit($err);
+				}
 				include "../xml/aws_signed_request.php";
 				include "../xml/getAmazonInfo.php";
 				if ( mysqli_num_rows( $res ) > 0 )
 				{
 					$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);		
+					mysqli_close($link);
 					$title = $rows["Title"];
 					$author = $rows["Author"];
 				}		
 				else
 				{
+				  mysqli_close($link);
 					$bookDetails = getAmazonDet($isbn,1,'uk'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
-					$title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					$author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					    $bookXML->Items->Item[0]->ItemAttributes)
+					  { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					    if ($attrs->Title) {
+					      $title = $attrs->Title; }
+					    else {
+					      $title ="[no Title]";
+					    }
+					    if ($attrs->Author) {
+					      $author = $attrs->Author;
+					    }
+					    else {
+					      $author ="[no Author]";
+					    }
+					  }
+					else {
+					  $title ="[no Title]";
+					  $author = "[no Author]";
+					}
 				}
 
 				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
@@ -158,16 +182,30 @@
 					if ( mysqli_num_rows( $res ) > 0 )
 					{
 						$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);		
+						mysqli_close($link);
 						$titleL = $rows["Title"];
 						$authorL = $rows["Author"];
-						mysqli_close($link);
 					}		
 					else
 					{					
+						mysqli_close($link);
 						$bookLDetails = getAmazonDet($linkedISBN,1,'uk'); 
 						$bookLXML = new SimpleXMLElement($bookLDetails);
-						$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-						$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+						if ($bookLXML->Items &&
+						    $bookLXML->Items->Item[0] &&
+						    $bookLXML->Items->Item[0]->ItemAttributes) {
+						  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+						  if ($attrs->Title) {
+						    $titleL = $attrs->Title; }
+						  else {
+						    $titleL = ""; }
+						  if ($attrs->Author) {
+						    $authorL = $attrs->Author; }
+						  else {
+						    $authorL = ""; }
+						}
+						else {
+						  $titleL = ""; }
 					}
 					if($titleL != "")
 					{
--- a/us/index.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/us/index.php	Sat Jan 05 06:21:12 2019 -0500
@@ -133,15 +133,17 @@
 				if ( mysqli_num_rows( $res ) > 0 )
 				{
 					$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);		
+					mysqli_close($link);
 					$title = $rows["Title"];
 					$author = $rows["Author"];
 				}		
 				else
 				{
+				  mysqli_close($link);
 					$bookDetails = getAmazonDet($isbn,1,'us'); 
 					$bookXML = new SimpleXMLElement($bookDetails);
 					// HST added this
-					if (preg_match("<Error>",$bookDetails)) {
+					if (preg_match("/<Error>/",$bookDetails)) {
 					  $resName=$bookXML->getName();
 					  $code=$bookXML->Error->Code;
 					  file_put_contents('/var/ywww/debug/phpDebug',"Losing 3: $resName, ".
@@ -151,16 +153,41 @@
 					    // principled solution in place
 					  }
 					  $title = "";
+					  $author = "";
 					}
 					else {
-					  $title = $bookXML->Items->Item[0]->ItemAttributes->Title;
-					  $author = $bookXML->Items->Item[0]->ItemAttributes->Author;
+					  if ($bookXML->Items && $bookXML->Items->Item[0] &&
+					      $bookXML->Items->Item[0]->ItemAttributes)
+					    { $attrs=$bookXML->Items->Item[0]->ItemAttributes;
+					      if ($attrs->Title) {
+						$title = $attrs->Title; }
+					      else {
+						$title ="[no Title]";
+					      }
+					      if ($attrs->Author) {
+						$author = $attrs->Author;
+					      }
+					      else {
+						$author ="[no Author]";
+					      }
+					    }
+					  else {
+					    $title ="[no Title]";
+					    $author = "[no Author]";
+					  }	
 					}
 				}
 
-				$linkedBooks = include "../php/read/getLinkedBooks.php"; 
+				$linkedBooks = include "../php/read/getLinkedBooks.php";
+				try {
 				$xml = new SimpleXMLElement($linkedBooks);
-				
+				}
+				catch (Exception $e) {
+				  file_put_contents('/var/ywww/debug/phpDebug',
+						    "Bad XML?: ".$linkedBooks,
+						    FILE_APPEND);
+				  throw $e;
+				}
 				$recommended = "";
 				$linkedRecommended = "";
 				for($i=0;$i<sizeof($xml->isbn);$i++){
@@ -181,16 +208,17 @@
 				  if ( mysqli_num_rows( $res ) > 0 )
 				    {
 				      $rows=mysqli_fetch_array($res, MYSQLI_ASSOC);		
+				      mysqli_close($link);
 				      $titleL = $rows["Title"];
 				      $authorL = $rows["Author"];
-				      mysqli_close($link);
 				    }		
 				  else
 				    {					
+				      mysqli_close($link);
 				      $bookLDetails = getAmazonDet($linkedISBN,1,'us'); 
 				      $bookLXML = new SimpleXMLElement($bookLDetails);
 				      // HST added this
-				      if (preg_match("<Error>",$bookLDetails)) {
+				      if (preg_match("/<Error>/",$bookLDetails)) {
 					$resName=$bookLXML->getName();
 					$code=$bookLXML->Error->Code;
 					file_put_contents('/var/ywww/debug/phpDebug',"Losing 2: $resName, ".
@@ -202,8 +230,21 @@
 					$titleL = "";
 				      }
 				      else {
-					$titleL = $bookLXML->Items->Item[0]->ItemAttributes->Title;
-					$authorL = $bookLXML->Items->Item[0]->ItemAttributes->Author;
+					if ($bookLXML->Items &&
+					    $bookLXML->Items->Item[0] &&
+					    $bookLXML->Items->Item[0]->ItemAttributes) {
+					  $attrs=$bookLXML->Items->Item[0]->ItemAttributes;
+					  if ($attrs->Title) {
+					    $titleL = $attrs->Title; }
+					  else {
+					    $titleL = ""; }
+					  if ($attrs->Author) {
+					    $authorL = $attrs->Author; }
+					  else {
+					    $authorL = ""; }
+					}
+					else {
+					  $titleL = ""; }
 				      }
 				    }
 				  restore_error_handler();
@@ -327,5 +368,6 @@
 	pageTracker._setAllowLinker(true);
 	pageTracker._trackPageview();
 	} catch(err) {}</script>
-  </body>
+   <script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US&adInstanceId=322bafc0-69fa-4664-8e1c-0b9159259748"></script>
+   </body>
 </html>
--- a/user/resetPassword.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/user/resetPassword.php	Sat Jan 05 06:21:12 2019 -0500
@@ -5,15 +5,17 @@
 include "passGen.php";
 
 // emailname and password sent from form
-$userID=$_GET['userID'];
+$mypassword=$_GET['pwd'];
 $email=$_GET['email'];
-$mypassword=$_GET['pwd'];
-$oldpass=$_GET['oldpwd'];
+if ($mypassword!='regen') {
+  $oldpass=$_GET['oldpwd'];
+  $userID=$_GET['userID'];
 
-// To protect MySQL injection 
-$userID = stripslashes($userID);
-$userID = mysqli_real_escape_string($link,$userID);
-//echo $userID;
+  // To protect MySQL injection 
+  $userID = stripslashes($userID);
+  $userID = mysqli_real_escape_string($link,$userID);
+  //echo $userID;
+ }
 $email = stripslashes($email);
 $mypassword = stripslashes($mypassword);
 $email = mysqli_real_escape_string($link,$email);
--- a/xml/amazonBookSearch.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/xml/amazonBookSearch.php	Sat Jan 05 06:21:12 2019 -0500
@@ -93,6 +93,23 @@
         curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
 	curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
+	$gotit=0;
+	  $semaphore = new SyncSemaphore("Amazon");
+	  $gotit = $semaphore->lock(1000);
+          if (!$gotit) {
+	    file_put_contents('/var/ywww/debug/phpDebug',
+			      "Got it: ".(int)$gotit." 3\n",FILE_APPEND);
+	    $gotit=$semaphore->lock(1000);
+	    file_put_contents('/var/ywww/debug/phpDebug',
+			      "Got it: ".(int)$gotit." 3a\n",FILE_APPEND);
+	  }
         $ret = curl_exec($crl);
         curl_close($crl);
+        usleep(500000);
+	if ($gotit) {
+	  $semaphore->unlock();
+	}
+        else {
+	  file_put_contents('/var/ywww/debug/phpDebug',"W/o lock 3b\n",FILE_APPEND);
+        }
         echo $ret;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xml/doAmazonRequest.inc	Sat Jan 05 06:21:12 2019 -0500
@@ -0,0 +1,89 @@
+<?php
+
+function doAmazonRequest($ext, $parameters, $try, $dbl='x')
+{
+  $public_key ="AKIAIHTNWC7L6LOUY4LQ";
+  $private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde";
+  $requestURI = $_SERVER['REQUEST_URI'];
+  $requestIP = $_SERVER['REMOTE_ADDR'];
+  $file_data=$ext;
+  ksort($parameters);
+  foreach ($parameters as $i=>$d) {
+    $file_data.='&'.$i.'='.$d;
+  }
+  //file_put_contents('/var/ywww/debug/phpDebug',
+  //		"nai1: $requestIP $file_data\n",FILE_APPEND);
+  $gotit=0;
+  $url=aws_signed_request($ext,$parameters,$public_key,$private_key);  
+  for ($i=1; $i<=$try; $i++) {
+    $crl = curl_init();
+    $timeout = 5;
+    curl_setopt ($crl, CURLOPT_URL,$url);
+    curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); 
+    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
+    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
+    $semaphore = new SyncSemaphore("Amazon");
+    $gotit = $semaphore->lock(1000);
+    if (!$gotit) {
+      file_put_contents('/var/ywww/debug/phpDebug',
+			"Got it: ".(int)$gotit." $requestIP $dbl\n",FILE_APPEND);
+      $gotit=$semaphore->lock(1000);
+      file_put_contents('/var/ywww/debug/phpDebug',
+			"Got it: ".(int)$gotit." $requestIP $dbl"."a\n",FILE_APPEND);
+    }
+    $output = curl_exec($crl);
+    //file_put_contents('/var/ywww/debug/phpDebug',
+    //	      "nai2: ".strlen($output)."\n",FILE_APPEND);
+
+    curl_close($crl);
+    usleep(500000);
+    if ($gotit) {
+      $semaphore->unlock();
+    }
+    else {
+      file_put_contents('/var/ywww/debug/phpDebug',
+			"W/o lock for $requestIP $dbl"."b\n",FILE_APPEND);
+    }
+    $mm=array();
+    $xml = new SimpleXMLElement($output);	
+    if (preg_match("/<Error>/",$output,$mm)) {
+      $resName=$xml->getName();
+      $code=$xml->Error->Code;
+      if ($code) {
+	$message=$xml->Error->Message;
+      }
+      else {
+	$code=$xml->Items->Request->Errors->Error->Code;
+	$message=$xml->Items->Request->Errors->Error->Message;
+      }
+      file_put_contents('/var/ywww/debug/phpDebug',"Losing $i: $dbl ".$mm[0].", $resName, $code, $requestIP, $requestURI\n",FILE_APPEND);
+      if ($code!='RequestThrottled') {
+	file_put_contents('/var/ywww/debug/phpDebug',"message: $message\n",FILE_APPEND);
+	if ($code=='AWS.InvalidParameterValue' && strpos($message,"for ItemId.")>0) {
+	  // Check for common problem and try to fix...
+	  $spd=$parameters['ItemId'];
+	  if (strpos($spd,'/')>0) {
+	    $isbnMaybe=substr($spd,0,strpos($spd,'/'));
+	    $parameters['ItemId']=$isbnMaybe;
+	    if (isset($parameters['Keywords'])) {
+		$parameters['Keywords']=urlencode($isbnMaybe);
+	      }
+	    file_put_contents('/var/ywww/debug/phpDebug',"retrying with $isbnMaybe\n",FILE_APPEND);
+	    return doAmazonRequest($ext,$parameters,$try,$dbl);
+	  }
+	}
+	if ($code=="") {
+	  file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND);
+	}
+	throw new Exception($code);
+      }
+    }
+    else {
+      return $xml;
+    }
+    usleep(100000*$i); // Try to reduce throttling until we get a 
+    // principled solution in place
+  }
+  throw new Exception("ThrottledRepeatedly");
+}
+?>
--- a/xml/getAmazonInfo.php	Sun Jul 30 05:36:48 2017 -0400
+++ b/xml/getAmazonInfo.php	Sat Jan 05 06:21:12 2019 -0500
@@ -1,581 +1,584 @@
-<?php
-
-$lastReqTime=0;
-function getAmazonDet($isbn,$go,$localeIn)
-{
-  global $output;
-$Adefault=array(
-  'language'           =>'en',           //what language to render the page in
-  'locale'             =>$localeIn,           //which server's products? available: ca,de,fr,jp,uk,us
-//'mode'               =>'books',        //what product category?
-  'page'               =>1,              //first page to show (we are counting from 1 not 0)
-//'search'             =>'Machiavelli',  //what to search for?
-  'operation'          =>'ItemLookup',   //what to do?	//ItemSearch
- // 'searchindex'        =>'Books',        //what product category for search?
-  'searchparameter'    =>'ItemId',       //what kind of search?
-  'searchparameterdata'=>$isbn,  //what to search for?
-  //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
-  'show_array'         =>false,          //debug: show complete incoming array? You can use this to see what other information Amazon is sending
-  'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
-  'show_xml'           =>false,          //debug: show incoming XML code from Amazon?
-);
-//change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
-
-$Aassociates_id=array(
-  'uk' => 'bookwhack-21',
-  'us' => 'your02b-20',
-  'ca' => 'book009-20',
-  'de' => 'book04c-21',
-  'fr' => 'book07f-21',
-);
-
-$Aserver=array(
-  'ca' => array(
-    'ext' => 'ca'                      ,  //Canadian normal server
-    'nor' => 'http://www.amazon.ca'    ,  //Canadian normal server
-    'xml' => 'http://xml.amazon.com'   ,  //Canadian xml server
-  ),
-  'de' => array(
-    'ext' => 'de'                      ,  //German normal server
-    'nor' => 'http://www.amazon.de'    ,  //German normal server
-    'xml' => 'http://xml-eu.amazon.com',  //German xml server
-  ),
-  'fr' => array(
-    'ext' => 'fr'                      ,  //French normal server
-    'nor' => 'http://www.amazon.fr'    ,  //French normal server
-    'xml' => 'http://xml-eu.amazon.com',  //French xml server
-  ),
-  'jp' => array(
-    'ext' => 'jp'                      ,  //Japanese normal server, not co.jp!
-    'nor' => 'http://www.amazon.co.jp' ,  //Japanese normal server
-    'xml' => 'http://xml.amazon.com'   ,  //Japanese xml server
-  ),
-  'uk' => array(
-    'ext' => 'co.uk'                   ,  //UK normal server
-    'nor' => 'http://www.amazon.co.uk' ,  //UK normal server
-    'xml' => 'http://xml-eu.amazon.com',  //UK xml server
-  ),
-  'us' => array(
-    'ext' => 'com'                     ,  //USA normal server
-    'nor' => 'http://www.amazon.com'   ,  //USA normal server
-    'xml' => 'http://xml.amazon.com'   ,  //USA xml server
-  ),
-);
-
-//if(go != 1)
-	//include "aws_signed_request.php";  
-$public_key ="AKIAIHTNWC7L6LOUY4LQ";
-$private_key="zWQlIzndJDtXNfxEXH7K7YR7hzv3u77lOcqfqPde";
-//for all parameters see if the user has overruled it or use the default
-foreach ($Adefault as $i=>$d) {
-  $$i=isset($_GET[$i])?$_GET[$i]:$d;
-}
-//this is the data that is used to form the request for AWS
-//this is the part that is search specific
-  $parameters=array(
-    'Operation'       =>$operation              ,
-    //'Keywords'        =>urlencode($search)      ,
-    //'SearchIndex'     =>$searchindex            ,  //Books for example.
-    "$searchparameter"=>$searchparameterdata    ,
-    'ItemPage'        =>$page                   ,  //which page?
-    'AssociateTag'    =>$Aassociates_id[$locale],
-    'ResponseGroup'   =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes'                ,  //Small, Medium, Large or SellerListing,'BrowseNodes',// ,
-	'ReviewSort'	  =>'-HelpfulVotes'
-  );
-
-$ext=$Aserver[$locale]['ext'];  
-$file_data=$ext;
-ksort($parameters);
-foreach ($parameters as $i=>$d) {
-  $file_data.='&'.$i.'='.$d;
-}
-
-$url=aws_signed_request($ext,$parameters,$public_key,$private_key);  
-//echo $url;
-        $crl = curl_init();
-        $timeout = 5;
-        curl_setopt ($crl, CURLOPT_URL,$url);
-		curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); 
-        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
-        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
-	/*	$timeDiff=((int)(microtime(true)*1000))-$lastReqTime;
-	if ($timeDiff<1000) {
-	  usleep((1000-$timeDiff)*1000); // microseconds
-	  }*/
-        $output = curl_exec($crl);
-	//$lastReqTime=(int)(microtime(true)*1000); // milliseconds
-        curl_close($crl);
-		
-	/*$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2009-03-31/\"><Error><Code>AccountLimitExceeded</Code><Message>Account limit of 2056 requests per hour exceeded.</Message></Error><RequestID>290ed059-730c-4789-93b4-6d21e11053d3</RequestID></ItemLookupErrorResponse>");*/
-	$review = "";
-	// HST added this
-	if (preg_match("<Error>",$output)) {
-	  $xml = new SimpleXMLElement($output);	
-	  $resName=$xml->getName();
-	  $code=$xml->Error->Code;
-	  file_put_contents('/var/ywww/debug/phpDebug',"Losing (test): $resName, $code\n",FILE_APPEND);
-	  if ($code=='RequestThrottled') {
-	    usleep(200000); // Try to reduce throttling until we get a 
-	    // principled solution in place
-	  }
-	  else {
-	     file_put_contents('/var/ywww/debug/phpDebug',"parms: $go\nurl: $url\n".
-		   print_r($parameters,TRUE)."\n",FILE_APPEND);
-	     if ($code=="") {
-	       file_put_contents('/var/ywww/debug/phpDebug',"error elt:\n$output\n",FILE_APPEND);
-	     }
-	  }
-	}
-	else {
-	  $xml = new SimpleXMLElement($output);	
-	  set_error_handler(function () {
-	      global $output;
-	      file_put_contents('/var/ywww/debug/phpDebug',
-				"Caught one?: ".$searchparameterdata,
-				FILE_APPEND);
-	      file_put_contents('/var/ywww/debug/phpDebug',
-				print_r($output, TRUE)."\n",
-				FILE_APPEND);
-	    } );
-	  $review = $xml->Items->Item->CustomerReviews->IFrameURL;
-	  // The above is failing repeatedly -- 
-	  //PHP Notice: Trying to get property of non-object in
-	  // /var/ywww/xml/getAmazonInfo.php on line [109]
-	  // See the dumped structure at the end of this file for the
-	  // cause
-	  restore_error_handler();
-	  //echo $review;
-	  $review1 = "";
-	  $review2 = "";
-	  $review3 = "";
-	}
-	if ($review != "")
-	{
-		$text = @file_get_contents($review . "&truncate=300");
-		$removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text);
-		$removeTop2 = preg_replace('~<div class="crIFrameHeaderHistogram">(.*?)<div class="crIframeReviewList">~si', '', $text);
-		if (preg_match('~<body[^>]*>(.*?)</body>~si', $removeTop2, $body)){ $getBody = trim($body[1]); }
-		$removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody);
-		$removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv);
-		$setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs);
-		//replace <!-- BOUNDARY --> with BOTTOM-TOP
-		$remove1 = '~<table cellpadding="0"(.*?)%">~s';
-		$setBoundary = preg_replace($remove1,'', $setBoundary);
-		$remove2 = '~</td><td bg(.*?)</table>~s';
-		$setBoundary = preg_replace($remove2,'', $setBoundary);
-		$remove3 = '~<a name=(.*?)</a>~s';
-		$setBoundary = preg_replace($remove3,'', $setBoundary);
-		$setBoundary2 = str_replace('<br />','', $setBoundary);
-		//remove all extra crap;
-		$setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2);
-		//replace </td> with BOTTOM
-		
-		if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
-		{ 
-			$reviewContents = $reviews[1];
-			//print_r($reviewContents);
-			$review1 = trim($reviewContents[0]);
-			$review1 = str_replace("\n", "", $review1);
-			$review1 = str_replace("\r", "", $review1);
-			if (isset($reviewContents[1])) {
-			  $review2 = trim($reviewContents[1]);
-			  $review2 = str_replace("\n", "", $review2);
-			  $review2 = str_replace("\r", "", $review2);
-			}
-			else {
-			  $review2 = "";
-			}
-			if (isset($reviewContents[2])) {
-			  $review3 = trim($reviewContents[2]);
-			  $review3 = str_replace("\n", "", $review3);
-			  $review3 = str_replace("\r", "", $review3);
-			}
-			else {
-			  $review3 = "";
-			}
-		}
-		else
-		{
-			$review1 = "";
-			$review2 = "";
-			$review3 = "";
-			//echo "EPIC FAIL";
-		}
-
-		unset($xml->Items->Item->CustomerReviews);
-		$xdoc = new DomDocument;
-		$xdoc->loadXML($xml->asXML());
-		
-		$cReviews = $xdoc ->createElement('CustomerReviews');
-		$cReviewHolder = $xdoc ->createElement('Review');
-		$cReview = $xdoc ->createElement('Content');
-		$cReviewHolder2 = $xdoc ->createElement('Review');
-		$cReview2 = $xdoc ->createElement('Content');	
-		$cReviewHolder3 = $xdoc ->createElement('Review');
-		$cReview3 = $xdoc ->createElement('Content');
-		
-		$txtNode = $xdoc ->createTextNode ($review1);
-		$cReview -> appendChild($txtNode);
-		
-		$txtNode2 = $xdoc ->createTextNode ($review2);
-		$cReview2 -> appendChild($txtNode2);
-		
-		$txtNode3 = $xdoc ->createTextNode ($review3);
-		$cReview3 -> appendChild($txtNode3);
-		
-		$cReviewHolder -> appendChild($cReview);
-		$cReviewHolder2 -> appendChild($cReview2);
-		$cReviewHolder3 -> appendChild($cReview3);
-		
-		$cReviews -> appendChild($cReviewHolder);
-		$cReviews -> appendChild($cReviewHolder2);
-		$cReviews -> appendChild($cReviewHolder3);
-		
-		$xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
-		$newXML = simplexml_import_dom($xdoc);
-		$output = $newXML->asXml();
-	}
-	
-	switch($locale){
-		case "us": 
-			$loc = 0;
-			break;
-		case "uk": 
-			$loc = 1;
-			break;
-		case "ca": 
-			$loc = 2;
-			break;
-		case "de": 
-			$loc = 3;
-			break;
-		case "fr": 
-			$loc = 4;
-			break;
-	};		
-	
-	$errorCode = $xml->Error->Code;
-	//echo $errorCode;
-
-	if($errorCode != "AccountLimitExceeded")
-	{
-	  if($go == 1) {
-	    file_put_contents('/var/ywww/debug/phpDebug',"win: ".
-			    $xml->Items->Item->ItemAttributes->Title."\n",
-			      FILE_APPEND);
-			return $output;
-	  }
-		else
-		{
-			$title = $xml->Items->Item->ItemAttributes->Title;
-			$author = $xml->Items->Item->ItemAttributes->Author;
-			$binding = $xml->Items->Item->ItemAttributes->Binding;
-			$dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
-			if($dewey == "")
-				$dewey = "null";
-			$imageURL = $xml->Items->Item->MediumImage->URL;
-			$salesRank = $xml->Items->Item->SalesRank;
-			$pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
-			$publisher = $xml->Items->Item->ItemAttributes->Publisher;
-			
-			$genreID = "";
-			$genre = "";		
-			$genArr = array();
-			
-			for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){					
-				//sexy recursive function
-				findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
-				
-				if($genre != "")
-					$genArr[strval($genreID)] = strval($genre);
-					//$genArr[$i] = array(strval($genreID) => strval($genre));
-
-				//echo $genre;
-				//echo $genreID;
-				
-				$genre = "";
-				$genreID = "";
-			}
-			
-			$g1 = "null";
-			$g2 = "null";
-			$g3 = "null";
-			$loop = 1;
-			
-			foreach ($genArr as $key => $value) {
-				//echo "$key => $value";
-				$queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
-				//echo $queryG;
-				include "../../private/db.php";
-				$resG = mysqli_query($link, $queryG);
-				mysqli_close($link);
-				
-				switch ($loop) {
-				case 1:
-					$g1 = $key;
-					break;
-				case 2:
-					$g2 = $key;
-					break;
-				case 3:
-					$g3 = $key;
-					break;
-				}
-				
-				$loop++;
-			}
-			
-			if($salesRank == "")
-				$salesRank = "null";
-			
-			$title = strtr($title, '"', "'");
-			include "../../private/db.php";
-			$review1 = mysqli_real_escape_string($link,$review1);
-			$review2 = mysqli_real_escape_string($link,$review2);
-			$review3 = mysqli_real_escape_string($link,$review3);
-			
-			if($title != "")
-			{
-				$queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";	
-				//echo $queryInsert;
-				$queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")";
-				
-				$resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
-				if($review1 != "" && $review2 != "" && $review3 != "")
-					$resG = mysqli_query($link, $queryInsertReviews) or exit( mysqli_error( $link ));
-					
-				mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
-			}
-
-			echo $output;
-		}
-	}
-	else
-	{
-		//look up info from db	
-		include "../../private/db.php"; 
-		$query = "CALL b_getBookInfo('$searchparameterdata', $loc)";
-		//echo $query;
-		$res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
-	
-		$output = "";
-		$output .=  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
-		$output .=  "<Details>";
-		if ( mysqli_num_rows( $res ) > 0 )
-		{
-			$rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
-						
-			$output .=  "<ASIN>" . $searchparameterdata . "</ASIN>";
-			$output .=  "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>";			
-			$output .=  "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>";
-			$output .=  "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>";
-			$output .=  "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>";
-			$output .=  "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>";
-			$output .=  "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>";
-			$output .=  "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>";
-			$output .=  "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>";
-			$output .=  "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>";
-			$output .=  "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>";
-			$output .=  "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>";
-			$output .=  "<ProductGroup>Book</ProductGroup>";
-			$output .=  "<Error>AccountLimitExceeded</Error>";
-			
-		}		
-		$output .=  "</Details>";
-		echo $output;
-	}     
-}
-
-function findGenre($browseNode, &$ID, &$gen)
-{
-	if($browseNode->Name == "Subjects")
-	{
-		 return true;		 
-	}
-	else
-	{
-		if($browseNode->Ancestors->BrowseNode)
-		{
-			if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true)
-			{
-				$gen = $browseNode->Name;
-				$ID = $browseNode->BrowseNodeId;
-			}		
-		}
-		return false;		
-	}
-}
-
-if(!isset($ret))
-{
-	include "aws_signed_request.php";  
-	getAmazonDet('default',0,'us');	//will get overwritten
-}
-/*Caught oneSimpleXMLElement Object
-(
-    [OperationRequest] => SimpleXMLElement Object
-        (
-            [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330
-            [Arguments] => SimpleXMLElement Object
-                (
-                    [Argument] => Array
-                        (
-                            [0] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => AWSAccessKeyId
-                                            [Value] => AKIAIHTNWC7L6LOUY4LQ 
-                                        )
-
-                                )
-
-                            [1] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => AssociateTag
-                                            [Value] => bookwhack-21
-                                        )
-
-                                )
-
-                            [2] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => ItemId
-                                            [Value] => B004Q3Q3Y4
-                                        )
-
-                                )
-
-                            [3] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => ItemPage
-                                            [Value] => 1
-                                        )
-
-                                )
-
-                            [4] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => Operation
-                                            [Value] => ItemLookup
-                                        )
-
-                                )
-
-                            [5] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => ResponseGroup
-                                            [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes
-                                        )
-
-                                )
-
-                            [6] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => ReviewSort
-                                            [Value] => -HelpfulVotes
-                                        )
-
-                                )
-
-                            [7] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => Service
-                                            [Value] => AWSECommerceService
-                                        )
-
-                                )
-
-                            [8] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => Timestamp
-                                            [Value] => 2016-12-15T23:12:34Z
-                                        )
-
-                                )
-
-                            [9] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => Version
-                                            [Value] => 2011-08-01
-                                        )
-
-                                )
-
-                            [10] => SimpleXMLElement Object
-                                (
-                                    [@attributes] => Array
-                                        (
-                                            [Name] => Signature
-                                            [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ=
-                                        )
-
-                                )
-
-                        )
-
-                )
-
-            [RequestProcessingTime] => 0.3518217620000000
-        )
-
-    [Items] => SimpleXMLElement Object
-        (
-            [Request] => SimpleXMLElement Object
-                (
-                    [IsValid] => True
-                    [ItemLookupRequest] => SimpleXMLElement Object
-                        (
-                            [IdType] => ASIN
-                            [ItemId] => B004Q3Q3Y4
-                            [ResponseGroup] => Array
-                                (
-                                    [0] => ItemAttributes
-                                    [1] => Reviews
-                                    [2] => EditorialReview
-                                    [3] => OfferSummary
-                                    [4] => Offers
-                                    [5] => Images
-                                    [6] => AlternateVersions
-                                    [7] => SalesRank
-                                    [8] => BrowseNodes
-                                )
-
-                            [VariationPage] => All
-                        )
-
-                    [Errors] => SimpleXMLElement Object
-                        (
-                            [Error] => SimpleXMLElement Object
-                                (
-                                    [Code] => AWS.InvalidParameterValue
-                                    [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request.
-                                )
-
-                        )
-
-                )
-
-        )
-
-)
-*/
-?>
+<?php
+
+include_once "doAmazonRequest.inc";
+
+function getAmazonDet($isbn,$go,$localeIn)
+{
+  $Adefault=array(
+		  'language'           =>'en',           //what language to render the page in
+		  'locale'             =>$localeIn,           //which server's products? available: ca,de,fr,jp,uk,us
+		  //'mode'               =>'books',        //what product category?
+		  'page'               =>1,              //first page to show (we are counting from 1 not 0)
+		  //'search'             =>'Machiavelli',  //what to search for?
+		  'operation'          =>'ItemLookup',   //what to do?	//ItemSearch
+		  'searchindex'        =>'Books',        //what product category for search?
+		  'searchparameter'    =>'ItemId',       //what kind of search?
+		  'searchparameterdata'=>$isbn,  //what to search for?
+		  //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
+		  'show_array'         =>false,          //debug: show complete incoming array? You can use this to see what other information Amazon is sending
+		  'show_url'           =>false,          //debug: show XML request url to be send to Amazon?
+		  'show_xml'           =>false,          //debug: show incoming XML code from Amazon?
+		  );
+  //change the debug options to true if you want to activate them or call the script with '?show_array=true' to see what actual information you're getting from Amazon and how little my standard script is actually showing of it
+  //for all parameters see if the user has overruled it or use the default
+  foreach ($Adefault as $i=>$d) {
+    $$i=isset($_GET[$i])?$_GET[$i]:$d;
+  }
+  switch($locale){
+  case "us": 
+    $loc = 0;
+    break;
+  case "uk": 
+    $loc = 1;
+    break;
+  case "ca": 
+    $loc = 2;
+    break;
+  case "de": 
+    $loc = 3;
+    break;
+  case "fr": 
+    $loc = 4;
+    break;
+  };		
+
+  try {  
+    return getAmazonDetRemote($go,$language,$locale,$loc,
+			      $page,$operation,$searchparameter,
+			      $searchparameterdata,
+			      $show_array,$show_url,$show_xml);
+  }
+  catch (Exception $e) {
+    return getAmazonDetLocal($go,$language,$loc,
+			     $page,$operation,$searchparameter,
+			     $searchparameterdata,
+			     $show_array,$show_url,$show_xml);
+  }
+}
+
+function getAmazonDetRemote($go,$language,$locale,$loc,
+			    $page,$operation,$searchparameter,
+			    $searchparameterdata,
+			    $show_array,$show_url,$show_xml)
+{
+  global $output, $Aassociates_id, $Aserver;
+
+  //if(go != 1)
+  //include "aws_signed_request.php";  
+  //this is the data that is used to form the request for AWS
+  //this is the part that is search specific
+  $parameters=array(
+		    'Operation'       =>$operation              ,
+		    //'Keywords'        =>urlencode($search)      ,
+		    "$searchparameter"=>$searchparameterdata    ,
+		    'ItemPage'        =>$page                   ,  //which page?
+		    'AssociateTag'    =>$Aassociates_id[$locale],
+		    'ResponseGroup'   =>'ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes'                ,  //Small, Medium, Large or SellerListing,'BrowseNodes',// ,
+		    'ReviewSort'	  =>'-HelpfulVotes'
+		    );
+
+  if (isset($searchindex) && $searchindex!='Books') {
+    // HST did this
+    // Used to be in $parameters init above, but
+    // that caused an error:
+    // If idType equals ASIN, SearchIndex cannot be present
+    //'SearchIndex'     =>$searchindex      ,  //Books for example.
+    $parameters['SearchIndex']=$searchindex;
+  }
+  $xml=doAmazonRequest($Aserver[$locale]['ext'],$parameters,3,'i');  // may throw exception
+  set_error_handler(function () {
+      global $output;
+      file_put_contents('/var/ywww/debug/phpDebug',
+			"Caught one?: ".$searchparameterdata,
+			FILE_APPEND);
+      file_put_contents('/var/ywww/debug/phpDebug',
+			print_r($output, TRUE)."\n",
+			FILE_APPEND);
+    } );
+  $review = $xml->Items->Item->CustomerReviews->IFrameURL;
+  restore_error_handler();
+  //echo $review;
+  if ($review != "")
+    {
+      $review1 = "";
+      $review2 = "";
+      $review3 = "";
+      $text = @file_get_contents($review . "&truncate=300");
+      $removeTop1 = preg_replace('~<div class="crIFrameHeaderLeftColumn">(.*?)<div class="crIFrameHeaderHistogram">~si', '', $text);
+      $removeTop2 = preg_replace('~<div class="crIFrameHeaderHistogram">(.*?)<div class="crIframeReviewList">~si', '', $text);
+      if (preg_match('~<body[^>]*>(.*?)</body>~si', $removeTop2, $body)){ $getBody = trim($body[1]); } else { $getBody = $removeTop2;}
+      $removeDiv = preg_replace('~<div[^>]*>(.*?)</div>~si', '', $getBody);
+      $removeCloseDivs = preg_replace('/<\/div>/','', $removeDiv);
+      $setBoundary = str_replace('<!-- BOUNDARY -->','BOTTOM-TOP', $removeCloseDivs);
+      //replace <!-- BOUNDARY --> with BOTTOM-TOP
+      $remove1 = '~<table cellpadding="0"(.*?)%">~s';
+      $setBoundary = preg_replace($remove1,'', $setBoundary);
+      $remove2 = '~</td><td bg(.*?)</table>~s';
+      $setBoundary = preg_replace($remove2,'', $setBoundary);
+      $remove3 = '~<a name=(.*?)</a>~s';
+      $setBoundary = preg_replace($remove3,'', $setBoundary);
+      $setBoundary2 = str_replace('<br />','', $setBoundary);
+      //remove all extra crap;
+      $setBoundary3 = str_replace('</td>','BOTTOM', $setBoundary2);
+      //replace </td> with BOTTOM
+		
+      if (preg_match_all('~TOP(.*?)BOTTOM~s', $setBoundary3, $reviews))
+	{ 
+	  $reviewContents = $reviews[1];
+	  //print_r($reviewContents);
+	  $review1 = trim($reviewContents[0]);
+	  $review1 = str_replace("\n", "", $review1);
+	  $review1 = str_replace("\r", "", $review1);
+	  if (isset($reviewContents[1])) {
+	    $review2 = trim($reviewContents[1]);
+	    $review2 = str_replace("\n", "", $review2);
+	    $review2 = str_replace("\r", "", $review2);
+	  }
+	  else {
+	    $review2 = "";
+	  }
+	  if (isset($reviewContents[2])) {
+	    $review3 = trim($reviewContents[2]);
+	    $review3 = str_replace("\n", "", $review3);
+	    $review3 = str_replace("\r", "", $review3);
+	  }
+	  else {
+	    $review3 = "";
+	  }
+	}
+      else
+	{
+	  $review1 = "";
+	  $review2 = "";
+	  $review3 = "";
+	  //echo "EPIC FAIL";
+	}
+
+      unset($xml->Items->Item->CustomerReviews);
+      $xdoc = new DomDocument;
+      $xdoc->loadXML($xml->asXML());
+		
+      $cReviews = $xdoc ->createElement('CustomerReviews');
+      $cReviewHolder = $xdoc ->createElement('Review');
+      $cReview = $xdoc ->createElement('Content');
+      $cReviewHolder2 = $xdoc ->createElement('Review');
+      $cReview2 = $xdoc ->createElement('Content');	
+      $cReviewHolder3 = $xdoc ->createElement('Review');
+      $cReview3 = $xdoc ->createElement('Content');
+		
+      $txtNode = $xdoc ->createTextNode ($review1);
+      $cReview -> appendChild($txtNode);
+		
+      $txtNode2 = $xdoc ->createTextNode ($review2);
+      $cReview2 -> appendChild($txtNode2);
+		
+      $txtNode3 = $xdoc ->createTextNode ($review3);
+      $cReview3 -> appendChild($txtNode3);
+		
+      $cReviewHolder -> appendChild($cReview);
+      $cReviewHolder2 -> appendChild($cReview2);
+      $cReviewHolder3 -> appendChild($cReview3);
+		
+      $cReviews -> appendChild($cReviewHolder);
+      $cReviews -> appendChild($cReviewHolder2);
+      $cReviews -> appendChild($cReviewHolder3);
+		
+      $xdoc->documentElement->childNodes->item(1)->childNodes->item(1)->appendChild($cReviews);
+      $newXML = simplexml_import_dom($xdoc);
+      $output = $newXML->asXml();
+    }
+	
+  if($go == 1) {
+    $item = $xml->Items->Item[0];
+    if ($item && $item->ItemAttributes && $item->ItemAttributes->Title) {
+      $title = $item->ItemAttributes->Title; }
+    else { $title = "[no title]"; };
+    file_put_contents('/var/ywww/debug/phpDebug',"win: $title\n",
+		      FILE_APPEND);
+    return $output;
+  }
+  else {
+    if ($xml->Items->Item) {
+      $title = $xml->Items->Item[0]->ItemAttributes->Title;
+      $author = $xml->Items->Item[0]->ItemAttributes->Author;
+      $binding = $xml->Items->Item[0]->ItemAttributes->Binding;
+      $dewey = $xml->Items->Item[0]->ItemAttributes->DeweyDecimalNumber;
+      if($dewey == "")
+	$dewey = "null";
+      $imageURL = $xml->Items->Item[0]->MediumImage->URL;
+      $salesRank = $xml->Items->Item[0]->SalesRank;
+      $pubDate = $xml->Items->Item[0]->ItemAttributes->PublicationDate;
+      if (strlen($pubDate)==4) { $pubDate=$pubDate."-01-01";}
+      if (strlen($pubDate)==7) { $pubDate=$pubDate."-01";}
+      if (strlen($pubDate)==0) {
+	$pubDate="null";
+      }
+      else {
+	$pubDate="\"$pubDate\"";
+      }
+      $publisher = $xml->Items->Item[0]->ItemAttributes->Publisher;
+    }
+    else {
+      $title = $salesRank = "";
+      $dewey = "null";
+    }
+			
+    $genreID = "";
+    $genre = "";		
+    $genArr = array();
+
+    if ($xml->Items->Item[0] && $xml->Items->Item[0]->BrowseNodes) {
+      for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){	
+	//sexy recursive function
+	findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
+				
+	if($genre != "")
+	  $genArr[strval($genreID)] = strval($genre);
+	//$genArr[$i] = array(strval($genreID) => strval($genre));
+
+	//echo $genre;
+	//echo $genreID;
+				
+	$genre = "";
+	$genreID = "";
+      }
+    }
+			
+    $g1 = "null";
+    $g2 = "null";
+    $g3 = "null";
+    $loop = 1;
+			
+    foreach ($genArr as $key => $value) {
+      //echo "$key => $value";
+      if ($key>2047) {
+	//HST added
+	break;
+      }
+      $queryG = "CALL b_addBrowseNode($key,\"$value\")";	//add the name value pair for genre to new table	
+      //echo $queryG;
+      include "../../private/db.php";
+      $resG = mysqli_query($link, $queryG);
+      mysqli_close($link);
+				
+      switch ($loop) {
+      case 1:
+	$g1 = $key;
+	break;
+      case 2:
+	$g2 = $key;
+	break;
+      case 3:
+	$g3 = $key;
+	break;
+      }
+				
+      $loop++;
+    }
+			
+    if($salesRank == "")
+      $salesRank = "null";
+			
+    if($title != "")
+      {
+	include "../../private/db.php";
+	if ($publisher->count()==0) {
+	  $publisher="null";
+	}
+	else {
+	  $publisher=mysqli_real_escape_string($link,$publisher);
+	  if (strlen($publisher)>30) {
+	    $publisher=rtrim(substr($publisher,0,30),"\\");
+	  }
+	  $publisher="\"".$publisher."\"";
+	}
+	if ($author->count()==0) {
+	  $author="unknown";
+	}
+	else {
+	  $author=mysqli_real_escape_string($link,$author);
+	  if (strlen($author)>30) {
+	    $author=rtrim(substr($author,0,30),"\\");
+	  }
+	}
+	$author="\"".$author."\"";
+	$title=mysqli_real_escape_string($link,$title);
+	if (strlen($title)>100) {
+	  $title=rtrim(substr($title,0,100),"\\");
+	}
+	$title="\"".$title."\"";
+	$review1 = mysqli_real_escape_string($link,$review1);
+	if (strlen($review1)>500) { $review1=rtrim(substr($review1,0,500),"\\");}
+	$review2 = mysqli_real_escape_string($link,$review2);
+	if (strlen($review2)>500) { $review2=rtrim(substr($review2,0,500),"\\");}
+	$review3 = mysqli_real_escape_string($link,$review3);
+	if (strlen($review3)>500) { $review3=rtrim(substr($review3,0,500),"\\");}
+			
+	$queryInsert = "CALL b_addNewBook(\"$searchparameterdata\",$title, $author,\"$binding\",\"$imageURL\", $dewey, $salesRank,$pubDate,$publisher,$g1,$g2,$g3,$loc)";	             
+	//echo $queryInsert;
+				
+	$res = mysqli_query($link, $queryInsert);
+	if (!$res) {
+	  $err=mysqli_error( $link );
+	  mysqli_close($link);
+	  file_put_contents('/var/ywww/debug/phpDebug',
+			    "anb failed: $queryInsert\n$err\n",
+			    FILE_APPEND);
+	  exit($err);
+	}
+	$queryInsertReviews = "CALL b_insertReviews(\"$searchparameterdata\",\"$review1\",\"$review2\",\"$review3\")";
+	if($review1 != "") {
+	  $res = mysqli_query($link, $queryInsertReviews);
+	  if (!$res) {
+	    $err=mysqli_error( $link );
+	    mysqli_close($link);
+	    file_put_contents('/var/ywww/debug/phpDebug',
+			      "anr failed: $queryInsertReviews\n",
+			      FILE_APPEND);
+	    exit($err);
+	  }
+	}
+	mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop		
+      }
+
+    echo $output;
+  }
+}
+
+function getAmazonDetLocal($go,$language,$loc,
+			   $page,$operation,$searchparameter,
+			   $searchparameterdata,
+			   $show_array,$show_url,$show_xml)
+{
+  global $output;
+  //look up info from db	
+  include "../../private/db.php"; 
+  $query = "CALL b_getBookInfo('$searchparameterdata', $loc)";
+  //echo $query;
+  $res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
+	
+  $output = "";
+  $output .=  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+  $output .=  "<Details>";
+  if ( mysqli_num_rows( $res ) > 0 )
+    {
+      $rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
+      mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop						
+      $output .=  "<ASIN>" . $searchparameterdata . "</ASIN>";
+      $output .=  "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>";			
+      $output .=  "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>";
+      $output .=  "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>";
+      $output .=  "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>";
+      $output .=  "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>";
+      $output .=  "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>";
+      $output .=  "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>";
+      $output .=  "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>";
+      $output .=  "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>";
+      $output .=  "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>";
+      $output .=  "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>";
+      $output .=  "<ProductGroup>Book</ProductGroup>";
+      $output .=  "<Error>AccountLimitExceeded</Error>";
+			
+    }
+  else {
+    mysqli_close($link);	//do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
+  }
+  $output .=  "</Details>";
+  echo $output;
+}
+
+function findGenre($browseNode, &$ID, &$gen)
+{
+	if($browseNode->Name == "Subjects")
+	{
+		 return true;		 
+	}
+	else
+	{
+		if($browseNode->Ancestors->BrowseNode)
+		{
+			if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true)
+			{
+				$gen = $browseNode->Name;
+				$ID = $browseNode->BrowseNodeId;
+			}		
+		}
+		return false;		
+	}
+}
+
+if(!isset($ret))
+{
+	include "aws_signed_request.php";
+	getAmazonDet('default',0,'us');	//will get overwritten from URI params
+	// by the foreach ($Adefault as ... loop above
+}
+/*Caught oneSimpleXMLElement Object
+(
+    [OperationRequest] => SimpleXMLElement Object
+        (
+            [RequestId] => d2eaacba-2411-44e7-b268-f23a20167330
+            [Arguments] => SimpleXMLElement Object
+                (
+                    [Argument] => Array
+                        (
+                            [0] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => AWSAccessKeyId
+                                            [Value] => AKIAIHTNWC7L6LOUY4LQ 
+                                        )
+
+                                )
+
+                            [1] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => AssociateTag
+                                            [Value] => bookwhack-21
+                                        )
+
+                                )
+
+                            [2] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => ItemId
+                                            [Value] => B004Q3Q3Y4
+                                        )
+
+                                )
+
+                            [3] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => ItemPage
+                                            [Value] => 1
+                                        )
+
+                                )
+
+                            [4] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => Operation
+                                            [Value] => ItemLookup
+                                        )
+
+                                )
+
+                            [5] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => ResponseGroup
+                                            [Value] => ItemAttributes,Reviews,EditorialReview,OfferSummary,Offers,Images,AlternateVersions,SalesRank,BrowseNodes
+                                        )
+
+                                )
+
+                            [6] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => ReviewSort
+                                            [Value] => -HelpfulVotes
+                                        )
+
+                                )
+
+                            [7] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => Service
+                                            [Value] => AWSECommerceService
+                                        )
+
+                                )
+
+                            [8] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => Timestamp
+                                            [Value] => 2016-12-15T23:12:34Z
+                                        )
+
+                                )
+
+                            [9] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => Version
+                                            [Value] => 2011-08-01
+                                        )
+
+                                )
+
+                            [10] => SimpleXMLElement Object
+                                (
+                                    [@attributes] => Array
+                                        (
+                                            [Name] => Signature
+                                            [Value] => SUXfFZHQ74Joc+WDLx87uzemTdtHijNohykqafJXYKQ=
+                                        )
+
+                                )
+
+                        )
+
+                )
+
+            [RequestProcessingTime] => 0.3518217620000000
+        )
+
+    [Items] => SimpleXMLElement Object
+        (
+            [Request] => SimpleXMLElement Object
+                (
+                    [IsValid] => True
+                    [ItemLookupRequest] => SimpleXMLElement Object
+                        (
+                            [IdType] => ASIN
+                            [ItemId] => B004Q3Q3Y4
+                            [ResponseGroup] => Array
+                                (
+                                    [0] => ItemAttributes
+                                    [1] => Reviews
+                                    [2] => EditorialReview
+                                    [3] => OfferSummary
+                                    [4] => Offers
+                                    [5] => Images
+                                    [6] => AlternateVersions
+                                    [7] => SalesRank
+                                    [8] => BrowseNodes
+                                )
+
+                            [VariationPage] => All
+                        )
+
+                    [Errors] => SimpleXMLElement Object
+                        (
+                            [Error] => SimpleXMLElement Object
+                                (
+                                    [Code] => AWS.InvalidParameterValue
+                                    [Message] => B004Q3Q3Y4 is not a valid value for ItemId. Please change this value and retry your request.
+                                )
+
+                        )
+
+                )
+
+        )
+
+)
+*/
+	/*$xml = new SimpleXMLElement("<?xml version=\"1.0\"?><ItemLookupErrorResponse xmlns=\"http://ecs.amazonaws.com/doc/2009-03-31/\"><Error><Code>AccountLimitExceeded</Code><Message>Account limit of 2056 requests per hour exceeded.</Message></Error><RequestID>290ed059-730c-4789-93b4-6d21e11053d3</RequestID></ItemLookupErrorResponse>");*/
+?>