<?
	require("Sajax.php");
	
	function portstatus() {
		return date("M dS, Y, H:i:s  ") . " STATUS=" . file_get_contents("status.txt");
	}
        function portcontrol($x, $y) {
                // read file
                $controlstring=file_get_contents("status.txt");
                if ($controlstring==FALSE) $controlstring = '00000000';
                if (($x >= 0) && ($x < 8)) {
                 if ($y == 1) 
                 {
		  $controlstring[7-$x]='1';
                 }
                 else
                 {
                   $controlstring[7-$x]='0';
                 }
                }
                // write file
                $filehandle=fopen ("status.txt",'w'); 
                fwrite($filehandle, $controlstring); 
		fclose($filehandle);
                return portstatus();
        }
	
	sajax_init();
	// $sajax_debug_mode = 1;
	sajax_export("portstatus");
        sajax_export("portcontrol");
	sajax_handle_client_request();
	
?>
<html>
<head>
	<title>Port control</title>
	<script>
	<?
	sajax_show_javascript();
	?>
	
	function do_portstatus_cb(z) {
		// update status field in form
		document.getElementById("status").value = z;
	}
	
	function do_portstatus() {
		x_portstatus(do_portstatus_cb);
		setTimeout('do_portstatus();',5000); // executes the next data query in every n milliseconds
	}

	function do_portcontrol_cb(z) {
		// update status field in form
		document.getElementById("status").value = z;
        }
	
	function do_portcontrol(bit,value) {
		x_portcontrol(bit,value,do_portcontrol_cb);
	}

	</script>
	
</head>
<body>

<SCRIPT LANGUAGE="JavaScript">
<!--
do_portstatus();
// -->
</SCRIPT>

<P>

<H1>Port control</H1>
<P>

<input type="text" name="status" id="status" value="No status yet" size="60">

<P>

Bit 0: 
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(0,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(0,0); return false;">
<BR>
Bit 1:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(1,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(1,0); return false;">
<BR>
Bit 2:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(2,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(2,0); return false;">
<BR>
Bit 3:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(3,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(3,0); return false;">
<BR>
Bit 4:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(4,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(4,0); return false;">
<BR>
Bit 5:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(5,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(5,0); return false;">
<BR>
Bit 6:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(6,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(6,0); return false;">
<BR>
Bit 7:
<input type="button" name="check" value="Set"
		onclick="do_portcontrol(7,1); return false;">
<input type="button" name="check" value="Reset"
		onclick="do_portcontrol(7,0); return false;">
<BR>


</body>
</html>






