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

    }
    
//*************************************************************************************************************************************************
	function category()
	{
  		global $objSmarty;
  		$SelQuery3		= 'SELECT * FROM `book` WHERE `category` = "Childrens/Young Adults * Graphic Novel"';
		$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);
  return $PageList2;
  }
  elseif(empty($PageList2) && is_array($PageList2))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
 }

 function GetCartList($objArray = '')
    {
        global $objSmarty;
         $SelQuery5 = 'SELECT book_cart_temp.*, book.book_name,book.category,book.author,book.image,book.reading_charges,book.default_reading_days FROM book, book_cart_temp  WHERE book.id=book_cart_temp.book_id AND  member_id ="' . $_SESSION['User_ID'] . '" AND book.is_status="1"';
        $cartDet = $this->ExecuteQuery($SelQuery5, 'select');
        $objSmarty->assign('cartDet', $cartDet);

        $selBookCount='SELECT COUNT(*) AS CNT FROM book_cart_temp where `member_id`="' . $_SESSION['User_ID'] . '" and status="1" ';
        $BookCartCount=$this->ExecuteQuery($selBookCount, 'select');
        $objSmarty->assign('BookCartCount', $BookCartCount);
    }

/**********************************************************************************************/
function Getbooks()
{
global $objSmarty;
	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']."')";
}
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 * FROM `check_out_in_history` WHERE `category` = "'.$_GET['category'].'"';
		$listing_split = new MsplitPageResults($SelQuery2, $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'))));   $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');
}
/*************************************************************Update*************************************************************** */
// function ViewAddress()
// {
//     global $objSmarty;
//     $SelQuery = 'SELECT * FROM employee where `address`="' . $_SESSION['Address'] . '" and status="1" ';
//     $ViewAddress = $this->ExecuteQuery($SelQuery, "select");
//     $objSmarty->assign('ViewAddress', $ViewAddress);
//     return $ViewAddress;
// }
function AjaxUpdateAddress($objArray='')
{
    global $objSmarty;
     $UpQuery = 'UPDATE `members` SET `address`="' . trim($_POST['address']) . '" WHERE `member_code` = "' . $_SESSION['MemberCode'] . '"';
    $this->ExecuteQuery($UpQuery, "update");
}
/*********************************************************DELETE******************************************************************** */
public function DeleteID($objArray='')
{
    global $objSmarty,$_GET;
    $MemberId =$_GET['MemberId'];
     
    $DelQuery1 = 'DELETE FROM `book_cart_temp` WHERE `member_id`="' . $MemberId . '" AND book_id="'.$_GET['bookId'].'"';
    $this->ExecuteQuery($DelQuery1, 'delete');
    header('Location:myCart.php?q_mode=delete&MemberId='.$MemberId.'&message=success');
}
/*************************************************Check Out*********************************************************************** */
 function CheckoutMove($objArray='')
{


    $orderId = $_POST["order_id"];
    $SelQuery5 = 'SELECT * FROM book_cart_temp WHERE member_id="'.$_SESSION['User_ID'].'"';
    $BookCart=$this->ExecuteQuery($SelQuery5, 'select');

    $SelQueryCust = 'SELECT * FROM members WHERE id="'.$BookCart[0]['member_id'].'"';
    $CustomerDetails=$this->ExecuteQuery($SelQueryCust, 'select');

    foreach($BookCart as $keys=>$value)
		{
            $SelQuery = 'SELECT * FROM book WHERE id="'.$BookCart[$keys]['book_id'].'"';
            $BookDetails=$this->ExecuteQuery($SelQuery, 'select');


            echo $InsMaster = 'INSERT INTO customer_orders_master(member_name,
                                                            member_id,
                                                            member_code,
                                                            member_type,
                                                            mobile_number,
                                                            phone_number,
                                                            date_of_order,
                                                            `count`,
                                                            total_reading_charges,
                                                            delivery_charges,
                                                            other_charges,
                                                            delivery_date,
                                                            delivery_time,
                                                            return_date,
                                                            return_time,
                                                            total_cahrges                              
			                                                        	)
                VALUES("'.$CustomerDetails[0]['member_name'].'",
                "'.$CustomerDetails[0]['id'].'",
                "'.$CustomerDetails[0]['member_code'].'",
                "'.$CustomerDetails[0]['member_type'].'",
                "'.$CustomerDetails[0]['contact_number'].'",
                "'.$CustomerDetails[0]['phoneNo'].'",
                "'.$CustomerDetails[0]['date_of_order'].'",
                "'.$CustomerDetails[0]['count'].'",
                "'.$CustomerDetails[0]['total_reading_charges'].'",
                "'.$CustomerDetails[0]['delivery_charges'].'",
                "'.$CustomerDetails[0]['other_charges'].'",
                "'.$CustomerDetails[0]['delivery_date'].'",
                "'.$CustomerDetails[0]['delivery_time'].'",
                "'.$CustomerDetails[0]['return_date'].'",
                "'.$CustomerDetails[0]['return_time'].'",
                "'.$CustomerDetails[0]['total_cahrges'].'"
				)';exit;
                    $this->ExecuteQuery($InsMaster, 'insert');
		}

   
}

