<?php

	include "small_library.php";


	$cxn = start_code( true, "", "true" );


	$member_id = val( $_GET, "memberid" );

	$ip_address = val( $_GET, "ipaddress" );


		/* clear out members not logged in */

	$prev_time = date("Y-m-d H:i:s", time() - 20);

	$query = "DELETE FROM online_status WHERE refresh_stamp < '".$prev_time."'";
	
	$result = run_query( $query, $cxn );



		/* refresh our stamp */

	$curr_time = date("Y-m-d H:i:s");


    if ($member_id != "")
    {
    	if (! query_has_rows( "SELECT id FROM online_status WHERE member_id = ".$member_id." AND ip_address = '".$ip_address."'", $cxn ))
    	{
    		$query = "INSERT INTO online_status ( member_id, ip_address, refresh_stamp ) VALUES ( ".$member_id.", '".$ip_address."', '".$curr_time."')";
    
    		$result = run_query( $query, $cxn );
    	}
    	else
    	{
    		$query = "UPDATE online_status SET refresh_stamp = '".$curr_time."' WHERE member_id = ".$member_id." AND ip_address = '".$ip_address."'";
    
    		$result = run_query( $query, $cxn );
    	}
    }
    

    echo "ok";  	/* don't change this it's used to identify that we're not sending through a chat request id */


?>