<?php

if (preg_match('/funcconnect.php/i', $_SERVER['PHP_SELF']))
{ header("location:index.php");
  exit;
  }
  
function openDB()
{ global $dbConnection;
		include "common/config/dbconfig.php";
		$dbConnection=mysqli_connect($dbHost, $dbUser, $dbPassword, $dbName) or die ("Database connection failed");
  }
		
function closeDB()
{ global $dbConnection;
		mysqli_close($dbConnection);
  }

function userpresence($username)
{ global $dbConnection;
		include "common/config/config.php";
		$sql="SELECT logintime 
								FROM $db_appusers
								WHERE username='".$username."'
								";
		$res=mysqli_query($dbConnection, $sql);
		$dat=mysqli_fetch_array($res);
		if (mysqli_num_rows($res)>0 && !empty($dat['logintime']))
		{ list ($cY, $cM, $cD, $cH, $cI, $cS)=preg_split("/[- :]/", $dat['logintime']);
				$timeafter=date("d-m-Y H:i:s", mktime($cH, $cI+5, $cS, $cM, $cD, $cY));
				$sessionrange=strtotime($timeafter);
				$skrg=strtotime($wktsekarang);
				if ($skrg>=$sessionrange)
				{ return true;
						}
				else
				{ return false;
						}
				}
		else
		{ return true;
				}
		}

?>