<?php
$this->load->view('top');
$mediaRes = $media_res;
$overall_rating_product = product_overall_rating($res['products_id'], 'product');
//print_r($res);
$cat_res = get_db_single_row('wps_categories', '*', " category_id='$res[category_id]'");
$cart_array = $this->cart->contents();
$insert_flag = 0;
if (is_array($cart_array) && !empty($cart_array)) {
    foreach ($this->cart->contents() as $item) {
        if (array_key_exists('pid', $item)) {
            if ($item['pid'] == $res['products_id']) {
                $insert_flag = 1;
            }
        }
    }
}
?>

<link href="<?php echo theme_url(); ?>css/magiczoomplus.css" rel="stylesheet" type="text/css" />
<style>
    .product_color_switch ul li.active a {
        border: 5px solid #08c;
        padding: 12px;
    }

</style>
<div class="page_breadcrumbs">
    <div class="container">
        <ul>
            <li><a href="<?= site_url(); ?>" title="Home">Home</a>
            </li>
            <?php echo category_breadcrumbs($res['category_id']); ?>
            <li><?php echo $res['product_name']; ?></li>
        </ul>
    </div>
</div>
<section class="product_listing">
    <div class="container">
        <div class="row">
            <div class="col-lg-6 col-md-6 col-sm-6  col-xs-12">
                <div class="app-figure" id="zoom-fig">
                    <div class="details_zoom">
                        <div class="row">
                            <div class="col-sm-2 col-md-2 col-xs-3">
                                <div class="selectors">
                                    <?php foreach ($mediaRes as $mres) { ?>
                                        <a data-slide-id="zoom" class="active" href="<?php echo get_image('products', $mres['media'], '', '', 'R'); ?>" data-image="<?php echo get_image('products', $mres['media'], '460', '690', 'R'); ?>" title="<?= $res['product_name']; ?>" title="mothers-day" data-zoom-id="zoom-v">
                                            <img srcset="<?php echo get_image('products', $mres['media'], '85', '128', 'R'); ?>" src="<?php echo get_image('products', $mres['media'], '85', '128', 'R'); ?>" title="<?= $res['product_name']; ?>" alt="<?= $res['product_name']; ?>" />
                                        </a>
                                    <?php } ?>
                                </div>
                            </div>
                            <div class="col-sm-10 col-md-10 col-xs-9">
                                <a id="zoom-v" class="MagicZoom" title="<?= $res['product_name']; ?>" href="<?php echo get_image('products', $res['media'], '2000', '2000', 'R'); ?>" data-options="zoomWidth:470; zoomHeight:470px">
                                    <img src="<?php echo get_image('products', $res['media'], '460', '690', 'R'); ?>" alt="<?= $res['product_name']; ?>" title="<?= $res['product_name']; ?>" />
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-6 col-md-6">
                <div class="product_details service_details">
                    <?php echo form_open(site_url('cart/add_to_cart'), 'id="cart_form"'); ?>
                    <h1><?= $res['product_name']; ?></h1>
                    <?php if ($res['product_code'] != '') { ?><div class="styles"><strong>Product Code: </strong> <?= $res['product_code']; ?><br /><br /><?php } ?>

                       <?php echo html_entity_decode($res['products_description']);?>


                        <div class="clearfix"></div>
                       
                            <a href="javascript:void(0);" data-toggle="modal" data-target="#getquote" class="getQuote" data-friendly_url="<?php echo site_url($res['friendly_url']); ?>" data-ProductID="<?php echo $res['products_id']; ?>" data-ProductName="<?php echo $res['product_name']; ?>" data-ProductImage="<?php echo get_image('products', $res['media'], '', '', 'AR'); ?>" data-id="<?php echo $res['products_id']; ?>">
                            <span class="details_btn hover_btn">Send Enquiry</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
        <br />


        <div class="product_overview">
            <div class="panel with-nav-tabs panel-default">
                <div class="panel-heading">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab1productdetails" data-toggle="tab">Product Details</a>
                        </li>
                        <?php if ($res['specification'] != '') { ?>
                            <li><a href="#tab1specification" data-toggle="tab">Specification</a>
                            </li>
                        <?php } ?>
