<?php
$data = json_decode(file_get_contents("data.json"),true)[$_GET["sharingid"]];
function formatSizeUnits($bytes){
        if ($bytes >= 1073741824){
            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
        }elseif ($bytes >= 1048576){
            $bytes = number_format($bytes / 1048576, 2) . ' MB';
        }elseif ($bytes >= 1024){
            $bytes = number_format($bytes / 1024, 2) . ' KB';
        }elseif ($bytes > 1){
            $bytes = $bytes . ' bytes';
        }elseif ($bytes == 1){
            $bytes = $bytes . ' byte';
        }else{
            $bytes = '0 bytes';
        }
        return $bytes;
}
?>
<!DOCTYPE html>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
<html>
<head>
<script type='text/javascript' charset='utf-8'>
    // Hides mobile browser's address bar when page is done loading.
      window.addEventListener('load', function(e) {
        setTimeout(function() { window.scrollTo(0, 1); }, 1);
      }, false);
</script>
<meta charset="UTF-8">
<title>Quick Send</title>
<link rel="stylesheet" href="../script/tocas/tocas.css">
<style>
.outer-div
{
     display: table;
     position: absolute;
     height: 100%;
     width: 100%;
}
.mid-div
{
     display: table-cell;
     vertical-align: middle;
}
.center-div
{
     margin: 0 auto;
     width: 300px;
     height: 100px;
}
</style>
</head>
<body>
<br>
<div class="outer-div"><div class="mid-div"><div class="center-div">

<div class="ts container" style="margin: auto;margin: auto;margin-top: 30vh;text-align: center">
	<div class="ts segment">
		<h3 class="ts center aligned icon header">
			<i id="icn" class="file outline icon"></i><?php echo pathinfo($data["path"],PATHINFO_BASENAME); ?>
			<div class="sub header"><?php echo formatSizeUnits(filesize($data["path"])); ?></div>
		</h3>
		<?php if(isset($data["password"])){ ?>
		<br>
		<div class="ts fluid input">
			<input id="pwd" type="password" placeholder="Verification Code">
		</div>
		<br>
		<?php } ?>
		<br>
		<button onclick="download()" class="ts fluid button">Download</button>
	<div>
</div>

</div></div></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="../script/tocas/tocas.js"></script>
<script src="../script/ao_module.js"></script>
<script>
var sharingid = "<?php echo $_GET["sharingid"]; ?>";
var ext = ao_module_utils.getIconFromExt("<?php echo pathinfo($data["path"],PATHINFO_EXTENSION) ?>");
$("#icn").attr("class",ext + " icon");

function download(){
	if($("#pwd").length){
		$.get( "download.php?sharingid=" + sharingid + "&chkpassword=" + $("#pwd").val(), function( data ) {
			if(data){
				window.location = "download.php?sharingid=" + sharingid + "&password=" + $("#pwd").val();
			}else{
				console.log("Incorrect");
			}
		});
	}else{
		window.location = "download.php?sharingid=" + sharingid;
	}
}

var lan = JSON.parse('{"zh-TW":{"%n KB":"%n千位元組","%n MB":"%n百萬位元組","%n GB":"%n吉位元組","%n TB":"%n兆位元組","%n PB":"%n拍位元組","%n EB":"%n艾位元組","%n ZB":"%n皆位元組","%n YB":"%n佑位元組","Verification Code":"驗證碼","Download":"下載"},"en-US":{"%nKB":"%nKiloByte","%nMB":"%nMegaByte","%nGB":"%nGigaByte","%nTB":"%nTeraByte","%nPB":"%nPetaByte","%nEB":"%nExaByte","%nZB":"%nZettaByte","%nYB":"%nYottaByte","Verification Code":"Verification Code","Download":"Download"}}');
</script>
<script src="i18n.js"></script>
</body>
</html>