<?php
require_once("lib/inc.php");
require_once("lib/security.php");
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title ="::: Add 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
$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'];
$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);
$rr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
$a= mysql_fetch_array($rr);
$cat_id_book= $a[0];
$book_count = mysql_num_rows($rr);
$smarty->assign('book_count',$book_count);
if(isset($_REQUEST['act']))
{
if($_GET['act']=="add")
{
$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 "ll";echo $category_id;
$book_name =trim($_POST['book_name']);
$author =trim($_POST['author']);
$isbn_no = $_POST['isbn_no'];
$publisher =trim($_POST['publisher']);
$rec_date =trim($_POST['rec_date']);
$price =trim($_POST['price']);
if(!$pieces =$_POST['pieces'])
$pieces = 10;
$flag=0;
//$one_pc_price=$price/$pieces;
for($i=0;$i<$pieces;$i++)
{
// checking for existing ISBN
$existing = $database->no_of_rows("SELECT * from asset_books WHERE book_name='$book_name' AND author='$author' AND publisher='$publisher' AND isbn_no='$isbn_no[$i]';");
if($existing > 0)
{
$flag = 1;
}
else
{
$database->insert("insert into asset_books ( book_id,book_name,author, publisher,isbn_no, receive_date,price,status) values ('','$book_name','$author', '$publisher','$isbn_no[$i]','$rec_date','$price',0)");
}
}
if( $flag ==1)
{
redirect ("display_book.php","Exist");
}
else
{
redirect ("display_book.php","Add");
}
}
}
$smarty->assign('status',$status);
$smarty->display('add_book.tpl');
?>