<script language="JavaScript1.2" type="text/javascript">
tb = parent.AfianHandler['allTabs']['<?echo $_GET['tabid'];?>'];

<?
$list = new iconlist($_GET['tabid']);

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


/* check folder */
if (!is_dir($sys['fullPath'])) {
	//iframeAlert("The folder you are trying to refresh does not exists any more");
	echo "parent.MyFilesEndAction(tb);parent.MyFilesFolderNA(tb, '".$str->safeJS($sys['path'])."');</script>";
	exit();
}


/* getting current folder contents */
$d = @dir($sys['fullPath']);
if (!$d) {
	$sys['fullPath'] = $permissions['path'];
	$d = dir($sys['fullPath']);
	if (!$d) {
		header("Location: ?logout=1&msg=3");
		exit();
	}
	iframeAlert($lang->get("Cannot read folder contents"));
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
	
}
while ($file = @$d->read()) {
	if ($file != "." && $file != ".." && !in_array($file, $ignoreFiles)) {
	$serverItems[] = $file;
	}
}


if ($_POST['itemlist'] != "") {
	$split = explode("|", $str->fromHTML($_POST['itemlist']));
	foreach ($split as $key => $value) {
		if ($value != "") {
		$clientItems[] = $value;
		}
	}
}

/* comparing client-side and server-side lists */
if (is_array($serverItems)) {
	if (is_array($clientItems)) {
		$forAdditionItems = array_diff($serverItems, $clientItems);
	} else {
		$forAdditionItems = $serverItems;
	}
} else {
$forAdditionItems = array();
}

if (is_array($serverItems)) {
	if (is_array($clientItems)) {
		$forDeletionItems = array_diff($clientItems, $serverItems);
	} else {
		$forDeletionItems = array();
	}
} else {
$forDeletionItems = $clientItems;
}

//debug($serverItems);
//debug($clientItems);
?>

<?
if (sizeof($forAdditionItems) > 0 || sizeof($forDeletionItems) > 0) {?>
tb.destroyItems();
<?}?>

<?
if (is_array($forAdditionItems)) {
foreach ($forAdditionItems as $key => $value) {

	$file = $value;
	$fullpath = gluePath($sys['fullPath'],$file);

	$data['name'] = $file;
	$data['lcname'] = strtolower($file);
	$data['mdate'] = filemtime($fullpath);

if (is_dir($fullpath)) {
	$data['isdir'] = true;
	$data['size'] = $fm->getDirSize($fullpath);
	$data['ext'] = "";
	$data['filetypedescription'] = $lang->get("Folder");

		$path = gluePath($sys['path'], $file);
		$isShared = $share->isShared($path);
		//$isPublic = $public->isPublic($path);
		if ($isShared && !$isPublic) {
			$icon = "folder-shared.gif";
		} elseif (!$isShared && $isPublic) {
			$icon = "folder-public.gif";
		}  elseif ($isShared && $isPublic) {
			$icon = "folder-shared-public.gif";
		} else {
			$icon = "folder.gif";
		}
		$data['icon_img'] = gluePath("images/icons/filetypes/big/", $icon);
		$data['thumb_img'] = gluePath("images/icons/filetypes/big/", $icon);
		$data['list_img'] = gluePath("images/icons/filetypes/small/", $icon);

	$data['filetype'] = "folder";
	$data['ondblclick'] = "cd('".$str->safeJS(gluePath($sys['path'], $file))."')";
} else {
	$data['isdir'] = false;
	$data['size'] = filesize($fullpath);
	$extension = $fm->getExtension($file);
	$data['ext'] = $extension;
	if (strtolower($data['ext']) == "zip") {
		$data['iszip'] = true;
	} else {
		$data['iszip'] = false;
	}
	$fileinfo = $fm->fileTypeInfo($extension);
	$data['filetypedescription'] = $fileinfo['description'];
	$data['icon_img'] = gluePath("images/icons/filetypes/big/",$fileinfo['icon']);
	$iconfolder = "images/icons/filetypes/big/";
	$data['thumb_img'] =  $img->icon($sys['fullPath']."/".$file, 1, 1, $sys['path']);
	$data['bigthumb'] = ((strstr($data['thumb_img'], '?'))?true:false);
	$data['list_img'] = gluePath("images/icons/filetypes/small/",$fileinfo['icon']);
	$data['filetype'] = $img_prefix.$fileinfo['type'];
	$data['ondblclick'] = "get('".$str->safeJS($data['name'])."')";
	if ($fileinfo['type'] == "txt") {
		$data['txt'] = true;
	} else {
		$data['txt'] = false;
	}
}

$list->drawIcon($data);

}
}

if (is_array($forDeletionItems)) {
	foreach ($forDeletionItems as $key => $value) {
	?>
tb.removeItemArray('<?echo $str->safeJS($value);?>');
	<?
	}
}

if (sizeof($forAdditionItems) > 0 || sizeof($forDeletionItems) > 0) {

/* sort icons only if objects added */
if (sizeof($forAdditionItems) > 0) {
?>
if (tb != undefined) {
tb.sortItems(tb.sortBy, 'desc');
}
<?}?>

if (tb != undefined) {
	parent.cancelTimeOut(tb.id);
	tb.buildItems();
	if (tb.active) {
		tb.showItems();
	}
	tb.hideHourGlass();
}
<?
} else {
?>
	if (tb != undefined) {
	tb.hideHourGlass();
	}
<?
}
?>
parent.cancelTimeOut(tb.id);
</script>