<script language="JavaScript1.2" type="text/javascript">
tb = parent.AfianHandler['allTabs']['<?echo $_GET['totabid'];?>'];
<?
$fromfolder	= $str->fromHTML($_GET['fromfolder']);
$tofolder	= $str->fromHTML($_GET['tofolder']);
$uid		= $str->fromHTML($_GET['uid']);
$list = new iconlist($_GET['totabid']);

$shareInfo = $share->getInfo($uid."::".$tofolder);
$sys['subpath'] = $shareInfo['subpath'];
$sys['sharename'] = $shareInfo['sharename'];
$sys['fullPath'] = $shareInfo['path'];


/* check user permission*/
if ($permissions['readonly']) {
	iframeAlert($lang->get("You are not alowed to copy files or folders."));
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}

if (!$shareInfo['write']) {
	iframeAlert($lang->get("You are not allowed to upload files in this folder."));
	echo "parent.BShareEndAction(tb);</script>";
	exit();
}



if (!isCleanPath($fromfolder)) {
	iframeAlert($lang->get("Ilegal path: ").$fromfolder);
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}

if (!isCleanPath($tofolder)) {
	iframeAlert($lang->get("Ilegal path: ").$tofolder);
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}


/* checking input */
$split = explode("|", $str->fromHTML($_POST['itemlist']));
for ($i = 0 ; $i < sizeof($split) ; $i++) {
	if ($split[$i] != "") {
		$items[] = $split[$i];
	}
}

foreach ($items as $item) {
	if (!isCleanFilename($item)) {
	iframeAlert($lang->get("Ilegal filename: ").$item);
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
	}
}

?>
if (tb != undefined) {
tb.destroyItems();
}
<?

$copyiedFolders = 0;
$copyiedItems = 0;


$userinfo = $auth->getUserInfoById($uid);
$groupinfo = $auth->getGroupInfo($userinfo['gid']);
if ($userinfo['path'] == "") {
	$userpath = $groupinfo['path'];
} else {
	$userpath = $userinfo['path'];
}
$homefolder = $userpath;
$trashfolder = gluePath((($settings->config['trashpath'])?$settings->config['trashpath']:gluePath($sys['root'], "/system/data/trash/")), $userinfo['username']);
function getUserUsedSpace() {
	global $homefolder, $trashfolder, $fm;
	return $fm->getDirSize($homefolder) + $fm->getDirSize($trashfolder);
}


foreach ($items as $filename) {
	$fromRelativePath = gluePath($fromfolder, $filename);
	$fromFullPath = gluePath($permissions['path'], $fromRelativePath);
	$toRelativePath = gluePath("/",$tofolder, $filename);
	$toFullPath = gluePath($sys['fullPath'], $filename);


/* calculating user (to where we paste) used space */
$userUsedSpace = getUserUsedSpace();
if ($userinfo['spacequota'] == "-") {
$useHasNoFreeSpace = false;
} elseif($userinfo['spacequota'] == "") {
	if ($groupinfo['spacequota'] == "") {
		$useHasNoFreeSpace = false;
	} else {
		if ($userUsedSpace >= $groupinfo['spacequota']) {
			$useHasNoFreeSpace = true;
		} else {
			$useHasNoFreeSpace = false;
		}
	}
} else {
		if ($userUsedSpace >= $userinfo['spacequota']) {
			$useHasNoFreeSpace = true;
		} else {
			$useHasNoFreeSpace = false;
		}
}




if (!$useHasNoFreeSpace) {


	if ($fm->copy($fromFullPath, $toFullPath)) {
		$copyiedItems++;
		$lastItem = $filename;
		$comments->copy($fromFullPath, $toFullPath);
		$log->act("0", "object copy", "\"".$fromFullPath."\" TO \"".$toFullPath."\"");
		$data['name'] = $filename;
		$data['lcname'] = strtolower($data['name']);
		$data['mdate'] = filemtime($toFullPath);
		if (is_dir($toFullPath)) {
			$copyiedFolders++;
			$data['isdir'] = true;
			$data['size'] = $fm->getDirSize($toFullPath);
			$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($toRelativePath)."')";

		} else {
			$data['isdir'] = false;
			$data['size'] = filesize($toFullPath);
			$extension = $fm->getExtension($data['lcname']);
			$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($toFullPath, 1, 1, $tofolder);
			$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'])."')";
			if ($fileinfo['type'] == "txt") {
				$data['txt'] = true;
			} else {
				$data['txt'] = false;
			}
		}
		$list->drawIcon($data);
		
		
		
	} else {
		if (!file_exists($fromFullPath)) {
			$iframeAlertMsg[] = $lang->get("Copy failed: '%1: ".$fromRelativePath."' not available.", array($userinfo['username']));
		} else if (file_exists($toFullPath)) {
			$iframeAlertMsg[] = $lang->get("Copy failed: '%1: %2' already exists.", array($userinfo['username'], $toRelativePath));
		}
	}
	
	} else {
	$iframeAlertMsg[] = $lang->get("User '%1' has not enough space available so you can upload '%2'", array($userinfo['username'], $filename));
	}
}
?>



<?if ($copyiedFolders > 0) {?>
parent.reloadTreeByPath('<?echo $str->safeJS($tofolder);?>');
<?}?>


parent.BShareEndAction(tb);
if (tb != undefined) {
	tb.buildItems();
	if (tb.active) {
		tb.showItems();
		tb.focusItem('<?echo $str->safeJS($lastItem);?>');
	}
}
<?iframeAlert($iframeAlertMsg);?>
</script>
