<?php 
$this->load->view("top_application");
$messurement = $this->config->item('unit_measurement');
$QryStringArr = array();  // To store all Query Variables so to move to other view;
$QryStringArr = array_unique($QryStringArr);
if (isset($this->meta_info['entity_id']) && $this->meta_info['entity_id'] != '') {
  $QryStringArr['category_id'] = $this->meta_info['entity_id'];
}
if ($this->input->post('category_id')) {
  $QryStringArr['category_id'] = $this->input->post('category_id');
}
if ($this->input->get_post('keyword') != '') {
  $QryStringArr['keyword'] = $this->input->get_post('keyword');
}
if ($this->input->get_post('keyword_search') != '') {
  $QryStringArr['keyword_search'] = $this->input->get_post('keyword_search');
}
if ($this->input->get_post('sort') != '') {
  $QryStringArr['sort'] = $this->input->get_post('sort');
}
?>
<section class="dir-alp dir-pa-sp-top">
  <div class="container">
    <div class="row">
      <div class="dir-alp-tit">
        <h1><?php echo $heading_title; ?></h1>
        <ol class="breadcrumb">
          <li><a href="<?php echo site_url(); ?>">Home</a> </li>
          <?php //echo category_breadcrumbs($categoryId); ?>
        </ol>
      </div>
    </div>
    <div class="row">
      <div class="dir-alp-con">
        <?php $this->load->view("category/category_left_view"); ?>
        <div class="col-md-9 dir-alp-con-right list-grid-rig-pad">
          <div class="dir-alp-con-right-1">
            <div class="row">
              <!--LISTINGS-->
              <div id="prodListingContainer">
                <?php
                if (is_array($listRes) && !empty($listRes)) {
                  foreach ($listRes as $listKey => $listVal) {
                    //trace($listVal);
                    $userDets = get_db_single_row("wps_customers", "customers_id, website, company_name, state, city, locality, address, landmark, locality", "customers_id = '" . $listVal['customers_id'] . "'");
                    $aboutCompany = get_db_field_value("wps_customers_factsheet", "about_company", "WHERE id = '" . $listVal['customers_id'] . "'");
                    $city = "";
                    $state = "";
                    $locality = "";
                    if (is_array($userDets) && !empty($userDets)) {
                      $city = get_db_field_value("wps_cities_list", "city", "WHERE id = '" . $userDets['city'] . "'");
                      $state = get_db_field_value("wps_states_list", "name", "WHERE id = '" . $userDets['state'] . "'");
                      $locality = $userDets['locality'];
                    }

                    //more products
                    $condtion = array();
                    $condtion['customers_id'] = $userDets['customers_id'];
                    $condtion['category_id'] = $categoryId;
                    $condtion['leave_product_id'] = $listVal['products_id'];
                    $productList = $this->product_model->get_products(4, 0, $condtion);
                    $otherProductCount = get_found_rows();

                    $location = $location1 = "";
                    if ($state || $city) {
                      $location .= '<i class="fa fa-map-marker"></i> ';
                    }
                    if ($state)
                      $location .= $state;
                    $location1 .= $state;
                    if ($city) {
                      if ($state)
                        $location .= ', ';
                      $location1 .= ', ';
                      $location .= $city;
                      $location1 .= $city;
                    }
                    ?>
                    <!--LISTINGS-->
                    <div class="home-list-pop list-spac listpager">
                      <!--LISTINGS IMAGE-->
                      <?php
                      if ($listVal['youtube_id'] != '') {
                        
                      }
                      ?>
                      <div class="col-md-3 list-ser-img">
                        <a href="javascript:void(0);" title="<?php echo $listVal['product_name']; ?>" data-productID="<?php echo $listVal['products_id']; ?>" data-companyID="<?php echo $listVal['customers_id']; ?>" data-productName="<?php echo $listVal['product_name'] . ' <br> ' . $userDets['company_name'] . ' ' . $location1; ?>" data-companyName="<?php echo $userDets['company_name']; ?>" data-productImage="<?php echo get_image('product_images', $listVal['media'], '400', '600', 'R'); ?>" data-unit="<?php echo @$messurement[$listVal['unit_measurement']]; ?>" class="getQuote" data-dismiss="modal" data-toggle="modal" data-target="#list-quo"><img src="<?php echo get_image('product_images', $listVal['media'], '400', '350', 'R'); ?>" alt="" /></a>
                        <div class="row">
                          <div class="col-md-12 col-lg-12 inn-list-pop-desc">
                            <span>
                              <i class="fa fa-rupee" aria-hidden="true"></i>
                              <?php
                              if($listVal['product_discounted_price'] > 0){
                                echo display_price($listVal['product_discounted_price']); ?> <span class="old-price"><i class="fa fa-rupee" aria-hidden="true"></i> <?php echo display_price($listVal['product_price']); ?></span>
                                <?php
                              }else{
                                echo display_price($listVal['product_price']);
                              }
                              ?>/ <?php echo $listVal['unit_value']; ?> <?php echo @$unit_measurement[$listVal['unit_measurement']]; ?><br> <i class="fa fa-list" aria-hidden="true"></i>
                              MOQ : <?php echo $listVal['moq']; ?> <?php echo @$unit_measurement[$listVal['unit_measurement']]; ?>
                            </span>
                          </div>
                        </div>
                      </div>
                      <!--LISTINGS: CONTENT-->
                      <div class="col-md-6 home-list-pop-desc inn-list-pop-desc">  
                        <div class="verified_badge">
                          <img src="<?php echo theme_url(); ?>images/verified.png">
                          <div class="info_02">
                            <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nostrum qui ex nobis perferendis, recusandae, vel enim, quam tempore soluta eaque dicta fugiat animi perspiciatis accusamus distinctio sequi natus nam atque?</p>
                          </div>
                        </div>                  
                        <h3><a href="<?php echo site_url() . $listVal['friendly_url']; ?>" title="<?php echo $listVal['product_name']; ?>"><?php echo $listVal['product_name']; ?></a></h3>
                        <div class="clearfix"></div>
                        <p><?php echo char_limiter($aboutCompany,155); ?></p>

                        <div class="list-details">
                          <?php
                          if ($listVal['attribute_name']) {
                            $atrribute = explode(',', $listVal['attribute_name']);
                            $atrributeVal = explode(',', $listVal['attribute_value']);
                            ?>
                            <div class="row">
                              <?php
                              $it = 1;
                              foreach ($atrribute as $ak => $av) {
                                ?>
                                <div class="col-md-5"><?php echo $av; ?></div>
                                <div class="col-md-2">:</div>
                                <div class="col-md-5"><?php echo $atrributeVal[$ak]; ?></div>
                                <?php
                                $it++;
                                if ($it == 7)
                                  break;
                              }
                              ?>                          
                            </div>
                            <?php
                          }
                          ?>
                        </div>
                        <?php
                        /*
                          <div class="list-enqu-btn">
                          <ul>
                          <li><a href="#!" data-productID="<?php echo $listVal['products_id']; ?>" data-companyID="<?php echo $listVal['customers_id']; ?>" data-productName="<?php echo $listVal['product_name'] . ' <br> ' . $userDets['company_name'] . ' ' . $location1; ?>" data-productImage="<?php echo get_image('product_images', $listVal['media'], '400', '600', 'R'); ?>" class="getQuote" data-dismiss="modal" data-toggle="modal" data-target="#list-quo">View Details</a> </li>
                          <li><a href="#!" data-productID="<?php echo $listVal['products_id']; ?>" data-companyID="<?php echo $listVal['customers_id']; ?>" data-productName="<?php echo $listVal['product_name'] . ' <br> ' . $userDets['company_name'] . ' ' . $location1; ?>" data-productImage="<?php echo get_image('product_images', $listVal['media'], '400', '600', 'R'); ?>" class="getQuote" data-dismiss="modal" data-toggle="modal" data-target="#list-quo"><i class="fa fa-rupee" aria-hidden="true"></i> Get a Quote</a></li>
                          </ul>
                          </div>
                         * 
                         */
                        ?>
                        <a class="view_more_btn" href="<?php echo site_url() . $listVal['friendly_url']; ?>" title="<?php echo $listVal['product_name']; ?>">View More Details <i class="fa fa-angle-double-right"></i></a>

                      </div>
                      <div class="col-md-3 home-list-pop-desc inn-list-pop-desc borderCompLeft right_sub">
                        <a href="javascript:void(0);">
                          <h4><a href="<?php echo $userDets['website']; ?>" title="View More About <?php echo $userDets['company_name']; ?>"><?php echo $userDets['company_name']; ?> in New Delhi, India</a></h4>
                        </a>
                        <div class="location"><?php echo $location; ?>
                          <div class="location_city">
                            <?php echo $userDets['address'] . ', ' . $userDets['locality'] . ', Near ' . $userDets['landmark']; ?>, <?php echo $state; ?>, <?php echo $city; ?>
                          </div>
                        </div>
                        <ul class="verified">
                          <!--<li><a href="javascript:void()"><i class="fa fa-gratipay"></i> Trust Verified</a></li>-->
                          <li><i class="fa fa-check-circle"></i> Verified Manufacturer</li>
                          <!--<li><a href="javascript:void()"><i class="fa fa-youtube-play"></i> Company Video</a></li>-->
                        </ul>
                        <div class="">
                          <?php
                          if ($listVal['youtube_id'] != '' && $listVal['youtube_id'] != '0') {
                            ?>
                            <a href="javascript:void(0);" data-youtubeId="<?php echo $listVal['youtube_id']; ?>" data-companyFacName="<?php echo $userDets['company_name']; ?>" title="Factory Video" class="youtube_btn" data-dismiss="modal" data-toggle="modal" data-target="#facVideo"><i class="fa fa-youtube-play"></i> Factory Video</a>
                            <?php
                          }
                          ?>

                          <a href="javascript:void(0);" data-companyID="<?php echo $listVal['customers_id']; ?>" class="view_contact_number <?php echo ($this->session->userdata('user_id') <= 0) ? 'getContactNo' : 'viewContactNo'; ?>" <?php echo ($this->session->userdata('user_id') <= 0) ? 'data-dismiss="modal" data-toggle="modal" data-target="#regis-ter"' : ''; ?>>View Contact Number</a>

                          <a href="javascript:void(0);" data-productID="<?php echo $listVal['products_id']; ?>" data-companyID="<?php echo $listVal['customers_id']; ?>" data-productName="<?php echo $listVal['product_name'] . ' <br> ' . $userDets['company_name'] . ' ' . $location1; ?>" data-companyName="<?php echo $userDets['company_name']; ?>" data-productImage="<?php echo get_image('product_images', $listVal['media'], '400', '600', 'R'); ?>" data-unit="<?php echo @$messurement[$listVal['unit_measurement']]; ?>" class="get_quotes_btn getQuote" data-dismiss="modal" data-toggle="modal" data-target="#list-quo"><i class="fa fa-rupee" aria-hidden="true"></i> Get a Quote</a>
                        </div>
                      </div>
                      <?php
                      if ($otherProductCount > 0) {
                        ?>
                        <div class="col-md-12 home-list-pop-desc inn-list-pop-desc borderExtProTop">
                          <div class="more_products01"><?php echo $otherProductCount; ?> more products from this supplier</div>
                          <div class="clearfix"></div>
                          <div class="row">
                            <?php
                            foreach ($productList as $proVal) {
                              if ($proVal['media']) {
                                ?>

                                <div class="col-md-4">
                                  <div class="list-customize more_item">
                                    <div class="img-customize">
                                      <a href="<?php echo site_url() . $proVal['friendly_url']; ?>" title="<?php echo $proVal['product_name']; ?>">
                                        <img src="<?php echo get_image('product_images', $proVal['media'], '120', '120', 'R'); ?>" alt="" height="100" width="100" /> </a>
                                    </div>
                                    <div class="list-enqu-btn width_auto">
                                      <h6><a href="<?php echo site_url() . $proVal['friendly_url']; ?>" title="<?php echo $proVal['product_name']; ?>"><?php echo $proVal['product_name']; ?></a></h6>
                                    <!--  <p>Rs: 999/Piece</p>-->
                                      <ul>
                                        <li><a href="javascript:void(0);" data-productID="<?php echo $proVal['products_id']; ?>" data-companyID="<?php echo $proVal['customers_id']; ?>" data-productName="<?php echo $proVal['product_name'] . ' <br> ' . $userDets['company_name'] . ' ' . $location1; ?>" data-companyName="<?php echo $userDets['company_name']; ?>" data-productImage="<?php echo get_image('product_images', $proVal['media'], '400', '600', 'R'); ?>" data-unit="<?php echo $messurement[$proVal['unit_measurement']]; ?>" class="getQuote" data-dismiss="modal" data-toggle="modal" data-target="#list-quo"><i class="fa fa-rupee" aria-hidden="true"></i> Get a Quote</a> </li>
                                      </ul>
                                    </div>

                                  </div>
                                </div>

                                <?php
                              }
                            }
                            ?>
                          </div>
                        </div>
                        <?php
                      }
                      ?>
                    </div>
                    <!--LISTINGS END-->
                    <?php
                  }
                } else {
                  ?>
                  <div class="alert alert-warning" role="alert">
                    <strong>Oh snap!</strong> No Listing Found.
                  </div>
                  <div class="row">
                    <div class="input-field s12 text-center">
                      <div class="row">
                        <div class="input-field s4 "><a href="<?php echo site_url(); ?>members/add_listing" class="waves-effect waves-light btn-large" >Are your a Supplier? Add New Listing Now!</a></div>
                      </div>
                    </div>
                  </div>
                  <?php
                }
                ?>
              </div>
            </div>
          </div>
          <!--LISTINGS END-->
        </div>
      </div>
    </div>
  </div>
