<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts Multicart                     |
// +----------------------------------------------------------------------+
// | Authors: Santhosh Thomas Alexander<santhosh.thomas@armiasystems.com>  |
// +----------------------------------------------------------------------+
// | Copyrights Armia Systems, Inc and iScripts.com � 2005                |
// | All rights reserved                                                  |
// +----------------------------------------------------------------------+
// | This script may not be distributed, sold, given away for free to     |
// | third party, or used as a part of any internet services such as      |
// | webdesign etc.                                                       |
// +----------------------------------------------------------------------+
?>
<?php
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";

function getProductOptionDetails($productOptionID) {
		global $tableprefix;
		$query 		= "SELECT (p.product_price+po.additional_price) AS product_price,po.product_stock,po.image_big,po.image_small,po.discount,po.discount_description,po.product_shipping_weight
		         	 	FROM " . $tableprefix."product_options po
                                        INNER JOIN " . $tableprefix."products p ON p.product_id = po.product_id
                                        WHERE po.product_option_id = '".$productOptionID."'";
		$queryQ 	=  mysql_query($query);
		$details 	=  mysql_fetch_object($queryQ);
		return $details;
}
$productOptionId = $_POST['product_option_id'];

$productObj = getProductOptionDetails($productOptionId);
if(!empty($productObj->image_big))
{
        if(strpos($productObj->image_big,"http")===false) {
                $product_image = SITE_URL."/products/".$productObj->image_big;
        }else {
                $product_image = $productObj->image_big;
        }
}else if(!empty($productObj->image_small))
{
        if(strpos($productObj->image_small,"http")===false) {
                $product_image = SITE_URL."/products/".$productObj->image_small;
        }else {
                $product_image = $productObj->image_small;
        }
}
else
{
        $product_image = SITE_URL."/products/noimage.jpg"; // no image
}

$check_array = array('ndisplay_stock');
$settings = getSiteGeneralSettings($check_array);
$showStock = $settings[0];
$imageurl= "<img width='283' height='269' src='".$product_image."' border='0' id='itemImage' onClick=PopWinbig('".$product_image."','MoreImages',width=400,height=400,resizable=1,scrollbars=1,toolbar=0,status=1'); style='cursor: pointer;'>";
$currency_attributes = displayCurrencyType();
$price = $productObj->product_price;
$discount = $productObj->discount;
$conversionRate	= ConvertedCurrencyRate($currency_attributes[2]);
$converted_price = $price * $conversionRate;


$value = array("stock" => $productObj->product_stock,"show_item_status" => $showStock,"imageUrl" => rawurlencode($imageurl),"image"=>rawurlencode($product_image),"price"=> $converted_price,"discount"=> $discount,"discount_description"=>$productObj->discount_description,"product_shipping_weight"=>$productObj->product_shipping_weight,"currency"=>$currency_attributes[0]);
echo json_encode(array("value"=>$value,"response"=>"success"));
?>