All pastes #519575 Raw Edit

mark

public text v1 · immutable
#519575 ·published 2007-05-29 18:21 UTC
rendered paste body
<html>
<style type="text/css">
<!--
.backStyle {
        position:absolute;
        width:269px;
        height:250px;
        left:0px;
        top:0px;
        z-index:0;
        visibility: visible;
}

.textStyle {
        font-family: Arial, Helvetica, sans-serif;
        font-size: 12px;
        color: #000000;
        position:absolute;
        z-index:1;
        left: 67px;
        top: 68px;
}

.inputStyle{
        position:absolute;
        z-index:2;
        left: 67px;
        top: 87px;
        visibility: visible;
}

.outputStyle{
	position:absolute;
	z-index:1;
	width: 200px;
	Height: 45px;
	left: 25px;
	top: 55px;
}

-->
</style>

<script language="javascript">
var xmlhttp=false;

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {

	try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }

}

function loadDoc(docname) {

	if (xmlhttp) {
	
	xmlhttp.open("GET", docname,true);
	 xmlhttp.onreadystatechange=function() {
	  if (xmlhttp.readyState==4) {
	   document.all.OutputLayer.innerHTML=xmlhttp.responseXml;
	  }
	 }
	 xmlhttp.send(null)

	 }

}

</script>

<body>
<div id="BackgroundLayer" class="backStyle">
  <center>
        <img src="./default.png" width="269" height="250">
  </center>
        <div id="TextLayer" class="textStyle">
                <div align="center"> Search for Recipes:</div>
        </div>
</div>

<div id="InputLayer" class="inputStyle">
  <center>
	<form action="test.php" method="get" name="recipeType">
	 <select name="type" id="recipeName" onChange="loadDoc('test.php')" size="1" border="0">
	  <option value="null" selected> </option>
	  <option value="appetizer" name="appetizer">Appetizers</option>
	  <option value="lunch" name="lunch">Lunches</option>
	  <option value="dinner" name="dinner">Dinners</option>
	  <option value="dessert" name="dessert">Desserts</option>
	 </select>
	</form>
  <center>
</div>

<div id="OutputLayer" class="outputStyle">

</div>





</body>
</html>










------------PHP/XML--------------------------


<?php
header('Content-Type: text/xml');


if(isset($_GET['type'])){ // if type is set in the url...
	$type = $_GET['type']; //...set variable $type
}
else{
	$type = 'lunch'; // if type is not set in url default to lunch
}



//list_by_ext: returns an array containing an alphabetic list of files in the specified directory ($path) with a file extension that matches $extension

function list_by_ext($extension, $path){
    $list = array(); //initialize a variable
    $dir_handle = @opendir($path) or die("Unable to open $path"); //attempt to open path
    while($file = readdir($dir_handle)){ //loop through all the files in the path
        if($file == "." || $file == ".."){continue;} //ignore these
        $filename = explode(".",$file); //seperate filename from extenstion
        $cnt = count($filename); $cnt--; $ext = $filename[$cnt]; //as above
        if(strtolower($ext) == strtolower($extension)){ //if the extension of the file matches the extension we are looking for...
            array_push($list, $file); //...then stick it onto the end of the list array
        }
    }
    if($list[0]){ //...if matches were found...
    sort($list); //...sort the list...
    return $list; //...return the array
    } else {//otherwise...
    return false;
    }
}



define('NL', chr(10));


if(is_dir('./recipes/'.$type)){
	echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
	echo "<recipes>\n";
	if($recipes = list_by_ext("docx", "./recipes/$type/")){
	    for($i = 0; $i < count($recipes); $i++){
		echo NL.'<recipe>'.NL.'<type>'.$type.'</type>'.NL.'<fileName>'.$recipes[$i].'</fileName>'.NL.'</recipe>';
	    }
	echo "\n</recipes>\n";
	}
}






?>