Location: PHPKode > projects > CoreAsset > coreasset/edit_asset.php
<?php
require_once("lib/inc.php");
require_once("lib/security.php");

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Edit Asset :::";
$smarty->assign('title',$title);
// 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);
// Done
$asset_manufacturer = "";
$vendor_id = "";
$u_id = "";
$img_nm = "";
$date     = date("Y-m-d");
$smarty->assign('cur_date',$date);
$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);

if($status < 4)
{

//*********************************** Getting User Lists *************************************************
  $res3          = $database->Execute("select * from asset_users");
  while($row3    = mysql_fetch_array($res3))
  {
   $userid[]                          = $row3['user_id'];
   $full_name[]                       = $row3['full_name'];
  }
  $smarty->assign("userid",$userid);
  $smarty->assign("full_name",$full_name);
// *********************************************************************

  if(isset($_GET['hd83___2y8dh328f____8hhdiw___jd9']))
  {
   $asset_tag           = $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
   $row                 = $database->get_from_database("select * from asset_assets where asset_tag='$asset_tag'");

//   $asset_manufacturer  = $row['asset_manufacturer'];
   $asset_nickname      = $row['asset_nickname'];
   $po_no               = $row['po_no'];
   $asset_price         = $row['asset_price'];
   $asset_description   = $row['asset_description'];
   $receive_date        = $row['receive_date'];
   $vendorid            = $row['vendor_id'];
   $equipmentid         = $row['equipment_id'];
   $attachment_name     = $row['attachment_name'];
   
   $ext_arr = explode(".",$attachment_name);
   $siz = sizeof($ext_arr);
   $ext = $ext_arr[$siz-1];
   
   if(($ext=="htm") || ($ext=="html"))
   {
		$img_nm = "images/i_doc.gif";
   }
   else if(($ext=="csv") || ($ext=="xls"))
   {
		$img_nm = "images/e_doc.gif";
   }
   else if($ext=="txt")
   {
		$img_nm = "images/t_doc.gif";
   }
   else if($ext=="doc")
   {
		$img_nm = "images/w_doc.gif";
   }
   else if($ext=="pdf")
   {
		$img_nm = "images/p_doc.gif";
   }
   	

//   $u_id                = $row['issued_userid'];
// *******************  GETTING VENDOR INFORMATION ***********************************************************
   $vend_id               = $row['vendor_id'];
   $row3                  = $database->get_from_database("select * from asset_vendor where vendor_id='$vend_id'");
   $vendor_name           = $row3['vendor_name'];

   // *******************  GETTING EQUIPMENT INFORMATION *********************************************************
   $eq_id                 = $row['equipment_id'];
   $eq                    = explode(",",$eq_id);

   $manufacturer		=array();
   $expiry_date			=array();
   $depreciation    	=array();
   $eq_price            =array();
   $eq_status           =array();

   foreach($eq as $n=>$v)
   {
    if($v!="")
    {
     $row4				= $database->get_from_database("select * from asset_equipment where equipment_id='$v'");
     $equipment_name[]	= $row4['equipment_name'];
	 $equipment_model[] = $row4['equipment_model'];
	}
   }
	 $res5			   = $database->Execute("select * from asset_serial_number where asset_id='$asset_tag'");
     while($row5	   = mysql_fetch_array($res5))
     {
		 $serial_no[]		= $row5['serial_no'];
		 $manufacturer[]	= $row5['manufacturer']; 
		 $serial_id[]		= $row5['serial_id'];
		 $expiry_date[]		= $row5['expiry_date'];
//		 $depreciation[]	= $row5['depreciation'];
		 $eq_price[]		= $row5['equip_price'];
		 $eq_status[]		= $row5['status'];
		 $issud_userid[]	= $row5['issud_userid'];
	 }
	 
   $smarty->assign('asset_tag',$asset_tag);

   $smarty->assign('asset_manufacturer',$asset_manufacturer);
   $smarty->assign('asset_nickname',$asset_nickname);
   $smarty->assign('serial_no',$serial_no);
   $smarty->assign('serial_id',$serial_id);
   $smarty->assign('man',$manufacturer);
   $smarty->assign('expiry_date',$expiry_date);
//   $smarty->assign('depreciation',$depreciation);
   $smarty->assign('eq_price',$eq_price);
   $smarty->assign('eq_status',$eq_status);

   //$smarty_assign('manufacturer',$manufacturer);
   $smarty->assign('po_no',$po_no);
   $smarty->assign('asset_price',$asset_price);
   $smarty->assign('asset_description',$asset_description);
   $smarty->assign('receive_date',$receive_date);
   $smarty->assign('vendor_id',$vendor_id);
   $smarty->assign('equi_id',$eq_id);
   $smarty->assign('vendor_name',$vendor_name);
   $smarty->assign('equipment_name',$equipment_name);
   $smarty->assign('issud_userid',$issud_userid);
   $smarty->assign('equipment_model',$equipment_model);
   $smarty->assign('attachment_name',$attachment_name);
   $smarty->assign('u_id',$u_id);
   $smarty->assign('img_nm',$img_nm);
  }

  if(isset($_GET['act']))
  {
   if($_GET['act']=="edit")
   {
   $asset_tag           = $_POST['asset_tag'];
   $asset_manufacturer  = $_POST['asset_manufacturer'];
   $asset_nickname      = $_POST['asset_nickname'];
   $iss_userid		    = $_POST['iss_userid'];
   $po_no               = $_POST['po_no'];
   $asset_price         = $_POST['asset_price'];
   $asset_description   = $_POST['asset_description'];
   $receive_date        = $_POST['receive_date'];
   $vendorid            = $_POST['vendor_id'];
   $serialid			= $_POST['serial_id'];
   $equip_id_arr        = explode(',',$_POST['equi_id']);
   $serial_no			= $_POST['serial'];
   $manufacturer		= $_POST['asset_manufacturer'];
   $u_id                = $_POST['issued_userid'];
   $depreciation        = $_POST['depre'];
   $eq_price            = $_POST['eq_price']; 
   $attachment_name		= $_FILES['attachment_name']['name'];
  // print_r($serialid);
  // echo sizeof($serialid);
  //echo "kdflkf="; echo $u_id;
    
	if($database->update("update asset_assets set asset_nickname='$asset_nickname', asset_price='$asset_price', asset_description='$asset_description', receive_date='$receive_date', attachment_name='$attachment_name'  where asset_tag='$asset_tag'"))
    {
	 $price_total=0;
	for($i=0; $i<sizeof($serialid); $i++)
	  {
	   //echo $eq_price[$i];
	   //echo "asset_tag=";echo $asset_tag;echo "<br>";
	   $exp_dt="exp_date".$i;
	   $rsn	= "Newly Edited";

	   $database->update("UPDATE asset_serial_number SET serial_no='$serial_no[$i]' , manufacturer='$manufacturer[$i]',expiry_date='$_POST[$exp_dt]',equip_price='$eq_price[$i]', issud_userid='$iss_userid[$i]', reason='$rsn' where serial_id='$serialid[$i]'");
		
		$get_max_hid = $database->get_from_database("select MAX(history_id) from asset_history where   serial_id='$serialid[$i]'");
		$hist_id = $get_max_hid[0];

		$get = $database->get_from_database("select * from asset_history where history_id='$hist_id'");
		$old_st = $get['old_status'];
		$new_st = $get['new_status'];
		

//		$database->update("update asset_history set user_id='$iss_userid[$i]' where history_id='$hist_id'");

		$database->insert("insert into asset_history (asset_tag, serial_id, equipment_id, old_status, new_status, reason, change_date, user_id) values('$asset_tag', '$serialid[$i]', '$equip_id_arr[$i]', '$old_st', '$new_st', '$rsn', NOW(), '$iss_userid[$i]')");
		$price_total=$price_total + $eq_price[$i];
	   }
	   //echo $price_total;
      $database->update("UPDATE asset_assets SET asset_price='$price_total' WHERE asset_tag = '$asset_tag'");  
		
		$rrrw = $database->get_from_database("select attachment_name from asset_assets where asset_tag = '$asset_tag'");
		$file_name = $rrrw[0];

		$uploadpath = 'attachment_files/';

		/*
		if(file_exists($uploadpath.$file_name))
		{

			if(!unlink($uploadpath.$file_name))
			{
				echo "The File can't be deleted !";
			}
		} */

      //here uploaded image files are stored.
		$source  = $_FILES['attachment_name']['tmp_name'];

		if($attachment_name!="")
		{
			if ( move_uploaded_file( $source, $uploadpath.$attachment_name))
			{
			  redirect ("manage_asset.php","Edit");
			}
			else
			{
				echo "OOps, there is an Error while uploading the file !";
			}
		}
		else
		{
		  redirect ("manage_asset.php","Edit");			
		}
    }
   }
  }
}

else
{
 $mes = "Sorry ! You have no such Privillage ...";
 $smarty->assign('mes',$mes);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);
$smarty->assign('cal_cnt',0);
$smarty->display('edit_asset.tpl');
?>
Return current item: CoreAsset