Location: PHPKode > projects > CoreAsset > coreasset/manage_asset.php
<?php
require_once("lib/inc.php");
require_once("lib/security.php");
error_reporting(0);
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Manage 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
$mes      = "";
$num      = "";
$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 < 5)
{

    $rr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	$a= mysql_fetch_array($rr);
	$cat_id_book= $a[0];
	
	$smarty->assign('cat_id_book',$cat_id_book);

    $num_book=$database->no_of_rows("select category_id from asset_assets where category_id='$cat_id_book';");
    $smarty->assign('num_of_book',$num_book);
	//////////////
	if($num_book > 0)
	{
    $res              = $database->Execute("select * from asset_assets where category_id = $cat_id_book");
      while($row_book   = mysql_fetch_array($res))
      {
		$book_id[]		= $row_book['equipment_id'];
		$price_book[]   = $row_book['asset_price'];
		$tag_book[]     = $row_book['asset_tag'];  
	  }
   $smarty->assign('book_id',$book_id);
   $smarty->assign('tag_book',$tag_book);
   $smarty->assign('price_book',$price_book);
   //print_r($tag_book);
   $count_book = count($book_id);
   for($i=0;$i<$count_book;$i++)
   {
     $a=explode(",",$book_id[$i]);
	 //print_r($a);
	 $count_no = count($a);
	 $bb="";
	  
	 for($j=0;$j<$count_no;$j++)
	 {  
	    $b_id = $a[$j];
	 $res_bookname          = $database->Execute("select * from asset_books where book_id = $b_id");
	  
	   
      while($row_bookname   = mysql_fetch_array($res_bookname))
      {
	   $bb.= $row_bookname['book_name'] ;
	   $bb.=",";
	   }
	 }
	 $book_final[$i] = $bb;
	 
   }
 
   //print_r($book_final);
   
   for($u=0; $u<$num_book; $u++)
    {
                    $book_f=$book_final[$u];
					
					$bb_final=explode(",",$book_f);
					//print_r($bb_final);echo "--";
				    $p = array_count_values($bb_final);
				    //print_r($p);echo "--";
				       //$p=array();
					$book_nm="";
					$piec="";
					foreach($p as $n=>$v)
					{
						$book_nm[] = $n;
						$piec[] = $v;
					}
					//print_r($book_nm);echo "<br>";
					//print_r($piec);
					$a="";
					for($k=0;$k<count($book_nm)-1;$k++)
					{
					 //echo $book_nm[$k];
					  $a.=$k+1;
					  $a.=". ";
					 $a.=$book_nm[$k];
					 $a.=" (";
					 $a.=$piec[$k];
					 $a.=" Pc/s ) "; 
					 $a.="<br>";
					}
					//echo  $a; echo "<br>";
   					$arr_book[$u]   = $a;
   }
   //$ar = array_reverse($arr);
   //print_r($arr_book);
   $smarty->assign('arr_book',$arr_book);
    
   
   
  $count_short=count($book_final);
  for($i=0;$i<$count_short;$i++)
  {
  $b_short=explode(",",$book_final[$i]);
   $count_ele=count($b_short)-1;
    $count_el[$i] = $count_ele;
   for($j=0;$j<$count_ele;$j++)
   {
    $book_sh=array_unique($b_short);
   }
   
   $book_short[$i] = $book_sh[0];
  }
  $smarty->assign('book_final',$book_short);
  $smarty->assign('count_el',$count_el);
  $smarty->assign('book_length','0');
  }
   ////////////


    $num = $database->no_of_rows("select * from asset_assets");

    if(isset($_GET['hd83___2y8dh328f____8hhdiw___jd9']))
    {

      if($status < 4)
      {
        $asset_tag = $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
        if($database->delet("delete from asset_assets where asset_tag='$asset_tag'"))
        {
		 $database->delet("delete from asset_serial_number where asset_id='$asset_tag'"); 
		 $database->delet("delete from asset_history where asset_tag='$asset_tag'");  
		 redirect ("manage_asset.php","Delete");
        }
        else
        {
         echo mysql_error();
        }
       }
       else
       {
         $num = "invalid";
         $smarty->assign('num',$num);
       }
    }
    

    if(isset($_GET['act']))
    {
     if($_GET['act']=="Add")
     {
      $mes = "Asset is Successfully Created !";
     }
     if($_GET['act']=="Edit")
     {
      $mes = "Asset is Successfully Updated !";
     }
     if($_GET['act']=="Delete")
     {
      $mes = "Asset is Successfully Deleted !";
     }
     if($_GET['act']=="Exist")
     {
      $mes = "Asset is already Added ...";
     }
    }


    if($num  - $num_book> 0)
    {
      $res          = $database->Execute("select * from asset_assets");
      while($row1   = mysql_fetch_array($res))
      {
       $asset_tag[]               = $row1['asset_tag'];
       $asset_manufacturer[]      = $row1['asset_manufacturer'];
       $asset_model[]             = $row1['asset_model'];
       $asset_serial[]            = $row1['asset_serial'];
       $po_no[]                   = $row1['po_no'];
	   $pono	                  = $row1['po_no'];
       $vendor_id[]               = $row1['vendor_id'];
       $asset_price[]             = $row1['asset_price'];
       $equipment_id[]            = $row1['equipment_id'];
       $asset_description[]       = $row1['asset_description'];
       $receive_date[]            = $row1['receive_date'];
       $cat_id[]                  = $row1['category_id'];     
       $asset_nickname[]          = $row1['asset_nickname']; 

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

       // *******************  GETTING EQUIPMENT INFORMATION *********************************************************
	   $res123          = $database->Execute("select * from asset_purchase_order where po_no='$pono'");

	   while($rrw123 = mysql_fetch_array($res123))	
	   {
		   $eq_id                 = $rrw123['equipment_id'];
		   $n_pcs                 = $rrw123['no_pcs'];
		   $no_pcs                = explode(",",$n_pcs);
		   $eq                    = explode(",",$eq_id);

       foreach($eq as $n=>$v)
       {
       //echo $v;
         if($v!="")
         {
           $row4                  = $database->get_from_database("select * from asset_equipment where equipment_id='$v'");
           $eq_mod	   =	$row4['equipment_model'];
		   $equip_name.=    $row4['equipment_name']." [".$eq_mod."]"." ".$no_pcs[$n]." Pcs"."<br>";
         }
       }
       
       $equipment_name[]        = $equip_name;
       //echo "<br>";
       $equip_name = "";
	   }

/*
	   $eq_id           = $row1['equipment_id'];
       $eq                    = explode(",",$eq_id);
       foreach($eq as $n=>$v)
       {

         if($v!="")
         {
           $row4                  = $database->get_from_database("select * from asset_equipment where equipment_id='$v'");
           $eq_mod	   =	$row4['equipment_model'];
		   $equip_name.=    $row4['equipment_name']." [".$eq_mod."]"." ".$no_pcs[$n]." Pcs"."<br>";
         }
       }

       $equipment_name[]        = $equip_name;
       //echo "<br>";
       $equip_name = "";
*/
       
      }

      $smarty->assign('asset_tag',$asset_tag);
      $smarty->assign('asset_manufacturer',$asset_manufacturer);
      $smarty->assign('asset_model',$asset_model);
      $smarty->assign('asset_serial',$asset_serial);
      $smarty->assign('asset_price',$asset_price);
	  $smarty->assign('asset_nickname',$asset_nickname);
      $smarty->assign('asset_description',$asset_description);
      $smarty->assign('receive_date',$receive_date);
      $smarty->assign('po_no',$po_no);
      $smarty->assign('vendor_id',$vendor_id);
      $smarty->assign('vendor_name',$vendor_name);
      $smarty->assign('equipment_id',$equipment_id);
      $smarty->assign('equipment_name',$equipment_name);
	  $smarty->assign('cat_id',$cat_id);
    }
  $smarty->assign('num',$num);
  $smarty->assign('mes',$mes);
  
  //////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  $res_book          = $database->Execute("select * from asset_assets where category_id = '$cat_id_book'");
      while($row_book   = mysql_fetch_array($res_book))
      {
         $equipment_id_book[]            = $row_book['equipment_id'];
  
       $eq_id_book                 = $row_book['equipment_id'];
       $eq_book                    = explode(",",$eq_id_book);
	   
       foreach($eq_book as $n=>$v)
       {
       //echo $v;
         if($v!="")
         {
           $row4                  = $database->get_from_database("select * from asset_books where book_id='$v'");
           $equip_name_book.=          $row4['book_name'].",";
         }
       }

       $equipment_name_book[]        = $equip_name_book;
       //echo "<br>";
       $equip_name_book = "";
  
  }
  print_r($equip_name_book);
   $smarty->assign('equipment_name_book',$equipment_name_book);
  /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else
{
 $num = "invalid";
 $smarty->assign('num',$num);
}

$smarty->assign('name',$name);
$smarty->assign('status',$status);



$smarty->display('manage_asset.tpl');
?>
Return current item: CoreAsset