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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
// 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
$title	  ="::: Add Category :::";
$smarty->assign('title',$title);
$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)
{
  if(isset($_GET['act']))
  {
   if($_GET['act']=="add")
   {
    $category_name                = trim($_POST['category_name']);
    $category_description         = trim($_POST['category_description']);
	//$expn						  = '^(book)*$';//$category_name;
	$num_exists					  = $database->no_of_rows("SELECT * FROM asset_category where category_name='$category_name'");
	if($num_exists > 0)
	{
		redirect ("manage_category.php","Exist");
	}
	else
	{
    $numb                 		  = $database->no_of_rows("select * from asset_category  where category_name LIKE '%book%'");
	
    if($numb > 0)
    {
		//$stat = stripos($category_name,"book"); // **********
		$stat = strpos(strtoupper($category_name),strtoupper("book"));

		if($stat===FALSE)
		{
			  if($database->insert("insert into asset_category (category_name, category_description, create_date) values ('$category_name', '$category_description', '$date')"))
			  {
				 redirect ("manage_category.php","Add");
			  }
		}
		else
		{
			redirect ("manage_category.php","Exist");
		}
	}
    else
    {
      if($database->insert("insert into asset_category (category_name, category_description, create_date) values ('$category_name', '$category_description', '$date')"))
      {
       redirect ("manage_category.php","Add");
      }
    }
   }
   }
  }
}
else
{
 $mes = "Sorry ! You have no such Privillage ...";
 $smarty->assign('mes',$mes);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);



$smarty->display('add_category.tpl');
?>
Return current item: CoreAsset