<?echo '<?
xml version="1.0" encoding="ISO-8859-1"?>' ?>
<!DOCTYPE
html PUBLIC "-//
W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php
require("Sajax.php");
function colorify_ip($
ip)
{
$parts = explode(".", $
ip);
$color = sprintf("%02s", dechex($parts[1])) .
sprintf("%02s", dechex($parts[2])) .
sprintf("%02s", dechex($parts[3]));
return $color;
}
function add_line($msg) {
$f = fopen("/tmp/wall.html", "a");
$dt = date("Y-m-d h:i:s");
$msg = strip_tags(stripslashes($msg));
$remote = $_SERVER["REMOTE_ADDR"];
// generate unique-ish color for
IP
$color = colorify_ip($remote);
fwrite($f, "<span style=\"color:#$color\">$dt</span> $msg
\n");
fclose($f);
}
function refresh() {
$lines = file("/tmp/wall.html");
// return the last 25 lines
return join("\n", array_slice($lines, -25));
}
$sajax_request_type = "GET";
sajax_init();
sajax_export("add_line", "refresh");
sajax_handle_client_request();
?>
<
html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="de">
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//<![CDATA[
<?
sajax_show_javascript();
?>
var check_n = 0;
var old_data = "--";
function refresh_cb(new_data) {
if (new_data != old_data) {
document.getElementById("wall").innerHTML = new_data;
setTimeout("refresh()", 1000);
old_data = new_data;
} else {
setTimeout("refresh()", 2500);
}
document.getElementById("status").innerHTML = "Checked #" + check_n++;
}
function refresh() {
document.getElementById("status").innerHTML = "Checking..";
x_refresh(refresh_cb);
}
function add_cb() {
// we don't care..
}
function add() {
var line;
var
handle;
handle = document.getElementById("
handle").value;
line = document.getElementById("line").value;
if (line == "")
return;
sajax_request_type = "POST";
x_add_line("[" +
handle + "] " + line, add_cb);
document.getElementById("line").value = "";
}
//]]>
</script>
</head>
<body onload="refresh();">
<div id="container">
<div id="kopf"></div>
<div id="navigation"><div id="rollovermenu"><?php include 'navi.ink' ?></div></div>
<div id="links"><?php include 'valid.ink' ?></div>
<div id="inhalt">
<h1>Chat</h1>
<form action="#" onsubmit="add();return false;">
<input type="text" name="
handle" id="
handle" value="(Name)" onfocus="this.select()" style="width:130px;" />
<input type="text" name="line" id="line" value="(Nachricht)" onfocus="this.select()" style="width:300px;" />
<input type="button" name="check" value="Senden" onclick="add(); return false;" />
<div id="wall"></div>
<div id="status">[i]Loading..[/i]</div>
</form>
</div>
</div>
</body>
</
html>