Location: PHPKode > projects > CoreAsset > coreasset/export_book_history.php
<?php
require_once("lib/inc.php");
require_once("lib/security.php");
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Show Asset History :::";
$smarty->assign('title',$title);
//echo "bunti";
$date     = date("Y-m-d");
$status   = $_SESSION['status'];
$user_id  = $_SESSION['user_id'];
$smarty->assign('user_id',$user_id);	
$row      = $database->get_from_database("select * from asset_users where user_id='$user_id'");
$name     = $row['full_name'];
$rw		  = $database->get_from_database("select * from asset_users where user_id='$_SESSION[user_id]'");
$last_login  = $rw['last_login'];
$last_logout = $rw['last_logout'];
$smarty->assign('last_login',$last_login);
$smarty->assign('last_logout',$last_logout);

// Date & Time to be dispalyed on the header 
$date_time	= date("h:i:s A")." ".date("d-m-Y");
$smarty->assign('date_time',$date_time);

if($status < 4)
{
// Done
$res_cat=$database->get_from_database("select category_id from asset_category where category_name like 'book%';");
$cat_id_book		= $res_cat['category_id'];
//$query_cond	= "SELECT asset_tag FROM asset_assets where category_id !='$cat_id_book'";
$history="\n\n";
$res_asset=$database->Execute("SELECT * FROM asset_assets where category_id='$cat_id_book'");
while($row_asset = mysql_fetch_array($res_asset))
{
$asset_tag           = $row_asset['asset_tag'];
$history.="Asset Tag:\t".$asset_tag."\t";

$data				 = $database->get_from_database("SELECT * from asset_assets WHERE asset_tag='$asset_tag'");
$bk_id_list			 = explode(',',$data['equipment_id']); 
$count_book			 = count($bk_id_list);

$i=0;
if($count_book > 0)
{
 foreach($bk_id_list as $n=>$v)
 {
	$book_id						= $v;

	$b_nm							= $database->get_from_database("SELECT * FROM asset_books WHERE book_id='$book_id'");

	$book_name					= $b_nm['book_name'];
	$author						= $b_nm['author'];
	$publisher					= $b_nm['publisher'];
	$isbn_no					= $b_nm['isbn_no'];
	$price						= $b_nm['price'];

	$history.= "\n\t\tBook Name :".$book_name."\t ISBN No :".$isbn_no."\t"."Publisher :".$publisher."\tAuthor :".$author."\t"."Price : ".$price."\n\t\t";
	$history.="Issued To \t Issued On \t Return Date \n\t\t";

	$result         = $database->Execute("select * from asset_book_history where asset_tag='$asset_tag' and book_id='$book_id'");
	$count			= mysql_num_rows($result);

	while($rwrw = mysql_fetch_array($result))
	{
		$book_hist_id			= $rwrw['book_hist_id'];
		$assigned_userid		= $rwrw['assigned_userid'];

		if($assigned_userid > 0)
		{
			$u_nm							= $database->get_from_database("SELECT * FROM asset_users WHERE user_id='$assigned_userid'");
			$user_nm					= $u_nm['full_name'];
		}
		else
		{
			$user_nm					= "Not Assigned !";
		}

		$issued_on		= $rwrw['issued_on'];
		$return_date	= $rwrw['return_date'];
		$change_date	= $rwrw['change_date'];

		$history.=$user_nm." \t ".$issued_on." \t ".$return_date." \n\t\t";
	}
  }
  $history.="\n\n"; 
}
}
$fname	= "file/export_book_history.xls";
$handle = fopen ($fname, 'w+');
fwrite($handle, $history);
fclose($handle);

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=asset_history.xls");
readfile("$fname");

}
else
{
    redirect ("bookt_history.php","");
}

?>
Return current item: CoreAsset