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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Add Equipment :::";
$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'];
$user_id  = $_SESSION['user_id'];
$smarty->assign('user_id',$user_id);
$rrr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	   $aa= mysql_fetch_array($rrr);
	   $cat_id_book= $aa[0];
	   $smarty->assign('cat_id_book',$cat_id_book);

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

// Retriving categories from database
$result     = $database->Execute("select * from asset_category");
$category_name=array();
$category_id=array();
while($row=mysql_fetch_array($result))
{
array_push($category_name,$row[1]);
array_push($category_id,$row[0]);
}

if(count($category_id) > 0)
{
$smarty->assign('category_name',$category_name);
$smarty->assign('category_id',$category_id);
$mm="";
$count_cat=1;
}
else
 {
 $mm="No Category Still Added !!";
 $count_cat=0;
 }
 $smarty->assign('mm_cat',$mm);
// echo $count_cat;
 $smarty->assign('count_cat',$count_cat);
// category retrived and send to smarty
if($status < 4)
{
  if(isset($_GET['act']))
  {
   if($_GET['act']=="add")
   {
    $equipment_name                = trim($_POST['equipment_name']);
	$equipment_model               = trim($_POST['equipment_model']);
	$category_id				   = trim($_POST['category']);

    $numb                 = $database->no_of_rows("select * from asset_equipment where equipment_name='$equipment_name' and equipment_model='$equipment_model'");
    if($numb==0)
    {
	    $prev_counnt=$database->no_of_rows("select * from asset_equipment where equipment_name='$equipment_name' and equipment_model='$equipment_model' and category_id='$category_id'");
		if($prev_count > 0)
		{
		 redirect ("manage_equipment.php","Exist");
		}
      if($database->insert("insert into asset_equipment (equipment_name, equipment_model, category_id, create_date) values ('$equipment_name', '$equipment_model', '$category_id','$date')"))
      {
       redirect ("manage_equipment.php","Add");
      }
    }
    else
    {
      redirect ("manage_equipment.php","Exist");
    }
   }
  }
}
else
{
 $mes = "Sorry ! You have no such Privillage ...";
 $smarty->assign('mes',$mes);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);



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