<?php
$this->load->view("top_application");
$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>
      

<ul class="location_search">
<li><span class="location01"><i class="fa fa-map-marker"></i> Location</span>
<div class="location01_form">
<form method="post">
<div class="city_group">
<i class="fa fa-search"></i>
<input type="text" name="city" class="city_search" placeholder="Enter city">
<a class="near"><i class="fa fa-compass"></i> Near Me</a>
</div>
</form>
</div>
</li>

<li><a class="active" href="">All India</a></li>
<li><a href="">Delhi</a></li>
<li><a href="">Bengaluru</a></li>
<li><a href="">Ludhiana</a></li>
<li><a href="">Mumbai</a></li>
<li><a href="">Hyderabad</a></li>
<li><a href="">Tiruppur</a></li>
<li><a href="">Noida</a></li>
<li><a href="">Coimbatore</a></li>
<li><a href="">Ahmedabad</a></li>
<li><a href="">Kolkata</a></li>
</ul>

</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">
           
              <!--LISTINGS-->
              <?php
              if (is_array($catList) && !empty($catList)) {
                ?>
                <div class="span-none">
                  <?php
                  foreach ($catList as $val) {
                    //trace($val);
                    $catCount = count_category(" AND parent_id = '" . $val['category_id'] . "' ");
                    $proCount = count_products(" AND category_id = '" . $val['category_id'] . "' ");
                    if ($proCount > 0) {
                      $count = $proCount;
                      $catRes = array();
                    } else {
                      $count = $catCount;
                      $catRes = $this->db->query("SELECT * FROM wps_categories WHERE parent_id = '" . $val['category_id'] . "' AND status = '1' LIMIT 0, 4")->result_array();
                    }
                    ?>
                    <?php
                    if ($catCount > 0) {
                      ?>
                      <div class="col-md-12 col-sm-12"><h2><?php echo $val['category_name']; ?></h2></div>
                      <?php
                      if (is_array($catRes) && !empty($catRes)) {
                        ?>
<div class="col-md-12 col-sm-12">
<div class="popular-links">
<ul class="full_item">
<?php
                            foreach ($catRes as $sval) {
                              $catCountSub = count_category(" AND parent_id = '" . $sval['category_id'] . "' ");
                              $proCountSub = count_products(" AND category_id = '" . $sval['category_id'] . "' ");
                              if ($proCountSub > 0) {
                                $countSub = $proCountSub;
                              } else {
                                $countSub = $catCountSub;
                              }
                              ?>
<li>
<a href="<?php echo site_url($sval['friendly_url']); ?>" title="<?php echo $sval['category_name']; ?>">
<div class="image_001">
<img src="<?php echo get_image('category', $sval['category_image'], '250', '160', 'R'); ?>" alt="<?php echo $sval['category_name']; ?>"> 
</div>
<div class="titles001"><?php echo $sval['category_name']; ?>(<?php echo $countSub; ?>)</div>
</a>
</li>
   <?php
                            }
                            ?>
</ul>
</div>

                        </div>
                        <?php
                      }
                    }
                  }
                  ?>
                </div>
                <?php
              }
              ?>
              <div class="clearfix"></div>
              <div id="prodListingContainer">
                <?php
                if (is_array($listRes) && !empty($listRes)) {
                  foreach ($listRes as $listKey => $listVal) {
                    $userDets = get_db_single_row("wps_customers", "customers_id, website, company_name, state, city, locality", "customers_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;
                    $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">
                          <iframe width="180" height="180" src="https://www.youtube.com/embed/<?php echo $listVal['youtube_id']; ?>" frameborder="0" allow="accelerometer; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                        </div>
                        <?php
                      } else {
                        ?>
                        <div class="col-md-3 list-ser-img">
                          <img src="<?php echo get_image('product_images', $listVal['media'], '400', '350', 'R'); ?>" alt="" /> 
                        </div>
                        <?php
                      }
                      ?>
                      <!--LISTINGS: CONTENT-->
                      <div class="col-md-5 home-list-pop-desc inn-list-pop-desc"> 
                        <a href="javascript:void(0);">
                          <h3><?php echo $listVal['product_name']; ?></h3>
                        </a>
                        <p>
                          <i class="fa fa-rupee" aria-hidden="true"></i>
                          <?php echo $listVal['product_price']; ?> / <?php echo $listVal['unit_value']; ?> <?php echo $unit_measurement[$listVal['unit_measurement']]; ?>
                        </p>
                        <div class="list-details">
                          <?php
                          if ($listVal['attribute_name']) {
                            $atrribute = explode(',', $listVal['attribute_name']);
                            $atrributeVal = explode(',', $listVal['attribute_value']);
                            ?>
                            <div class="row">
                              <?php
                              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
                              }
                              ?>                          
                            </div>
                            <?php
                          }
                          ?>
                        </div>
                        <div class="list-enqu-btn">
                          <ul>
                            <li><a href="#!" 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 Quotes</a></li>
                          </ul>
                        </div>
                      </div>
                      <div class="col-md-4 home-list-pop-desc inn-list-pop-desc borderCompLeft right_sub">
                        <a href="javascript:void(0);">
                          <h4><?php echo $userDets['company_name']; ?></h4>
                        </a>
                        <p class="mb10"><?php echo $userDets['website']; ?></p>
                        <div class="location"><?php echo $location; ?>
                        <div class="location_city">
                            71/7A, 2nd Floor, Rama Road, Kirti Nagar Industrial Area, Najafgarh Road Industrial Area, New Delhi, Delhi 110015, India
                        </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>
                        </ul>
                        <div class="">                        
                          <a href="#!" class="view_contact_number">View Contact Number</a>

                          <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="get_quotes_btn" data-dismiss="modal" data-toggle="modal" data-target="#list-quo"><i class="fa fa-rupee" aria-hidden="true"></i> Get Quotes</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="javascript:void()">
                                      <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="javascript:void()"><?php echo $proVal['product_name']; ?></a></h6>
                                  <p>Rs: 999/Piece</p>
                                  <ul>
                                    <li><a href="#!" 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-productImage="<?php echo get_image('product_images', $proVal['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 Quotes</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>
         
          <!--LISTINGS END-->
        </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 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);
    $('#productQuoteID').val(productID);
    $('#productCompID').val(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);
            });
          }
        });
      }
    }
  });
</script>
<script src="<?php echo theme_url(); ?>js/jquery.showmore.js" type="text/javascript"></script>
<script>
		
jQuery(document).ready(function(){
jQuery(".ul").showmore({visible:10});
jQuery(".full_item").showmore({
childElement:"li",
visible : 3,
showMoreText : "<button class='view_btn'>+ View More</button>",
showLessText : "<button class='view_btn'>- View Less</button>",
});
});
</script>
<?php $this->load->view("bottom_application"); ?>
