<?php
 
 ###########################################################################
 #   OsCommerce WAP 1.1                                                    #
 #   This file is part of the wap tweak for OsCommerce (c) copyright 2004  #
 #   by Tom Nitzschner (tom@toms-home.com)                                 #
 #   http://www.toms-home.com                                              #
 #                                                                         #
 #   As always, make a backup before messing with anything. All code       #
 #   release by me is considered sample code only. It may be fully         #
 #   functual, but you use it at your own risk, if you break it,           #
 #   you get to fix it too. No waranty is given or implied.                #
 #                                                                         #
 #   All my work is released under the GNU GENERAL PUBLIC LICENSE.         #
 #   Please see the README for more information.                           #
 ###########################################################################

# User changable item below
# You can set the maximum amount of characters from the description
# that will be displayed. I would not reccomend setting it too high, 
# as that can cause timeouts while a WAP device reads the data and 
# some devices have limits on the amount of text they can display

$max_chars = 300;

# End user changable settings. 
# Do NOT change anything below unless you really know what you are doing.

header( 'content-Type: text/vnd.wap.wml');

// Print the file text header
echo  '<?xml version="1.0" ?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">';
?>

<wml>
<template>
<do type="prev" label="Back"><prev/></do>
<do type="accept" label="Main"><go href="wapindex.php"/></do>
</template>

<card id="item" title="Product Item">

<?php
require("includes/wap_top.php");
#
# Query the database for the Product selected
#
$product_query_item = tep_db_query("select pd.products_name as products_name, pd.products_description as products_description,  p.products_price as products_price from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" .$item_id . "' and pd.products_id = p.products_id");
$product = tep_db_fetch_array($product_query_item);
#
# Fill some variables and do some general string cleanup
#
$product_name = $product['products_name'];
$product_desc = strip_tags($product['products_description'], '');
$product_price = tep_round($product['products_price'], 2);
$char_count = strlen($product_desc);
#
# Trim the text if it excedes the limit set at the top.
#
if ($char_count > $max_chars) {
	$product_desc = substr($product_desc, 0, ($max_chars-5));
	$product_desc = $product_desc."[...]";
}
#
# And show the customer the details about the product selected.
#
echo ("<p>".tep_clean_wap_text($product_name) . " (Item ".$item_id.")</p>\n");
echo ("<p>Price: ($$" . $product_price . ")</p>\n");
echo ("<p>Description:</p>");
echo ("<p>".tep_clean_wap_text($product_desc)."</p>\n");
?>
</card>
</wml>
