<?php
header('Access-Control-Allow-Origin: *');
class indexservice{
function __construct($conn){
$this->mySQLConn=$conn;
}

function in_news(){
	$categoryData=array();
	$category="SELECT ns_id,title,date_format(newsdatetime,'%d-%b-%Y ') as newsdatetime,imagename,smalldescp,SUBSTRING(newscontent,1,300) as newscontent FROM tbl_news order by ns_id desc limit 6";
	$categoryquery=mysqli_query($this->mySQLConn,$category);
	$rows=mysqli_num_rows($categoryquery);
	if($rows>0){
		while($row=mysqli_fetch_array($categoryquery,MYSQLI_ASSOC)){
                        $row['newscontent']=str_replace("^","'",html_entity_decode($row['newscontent']));
			$categoryData[]=str_replace("^","'",$row);		
		}
	}
	return $categoryData;
}

function news(){
	$categoryData=array();
	$category="SELECT ns_id,title,date_format(newsdatetime,'%d-%b-%Y ') as newsdatetime,SUBSTRING(newscontent,1,400) as newscontent FROM tbl_news order by ns_id desc";
	$categoryquery=mysqli_query($this->mySQLConn,$category);
	$rows=mysqli_num_rows($categoryquery);
	if($rows>0){
		while($row=mysqli_fetch_array($categoryquery,MYSQLI_ASSOC)){
			$row['newscontent']=str_replace("^","'",html_entity_decode($row['newscontent']));
			$categoryData[]=str_replace("^","'",$row);		
		}
	}
	return $categoryData;
}

function news1($id){
	
	$categoryData=array();
	$category="SELECT ns_id,title,date_format(newsdatetime,'%d-%b-%Y ') as newsdatetime,newscontent FROM tbl_news where ns_id='".$id."' order by ns_id desc";
	$categoryquery=mysqli_query($this->mySQLConn,$category);
	$rows=mysqli_num_rows($categoryquery);
	if($rows>0){
		while($row=mysqli_fetch_array($categoryquery,MYSQLI_ASSOC)){
			$row['newscontent']=str_replace("^","'",html_entity_decode($row['newscontent']));
			$categoryData[]=str_replace("^","'",$row);		
		}
	}
	return $categoryData;
}

function newsdate(){
	
	$categoryData=array();
	$category="SELECT distinct date_format(newsdatetime,'%Y') as ndate FROM tbl_news";
	$categoryquery=mysqli_query($this->mySQLConn,$category);
	$rows=mysqli_num_rows($categoryquery);
	if($rows>0){
		while($row=mysqli_fetch_array($categoryquery,MYSQLI_ASSOC)){
			$categoryData[]=str_replace("^","'",$row);		
		}
	}
	return $categoryData;
}


}
?>