<?php

//////////////////////////////////////////////////////////////
//===========================================================
// vscpu_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 vscpu_theme(){

global $theme, $globals, $cluster, $user, $l, $vpsusage, $available, $vpses;

softheader($l['<title>']);
					if(server_virt($globals['server'], 'xcp') == 'xcp'){
	echo '<div class="notice"><img src="'.$theme['images'].'notice.gif" /> &nbsp; '.__('This feature is currently not available in XenServer').'</div>';
}else{
	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> '.__('VPS CPU Utilization').'</h4>
			</div>
			<div class="col-2 text-right">
				<a href="'.$globals['docs'].'Server_CPU_Usage" target="_blank" class="wiki_help" tooltip="'.__('You can do a Wildcard search using *<br>e.g. abc* will match emails starting with abc').'"><i class="icon-help" ></i></a>
			</div>
		</div>';

	// Is it offline ?
	$hypervisor_status = $cluster->statewise($globals['server']);
	if($hypervisor_status == 0 || $hypervisor_status == 2){

		echo '<div class="e_notice"><img src="'.$theme['images'].'notice.gif" /> &nbsp; '.$globals['hypervisor_status'][$hypervisor_status].'</div>';
		
	}else{

		if(count($vpses) < 1){
			echo '<div class="notice"><img src="'.$theme['images'].'notice.gif" /> &nbsp; '.__('There is no VPS on this Server').'</div>';
			
		}else{
		
		$total = 0;
			
		foreach($vpsusage as $k => $v){
			if($v == 0){
				continue;
			}
			$total += $v;
			$values["VPS ID - ".$k] = $v;
		}
		
		if($total < 100){
			$values['Free'] = 100 - $total;
		}

		$labels = json_encode(array_keys($values));
		$values = json_encode(array_values($values));
		
		echo '<center><div id="holder" style="width:450px; height: 250px"></div><br /><br /></center>

	<script type="text/javascript" charset="utf-8"><!-- // --><![CDATA[
		
	$(function () {
		
		var label = JSON.parse(\''.$labels.'\');
		var data = JSON.parse(\''.$values.'\');
		data = data.map(Number);

		var cpu_options = {
			chart: {
				"type": "pie"
				
			},
			series: data,
			labels: label,
			tooltip: {
					enabled: true,
					y: {
						formatter: function(val) {
							return val + " %";
						}
					}
				}
		};

		var chart = new ApexCharts(document.querySelector("#holder"), cpu_options);
		chart.render();

	});
		
	// ]]></script>	
	
		<table class="table table-hover tablesorter">
		<tr>
			<th align="center">'.__('VPS ID').'</th>
			<th align="center">'.__('VPS Name').'</th>
			<th align="center">'.__('Hostname').'</th>
			<th align="center">'.__('Used').' %</th>
		</tr>';

		$i = 1;
		
		foreach($vpses as $k => $v){
			
			echo '<tr>
				<td align="center">'.$v['vpsid'].'</td>
				<td align="center">'.$v['vps_name'].'</td>
				<td>'.$v['hostname'].'</td>
				<td align="center">'.$vpsusage[$k].'</td>
			</tr>';
		
			$i++;
		}
			
		echo '</table>';
		
		}

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

}

?>
