<?php
include_once '../auth.php';
?>
<html>
<head>
    <link rel="stylesheet" href="../script/tocas/tocas.css">
	<script src="../script/tocas/tocas.js"></script>
	<script src="../script/jquery.min.js"></script>
	<script src="../script/ao_module.js"></script>
	<meta name="viewport" content="width=device-width, initial-scale=0.6, shrink-to-fit=no">
	<style>
	.item{
		text-align: center;
	}
	.ts.mini.input{
		padding: .48571em 1em;
	}
	</style>
	</head>
<body>
<div class="ts tabbed menu" id="menu">
</div>
<div class="ts grid">
    <div class="sixteen wide column"><h3 class="ts center aligned header" id="drivename">INTEL SSDSC2BW240H6 240.0GB</h3></div>
    <div class="sixteen wide column">
		<div class="ts narrow container">
			<div class="ts grid">
				<div class="two wide column">
					<h5 class="ts center aligned header">Health Status</h5>
					<div class="ts inverted primary card">
						<div class="content">
							<div class="header" style="text-align: center;" id="health_status">Good</div>
							<div class="description" style="text-align: center;" id="health_prec">
								95%
							</div>
						</div>
					</div>
					<h5 class="ts center aligned header">Temperture</h5>
					<div class="ts inverted primary card">
						<div class="content">
							<div class="description" style="text-align: center;" id="temperture">
								25C
							</div>
						</div>
					</div>
				</div>
				<div class="fourteen wide column">
					<div class="ts grid">
						<div class="sixteen wide column">
							<div class="ts grid">
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Firmware</label>
											<input id="firmware" class="ts mini input" style="color:black" type="text" value="RG21"></input>
										</div>
									</div>
								</div>
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label id="col1" style="color:black">Total Host Reads</label>
											<input id="col1_v" class="ts mini input" style="color:black" type="text" value="22507GB"></input>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="sixteen wide column">
							<div class="ts grid">
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Serial Number</label>
											<input id="serial" class="ts mini input" style="color:black" type="text" value="CVTR505030T240CGN"></input>
										</div>
									</div>
								</div>
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label id="col2" style="color:black">Total Host Writes</label>
											<input id="col2_v" class="ts mini input" style="color:black" type="text" value="18517GB"></input>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="sixteen wide column">
							<div class="ts grid">
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Interface</label>
											<input id="interface" class="ts mini input" style="color:black" type="text" value="Serial ATA"></input>
										</div>
									</div>
								</div>
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label id="col3" style="color:black">Total NAND Writes</label>
											<input id="col3_v" class="ts mini input" style="color:black" type="text" value="77840GB"></input>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="sixteen wide column">
							<div class="ts grid">
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Transfer Mode</label>
											<input id="transfer" class="ts mini input" style="color:black" type="text" value="SATA/600 | SATA/600"></input>
										</div>
									</div>
								</div>
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Power On Count</label>
											<input id="powercount" class="ts mini input" style="color:black" type="text" value="3816 count"></input>
										</div>
									</div>
								</div>
							</div>
						</div>
						<div class="sixteen wide column">
							<div class="ts grid">
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Drive Letter</label>
											<input id="driveleter" class="ts mini input" style="color:black" type="text" value="C:"></input>
										</div>
									</div>
								</div>
								<div class="eight wide column">
									<div class="ts horizontal form" style="opacity: 1;">
										<div class="disabled field" style="opacity: 1;">
											<label style="color:black">Power On Hours</label>
											<input id="powerhour" class="ts mini input" style="color:black" type="text" value="1834 hours"></input>
										</div>
									</div>
								</div>
							</div>
						</div>
						<!-- Below is  full width-->
						<div class="sixteen wide column">
							<div class="ts horizontal form" style="opacity: 1;">
								<div class="disabled field" style="opacity: 1;">
									<label style="color:black">Standard</label>
									<input id="standard" class="ts mini input" style="color:black" type="text" value="ACS-3 | ----"></input>
								</div>
							</div>
						</div>
						<div class="sixteen wide column">
							<div class="ts horizontal form" style="opacity: 1;">
								<div class="disabled field" style="opacity: 1;">
									<label style="color:black">Features</label>
									<input id="features" class="ts mini input" style="color:black" type="text" value="S.M.A.R.T., APM, NCQ, TRIM, DevSleep"></input>
								</div>
							</div>
						</div>
						
					</div>
				</div>
			</div>
		</div>
	</div>
	</div class="sixteen wide column">
		<br>
		<div class="ts narrow container">
			<table class="ts very basic table">
			<thead>
				<tr>
					<th>Stat</th>
					<th>ID</th>
					<th>Attribute Name</th>
					<th>Current</th>
					<th>Worst</th>
					<th>Threshold</th>
					<th>Raw Values</th>
				</tr>
			</thead>
			<tbody id="tbody">
			</tbody>
		</table>
		</div>
	</div>