<!--                        <li><a href="#tab3review" data-toggle="tab">Ratings & Reviews</a>
                        </li>-->
                    </ul>
                </div>
                <div class="panel-body">
                    <div class="tab-content">
                        <div class="tab-pane fade in active" id="tab1productdetails">
                            <?= $res['products_description']; ?>
                        </div>
                        <div class="tab-pane fade" id="tab1specification">
                            <?= $res['specification']; ?>
                        </div>

                        <div class="tab-pane fade" id="tab3review">
                            <h3>Ratings & Reviews
                                <?php if ($this->session->userdata('user_id') > 0) { ?>
                                    <a href="<?php echo site_url(); ?>members/post_review/<?php echo $res['products_id']; ?>" class="product_rate">Write Review</a><?php } else {
                                    ?>
                                    <a href="<?= base_url('login'); ?>" class="product_rate">Write Review</a>
                                    <?php }
                                ?>
                            </h3>
                            <?php
                            $reviews = $this->db->query("SELECT * FROM  wps_review WHERE entity_id='" . $res['products_id'] . "'")->result_array();
                            if (is_array($reviews) && !empty($reviews)) {
                                $starArray = $this->config->item('starArray');
                                krsort($starArray);
                                foreach ($reviews as $key => $revval) {
                                    ?>
                                    <div class="review">
                                        <div class="review-title"><span class="summary"><i class="fa fa-user"></i> <?php echo $revval['author']; ?></span><span class="date"><i class="fa fa-calendar"></i><span><?php echo date('d M Y H:i A', strtotime($revval['review_date'])); ?></span></span>
                                        </div>
                                        <div class="product_ratings">
        <?php
        $ads_rating = $revval['ads_rating'];
        for ($i = 1; $i < 6; $i++) {
            ?>
                                                <i class="fa fa-star <?php if ($i <= $ads_rating) {
                                        echo 'checked';
                                    } ?>"></i>
                                                <?php
                                                # code...
                                            }
                                            ?>
                                            <?php echo form_error('ads_rating'); ?>
                                        </div>
                                        <div class="text"><?php echo $revval['text']; ?></div>
                                        <div class="">
                                            <!--						                  <img src="<?php echo get_image('revies', $revval['upload_image'], '125', '125', 'R'); ?>" id="pic1" class="profile_picture" width="125" height="125"  />				               -->
                                        </div>
                                    </div>
                                <?php }
                            }
                            ?>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<?php if (is_array($related) && !empty($related)) { ?>
    <section class="new_arrvals">
        <div class="container">
            <div class="heading wow fadeInLeft animated" data-wow-delay=".1s">
                <h2>Related Products</h2>
            </div>
            <div id="ProductsStyle" class="owl-carousel">
                <?php
                foreach ($related as $key => $val) {
                    $productImage = get_db_field_value("wps_products_media", "media", "WHERE products_id = '" . $val['products_id'] . "' ORDER BY id asc LIMIT 0, 1");
                    ?>
                    <div class="product wow fadeInDown animated" data-wow-delay=".2s">
                        <a href="<?php echo base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                            <?php if ($val['product_discounted_price'] > 0) {
                                $percent = (($val['product_price'] - $val['product_discounted_price']) * 100) / $val['product_price'];
                                ?>
                                <div class="off_label"><?= round($percent); ?> %off</div>
        <?php } ?>
                            <div class="image01">
                                <img src="<?php echo get_image('products', $productImage, '251', '251', 'R'); ?>" alt="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                            </div>
                        </a>
                        <div class="new_desc">
                            <!-- <span class="starrating">
                                <i class="fa fa-star star-on"></i>
                                <i class="fa fa-star star-on"></i>
                                <i class="fa fa-star star-on"></i>
                                <i class="fa fa-star star-on"></i>
                                <i class="fa fa-star-half-o"></i>(0)
                                </span> -->
                            <h3><a href="<?php echo base_url($val['friendly_url']); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
                            <?php echo char_limiter($val['product_name'], 94); ?></a></h3>
                            <?php if ($val['product_discounted_price'] > 0) { ?>
                                <span class="price"><span><?= display_price($val['product_price']); ?></span> <?= display_price($val['product_discounted_price']); ?></span>
        <?php } else { ?>
                                <span class="price"><?= display_price($val['product_price']); ?></span>
                    <?php } ?>
                        </div>
                    </div>
    <?php } ?>

            </div>
        </div>
    </section>
<?php } ?>


<?php $this->load->view("bottom"); ?>

