<?php //require('includes/cmain.inc.php');?>

<?php
$url = explode('/', rtrim($_SERVER["REQUEST_URI"],"/")); 
//print_r($url);exit();
$count=count($url);
$urltag=str_replace('-',' ',trim($url[2]));
$urls= SITE_WS_PATH.'/'.$url[1];
$menuurl = ucwords(str_replace('-', ' ',$url[$count-1]));
//print_r($menuurl);exit();
if($menuurl!='Tags'){
$search_terms = explode(" ", $menuurl);
$sql_parts = array();
foreach ($search_terms as $term) {
    $sql_parts[] = "heading LIKE '%$term%'";
}
$sql_condition = implode(" OR ", $sql_parts);
}
else{
    $sql_condition=1;
}
//print_r("SELECT * FROM `tbl_blog`  where $sql_condition");exit();
$sqlmenu=db_query("SELECT * FROM `tbl_blog` where $sql_condition and status='1'");
$menu=mysqli_fetch_array($sqlmenu);
//print_r($menu);exit();
//print_r($menu['cat_name']);exit();
$titlekb = "Knowledge Base Tags";
$descriptionkb= "Knowledge Base Tags";
$keywordkb="Knowledge Base Tags";
?>
<?php include('header.php'); ?>

<?php

//------------ start of knowledge base------------------?>
<div id="content">
<br />
<div class="container">
 <ol class="alopshgv breadcrumb breadcrumb-arrow">
    <li><a href="<?php echo SITE_WS_PATH;?>"> Home </a></li>
  <li><a href="<?php echo SITE_WS_PATH.'/knowledge-base';?>"> Knowledge Base </a></li>
  <li><a href="<?php echo SITE_WS_PATH.'/knowledge-base/tags';?>">Tags </a></li>
  <li class="active"><span><?php if($menuurl!='Tags'){ echo $menuurl;}else{echo "";}?> </span></li>
</ol>
    <div class="col-md-12" style="margin-bottom:20px;" >
      <ol class="breadcrumb y">

<p class="rblo" style="font-weight:bold;margin-top:20px;margin-bottom:20px;">Tag : "<?php if($menuurl!='Tags'){echo $menuurl;}else{echo "All Tags";}?>"

</p>
</ol>
</div>
</div>
<div class="container">

<div class="col-md-12" >

<!--<ol class="breadcrumb y">
<p class="rblo">OUR RECENT BLOGS</p>
<?php 
/*$blogCount=mysql_query("SELECT catP_Name from tbl_blogcatp where status=1");
while($blogWs=mysqli_fetch_array($blogCount)){
	$blogCountA=mysql_query("SELECT cat_name from tbl_blog where cat_name LIKE '%$blogWs[catP_Name]%'");
    $count=0;
    while($blogW=mysqli_fetch_array($blogCountA)){
		$count++;
    } ?>
<li><a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.''.str_replace(" ","-",strtolower($blogWs['catP_Name']));?>" class="btn btn-primary hu"><?php echo $blogWs['catP_Name']; ?> ( <?php echo $count; ?> )</a></li>
   <?php } */?>
</ol>-->

<?php
$req = $_SERVER['HTTP_HOST'].''.$_SERVER['REQUEST_URI'];
$exsp = explode("=", $req);
$start =$exsp[1] ?? '';
$dsdsd = explode("/", $req);
$poison=$dsdsd[3] ?? '';
$poisonA=explode("?", $poison);
$poisonB=ucwords(str_replace("-"," ",$poisonA[0]));

$start = intval($start);
$pagesize = isset($pagesize)?intval($pagesize): 100;
$columns = "select * ";
$sql = " from `tbl_blog` ";
$sql .= " where $sql_condition and status='1'";
if($poisonB !=""){
  $sql .= "and heading LIKE '%$poisonB%'";
}
//$order_by == '' ? $order_by = ' `id`' : true;
//$order_by2 == '' ? $order_by2 = 'DESC' : true;
$sql_count = "select count(*) ".$sql; 
$sql .= "order by id DESC ";
$sql .= "limit $start, $pagesize ";
$sql = $columns.$sql;
$result = db_query($sql);
$reccnt = db_scalar($sql_count);
//print_r($sql);exit();
?>
<?php
if($start==0){
  $cnt=0;
}
else{
  $cnt=$start;
}
while($line_raw = mysqli_fetch_array($result)) {
  $cnt++;
@extract($line_raw);

?>
<div class="col-md-6"> 
  <div class="well bn">
      <div class="media">
      	<a class="pull-left" href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading)); ?>">
    		<img class="media-object" src="<?php echo SITE_WS_PATH."/uploaded_files/blog/original/".$blog_banner; ?>" alt="<?php echo $alt; ?>">
  		</a>
  	<div class="media-body">
  	 <ul class="list-inline list-unstyled">
  	 <!--<p class="text-right"><?php //echo $post_writer; ?></p>-->
  	
  			
           <?php $fetchSQL = mysqli_fetch_array(db_query("SELECT cat_name from tbl_blog where id='$id' "));
	 $items= explode(",", $fetchSQL['cat_name']); 
	foreach($items as $value){ 
	$dynamicURL= SITE_WS_PATH.'/knowledge-base/'.strtolower(str_replace(" ","-",$value));
    echo "<a href='$dynamicURL' class='btn btn-xs btn-primary'>".$value."</a>";   ?>  
	<?php
	}
	?>
		 
	</ul>
	<h1 class="media-heading hjk"><a style="text-decoration:none;" href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading)); ?>"> <?php echo substr(strip_tags(ucwords($heading)), 0, 38).'...'?></a></h1>
          
          <p><?php echo substr(strip_tags(($line_raw['content'])), 0, 100).'...'; ?></p>
          <p class="readmm"><a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($heading));  ?>">Read more <i class="fa fa-angle-right"></i></a></p>
	
	
    </div>
    </div>
  </div>
  </div>
<?php }?>
</div>
<!--<div class="col-lg-3 right-form">
<div class="list-group" style="border-radius: 4px;">
 <ol class="breadcrumb" style="    background: #8e8d8d; color: #fff;  font-size: x-large;">Latest Blog</ol>
  <?php $sql123 =db_query("select heading from tbl_blog where status=1 order by id DESC limit 10");
        while ($ddd = mysqli_fetch_array($sql123)) { ?>
        <a href="<?php echo SITE_WS_PATH.'/knowledge-base/'.$serviceUri=str_replace(" ", "-",strtolower($ddd['heading'])); ?>" class="list-group-item" style="line-height: 2em;"><i class="fa fa-link" aria-hidden="true"></i> <?php echo ucfirst(substr($ddd['heading'], 0, 30)).'...';?></a>  
   <?php } ?>
</div>
</div> -->

</div>
</div>
<?php include('footer.php'); ?>