annotate php/read/getBookDetails.php @ 36:e570b199108b

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