<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/
// +----------------------------------------------------------------------+
// | PHP version 4/5                                                      |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004-2010 ARMIA INC                                    |
// +----------------------------------------------------------------------+
// | This source file is a part of iScripts EasyCart                      |
// +----------------------------------------------------------------------+
// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |
// +----------------------------------------------------------------------+
?>
<?php
echo $javascript->link('jquery.js');	
echo $javascript->link('jquery.ad-gallery.js');
echo $javascript->link('rater.js');

if(isset($pcombndet) && !empty($pcombndet)) {
    $dflt_cmbnid=$pcombndet[0]["Productdetail"]["id"];
    //Setting the Prices & Discount for Wholesale/Retail Users
    $dflt_price=0;
    $dflt_distype=0;
    $dflt_discnt=0;
    if(isset($sus) && empty($sus)===false) {
        if($sus["usertype"]=='wholesale') {
            if(isset($productdet["Product"]["wholesale_price"]))
                $dflt_price=$productdet["Product"]["wholesale_price"];
        }
        else if($sus["usertype"]=='retail') {
            if(isset($ft["Product"]["price"]))
                $dflt_price=$productdet["Product"]["price"];
        }
        else
            $dflt_price=$productdet["Product"]["price"];
    }
    else
        $dflt_price=$productdet["Product"]["price"];
    $dflt_distype=$productdet["Product"]["discount_type"];
    $dflt_discnt=$productdet["Product"]["discount"];
}
$_SESSION['User']['Usertype'] = $sus["usertype"];
?>

<script>
    $(document).ready(
    function (){

        var url='<?php echo $sitefolder;?>/'+'<?php echo $this->params['controller'];?>/rate/';
        $('#Rater').rater({ postHref: url+<?php echo $productdet["Product"]["id"]; ?>+'/' });


<?php  if(isset($pcombndet)) { ?>
                                          getImages('<?php echo $dflt_cmbnid;?>','<?php echo $dflt_price;?>','<?php echo $dflt_distype;?>','<?php echo $dflt_discnt;?>')
    <?php } ?>


                               var galleries = $('.ad-gallery').adGallery();
                               $('#switch-effect').change(
                               function() {
                                   galleries[0].settings.effect = $(this).val();
                                   return false;
                               }
                           );
                               $('#toggle-slideshow').click(
                               function() {
                                   galleries[0].slideshow.toggle();
                                   return false;
                               }
                           );
                               $('#toggle-description').click(
                               function() {
                                   if(!galleries[0].settings.description_wrapper) {
                                       galleries[0].settings.description_wrapper = $('#descriptions');
                                   } else {
                                       galleries[0].settings.description_wrapper = false;
                                   }
                                   return false;
                               }
                           );




                           });
