Location: PHPKode > projects > Wiki Web Help > wwh/handlers/getindex.php
<?php
require_once("../config.php");

$lang = $_GET['lang'];
if(!preg_match('/[a-z]{2}/',$lang)) exit;
$sql = "SELECT * FROM langxref WHERE language = '$lang'";
$result = mysql_query($sql,$con) or die("<tree><root id='0'></root></tree>");

$id = mysql_result($result, 0, 'node_id');

$label = '';
$in = '';
header("Content-Type: text/xml");
$in = parseTree($id, $label, $in, $con, false);
$in = substr($in, 1);

$sql = "SELECT DISTINCT tag.tag,tag.tag_id FROM tagxref ";
$sql .= "INNER JOIN tag ON tagxref.tag_id = tag.tag_id ";
$sql .= "WHERE tagxref.node_id IN ($in) AND tag.tag !='' ORDER BY tag.tag";
$result = mysql_query($sql,$con) or die("<index><root id='$in'></root></index>");
$xml = "<index>";

for($r=0;$r<mysql_num_rows($result);$r++){
	$tag = htmlspecialchars(mysql_result($result, $r, 'tag'), ENT_QUOTES, 'UTF-8' );
	$tag_id = mysql_result($result, $r, 'tag_id');

	$sql = "SELECT tagxref.node_id,node.label FROM tagxref INNER JOIN node ON tagxref.node_id=node.node_id ";
	$sql .= "WHERE tag_id=$tag_id AND  tagxref.node_id IN ($in) AND node.parent_id != 0 ORDER BY node.label";
	$resultn = mysql_query($sql,$con) or die("<index><root id='-1'></root></index>");

	if(mysql_num_rows($resultn) > 0)
			$xml .= "<tag label='$tag'>"; // make sure it is not a tag from deleted page

	for($n=0;$n<mysql_num_rows($resultn);$n++){
		$node_id = mysql_result($resultn, $n, 'node_id');
		$label = mysql_result($resultn, $n, 'label');
		$xml.="<node id='$node_id' label='" . htmlspecialchars( $label, ENT_QUOTES, 'UTF-8' ) . "' />";
	}
	$xml.= "</tag>";
}

$xml .= "</index>";
echo $xml;

function parseTree($node, $label, $in, $con, $child=true){
	// root needed for selection but not display
	if($child){
		$in.=",$node";
	}  
	$sql = "SELECT * FROM node WHERE parent_id=$node ORDER BY node_position";
	$result = mysql_query($sql,$con) or die("<tree><root id='-2'></root></tree>");
	$n = mysql_num_rows($result);
	
	for($f=0;$f<$n;$f++){
		$nodex = mysql_result($result, $f, 'node_id');
		$label = mysql_result($result, $f, 'label');
		$in = parseTree($nodex, $label, $in, $con);
	}
	
	return $in;
}

?>
Return current item: Wiki Web Help