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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Add 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
$eq_id = "";
$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'];
$smarty->assign('name',$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)
{
  if(isset($_GET['act']))
  {
   if($_GET['act']=="add")
   {
    $category_id                = trim($_POST['category_id']);
    $iss_userid		            = $_POST['iss_userid'];
    $manufacturer               = trim($_POST['manufacturer']);
    $asset_price                = trim($_POST['asset_price']);
    $vendor_id                  = trim($_POST['vendor_id']);
    $equip_id_arr               = $_POST['equi_id'];
	$equip_id                   = trim(implode(",",$_POST['equi_id']));
    $receive_date               = trim($_POST['receive_date']);
    $po_no                      = trim($_POST['po_no']);
    $asset_description          = trim($_POST['asset_description']);
    $asset_nickname             = trim($_POST['asset_nickname']);
    $serial_no					= $_POST['serial'];
	$manufacturer               = $_POST['manufacturer'];
	$depreciation               = $_POST['depre']; 
	$eq_price                   = $_POST['eq_price'];
	$attachment_name			= $_FILES['attachment_name']['name'];
	
    if($asset_id=$database->insert("insert into asset_assets (category_id, asset_nickname, po_no, vendor_id, asset_price, equipment_id, asset_description, receive_date, create_date, attachment_name) values ('$category_id',  '$asset_nickname', '$po_no', '$vendor_id', '$asset_price', '$equip_id', '$asset_description', '$receive_date', '$date', '$attachment_name')"))
    { 
	  $price_total=0;
      for($i=0;$i<count($serial_no);$i++)
	  {
		   $exp_dt="exp_date".$i;
		   $serial_id=$database->insert("insert into asset_serial_number (category_id,po_no,asset_id,equipment_id,serial_no,manufacturer ,user_id,created_on,expiry_date,equip_price,status,reason, issud_userid) values ('$category_id','$po_no','$asset_id','$equip_id_arr[$i]','$serial_no[$i]','$manufacturer[$i]','$issued_userid','$date','".$_POST[$exp_dt]."','$eq_price[$i]','1','Newly Added', '$iss_userid[$i]')");
		   $price_total=$price_total+$eq_price[$i];
		   
		   $database->insert("insert into asset_history(history_id,asset_tag,serial_id,equipment_id,old_status,new_status,reason,change_date,user_id)
			 values('','$asset_id','$serial_id','$equip_id_arr[$i]','None','1','Newly Added',NOW(), '$iss_userid[$i]')");
	   }
	   //echo $price_total;
	    $database->update("UPDATE asset_assets SET asset_price='$price_total' WHERE asset_tag = '$asset_id'");
		
		$uploadpath = 'attachment_files/';      //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","Add");
			}
			else
			{
				echo "OOps, there is an Error while uploading the file !";
			}
		}
		else
		{
		  redirect ("manage_asset.php","Add");
		}
    }
   }
  }
  
  
  // asset nickname collection
  $res_nickname    = $database->Execute("select * from asset_assets");
  $res_num 		   = mysql_num_rows($res_nickname);
  $smarty->assign('res_num',$res_num);	
  while($row_nickname    = mysql_fetch_array($res_nickname))
  {
	$asset_nickname[]     = $row_nickname['asset_nickname'];
  }
 //print_r($asset_nickname);
  $smarty->assign('asset_nickname',$asset_nickname);

// 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);
// *********************************************************************

// Getting Category Lists *************************************************
  $res5          = $database->Execute("select * from asset_category");
  while($row5    = mysql_fetch_array($res5))
  {
   $category_id[]                         = $row5['category_id'];
   $category_name[]                       = $row5['category_name'];
  }
 // echo $category_name[0];
  $smarty->assign("category_id",$category_id);
  $smarty->assign("category_name",$category_name);
  
// *********************************************************************

  if(isset($_GET['fill']))
  {
   if($_GET['fill']==1)
   {
       $po_no            = trim($_GET['idu392__d9j__932uf']);
       $vend_id          = trim($_GET['dhu283__82y8f']);
       $eq_id1           = trim($_GET['dh32__jd3ud']);
	   $n_pcs		     = trim($_GET['tr64r7__38ud']);
       $row3             = $database->get_from_database("select * from asset_vendor where vendor_id='$vend_id'");
       $vendor_name      = $row3['vendor_name'];
		
       $no_pcs_arr		 = explode(",",$n_pcs);
       $eq               = explode(",",$eq_id1);

       foreach($eq as $n=>$v)
       {
        if($v!="")
        {
			$eq_id.=          $v.",";
			$row4             = $database->get_from_database("select * from asset_equipment where equipment_id='$v'");
			$eeq[]				= $v;
			$equipment_name[]	= $row4['equipment_name'];
			$equipment_model[]	= $row4['equipment_model'];
			$cat_id			= $row4['category_id'];
        }
       }
  
       
	   $smarty->assign('po_no',$po_no);
       $smarty->assign('vendor_id',$vend_id);
       $smarty->assign('equi_id',$eq_id);
	   $smarty->assign('eeq',$eeq);
       $smarty->assign('vendor_name',$vendor_name);
       $smarty->assign('equipment_name',$equipment_name);
	   $smarty->assign('equipment_model',$equipment_model);
	   $smarty->assign('cat_id',$cat_id);
	   $smarty->assign('no_pcs',$no_pcs_arr);
	}
  }
}
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('add_asset.tpl');
?>
Return current item: CoreAsset