<?php
require_once("db_conn_class.php");
require_once("common_slug_functions.php"); // ✅ added 
$blog_id         = 0;

$blog_desc       = "";
$written_by      = "";
$posting_dt      = "";
$blog_image_path = "";
$blogs = "";
$msg ="";
$flag = 0;
$no_of_blogs = 0;
if(isset($_GET['id']) && !empty($_GET['id'])) {
   $blog_id = $_GET['id'];
}
//creating object of database class
$dbh = new db_conn();
$dbh->set_conn();
//getting news id by explode function
$path = ltrim($_SERVER['REQUEST_URI'], '/');
//echo "path = ".$path;
$b = explode("/", $path);
$id = explode(".", $b[1]);
$b_url = explode("-", $id[0]);
//echo $id[0];
//return;
$b_id = $b_url[0];
$blog_t = $id[0];
$blog_id = $b_id;
$blog_t = explode($blog_id,$path);
$blog_tt =  explode('blog.php',$blog_t[1]);
$blog_ttt = substr($blog_tt[0],1);
$blog_tttt = rtrim($blog_ttt, "- ");
$blog_e = str_replace("-"," ",$blog_tttt);
//echo $b_url;
//return;
//query for fetching blog categories
$sql_cat = "select category_id, category from tbl_category where category_for = 'TTKolkata' and status = 'ACTIVE' and deleted = 0 ";
$sql_cat = $sql_cat . " order by category ";
//echo "sql_cat=".$sql_cat;
$result_cat = mysqli_query($dbh->link,$sql_cat);

if($result_cat)
{
	$no_of_cat = mysqli_num_rows($result_cat);
	  for($j=0; $j<$no_of_cat; $j++)  
	  {  
	  $rw_cat = mysqli_fetch_array($result_cat);
	  $category_id[$j] = $rw_cat['category_id'];
	  $category[$j] = $rw_cat['category'];
	  }
}
//==================================================================================================================

//==================================================================================================================
//fetching  blog from database
$sql_blogs = "select * from tbl_blogs ";
//$sql_blogs = $sql_blogs . " where status = 'ACTIVE' and blog_title = '".$blog_e."' and blog_type = 'TTHyderabad' and deleted = 0 and blog_id = ".$blog_id;
$sql_blogs = $sql_blogs . " where status = 'ACTIVE' and blog_type = 'TTKolkata' and deleted = 0 and blog_id = ".$blog_id;

//$sql_blogs = $sql_blogs . " and blog_title = ".$ ;
//echo "sql_blogs=".$sql_blogs;
//return;
$result_blogs = mysqli_query($dbh->link,$sql_blogs);
$no_of_blogs = mysqli_num_rows($result_blogs);
if($no_of_blogs>0)
{
	
	$flag= 1;
	$rw_blogs = mysqli_fetch_array($result_blogs);
	
	$blog_id         = $rw_blogs['blog_id'];
	$blog_title      = $rw_blogs['blog_title'];
	$blog_pre_desc   = $rw_blogs['blog_pre_desc'];
	$blog_desc       = $rw_blogs['blog_desc'];
	$written_by      = $rw_blogs['written_by'];
	$posting_dt      = $rw_blogs['posting_dt'];
	$blog_image_path = $rw_blogs['blog_image_path'];
	$meta_title      = $rw_blogs['meta_title'];
	$meta_desc       = $rw_blogs['meta_desc'];
	$og_title        = $rw_blogs['og_title'];
	$og_desc         = $rw_blogs['og_desc'];
	
	// $blog_title_url = str_replace(" ","-",$blog_title); 
	//  $blog_title_url = str_replace("&","-",$blog_title_url); 
	//  $blog_title_url = str_replace("(","",$blog_title_url); 
	//  $blog_title_url = str_replace(")","",$blog_title_url); 
	//  $blog_title_url = str_replace("?","",$blog_title_url);
	//  $blog_title_url = str_replace(":","",$blog_title_url);
	//  $blog_title_url = str_replace("'","",$blog_title_url);
	//  $blog_title_url = str_replace("!","",$blog_title_url);
	//  $blog_title_url = str_replace(";","",$blog_title_url);
	//  $blog_title_url = str_replace("_","",$blog_title_url);
	//  $blog_title_url = str_replace("–","",$blog_title_url);
	//  $blog_title_url = str_replace("/","",$blog_title_url);
	//  $blog_title_url = str_replace(",","",$blog_title_url);
	//  $blog_title_url = str_replace("’","",$blog_title_url);	
	
	 // ✅ NEW CLEAN CODE
    $blog_title_url = createSlug($blog_title);
		
}
else
{
 $flag = 0;
 $msg = "No Blogs Found";	
}	
//==================================================================================================================
//fetching latest blogs from database
$sql_blogs2 = "select * from tbl_blogs ";
$sql_blogs2 = $sql_blogs2 . " where status = 'ACTIVE' and blog_type = 'TTKolkata' and deleted = 0 ";
//if($blogs != "")
//{
//	$sql_blogs2 = $sql_blogs2 . " and blog_title like '%".$blogs."%'";
//}
$sql_blogs2 = $sql_blogs2 . " order by posting_dt DESC, blog_id DESC limit 6";
//echo "sql_blogs2=".$sql_blogs2;
$result_blogs2 = mysqli_query($dbh->link,$sql_blogs2);
if($result_blogs2)
{
	$no_of_blogs2 = mysqli_num_rows($result_blogs2);
	
	for($i=0; $i<$no_of_blogs2; $i++)
	{
		$rw_blogs2 = mysqli_fetch_array($result_blogs2);
		
		$blog_id2[$i]         = $rw_blogs2['blog_id'];
		$blog_title2[$i]      = $rw_blogs2['blog_title'];
		
	}	
}
?>