<?
header("Pragma: no-cache");

if ($sys['path'] == "") {
	$sys['path'] = "/";
}

$sys['fullPath'] = gluePath($permissions['path'],$sys['path']);

/* check folder */
if (!is_dir($sys['fullPath'])) {
?>
<script>
treeitem = parent.AfianTreeHandler.all['<?echo $_GET['id'];?>'];
parent.AfianTreeDataLoaded(new Array, treeitem);
treeitem.remove();
</script>
<?
	exit();
}

$list = new iconlist($_GET['setindex']);

//get dir listing
$d = dir($sys['fullPath']);
if (!$d) {
	$sys['fullPath'] = $permissions['path'];
	$d = dir($sys['fullPath']);
	if (!$d) {
		header("Location: ?logout=1&msg=3");
		exit();
	}
	?>
	<script>alert('<?$lang->display("Failed to access %1", array($sys['path']))?>');</script>
	<?
}


$tmp = array();
//arrange data for icon listing
while ($file = @$d->read()) {
	if ($file != "." && $file != ".." && !in_array($file, $ignoreFiles)) {
		$fullpath = gluePath($sys['fullPath'],$file);
		if (is_dir($fullpath)) {
			$data['name'] = $file;
			$data['lcname'] = strtolower($file);
			$data['mdate'] = filemtime($fullpath);
			$tmp[$data['name']] = $data;
		}
	}
}

if (is_array($tmp)) {
	ksort($tmp);
	foreach ($tmp as $data) {
		$list->setIcon($data);
	}
}

?>
<script>
d = new Array;
<?
for ($i = 0 ; $i < sizeof($list->icons) ; $i++) {
?>
d[<?echo $i;?>] = new Array;
d[<?echo $i;?>]['text'] = '<?echo $str->safeJS($list->icons[$i]['name']);?>';
d[<?echo $i;?>]['path'] = '<?echo $str->safeJS(gluePath($sys['path'], $list->icons[$i]['name']));?>';
<?
}
?>
/* sort here the new items */

treeitem = parent.AfianTreeHandler.all['<?echo $_GET['id'];?>'];
parent.AfianTreeDataLoaded(d, treeitem);
</script>

