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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Search 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      = "";
$box	  = "";
$equip_name = "";
$asset_manufacturer = "";
$asset_serial = "";
$asset_model = "";
$userr_id = "";
$full_namee = "";

$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);

$numm = $database->no_of_rows("select * from asset_users");

if($numm > 0)
{
	$roww = $database->Execute("select * from asset_users");
	while($rrrw = mysql_fetch_array($roww))
	{
		$userr_id[]		= $rrrw['user_id'];
		$login[]		= $rrrw['login'];
	}
	$smarty->assign('userr_id', $userr_id);
	$smarty->assign('login', $login);
}


if($status < 5)
{
    $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'"))
        {
        // redirect ("manage_asset.php","Delete");
        }
        else
        {
         echo mysql_error();
        }
       }
       else
       {
         $num = "invalid";
         $smarty->assign('num',$num);
       }
    }
	 
	if(isset($_POST['srch_type']))
    {
	 // Search the record and assgn properly to smarty
	 $option=$_REQUEST['srch_type'];
	 $smarty->assign('option',$option);

	 $box=$_REQUEST['criteria'];
	 $cond=$box[$option-1];
	 $smarty->assign('cond',$cond);
	 //echo $cond;
	 $rr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	$a= mysql_fetch_array($rr);
	$cat_id_book= $a[0];
    if($cat_id_book!="")
	{
		switch ($option)
		{
		 case 0:
			 $q	=	"select * from asset_assets where category_id != '$cat_id_book'";
			 break;
		 case 1:
			 $q	=	"select * from asset_assets where asset_tag='$cond' and category_id != '$cat_id_book'";
			 break;
		 case 2:
			 $q	=	"select db1.* from asset_assets  as db1 , asset_serial_number  as db2 where db1.asset_tag=db2.asset_id and db2.manufacturer like '$cond%' and db1.category_id != '$cat_id_book'   group by db2.asset_id";
			 break;
		 case 3:
			 $q	=	"select * from asset_assets where asset_nickname like '$cond%' and category_id != '$cat_id_book'";
			 break;
		 case 4:
			$q	=	"select db1.* from asset_assets as db1, asset_equipment as db2 where db2.equipment_name like '$cond%' and FIND_IN_SET(db2.equipment_id, db1.equipment_id) > '0' and db1.category_id != '$cat_id_book'";
			//echo $q;
			 break;
		 case 5:
			 $q	=	"select db1.* from asset_assets as db1,asset_vendor as db2 where db1.vendor_id=db2.vendor_id and db2.vendor_name like '$cond%' and db1.category_id != '$cat_id_book'";
			 break;
		 case 6:
			 $q	=	"select db1.* from asset_assets as db1,asset_serial_number as db2 where db1.po_no=db2.po_no and db2.serial_no like '$cond%' and db1.category_id != '$cat_id_book' group by db2.asset_id";
			 break;
		 case 7:
			 $q	=	"select * from asset_assets where po_no like'$cond%' and category_id != '$cat_id_book'";
			 break;
		 case 8:
			 $cond	=	$_REQUEST['receive_date'];
			 $q		=	"select * from asset_assets where receive_date ='$cond' and category_id != '$cat_id_book'";
			 break;

		}
	}
	else
	{
		switch ($option)
		{
		 case 0:
			 $q	=	"select * from asset_assets";
			 break;
		 case 1:
			 $q	=	"select * from asset_assets where asset_tag='$cond'";
			 break;
		 case 2:
			 $q	=	"select db1.* from asset_assets  as db1 , asset_serial_number  as db2 where db1.asset_tag=db2.asset_id and db2.manufacturer like '$cond%'  group by db2.asset_id";
			 break;
		 case 3:
			 $q	=	"select * from asset_assets where asset_model like '$cond%'";
			 break;
		 case 4:
			$q	=	"select db1.* from asset_assets as db1, asset_equipment as db2 where db2.equipment_name like '$cond%' and FIND_IN_SET(db2.equipment_id, db1.equipment_id) > '0' and db1.category_id != '$cat_id_book'";
			//echo $q;
			 break;
		 case 5:
			 $q	=	"select db1.* from asset_assets as db1,asset_vendor as db2 where db1.vendor_id=db2.vendor_id and db2.vendor_name like '$cond%'";
			 break;
		 case 6:
			 $q	=	"select db1.* from asset_assets as db1,asset_serial_number as db2 where db1.po_no=db2.po_no and db2.serial_no like '$cond%'";
			 break;
		 case 7:
			 $q	=	"select * from asset_assets where po_no like'$cond%'";
			 break;
		 case 8:
			 $cond	=	$_REQUEST['receive_date'];
			 $q		=	"select * from asset_assets where receive_date ='$cond'";
			 break;
		}	
	}
  }
  else
    { 
	$rr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	$a= mysql_fetch_array($rr);
	 $cat_id_book= $a[0];
	// echo $cat_id_book;
	
	 $q	=	"select * from asset_assets where category_id!='$cat_id_book'";
    }

    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 > 0)
    {
	 
	
      $res          =	$database->Execute($q);
	  $numrow       =	$database->no_of_rows($q);
	  if($numrow>0)
	  {
      while($row1   =	mysql_fetch_array($res))
      {
       $asset_tag[]               = $row1['asset_tag'];
	   $as_tg					  = $row1['asset_tag'];
	   
	  // $asset_manufacturer[]      = $row1['asset_manufacturer'];
      // $asset_model[]             = $row1['asset_model'];
	  // $asset_serial[]            = $row1['asset_serial'];

	   $po_no[]                   = $row1['po_no'];
	   $p_no	                  = $row1['po_no'];


	  $res123          = $database->Execute("select * from asset_purchase_order where po_no='$p_no'");
	  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 = "";
	   }



       $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'];

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

      }

      $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_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('num',$num);
	  $smarty->assign('mes',$mes);
	  if($box=="")
	    $message="";
	  else
	    $message="$numrow records found";
	  $smarty->assign('message',$message);
}
else
{
$flag=1;
$smarty->assign('flag',$flag);
$message="Sorry!no matching with your criteria..";
$smarty->assign('message',$message);
}
}
}
else
{
 $num = "invalid";
 $smarty->assign('num',$num);
 $message="Sorry!no matching with your criteria..";
 $smarty->assign('message',$message);

}

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

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