Location: PHPKode > projects > phpautotest > record.php
<?php
session_start();

require 'includes/phpautotest_config.php';
require 'includes/phpautotest_functions.php';

restrict_access();
?>
<HTML>
<HEAD>
<TITLE>phpautotest</TITLE>
</HEAD>
<script type='text/javascript' src='./jsolait/init.js'></script>
<script type='text/javascript' src='./dojo/dojo.js'></script>
<script type='text/javascript' src='tophp.js'></script>
<SCRIPT LANGUAGE='JavaScript'>

<?php
echo
"
var phpautotest_install_path = '$phpautotest_install_path';
dojo.require('dojo.event.*');
var phpautotest_report = 1;
var record = 0;
// Does the user want to be informed whenever the back-end is requested to record a page? Toggled via top.php
var interact = true;
";
?>

// Sends data to PHP whenever a page loads, so we know of page changes
function page_change()
{
	top.frames[0].document.location = 'top.php';
	// Check if a 
	if(self.frames[1].page_var != '979a_PTFE')
	{
		record = 1;

		// Make top frame reload so it can detect the page change
		top.frames[0].document.location = 'top.php';
	}
	
	// Initially recording is disabled
	if(record == 1)
	{
		// If page change took place due to a form then dont report page change to phpautotest
		if(phpautotest_report == 1)
		{
			var urllib = importModule('urllib');
			var codecs = importModule('codecs');
			
			getdata = new Array();
			
			// Javascript refuses to allow me to place the string in the array unless I do this, WHY???
			plocation = new String(self.frames[1].document.location);

			// Base64 Encode the URL as we are passing it via HTTP, it will cause problems
			plocation = plocation.encode_base64();
				
			getdata['plocation'] = plocation;
			
			// Serialize it
			getdata = getdata.toPHP();
			
			window.status = 'Reporting page change to phpautotest...';
						
			// Without this header POST data doesnt make it to PHP
			header_post = new Array('Content-Type', 'application/x-www-form-urlencoded');

			headers = new Array(header_post);
						
			urllib.postURL('phpautotest_backend.php', null, null, 'getdata='+getdata, headers);
			
			if(interact == true)
			{
				alert('Asked phpautotest back-end to record '+self.frames[1].document.location);
			}
			
			window.status = '';
		}
	}
	
	// Allow further reporting
	phpautotest_report = 1;
}

// Sends data to PHP using Javascript o laits urllib
function send()
{
	var urllib = importModule('urllib');

	window.status = 'Serializing form elements....';
	
	// Serialize so we can send it
	postdata = serialize_form_data(this.no);
	
	window.status = 'Finished serializing. Sending to phpautotest...';
	
	// Without this header POST data doesnt make it to PHP
	header_post = new Array('Content-Type', 'application/x-www-form-urlencoded');

	headers = new Array(header_post);
						
	urllib.postURL('phpautotest_backend.php', null, null, 'postdata='+postdata, headers);
	
	if(interact == true)
	{
		alert('Asked phpautotest back-end to record '+self.frames[1].document.location+' and '+self.frames[1].document.forms[this.no].length+' form fields');
	}

	window.status = '';
	
	// Dont allow the impending page change to be reported again to phpautotest
	phpautotest_report = 0;
}

// Extract all elements from the form and serialize the resultant array using Harry Fuecks ToPHP.js
function serialize_form_data(no)
{
	// Loop through all the elements of the form and store them in an array
	aform = self.frames[1].document.forms[no];
	
	form_data = new Array();
	elements = new Array();
	element_name = new Array();
	element_value = new Array();
	
	for(var i = 0; i < aform.length; i++)
	{
		elements[aform.elements[i].name] = aform.elements[i].value;
	}
		
	action = new String(aform.action);
	form_data['action'] = action.encode_base64();
	
	form_data['elements'] = elements;
	// Javascript refuses to allow me to place the string in the array unless I do this, WHY???
	plocation = new String(self.frames[1].location);
	
	// Base64 Encode the URL as we are passing it via HTTP, it will cause problems
	plocation = plocation.encode_base64();
		
	form_data['plocation'] = plocation;
	
	return form_data.toPHP();
}

function submit_handler(i) 
{
	// The number of the form
	this.no = i;   
	
	// Used to call urllib
	this.send = send;
}

// Use Dojo to connect all submit events to a function that sends the data to PHP first
function connect_listeners()
{
	// Initially recording is disabled
	if(record == 1)
	{
		l = new Array();
		for(var i = 0; i < self.frames[1].document.forms.length; i++)
		{
			l[i] = new submit_handler(i);
			
			// Set up listeners only for POST forms
			if(self.frames[1].document.forms[i].method == 'post')
			{
				dojo.event.connect(self.frames[1].document.forms[i], 'onsubmit', l[i], 'send');
			}
		}
	}
}

</SCRIPT>
<FRAMESET ROWS='5%,95%' border='1' frameborder='0' framespacing='0'>
<FRAME SRC='top.php' NAME='phpautotest'>
<FRAME SRC='start.php' NAME='targetpage' onLoad = 'page_change(), connect_listeners()'>
</FRAMESET>
</HTML>
Return current item: phpautotest