</script>
<script>
    function getImages(id,price,distype,discount)
    {
        var cntlr='<?php echo $this->params['controller'];?>';
        $.ajax({
            type: "post",  // Request method: post, get
            url: "../../showcombnimage/"+id+"/"+price+"/"+distype+"/"+discount, // URL to request
            success: function(response)
            {
               
                if($.trim(response)!='')
                {
                    
                    $('#cmbnimgarea').fadeIn(10);
                    var res=response.split('|~^@^~|')
                    
                    $('#cmbnimgarea').html(res[1]);
                    $('div.productoption_newlayout-comb1').html(res[0]);
                    if(res[1] != ''){
                        $('div.productoption_newlayout-comb2').html('<div style="width:100px; float:left; padding:7px 0 7px 7px; border:1px solid #cfcfcf; "><b>SKU No  : </b>'+res[2]+'</div>');
                    }
                    $('#prod_price').html(res[3]);
                    $('#prod_stock').html(res[4]);
                }
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });
        return false;
    }
</script>
<style>
    .price-txt{ background-color: #FFF !important; }
</style>
<?php if ($session->check('Message.flash')) { ?><div id="okbox"><font color="#078402"><?php $session->flash(); ?></font></div><?php } ?>
<div align="center" class="innerheading">   
    <div align="left">Products</div>
</div>
<div class="row">
<div class="product-details"><!--product-details-->
                        <div class="col-sm-5">
                            <div class="pro-thumb-panel">
                                <div class="pro-thumb-in">

                    <?php

                    if(!isset($imgarr) && empty($imgarr)) {
                        $imgarr[] = "noimages.gif";
                                        $imgarr[] = "noimages.gif";
                                        $imgarr[] = "noimages.gif";
                                        // $imgarr[] = "noimages.gif";
                                    }

                                    if(isset($imgarr) && !empty($imgarr)) { ?>

                                    <div id="gallery" class="ad-gallery">
                                        <div class="outerborder">
                                            <div class="ad-image-wrapper">
                                            </div>
                                            <div class="clear"></div>
                                        </div>
                                        <div class="ad-controls">
                                        </div>
                                        <div class="outerborder">
                                            <div class="ad-nav">
                                                <div class="ad-thumbs">
                                                    <ul class="ad-thumb-list">

                        <?php
                        foreach($imgarr as $val) {
                            $img    = explode(".",$val);
                            $ext    = '.'.end(explode(".",$val));
                            ?>
                                                        <li>
                                                            <a href="<?php echo $sitefolder.'/img/products/'.$img[0].'_xtra'.$ext;?>">
                                                                <img src="<?php echo $sitefolder.'/img/products/'.$img[0].'_thumb'.$ext;?>" class="image0" width="100" height="100">
                                                            </a>
                                                        </li>
                                                                <?php   }   ?>
                                                    </ul>
                                                </div>
                                                <div class="clear"></div>
                                            </div>
                                            <div class="clear"></div>
                                        </div>
                                    </div>

                        <?php } ?>

                                </div>
                            </div>

                        </div>
                        <div class="col-sm-7">
                            <div class="product-information"><!--/product-information-->
                                <h2><?php echo $productdet["Product"]["pname"]; ?></h2>
                                <p><?php echo $productdet["Product"]["descr"]; ?></p>
                                <div class="price-panel">

            <div class="price-txt pricemodified">
       <label id="prod_price">
        
        
<?php                                           
//Setting the Prices & Discount for Wholesale/Retail Users
$prod_price=0;
$discnt_type='';
$discnt_price=0;    

if($productdet["Product"]["wholesale_price"] > 0 || $productdet["Product"]["price"] > 0 ) {
                        if(isset($productdet["Product"]["discount"]) && $productdet["Product"]["discount"] > 0) {
                            $discnt_type=$productdet["Product"]["discount_type"];
                            $discnt_price=$productdet["Product"]["discount"];
                        }
                    }

                    if(isset($sus) && empty($sus)===false) {
                        if($sus["usertype"]=='wholesale') {
                            if(isset($productdet["Product"]["wholesale_price"]) && $productdet["Product"]["wholesale_price"] > 0 ) {
                                $wholesale_price=$productdet["Product"]["wholesale_price"];
                                $utype='wholesale';
                                display_price($utype,$wholesale_price,$discnt_type,$discnt_price,$curlogo);
                                echo "<br><br>";
                            }
                            if(isset($productdet["Product"]["price"]) && $productdet["Product"]["price"] > 0 ) {
                                $retail_price=$productdet["Product"]["price"];
                                $utype='retail';
                                display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
                            }
                            else
                                display_price('retail',0,'',0,$curlogo);
                        }
                        else if($sus["usertype"]=='retail') {
                            if(isset($productdet["Product"]["price"]) && $productdet["Product"]["price"] > 0 ) {
                                $retail_price=$productdet["Product"]["price"];
                                $utype='retail';
                                display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
                            }
                            else
                                display_price('',0,'',0,$curlogo);
                        }
                    }
                    else {
                        if(isset($productdet["Product"]["price"]))
                            $retail_price=$productdet["Product"]["price"];
                        $utype='normal';
                        display_price($utype,$retail_price,$discnt_type,$discnt_price,$curlogo);
                    }
                    //Setting the Prices for Wholesale/Retail Users
                    ?>
                </label>   
                
               
                 <br /><div class="price-txt prod_stock">
                    <label id="prod_stock">
                <p>Stock : <?php echo $productdet["Product"]["stock"]; ?> (Items)</p>   </label>                    

            </div>

            </div>
            <div>
                <?php
                if(isset($pcombndet) && $productdet["Product"]["combination"]<>'N' && $productdet["Product"]["stock"] > 0) { ?>
                <div id="cmbnimgarea" style="display:none;">
                    <!-- Combination Image will be displayed here.. -->
                </div>
                    <?php
} 
                    else if(($productdet["Product"]["combination"]=='N' ||  $productdet["Product"]["combination"]=='')&& $productdet["Product"]["stock"] > 0 ) { ?>
                <div>
                    <a  class="buy-now right cart" href="<?php echo $html->url('/carts/add/'.$productdet["Product"]["id"]."/".$productdet["Product"]["category_id"])?>"> <!-- Parameters : productid,categoryid,combinationid -->
                        <?php //echo $html->image('/img/addtocart3.gif',array('border' =>'0')); ?><i class="fa fa-shopping-cart"></i>
                                        Add to cart
                    </a>
                    <div class="clear"></div>
                </div>
    <?php } else if($productdet["Product"]["stock"] < 1) { ?>
                <div>
                    <font color="red"><strong>Out of Stock<strong></font>
                                </div>
                        <?php } ?>
                               

                                <div class="clear"></div>
                                </div>
                                <div class="productoption_newlayout-detail">
                                    <!-- Select OPtion -->
                                        <?php

                                            if(isset($pcombndet) && !empty($pcombndet) && $productdet["Product"]["combination"]<>'N') {
                                                //Setting the Prices & Discount for Wholesale/Retail Users
                                                $prd_price=0;
                                                $disc_price=0;
                                                $disc_type='';
                                                if(isset($sus) && empty($sus)===false) {
                                                    if($sus["usertype"]=='wholesale') {
                                                        if(isset($productdet["Product"]["wholesale_price"]) && $productdet["Product"]["wholesale_price"] > 0)
                                                            $prd_price=$productdet["Product"]["wholesale_price"];
                                                        else
                                                            $prd_price=$productdet["Product"]["price"];
                                                    }
                                                    else if($sus["usertype"]=='retail') {
                                    if(isset($productdet["Product"]["price"]))
                                                        $prd_price=$productdet["Product"]["price"];
                                                }
                                                else
                                                    $prd_price=$productdet["Product"]["price"];
                                            }

                                            if(isset($productdet["Product"]["discount"]) && $productdet["Product"]["discount"] > 0) {
                                                $disc_type=$productdet["Product"]["discount_type"];
                                                $disc_price=$productdet["Product"]["discount"];
                                            }

                                            //Setting the Prices for Wholesale/Retail Users
                                            ?>
                                        <br>
                                        <select name="select" class="box2" onchange="return getImages(this.value,'<?php echo $prd_price;?>','<?php echo $disc_type;?>','<?php echo $disc_price;?>');return false;">
                                            <?php
                                            $i=1;
                                            foreach($pcombndet as $val) {
                                                if(isset($val["Productdetail"]["combinations"])) {  ?>
                                            <option value="<?php echo $val["Productdetail"]["id"];?>"><?php echo $val["Productdetail"]["combinations"];?></option>
                                                    <?php
                                                    $i++;
                                                }
                                            } ?>
                                        </select>
                                            <?php } ?>
                                        <!-- Select OPtion End -->
                                        <div class="productoption_newlayout-comb1"></div>
                                        <div class="productoption_newlayout-comb2"></div>
                                        <div class="clear"></div>
                                </div>
                                
<?php if($cnfg["allow_product_feedback"] == "Y") {  ?>
                                <div class="feedback-row display_table wid100p">
                                    <div class="fb-post display_table_cell wid50p">
                                        <p>
                                            <a href="<?php echo $html->url('/feedbacks/add/'.$productdet["Product"]["id"]); ?>">Post Feedback on <?php  echo $productdet["Product"]["pname"]; ?></a>
                                        </p>
                                    </div>
                                    <div class="fb-view display_table_cell wid50p"><p><a href="<?php echo $html->url('/feedbacks/show/'.$productdet["Product"]["id"]); ?>">View Feedback on <?php  echo $productdet["Product"]["pname"]; ?></a></p></div>
                                </div>
                    <?php } ?>
                                <div>

<?php if($cnfg["allow_rating"] == "Y") {  ?>


    <?php
                    $rate_width='';
    if($avgrate == 0) {
        $rate_width="0px";
    }
                                    elseif($avgrate < 0.6) {
        $rate_width="9px";
    }
    elseif($avgrate < 1.1) {
        $rate_width="18px";
                                    }
    elseif($avgrate < 1.6) {
        $rate_width="27px";
    }
    elseif($avgrate < 2.1) {

        $rate_width="36px";
                                    }
    elseif($avgrate < 2.6) {
        $rate_width="45px";
    }
                                        elseif($avgrate < 3.1) {
                                            $rate_width="54px";
    }
    elseif($avgrate < 3.6) {
                                            $rate_width="63px";
                                        }
                                        elseif($avgrate < 4.1) {
                                            $rate_width="72px";
                                        }
                                        elseif($avgrate < 4.6) {
                                            $rate_width="81px";
                                        }
                                        else {
                                            $rate_width="90px";
                                        }
                                        ?>
                                    <div class="left" id="Rater">
                                        <span class="ui-rater">
                                            <span class="ui-rater-starsOff" style="width:90px;">
                                                <span class="ui-rater-starsOn" style="width:<?php echo $rate_width;?>"></span>
                                            </span>
                                            <span class="ui-rater-rating" id="ui-rater-rating"></span>
                                            <label id="loader" style="display:none;"><?php  echo $html->image('/img/loader.gif',array('border' => '0'));?></label>
                                        </span>
                                    </div>



                                        <?php } ?>

                                </div>
                                <div class="clear"></div>
                                </div>
                                <div class="clear"></div>
                                </div>
                                <!-- new design-->
                                <div align="center" id="item_details">

                                    <!--Total  Rating starts here -->
                                    <div align="left" class="displaybottom">


                                        <!-- #################################### -->





                                        <!-- #################################### -->

                                    </div>
                                </div>
                                
                            </div><!--/product-information-->
                </div><!--/product-details-->
            </div>








       
        
								
                               

                              
                                <div align="left" class="float_clear"><?php  echo $html->image('/img/clear.gif',array('width' => '1','height' => '1'));?></div>
<?php
//Function to display price for Wholesale and Retail Users
function display_price($utype='',$prod_price='',$discnt_type='',$discnt_price='',$curlogo='') {
    if($utype=='wholesale')
        echo "<p>Wholesale Price : ";
    else if($utype=='retail'){
        if($_SESSION['User']['Usertype']=='wholesale')
            echo "<p>Retail Price : ";
        else
            echo "<p>Price : ";    }
        
    else if($utype=='normal')
        echo "<p>Price : ";

    if(isset($discnt_type) && $discnt_type <> '') {
        if($discnt_type=='per') {
            if(isset($discnt_price) && $discnt_price <> '' && $discnt_price > 0) {
                $discounted_price=($prod_price-(($prod_price * $discnt_price)/100));
                echo "<span><strike>".$curlogo.number_format($prod_price,2)."</strike>&nbsp;&nbsp;".$curlogo.number_format($discounted_price,2)."</span>";
            }
            else
                echo "<span>".$curlogo.number_format($prod_price,2)."</span>";
        }
        else if($discnt_type=='amnt') {
            if(isset($discnt_price) && $discnt_price <> '' && $discnt_price > 0) {
                $discounted_price=($prod_price-$discnt_price);
                echo "<span><strike>".$curlogo.number_format($prod_price,2)."</strike>&nbsp;&nbsp;".$curlogo.number_format($discounted_price,2)."</span>";
                                            }
                                            else
                                                echo "<span>".$curlogo.number_format($prod_price,2)."</span>";
                                        }
                                    }
                                    else {
                                        echo "<span>".$curlogo.number_format($prod_price,2)."</span>";
                                    }
									echo '</p>';
                                }
								
                                echo $javascript->link('productdetails_tooltip.js');
                                ?>