</div>
</body>
<script>
var active = "<?php echo isset($_GET["drive"])?$_GET["drive"]:"" ?>";
$.get( "opr.php?opr=scan", function( data ) {
	var arr = JSON.parse(data);
	$(arr["devices"]).each(function(index, element) {
		if(active == element["info_name"]){
			$( "#menu" ).append('<a class="active item" href="?drive=' + element["info_name"] + '">' + smartok(element["info_name"]) + '<br>29C<br>' + element["info_name"] + '</a>');
		}else{
			$( "#menu" ).append('<a class="item" href="?drive=' + element["info_name"] + '">' + smartok(element["info_name"]) + '<br>29C<br>' + element["info_name"] + '</a>');
		}
	});
});
$.get( "opr.php?opr=info&drive=" + active, function( data ) {
	var arr = JSON.parse(data);
	$("#drivename").html(arr["model_family"] + " " + arr["model_name"] + " " + formatSizeUnits(arr["user_capacity"]["bytes"]));
	$("#firmware").attr("value",arr["firmware_version"]);
	$("#serial").attr("value",arr["serial_number"]);
	$("#interface").attr("value",arr["device"]["protocol"]);
	$("#transfer").attr("value",arr["interface_speed"]["current"]["string"] + " | " + arr["interface_speed"]["max"]["string"]);
	$("#driveleter").attr("value",arr["device"]["name"]);
	$("#standard").attr("value",arr["ata_version"]["string"]);
	$("#features").attr("value","S.M.A.R.T.");
	if(arr["rotation_rate"] > 0){
		$("#col1").html("----");
		$("#col1_v").attr("value","----");
		
		$("#col2").html("----");
		$("#col2_v").attr("value","----");
		$("#col3").html("Rotation Rate");
		$("#col3_v").attr("value",arr["rotation_rate"] + " rpm");
	}else{
		$("#col1").html("Total Host Reads");
		$("#col1_v").attr("value","----");
		
		$("#col2").html("Total Host Writes");
		$("#col2_v").attr("value","----");
		$("#col3").html("Total NAND Writes");
		$("#col3_v").attr("value","----");
	}
	$("#powercount").attr("value",arr["power_cycle_count"] + " count");
	$("#powerhour").attr("value",arr["power_on_time"]["hours"] + " hours");
	$(arr["ata_smart_attributes"]["table"]).each(function(index, element) {
		if(element["when_failed"] == ""){
			var stat = "OK";
		}else{
			var stat = "Failed";
		}
		$("#tbody").append('<tr><td>' + stat + '</td><td>' + element["id"] + '</td><td>' + element["name"] + '</td><td>' + element["value"] + '</td><td>' + element["worst"] + '</td><td>' + element["thresh"] + '</td><td>' + element["raw"]["value"] + '</td></tr>');
	});
});

function smartok(drive){
	return "Good";
}

//from https://stackoverflow.com/questions/5501427/php-filesize-mb-kb-conversion/5501447
    function formatSizeUnits(bytes)
    {
        if(bytes >= 1000000000){
            bytes = Math.round(bytes / 1000000000,2) + 'GB';
        }else if (bytes >= 1000000){
            bytes = Math.round(bytes / 1000000,2) + 'MB';
        }else if (bytes >= 1000){
            bytes = Math.round(bytes / 1000,2) +  'KB';
        }else if (bytes > 1){
            bytes = bytes + 'bytes';
        }else if (bytes == 1){
            bytes = bytes + 'byte';
        }else{
            bytes = '0bytes';
        }

        return bytes;
}
</script>
</html>