<script type="text/javascript" language="javascript">
var http_request = false;
function makePOSTRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
/*if (dstatus == 'on')
{
http_request.onreadystatechange = alertContentsSecondary;
dstatus = 'off'
}
else
{*/
http_request.onreadystatechange = alertContents;
//}
http_request.open('POST', url, true);
http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http_request.setRequestHeader("Content-length", parameters.length);
http_request.setRequestHeader("Connection", "close");
http_request.send(parameters);
}
var dstatus = 'off'
//var srun = 0
var itemcount = 0
function processdata(operation, status) {
if (status == 'confirmed'){
var addpoststr = '&opstatus=confirmed'
str = cpoststr + addpoststr
dstatus = 'on'
makePOSTRequest('post3.php', str)
}
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
switch(directive) {
case "Populate":
document.getElementById('results').innerHTML = result
break
case "newitem":
try{var opprocess = document.getElementById('process').value}catch(err){}
//should take the data send it to the status span, then check that data to see if the status is confirmed, once confirmed it will process that data in the process data function to send back to the php display function
if (opprocess == 'addtodb' && dstatus == 'off')
{
document.getElementById('opspan').innerHTML = result
try{var status = document.getElementById('opstatus').value}catch(err){var status = "error"}
processdata(directive, status)
}
//populates the results table
else if (opprocess == 'addtodb' && dstatus == 'on')
{
//dstatus is the switch between the 2 and 3 _POST areas, turning it off means that the next run through the code will send the data to id=opspan instead of id=results
dstatus = 'off';
itemcount = itemcount++;
//testing for duplicates in the add item process, if duplicate is found then that duplicates information gets removed from 'allnewitems' and replaced with the new data, then all data gets sent to results table.
//var allitems[itemcount] = newitemid;
alert(dupes.length)
arrHasDupes(allnewitems);
//statement checking number of dupes
if (dupes.length > 0)
{
//delete duplicates
for(i=6;,i>=0,i--)
{
data.splice((dupes[i]-1),dupes[i]);
allitems.splice((dupes[i]-1),dupes[i]);
}
itemcount = itemcount - dupes.length;
}
for (i=itemcount,i<=0,i--)
{
document.getElementById('results').innerHTML = document.getElementByID('results').innerHTML + data[i]
}
}
else
{
document.getElementById('ops').innerHTML = result
//reset any itemcount for display of new results
itemcount = 0
}
break
}
}
//document.getElementById('results').innerHTML = result;
else {
alert('There was a problem with the request.'); }
}
}
var dupes
//function finds dupes and dumps them in a new arry called dupes
function arrHasDupes(A) { // finds any duplicate array elements using the fewest possible comparison
var i, j, n;
n=A.length;
var d = 0 // to ensure the fewest possible comparisons
for (i=0; i<n; i++) { // outer loop uses each item i at 0 through n
for (j=i+1; j<n; j++) { // inner loop only compares items j at i+1 to n
if (A[i]==A[j])
{
dupes[d] = i
d++;
}
} }
return false;
var directive
var cpoststr
function get(obj, operation, task) {
directive = operation
var poststr = "itype=" + encodeURI( document.getElementById("itype").value ) +
"&status=" + encodeURI( document.getElementById("status").value ) +
"&constraint=" + encodeURI( document.getElementById("constraint").value ) +
"&tfilter=" + encodeURI( document.getElementById("tfilter").value ) +
"&sstring=" + encodeURI( document.getElementById("sstring").value ) +
"&operation=" + operation;
if (operation == 'newitem' && task == 'process')
{
var newitemstr = "&newitemid=" + encodeURI( document.getElementById("newitemid").value) + "&newitemdescription="
+ encodeURI( document.getElementById("newitemdescription").value) + "&newitempartnumber="
+ encodeURI( document.getElementById("newitempartnumber").value) + "&newitemquantity="
+ encodeURI( document.getElementById("newitemquantity").value) + "&process=" + encodeURI( document.getElementById("process").value)
poststr = poststr + newitemstr
}
cpoststr = poststr
makePOSTRequest('post3.php', poststr);
}
</script>