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

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

$fromfolder	= $str->fromHTML($_GET['fromfolder']);
$tofolder	= $str->fromHTML($_GET['tofolder']);
$list = new iconlist($_GET['totabid']);

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

if (!isCleanPath($tofolder)) {
	iframeAlert($lang->get("Ilegal path: ").$tofolder);
	echo "parent.MyFilesEndAction(totb);parent.MyFilesEndAction(fromtb);</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(totb);parent.MyFilesEndAction(fromtb);</script>";
	exit();
	}
}

$movedFolders = 0;
$movedItems = 0;
?>
if (totb != undefined) {
totb.destroyItems();
}
<?

foreach ($items as $filename) {
	$objectInfo = $trash->getObjectInfo($filename);
	$fromFullPath = gluePath((($settings->config['trashpath'])?$settings->config['trashpath']:gluePath($sys['root'], "/system/data/trash/")), $auth->currentUserInfo['username'], $objectInfo['id']);
	$toFullPath = gluePath($permissions['path'], $tofolder, $fm->basename($objectInfo['path']));
	
	if ($fm->copy($fromFullPath, $toFullPath)) {
		$movedItems++;
		$data['name'] = $fm->basename($toFullPath);
		$lastItem = $data['name'];
		$data['lcname'] = strtolower($data['name']);
		$data['mdate'] = filemtime($toFullPath);
		if (is_dir($toFullPath)) {
			$movedFolders++;
			$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'] = "cd('".$str->safeJS(gluePath($tofolder,$data['name']))."')";
		} else {
			$data['isdir'] = false;
			$data['size'] = filesize($toFullPath);
			$extension = $fm->getExtension($data['name']);
			$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'] = "get('".$str->safeJS($data['name'])."')";
			if ($fileinfo['type'] == "txt") {
				$data['txt'] = true;
			} else {
				$data['txt'] = false;
			}
		}
		$list->drawIcon($data);
		
		
		if ($fm->delete($fromFullPath)) {
		//delete db record
		$rs = $db->query("DELETE FROM ".$settings->config['trash_tablename']." WHERE uid='".$auth->currentUserInfo['id']."' and id='".$filename."'");
		?>
		if (fromtb != undefined) {
			fromtb.removeItem('<?echo $str->safeJS($filename);?>');
		}
		<?
		} else {
			$iframeAlertMsg[] = $lang->get("Failed to remove database trash record.");
		}
	} else {
		if (!file_exists($fromFullPath)) {
			$iframeAlertMsg[] = $lang->get("Move failed: Trash item not available.");
		} else {
			$iframeAlertMsg[] = $lang->get("Move failed: '%1' already exists.", array(gluePath($tofolder, $fm->basename($objectInfo['path']))));
		}
		
	}
}
?>


parent.MyFilesEndAction(totb);
parent.MyFilesEndAction(fromtb);

if (totb != undefined) {
	totb.buildItems();
	if (totb.active) {
		totb.showItems();
		totb.focusItem('<?echo $str->safeJS($lastItem);?>');
	}
}

<?if ($movedItems > 0) {?>
parent.AfianBubbleMessage('<?$lang->display("Object(s) moved from trash.");?>');
<?}?>

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

<?iframeAlert($iframeAlertMsg);?>
</script>