<?php

//////////////////////////////////////////////////////////////
//===========================================================
// cpu_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 cpu_theme(){

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

if(optGET('ajax')){	

	echo 'var cpu = [
		{ label: "Used",  data: '.$cpu['percent'].'},
		{ label: "Free",  data: '.$cpu['percent_free'].'}
	];';
		
	return true;

}

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-microchip"></i> '.__(' CPU ').'</h4>
</div>
<div class="col-2 text-right">
<span><a href="'.$globals['docs'].'os-templates/" target="_blank" tooltip="'.__('You can do a Wildcard search using *<br>e.g. abc* will match device starting with abc').'"><i class="icon-help text-dark" ></i></a></span>
</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{

echo '<script language="javascript" type="text/javascript"><!-- // --><![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 getusage(){
	if(AJAX("'.$globals['index'].'act=cpu&ajax=true", "drawpie(re)")){
		return false;
	}else{
		return true;	
	}
};

function startusage(){
	ajaxtimer = setInterval("getusage()", 5000);
};	

function drawpie(re){	
	
	var cpu = [
		{ label: "Used",  data: '.$cpu['percent'].'},
		{ label: "Free",  data: '.$cpu['percent_free'].'}
	];
	
	if(re.length > 0){
		try{
			eval(re);
		}catch(e){ }
	}
	
	resource_graph("holder", cpu);
	$_("cppercent").innerHTML = cpu[0]["data"]+" %";
	
};

addonload("drawpie(\'void(0);\');startusage();");

// ]]></script>


<div class="row w-100 mx-auto">
	<div class="col-sm-6 border-right">
		<div class="roundheader">'.__('CPU 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%">'.__('CPU Information').'</td><td class="fhead val">'.$cpu['limit'].'</td></tr>
			<tr><td align="left" class="blue_td">'.__('Utilized : ').'</td><td class="val" id="cppercent"></td></tr>
			<tr><td align="left" class="blue_td">'.__('Powered by : ').'</td><td><img src="'.$theme['images'].$cpu['manu'].'.png" /></td></tr>
		</table>
	</div>
	<div class="col-sm-6" align="center">
		<div class="roundheader" align="left">'.__('CPU Utilization').'</div>
		<div id="holder" style="width:170px; height:170px;" class="m-2">
	</div>
</div>


';

}
echo '</div><br><br><div class="notice">
'.__('All logos used are trademarks or registered trademarks of their respective companies.').'
</div></div>';
softfooter();

}

?>