Location: PHPKode > projects > HypatiaDB > hypatiadb/js/rep4.php
<?php header("Content-Type: text/javascript");
include('../common_db.php');
include('../functions.php');
dbconnect($host, $username, $password);
$strings = loadStrings($lang, 'REP4JS');

//This function is responsible for adding the sort to the database
//via a XmlHttpRequest, and adding it visually so that the user can see
//it. Assuming success, it also clears the form elements for the next
//condition to be added.

//TODO: Internet explorer support

$report_id = intval($_REQUEST['rid']);
?>
var r4condReq;
function addSort() {
	r4condReq = new XMLHttpRequest();
	r4condReq.onreadystatechange = callback;
	r4condReq.open("POST", "xhr/addReportSort.php");
	r4condReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	r4condReq.send('rid=<?php echo($report_id)?>&field=' + document.getElementById('sort_field').value + '&type=' + (document.getElementById('asort').checked == true ? 'asc' : 'desc' ));
}

function callback() {
	if(r4condReq.readyState == 4) {
		if(r4condReq.status != 200) {
			alert('Server returned a ' + r4condReq.status);
		} else {
			var e = document.getElementById('sorts');
			var src = r4condReq.responseXML.firstChild;
			var nn = document.importNode(src, true);
			e.appendChild(nn);
			var a = document.getElementById('sort_field');
			for(var i = a.options.length-1; i>=0; i--) {
				if(a.options[i].selected) {
				a.remove(i);
				}
			}
		}
	}
}

var r4killReq;

function removeSort(id) {
	r4killReq = new XMLHttpRequest();
	r4killReq.open("GET", "xhr/killReportSort.php?id=" + id);
	r4killReq.send("");
	document.getElementById('sort' + id).parentNode.removeChild(document.getElementById('sort' + id));
} 
Return current item: HypatiaDB