/**
* KAPAJAX module -
* Kris' Awesome PHP Asynchrnonous Javascript and XML module.
*
* Not for distribution.
* (C) 2005 Kris Sum
*/
// CLASS construct
function KAPAJAX() {
KAPAJAX.prototype.init = createRequestObject;
KAPAJAX.prototype.sendComment = sendComment;
KAPAJAX.prototype.getRoomInfo = getRoomInfo;
KAPAJAX.prototype.getRoomSearchResults = getRoomSearchResults;
KAPAJAX.prototype.getTopSearchResults = getTopSearchResults;
/**
* Creates an XML HTTP Request Object
* Works for both IE and Mozilla etc.
*
*/
function createRequestObject() {
if (window.XMLHttpRequest) {
// Mozilla/other based browser
this.xmlhttp = new XMLHttpRequest();
if (this.xmlhttp.overrideMimeType) {
// this.xmlhttp.overrideMimeType('text/xml');
// - use only if returning valid XML
}
} else if (window.ActiveXObject) {
// IE based browser
try {
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) { }
}
}
}
/**
* Sends a comment to the webmaster.
*
* @param string nav
* @param string confirmCode
* @param string fromName
* @param string fromEmail
* @param string messageText
* @param string theStatus
* @param string theCommentBox
*/
function sendComment(nav,confirmCode,fromName,fromEmail,messageText,theStatus,theCommentBox) {
var xmlhttp=this.xmlhttp;
this.xmlhttp.open('get','http://www1.secam.ex.ac.uk/scripts/kapajax/sendComment.php?nav='+nav+'&confirmCode='+confirmCode+'&fromName='+fromName+'&fromEmail='+fromEmail+'&messageText='+messageText);
this.xmlhttp.onreadystatechange =
function () {
// setup variables
obj_status = document.getElementById(theStatus);
obj_cbox = document.getElementById(theCommentBox);
// LOADING
if (xmlhttp.readyState == 1) {
if (obj_status!=null) obj_status.innerHTML = ' Requesting Reply...';
}
// DATA LOADED
if (xmlhttp.readyState == 4) {
if (xmlhttp.status != 200) {
if (obj_status!=null) obj_status.innerHTML = '
An error occured whilst connecting to the comments system. Please try again later.
';
} else {
var response = xmlhttp.responseText;
// check security
if (response == 'unauthorised') {
if (obj_status!=null) obj_status.innerHTML = 'An error occured whilst connecting to the comments system. Please ensure you have cookies enabled.
';
} else {
if (response.charAt(0)=='1') {
if (obj_cbox!=null) obj_cbox.innerHTML = 'Comment Received, thank you for your feedback!
';
} else if (response.charAt(0)=='2') {
if (obj_status!=null) obj_status.innerHTML = ''+response.substring(1)+'
';
document.getElementById('submit_button').style.display='';
}
} // not unauthorised
} // xmlhttp status 200
} // DATA LOADED
}
this.xmlhttp.send(null);
} // sendComment
/**
* Retrieves room information based on roomIDd
*
* @param integer roomId
*/
function getRoomInfo(roomId,theStatus,theTarget) {
var xmlhttp=this.xmlhttp;
this.xmlhttp.open('get','http://www1.secam.ex.ac.uk/scripts/kapajax/getroominfo.php?roomId='+roomId);
this.xmlhttp.onreadystatechange =
function () {
// setup variables
obj = document.getElementById(theTarget);
obj_status = document.getElementById(theStatus);
// LOADING
if (xmlhttp.readyState == 1) {
if (obj_status!=null) obj_status.innerHTML = ' Loading...';
}
// DATA LOADED
if (xmlhttp.readyState == 4) {
if (xmlhttp.status != 200) {
if (obj_status!=null) obj_status.innerHTML = 'ERROR';
} else {
var response = xmlhttp.responseText;
// debug
// document.getElementById('test').innerHTML = response;
// check security
if (response == 'unauthorised') {
if (obj_status!=null) obj_status.innerHTML = 'Unauthorised access';
} else {
if (obj_status!=null) obj_status.innerHTML = ' ';
if (obj!=null) obj.innerHTML = response;
} // not unauthorised
} // xmlhttp status 200
} // DATA LOADED
}
this.xmlhttp.send(null);
} // getRoomInfo
/**
* Retrieves the result of a search for room info
*
* @param string search_text - text to search for
* @param string search_area - area to search in
* @param string theTarget - area to populate
*/
function getRoomSearchResults(search_text,search_area,theTarget) {
var xmlhttp=this.xmlhttp;
this.xmlhttp.open('get','http://www1.secam.ex.ac.uk/scripts/kapajax/getroomsearchresults.php?searchtext='+search_text+'&searcharea='+search_area);
this.xmlhttp.onreadystatechange =
function () {
// setup variables
obj = document.getElementById(theTarget);
obj_status = document.getElementById(theTarget);
// LOADING
if (xmlhttp.readyState == 1) {
if (obj_status!=null) obj_status.innerHTML = ' Running Search...';
}
// DATA LOADED
if (xmlhttp.readyState == 4) {
if (xmlhttp.status != 200) {
if (obj_status!=null) obj_status.innerHTML = 'ERROR';
} else {
var response = xmlhttp.responseText;
// debug
// document.getElementById('test').innerHTML = response;
// check security
if (response == 'unauthorised') {
if (obj_status!=null) obj_status.innerHTML = 'Unauthorised access';
} else {
if (obj_status!=null) obj_status.innerHTML = ' ';
var index=response.indexOf('-');
var numresults = response.substring(0, index);
response = response.substring(index+1, response.length);
index=response.indexOf('-');
var firstresult = response.substring(0, index);
var searchresults = response.substring(index+1, response.length);
if (obj!=null) obj.innerHTML = searchresults;
if (numresults==1) {
}
} // not unauthorised
} // xmlhttp status 200
} // DATA LOADED
}
this.xmlhttp.send(null);
} // getRoomSearchReults
/**
* Retrieves the result of a search from the top toolbar
*
*/
function getTopSearchResults(search_text,search_area,theTarget,theStatus,theSearchResult) {
var xmlhttp=this.xmlhttp;
//this.xmlhttp.abort; - BERAKS IN IE
this.xmlhttp.open('get','http://www1.secam.ex.ac.uk/scripts/kapajax/gettopsearchresults.php?searchtext='+search_text+'&searcharea='+search_area);
this.xmlhttp.onreadystatechange =
function () {
// setup variables
obj = document.getElementById(theTarget);
obj_status = document.getElementById(theStatus);
obj_searchResult = document.getElementById(theSearchResult);
// LOADING
if (xmlhttp.readyState == 1) {
if (obj_status!=null) obj_status.innerHTML = ' Running Search...';
}
// DATA LOADED
if (xmlhttp.readyState == 4) {
if (xmlhttp.status != 200) {
if (obj_status!=null) obj_status.innerHTML = 'ERROR';
} else {
var response = xmlhttp.responseText;
// debug
// document.getElementById('test').innerHTML = response;
// check security
if (response == 'unauthorised') {
if (obj_status!=null) obj_status.innerHTML = 'Unauthorised access';
} else {
if (obj_status!=null) obj_status.innerHTML = ' ';
var index=response.indexOf('-');
var numresults = response.substring(0, index);
response = response.substring(index+1, response.length);
index=response.indexOf('-');
var firstresult = response.substring(0, index);
var searchresults = response.substring(index+1, response.length);
if (obj!=null) {
if (numresults==0) {
obj_status.innerHTML='No Results Found';
obj.style.display='none';
} else {
obj_searchResult.innerHTML = searchresults;
var windowWidth=getWindowSize('width')-530;
obj.style.left=windowWidth+'px';
obj.style.opacity=0;
obj.style.display='';
var attributes = { width: {to: 500}, height: {to: 200},opacity: { to: 0.93} };
var anim = new YAHOO.util.Anim(obj, attributes, 1, YAHOO.util.Easing.easeOut);
anim.animate();
}
}
if (numresults==1) {
}
} // not unauthorised
} // xmlhttp status 200
} // DATA LOADED
}
this.xmlhttp.send(null);
} // getTopSearchReults
} // end of class