<?php

//////////////////////////////////////////////////////////////
//===========================================================
// vsram_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 vsram_theme(){

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

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-memory"></i> '.__('VPS RAM Utilization').'</h4>
	</div>
	<div class="col-2 text-right">
		<a href="'.$globals['docs'].'Server_RAM_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{
	
	// Are there any VPSes ?
	if(count($vpses) < 1){
	
		echo '<div class="notice"><img src="'.$theme['images'].'notice.gif" /> &nbsp; '.__('There is no VPS on this Server').'</div>';
		
	}else{
	
		foreach($vpsusage as $k => $v){
			if($v['used'] <= 0){
				continue;
			}

			if($k == 0) continue;
			$data["VPS ID - ".$k] = $v['used'];
			
		}
		$label = json_encode(array_keys($data));
		$data = array_map('intval', array_values($data));
		// Encode to JSON
		$data2 = json_encode($data);
		echo '<center><div id="holder" style="width:450px; height: 250px">&nbsp</div><br /><br /></center>
<script type="text/javascript" charset="utf-8"><!-- // --><![CDATA[

$(function () {
	
	var label = JSON.parse(\''.$label.'\');
	var data = JSON.parse(\''.$data2.'\');



		var ram_options = {
			chart: {
				type: "pie"
			},
			series: data,
			labels: label,
			tooltip: {
					enabled: true,
					y: {
						formatter: function(val) {
							// Format the tooltip with the VPSID
							return (val / 1024).toFixed(2) + " GB";
						}
					}
				}
		};



	var chart = new ApexCharts(document.querySelector("#holder"), ram_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">'.__('RAM').'</th>
		<th align="center">'.($cluster->virt(1) ? __('Burst') : __('Swap')).'</th>
		<th align="center">'.__('Used').'</th>
	</tr>';

	$i = 1;
	
	foreach($vpses as $k=>$v){
		
		echo '<tr>
			<td align="left">'.$v['vpsid'].'</td>
			<td align="left">'.$v['vps_name'].'</td>
			<td>'.$v['hostname'].'</td>
			<td align="left">'.$v['ram'].' MB</td>
			<td align="left">'.($cluster->virt(1) ? $v['burst'] : $v['swap']).' MB</td>
			<td align="left">'.$vpsusage[$k]['used'].'</td>
		</tr>';
	
		$i++;
	}
		
	echo '</table>';
	
	}
	
}
echo '</div>';
softfooter();

}

?>