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

$copyiedFolders = 0;
$copyiedItems = 0;
$removedFolders = 0;

?>
/*
if (totb != undefined) {
totb.destroyItems();
}
*/
<?

foreach ($items as $filename) {
	$fromRelativePath = gluePath($fromfolder, $filename);
	$fromFullPath = gluePath($permissions['path'], $fromRelativePath);
	$toRelativePath = gluePath($tofolder, $filename);
	$toFullPath = gluePath($permissions['path'], $toRelativePath);
	
	$fromFullPathIsDir = is_dir($fromFullPath);
	if ($fm->copy($fromFullPath, $toFullPath)) {
		$lastItem = $filename;
		$copyiedItems++;
		$comments->move($fromFullPath, $toFullPath);
		$log->act("0", "document move", "\"".$fromFullPath."\" TO \"".$toFullPath."\"");
		$thumb->clearCache($fromFullPath);
		
		$data['name'] = $filename;
		$data['lcname'] = strtolower($data['name']);
		$data['mdate'] = filemtime($toFullPath);
		if (is_dir($toFullPath)) {
		
		$isShared = $share->isShared($fromRelativePath);
		//$isPublic = $public->isPublic($fromRelativePath);
		$flags->changeFlaggedPath($fromRelativePath, $toRelativePath);
		$flags->updateSubPaths($fromRelativePath, $toRelativePath);
		
		
		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);
		
			$copyiedFolders++;
			$data['isdir'] = true;
			$data['size'] = $fm->getDirSize($toFullPath);
			$data['ext'] = "";
			$data['filetypedescription'] = $lang->get("Folder");
			$data['filetype'] = "folder";
			$data['ondblclick'] = "cd('".$str->safeJS(gluePath($tofolder,$filename))."')";
		} 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'] = "get('".$str->safeJS($data['name'])."')";
			if ($fileinfo['type'] == "txt") {
				$data['txt'] = true;
			} else {
				$data['txt'] = false;
			}
		}
		//$list->drawIcon($data);
		
	if ($fm->delete($fromFullPath)) {
		?>
		if (fromtb != undefined) {
		fromtb.removeItem('<?echo $str->safeJS($filename);?>');
		}
		<?
		
		if ($fromFullPathIsDir) {
			$removedFolders++;
		?>
			parent.closeTabByPath('<?echo $str->safeJS(gluePath($fromfolder, $filename));?>');
		<?
		}
	} else {
		if (!file_exists($fromFullPath)) {
			$iframeAlertMsg[] = $lang->get("Move (delete) failed: '%1' not available.", array($fromRelativePath));
		}
	}
		
		
	} else {
		if (!file_exists($fromFullPath)) {
			$iframeAlertMsg[] = $lang->get("Move (copy) failed: '%1' not available.", array($fromRelativePath));
		} else if (file_exists($toFullPath)) {
			$iframeAlertMsg[] = $lang->get("Move (copy) failed: '%1' already exists.", array($toRelativePath));
		}
	}


}
?>

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

parent.MyFilesEndAction(totb);


<?
if (substr($tofolder, 0, strlen($fromfolder)) != $fromfolder) {
	if ($copyiedFolders > 0) {
	?>
	parent.reloadTreeByPath('<?echo $str->safeJS($tofolder);?>');
	<?
	}
}

if (substr($fromfolder, 0, strlen($tofolder)) != $tofolder) {
	if ($removedFolders > 0) {
	?>
	parent.reloadTreeByPath('<?echo $str->safeJS($fromfolder);?>');
	<?
	}
}
?>

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