<script language="JavaScript1.2" type="text/javascript">
tb = parent.AfianHandler['allTabs']['<?echo $_GET['fromtabid'];?>'];
<?
$fromfolder	= $str->fromHTML($_GET['fromfolder']);
$sys['fullPath'] = gluePath($permissions['path'], $fromfolder);
$list = new iconlist($_GET['fromtabid']);


/* check user permission*/
if ($permissions['readonly']) {
	iframeAlert($lang->get("You are not allowed to perform this action."));
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}

if ($permissions['unlimitedTraffic'] == false && $quota->canAddTraffic() == false) {
	iframeAlert($lang->get("Not enough space available"));
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}

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


$archName = $str->fromHTML($_GET['zipname']);
if (!$archName) {
	$archName = "ZipArchive.zip";
}
if (!isCleanFilename($archName)) {
	iframeAlert($lang->get("Ilegal filename: ").$archName);
	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 (file_exists(gluePath($sys['fullPath'], $archName))) {
	iframeAlert($lang->get("Zip: archive '%1' already exists.", array($archName)));
	echo "parent.MyFilesEndAction(tb);</script>";
	exit();
}

?>
tb.destroyItems();
<?

$zip = new PclZip(gluePath($sys['fullPath'], $archName));
$log->act("0", "zip", gluePath($sys['fullPath'], $archName));

foreach ($items as $filename) {
	/* no bulshit filename */
	$filelist = $zip->add(gluePath($sys['fullPath'], $filename), PCLZIP_OPT_REMOVE_PATH, gluePath($sys['fullPath'],"/"));
	if (is_dir($sys['fullPath']."/".$filename)) {
		$log->act("0", "folder added to zip", "\"".gluePath($sys['fullPath'], $filename)."\" TO \"".$archName."\"");
	} else {
		$log->act("0", "file added to zip", "\"".gluePath($sys['fullPath'], $filename)."\" TO \"".$archName."\"");
	}
}

if ($filelist == 0) {
	$iframeAlertMsg[] = $lang->get("Error: ").$zip->errorInfo(true);
}

	/* insert created item in list*/
	$data['name'] = $archName;
	$data['iszip'] = true;
	$data['lcname'] = strtolower($data['name']);
	$data['mdate'] = filemtime(gluePath($sys['fullPath'], $archName));
	$data['isdir'] = false;
	$data['size'] = filesize(gluePath($sys['fullPath'], $archName));
	$extension = $fm->getExtension($data['name']);
	$data['ext'] = $extension;
	$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(gluePath($sys['fullPath'], $archName), 1, 1, $fromfolder);
	$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);

?>
parent.AfianBubbleMessage('<?$lang->display("Zip archive created.");?>');

if (tb != undefined) {
	parent.MyFilesEndAction(tb);
	
	tb.buildItems();
	tb.showItems();
	if (tb.active) {
		parent.MyFilesStatusBar();
	}
}

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