annotate php/read/getBookDetails.php @ 2:45ae2aeb2b52

original
author robert
date Wed, 28 Dec 2016 12:44:57 +0000
parents
children a5e5475bf357
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
45ae2aeb2b52 original
robert
parents:
diff changeset
26 if(isset($_GET['isbn'])){
45ae2aeb2b52 original
robert
parents:
diff changeset
27 $isbn = $_GET['isbn'];
45ae2aeb2b52 original
robert
parents:
diff changeset
28 if(isset($_GET['locale'])){
45ae2aeb2b52 original
robert
parents:
diff changeset
29 $locale=$_GET['locale'];
45ae2aeb2b52 original
robert
parents:
diff changeset
30
45ae2aeb2b52 original
robert
parents:
diff changeset
31 switch ($locale) {
45ae2aeb2b52 original
robert
parents:
diff changeset
32 case "uk":
45ae2aeb2b52 original
robert
parents:
diff changeset
33 $loc = 1;
45ae2aeb2b52 original
robert
parents:
diff changeset
34 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
35 case "us":
45ae2aeb2b52 original
robert
parents:
diff changeset
36 $loc = 0;
45ae2aeb2b52 original
robert
parents:
diff changeset
37 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
38 case "ca":
45ae2aeb2b52 original
robert
parents:
diff changeset
39 $loc = 2;
45ae2aeb2b52 original
robert
parents:
diff changeset
40 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
41 case "de":
45ae2aeb2b52 original
robert
parents:
diff changeset
42 $loc = 3;
45ae2aeb2b52 original
robert
parents:
diff changeset
43 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
44 case "fr":
45ae2aeb2b52 original
robert
parents:
diff changeset
45 $loc = 4;
45ae2aeb2b52 original
robert
parents:
diff changeset
46 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
47 case "":
45ae2aeb2b52 original
robert
parents:
diff changeset
48 $loc = 0;
45ae2aeb2b52 original
robert
parents:
diff changeset
49 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
50 }
45ae2aeb2b52 original
robert
parents:
diff changeset
51 }
45ae2aeb2b52 original
robert
parents:
diff changeset
52 else{
45ae2aeb2b52 original
robert
parents:
diff changeset
53 $loc=0;
45ae2aeb2b52 original
robert
parents:
diff changeset
54 }
45ae2aeb2b52 original
robert
parents:
diff changeset
55 $output = "";
45ae2aeb2b52 original
robert
parents:
diff changeset
56
45ae2aeb2b52 original
robert
parents:
diff changeset
57 $output .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
45ae2aeb2b52 original
robert
parents:
diff changeset
58 $output .= "<BookDetails>";
45ae2aeb2b52 original
robert
parents:
diff changeset
59
45ae2aeb2b52 original
robert
parents:
diff changeset
60 $proceed = true;
45ae2aeb2b52 original
robert
parents:
diff changeset
61 include "../../../private/db.php";
45ae2aeb2b52 original
robert
parents:
diff changeset
62
45ae2aeb2b52 original
robert
parents:
diff changeset
63 $query = "CALL b_getBookInfo('$isbn', $loc)";
45ae2aeb2b52 original
robert
parents:
diff changeset
64 //select Timestamp,Title,Author,Binding,DeweyDecimal,ImageURL,SalesRank,PublicationDate,Publisher,Genre1,Genre2,Genre3 from books where ISBN = '$isbn'";
45ae2aeb2b52 original
robert
parents:
diff changeset
65 //echo $query;
45ae2aeb2b52 original
robert
parents:
diff changeset
66 $res = mysqli_query($link, $query) or exit( mysqli_error( $link ));
45ae2aeb2b52 original
robert
parents:
diff changeset
67
45ae2aeb2b52 original
robert
parents:
diff changeset
68 if ( mysqli_num_rows( $res ) > 0 )
45ae2aeb2b52 original
robert
parents:
diff changeset
69 {
45ae2aeb2b52 original
robert
parents:
diff changeset
70 $rows=mysqli_fetch_array($res, MYSQLI_ASSOC);
45ae2aeb2b52 original
robert
parents:
diff changeset
71 $timestamp=$rows['Timestamp'];
45ae2aeb2b52 original
robert
parents:
diff changeset
72 //echo $timestamp;
45ae2aeb2b52 original
robert
parents:
diff changeset
73 date_default_timezone_set('UTC');
45ae2aeb2b52 original
robert
parents:
diff changeset
74 $dbStamp = strtotime($timestamp);
45ae2aeb2b52 original
robert
parents:
diff changeset
75 //echo $dbStamp;
45ae2aeb2b52 original
robert
parents:
diff changeset
76 $unixTime = time();
45ae2aeb2b52 original
robert
parents:
diff changeset
77 //echo $unixTime;
45ae2aeb2b52 original
robert
parents:
diff changeset
78 $timeDiff = $unixTime - $dbStamp;
45ae2aeb2b52 original
robert
parents:
diff changeset
79 //echo $timeDiff;
45ae2aeb2b52 original
robert
parents:
diff changeset
80
45ae2aeb2b52 original
robert
parents:
diff changeset
81 if($timeDiff < 2592000) //if it has been updated in the last 30 days
45ae2aeb2b52 original
robert
parents:
diff changeset
82 {
45ae2aeb2b52 original
robert
parents:
diff changeset
83 $proceed = false;
45ae2aeb2b52 original
robert
parents:
diff changeset
84 $output .= "<ISBN>" . $isbn . "</ISBN>";
45ae2aeb2b52 original
robert
parents:
diff changeset
85 $output .= "<Title>" . htmlspecialchars($rows["Title"]) . "</Title>";
45ae2aeb2b52 original
robert
parents:
diff changeset
86 $output .= "<Author>" . htmlspecialchars($rows["Author"]) . "</Author>";
45ae2aeb2b52 original
robert
parents:
diff changeset
87 $output .= "<Binding>" . htmlspecialchars($rows["Binding"]) . "</Binding>";
45ae2aeb2b52 original
robert
parents:
diff changeset
88 $output .= "<Dewey>" . htmlspecialchars($rows["DeweyDecimal"]) . "</Dewey>";
45ae2aeb2b52 original
robert
parents:
diff changeset
89 $output .= "<ImageURL>" . htmlspecialchars($rows["ImageURL"]) . "</ImageURL>";
45ae2aeb2b52 original
robert
parents:
diff changeset
90 $output .= "<SalesRank>" . htmlspecialchars($rows["SalesRank"]) . "</SalesRank>";
45ae2aeb2b52 original
robert
parents:
diff changeset
91 $output .= "<PublicationDate>" . htmlspecialchars($rows["PublicationDate"]) . "</PublicationDate>";
45ae2aeb2b52 original
robert
parents:
diff changeset
92 $output .= "<Publisher>" . htmlspecialchars($rows["Publisher"]) . "</Publisher>";
45ae2aeb2b52 original
robert
parents:
diff changeset
93 $output .= "<Genre1>" . htmlspecialchars($rows["Genre1"]) . "</Genre1>";
45ae2aeb2b52 original
robert
parents:
diff changeset
94 $output .= "<Genre2>" . htmlspecialchars($rows["Genre2"]) . "</Genre2>";
45ae2aeb2b52 original
robert
parents:
diff changeset
95 $output .= "<Genre3>" . htmlspecialchars($rows["Genre3"]) . "</Genre3>";
45ae2aeb2b52 original
robert
parents:
diff changeset
96 $output .= "<ProductGroup>Book</ProductGroup>";
45ae2aeb2b52 original
robert
parents:
diff changeset
97 }
45ae2aeb2b52 original
robert
parents:
diff changeset
98 }
45ae2aeb2b52 original
robert
parents:
diff changeset
99 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
45ae2aeb2b52 original
robert
parents:
diff changeset
100 include "../../../private/db.php";
45ae2aeb2b52 original
robert
parents:
diff changeset
101
45ae2aeb2b52 original
robert
parents:
diff changeset
102 if($proceed == true)
45ae2aeb2b52 original
robert
parents:
diff changeset
103 {
45ae2aeb2b52 original
robert
parents:
diff changeset
104 include "aws_signed_request.php";
45ae2aeb2b52 original
robert
parents:
diff changeset
105 //book does not exist already so look up all the info from browse nodes....
45ae2aeb2b52 original
robert
parents:
diff changeset
106
45ae2aeb2b52 original
robert
parents:
diff changeset
107 $Adefault=array(
45ae2aeb2b52 original
robert
parents:
diff changeset
108 'language' =>'en', //what language to render the page in
45ae2aeb2b52 original
robert
parents:
diff changeset
109 'locale' =>'us', //which server's products? available: ca,de,fr,jp,uk,us
45ae2aeb2b52 original
robert
parents:
diff changeset
110 'page' =>1, //first page to show (we are counting from 1 not 0)
45ae2aeb2b52 original
robert
parents:
diff changeset
111 'operation' =>'ItemLookup', //what to do? //ItemSearch
45ae2aeb2b52 original
robert
parents:
diff changeset
112 'searchparameter' =>'ItemId', //what kind of search?
45ae2aeb2b52 original
robert
parents:
diff changeset
113 'searchindex' => 'Books',
45ae2aeb2b52 original
robert
parents:
diff changeset
114 'searchparameterdata'=>$isbn, //what to search for?
45ae2aeb2b52 original
robert
parents:
diff changeset
115 'search' =>$isbn,
45ae2aeb2b52 original
robert
parents:
diff changeset
116 //here some debugging flags you can put at the end of the URL to call this script with, like: '?show_array=true'
45ae2aeb2b52 original
robert
parents:
diff changeset
117 'show_array' =>false, //debug: show complete incoming array? You can use this to see what other information Amazon is sending
45ae2aeb2b52 original
robert
parents:
diff changeset
118 'show_url' =>false, //debug: show XML request url to be send to Amazon?
45ae2aeb2b52 original
robert
parents:
diff changeset
119 'show_xml' =>false, //debug: show incoming XML code from Amazon?
45ae2aeb2b52 original
robert
parents:
diff changeset
120 );
45ae2aeb2b52 original
robert
parents:
diff changeset
121 //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
45ae2aeb2b52 original
robert
parents:
diff changeset
122
45ae2aeb2b52 original
robert
parents:
diff changeset
123 $Aassociates_id=array(
45ae2aeb2b52 original
robert
parents:
diff changeset
124 'uk' => 'bookwhack-21',
45ae2aeb2b52 original
robert
parents:
diff changeset
125 'us' => 'your02b-20',
45ae2aeb2b52 original
robert
parents:
diff changeset
126 'ca' => 'book009-20',
45ae2aeb2b52 original
robert
parents:
diff changeset
127 'de' => 'book04c-21',
45ae2aeb2b52 original
robert
parents:
diff changeset
128 'fr' => 'book07f-21',
45ae2aeb2b52 original
robert
parents:
diff changeset
129 );
45ae2aeb2b52 original
robert
parents:
diff changeset
130
45ae2aeb2b52 original
robert
parents:
diff changeset
131 $Aserver=array(
45ae2aeb2b52 original
robert
parents:
diff changeset
132 'ca' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
133 'ext' => 'ca' , //Canadian normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
134 'nor' => 'http://www.amazon.ca' , //Canadian normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
135 'xml' => 'http://xml.amazon.com' , //Canadian xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
136 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
137 'de' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
138 'ext' => 'de' , //German normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
139 'nor' => 'http://www.amazon.de' , //German normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
140 'xml' => 'http://xml-eu.amazon.com', //German xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
141 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
142 'fr' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
143 'ext' => 'fr' , //French normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
144 'nor' => 'http://www.amazon.fr' , //French normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
145 'xml' => 'http://xml-eu.amazon.com', //French xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
146 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
147 'jp' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
148 'ext' => 'jp' , //Japanese normal server, not co.jp!
45ae2aeb2b52 original
robert
parents:
diff changeset
149 'nor' => 'http://www.amazon.co.jp' , //Japanese normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
150 'xml' => 'http://xml.amazon.com' , //Japanese xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
151 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
152 'uk' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
153 'ext' => 'co.uk' , //UK normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
154 'nor' => 'http://www.amazon.co.uk' , //UK normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
155 'xml' => 'http://xml-eu.amazon.com', //UK xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
156 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
157 'us' => array(
45ae2aeb2b52 original
robert
parents:
diff changeset
158 'ext' => 'com' , //USA normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
159 'nor' => 'http://www.amazon.com' , //USA normal server
45ae2aeb2b52 original
robert
parents:
diff changeset
160 'xml' => 'http://xml.amazon.com' , //USA xml server
45ae2aeb2b52 original
robert
parents:
diff changeset
161 ),
45ae2aeb2b52 original
robert
parents:
diff changeset
162 );
45ae2aeb2b52 original
robert
parents:
diff changeset
163
45ae2aeb2b52 original
robert
parents:
diff changeset
164 $public_key ="AKIAJBXEHTNCU6LLFNIA";
45ae2aeb2b52 original
robert
parents:
diff changeset
165 $private_key="Dgyv7aR6uGe3OtY95Dj6hHpDS/UEtyboMWpJchYA";
45ae2aeb2b52 original
robert
parents:
diff changeset
166
45ae2aeb2b52 original
robert
parents:
diff changeset
167 //for all parameters see if the user has overruled it or use the default
45ae2aeb2b52 original
robert
parents:
diff changeset
168 foreach ($Adefault as $i=>$d) {
45ae2aeb2b52 original
robert
parents:
diff changeset
169 $$i=isset($_GET[$i])?$_GET[$i]:$d;
45ae2aeb2b52 original
robert
parents:
diff changeset
170 }
45ae2aeb2b52 original
robert
parents:
diff changeset
171
45ae2aeb2b52 original
robert
parents:
diff changeset
172 $parameters=array(
45ae2aeb2b52 original
robert
parents:
diff changeset
173 'Operation' =>$operation ,
45ae2aeb2b52 original
robert
parents:
diff changeset
174 'Keywords' =>urlencode($search) ,
45ae2aeb2b52 original
robert
parents:
diff changeset
175 'SearchIndex' =>$searchindex , //Books for example.
45ae2aeb2b52 original
robert
parents:
diff changeset
176 "$searchparameter"=>$searchparameterdata ,
45ae2aeb2b52 original
robert
parents:
diff changeset
177 'ItemPage' =>$page , //which page?
45ae2aeb2b52 original
robert
parents:
diff changeset
178 'AssociateTag' =>$Aassociates_id[$locale],
45ae2aeb2b52 original
robert
parents:
diff changeset
179 'ResponseGroup' =>'ItemAttributes,Images,SalesRank,BrowseNodes'
45ae2aeb2b52 original
robert
parents:
diff changeset
180 );
45ae2aeb2b52 original
robert
parents:
diff changeset
181
45ae2aeb2b52 original
robert
parents:
diff changeset
182
45ae2aeb2b52 original
robert
parents:
diff changeset
183 $ext=$Aserver[$locale]['ext'];
45ae2aeb2b52 original
robert
parents:
diff changeset
184 $file_data=$ext;
45ae2aeb2b52 original
robert
parents:
diff changeset
185 ksort($parameters);
45ae2aeb2b52 original
robert
parents:
diff changeset
186 foreach ($parameters as $i=>$d) {
45ae2aeb2b52 original
robert
parents:
diff changeset
187 $file_data.='&'.$i.'='.$d;
45ae2aeb2b52 original
robert
parents:
diff changeset
188 }
45ae2aeb2b52 original
robert
parents:
diff changeset
189
45ae2aeb2b52 original
robert
parents:
diff changeset
190 $url=aws_signed_request($ext,$parameters,$public_key,$private_key);
45ae2aeb2b52 original
robert
parents:
diff changeset
191 //echo $url;
45ae2aeb2b52 original
robert
parents:
diff changeset
192
45ae2aeb2b52 original
robert
parents:
diff changeset
193 $crl = curl_init();
45ae2aeb2b52 original
robert
parents:
diff changeset
194 $timeout = 5;
45ae2aeb2b52 original
robert
parents:
diff changeset
195 curl_setopt ($crl, CURLOPT_URL,$url);
45ae2aeb2b52 original
robert
parents:
diff changeset
196 curl_setopt ($crl, CURLOPT_ENCODING , "gzip");
45ae2aeb2b52 original
robert
parents:
diff changeset
197 curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
45ae2aeb2b52 original
robert
parents:
diff changeset
198 curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
45ae2aeb2b52 original
robert
parents:
diff changeset
199 $out = curl_exec($crl);
45ae2aeb2b52 original
robert
parents:
diff changeset
200 curl_close($crl);
45ae2aeb2b52 original
robert
parents:
diff changeset
201
45ae2aeb2b52 original
robert
parents:
diff changeset
202 //echo $out;
45ae2aeb2b52 original
robert
parents:
diff changeset
203
45ae2aeb2b52 original
robert
parents:
diff changeset
204 $xml = new SimpleXMLElement($out);
45ae2aeb2b52 original
robert
parents:
diff changeset
205 //use this xml to pull out the necessary information and save it
45ae2aeb2b52 original
robert
parents:
diff changeset
206
45ae2aeb2b52 original
robert
parents:
diff changeset
207 $title="";
45ae2aeb2b52 original
robert
parents:
diff changeset
208 $author="";
45ae2aeb2b52 original
robert
parents:
diff changeset
209 $binding="";
45ae2aeb2b52 original
robert
parents:
diff changeset
210 $dewey="";
45ae2aeb2b52 original
robert
parents:
diff changeset
211 $imageURL="";
45ae2aeb2b52 original
robert
parents:
diff changeset
212 $salesRank="";
45ae2aeb2b52 original
robert
parents:
diff changeset
213 $pubDate="";
45ae2aeb2b52 original
robert
parents:
diff changeset
214 $publisher="";
45ae2aeb2b52 original
robert
parents:
diff changeset
215
45ae2aeb2b52 original
robert
parents:
diff changeset
216 $title = $xml->Items->Item->ItemAttributes->Title;
45ae2aeb2b52 original
robert
parents:
diff changeset
217 $author = $xml->Items->Item->ItemAttributes->Author;
45ae2aeb2b52 original
robert
parents:
diff changeset
218 $binding = $xml->Items->Item->ItemAttributes->Binding;
45ae2aeb2b52 original
robert
parents:
diff changeset
219 $dewey = $xml->Items->Item->ItemAttributes->DeweyDecimalNumber;
45ae2aeb2b52 original
robert
parents:
diff changeset
220 if($dewey == "")
45ae2aeb2b52 original
robert
parents:
diff changeset
221 $dewey = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
222 $imageURL = $xml->Items->Item->MediumImage->URL;
45ae2aeb2b52 original
robert
parents:
diff changeset
223 $salesRank = $xml->Items->Item->SalesRank;
45ae2aeb2b52 original
robert
parents:
diff changeset
224 $pubDate = $xml->Items->Item->ItemAttributes->PublicationDate;
45ae2aeb2b52 original
robert
parents:
diff changeset
225 $publisher = $xml->Items->Item->ItemAttributes->Publisher;
45ae2aeb2b52 original
robert
parents:
diff changeset
226
45ae2aeb2b52 original
robert
parents:
diff changeset
227 /*echo $title;
45ae2aeb2b52 original
robert
parents:
diff changeset
228 echo $author;
45ae2aeb2b52 original
robert
parents:
diff changeset
229 echo $binding;
45ae2aeb2b52 original
robert
parents:
diff changeset
230 echo $dewey;
45ae2aeb2b52 original
robert
parents:
diff changeset
231 echo $imageURL;
45ae2aeb2b52 original
robert
parents:
diff changeset
232 echo $salesRank;
45ae2aeb2b52 original
robert
parents:
diff changeset
233 echo $pubDate;
45ae2aeb2b52 original
robert
parents:
diff changeset
234 echo $publisher;*/
45ae2aeb2b52 original
robert
parents:
diff changeset
235
45ae2aeb2b52 original
robert
parents:
diff changeset
236 $genreID = "";
45ae2aeb2b52 original
robert
parents:
diff changeset
237 $genre = "";
45ae2aeb2b52 original
robert
parents:
diff changeset
238 $genArr = array();
45ae2aeb2b52 original
robert
parents:
diff changeset
239 $g1 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
240 $g2 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
241 $g3 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
242 if(isset($xml->Items->Item->BrowseNodes->BrowseNode)){
45ae2aeb2b52 original
robert
parents:
diff changeset
243 for($i=0;$i<sizeof($xml->Items->Item->BrowseNodes->BrowseNode);$i++){
45ae2aeb2b52 original
robert
parents:
diff changeset
244 //sexy recursive function
45ae2aeb2b52 original
robert
parents:
diff changeset
245 findGenre($xml->Items->Item->BrowseNodes->BrowseNode[$i], $genreID, $genre);
45ae2aeb2b52 original
robert
parents:
diff changeset
246
45ae2aeb2b52 original
robert
parents:
diff changeset
247 if($genre != "")
45ae2aeb2b52 original
robert
parents:
diff changeset
248 $genArr[strval($genreID)] = strval($genre);
45ae2aeb2b52 original
robert
parents:
diff changeset
249 //$genArr[$i] = array(strval($genreID) => strval($genre));
45ae2aeb2b52 original
robert
parents:
diff changeset
250
45ae2aeb2b52 original
robert
parents:
diff changeset
251 //echo $genre;
45ae2aeb2b52 original
robert
parents:
diff changeset
252 //echo $genreID;
45ae2aeb2b52 original
robert
parents:
diff changeset
253
45ae2aeb2b52 original
robert
parents:
diff changeset
254 $genre = "";
45ae2aeb2b52 original
robert
parents:
diff changeset
255 $genreID = "";
45ae2aeb2b52 original
robert
parents:
diff changeset
256 }
45ae2aeb2b52 original
robert
parents:
diff changeset
257
45ae2aeb2b52 original
robert
parents:
diff changeset
258 $g1 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
259 $g2 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
260 $g3 = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
261 $loop = 1;
45ae2aeb2b52 original
robert
parents:
diff changeset
262
45ae2aeb2b52 original
robert
parents:
diff changeset
263 foreach ($genArr as $key => $value) {
45ae2aeb2b52 original
robert
parents:
diff changeset
264 //echo "$key => $value";
45ae2aeb2b52 original
robert
parents:
diff changeset
265 $queryG = "CALL b_addBrowseNode($key,\"$value\")"; //add the name value pair for genre to new table
45ae2aeb2b52 original
robert
parents:
diff changeset
266 //echo $queryG;
45ae2aeb2b52 original
robert
parents:
diff changeset
267 $resG = mysqli_query($link, $queryG);
45ae2aeb2b52 original
robert
parents:
diff changeset
268
45ae2aeb2b52 original
robert
parents:
diff changeset
269 switch ($loop) {
45ae2aeb2b52 original
robert
parents:
diff changeset
270 case 1:
45ae2aeb2b52 original
robert
parents:
diff changeset
271 $g1 = $key;
45ae2aeb2b52 original
robert
parents:
diff changeset
272 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
273 case 2:
45ae2aeb2b52 original
robert
parents:
diff changeset
274 $g2 = $key;
45ae2aeb2b52 original
robert
parents:
diff changeset
275 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
276 case 3:
45ae2aeb2b52 original
robert
parents:
diff changeset
277 $g3 = $key;
45ae2aeb2b52 original
robert
parents:
diff changeset
278 break;
45ae2aeb2b52 original
robert
parents:
diff changeset
279 }
45ae2aeb2b52 original
robert
parents:
diff changeset
280
45ae2aeb2b52 original
robert
parents:
diff changeset
281 $loop++;
45ae2aeb2b52 original
robert
parents:
diff changeset
282 }
45ae2aeb2b52 original
robert
parents:
diff changeset
283 }
45ae2aeb2b52 original
robert
parents:
diff changeset
284
45ae2aeb2b52 original
robert
parents:
diff changeset
285 if($salesRank == "")
45ae2aeb2b52 original
robert
parents:
diff changeset
286 $salesRank = "null";
45ae2aeb2b52 original
robert
parents:
diff changeset
287
45ae2aeb2b52 original
robert
parents:
diff changeset
288 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
45ae2aeb2b52 original
robert
parents:
diff changeset
289 include "../../../private/db.php";
45ae2aeb2b52 original
robert
parents:
diff changeset
290
45ae2aeb2b52 original
robert
parents:
diff changeset
291 $title = strtr($title, '"', "'");
45ae2aeb2b52 original
robert
parents:
diff changeset
292 $queryInsert = "CALL b_addNewBook(\"$isbn\",\"$title\", \"$author\",\"$binding\",\"$imageURL\", $dewey, $salesRank,\"$pubDate\",\"$publisher\",$g1,$g2,$g3,$loc)";
45ae2aeb2b52 original
robert
parents:
diff changeset
293 //echo $queryInsert;
45ae2aeb2b52 original
robert
parents:
diff changeset
294
45ae2aeb2b52 original
robert
parents:
diff changeset
295 $resG = mysqli_query($link, $queryInsert) or exit( mysqli_error( $link ));
45ae2aeb2b52 original
robert
parents:
diff changeset
296 mysqli_close($link); //do not remove. reset is needed otherwise mysqli_fetch_array doesn't work after first loop
45ae2aeb2b52 original
robert
parents:
diff changeset
297
45ae2aeb2b52 original
robert
parents:
diff changeset
298
45ae2aeb2b52 original
robert
parents:
diff changeset
299 $output .= "<ISBN>" . htmlspecialchars($isbn) . "</ISBN>";
45ae2aeb2b52 original
robert
parents:
diff changeset
300 $output .= "<Title>" . htmlspecialchars($title) . "</Title>";
45ae2aeb2b52 original
robert
parents:
diff changeset
301 $output .= "<Author>" . htmlspecialchars($author) . "</Author>";
45ae2aeb2b52 original
robert
parents:
diff changeset
302 $output .= "<Binding>" . htmlspecialchars($binding) . "</Binding>";
45ae2aeb2b52 original
robert
parents:
diff changeset
303 $output .= "<Dewey>" . htmlspecialchars($dewey) . "</Dewey>";
45ae2aeb2b52 original
robert
parents:
diff changeset
304 $output .= "<ImageURL>" . htmlspecialchars($imageURL) . "</ImageURL>";
45ae2aeb2b52 original
robert
parents:
diff changeset
305 $output .= "<SalesRank>" . htmlspecialchars($salesRank) . "</SalesRank>";
45ae2aeb2b52 original
robert
parents:
diff changeset
306 $output .= "<PublicationDate>" . htmlspecialchars($pubDate) . "</PublicationDate>";
45ae2aeb2b52 original
robert
parents:
diff changeset
307 $output .= "<Publisher>" . htmlspecialchars($publisher) . "</Publisher>";
45ae2aeb2b52 original
robert
parents:
diff changeset
308 $output .= "<Genre1>" . htmlspecialchars($g1) . "</Genre1>";
45ae2aeb2b52 original
robert
parents:
diff changeset
309 $output .= "<Genre2>" . htmlspecialchars($g2) . "</Genre2>";
45ae2aeb2b52 original
robert
parents:
diff changeset
310 $output .= "<Genre3>" . htmlspecialchars($g3) . "</Genre3>";
45ae2aeb2b52 original
robert
parents:
diff changeset
311 $output .= "<ProductGroup>Book</ProductGroup>";
45ae2aeb2b52 original
robert
parents:
diff changeset
312 }
45ae2aeb2b52 original
robert
parents:
diff changeset
313
45ae2aeb2b52 original
robert
parents:
diff changeset
314 $output .= "</BookDetails>";
45ae2aeb2b52 original
robert
parents:
diff changeset
315
45ae2aeb2b52 original
robert
parents:
diff changeset
316 echo $output;
45ae2aeb2b52 original
robert
parents:
diff changeset
317 }
45ae2aeb2b52 original
robert
parents:
diff changeset
318 ?>