Location: PHPKode > projects > CoreAsset > coreasset/add_purchase_book.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	  ="::: Add Purchase 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'];
$smarty->assign('status',$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);

//for book name 
$found	  =0;
$res      = $database->Execute("select book_name,count(book_name) as cn from asset_books WHERE status='0' GROUP BY book_name");
while($row_bookname   = mysql_fetch_array($res))
{
	$found				=1;
	$book_name_array[] 	= $row_bookname['book_name']; 
	$cnt[] 				= $row_bookname['cn'];
	
}

/*print_r($book_name_array);
print_r($cnt);*/
$count_record = count($cnt);

//for category id of book
$rrr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	   $aa= mysql_fetch_array($rrr);
	   $cat_id_book= $aa[0];
	   
//for book ids	   
for($j=0;$j<$count_record;$j++)
{
	$res_bid      = $database->Execute("select book_id from asset_books where book_name ='$book_name_array[$j]'");
	$book_id_temp= array();
	while($row_bookid   = mysql_fetch_array($res_bid))
	{
		//echo $row_bookid['book_id']; 
		$book_id_temp[] 	= $row_bookid['book_id']; 
	}
	$book_id_array[]	= implode(",",$book_id_temp);
}
$smarty->assign('book_ids',$book_id_array);

if(isset($_REQUEST['act']))
  {
  
   if($_GET['act']=="add")
   { 
		$today_date     	 = date("Y-m-d");
	    $po_date             = $_REQUEST['po_date'];
		$book_ids			 = $_REQUEST['book_ids'];
		//$book_names			 = $_REQUEST['book_name'];
		//print_r($book_ids);
		//print_r($book_names);
		$count_array= count($book_ids);
		///////////////////////////////////to make same purchase order////////////////////////
		$bb_id=implode(",",$book_ids);
		//echo $bb_id;
		//$bb_name=implode(",",$book_names);
		//echo $bb_name;
		$b_id_lst = explode(",",$bb_id);
		/////////////////////////////////////////////////////////////////////////////////////
		
		//for($i=0;$i<count($book_names);$i++)
		//{
		   $database->insert("insert into asset_purchase_order (po_date, vendor_id, category_id,equipment_id, create_date) values ('$po_date',0,'$cat_id_book','$bb_id','$today_date')");
		   //$book_id_list 	= explode(",",$book_ids[$i]);
		   //print_r($book_id_list);
		   for($j=0;$j<count($b_id_lst);$j++)
		    {
			 	$database->update("UPDATE asset_books SET status = 1 WHERE book_id='$b_id_lst[$j]'");
		    }

		//}
		redirect ("manage_purchase.php","Add");
	   
	}
	}
$smarty->assign('book_name',$book_name_array);
$smarty->assign('cnt',$cnt);
$smarty->assign('found',$found);
$smarty->display('add_purchase_book.tpl');
?>
Return current item: CoreAsset