Location: PHPKode > projects > CoreAsset > coreasset/edit_asset_book.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 For Book :::";
$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
$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);

if($status < 4)
{
 //category selected
 $rr=$database->Execute("select category_id from asset_category where category_name like'book%';");
 $a= mysql_fetch_array($rr);
 $cat_id_book= $a[0];
 $rrr=$database->Execute("select category_name from asset_category where category_id = '$cat_id_book';");
 $aa= mysql_fetch_array($rrr);
 $cat_name_book= $aa[0];
 //echo $cat_name_book;
$smarty->assign('cat_id_book',$cat_id_book);
$smarty->assign('cat_name_book',$cat_name_book);
// po_no selected


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

	   $data			= $database->get_from_database("SELECT * from asset_assets WHERE asset_tag='$asset_id'");
	   $po_no			= $data['po_no'];
	   $eq_list			= $database->get_from_database("Select equipment_id from asset_purchase_order where po_no='$po_no'");
	   $book_id_list	= explode(',',$eq_list['equipment_id']);
	   $smarty->assign('pcs',count($book_id_list));
	   $price=0;
	   for($i=0;$i<count($book_id_list);$i++)
	      {
		  	$book_price	= $database->get_from_database("Select book_name,price from asset_books where book_id='$book_id_list[$i]'");			$smarty->assign('book_name',$book_price['book_name']);
			$price+=$book_price['price'];	
		  }
       $smarty->assign('po_no',$po_no);
       $smarty->assign('asset_description',$data['asset_description']);
	   $smarty->assign('receive_date',$data['receive_date']); 
	   $smarty->assign('total_price',$price); 

////////////////////for book name and pcs/////////////////////////////////////
	    $asset_tag 		= $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
		$eq_list		= $database->get_from_database("SELECT * FROM asset_assets where asset_tag ='$asset_tag'");
		$book_id_list	= explode(',',$eq_list['equipment_id']);
	   // print_r($book_id_list);
		$count_bname=count($book_id_list);
	   for($p=0;$p<$count_bname;$p++)
	    {
	    $data_bname			= $database->get_from_database("SELECT * from asset_books WHERE book_id='$book_id_list[$p]'");   
	    $data_bookname[]    = $data_bname['book_name'];
	    }
	  	 //print_r($data_bookname);
		 if(!isset($_REQUEST['act']))
		 {
		 $p = array_count_values($data_bookname);
				   //  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);
					$count_nm=count($book_nm);
   					 //for()
	                $a="";
					for($re=0;$re<$count_nm;$re++)
					 {
					 $a.=$re+1;
					 $a.=". ";
					 $a.=$book_nm[$re];
					 $a.="(";
					 $a.=$piec[$re];
					 $a.="Pc/s) "; 
					// $a.=" ,";
					 $all_book_names[]=$a;
					 $a="";
					 }
	   //echo $a;
	   }
	   
	$smarty->assign('a',$all_book_names);   
	   /////////////////////for book name and pcs/////////////////////////////////////
  
  
  if(isset($_REQUEST['act']))
  {
   if($_REQUEST['act'] == "edit")
   {
    $asset_id					  = $_REQUEST['asset_id'];
    //$category_name              = trim($_POST['cat_name']);
    //$category_id                = trim($_POST['cat_id']);
    //$po_no                      = trim ($_POST['po_no']);   
    $asset_price                  = trim($_POST['asset_price']);
	$asset_description            = trim($_POST['asset_description']);
	$receive_date                 = trim($_POST['receive_date']);
	//$issued_userid              = trim($_POST['issued_userid']);
	
	
   

  ////////////////////////////////////////////////insert query///////////////////////////////////////////////////

  $database->update("UPDATE asset_assets SET asset_description='$asset_description',receive_date='$receive_date',asset_price='$asset_price' WHERE asset_tag='$asset_id'");
  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->display('edit_asset_book.tpl');
?>
Return current item: CoreAsset