<?php
    
/**
     * Copyright 2005 Zervaas Enterprises (www.zervaas.com.au)
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *     http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */

    
require_once('GoogleSuggestCloneJax.class.php');

    
$ajax = new GoogleSuggestCloneJax();
    
$ajax->handleRequest();
    
$ajax_core = $ajax->loadJsCore(true);
    echo <<<EOD
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>amazon検索</title>
$ajax_core
<link rel="StyleSheet" type="text/css" href="googlesuggestclone.css" />
</head>
<body>
<h1>amazon検索</h1>
EOD;

    echo <<<EOD
        <form method="get" id="f">
            <input type="text" name="q" id="fq" autocomplete="off" />
            <input type="submit" value="Search" id="fs" />
            <div id="search-results"></div>
        </form>
EOD;
    echo
$ajax->attachWidgets(array('query'   => 'fq',
                                       
'results' => 'search-results'));
    echo
$ajax->loadJsApp(true);
    
$q = isset($_GET['q']) ? $_GET['q'] : '';
    if ( empty(
$q) != TRUE) {
        
$amazon = &new Services_Amazon('0AW6NMZ572Z4M7VHCRR2', 'yokukitanaii-22', 'jp', 'http://xml.amazon.co.jp/onca/xml2');
        
$products = $amazon->searchKeyword( htmlspecialchars($q), "All Modes", 1);
        if(
PEAR::isError( $products)) {
            
printf( "指定のキーワード%sを含む商品が見つかりませんでした。", htmlspecialchars( $q));
        } else {
            for (
$i = 0; $i < $ajax->suggestion_limit && empty( $products[ $i]) != TRUE; $i++) {
               
$product = $products[ $i];
               if ( empty(
$product[ "authors"]) != TRUE) {
                   
$authors = is_array( $product[ "authors"]) == TRUE? implode( ",", $product[ "authors"]): $product[ "authors"];
               } else {
                   
$authors = "N/A";
               }
echo <<<EOD
<h2><a href="{$product[ "url"]}">{$product[ "name"]}</a></h2>
<table>
<tr>
<td rowspan="5"><a href="
{$product[ "url"]}"><img src="{$product[ "imagemedium"]}" title="{$product[ "name"]}" /></a></td>
<th>著者:</th><td>$authors</td>
</tr>
<tr><th>出版社:</th><td>
{$product["manufacturer"]}</td></tr>
<tr><th>出版日:</th><td>
{$product["release"]}</td></tr>
<tr><th>価格:</th><td>
{$product["listprice"]}/{$product["ourprice"]}</td></tr>
<tr><th>ASIN:</th><td>
{$product[ "asin"]}</td></tr>
</table>
<hr />

EOD;
            }
        }
    }
?>
</body>
</html>