/****************************************Search Books******************************************************/
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.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.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 * 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_tab2',$listing_split3->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
  $objSmarty->assign('PerPageNavigation_amc_view_tab2',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');
}
/***********************************Cart List***********************************************************/
function searchbooks_wishlist()
{
global $objSmarty;
 $name= $_POST['search_text'];
// echo $name;
//cart table data check
	//$SelQuery4		= "SELECT * FROM `book` WHERE  book_name like '$name%' or author like '$name%' or isbn like '%$name%' "; 
		//$SelQuery4		= "SELECT * FROM `temp_cart` WHERE  session_id='".session_id()."' AND status='1'";
		if($_SESSION['User_ID'] != '')
            {
			$SelQuery4		= "SELECT * FROM `customer_orders_details` WHERE status='1' AND order_id IN(SELECT order_id FROM `customer_orders_master` WHERE record_status='1' AND member_id='".$_SESSION['User_ID']."' AND submit_status='0') ";
			}
			else
			{
			$SelQuery4		= "SELECT * FROM `customer_orders_details` WHERE status='1' AND order_id IN(SELECT order_id FROM `customer_orders_master` WHERE record_status='1' AND  submit_status='0') ";
			}
		$listing_split3 = new MsplitPageResults($SelQuery4, $this->Limit);
		
  if ( ($listing_split3->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab2',$listing_split3->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
  $objSmarty->assign('PerPageNavigation_amc_view_tab2',TEXT_RESULT_PAGE1 . ' ' . $listing_split3->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y'))));   $PageList4 = $this->ExecuteQuery($listing_split3->sql_query, 'selectassoc');
  }
   if(!empty($PageList4) && is_array($PageList4))
  {
  $objSmarty->assign('i', $listing_split3->i);
  $objSmarty->assign('PageList4', $PageList4);//print_r($PageList3);
  return $PageList4;
  }
  elseif(empty($PageList4) && is_array($PageList4))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
/*************************************Cart Detail*********************************************************/
function searchbooks_cart()
{
global $objSmarty;
 $name= $_POST['search_text'];
// echo $name;
//cart table data check
if($_SESSION['User_ID'] != '')
{
		$SelQuery4		= "SELECT * FROM `customer_orders_details` WHERE order_id IN(SELECT order_id FROM `customer_orders_master` WHERE record_status='1' AND member_id='".$_SESSION['User_ID']."' AND submit_status='0') ";
	}
	else
	{
		$SelQuery4		= "SELECT * FROM `customer_orders_details` WHERE order_id IN(SELECT order_id FROM `customer_orders_master` WHERE record_status='1' AND submit_status='0')";
	}
		$listing_split3 = new MsplitPageResults($SelQuery4, $this->Limit);
		
  if ( ($listing_split3->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab2',$listing_split3->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
  $objSmarty->assign('PerPageNavigation_amc_view_tab2',TEXT_RESULT_PAGE1 . ' ' . $listing_split3->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y'))));   $PageList4 = $this->ExecuteQuery($listing_split3->sql_query, 'selectassoc');
  }
   if(!empty($PageList4) && is_array($PageList4))
  {
  $objSmarty->assign('i', $listing_split3->i);
  $objSmarty->assign('PageList4', $PageList4);//print_r($PageList3);
  return $PageList4;
  }
  elseif(empty($PageList4) && is_array($PageList4))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
/*************************************Wish List Detail*********************************************************/
function wishlist()
{
global $objSmarty;
 $name= $_POST['search_text'];
// echo $name;
//cart table data check
	//$SelQuery4		= "SELECT * FROM `book` WHERE  book_name like '$name%' or author like '$name%' or isbn like '%$name%' "; 
		//$SelQuery6		= "SELECT * FROM `temp_cart` WHERE  session_id='".session_id()."' AND status='2' ";
		if($_SESSION['User_ID'] != '')
{
		$SelQuery6		= "SELECT * FROM `customer_wish_details` WHERE status='1' AND member_id='".$_SESSION['User_ID']."' ";
	}
	else
	{
		$SelQuery6		= "SELECT * FROM `customer_wish_details` WHERE status='1' ";
	}

		$listing_split6 = new MsplitPageResults($SelQuery6, $this->Limit);
		
  if ( ($listing_split6->number_of_rows > 0) )  {
   $objSmarty->assign('LinkPage_amc_view_tab2',$listing_split6->display_count (TEXT_DISPLAY_NUMBER_OF_RESULT));
  $objSmarty->assign('PerPageNavigation_amc_view_tab2',TEXT_RESULT_PAGE1 . ' ' . $listing_split6->display_links($this->Limit, get_all_get_params(array('page', 'info', 'x', 'y'))));   $PageList6 = $this->ExecuteQuery($listing_split6->sql_query, 'selectassoc');
  }
   if(!empty($PageList6) && is_array($PageList6))
  {
  $objSmarty->assign('i', $listing_split6->i);
  $objSmarty->assign('PageList6', $PageList6);//print_r($PageList3);
  return $PageList6;
  }
  elseif(empty($PageList6) && is_array($PageList6))
    $objSmarty->assign('ErrorMessage', 'No Records Found');
}
/**********************************************************************************************/
function orderofbooks()
{
global $objSmarty;

				if($_GET['type'] == "dateorder")
				{
		  			//cart table data check
	            $SelQuery5		= "SELECT * FROM `book` WHERE  emailid='' AND member_code='' order by cart_date";
				}
				elseif($_GET['type'] == "bookorder")
				{
				$SelQuery5		= "SELECT * FROM `book` WHERE  emailid='' AND member_code='' order by book_name";
				}
				elseif($_GET['type'] == "authororder")
				{
				$SelQuery5		= "SELECT * FROM `book` WHERE  emailid='' AND member_code='' order by author";
				}
				else
				{
				$SelQuery5		= "SELECT * FROM `book` WHERE  emailid='' AND member_code=''";
				}
				$ListView = $this->ExecuteQuery($SelQuery5, "select");
			    $objSmarty->assign('ListView', $ListView);
			    return $ListView;

 }
 
 }
 
?>


