<?
function addLog($u,$t)
{
include "connect.inc.php";
$dnow = date("Y-m-d H:i:s");
$sqladdlog = "insert into usrlog values('$dnow','$u','$t')";
//echo $sqladdlog;
mysql_query($sqladdlog) or die ("can't insert log");
mysql_close($link);
}
function updatetime($username)
{
	include "connect.inc.php";
	$dnow = date("Y-m-d H:i:s");
	$sqlupdatetime = "update sysuser set lastlogin = '$dnow' where uname='$username'";
	//echo $sqlupdatetime;
	mysql_query($sqlupdatetime);
}
function ChangePassword($uid,$newpwd)
{
	include "connect.inc.php";
	$sqlupdate = "update sysuser set pwd=password('$newpwd') where uname='$uid'";
	//echo $sqlupdate;
	mysql_query($sqlupdate) or die("can't change password");
	//require_once("usr_function.php");
	$msg = "Your password has been change";
	ErrMsg($msg);
}
function ChangePasswordAdmin($newpwd)
{
	include "connect.inc.php";
	$sqlupdate = "update sysuser set pwd=password('$newpwd') where uname='admin'";
	//echo $sqlupdate;
	mysql_query($sqlupdate) or die("can't change password");
	//require_once("usr_function.php");
	$msg = "Your password for admin has been set";
	ErrMsg($msg);
}
function AddUser($usname,$passwd,$nameuser,$st)
{
	include "connect.inc.php";
	$sqladduser = "insert into sysuser(uname,pwd,nameofuser,status) values('$usname',password('$passwd'),'$nameuser',$st)";
	//echo $sqladduser;
	mysql_query($sqladduser) or die(mysql_error());
}
function UpdateUser($usname,$newusname,$passwd,$nameuser,$st)
{
	include "connect.inc.php";
	$sqlupdateuser = "Update  sysuser set uname='$newusname',pwd=password('$passwd'),nameofuser='$nameuser',status=$st where uname='$usname'";
	//echo $sqlupdateuser;
	mysql_query($sqlupdateuser) or die(mysql_error());
}
function UpdateUserNoPass($usname,$newusname,$nameuser,$st)
{
	include "connect.inc.php";
	$sqlupdateuser = "Update  sysuser set uname='$newusname',nameofuser='$nameuser',status=$st where uname='$usname'";
	//echo $sqlupdateuser;
	mysql_query($sqlupdateuser) or die(mysql_error());
}


function DeleteUser($usname)
{
	include "connect.inc.php";
	$sqldeleteuser = "delete from sysuser where uname='$usname'";
	//echo $sqladduser;
	mysql_query($sqldeleteuser) or die(mysql_error());
}
function chknull($tb)
{
return empty($tb) ? "NULL": $tb;
}

function ErrMsg($msg)
{	
	echo "<script>alert('$msg')</script>";
}
?>