<?php 
require "../commonincludefiles.php";
if($_SESSION["aCollegeId"]!="" && isset($_SESSION["aCollegeId"]))
{
	$action = Escape($_REQUEST['action']);
	$regId  = Escape($_REQUEST['regId']);
	$objBook = new BookMgmt();

	if($action=="language"){
		$result = $objBook->getDistinctLanguage();
		$total = dbRows($result);
		$i=0;
		$languageData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_language"]  = $row["book_language"];
				$languageData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($languageData);
	}
	else if($action=="category"){
		$result = $objBook->getDistinctCategory();
		$total = dbRows($result);
		$i=0;
		$categoryData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_category"]  = $row["book_category"];
				$categoryData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($categoryData);
	}
	else if($action=="name"){
		$result = $objBook->getDistinctName();
		$total = dbRows($result);
		$i=0;
		$nameData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_name"]  = $row["book_name"];
				$temparray["book_registerno"]  = $row["book_registerno"];
				$nameData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($nameData);
	}
	else if($action=="namesearch"){
		$result = $objBook->getBookNameByRegiste($regId);
		$total = dbRows($result);
		$i=0;
		$nameData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_name"]  = $row["book_name"];
				$temparray["book_registerno"]  = $row["book_registerno"];
				$nameData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($nameData);
	}
	else if($action=="edition"){
		$result = $objBook->getDistinctEdition();
		$total = dbRows($result);
		$i=0;
		$editionData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_edition"]  = $row["book_edition"];
				$editionData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($editionData);
	}
	else if($action=="author"){
		$result = $objBook->getDistinctAuthor();
		$total = dbRows($result);
		$i=0;
		$authorData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_author"]  = $row["book_author"];
				$authorData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($authorData);
	}
	else if($action=="publishername"){
		$result = $objBook->getDistinctPublisherName();
		$total = dbRows($result);
		$i=0;
		$publishernameData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["publisher_name"]  = $row["publisher_name"];
				$publishernameData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($publishernameData);
	}else if($action=="edition"){
		$result = $objBook->getDistinctEdition();
		$total = dbRows($result);
		$i=0;
		$editionData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_edition"]  = $row["book_edition"];
				$editionData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($editionData);
	}
	else{
		$result = $objBook->getDistinctVender();
		$total = dbRows($result);
		$i=0;
		$venderData = array("count" => $total, "rows" => array());
		if	(dbRows($result) > 0){
			$temparray = array();
			while($row = dbArray($result)){
				$temparray["book_vender"]  = $row["book_vender"];
				$venderData["rows"][$i] = $temparray;   
				$i++;
			}										
		}				   		 
 		echo json_encode($venderData);
	}
}
?>