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

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


if (substr($sys['path'], 0, 1) == "/") {
	$sys['path'] = substr($sys['path'], 1, strlen($sys['path']));
}


$userinfo = $auth->getUserInfoById($sys['uid']);
$groupInfo = $auth->getGroupInfo($userinfo['gid']);

$splited = split("/", $sys['path']);
$sys['sharename'] = $splited[0];

if (strpos($sys['path'], "/")) {
$subpath = substr($sys['path'], strpos($sys['path'], "/"), strlen($sys['path']));
}



$rs = $db->query("SELECT * FROM ".$settings->config['flags_tablename'].",".$settings->config['share_info_tablename']." WHERE ".$settings->config['share_info_tablename'].".to_uid='".$auth->currentUserInfo['id']."' AND ".$settings->config['flags_tablename'].".id=".$settings->config['share_info_tablename'].".fid and ".$settings->config['flags_tablename'].".shared='1' AND ".$settings->config['flags_tablename'].".uid='".$sys['uid']."' and ".$settings->config['share_info_tablename'].".as='".$sys['sharename']."'");


		if ($rs->RecordCount() > 0) {
			$shareInfo = $rs->fields;
			$sys['pathPermissions']['write'] = $shareInfo['write'];
		} else {
			exit('share info problem');
		}

	if ($userinfo['path'] == "") {
		$userpath = $groupInfo['path'];
	} else {
		$userpath = $userinfo['path'];
	}

$sys['fullPath'] = gluePath($userpath, $shareInfo['path'], $subpath);

/* ar putea pune un flag, hasSpace, pt meniu (upload, paste) */


//get dir listing
$d = @dir($sys['fullPath']);
if (!$d) {
	$sys['fullPath'] = gluePath($userpath, $shareInfo['path']);
	$d = dir($sys['fullPath']);
	$statusBarMessage[] = array($lang->get("You are not allowed to access folder %1", array($_GET['path'])), 1);
}

//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");
			$data['icon_img'] = "images/icons/filetypes/big/folder.gif";
			$data['thumb_img'] = "images/icons/filetypes/big/folder.gif";
			$data['list_img'] = "images/icons/filetypes/small/folder.gif";
			$data['filetype'] = "folder";
			$data['ondblclick'] = "BShareCD('".$str->safeJS(gluePath("/",$sys['path'],$data['name']))."')";
			$data['bigthumb'] = false;
		} else {
			$data['isdir'] = false;
			$data['size'] = filesize($fullpath);
			$extension = $fm->getExtension($file);
			$data['ext'] = $extension;
			$fileinfo = $fm->fileTypeInfo($extension);
			$data['filetypedescription'] = $fileinfo['description'];
			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, gluePath("/",$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'] = "BShareGet('".$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);
	}
}


?>
<script>
tb = parent.AfianHandler['allTabs']['<?echo $_GET['tabid'];?>'];

if (tb != undefined) {
tb.removeAll();
tb.title='<?echo $str->safeJS($sys['sharename']);?>';
tb.uponepath='<?echo $str->safeJS(getUpOneDir(gluePath("/",$sys['path'])));?>';
tb.canwrite=<?echo ($sys['pathPermissions']['write'])?"true":"false";?>;
}
<?
for ($i = 0 ; $i < sizeof($list->icons) ; $i++) {
	$list->drawIcon($list->icons[$i]);
}
?>
if (tb != undefined) {
parent.cancelTimeOut(tb.id);
tb.sortItems('name', 'desc');
tb.buildItems();
tb.changeTaskBarOptTitle(tb.username+': '+tb.basepath);
if (tb.active) {
tb.showItems();
}
tb.countSelected = 0;
tb.onselect();
	if (tb.active) {
		parent.toggleTreeByPath(tb.username+'::'+tb.basepath);
	}
tb.hideHourGlass();
tb.browsed = true;
tb.onload();
}
</script>