<?
include_once("./_common.php");

Header("Content-type: text/xml"); 
header("Cache-Control: no-cache, must-revalidate"); 
header("Pragma: no-cache");   

echo "<?xml version=\"1.0\" encoding=\"$g4[charset]\"?>\n";
echo "<response>\n";
$arr = explode("&", $_SERVER['QUERY_STRING']);
for ($i=0; $i<count($arr); $i++) :
    list($name, $value) = explode("=", $arr[$i]);

    $sql = " select * from $g4[yc4_item_table] where it_id = '$value' ";
    $row = sql_fetch($sql);

    $caid1 = substr($row[ca_id],0,2);
    $row2 = sql_fetch(" select ca_name from $g4[yc4_category_table] where ca_id = '$caid1' ");
    $cate1 = get_text($row2[ca_name]);
    $cate2 = $cate3 = $cate4 = "";
    if (strlen($row[ca_id]) >= 4) {
        $caid2 = substr($row[ca_id],0,4);
        $row2 = sql_fetch(" select ca_name from $g4[yc4_category_table] where ca_id = '$caid2' ");
        $cate2 = get_text($row2[ca_name]);
    }
    if (strlen($row[ca_id]) >= 6) {
        $caid3 = substr($row[ca_id],0,6);
        $row2 = sql_fetch(" select ca_name from $g4[yc4_category_table] where ca_id = '$caid3' ");
        $cate3 = get_text($row2[ca_name]);
    }
    if (strlen($row[ca_id]) >= 8) {
        $caid4 = substr($row[ca_id],0,8);
        $row2 = sql_fetch(" select ca_name from $g4[yc4_category_table] where ca_id = '$caid4' ");
        $cate4 = get_text($row2[ca_name]);
    }

    $id = $row[it_id];
    $name = get_text($row[it_name]);
    $url = "$g4[shop_url]/item.php?it_id=$id";
    $description = get_text($row[it_explan]);
    $image = "$g4[url]/data/item/{$id}_l1";
    $thumb = "$g4[url]/data/item/{$id}_s";
    $price = $row[it_amount];
    $quantity = get_it_stock_qty($id);

?>
    <item id="<?=$id?>">
        <name><![CDATA[<?=$name?>]]></name>
        <url><?=$url?></url>
        <description><![CDATA[<?=$description?>]]></description>
        <image><?=$image?></image>
        <thumb><?=$thumb?></thumb>
        <price><?=$price?></price>
        <quantity><?=$quantity?></quantity>
        <category>
            <first id="<?=$caid1?>"><?=$cate1?></first>
            <? if ($cate2) { ?><second id="<?=$caid2?>"><?=$cate2?></second><? } ?>
            <? if ($cate3) { ?><third id="<?=$caid3?>"><?=$cate3?></third><? } ?>
            <? if ($cate4) { ?><fourth id="<?=$caid4?>"><?=$cate4?></fourth><? } ?>
        </category>
    </item>
<? endfor; ?>
</response>