<?php
session_start();
if ($_SESSION['login']!="ok") {
	echo "<script language='javascript'>";
	echo " location='./';";
	echo "</script>";
}
?>
<?php
require("conn.php");
$father_id=$_POST['id'];
function _count($father_id){
   $count_req=mysql_query("select count(id) as count from kind where father_id=$father_id");
   $count_num=mysql_fetch_array($count_req);
   return $count_num['count'];
}
$count=_count($father_id);
$return=mysql_query("select * from kind where father_id=$father_id");
echo "[";
$i=1;
while ($req=mysql_fetch_array($return)) {
	$id=$req['id'];
	$name=$req['name'];
	if($id!=99999){
	if (_count($id)>0) {
        echo "{
       id: $id,
       text: '$name',
       leaf: false
     }";		
	}else {
		echo "{
       id: $id,
       text: '$name',
       leaf: true
     }";
	}	
	if ($i<$count) {
		echo ",";
	}
	}
	$i++;
}
echo "]";

?>
