<?php 
include_once __INCLUDE_CLASS_PATH."/class.ItemManager.php";
$option_manager = new OptionManager();
$sesstime=$option_manager->GetValue('session_exptime');

 $Sess_UserId=$_SESSION['Sess_UserId'];
 $Sess_UserName=$_SESSION['Sess_UserName'];
$time=time();

$timeout = time()-$sesstime*60;
      $q = "DELETE FROM ".TBL_ACTIVE_USERS." WHERE timestamp < $timeout";
      mysql_query($q);

 //$act_sess="select count(*) as count from ".TBL_ACTIVE_USERS." where username='$Sess_UserName'";
 $act_sess="select count(*) as count from active_users where username='$Sess_UserName'";
 
 $active=mysql_query($act_sess);
 $count_row=mysql_fetch_object($active);
 $count=$count_row->count;

if($count==0){


echo "<script>location.href='" . $CONST_LINK_ROOT . "/logoff.php?log_time=expired'</script>";


}else{

 $q = "UPDATE members SET timestamp = '$time' WHERE mem_username = '$Sess_UserName'";
      mysql_query($q);
 $q = "REPLACE INTO active_users VALUES ('$Sess_UserId', '$Sess_UserName', '$time')";
      mysql_query($q);
}


if (!isset($Sess_UserId))	
{
    //Save current request and redirect to the login page.
   

     echo "<script>location.href='" . $CONST_LINK_ROOT . "/logoff.php'</script>";   
 
   
}
?>