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

<?php
if($_REQUEST['registerid']=="" && $_REQUEST['bookdate_from']=="" && $_REQUEST['bookdate_to']=="")
{
?>
	<script language="javascript" type="text/javascript">
		location.href='report-form-book-cancel.php';
	</script>
<?php
}
elseif($_SESSION['aCollegeId']!="" && isset($_SESSION['aCollegeId'])){
			$header_row_string = "Report Book Cancelation";
			$title_array = array();
			$title_array[0] = "Book Reg.No,center,10%";
			$title_array[1] = "Book Name,left,30%";
			$title_array[2] = "Cancel Date,center,30%";
			$title_array[3] = "Reason,left,30%";
			
			$register  = Escape($_REQUEST['registerid']);
			
			$date_from = Escape($_POST['bookdate_from']);
			$date_to   = Escape($_POST['bookdate_to']);
				
			$condition = " school_id = '".$_SESSION['aCollegeId']."' AND book_active='0' ";
		
		if($register != ""){
		  $condition .= " and book_registerid >= '$register' ";
	    }
		                  
		if($date_from != "From"){
			$date_from=DateConversion(Escape($_POST['bookdate_from']),"Y-m-d","d/m/Y");
		    $condition .= " and book_canceldate >= '$date_from' ";
	     }
 	    if($date_to != "To"){
			$date_to=DateConversion(Escape($_POST['bookdate_to']),"Y-m-d","d/m/Y");
			$condition .= " and book_canceldate <= '$date_to' ";
	     }
		
		$obj = new Query2Report();
		$obj->reportid="report-table";
		
		$obj->createHeaderRow($header_row_string);
		 $header_row_string = "";
		
		$query = "SELECT book_id,book_name,DATE_FORMAT(book_canceldate,'$SQLDateFormat'),book_comment from lms_bookmaster where ".$condition;
		$obj->generateReport($query,$title_array);
		
		$obj->displayReportData();
	 if($obj->rowCount>0)
		{	
			$HtmlUrl 	=	"book-cancel-report-". $_SESSION["aUserId"].".html";
			$HtmlPath 	=	"../report/".$HtmlUrl;
			
			$obj->setHtmlUrl($HtmlUrl);
			$obj->setHtmlPath($HtmlPath); 	
			$obj->saveReportData();	
			
		?>
		<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>";
			}
	} ?>
</div>
<?php require "../_footer.php";?>