<script type="text/javascript">
    setTimeout(function () {
        $('.colorList').eq(0).trigger('click');
        $('.sizeList').eq(0).trigger('click');
    }, 600);


    var dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
    var MAX_QTY = $('.stockValue').val();
    ;
    var MIN_QTY = 1;
    jQuery(".super-attribute-select").change(function () {
        dqty = jQuery(".super-attribute-select").find("option:selected").attr("qty");
        if (typeof dqty == "undefined") {
            MAX_QTY = 10
        } else {
            MAX_QTY = dqty
        }
        jQuery("#qty").val(1)
    });
    jQuery(".plus").click(function () {
        var MAX_QTY = $('#stockValue').val();
        ;
        var MIN_QTY = 1;
        if (typeof MAX_QTY == "undefined") {
            MAX_QTY = 10
        }
        var a = parseInt(jQuery(this).prev(".qty").val());
        if (!a || a == "" || a == "NaN") {
            a = 0
        }
        if (a < MAX_QTY) {
            jQuery(this).prev(".qty").val(a + 1)
        } else {
            alert('You have reached to maximum available quantity.');
        }
    });
    jQuery(".minus").click(function () {
        var MAX_QTY = $('#stockValue').val();
        ;
        var MIN_QTY = 1;
        var a = parseInt(jQuery(this).next(".qty").val());
        if (a == "NaN") {
            a = 0
        }
        if (a > MIN_QTY) {
            jQuery(this).next(".qty").val(a - 1)
        }
    });

    $('.sizeList, .colorList').click(function () {
        if ($(this).hasClass("sizeList")) {
            $('.sizeList').parent('li').removeClass('active');
            $(this).parent('li').addClass('active');
            $('#size_id').val($(this).attr('data-Val'));
        } else {
            $('.colorList').parent('li').removeClass('active');
            $(this).parent('li').addClass('active');
            $('#color_id').val($(this).attr('data-Val'));
        }
        //get value
        var sz = $('#size_id').val();
        var cl = 0; //$('#color_id').val();
        //if (sz > 0 && cl > 0) {
        $.post('<?php echo site_url(); ?>products/get_product_price', {
            sid: sz,
            cid: cl,
            pid: '<?php echo $res['products_id']; ?>'
        }, function (msg) {
            if (msg) {
                var txt = msg.split('-');
                if (txt[2] > 0 && txt[0] > 0) {
                    var percent = ((txt[1] - txt[2]) * 100) / txt[1];
                    $('#price').html('');
                    $('#price').html('<i class="fa fa-inr"></i> ' + txt[2] + ' <span class="old_price"><i class="fa fa-inr"></i> ' + txt[1] + '</span><div class="off_label">' + Math.round(percent) + '% Off</div>');
                    $('.stock').html('In Stock');
                    $('.cartButton').show(0);
                    $('.stockValue').val(txt[0]);
                } else if (txt[1] > 0 && txt[0] > 0) {
                    $('#price').html('<i class="fa fa-inr"></i> ' + txt[1]);
                    $('.stock').html('In Stock');
                    $('.cartButton').show(0);
                    $('.stockValue').val(txt[0]);
                } else {
                    $('#price').html('OUT OF STOCK');
                    $('.stock').html('Out of Stock');
                    $('.cartButton').hide(0);
                    $('.stockValue').val('0');
                }
            } else {
                // $('#price').html('OUT OF STOCK');
                // $('.stock').html('Out of Stock');
                // $('.stockValue').val('0');
                // $('.cartButton').hide(0);
            }

        });
        // }
    });
<?php if ($res['size_ids'] != '' && $res['color_ids'] != '') { ?>
        $('.cartButton').click(function () {
            if ($('#size_id').val() == '' || $('#color_id').val() == '') {
                alert('please select size & color to add in the cart!');
                return false;
            } else {
                $('#cart_form').submit();
            }
        });
<?php } else if ($res['size_ids'] != '' && $res['color_ids'] == '') { ?>
        $('.cartButton').click(function () {
            if ($('#size_id').val() == '') {
                alert('please select size to add in the cart!');
                return false;
            } else {
                $('#cart_form').submit();
            }
        });
<?php } else if ($res['size_ids'] == '' && $res['color_ids'] != '') { ?>
        $('.cartButton').click(function () {
            if ($('#color_id').val() == '') {
                alert('please selectcolor to add in the cart!');
                return false;
            } else {
                $('#cart_form').submit();
            }
        });
<?php } else { ?>
        $('.cartButton').click(function () {
            $('#cart_form').submit();
        });
<?php } ?>

</script>



<script src="<?php echo theme_url(); ?>js/magiczoomplus.js" type="text/javascript"></script>

<script>
    jQuery('.zoom-gallery .selectors a').on('click touch', function (e) {
        var iframe = jQuery('.active iframe[src*="youtube"],.active iframe[src*="vimeo"]');
        if (iframe.length) {
            iframe.attr('src', iframe.attr('src'));
        }
        jQuery('.zoom-gallery .zoom-gallery-slide').removeClass('active');
        jQuery('.zoom-gallery .selectors a').removeClass('active');
        jQuery('.zoom-gallery .zoom-gallery-slide[data-slide-id="' + jQuery(this).attr('data-slide-id') + '"]').addClass('active');
        jQuery(this).addClass('active');
        e.preventDefault();
    });

</script>

<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
<?php if ($this->session->flashdata('success') != '') { ?>
            swal({
                title: "<?php echo $this->session->flashdata('success'); ?>",
                text: "",
                type: "success",
                showCancelButton: true,
                cancelButtonText: "Continue Shopping",
                cancelButtonColor: '#01a1e3',
                confirmButtonColor: '#ff0000',
                confirmButtonText: 'Go to Cart',
                //closeOnConfirm: false,
                //closeOnCancel: false
            },
                    function (isConfirm) {
                        if (isConfirm) {
                            window.location.href = "<?php echo base_url('cart'); ?>";
                        } else {
                            // window.location.href="<?php echo base_url('cart'); ?>";
                            //swal("Cancelled", "Your imaginary file is safe :)", "error");
                        }
                    });
<?php } ?>
    });

</script>
