<section class="page-title">
		<div class="pattern-layer-one" style="background-image: url(assets/images/background/pattern-14.png)"></div>
		<div class="pattern-layer-two" style="background-image: url(assets/images/background/pattern-15.png)"></div>
    	<div class="auto-container">
			<h2><?php echo $categoriesDataCheck['title']; ?></h2>
			<ul class="page-breadcrumb">
			<li><a href="<?php echo $generalSettingCheck['site_url']; ?>"><?php echo $langArray['LINK_HOME']; ?></a></li>
            <?php if ($categoriesDataCheck['categories_type'] == 'product_categories') { ?>
            <li><a href="<?php echo $generalSettingCheck['site_url']; ?><?php echo $langArray['LINK_PRODUCT_LINK']; ?>"><?php echo $langArray['LINK_PRODUCT']; ?></a></li>
            <?php } ?>
            <?php
              if ($categoriesDataCheck['categories_top_id'] > 0) {
                $topCategoriesAsk=$db->prepare("SELECT * FROM categories WHERE categories_id=:categories_id");
                $topCategoriesAsk->execute(array(
                  'categories_id' => $categoriesDataCheck['categories_top_id']
                ));
                $topCategoriesCheck=$topCategoriesAsk->fetch(PDO::FETCH_ASSOC);
            ?>
            <li><a href="<?php echo $topCategoriesCheck['seo_url']; ?>"><?php echo $topCategoriesCheck['title']; ?></a></li>
            <?php } ?>
						<li class="active"><?php echo $categoriesDataCheck['title']; ?></li>
			</ul>
        </div>
    </section>

    <div class="sidebar-page-container">
    	<div class="auto-container">

        	<div class="row clearfix">

                <div class="content-side col-lg-8 col-md-12 col-sm-12">
                	<div class="shop-section">

                        <div class="our-shops">

                            <div class="row clearfix">
                            	<?php
			        $totalData = $db->query("SELECT COUNT(*) FROM posts WHERE categories={$categoriesDataCheck['categories_id']}")->fetchColumn();
			        $show = 99999;
			        $totalPage = ceil($totalData / $show);
			        $page = @$_GET["p"];
			        if($page < 1) $page = 1;
			        if($page > $totalPage){
			          $page = (int)$totalPage;
			        }
			        $limit = ($page - 1) * $show;
			        $data = $db->prepare("SELECT * FROM posts WHERE categories={$categoriesDataCheck['categories_id']} LIMIT :basla, :bitir");
			        $data->bindValue(":basla",$limit,PDO::PARAM_INT);
			        $data->bindValue(":bitir",$show,PDO::PARAM_INT);
			        $data->execute();
			        $sequence = $data->fetchAll(PDO::FETCH_OBJ);
						 if ($sequence == null) {
						 	echo '
							<div class="col-sm-12">
								<span class="alert alert-danger block">'.$langArray['NO_CONTENT'].'</span>
							</div>
							';
						 }
			        foreach ($sequence as $item){
			          $x = explode("/", $item->banner);
			          $y = explode('.', $x[1]);
								$homeProductsDetailAsk->execute(array(
			            'product_post_id'       => $item->post_id,
			          ));
			          $homeProductsDetailCheck=$homeProductsDetailAsk->fetch(PDO::FETCH_ASSOC);
			      ?>
                                <div class="shop-item col-lg-4 col-md-6 col-sm-12">
                                    <div class="inner-box">
                                        <div class="image">
                                            <img src="<?php echo $item->banner; ?>" alt="<?php echo $item->title; ?>" />
                                            <div class="overlay-box">
                                                <ul class="cart-option">
                                                    <li><a href="<?php echo  $item->seo_url; ?>"><span class="flaticon-eye"></span></a></li>

                                                </ul>
                                            </div>
                                        </div>
                                        <div class="lower-content clearfix">
                                        	<div class="pull-left">
                                            	<h6><a href="<?php echo $item->seo_url; ?>"><?php echo $item->title; ?></a></h6>
                                            </div><br>
                                            <div class="pull-right">
                                            	<ul class="price">
                                            		<?php
                if ($homeProductsDetailCheck['discount_price'] == "") {
                  $homeProductsDetailCheck['discount_price'] = 0;
                }
                $productVatRate = $homeProductsDetailCheck['vat'];
                $productPrice = $homeProductsDetailCheck['price'];
                $productPercentRate = $homeProductsDetailCheck['discount_price'];
                $disPriceRate = percentCalc($productPrice,$productPercentRate);
                $productDisTotal = $productPrice-$disPriceRate;
                if ($productVatRate>0) {
                  $disVatResult = addVat($productDisTotal,$productVatRate);
                  $vatResult = addVat($productPrice,$productVatRate);
                }else{
                  $disVatResult = $productDisTotal;
                  $vatResult = $productPrice;
                }
                ?>
                <?php if ($homeProductsDetailCheck['discount_price']) { ?>
                                                	<li><h6><del style="color:red;"><?php echo $vatResult; ?> <?php echo $homeProductsDetailCheck['currency']; ?></del>
                  <?php echo $disVatResult; ?> <?php echo $homeProductsDetailCheck['currency']; ?></h6>
                <?php }else{ ?></li>
                <li><h6><?php echo $vatResult; ?> <?php echo $homeProductsDetailCheck['currency']; ?></h6></li>
                                               <?php } ?>  </ul>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                 <?php } ?>


                            </div>

                        </div>

                       <!-- Post Share Options -->
						<div class="styled-pagination text-center">
							<ul class="clearfix">
							<?php for($i = 1; $i<=$totalPage;$i++){?>
			  					<li><a href="<?php echo $generalSettingCheck['site_url'] . $categoriesDataCheck['seo_url']; ?>?p=<?php echo $i;?>"><?php echo $i;?></a></li>
			          <?php } ?>
							</ul>
						</div>

                    </div>
                </div>

                <!--Sidebar Side-->
                <div class="sidebar-side col-lg-4 col-md-12 col-sm-12">
                	<aside class="sidebar sticky-top">

						<!-- Categories Widget -->
						<div class="sidebar-widget categories-widget">
							<div class="sidebar-title">
								<h4><?php echo $langArray['HEAD_CATEGORIES']; ?></h4>
							</div>
							<div class="widget-content">
								<?php
						 $allCategories = array();
						 $allCatCheck=$db->query("SELECT * FROM categories where language={$getLangCheck['language_id']} and categories_type='product_categories'", PDO::FETCH_ASSOC);
						 if ( $allCatCheck->rowCount() ){
							 foreach( $allCatCheck as $line ){
									$allCategories[$line['categories_id']]['categories_id'] = $line['categories_id'];
									$allCategories[$line['categories_id']]['title'] = $line['title'];
									$allCategories[$line['categories_id']]['categories_top_id'] = $line['categories_top_id'];
									$allCategories[$line['categories_id']]['seo_url'] = $line['seo_url'];
							 }
						 }
						 function findCategories($categories){
								$row = array();
								foreach($categories as $category){
									if($category['categories_top_id'] == 0) $row[] = $category;
								}
								return $row;
						 }
						 function findSubCategories($topCat,$categories,$again = 2){
								$row = array();
								foreach($categories as $category){
									if($category['categories_top_id'] == $topCat){
										$row[] = $category;
									}
								}
								if(count($row) > 0){
									foreach($row as $cat){
										echo '<li><a href="'.$cat['seo_url'].'">'.str_repeat('- ',$again).' '.$cat['title'].'</a></li>';
										findSubCategories($cat['categories_id'],$categories,$again+1);
									}
								}
						 }
						 $mainCategories = findCategories($allCategories);
						 echo '
							 <ul class="blog-cat">
						 ';
							foreach($mainCategories as $category){
								echo '
								 <li><a href="'.$category['seo_url'].'">'.str_repeat('- ',0).' '.$category['title'].'</a></li>
								';
								findSubCategories($category['categories_id'],$allCategories);
							}
						 echo '</ul>';
						?>
							</div>
						</div>
              <div class="broucher-info-widget">
                <div class="title-box">
                  <div class="title-inner">
                    <span class="icon flaticon-info"></span>
                    <?php echo $langArray['FRONT_CON_INFO']; ?>
                  </div>
                </div>
                <div class="lower-box">
                  <ul class="brouchers">
                           <li>
               <a href="tel:<?php echo $generalSettingCheck['contact_land_phone']; ?>"> <strong><?php echo $generalSettingCheck['contact_land_phone']; ?></strong></a> </li>
               <li>  <a href="tel:<?php echo $generalSettingCheck['contact_mobile_phone']; ?>"><strong><?php echo $generalSettingCheck['contact_mobile_phone']; ?></strong></a> </li>
                <li>  <a href="tel:<?php echo $generalSettingCheck['contact_fax']; ?>"> <strong><?php echo $generalSettingCheck['contact_fax']; ?></strong></a>
              </li>

                  </ul>
                </div>
              </div>
						
					</aside>
				</div>

			</div>
		</div>
	</div>
