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

$tofolder	= $str->fromHTML($_GET['tofolder']);
$sys['fullPath'] = gluePath($permissions['path'], $tofolder);
$list = new iconlist($_GET['totabid']);


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

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

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

/* check folder*/
if (!is_dir($sys['fullPath'])) {
	iframeAlert($lang->get("The folder where you want to upload files does not exist any more."));
	echo "parent.MyFilesEndAction(tb);parent.MyFilesFolderNA(tb, '".$str->safeJS($tofolder)."');</script>";
	exit();
}
?>

if (tb != undefined) {
tb.destroyItems();
}
<?
$uploadedFiles = 0;
		for ($i=0 ; $i < sizeof($_FILES['uploadfiles']) ; $i++) {

			$uploadItem = $_FILES['uploadfiles'];
			$uploadFilename = $uploadItem['tmp_name'][$i];
			$niceFilename = $str->fromHTML($uploadItem['name'][$i]);
			$toFile = gluePath($sys['fullPath'],$niceFilename);
			$filesize = $uploadItem['size'][$i];



			if ($uploadItem['error'][$i] && $niceFilename != "") {
				$iframeAlertMsg[] = $lang->get("Maximum upload limit reached. File \"%1\" could not be uploaded.", array($niceFilename));
			}
			if ($niceFilename != "") {
			if ($permissions['unlimitedSpace'] || $quota->canAddToSpace()) {
				if (is_uploaded_file($uploadFilename)) {
				if ($fm->copyFile($uploadFilename, $toFile)) {
				$uploadedFiles++;
				$quota->recalcUsedSpace();
				
	/* insert uploaded file in list */
	$data['name'] = $niceFilename;
	$data['lcname'] = strtolower($data['name']);
	$data['mdate'] = filemtime($toFile);
	$data['isdir'] = false;
	$data['size'] = filesize($toFile);
	$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($toFile, 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;
	}
	if (strtolower($data['ext']) == "zip") {
		$data['iszip'] = true;
	} else {
		$data['iszip'] = false;
	}
	$list->drawIcon($data);
	$lastItem = $data['name'];

					$quota->addTraffic($filesize);
					
					$actionInfo = "";
					$actionInfo .= "\r\n\tFile name: " . $niceFilename ."\n";
					$actionInfo .= "\tFile size: " . $fm->formatFileSize($data['size']) ."\n";
					$logInfo = $actionInfo;
					$logInfo .= "\tUploaded to folder: " . $tofolder ."\n";
					$log->act("0", "upload", $logInfo);
					
					$log->lastUpload($toFile);
					
					/* send email notice to admin */
					if ($options['uploadNotice'] && $config->settings['adminemail']) {
						$mail = new htmlMimeMail();
						$message = "\n";
						$message .= "User \"".$auth->currentUserInfo['username']."\" uploaded:\n";
						$message .= "Date: " . date("n/d/Y H:i") ."\n";
						$message .= $actionInfo;
						$message .= "\tUploaded to folder: " . $tofolder ."\n";
						$mail->setText($message);
						$customFrom = "";
						if ($customFrom) {
							$mail->setFrom($customFrom);
						} else {
							$mail->setFrom(($sys['license']['unbranded']?$sys['license']['unbranded']:"Afian"));
						}
						$mail->setSubject("Upload from ".$auth->currentUserInfo['username']);
						$result = @$mail->send(array($config->settings['adminemail']));
					}
					
					} else {
						if (file_exists($toFile)) {
							$iframeAlertMsg[] = $lang->get("Upload failed: '%1' already exists.", array(gluePath($tofolder, $niceFilename)));
						}
						$log->act("1", "upload", $toFile." (".$fm->errorMsg.")");
					}
				}
			} else {
				$iframeAlertMsg[] = $lang->get("Not enough space available to upload '%1'", array($niceFilename));
			}
			}
		}
?>

<?
if ($uploadedFiles > 0) {
?>
parent.AfianBubbleMessage('<?$lang->display("File(s) uploaded.");?>');
<?}?>



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

<?if (!$permissions['unlimitedSpace']) {?>
parent.setQuotaIndicators ('space', <?echo $quota->currentSpace;?>, <?echo $permissions['spaceQuota'];?>);
<?}?>


<?if (!$permissions['unlimitedTraffic']) {?>
parent.setQuotaIndicators ('traffic', <?echo $quota->currentTraffic;?>, <?echo $permissions['trafficQuota'];?>);
<?}?>

<?iframeAlert($iframeAlertMsg);?>

</script>