<?
ob_end_clean();

$filename = $str->fromHTML($_GET['filename']);
$fromfolder	= $str->fromHTML($_GET['path']);
$uid		= $str->fromHTML($_GET['uid']);

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



if (!isCleanPath($sys['subpath'])) {
?>
<script language="JavaScript1.2" type="text/javascript">
<?echo iframeAlert($lang->get("Ilegal path."));?>
</script>
<?
	exit();
}


if (!isCleanFilename($filename)) {
?>
<script language="JavaScript1.2" type="text/javascript">
<?echo iframeAlert($lang->get("Ilegal filename."));?>
</script>
<?
	exit();
}


if ($permissions['unlimitedTraffic'] || $quota->canAddTraffic()) {
	if (isCleanFilename($filename)) {
		//header("Cache-Control: private");
		if (@file_exists($sys['fullPath'])) {
			$filesize = $fm->getFileSize($sys['fullPath']);
			$fm->sendHTTPFile($sys['fullPath']);
			$quota->addTraffic($filesize);
			
			$filename = $fm->basename($str->fromHTML($sys['fullPath']));
			$actionInfo = "";
			$actionInfo .= "File name: " . $filename ."\n";
			$actionInfo .= "File size: " . $fm->formatFileSize($filesize) ."\n";
			$logInfo = $actionInfo;
			$logInfo .= "Path: " . $sys['fullPath'] ."\n";
			$log->act("0", "download", $logInfo);
			
			/* send email notice to admin */
			if ($options['downloadNotice'] && $config->settings['adminemail']) {
				$mail = new htmlMimeMail();
				$message = "\n";
				$message .= "User \"".$auth->currentUserInfo['username']."\" downloaded:\n";
				$message .= "Date: " . date("n/d/Y H:i") ."\n";
				$message .= $actionInfo;
				$message .= "Folder: " . $fromfolder ."\n";
				
				$mail->setText($message);
				$customFrom = "";
				if ($customFrom) {
					$mail->setFrom($customFrom);
				} else {
					$mail->setFrom(($sys['license']['unbranded']?$sys['license']['unbranded']:"Afian"));
				}
				$mail->setSubject("User ".$auth->currentUserInfo['username']." downloaded a file.");
				$result = @$mail->send(array($config->settings['adminemail']));
			}
			
		} else {
			?>
		<script language="JavaScript1.2" type="text/javascript">
		<?echo iframeAlert($lang->get("Download: shared file '%1' not available", array(gluePath($sys['subpath'], $filename))));?>
		</script>
			<?
		}
	} else {
	}
} else {
?>
<script language="JavaScript1.2" type="text/javascript">
<?echo iframeAlert($lang->get("Download failed: traffic quota excedeed."));?>
</script>
<?
}

exit();

?>