<?php

//////////////////////////////////////////////////////////////
//===========================================================
// disk_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function disk_theme(){

global $theme, $globals, $cluster, $user, $l, $disk;

softheader($l['<title>']);
										
echo '
<div class="bg">
<div class="row my-3 mx-auto">
<div class="col-10">
<h4 class="text-dark"><i class="fas fa-hdd"></i> '.__('Disk').'</h4>
</div>
</div>';

// Is it offline ?
$hypervisor_status = $cluster->statewise($globals['server']);
if($hypervisor_status == 0 || $hypervisor_status == 2){
	show_alert($globals['hypervisor_status'][$hypervisor_status] ,"1");
	echo '<div class="e_notice"><b>NOTE : </b>&nbsp; '.$globals['hypervisor_status'][$hypervisor_status].'</div>';
	
}else{

$i = 1;
foreach($disk['disk'] as $k => $v){

echo '
<div class="row w-100 mx-auto">
	<div class="col-sm-6 border-right">
		<div class="roundheader">'.__('Disk Information').'</div>
		<table align="center" class="table table-hover" cellpadding="3" cellspacing="4" border="0" width="100%">
			<tr><td align="left" class="blue_td" width="30%">'.__('Mounted On : ').'</td><td class="fhead val">'.$k.'</td></tr>
			<tr><td align="left" class="blue_td">'.__('Total Disk : ').'</td><td class="val">'.$disk['disk'][$k]['limit_gb'].' GB</td></tr>
			<tr><td align="left" class="blue_td">'.__('Utilized : ').'</td><td class="val">'.$disk['disk'][$k]['used_gb'].' GB</td></tr>
		        <tr><td align="left" class="blue_td">'.__('Actual Disk Usage :').'</td><td class="val">'.$disk['disk'][$k]['actual_gb'].' GB</td></tr>
			<tr><td align="left" class="blue_td">'.__('Utilization % : ').'</td><td class="val">'.$disk['disk'][$k]['percent'].' %</td></tr>
		</table>
	</div>
	<div class="col-sm-6" align="center" width="50%">
		<div class="roundheader" align="left">'.__('Disk Utilization').'</div>
		<br />
		<div id="disk'.$i.'_holder" style="width:130px; height:130px;"></div>
	</div>
</div>

<div class="row w-100 mx-auto">
	<div class="col-sm-6 border-right">
		<div class="roundheader">'.__('Inodes Information').'</div>
		<table align="center" class="table table-hover" cellpadding="3" cellspacing="4" border="0" width="100%">
			<tr><td align="left" class="blue_td" width="30%">'.__('Total Inodes :').'</td><td class="val">'.$disk['inodes'][$k]['limit'].'</td></tr>
			<tr><td align="left" class="blue_td">'.__('Utilized : ').'</td><td class="val">'.$disk['inodes'][$k]['used'].'</td></tr>
			<tr><td align="left" class="blue_td">'.__('Utilization % :').'</td><td class="val">'.$disk['inodes'][$k]['percent'].' %</td></tr>
		</table>
	</div>
	<div class="col-sm-6" align="center" width="50%">
		<div class="roundheader" align="left">'.__('Inodes Utilization').'</div>
		<br />
		<div id="inodes'.$i.'_holder" style="width:130px; height:130px;"></div>
	</div>
</div>
<hr><br>';
	
	$i++;
}

echo '<script type="text/javascript" charset="utf-8"><!-- // --><![CDATA[	

// Draw a Resource Graph
function resource_graph(id, data){

    $.plot($("#"+id), data, 
	{
		series: {
			pie: { 
				innerRadius: 0.7,
				radius: 1,
				show: true,
				label: {
					show: true,
					radius: 0,
					formatter: function(label, series){
						if(label != "Used") return "";
						return \'<div class="h4 m-0">\'+Math.round(series.percent)+\'%</div><div class="text-center">\'+label+\'</div>\';	
					}
				}
			}
		},
		legend: {
			show: false
		}
	});
}

function drawpie(){';

$i = 1;
foreach($disk['disk'] as $k => $v){

	echo '	
	resource_graph("disk'.$i.'_holder", [
		{ label: "Used",  data: '.$disk['disk'][$k]['used_gb'].'},
		{ label: "Free",  data: '.$disk['disk'][$k]['free_gb'].'}
	]);
	
	resource_graph("inodes'.$i.'_holder", [
		{ label: "Used",  data: '.$disk['inodes'][$k]['used'].'},
		{ label: "Free",  data: '.$disk['inodes'][$k]['free'].'}
	]);
	';
	
	$i++;
}

echo '};

addonload("drawpie();");
// ]]></script>';

}

echo '</div>';
softfooter();

}

?>