</div>
</div>
</section>
<!--MOBILE APP-->

<script type="text/javascript">

  $('.getQuote').click(function () {
    var productID = $(this).attr('data-ProductID');
    var companyID = $(this).attr('data-companyID');
    var companyName = $(this).attr('data-companyName');
    var productName = $(this).attr('data-ProductName');
    var productImage = $(this).attr('data-ProductImage');
    $('#productQuoteImage').attr('src', productImage);
    $('#productQuoteImage').css({"border": "3px solid #CCC"});
    $('#companyProDetails').html('');
    $('#companyProDetails').html(productName);
    $('#companyProName').html(companyName);
    $('#productQuoteID').val(productID);
    $('#productCompID').val(companyID);
    $('.unitSize').html('/' + $(this).attr('data-unit'));
  });


  $(".getContactNo").click(function () {
    $('.pop-btn-rgstr').val('View Contact No.');
    $('.viewCompContact').val($(this).attr('data-companyID'));
  });

  var page = 1;
  var triggeredPaging = 0;
  $(window).scroll(function () {
    $('#loadingdiv').hide();
    var scrollTop = $(window).scrollTop();
    var scrollBottom = (scrollTop + $(window).height());
    var containerTop = $('#prodListingContainer').offset().top;
    var containerHeight = $('#prodListingContainer').height();
    var containerBottom = Math.floor(containerTop + containerHeight);
    var scrollBuffer = 0;
    if ((containerBottom - scrollBuffer) <= scrollBottom) {
      page = $('.listpager').length;
      var queryString = '?stOffSet=' + page;
<?php
if (count($QryStringArr)) {
  foreach ($QryStringArr as $qrykey => $qryval) {
    ?>
          queryString += "&<?php echo $qrykey; ?>=<?php echo $qryval; ?>";
    <?php
  }
}
?>
      var actual_count = <?php echo $total_list_rows; ?>;
      if (!triggeredPaging && page < actual_count) {
        triggeredPaging = 1;
        $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>products/ajax_load_product_view" + queryString,
          error: function (res) {
            //alert('Error');
            triggeredPaging = 0;
            $('#loadingdiv').hide();
            //console.log(arguments);
          },
          beforeSend: function (jqXHR, settings) {
            $('#loadingdiv').show();

          },
          success: function (res) {
            $('#loadingdiv').hide();
            $("#prodListingContainer").append(res);
            triggeredPaging = 0;
            //console.log(res);
            $('.listpager').fadeTo(1000, 0.5, function () {
              $(this).fadeTo(1000, 1.0);
            });
          }
        });
      }
    }
  });

  $('.view_btn').click(function () {
    var text = $(this).html();
    //alert(text);
    if (text == '+ View More') {
      $(this).html('- View Less');
      $(this).parent().children('.full_item').children('.vm').removeClass('hidden');
    } else {
      $(this).html('+ View More');
      $(this).parent().children('.full_item').children('.vm').addClass('hidden');
    }
  });

</script>
<?php $this->load->view("bottom_application"); ?>