<?php require "../_header.php";?>
<div id="main-report" align="center">

<?php
if($_REQUEST['registerid']=="")
{
?>
	<script language="javascript" type="text/javascript">
		location.href='report-form-book-register.php';
	</script>
<?php
}
elseif($_SESSION['aCollegeId']!="" && isset($_SESSION['aCollegeId'])) 
{
		$header_row_string = "<u>Report Book Register</u>";
		$title_array = array();
		$title_array[0] = "Book Reg.No,center,5%";
		$title_array[1] = "Book Name,left,15%";
		$title_array[2] = "Author,left,15%";
		$title_array[3] = "Publisher Name,left,13%";
		$title_array[4] = "Publisher Address,left,13%";
		$title_array[5] = "Pages,right,5%";
		$title_array[6] = "Book Category,left,10%";
		$title_array[7] = "Language,left,5%";
		$title_array[8] = "Rack No,left,5%";
		$title_array[9] = "Purchase Date,center,5%";
		$title_array[10] = "Price,right,9%";
		
		$condition = " school_id = '".$_SESSION['aCollegeId']."' AND book_active='1' ";
		
		if($_REQUEST['registerid']!=""){
			$condition .= " AND book_registerid = '".Escape($_REQUEST['registerid'])."' ";
		}
		if($_REQUEST['book_from']!=""){
			$purchase_from = DateConversion(Escape($_REQUEST['book_from']),"Y-m-d","d/m/Y");
			$condition .= " AND book_gift = 'Purchase' AND book_purchasedate >= '$purchase_from' ";
		}
		if($_REQUEST['book_to']!=""){
			$purchase_to = DateConversion(Escape($_REQUEST['book_to']),"Y-m-d","d/m/Y");
			$condition .= " AND book_purchasedate <= '$purchase_to' ";
		}
		
		$obj = new Query2Report();
		$obj->reportid="report-table";
		
		$obj->createHeaderRow($header_row_string);
		
		$query = "SELECT book_id,book_name,book_author,book_publishername,book_publisheradd,book_pageno,book_category,book_language,
			book_rack,DATE_FORMAT(book_purchasedate,'$SQLDateFormat'),book_price from lms_bookmaster where ".$condition;
				
		$obj->generateReport($query,$title_array);
		
		$obj->displayReportData();
	
		if($obj->rowCount>0)
		{	
		  	$HtmlUrl 	=	"book-register-report-". $_SESSION["aUserId"].".html";
			$HtmlPath 	=	"../report/".$HtmlUrl;
		
			createHTMLReportPage($header_row_string,$HtmlUrl,$HtmlPath,$HtmlCode);  ?>
		
		<script type="text/javascript">
		Ext.onReady(function(){
			 var grid = new Ext.ux.grid.TableGrid("report-table", {
					stripeRows: true // stripe alternate rows
				});
				grid.render();
		});
		</script>
		<br/>
<form name="frm" id="frm" action="" method="post">		
	<input type="hidden" name="txtFile" id="txtFile" value="<?php echo $HtmlUrl ;?>" />
	<input type="button" name="btnPdf" id="btnPdf" value="Create PDF" onclick="SetPageAction('PDF');"/>
	<input type="button" name="btnHtml" id="btnHtml" value="Create HTML" onclick="SetPageAction('HTML');"/>
	<input type="button" name="btnWord" id="btnWord" value="Create WORD" onclick="SetPageAction('WORD');"/>
	<input type="button" name="btnExcel" id="btnExcel" value="Create EXCEL" onclick="SetPageAction('Excel');"/>
</form>
<script language="javascript" type="text/javascript">
	function SetPageAction(varAction) {
		if(varAction=="PDF"){			
			document.frm.action="../convertpdf/create-pdf.php";
			document.frm.target = "_blank";
			document.frm.submit();
		}
		else if(varAction=="HTML"){
			document.frm.action="<?php echo $HtmlPath ;?>";
			document.frm.target = "_blank";
			document.frm.submit();
		}
		else if(varAction=="WORD"){
			document.frm.action="../convertword/create-word.php";
			document.frm.target="_blank";
			document.frm.submit();
		}
		else if(varAction=="Excel"){
			document.frm.action="../convertword/create-excel.php";
			document.frm.target="_blank";
			document.frm.submit();
		}
	}
</script>
		<?php 
		} else
			{
				echo "<br/><b>No Data Found</b>";
			}
	}else {
       echo "Session Expired"; 
      } ?>
</div>
<?php require "../_footer.php";?>