<?
/* remember the last opened folder */
setcookie("AfianLastFolder", $sys['path'], time()+(60*60*24*30));
?>
<script language="JavaScript1.2" type="text/javascript">
tb = parent.AfianHandler['allTabs']['<?echo $_GET['tabid'];?>'];
<?
if ($sys['path'] == "") {
	$sys['path'] = "/";
}

if (!isCleanPath($sys['path'])) {
iframeAlert("Ilegal path");
exit();
}



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

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();
}


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

//get dir listing
$d = @dir($sys['fullPath']);
if (!$d) {
	$sys['fullPath'] = $permissions['path'];
	$d = dir($sys['fullPath']);
	if (!$d) {
		iframeAlert("Your account is misconfigured.<br>Please contact the administrator.");
		echo "parent.MyFilesEndAction(tb);</script>";
		exit();
	}
	iframeAlert("Cannot read folder contents");
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}


//arrange data for icon listing
while ($file = @$d->read()) {
	if ($file != "." && $file != ".." && !in_array($file, $ignoreFiles)) {
			$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'] = $settings->config['compute_folder_size']?$fm->getDirSize($fullpath):0;
			$data['ext'] = "";
			$data['filetypedescription'] = $lang->get("Folder");

		$path = gluePath($sys['path'], $file);
		$isShared = $share->isShared(addslashes($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['bigthumb'] = false;
			
			$data['filetype'] = "folder";
			$data['ondblclick'] = "cd('".$str->safeJS(gluePath($sys['path'], $file))."', false, '".$str->safeJS($data['name'])."')";
		} else {
			$data['isdir'] = false;
			$data['size'] = sprintf("%u", 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'];
			//debug($fileinfo);
			if ($fileinfo['type'] == "txt") {
				$data['txt'] = true;
			} else {
				$data['txt'] = false;
			}
			$data['icon_img'] = gluePath("images/icons/filetypes/big/",$fileinfo['icon']);
			$iconfolder = "images/icons/filetypes/big/";
			$data['thumb_img'] = $img->icon($fullpath, 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'])."')";
		}
		
		$comm = $comments->get($fullpath);
		if (is_array($comm)) {
			$commentsnr = sizeof($comm);
		} else {
			$commentsnr = 0;
		}
		$data['extra'] = ($commentsnr > 0)?$commentsnr." comments":"&nbsp;";
		$list->setIcon($data);
	}
}

?>
if (tb != undefined) {
tb.removeAll();
}
<?
if (basename($sys['path']) == ""){
	$name = "/";
} else {
	$name = basename($sys['path']);
}
?>

tb.title='<?echo $str->safeJS($name);?>';

tb.basepath='<?
if ($sys['path'] == "") {
echo "/";
} else {
echo $str->safeJS($sys['path']);
}
?>';

tb.uponepath='<?echo $str->safeJS(getUpOneDir($sys['path']));?>';
<?
for ($i = 0 ; $i < sizeof($list->icons) ; $i++) {
	$list->drawIcon($list->icons[$i]);
}
?>
parent.MyFilesEndAction(tb);
if (tb != undefined) {
	tb.sortItems(tb.sortBy, 'desc');
	tb.buildItems();
	if (tb.active) {
		tb.showItems();
		parent.toggleTreeByPath('<?echo $str->safeJS($sys['path']);?>');
	}
	tb.changeTaskBarOptTitle('<?echo $str->safeJS($name);?>');
	tb.browsed = true;
	tb.onload();
}
</script>