All pastes #560216 Raw Edit

patrick britz

public text v1 · immutable
·published 2007-06-12 01:06 UTC
rendered paste body
<html>
<head>
<title>Blair Business Communication Inventory Tracking System</title>
</head>
<body>
<div align="left">
	<img src="logot.jpg"></br>

</div></br>
<div align="left">
<form method="post" name="tiger" action="javascript:get(document.getElementById('tiger'));">
Search via Bar Code</br>
<input type="text" length="10" name="barcode" id="barcode"></br>	
<table border="0" width="100%">

		<tr style="background-color:#e4e4e4;">
			<td width="100">
				Inventory Type<br>
				<select name="itype" id="itype">
				<option value="" selected>All</option>
				<option value="rental">Rental</option>
				<option value="material">Material</option>
				</select>
			</td>
			<td width="10%">
				Status<br>
				<SELECT id="status" NAME="status">
				<Option value="">All</option>
				<Option value="leased">On Lease</option>
				<Option value="ininventory">In Inventory</option>
				<Option value="notreceived">Not Received</option>
				<Option value="outofstock">Out of Stock</option>
				<Option value="inactive">Inactive</option>
				<Option value="discontinued">Discontinued</option>
				</SELECT>
			</td>
			<td width="10%">
				Search Constraint<br>
				<SELECT id="constraint" NAME="constraint">
				<Option value="">None</option>
				<Option value="name">Name</option>
				<Option value="description">Description</option>
				<Option value="partnumber">Part Number</option>
				<Option value="location">Location</option>
				<Option value="serialnumber">Serial Number</option>
				<Option value="serviceorder">Service order</option>
				<Option value="serviceorder">Part Number</option>
				</SELECT>
			</td>
			<td width="10%">
				Text Filter<br>
				<SELECT id="tfilter" NAME="tfilter">
				<Option value="">None</option>
				<Option value="including">Including</option>
				<Option value="excluding">Excluding</option>
				<Option value="matching">Matching</option>
				</SELECT>
			</td>
			<td width="10%">
				Search String<br>
				<input type="text" length="10" name="sstring" id="sstring">
			</td>
			<td align="left">
			<input type="button" name="populate" id="populate" value="Populate" onclick="javascript:get(this.parentNode, 'Populate');">
			</td>

		</tr>
	</table>
	<table>
	<tr>
		<td>
			Operation</br>
			<SELECT id="formop" NAME="pickop">
			<Option value="newitem">Create Item</option>
			<Option value="newassembly">Create Assembly</option>
			<Option value="removeassembly">Remove Assembly</option>
			<Option value="remove">Remove Selected</option>
			<Option value="rent">Rent Selected</option>
			<Option value="returnrental">Return Rental</option>
			</SELECT>	
			<input type="button" name="execute" value="Execute" id="execute" onclick="javascript:get(this.parentNode, document.getElementById('formop').value)">
		</td>
		<td width="400">
			<span id="ops"></span>
		</td>
		<td>
			<span id="opspan"></span>
		</td>
	</tr>
	</table>
<input type="hidden" id="opstatus" value="confirmed">
<form name="operations" id="operations"> 	

</form>
<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>


<hr>	
<span id="results"></span>
	</form>
</div>
</body>
</html>