<?
/* This code is licensed under a BSD license. For more info, see license.txt */
require("wax.php");

/* Handle any call we may have comming in */
handle_wax_call(new wax_functions());

/* These are some special cases that should probibly be in a seperate file.
   They are used here to demonstrate the get_simple function and the submit_form
   function.
   */
if (@isset($_GET["get_date"])){
    
wax_headers();
    echo 
"The date, according to the server: " date("D, d M Y H:i:s");
    exit;
} else if (@isset(
$_GET["name"])){
    
wax_headers();
    echo 
"Hello " $_GET["name"] . "!  I see you like being able to post things like \"" $_GET["message"] . "\".";
    exit;
}

/* This class stores all the functions availble
   to the client-side javascript.
   */
class wax_functions {
    function 
get_date(){
        return 
"setHTML('output', 'The date, according to the server: " date("D, d M Y H:i:s") . "');";
    }
    function 
process_message($name$message){
        return 
"setHTML('output', 'Hello, " $name "!  I see you like being able to post things like \"" $message "\".')";
    }
    function 
get_source($filename){
        if(
$filename == 'wax.php' || $filename == 'example.php'){
            echo 
"element('output').innerHTML='";
            echo 
"<p align=left>";
            echo 
make_response_safe(highlight_string(join(" ",file($filename)),1));
            echo 
"</p>";
            echo 
"'";
        }
        return;
    }
    function 
get_whatis(){
        echo 
"setHTML('output','" make_response_safe("wax, or Wolever's AjaX, is a simple little toolkit that lets you add basic ajax functionality to your web page (PHP based or otherwise) with no knowlage of ajax and only very basic JavaScript.  Just take a look at the source code of this page to see how easy it is.") . "')";
        return;
    }
}


?>
<html><head><title>wax Test</title>
<script src="wax_common.js"></script>
<script>
<? echo wax_script('wax_functions'); // Insert the dynamic functions created by wax ?>
</script>
</head>
<body>
<button id="date_with_get_simple" onClick="get_simple('example.php?get_date=1','element(\'output\').innerHTML = response');">Get the date with get_simple()</button>
<form method=GET name="submit_form_name_form" onSubmit="return submit_form(this,'element(\'output\').innerHTML = response');" action="example.php">
<!-- Note that IE does not use buttons to submit forms by default, so it needs to have the this.form.onsubmit() to work -->
<button onClick="this.form.onsubmit();">Post a message with submit_form()</button>
<input type=text name="name" value="Your name" onClick="this.value='';"><input type=text name="message" value="Your message" onClick="this.value='';">
</form>

<button id="wax_date" onClick="get_date();">Get the date with a PHP function</button>
<form method=GET name="wax_name_form" onSubmit="return process_message(val('wax_name'),val('wax_message'));">
<button onClick="this.form.onsubmit();">Post a message with a PHP function</button>
<input type=text name="wax_name" value="Your name" onClick="this.value='';"><input type=text name="wax_message" value="Your message" onClick="this.value='';">
</form>
Get the source for:
<a href="" onClick="get_source('example.php'); return false;">example.php</a> 
<a href="" onClick="get_source('wax.php'); return false;">wax.php</a> <br>
<a href="#" onClick="get_whatis(); return false;">What the heck is wax, anyway?</a>
<center>
<p><div id="output">
The output will be here!
</div></p>
</center>
</body>
</html>