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

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


$list = new iconlist($_GET['totabid']);


/* check user permission*/
if (!$permissions['upload']) {
	iframeAlert($lang->get("You are not allowed to upload files."));
	echo "parent.BShareEndAction(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($tofolder)) {
	iframeAlert($lang->get("Ilegal path: ").$tofolder);
	echo "parent.BShareEndAction(tb);</script>";
	exit();
}

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


$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);
}

?>

if (tb != undefined) {
tb.destroyItems();
}
<?
		for ($i=0 ; $i < sizeof($_FILES['uploadfiles']['name']) ; $i++) {
			$uploadFilename = $_FILES['uploadfiles']['tmp_name'];
			$niceFilename = $_FILES['uploadfiles']['name'];
			$niceFilename[$i] = $str->fromHTML($niceFilename[$i]);
			$toFile = gluePath($sys['fullPath'],$niceFilename[$i]);
			$filesize = $_FILES['uploadfiles']['size'];
			$filename = $niceFilename[$i];
			if ($_FILES['uploadfiles']['error'][$i] && $niceFilename[$i] != "") {
				$iframeAlertMsg[] = $lang->get("Maximum upload limit reached. File \"%1\" could not be uploaded.", array($niceFilename[$i]));
			}

			if ($filename != "") {
			
$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 (is_uploaded_file($uploadFilename[$i])) {
				if ($fm->copyFile($uploadFilename[$i], $toFile)) {
				
				
	/* insert uploaded file in list */
	$data['name'] = $filename;
	$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'] = "BShareGet('".$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[$i]);
					$log->act("0", "file upload", $toFile);
					$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("d/n/Y H:i") ."\n";
						$message .= "Filename: " . $niceFilename[$i] ."\n";
						$message .= "Filesize: " . $fm->formatFileSize(@filesize($toFile)) ."\n";
						$message .= "Uploaded to folder: " . $sys['fullPath'] ."\n";
						$mail->setText($message);
						$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, $filename)));
}
						$log->act("1", "file upload", $toFile." (".$fm->errorMsg.")");
					}
				}
			} else {
				$iframeAlertMsg[] = $lang->get("User '%1' has not enough space available so you can upload '%2'", array($userinfo['username'], $filename));
			}
			}
		}
?>


parent.BShareEndAction(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>