<?php
function file_id_dir ($dirname){
	$Ld = dir($dirname);
	while (false !== ($entry = $Ld->read())) {
		$checkdir=$dirname."/".$entry;
		if (is_dir($checkdir)&&!preg_match("[^\.]",$entry)){
			$result[] = array(
				'id'=>str_replace('/','',str_replace('.','',$checkdir)),
				'text'=>$entry,
				'filename' => $checkdir,
				'state'=>'open',
				'isdir'=>true,
				'children' => file_id_dir($checkdir)
			);
		}elseif ($entry!='.' && $entry!='..') {
			$result[] = array(
				'id'=>str_replace('/','',str_replace('.','',$checkdir)),
				'name' => basename($checkdir,C('TMPL_TEMPLATE_SUFFIX')),
				'filename' => $checkdir,
				'isdir'=>false,
				'text'=>$entry,
			);
		}
	}
	$Ld->close();
	return $result;
}