<?php
require_once("lib/inc.php");
require_once("lib/security.php");
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title ="::: Manage Category :::";
$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 = "";
$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 < 5)
{
$count=$database->no_of_rows("select * from asset_category");
//echo $count;
$row_per_page=2;
$page=$count/2;
$smarty->assign('row_per_page',$row_per_page);
$smarty->assign('count',$count);
$smarty->assign('page',$page);
$num = $database->no_of_rows("select * from asset_category");
if(isset($_GET['hd83___2y8dh328f____8hhdiw___jd9']))
{
if($status < 4)
{
$category_id = $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
$database->delet("delete from asset_category where category_id='$category_id'");
$database->delet("delete from asset_equipment where category_id='$category_id'");
$database->delet("delete from asset_purchase_order where category_id='$category_id'");
$database->delet("delete from asset_assets where category_id='$category_id'");
$database->delet("delete from asset_serial_number where category_id='$category_id'");
$database->delet("delete from asset_books ");
redirect ("manage_category.php","Delete");
}
else
{
$num = "invalid";
$smarty->assign('num',$num);
}
}
if(isset($_GET['act']))
{
if($_GET['act']=="Add")
{
$mes = "Category is Successfully Created !";
}
if($_GET['act']=="Edit")
{
$mes = "Category is Successfully Updated !";
}
if($_GET['act']=="Delete")
{
$mes = "Category is Successfully Deleted !";
}
if($_GET['act']=="Exist")
{
$mes = "Category is already Added ...";
}
}
if($num > 0)
{
$res = $database->Execute("select * from asset_category");
while($row1 = mysql_fetch_array($res))
{
$cat_id = $row1['category_id'];
$p_no = $database -> no_of_rows("select * from asset_purchase_order where category_id=$cat_id");
$a_no = $database -> no_of_rows("select * from asset_assets where category_id=$cat_id");
$category_id[] = $row1['category_id'];
$category_name[] = $row1['category_name'];
$po_num[] = $p_no;
$asset_num[] = $a_no;
}
$smarty->assign('category_id',$category_id);
$smarty->assign('category_name',$category_name);
$smarty->assign('po_num',$po_num);
$smarty->assign('asset_num',$asset_num);
}
$smarty->assign('num',$num);
$smarty->assign('mes',$mes);
}
else
{
$num = "invalid";
$smarty->assign('num',$num);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);
$smarty->display('manage_category.tpl');
?>