All pastes #381973 Raw Edit

Mine

public php v1 · immutable
·published 2007-03-05 05:34 UTC
rendered paste body
<script type="text/javascript" language="javascript"><!--	//XML RSS Parser For Artician.com.	//getFile() provided by http://www.expertsrt.com/tutorials/Rod/JSread.php	//XMLParser provided by KnyghtMare from #php on irc.gamesurge.net	//Help on figuring out XML DOM provided by http://www.captain.at/howto-ajax-parse-rss.php	function setEntries(value) {		getFile("<?php echo $site['urlroot']; ?>/xml/index.php?page=productlist&man="+encodeURIComponent(value),"");	}	function getFile(pURL,statusDiv) {		if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 			xmlhttp=new XMLHttpRequest();			xmlhttp.onreadystatechange=postFileReady;			xmlhttp.open("GET", pURL, true);			xmlhttp.send(null);		}		else if (window.ActiveXObject) { //IE 			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 			if (xmlhttp) {				xmlhttp.onreadystatechange=postFileReady;				xmlhttp.open('GET', pURL, false);				xmlhttp.send();			}		}	}	function XMLParser(XML) {		var xmlDoc = null;		if (window.ActiveXObject) {			xmlDoc = new ActiveXObject("Microsoft.XMLDOM");			xmlDoc.async=false;			xmlDoc.loadXML(XML);		}		// code for Mozilla, etc.		else if (document.implementation &&			document.implementation.createDocument) {			var parser = new DOMParser();			xmlDoc = parser.parseFromString(XML, "text/xml");		}		return xmlDoc;	}	// function to handle asynchronous call	function postFileReady() {		if (xmlhttp.readyState==4) { 			if (xmlhttp.status==200) { 				// convert string to XML object				var xmlobject = XMLParser(xmlhttp.responseText);								var dropdown = document.getElementById("printers");				// get a reference to the root-element "rss"				var root = xmlobject.getElementsByTagName('rss')[0];				// get reference to "channel" element				var channels = root.getElementsByTagName("channel");				// now get all "item" tags in the channel				var items = channels[0].getElementsByTagName("item");				// now get all "title" tags in the channel				//var titles = channels[0].getElementsByTagName("title");				// in the "item" we have a description, so get that				//var descriptions = items[0].getElementsByTagName("description");				// we also get the "pubDate" element in the "item"				var date = channels[0].getElementsByTagName("pubDate");				//Clear dropdown before populating it.				if(dropdown.length>0) {					for(s=0;s<dropdown.length;s++) {						dropdown.remove(s);					}				}				for(x=0;x<items.length;x++) {					var titles = items[x].getElementsByTagName("title");					var ids = items[x].getElementsByTagName("id");										var selections = new Array;										selections[x] = titles[0].firstChild.nodeValue;					dropdown.options[x] = new Option (selections[x],ids[0].firstChild.nodeValue);									}				if(items.length<1) {					dropdown.options[x] = new Option ("No Printers are in this category.","NULL");				}			}		}	}		function drawDisplay() {		printer = (getElement('printerYes').checked?true:false);		accessory = (getElement('accessoryYes').checked?true:false);		printerAccessory = getElement('printerAccessory').style;		printerAccessory2 = getElement('printerAccessory2').style;		printerSelectBox = getElement('printerSelectBox').style;		printerSelectBox2 = getElement('printerSelectBox2').style;		price = getElement('price').style;		price2 = getElement('price2').style;				if(!printer) {			printerAccessory.display = "block";			printerAccessory2.display = "block";			price.display = "block";			price2.display = "block";			if(accessory) {				printerSelectBox.display = "block";				printerSelectBox2.display = "block";			}			else {				printerSelectBox.display = "none";				printerSelectBox2.display = "none";			}		}		else {			printerAccessory.display = "none";			printerAccessory2.display = "none";			printerSelectBox.display = "none";			printerSelectBox2.display = "none";			price.display = "none";			price2.display = "none";		}	}--></script><?php$cat = isset($_POST['product']['cat'])?$_POST['product']['cat']:$_GET['cat'];$HTML['option'] = <<< EOF<option value="{VALUE}" {SELECTED}>{NAME}</option>EOF;function addProduct($input) {	global $table,$masterError;	if(!isset($input['make']) || empty($input['make'])) {		$masterError .= "Input field 'make' isn't set.<br>\n";	}	if(!isset($input['modal']) || empty($input['modal'])) {		$masterError .= "Input field 'modal' isn't set.<br>\n";	}	if(!isset($input['man']) || empty($input['man'])) {		$masterError .= "Input field 'manufacturer' isn't set.<br>\n";	}	if(!isset($input['cat']) || empty($input['cat'])) {		$masterError .= "Input field 'category' isn't set.<br>\n";	}	if($input['printer']=="no") {		if(!isset($input['price']) || empty($input['price'])) {			$masterError .= "Input field 'price' isn't set.<br>\n";		}		$input['price'] = str_replace(",",NULL,$input['price']);		$input['price'] = number_format($input['price'],2);		$input['price'] = str_replace(",",NULL,$input['price']);		if(!ereg("^[0-9]+(.[0-9]{2})?$", $input['price'])) {			$masterError .= "The price is invalid. Please input a value with two optional decimal points.";		}	}	else {		$input['price'] = "";	}		$printer = $input['printer']=="yes"?TRUE:FALSE;	if($printer) {		$accessory = $input['accessory']=="yes"?TRUE:FALSE;		$parentPrinter = $accessory?$input['parentPrinter']:FALSE;	}	$disabled = $input['disabled']?TRUE:FALSE;		if($masterError) {		return FALSE;	}		if(mysql_query("INSERT INTO {$table['products']} (`make`,`modal`,`category`,`manufacturer`,`price`,`description`,`active`,`accessory`,`printer`,`isPrinter`) VALUES ('{$input['make']}','{$input['modal']}','{$input['cat']}','{$input['man']}','{$input['price']}','{$input['description']}','" . ($disabled?"0":"1") . "','" . ($accessory?"1":"0") . "','" . (isset($parentPrinter)?$parentPrinter:"0") . "','" . ($printer?"1":"0") . "')")) {		return TRUE;	}	else {		$masterError = mysql_error();		return FALSE;	}}if(isset($_POST['submit'])) {	if($_POST['submit'] == "Add New Product") {		if(addProduct($_POST['product'])) {			if($_POST['action'] == "done") {				header("Location: " . $site['urlroot'] . "/acp/index.php?page=viewproducts&view=" . $_POST['product']['cat']);				exit;			}			else if($_POST['action'] == "another") {				$masterSuccess .= "Successfully added a product.<br>\n";				unset($_POST['product']);			}		}		else {			$masterError = "There was a problem submitting the new product:<br>\n".$masterError;		}	}}?><div class="header">Add Product</div><?php masterStatus(); ?><form action="<?php echo $site['currenturl']; ?>" method="post" name="addPrinter"><table cellspacing="0" cellpadding="1" border="0">	<tr>		<td>Make</td>		<td><input type="text" name="product[make]" value="<?php echo $_POST['product']['make']; ?>"/></td>	</tr>	<tr>		<td>Modal</td>		<td><input type="text" name="product[modal]" value="<?php echo $_POST['product']['modal']; ?>"/></td>	</tr>	<tr>		<td>Manufacturer</td>		<td><select name="product[man]"><?php echo generateManufacturer($_POST['product']['man'],FALSE); ?></select></td>	</tr>	<tr>		<td>Category</td>		<td><select name="product[cat]"><?php echo generateCategories($cat,FALSE); ?></select></td>	</tr>	<tr>		<td valign="top">Description:</td>		<td><textarea name="product[description]" style="width: 300px; height: 100px;"><?php echo $_POST['product']['description']; ?></textarea></td>	</tr>	<tr>		<td>		Is this product a printer?<br>		<font size="1">Printers aren't for sale. Only used for customer profiles.</font>		</td>		<td>		Yes <input type="radio" name="product[printer]" id="printerYes" onclick="drawDisplay();" value="yes" <?php echo ($_POST['product']['printer']=="yes"?"CHECKED":NULL); ?> />		No <input type="radio" name="product[printer]" id="printerNo" onclick="drawDisplay();" value="no" <?php echo (($_POST['product']['printer']=="no"||!isset($_POST['product']['printer']))?"CHECKED":NULL); ?> />		</td>	</tr>	<tr>		<td colspan="2">		<div id="printerAccessory" style="display:none;">		Is this product a printer accessory? 		</div>		</td>	</tr>	<tr>		<td colspan="2">		<div id="printerAccessory2" style="display:none;">		Yes <input type="radio" name="product[accessory]" id="accessoryYes" onclick="drawDisplay();" value="yes" <?php echo ($_POST['product']['accessory']=="yes"?"CHECKED":NULL); ?>/>		No <input type="radio" name="product[accessory]" id="accessoryNo" onclick="drawDisplay();" value="no" <?php echo (($_POST['product']['accessory']=="no"||!isset($_POST['product']['accessory']))?"CHECKED":NULL); ?> />		</div>		</td>	</tr>	<tr>		<td colspan="2">		<div id="printerSelectBox" style="display:<?php echo ($_POST['product']['accessory']=="yes"?"block":"none"); ?>;">		To which printer does this accessory belong?		</div>		</td>	</tr>	<tr>		<td colspan="2">		<div id="printerSelectBox2" style="display:<?php echo ($_POST['product']['accessory']=="yes"?"block":"none"); ?>;">		<select name="product[parentPrinter]" id="printers">		<option>Select a Manufacturer First Please --></option>		</select>		<select name="catForXML" onchange="javascript:setEntries(this.value);">		<option>--</option><?php echo generateManufacturer(); ?>		</select>		</div>		</td>	</tr>	<tr>		<td width="150" colspan="2">		Disabled: <input type="checkbox" name="product[disabled]" value="disabled" <?php echo ($_POST['product']['disabled']=="disabled"?"CHECKED":NULL); ?> /><br>		</td>	</tr>	<tr>		<td colspan="2">		<font size="1">Disabled products are no longer available for order. Also note that products can not be deleted but can only be edited or disabled.</font><br>		</td>	</tr>	<tr>		<td><div id="price">Price</div></td>		<td><div id="price2">$<input type="text" name="product[price]" value="<?php echo $_POST['product']['price']; ?>" size="10"/> (0000.00)</div></td>	</tr>	<tr>		<td><script type="text/javascript" language="javascript">drawDisplay();</script></td>		<td><input type="submit" name="submit" value="Add New Product" /></td>	</tr>	<tr>		<td colspan="2">		<input type="radio" name="action" value="done" <?php echo ($_POST['action']!="another")?"CHECKED":NULL; ?> /> Submit and go back to the category product list.<br />		<input type="radio" name="action" value="another" <?php echo $_POST['action']=="another"?"CHECKED":NULL; ?>/> Submit and submit another.<br />		</td>	</tr></table></form>