<?php
#####Class For Adding Content Management ######
class Index extends MysqlFns
{
 /* class constructor */
	function Index()
	{
 		$this->LDDisplayPath= $config['SiteGlobalPath']."class.Index.php";
  		global $config;
  		global $objSmarty;
  		$this->MysqlFns();
  		$this->Limit = 12;
		
		
  }
  

//*************************************************************************************************************************************************
	function category()
	{
  		global $objSmarty;
  	$SelQuery2		= 'SELECT * FROM `book` WHERE `is_deleted` = "0" AND new_book_alert="1" order By id DESC';
		$listing_split = new MsplitPageResults($SelQuery2, $this->Limit);
  if ( ($listing_split->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab',$listing_split->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation_amc_view_tab',TEXT_RESULT_PAGE1 . ' ' . $listing_split->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y')))); 
   $PageList = $this->ExecuteQuery($listing_split->sql_query, 'selectassoc');
  }
   if(!empty($PageList) && is_array($PageList))
  {
  $objSmarty->assign('i', $listing_split->i);
  $objSmarty->assign('PageList', $PageList);//print_r($PageList);
  return $PageList;
  }
  elseif(empty($PageList) && is_array($PageList))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
 }
/************************************For Best Reading Books**********************************************************/
function Getbooks()
{
global $objSmarty;
$date = date("F 1, Y", strtotime("-6 months"));//echo $date;
$date3 = date('Y-m-d', strtotime($date));//echo $date3;
$date2 = date("Y-m-d");//echo $date2;
if($_SESSION['branchname'] != '')
{
 //$SelQuery2	= "select *,br.book_id,b.book_name,b.category from `book_receipt` br left join `book` b on br.book_id =b.id left join `images` m on m.isbn =b.isbn  where (b.category ='".$_GET['category']."' and br.branch_name='".$_SESSION['branchname']."')";
 
 $SelQuery2	= "select *,COUNT(ch.book_id) as cnt,ch.book_id,ch.book_receipt_id,b.book_name,b.category,b.author from `check_out_in_history` ch left join `book` b on ch.book_id =b.id where b.category like '%".$_GET['category']."%' and ch.branch='".$_SESSION['branchname']."' and ((ch.check_out_date between '$date3' and '$date2') or(ch.actual_check_in_date between '$date3' and '$date2')) GROUP BY ch.book_id HAVING COUNT(ch.book_id) > 1  ORDER BY cnt DESC ";
}
else
{
 //$SelQuery2	= "select *,br.book_id,b.book_name,b.category from `book_receipt` br left join `book` b on br.book_id =b.id left join `images` m on m.isbn =b.isbn  where (b.category ='".$_GET['category']."')";
 
   $SelQuery2	= "select *,COUNT(ch.book_id) as cnt,ch.book_id,ch.book_receipt_id,b.book_name,b.category,b.author from `check_out_in_history` ch left join `book` b on ch.book_id =b.id where b.category like '%".$_GET['category']."%' and ((ch.check_out_date between '$date3' and '$date2') or(ch.actual_check_in_date between '$date3' and '$date2')) GROUP BY ch.book_id HAVING COUNT(ch.book_id) > 1  ORDER BY cnt DESC ";
}
//"select *,br.book_id,b.book_name from `book_receipt` br left join `book` b on br.book_id =b.id left join `images` m on m.isbn =b.isbn  where (b.book_name like  '".$_POST['search_value']."%' or b.author like  '".$_POST['search_value']."%' or b.isbn like  '".$_POST['search_value']."%')";
  	// $SelQuery2		= 'SELECT * FROM `book` WHERE `category` = "'.$_GET['category'].'"';
		$listing_split = new MsplitPageResults($SelQuery2, $this->Limit);
  if ( ($listing_split->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab',$listing_split->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation_amc_view_tab',TEXT_RESULT_PAGE1 . ' ' . $listing_split->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y')))); 
   $PageList2 = $this->ExecuteQuery($listing_split->sql_query, 'selectassoc');
  }
   if(!empty($PageList2) && is_array($PageList2))
  {
  $objSmarty->assign('i', $listing_split->i);
  $objSmarty->assign('PageList2', $PageList2);//print_r($PageList2);
  //return $PageList;
  }
  elseif(empty($PageList2) && is_array($PageList2))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
/**************************************Best reading books default********************************************************/
function Getbooksdefault()
{
global $objSmarty;
$date = date("F 1, Y", strtotime("-6 months"));//echo $date;
$date3 = date('Y-m-d', strtotime($date));//echo $date3;
$date2 = date("Y-m-d");//echo $date2;
if($_SESSION['branchname'] != '')
{
 //$SelQuery3	= "select *,br.book_id,b.book_name,b.category from `book_receipt` br left join `book` b on br.book_id =b.id left join `images` m on m.isbn =b.isbn  where (b.category like  'fiction%' and br.branch_name='".$_SESSION['branchname']."')";
 
 $SelQuery3	= "select *,COUNT(ch.book_id) as cnt,ch.book_id,ch.book_receipt_id,b.book_name,b.category,b.author from `check_out_in_history` ch left join `book` b on ch.book_id =b.id where b.category like  'fiction%' and ch.branch='".$_SESSION['branchname']."' and ((ch.check_out_date between '$date3' and '$date2') or(ch.actual_check_in_date between '$date3' and '$date2')) GROUP BY ch.book_id HAVING COUNT(ch.book_id) > 1  ORDER BY cnt DESC ";
}
else
{
// $SelQuery3	= "select *,br.book_id,b.book_name,b.category from `book_receipt` br left join `book` b on br.book_id =b.id left join `images` m on m.isbn =b.isbn  where (b.category like  'fiction%')";
 
  $SelQuery3	= "select *,COUNT(ch.book_id) as cnt,ch.book_id,ch.book_receipt_id,b.book_name,b.category,b.author from `check_out_in_history` ch left join `book` b on ch.book_id =b.id where b.category like  'fiction%' and ((ch.check_out_date between '$date3' and '$date2') or(ch.actual_check_in_date between '$date3' and '$date2')) GROUP BY ch.book_id HAVING COUNT(ch.book_id) > 1  ORDER BY cnt DESC ";

}
  	// $SelQuery3		= 'SELECT * FROM `book` WHERE `category` Like "fiction%"';
	$listing_split = new MsplitPageResults($SelQuery3, $this->Limit);
  if ( ($listing_split->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab',$listing_split->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation_amc_view_tab',TEXT_RESULT_PAGE1 . ' ' . $listing_split->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y')))); 
   $PageList3 = $this->ExecuteQuery($listing_split->sql_query, 'selectassoc');
  }
   if(!empty($PageList3) && is_array($PageList3))
  {
  $objSmarty->assign('i', $listing_split->i);
  $objSmarty->assign('PageList3', $PageList3);//print_r($PageList2);
  //return $PageList;
  }
  elseif(empty($PageList3) && is_array($PageList3))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
//*************************************************************************************************************************************************
	function book_detail()
	{
  		global $objSmarty;
  		$SelQuery1		= 'SELECT * FROM `book` WHERE `book_name` = "'.$_GET['bk_name'].'"';
		$listing_split2 = new MsplitPageResults($SelQuery1, $this->Limit);
  if ( ($listing_split2->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab',$listing_split2->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation_amc_view_tab',TEXT_RESULT_PAGE1 .' '. $listing_split2->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y'))));   $PageList3 = $this->ExecuteQuery($listing_split2->sql_query, 'selectassoc');
  }
   if(!empty($PageList3) && is_array($PageList3))
  {
  $objSmarty->assign('i', $listing_split2->i);
  $objSmarty->assign('PageList3', $PageList3);
  return $PageList3;
  }
  elseif(empty($PageList3) && is_array($PageList3))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
 }
 /****************************************New Books *****************************************************************************/
 function new_books()
	{
  		global $objSmarty;
  	$SelQuery		= 'Select * from book where new_book_alert=1 ORDER BY date_of_arrival_new DESC Limit 0,5';
	$NewBookDetail	= $this->ExecuteQuery($SelQuery, 'select');
    $objSmarty->assign('NewBookDetail', $NewBookDetail);//print_r($RecDetail);
 }
  /****************************************Famous Author *****************************************************************************/
 function famous_authors()
	{
  		global $objSmarty;
  	$SelQuery		= 'SELECT coih.book_id, count(coih.book_id) as cnt, book.author FROM check_out_in_history coih, book where book.id=coih.book_id and not coih.book_id="108259" group by book.author order by cnt DESC LIMIT 0, 104';
	$FamousAuthDetail	= $this->ExecuteQuery($SelQuery, 'select');
    $objSmarty->assign('FamousAuthDetail', $FamousAuthDetail);//print_r($RecDetail);
 }
 /*********************************************************************************************************************/
 function recom_books()
	{
  		global $objSmarty;
  	$SelQuery2		= 'SELECT * FROM `recommended_books` WHERE `status` = "1" ORDER BY timestamp DESC';
	$RecDetail	= $this->ExecuteQuery($SelQuery2, 'select');
    $objSmarty->assign('RecDetail', $RecDetail);//print_r($RecDetail);
 }
 
 function media_list()
 {
 global $objSmarty;
 
 $UpQuery5 = 'SELECT * FROM `media` WHERE `status` = "1" ';
 $BookDetail3 =	$this->ExecuteQuery($UpQuery5, 'select');//print_r($BookDetail3);
 $objSmarty->assign('BookDetail3', $BookDetail3);
 }
 /*********************************************************************************************************************/
 function our_services()
	{
  		global $objSmarty;
  	$SelQuery2		= 'SELECT * FROM `services` WHERE `status` = "1" ';
	$SerImgDetail	= $this->ExecuteQuery($SelQuery2, 'select');
    $objSmarty->assign('SerImgDetail', $SerImgDetail);//print_r($PageList);
	
	$SelQuery22		= 'SELECT * FROM `services` WHERE `status` = "2" ';
	$SerImgDetail2	= $this->ExecuteQuery($SelQuery22, 'select');
    $objSmarty->assign('SerImgDetail2', $SerImgDetail2);
 }

 }
?>

