Mercurial > hg > ywww
annotate php/read/getBookDetails.php @ 15:385ddd7c4b55 testing
use test_db.php to get mysqld_test instance
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Sun, 19 Feb 2017 16:17:53 +0000 |
| parents | 5aa24c984a3b |
| children |
| rev | line source |
|---|---|
| 2 | 1 <?php |
| 2 | |
| 3 function findGenre($browseNode, &$ID, &$gen) | |
| 4 { | |
| 5 if($browseNode->Name == "Subjects") | |
| 6 { | |
| 7 return true; | |
| 8 } | |
| 9 else | |
| 10 { | |
| 11 if($browseNode->Ancestors->BrowseNode) | |
| 12 { | |
| 13 if(findGenre($browseNode->Ancestors->BrowseNode, $ID, $gen) == true) | |
| 14 { | |
| 15 $gen = $browseNode->Name; | |
| 16 $ID = $browseNode->BrowseNodeId; | |
| 17 | |
| 18 //if($browseNode->Name == "Literature & Fiction") //to return one level up the tree as well | |
| 19 // return true; | |
| 20 } | |
| 21 } | |
| 22 return false; | |
| 23 } | |
| 24 } | |
| 25 | |
| 3 | 26 global $out,$isbn; |
| 2 | 27 if(isset($_GET['isbn'])){ |
| 28 $isbn = $_GET['isbn']; | |
| 29 if(isset($_GET['locale'])){ | |
| 30 $locale=$_GET['locale']; | |
| 31 | |
| 32 switch ($locale) { | |
| 33 case "uk": | |
| 34 $loc = 1; | |
| 35 break; | |
| 36 case "us": | |
| 37 $loc = 0; | |
| 38 break; | |
| 39 case "ca": | |
| 40 $loc = 2; | |
| 41 break; | |
| 42 case "de": | |
| 43 $loc = 3; | |
| 44 break; | |
| 45 case "fr": | |
| 46 $loc = 4; | |
| 47 break; | |
| 48 case "": | |
| 49 $loc = 0; | |
| 50 break; | |
| 51 } | |
| 52 } | |
| 53 else{ | |
| 54 $loc=0; | |
| 55 } | |
| 56 $output = ""; | |
| 57 | |
| 58 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | |
| 59 $output .= "<BookDetails>"; | |
| 60 | |
| 61 $proceed = true; | |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
62 include "../../../../private/db_test.php"; |
| 2 | 63 |
| 64 $query = "CALL b_getBookInfo('$isbn', $loc)"; | |
| 65 //select Timestamp,Title,Author,Binding,DeweyDecimal,ImageURL,SalesRank,PublicationDate,Publisher,Genre1,Genre2,Genre3 from books where ISBN = '$isbn'"; | |
| 66 //echo $query; | |
| 67 $res = mysqli_query($link, $query) or exit( mysqli_error( $link )); | |
| 68 | |
| 69 if ( mysqli_num_rows( $res ) > 0 ) | |
| 70 { | |
| 71 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC); | |
| 72 $timestamp=$rows['Timestamp']; | |
| 73 //echo $timestamp; | |
| 74 date_default_timezone_set('UTC'); | |
| 75 $dbStamp = strtotime($timestamp); | |
| 76 //echo $dbStamp; | |
| 77 $unixTime = time(); | |
| 78 //echo $unixTime; | |
| 79 $timeDiff = $unixTime - $dbStamp; | |
| 80 //echo $timeDiff; | |
| 81 | |
| 82 if($timeDiff < 2592000) //if it has been updated in the last 30 days | |
| 83 { | |
| 84 $proceed = false; | |
| 85 $output .= "<ISBN>" . $isbn . "</ISBN>"; | |
| 86 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>"; | |
| 87 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>"; | |
| 88 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>"; | |
| 89 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>"; | |
| 90 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>"; | |
| 91 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>"; | |
| 92 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>"; | |
| 93 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>"; | |
| 94 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>"; | |
| 95 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>"; | |
| 96 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>"; | |
| 97 $output .= "<ProductGroup>Book</ProductGroup>"; | |
| 98 } | |
| 99 } | |
| 100 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop | |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
101 include "../../../../private/db_test.php"; |
| 2 | 102 |
| 103 if($proceed == true) | |
| 104 { | |
| 105 include "aws_signed_request.php"; | |
| 106 //book does not exist already so look up all the info from browse nodes.... | |
| 107 | |
| 108 $Adefault=array( | |
| 109 'language' =>'en', //what language to render the page in | |
| 110 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us | |
| 111 'page' =>1, //first page to show (we are counting from 1 not 0) | |
| 112 'operation' =>'ItemLookup', //what to do? //ItemSearch | |
| 113 'searchparameter' =>'ItemId', //what kind of search? | |
| 114 'searchindex' => 'Books', | |
| 115 'searchparameterdata'=>$isbn, //what to search for? | |
| 116 'search' =>$isbn, | |
| 117 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true' | |
| 118 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending | |
| 119 'show_url' =>false, //debug: show XML request url to be send to Amazon? | |
| 120 'show_xml' =>false, //debug: show incoming XML code from Amazon? | |
| 121 ); | |
| 122 //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 | |
| 123 | |
| 124 $Aassociates_id=array( | |
| 125 'uk' => 'bookwhack-21', | |
| 126 'us' => 'your02b-20', | |
| 127 'ca' => 'book009-20', | |
| 128 'de' => 'book04c-21', | |
| 129 'fr' => 'book07f-21', | |
| 130 ); | |
| 131 | |
| 132 $Aserver=array( | |
| 133 'ca' => array( | |
| 134 'ext' => 'ca' , //Canadian normal server | |
| 135 'nor' => 'http://www.amazon.ca' , //Canadian normal server | |
| 136 'xml' => 'http://xml.amazon.com' , //Canadian xml server | |
| 137 ), | |
| 138 'de' => array( | |
| 139 'ext' => 'de' , //German normal server | |
| 140 'nor' => 'http://www.amazon.de' , //German normal server | |
| 141 'xml' => 'http://xml-eu.amazon.com', //German xml server | |
| 142 ), | |
| 143 'fr' => array( | |
| 144 'ext' => 'fr' , //French normal server | |
| 145 'nor' => 'http://www.amazon.fr' , //French normal server | |
| 146 'xml' => 'http://xml-eu.amazon.com', //French xml server | |
| 147 ), | |
| 148 'jp' => array( | |
| 149 'ext' => 'jp' , //Japanese normal server, not co.jp! | |
| 150 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server | |
| 151 'xml' => 'http://xml.amazon.com' , //Japanese xml server | |
| 152 ), | |
| 153 'uk' => array( | |
| 154 'ext' => 'co.uk' , //UK normal server | |
| 155 'nor' => 'http://www.amazon.co.uk' , //UK normal server | |
| 156 'xml' => 'http://xml-eu.amazon.com', //UK xml server | |
| 157 ), | |
| 158 'us' => array( | |
| 159 'ext' => 'com' , //USA normal server | |
| 160 'nor' => 'http://www.amazon.com' , //USA normal server | |
| 161 'xml' => 'http://xml.amazon.com' , //USA xml server | |
| 162 ), | |
| 163 ); | |
| 164 | |
| 165 $public_key ="AKIAJBXEHTNCU6LLFNIA"; | |
| 166 $private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA"; | |
| 167 | |
| 168 //for all parameters see if the user has overruled it or use the default | |
| 169 foreach ($Adefault as $i=>$d) { | |
| 170 $$i=isset($_GET[$i])?$_GET[$i]:$d; | |
| 171 } | |
| 172 | |
| 173 $parameters=array( | |
| 174 'Operation' =>$operation , | |
| 175 'Keywords' =>urlencode($search) , | |
| 176 "$searchparameter"=>$searchparameterdata , | |
| 177 'ItemPage' =>$page , //which page? | |
| 178 'AssociateTag' =>$Aassociates_id[$locale], | |
| 179 'ResponseGroup' =>'ItemAttributes,Images,SalesRank,BrowseNodes' | |
| 180 ); | |
| 181 | |
| 3 | 182 if ($searchindex!='Books') { |
| 183 // HST did this | |
| 184 // Used to be in $parameters init above, but | |
| 185 // that caused an error: | |
| 186 // If idType equals ASIN, SearchIndex cannot be present | |
| 187 //'SearchIndex' =>$searchindex , //Books for example. | |
| 188 $parameters['SearchIndex']=$searchindex; | |
| 189 } | |
| 190 | |
| 191 | |
| 2 | 192 $ext=$Aserver[$locale]['ext']; |
| 193 $file_data=$ext; | |
| 194 ksort($parameters); | |
| 195 foreach ($parameters as $i=>$d) { | |
| 196 $file_data.='&'.$i.'='.$d; | |
| 197 } | |
| 198 | |
| 199 $url=aws_signed_request($ext,$parameters,$public_key,$private_key); | |
| 200 //echo $url; | |
| 201 | |
| 202 $crl = curl_init(); | |
| 203 $timeout = 5; | |
| 204 curl_setopt ($crl, CURLOPT_URL,$url); | |
| 205 curl_setopt ($crl, CURLOPT_ENCODING , "gzip"); | |
| 206 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); | |
| 207 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); | |
| 208 $out = curl_exec($crl); | |
| 209 curl_close($crl); | |
| 210 | |
| 211 //echo $out; | |
| 212 | |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
213 if (preg_match("<Error>",$out)) { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
214 $xml = new SimpleXMLElement($out); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
215 $resName=$xml->getName(); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
216 $code=$xml->Error->Code; |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
217 file_put_contents('/var/test/ywww/debug/testDebug',"Losing gBD: $resName, $code\n",FILE_APPEND); |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
218 if ($code=='RequestThrottled') { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
219 usleep(200000); // Try to reduce throttling until we get a |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
220 // principled solution in place |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
221 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
222 else { |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
223 file_put_contents('/var/test/ywww/debug/testDebug',"parms bd: ". |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
224 print_r($parameters,TRUE)."\n",FILE_APPEND); |
|
10
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
225 if ($code=="") { |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
226 file_put_contents('/var/test/ywww/debug/testDebug',"error elt:\n$out\n",FILE_APPEND); |
|
10
5aa24c984a3b
if no code show entire response
Henry S. Thompson <ht@markup.co.uk>
parents:
9
diff
changeset
|
227 } |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
228 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
229 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
230 else { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
231 $xml = new SimpleXMLElement($out); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
232 //use this xml to pull out the necessary information and save it |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
233 set_error_handler(function () { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
234 global $out,$isbn; |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
235 file_put_contents('/var/test/ywww/debug/testDebug', |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
236 "Caught one bd: ".$isbn, |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
237 FILE_APPEND); |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
238 file_put_contents('/var/test/ywww/debug/testDebug', |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
239 print_r($out, TRUE)."\n", |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
240 FILE_APPEND); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
241 } ); |
| 2 | 242 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
243 $title=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
244 $author=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
245 $binding=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
246 $dewey=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
247 $imageURL=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
248 $salesRank=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
249 $pubDate=""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
250 $publisher=""; |
| 2 | 251 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
252 $title = $xml->Items->Item->ItemAttributes->Title; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
253 $author = $xml->Items->Item->ItemAttributes->Author; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
254 $binding = $xml->Items->Item->ItemAttributes->Binding; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
255 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
256 if($dewey == "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
257 $dewey = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
258 $imageURL = $xml->Items->Item->MediumImage->URL; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
259 $salesRank = $xml->Items->Item->SalesRank; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
260 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
261 $publisher = $xml->Items->Item->ItemAttributes->Publisher; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
262 restore_error_handler(); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
263 /*echo $title; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
264 echo $author; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
265 echo $binding; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
266 echo $dewey; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
267 echo $imageURL; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
268 echo $salesRank; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
269 echo $pubDate; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
270 echo $publisher;*/ |
| 2 | 271 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
272 $genreID = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
273 $genre = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
274 $genArr = array(); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
275 $g1 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
276 $g2 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
277 $g3 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
278 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){ |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
279 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){ |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
280 //sexy recursive function |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
281 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre); |
| 2 | 282 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
283 if($genre != "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
284 $genArr[strval($genreID)] = strval($genre); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
285 //$genArr[$i] = array(strval($genreID) => strval($genre)); |
| 2 | 286 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
287 //echo $genre; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
288 //echo $genreID; |
| 2 | 289 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
290 $genre = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
291 $genreID = ""; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
292 } |
| 2 | 293 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
294 $g1 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
295 $g2 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
296 $g3 = "null"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
297 $loop = 1; |
| 2 | 298 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
299 foreach ($genArr as $key => $value) { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
300 //echo "$key => $value"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
301 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
302 //echo $queryG; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
303 $resG = mysqli_query($link, $queryG); |
| 2 | 304 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
305 switch ($loop) { |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
306 case 1: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
307 $g1 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
308 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
309 case 2: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
310 $g2 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
311 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
312 case 3: |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
313 $g3 = $key; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
314 break; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
315 } |
| 2 | 316 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
317 $loop++; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
318 } |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
319 } |
| 2 | 320 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
321 if($salesRank == "") |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
322 $salesRank = "null"; |
| 2 | 323 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
324 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
|
15
385ddd7c4b55
use test_db.php to get mysqld_test instance
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
10
diff
changeset
|
325 include "../../../../private/db_test.php"; |
| 2 | 326 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
327 $title = strtr($title, '"', "'"); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
328 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
329 //echo $queryInsert; |
| 2 | 330 |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
331 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link )); |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
332 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop |
| 2 | 333 |
| 334 | |
|
9
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
335 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
336 $output .= "<Title>" . htmlspecialchars($title) . "</Title>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
337 $output .= "<Author>" . htmlspecialchars($author) . "</Author>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
338 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
339 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
340 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
341 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
342 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
343 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
344 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
345 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
346 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>"; |
|
232deb0b066a
tidy up debugging, only show parms on non-throttled error
Henry S. Thompson <ht@markup.co.uk>
parents:
6
diff
changeset
|
347 $output .= "<ProductGroup>Book</ProductGroup>"; |
|
6
077b0a0a3e6d
remaining originals according to dependency walk
Robert Boland <robert@markup.co.uk>
parents:
3
diff
changeset
|
348 } |
| 2 | 349 } |
| 350 | |
| 351 $output .= "</BookDetails>"; | |
| 352 | |
| 353 echo $output; | |
| 354 } | |
| 355 ?> |
