Location: PHPKode > projects > CoreAsset > coreasset/export_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'];
$issued_userid 		 = $row_asset['issued_userid'];
$history.="Asset Tag:\t".$asset_tag."\t";
if($issued_userid == -1)
{
  $history.="[ In Store ]\t Not Issued Till Now\t";
}
else
{
  $history.="";
//  $issue_user = $database->get_from_database("select full_name from asset_users where user_id ='$issued_userid' ");
  //$issued_user = $issue_user['full_name'];
 // $history.="Issued to : ". $issued_user."\n\t";
}
$data				 = $database->get_from_database("SELECT equipment_id from asset_assets WHERE asset_tag='$asset_tag'");
$eq_id_list			 = explode(',',$data['equipment_id']); 

$serialno = array();
$maf = array();
$expr_dt = array();
$issued_nm = array();
$serial_id = array();

$rrrw = $database->Execute("select * from asset_serial_number where asset_id='$asset_tag'");
while($rwrw = mysql_fetch_array($rrrw))
{
	$serialno[]= $rwrw['serial_no'];
	$maf[]= $rwrw['manufacturer'];
	$expr_dt[]= $rwrw['expiry_date'];
	$serial_id[]  = $rwrw['serial_id'];
}


//array_pop($eq_id_list);
$count_equip		 = count($eq_id_list);
//print_r($eq_id_list);
for($i=0 ; $i<$count_equip ; $i++)
{
 	$serial_list	= $database->get_from_database("SELECT * from asset_serial_number WHERE equipment_id = '$eq_id_list[$i]' AND asset_id='$asset_tag'");
	$eq_serial		= $serialno[$i];
	$eq_manufac		= $maf[$i];
	$eq_warranty	= $expr_dt[$i];
	$issu_m			= $issued_nm[$i];
	
	$eq				= $database->get_from_database("SELECT * FROM asset_equipment WHERE equipment_id = '$eq_id_list[$i]'");
	$eq_name		= $eq['equipment_name'];
	$history.= "\n\t\tEquipment Name :".$eq_name."\t Serial No :".$eq_serial."\t"."Manufacturer :".$eq_manufac."\tWarranty :".$eq_warranty."\t"."\n\t\t";
	$history.="Old Status \t New Status \t Comment \t Date \t Issued To \n\t\t";
	//echo $history."<br>";
	$result         = $database->Execute("select * from asset_history where serial_id='$serial_id[$i]' and asset_tag='$asset_tag' order by history_id ASC");
	//echo "select * from asset_history where serial_id='$serial_id[$i]'";
	$count			= mysql_num_rows($result);
	//echo "--";
	if($count > 0)
	{
	  $count_inner[]		=$count;
	     while($row = mysql_fetch_array($result))
		{
			$issuduserid = $row['user_id'];
			if($issuduserid > 0)
			{
				$iss_nm = $database->get_from_database("select * from asset_users where user_id='$issuduserid'");
				$issued_nm = $iss_nm['full_name'];
			}
			else
			{
				$issued_nm = "None";
			}
			//$eq_id[]							= $row['equipment_id'];
			$old_stat							= $row['old_status'];
			$new_stat							= $row['new_status'];
			switch($old_stat)
			{
				case 1: $old_status			= "OK"; break;
				case 2: $old_status			= "Repairing"; break;
				case 3: $old_status			= "Obsolete"; break;
				default : $old_status		= "NA"; break;
			}
			switch($new_stat)
			{
				case 1: $new_status			= "OK"; break;
				case 2: $new_status			= "Repairing"; break;
				case 3: $new_status			= "Obsolete"; break;
				default : $new_status		= "NA"; break;
			}
		   $history.=$old_status."\t".$new_status."\t";
			$comment						= $row['reason'];
			$change_date                    = $row['change_date'];
		    $history.=$comment."\t".$change_date."\t".$issued_nm."\n\t\t";
		}
	}
	else
	{
		$count_inner[]		= 0;
		$history.="\tNot Available";
	}

}
$history.="\n";
}

//echo nl2br($history);
// Creating EXCEL file
	$fname	= "file/export_history.xls";
	$handle = fopen ($fname, 'w+');
	//fwrite($history);
	fwrite($handle, $history);
	fclose($handle);
	
	// Autometic donload section
	header("Content-type: application/vnd.ms-excel");
	header("Content-Disposition: attachment; filename=asset_history.xls");
	readfile("$fname");
}
else
{
	     redirect ("asset_history.php","");
}

?>
Return current item: CoreAsset