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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Welcome to Asset Management System :::";
$smarty->assign('title',$title);
$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);
$smarty->assign('name',$name);
$smarty->assign('status',$status);
// 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
$rrr		= $database->Execute("select category_id from asset_category where category_name like 'book%';");
$num_of_books	=mysql_num_rows($rrr);
if($num_of_books  > 0)
{
	$aa= mysql_fetch_array($rrr);
	$book_id= $aa[0];
}
else
 	$book_id=0;
 $today_date=date('Y-m-d');

if($status == 1 || $status == 2 )
{
    /* if(isset($_REQUEST['submit']))
	 {
    	 $reader_range		= $_REQUEST['reader_range']; 
	 }
	 else
	 {
	  	 $reader_range		= 30; 	 
	 }	

	     $database->update("UPDATE asset_alert SET reader_range = $reader_range where alert_id = 1");
*/
// for coming expiry message
//echo "llll";echo "<br>";
if(isset($_REQUEST['act']) && $_REQUEST['act'] == "equip")
{
	$eq_range		= $_REQUEST['equip_range'];	 
	if($eq_range == "")
	   {
	    $eq_range = 30;
	   }
	   
	$smarty->assign('eq_range',$eq_range);	
}
else
{
	$eq_range		= 30; 
	$smarty->assign('eq_range',$eq_range);	
}
$res          = $database->Execute("SELECT db1. * , db2. * , db3.asset_tag, db4.full_name,DATE_SUB(db2.expiry_date,INTERVAL 30 DAY)
FROM asset_equipment AS db1, asset_serial_number AS db2, asset_assets AS db3, asset_users AS db4
WHERE db2.asset_id = db3.asset_tag
AND db2.equipment_id = db1.equipment_id AND DATE_SUB(db2.expiry_date, INTERVAL $eq_range DAY) <= CURDATE()GROUP BY (
db2.serial_id
)
 
 ");

/*if(!$database->Execute("SELECT db1. * , db2. * , db3.asset_tag, db4.full_name,DATE_ADD(db2.expiry_date,INTERVAL 30 DAY)
FROM asset_equipment AS db1, asset_serial_number AS db2, asset_assets AS db3, asset_users AS db4
WHERE db2.asset_id = db3.asset_tag
AND db2.equipment_id = db1.equipment_id AND DATE_ADD(db2.expiry_date, INTERVAL 30 DAY) >= '$today_date' 
AND db2.user_id = db4.user_id
 "))
	{
		echo mysql_error();
	}*/

//echo "<br>";
$count_all			=mysql_num_rows($res);
// $count_all;
//echo "llll";
if($count_all > 0)
{
while($row1   = mysql_fetch_array($res))
      {
	   //echo  $sign[]                                           = $row1[16];
	   $equipment_id[]                                 = $row1['equipment_id'];  
       $equipment_name[]                               = $row1['equipment_name'];
	   $expiry_date[]                                  = $row1['expiry_date']; 
	   $asset_tag[]                                    = $row1['asset_tag'];
	   $user_name[]                                    = $row1['full_name'];
	   $serial_no[]                                    = $row1['serial_no'];
	   if($today_date > $row1['expiry_date'])
	   {
	     $sign[]         =0;
	   }
	   else
	   {
	     $sign[]          =1;
	   }
	  }
	  //print_r($equipment_id);echo "<br>";
	  //print_r($sign);
	  
	   $smarty->assign('equipment_name',$equipment_name);
	   $smarty->assign('expiry_date',$expiry_date);
	   $smarty->assign('equipment_id',$equipment_id);
	   $smarty->assign('count_all',$count_all);
	   $smarty->assign('asset_tag',$asset_tag);
	   $smarty->assign('user_name',$user_name);
       $smarty->assign('serial_no',$serial_no);
       $smarty->assign('sign',$sign);  
}	   

$today_date     = date("Y-m-d");
//echo $today_date;

// for book message
if(isset($_REQUEST['act']) && $_REQUEST['act'] == "book")
{
	$day_range		= $_REQUEST['range'];
	if($day_range == "")
	 {
	  $day_range = 30;
	 }
	$smarty->assign('day_range',$day_range);	
}
else
{
	$day_range		= 30; 
	$smarty->assign('day_range',$day_range);	
}
$res_book    =	$database->Execute("select db1.* ,db2.full_name from asset_books as db1,asset_users as db2 where  db1.issued_user=db2.user_id and db1.return_date > db1.issued_date AND DATE_ADD('$today_date',INTERVAL $day_range DAY) > db1.return_date
;");	
//print_r(mysql_fetch_array($res_book)); 
  $count_sp_book=mysql_num_rows($res_book);
 if($count_sp_book > 0)
 { 
  while($row_book   = mysql_fetch_array($res_book))
      { 
	   
		$issued_date 	                            = $row_book['issued_date'];
		$return_date								= $row_book['return_date'];
		$issued_dt[] 		                        = $row_book['issued_date'];
		$return_dt[]								= $row_book['return_date'];
		$today_year									=date('Y');
		$today_month								=date('m');
		$today_day									=date('d');
		$issued_dt_exp								=explode('-',$issued_date);
		$day1										= $today_year*365+$today_month*30+$today_day;
		$rt_dt										= explode('-',$return_date);
		$return_year								= $rt_dt[0];
		$return_month								= $rt_dt[1];
		$return_day									= $rt_dt[2];
		$day2										= $return_year*365+$return_month*30+$return_day;
		$day_rem									= $day2 - $day1;
		$book_id                                    = $row_book['book_id'];
		$book_name[]                                = $row_book['book_name'];  
		$isbn_no[]                                  = $row_book['isbn_no'];
		$author[]                                   = $row_book['author']; 
		$publisher[]                                = $row_book['publisher'];
		$full_name[]                                = $row_book['full_name'];
		$submit_date[]                              = $day_rem;
	   
	  }
	  //print_r($submit_date);
	   $smarty->assign('book_id',$book_id);
	   $smarty->assign('book_name',$book_name);
	   $smarty->assign('isbn_no',$isbn_no);
       $smarty->assign('author',$author);
	   $smarty->assign('publisher',$publisher);
 	   $smarty->assign('count_sp_book',$count_sp_book);
       $smarty->assign('full_name',$full_name);
       $smarty->assign('submit_date',$submit_date);
       $smarty->assign('issued_dt',$issued_dt);
       $smarty->assign('return_dt',$return_dt);
}	   

	/*$res_book_already    =	$database->Execute("select db1.* ,db2.full_name,DATEDIFF('$today_date',db1.issued_date) from asset_books as db1,asset_users as db2 where  db1.issued_user=db2.user_id and '$today_date' > db1.issued_date ; 
");
while($row_book_already   = mysql_fetch_array($res_book_already))
      { 	
	       $rem_sign[]= $row_book_already[10]; 
	
       }
	   	 // print_r($rem_sign);
       $smarty->assign('rem_sign',$rem_sign);
*/
}
else
{
	// For Users/Readers **********************88
// for already expired equipments
//echo "already";echo "<br>";
if($database->Execute("select db1.*,db2.*  from asset_equipment as db1,asset_serial_number as db2, asset_assets as db3 where db2.asset_id=db3.asset_tag and db2.equipment_id=db1.equipment_id and db2.issud_userid = '$user_id' and db2.expiry_date < '$today_date'"))
{
	$res_already = $database->Execute("select db1.*,db2.*  from asset_equipment as db1,asset_serial_number as db2, asset_assets as db3 where db2.asset_id=db3.asset_tag and db2.equipment_id=db1.equipment_id and db2.issud_userid = '$user_id' and db2.expiry_date < '$today_date'");
}
else
{
	echo mysql_error();
}

$count_sp_already=mysql_num_rows($res_already);
//echo "count_sp="; echo $count_sp_already;
if($count_sp_already > 0)
{
while($row1_al_sp   = mysql_fetch_array($res_already))
      {
	   $equipment_id_al[]                                 = $row1_al_sp['equipment_id'];  
       $equipment_name_al[]                               = $row1_al_sp['equipment_name'];
	   $expiry_date_al[]                                  = $row1_al_sp['expiry_date']; 
	   $serial_no_al[]                                    = $row1_al_sp['serial_no'];
	  }
	  //print_r($equipment_name_al);
	   $smarty->assign('equipment_name_all',$equipment_name_al);
	   $smarty->assign('expiry_date_all',$expiry_date_al);
	   $smarty->assign('equipment_id_all',$equipment_id_al);
	   $smarty->assign('count_sp_all',$count_sp_already);
	   $smarty->assign('serial_no_all',$serial_no_al);
	   $today_date     = date("Y-m-d");
}	   
//for coming to expired equipments
$res          = $database->Execute("select db1.*,db2.*  from asset_equipment as db1,asset_serial_number as db2,asset_assets as db3 where db2.asset_id=db3.asset_tag and db2.equipment_id=db1.equipment_id and db2.issud_userid = '$user_id'AND db2.expiry_date > '$today_date' ");

$count_sp=mysql_num_rows($res);
if($count_sp > 0)
{
while($row1   = mysql_fetch_array($res))
      {
	   $equipment_id[]                                 = $row1['equipment_id'];  
       $equipment_name[]                               = $row1['equipment_name'];
	   $expiry_date[]                                  = $row1['expiry_date']; 
	   $serial_no[]                                    = $row1['serial_no'];
	  }
	  //print_r($equipment_name);
	   $smarty->assign('equipment_name',$equipment_name);
	   $smarty->assign('expiry_date',$expiry_date);
	   $smarty->assign('equipment_id',$equipment_id);
	   $smarty->assign('count_sp',$count_sp);
	   $today_date     = date("Y-m-d");
}	   
//for books	   
//$res_book    =	$database->Execute("select * from asset_books where issued_user='$user_id' and '$today_date' > issued_date;");

$day_range = 30;

$res_book    =	$database->Execute("select db1.* ,db2.full_name from asset_books as db1,asset_users as db2 where  db1.issued_user='$user_id' and db1.return_date > db1.issued_date AND DATE_ADD('$today_date',INTERVAL $day_range DAY) > db1.return_date group by db1.book_id;");
 
 //echo "select db1.* ,db2.full_name from asset_books as db1,asset_users as db2 where  db1.issued_user='$user_id' and db1.return_date > db1.issued_date AND DATE_ADD('$today_date',INTERVAL $day_range DAY) > db1.return_date;";

 $count_sp_book=mysql_num_rows($res_book);
 if($count_sp_book > 0)
 { 
  while($row_book   = mysql_fetch_array($res_book))
      { 
	   
		$issued_date 	                            = $row_book['issued_date'];
		$return_date								= $row_book['return_date'];
		$issued_dt[] 		                        = $row_book['issued_date'];
		$return_dt[]								= $row_book['return_date'];
		$today_year									=date('Y');
		$today_month								=date('m');
		$today_day									=date('d');
		$issued_dt_exp								=explode('-',$issued_date);
		$day1										= $today_year*365+$today_month*30+$today_day;
		$rt_dt										= explode('-',$return_date);
		$return_year								= $rt_dt[0];
		$return_month								= $rt_dt[1];
		$return_day									= $rt_dt[2];
		$day2										= $return_year*365+$return_month*30+$return_day;
		$day_rem									= $day2 - $day1;
		$book_id                                    = $row_book['book_id'];
		$book_name[]                                = $row_book['book_name'];  
		$isbn_no[]                                  = $row_book['isbn_no'];
		$author[]                                   = $row_book['author']; 
		$publisher[]                                = $row_book['publisher'];
		$full_name[]                                = $row_book['full_name'];
		$submit_date[]                              = $day_rem;
	   
	  }
	  //print_r($submit_date);
	   $smarty->assign('book_id',$book_id);
	   $smarty->assign('book_name',$book_name);
	   $smarty->assign('isbn_no',$isbn_no);
       $smarty->assign('author',$author);
	   $smarty->assign('publisher',$publisher);
 	   $smarty->assign('count_sp_book',$count_sp_book);
       $smarty->assign('full_name',$full_name);
       $smarty->assign('submit_date',$submit_date);
       $smarty->assign('issued_dt',$issued_dt);
       $smarty->assign('return_dt',$return_dt);
}	    	
 
   
}  
$smarty->display('welcome.tpl');
?>
Return current item: CoreAsset