2009-06-30 10:46:00 +00:00
|
|
|
/**
|
|
|
|
* @package phpLDAPadmin
|
|
|
|
* @author The phpLDAPadmin development team
|
|
|
|
* @author Xavier Bruyet
|
|
|
|
*/
|
|
|
|
|
|
|
|
// current request
|
2009-07-01 06:09:17 +00:00
|
|
|
var http_div = '';
|
2009-06-30 10:46:00 +00:00
|
|
|
var http_request = null;
|
|
|
|
var http_request_success_callback = '';
|
|
|
|
var http_request_error_callback = '';
|
|
|
|
|
2009-08-22 11:30:50 +00:00
|
|
|
function ajDISPLAY(div,urlParameters,display) {
|
|
|
|
var pageDiv = getDiv(div);
|
|
|
|
|
|
|
|
if (pageDiv)
|
|
|
|
includeHTML(pageDiv,'<img src="images/ajax-progress.gif"><br><small>'+display+'...</small>');
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
|
|
|
|
makeHttpRequest('cmd.php',urlParameters+'&meth=ajax','GET','alertAJ','cancelAJ',div);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajJUMP(url,title,index,prefix) {
|
|
|
|
var attr = prefix ? document.getElementById(prefix+index).value : index;
|
|
|
|
|
|
|
|
if (attr)
|
|
|
|
url += '&viewvalue='+attr;
|
|
|
|
|
|
|
|
return ajDISPLAY('BODY',url,'Loading '+title);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ajSHOWTHIS(key,except,ctl) {
|
|
|
|
select = document.getElementById(key+except);
|
|
|
|
|
|
|
|
if (select.style.display == '')
|
|
|
|
return false;
|
|
|
|
|
|
|
|
hideall(key,except,ctl);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
function ajSHOWSCHEMA(type,key,value) {
|
|
|
|
select = document.getElementById(type);
|
|
|
|
|
|
|
|
if (value != null) {
|
|
|
|
except = value;
|
|
|
|
select.value = value;
|
|
|
|
} else {
|
|
|
|
except = select.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! except) {
|
|
|
|
showall(key);
|
|
|
|
} else {
|
|
|
|
objectclass = document.getElementById(key+except);
|
|
|
|
objectclass.style.display = '';
|
|
|
|
hideall(key,except);
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
function hideall(key,except,ctl) {
|
|
|
|
items = items();
|
|
|
|
|
|
|
|
for (x in items) {
|
|
|
|
if (! isNaN(x) && except != items[x]) {
|
|
|
|
item = document.getElementById(key+items[x]);
|
|
|
|
item.style.display = 'none';
|
|
|
|
|
|
|
|
if (ctl && (item = document.getElementById(ctl+items[x]))) {
|
|
|
|
item.style.background = '#E0E0E0';
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (! isNaN(x) && except == items[x]) {
|
|
|
|
item = document.getElementById(key+items[x]);
|
|
|
|
item.style.display = '';
|
|
|
|
|
|
|
|
if (ctl && (item = document.getElementById(ctl+items[x]))) {
|
|
|
|
item.style.background = '#F0F0F0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showall(key) {
|
|
|
|
items = items();
|
|
|
|
|
|
|
|
for (x in items) {
|
|
|
|
if (! isNaN(x)) {
|
|
|
|
item = document.getElementById(key+items[x]);
|
|
|
|
item.style.display = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
// include html into a component
|
2009-08-22 11:30:50 +00:00
|
|
|
function includeHTML(component,html) {
|
2009-06-30 10:46:00 +00:00
|
|
|
if (typeof(component) != 'object' || typeof(html) != 'string') return;
|
|
|
|
component.innerHTML = html;
|
|
|
|
|
|
|
|
var scripts = component.getElementsByTagName('script');
|
|
|
|
if (!scripts) return;
|
|
|
|
|
|
|
|
// load scripts
|
|
|
|
for (var i = 0; i < scripts.length; i++) {
|
|
|
|
var scriptclone = document.createElement('script');
|
|
|
|
if (scripts[i].attributes.length > 0) {
|
|
|
|
for (var j in scripts[i].attributes) {
|
|
|
|
if (typeof(scripts[i].attributes[j]) != 'undefined'
|
2009-08-28 10:07:56 +00:00
|
|
|
&& typeof(scripts[i].attributes[j].nodeName) != 'undefined'
|
|
|
|
&& scripts[i].attributes[j].nodeValue != null
|
|
|
|
&& scripts[i].attributes[j].nodeValue != '') {
|
|
|
|
scriptclone.setAttribute(scripts[i].attributes[j].nodeName,scripts[i].attributes[j].nodeValue);
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scriptclone.text = scripts[i].text;
|
2009-08-22 11:30:50 +00:00
|
|
|
scripts[i].parentNode.replaceChild(scriptclone,scripts[i]);
|
2009-06-30 10:46:00 +00:00
|
|
|
eval(scripts[i].innerHTML);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// callback function
|
|
|
|
function alertHttpRequest() {
|
|
|
|
if (http_request && (http_request.readyState == 4)) {
|
2009-07-11 00:18:48 +00:00
|
|
|
if (http_request.status == 200 || http_request.status == 401) {
|
2009-06-30 10:46:00 +00:00
|
|
|
response = http_request.responseText;
|
|
|
|
http_request = null;
|
|
|
|
//alert(response);
|
|
|
|
if (http_request_success_callback) {
|
2009-07-01 06:09:17 +00:00
|
|
|
eval(http_request_success_callback + '(response,http_div)');
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alert('There was a problem with the request.');
|
|
|
|
cancelHttpRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function cancelHttpRequest() {
|
|
|
|
if (http_request) {
|
|
|
|
http_request = null;
|
|
|
|
if (http_request_error_callback) {
|
2009-07-01 06:09:17 +00:00
|
|
|
eval(http_request_error_callback + '(http_div)');
|
2009-06-30 10:46:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-01 06:09:17 +00:00
|
|
|
function makeHttpRequest(url,parameters,meth,successCallbackFunctionName,errorCallbackFunctionName,div) {
|
|
|
|
cancelHttpRequest(div);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
http_request_success_callback = successCallbackFunctionName;
|
|
|
|
http_request_error_callback = errorCallbackFunctionName;
|
2009-07-01 06:09:17 +00:00
|
|
|
http_div = div;
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
if (window.XMLHttpRequest) { // Mozilla, Safari,...
|
|
|
|
http_request = new XMLHttpRequest();
|
|
|
|
if (http_request.overrideMimeType) {
|
|
|
|
http_request.overrideMimeType('text/html');
|
|
|
|
}
|
2009-07-01 06:09:17 +00:00
|
|
|
|
2009-06-30 10:46:00 +00:00
|
|
|
} else if (window.ActiveXObject) { // IE
|
|
|
|
try {
|
2009-08-22 11:30:50 +00:00
|
|
|
http_request = new ActiveXObject('Msxml2.XMLHTTP');
|
2009-06-30 10:46:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
try {
|
2009-08-22 11:30:50 +00:00
|
|
|
http_request = new ActiveXObject('Microsoft.XMLHTTP');
|
2009-06-30 10:46:00 +00:00
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!http_request) {
|
|
|
|
alert('Cannot create XMLHTTP instance.');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
http_request.onreadystatechange = window['alertHttpRequest'];
|
|
|
|
if (meth == 'GET') url = url + '?' + parameters;
|
2009-08-22 11:30:50 +00:00
|
|
|
http_request.open(meth,url,true);
|
2009-06-30 10:46:00 +00:00
|
|
|
|
2009-08-22 11:30:50 +00:00
|
|
|
http_request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
|
|
|
|
http_request.setRequestHeader('Content-length',parameters.length);
|
|
|
|
http_request.setRequestHeader('Connection','close');
|
2009-06-30 10:46:00 +00:00
|
|
|
|
|
|
|
if (meth == 'GET') parameters = null;
|
|
|
|
http_request.send(parameters);
|
|
|
|
}
|