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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Manage Library :::";
$smarty->assign('title',$title);

$to_date	=date("Y-m-d");
$smarty->assign('cur_date',$to_date);

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

$smarty->assign('status',$status);
if($status < 5)
{
  $query	="select * from asset_books";
if(isset($_REQUEST['srch_type']))
 { 
  $smarty->assign('srch_val',$_REQUEST['srch_type']);
  //echo $_REQUEST['srch_type'];
 if($_REQUEST['srch_type'] == 1)
 {
   //echo "normal";
   $book_norm         		=$_POST['book_name_norm']; 
   $author_norm             =$_POST['author_norm'];
   $smarty->assign('book_name_norm',$book_norm);
   $smarty->assign('author_norm',$author_norm);
   //echo $book_norm;
   if($status == 1)
   {
     $query="select * from asset_books where book_name LIKE'$book_norm%' and author LIKE'$author_norm%' "; 
	}
   else
   {
   $query="select * from asset_books where book_name LIKE '$book_norm%' and author LIKE '$author_norm%' and issued_user=0"; 
   }
 }
  
  
 if($_REQUEST['srch_type'] == 2)
  {
  $book_adv		         =$_POST['book_name']; 
  $isbn_noo		         =$_POST['isbn_no']; 
  $author_adv            =$_POST['author'];
  $publisher_adv         =$_POST['publisher'];
  $rec_date_adv          =$_POST['rec_date'];           
   $smarty->assign('book_name_adv',$book_adv);
   $smarty->assign('author_adv',$author_adv);
   $smarty->assign('publisher_adv',$publisher_adv);
   $smarty->assign('rec_date_adv',$rec_date_adv);
   if($status == 1)
    {
     $query="select * from asset_books where book_name='$book_adv' and isbn_no='$isbn_noo' and author='$author_adv' and publisher='$publisher_adv' and receive_date='$rec_date_adv'"; 
	}
   else
   {
   $query="select * from asset_books where book_name='$book_adv' and isbn_no='$isbn_noo' and author='$author_adv' and publisher='$publisher_adv' and receive_date='$rec_date_adv' and issued_user=0"; 
   }
      
  } 
  }
	if(isset($_REQUEST['act']) && $_REQUEST['act']=="assign")
	{
	// Book is assigned
	
	$book_id_list		= explode(',',$_REQUEST['book_id_list']);//array_pop($book_id_list);
	$user_id_list		= explode(',',$_REQUEST['user_id_list']);//array_pop($user_id_list);
	$changed_id_list	= explode(',',$_REQUEST['changed_id_list']);//array_pop($changed_list);
	$date_list			= explode(',',$_REQUEST['date_list']);//array_pop($user_id_list);
	
	
	/*print_r($book_id_list);
	echo "<br>";echo "<br>";*/
	/*print_r($user_id_list);
	echo "<br>";echo "<br>";*/
	/*print_r($changed_id_list);
	echo "<br>";echo "<br>";
	print_r($date_list);
	echo "<br>";echo "<br>";*/
/*echo count($changed_id_list);

$ccnntt =  $_REQUEST['cnt_book_nw'];
for($p=0;$p < $ccnntt;$p++)
{
	$fld_name = "ret_date".$p;
	echo $_REQUEST[$fld_name]; 
}
exit;*/	
	for($i=0; $i<count($changed_id_list); $i++)
		  {      
			 if($user_id_list[$i] == "")
			  {
			  	$date_today			= "";
				$ret_date			= "";
			  }
			else if($user_id_list[$i] == -1)
			  {
			  	$date_today			= "";
				$ret_date			= "";
			  }
			 else
			  { 
			  	$t = $i-1;
		  		$fld_name = "ret_date".$t;
			 	$date_today			= date("Y-m-d");
				$ret_date			= $_REQUEST[$fld_name];
							  }
			 if($changed_id_list[$i] !="")
			 {
			 	$database->update("UPDATE asset_books SET issued_user='$user_id_list[$i]',issued_date = '$date_today',return_date='$ret_date',issued_by = '$user_id'  WHERE book_id='$book_id_list[$i]'");
			 	
				$rrrw = $database->get_from_database("select * from asset_book_history where book_id='$book_id_list[$i]'");
				$ass_tag = $rrrw['asset_tag'];
				$ppo_no  = $rrrw['po_no'];
				$database->insert("insert into asset_book_history  (asset_tag, po_no, book_id, assigned_userid, issued_on, return_date, change_date) values ('$ass_tag', '$ppo_no', '$book_id_list[$i]', '$user_id_list[$i]', '$date_today', '$ret_date', '$date_today')");
			 }
		  }
	/*	  $update_list		= $_POST['usr_dt'];
	$row_to_update		= count($update_list);
	
	for($i=0 ; $i<$row_to_update ; $i++)
	{
		$update			= explode('###',$update_list[$i]);
		
		$database->update("UPDATE asset_books SET return_date='$update[0]' WHERE book_id='$update[1]'");
	}*/
	}
	$num = $database->no_of_rows($query);

   


    if($num > 0)
    {
      $res          = $database->Execute($query);
      while($row1   = mysql_fetch_array($res))
      {
       $book_id[]                          = $row1['book_id'];
	   $bid			                       = $row1['book_id'];
	   $rrrwww = $database->get_from_database("select * from asset_book_history where book_id='$bid'");
	   $astg[]							   = $rrrwww['asset_tag'];

       $book_name[]                        = $row1['book_name'];
       $author[]                           = $row1['author'];
       $publisher[]                        = $row1['publisher'];
       $isbn_no[]                          = $row1['isbn_no'];
       $price[]                            = $row1['price'];
       $receive_date[]                     = $row1['receive_date'];
       $issued_user[]                      = $row1['issued_user'];
	   $book_st[]                          = $row1['status'];
	   //$isbn_no[]                          = $row1['isbn_no'];
	  // $issued_date[] 					   = $row1['issued_date'];	
			  if($row1['return_date'] == "0000-00-00")
			   {   
			     $return_date[]                      = "Not Issued";
			   }
			  else
			   {
				  $return_date[]                      = $row1['return_date']; 
		
			   } 
			   if($row1['issued_date'] == "0000-00-00")
			   {   
			     $issued_date[]                      = "Not Issued";
			   }
			  else
			   {
				  $issued_date[]                     = $row1['issued_date']; 
		
			   } 
	  }
	$cnt_book_nw = count($book_id); 
	$smarty->assign('cnt_book_nw',$cnt_book_nw);	
    $smarty->assign('book_id',$book_id);
	$smarty->assign('astg',$astg);
	$smarty->assign('book_st',$book_st);
	$smarty->assign('isbn_noo',$isbn_noo);
    $smarty->assign('book_name',$book_name);
    $smarty->assign('author',$author);
    $smarty->assign('publisher',$publisher);
    //$smarty->assign('isbn_no',$isbn_no);
    $smarty->assign('price',$price);
    $smarty->assign('receive_date',$receive_date);
    $smarty->assign('issued_user',$issued_user);
	$smarty->assign('isbn_no',$isbn_no);
	$smarty->assign('return_dt',$return_date);
	$smarty->assign('issued_date',$issued_date);

    }
// User list pull down
 
 	  $res_user          = $database->Execute("select * from asset_users");
      while($row2   = mysql_fetch_array($res_user))
      {
       $userid[]    = $row2['user_id'];
       $user_name[] = $row2['full_name'];
       
      }
    $smarty->assign('user_id',$userid);
    $smarty->assign('user_name',$user_name);

    

// 	
	
$smarty->assign('num',$num);
$smarty->assign('mes',$mes);
}


else
{
 $num = "invalid";
 $smarty->assign('num',$num);
}

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

$smarty->assign('cal_cnt',0);
$smarty->assign('cal_cnt1',0);
$smarty->display('manage_book.tpl');
?>
Return current item: CoreAsset