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


	}


  
//*************************************************************************************************************************************************
	function category()
	{
  		global $objSmarty;
  		//$SelQuery3		= 'SELECT * FROM `book` WHERE `category` = "book"';
	/*	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 ='Auto-Biography' and br.branch_name='".$_SESSION['branchname']."')";
}
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 ='Auto-Biography' ";
}*/
	  //  $SelQuery3 =	"select *,br.isbn,br.book_name from `book` br left join `images` b on br.isbn =b.isbn  where (b.category =  'book')";
	  $SelQuery3	= "select * from `book`  where category ='Auto-Biography' ";
		$listing_split2 = new MsplitPageResults($SelQuery3, $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')))); 
   $PageList2 = $this->ExecuteQuery($listing_split2->sql_query, 'selectassoc');
  }
   if(!empty($PageList2) && is_array($PageList2))
  {
  $objSmarty->assign('i', $listing_split2->i);
  $objSmarty->assign('PageList2', $PageList2);//print_r($PageList2);
  return $PageList2;
  }
  elseif(empty($PageList2) && is_array($PageList2))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
 }
/**********************************************************************************************/
function Getbooks()
{
     $this->Limit = 25;
global $objSmarty;
/*if($_SESSION['branchname'] != '')
{
 $SelQuery3	= "select *,br.book_id,b.book_name,b.isbn,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']."')";
}
else
{
 $SelQuery3	= "select *,br.book_id,b.book_name,b.isbn,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']."')";
}*/
 //	$SelQuery3 =	"select *,br.isbn,br.book_name from `book` br left join `images` b on br.isbn =b.isbn  where (br.category =  '".$_GET['category']."')";
  //$SelQuery2		= 'SELECT * FROM `book` WHERE `category` = "'.$_GET['category'].'"';
  
 
 if($_POST['search'] <> "")
 {
 $SelQuery3 = "SELECT * FROM book WHERE is_status='1' AND category LIKE '%".$_GET['category']."%' AND  (book_name like '%".$_POST['search']."%'   OR author like '%".$_POST['search']."%' OR publication like '%".$_POST['search']."%') ORDER BY book_name ASC";

   }
 else
 {


$SelQuery3	= "SELECT * FROM  `book` WHERE category LIKE '%".$_GET['category']."%'";
 }
	//$SelQuery3	= "select * from  `book` where category Like '%".$_GET['category']."%'";
		$listing_split = new MsplitPageResults($SelQuery3, $this->Limit);
  if ( ($listing_split->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage',$listing_split->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation',$listing_split->display_links_mod($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);
  return $PageList;
  }
  elseif(empty($PageList) && is_array($PageList))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
/**********************************************************************************************/
function GetCategorybooks()
{
global $objSmarty;
/*if($_SESSION['branchname'] != '')
{
 $SelQuery3 = "select *,br.book_id,b.book_name,b.isbn,b.category from `book_receipt` br left join `book` b on br.book_id =b.id where  (b.category ='".$_GET['name']."' and br.branch_name='".$_SESSION['branchname']."')";
 
}
else
{
 $SelQuery3	= "select *,br.book_id,b.book_name,b.isbn,b.category from `book_receipt` br left join `book` b on br.book_id =b.id where  b.category ='".$_GET['name']."' ";
}*/
 //	$SelQuery3 =	"select *,br.isbn,br.book_name from `book` br left join `images` b on br.isbn =b.isbn  where (br.category =  '".$_GET['category']."')";
	$SelQuery3		= 'SELECT * FROM `book` WHERE `category` Like "%'.$_GET['category'].'%"';
		$listing_split = new MsplitPageResults($SelQuery3, $this->Limit);
  if ( ($listing_split->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab2',$listing_split->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
   $objSmarty->assign('PerPageNavigation_amc_view_tab2',TEXT_RESULT_PAGE1 . ' ' . $listing_split->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y')))); 
   $PageListcat = $this->ExecuteQuery($listing_split->sql_query, 'selectassoc');
  }
   if(!empty($PageListcat) && is_array($PageListcat))
  {
  $objSmarty->assign('i', $listing_split->i);
  $objSmarty->assign('PageListcat', $PageListcat);
  return $PageListcat;
  }
  elseif(empty($PageListcat) && is_array($PageListcat))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}


/******************************************************************************************/
function weekauthor()
{
global $objSmarty;
//SET DATEFIRST { number | @number_var };
//SET DATEFIRST 7 ; 
/*$SelQuery3		='SELECT * FROM `check_out_in_history` AND WorkDate >= dateadd(day, 1-datepart(dw, getdate()), CONVERT(date,getdate())) AND WorkDate <  dateadd(day, 8-datepart(dw, getdate()), CONVERT(date,getdate()))';
$AutDetail		= $this->ExecuteQuery($SelQuery3, 'select');*/

// $SelQuery4		='SELECT * FROM `check_out_in_history` WHERE check_out_date >= DATEADD(wk, DATEDIFF((wk,0,GETDATE()), -1) AND check_out_date <= DATEADD(wk, DATEDIFF((wk,0,GETDATE()), 5) ';
//$AutDetail2		= $this->ExecuteQuery($SelQuery4, 'select');//print_r($AutDetail2);
}

/************************************************************************************/
function monthbooks()
{
 $SelQuery5		='SELECT * FROM `check_out_in_history` WHERE check_out_date Between DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AND DATE(NOW())';
$BookDetail2		= $this->ExecuteQuery($SelQuery4, 'select');//print_r($BookDetail2);

 $SelQuery6		='SELECT * FROM `check_out_in_history` WHERE check_out_date Between "CONVERT(DATE,dateadd(dd,-(day(getdate())-1),getdate()))" AND "DATE(NOW())"';
$BookDetail3		= $this->ExecuteQuery($SelQuery6, 'select');//print_r($BookDetail3);

 }
 /**********************************************************************************************/
function searchbooks()
{
global $objSmarty;
 $name= $_POST['search_text'];
// echo $name;
//cart table data check
if($_SESSION['branchname'] != '')
{
 $SelQuery4	= "select *,br.book_id,b.book_name,b.isbn,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.book_name like '$name%' or b.author like '$name%' or b.isbn like '%$name%' and br.branch_name='".$_SESSION['branchname']."')";
}
else
{
 $SelQuery4	= "select *,br.book_id,b.book_name,b.isbn,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.book_name like '$name%' or b.author like '$name%' or b.isbn like '%$name%')";
}

//$SelQuery4 =	"select *,br.isbn,br.book_name from `book` br left join `images` b on br.isbn =b.isbn  where (br.book_name like '$name%' or br.author like '$name%' or br.isbn like '%$name%')";
	//$SelQuery4		= "SELECT * FROM `book` WHERE  book_name like '$name%' or author like '$name%' or isbn like '%$name%' "; 
		$listing_split3 = new MsplitPageResults($SelQuery4, $this->Limit);
		
  if ( ($listing_split3->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab3',$listing_split3->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
  $objSmarty->assign('PerPageNavigation_amc_view_tab3',TEXT_RESULT_PAGE1 . ' ' . $listing_split3->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y'))));   $PageList3 = $this->ExecuteQuery($listing_split3->sql_query, 'selectassoc');
  }
   if(!empty($PageList3) && is_array($PageList3))
  {
  $objSmarty->assign('i', $listing_split3->i);
  $objSmarty->assign('PageList3', $PageList3);//print_r($PageList3);
  return $PageList3;
  }
  elseif(empty($PageList3) && is_array($PageList3))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}



/***********************************************INSERT CART***************************************************************************/
function AjaxInsertCart($objArray='')
{
global $objSmarty;

//$objSmarty->assign('bookName', $objArray['bookName']);
//echo "hi";exit;

$selQuery='SELECT DATE(NOW()) AS date ';
$date=$this->ExecuteQuery($selQuery,'select');
//print_r($_POST['book_id']);exit;
if($this->ChkDupliCart($_POST['user_id'],$_POST['book_id']))
		{
		 
$InsQuery = 'INSERT INTO book_cart_temp
(
`member_id`,
`member_code`,
`book_id`,
`book_taken_date`,
`book_category_name`
) 
VALUES(
"'.$_POST['user_id'].'",
"'.$_POST['member_code'].'",
"'.$_POST['book_id'].'",
"'.$date[0]['date'].'",
"'.$_POST['category_name'].'")';  
$this->ExecuteQuery($InsQuery, 'insert');


echo "Successfully Added";

}
    else
				{
					echo "Already Added";
        }
        
       
}
function AjaxCartCount($objArray='')
{
   $selCart='SELECT COUNT(*) AS CartCnt FROM book_cart_temp WHERE member_id="'.$_POST['user_id'].'"';
  $Cart=$this->ExecuteQuery($selCart,'select');
  echo $Cart[0]['CartCnt'];
}
public function ChkDupliCart($userId,$bookId)
			{
				global $objSmarty;
				if (!empty($userId)) {
				$SelQuery2 = 'SELECT * FROM `book_cart_temp` WHERE `member_id` = "' . $userId . '" AND book_id="'.$bookId.'" Limit 0,1';
				}
		
				$bookCartTemp = $this->ExecuteQuery($SelQuery2, 'select');
				if (!empty($bookCartTemp) && is_array($bookCartTemp)) {
					return false;
				} else {
					return true;
				}
		
			}

 }
?>


