<?php

//////////////////////////////////////////////////////////////
//===========================================================
// ftpservers_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Julien
// Date:       19th July 2012
// 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 storageusage_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $storage, $storage_servers, $servers, $servergroups, $done, $disks;

softheader($l['<title>']);

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_storage', 'lms_storageusage');
					
echo page_header(__('Storage Usage'), 'fas fa-hdd','', 1, 0, '');

error_handle($error);

// Check which stid belongs to which servers
foreach($storage_servers as $p => $q){
	if($q['serid'] == -1){
		$ipgp[$q['stid']][] = __('All Servers');
	}elseif($q['serid'] == -2){
		$ipgp[$q['stid']][] = '[Group] '.$servergroups[$q['sgid']]['sg_name'];
	}else{
		foreach($servers as $x => $y){
			if($q['serid'] == $y['serid'] || $q['sgid'] == $y['sgid']){
				$ipgp[$q['stid']][] = $y['server_name'];
			}
		}
	}
}

echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
let storageflare = {"LVM":"<span class=\"roundflare text-always-white bg-orange\">", 
	"Thin LVM":"<span class=\"roundflare text-always-white bg-orange\">",
	"OpenVZ":"<span class=\"roundflare text-always-white bg-success\">",
	"File":"<span class=\"roundflare text-always-white bg-success\">",
	"ZFS":"<span class=\"roundflare text-always-white bg-warning\">",
	"ZFS Thin":"<span class=\"roundflare text-always-white bg-warning\">",
	"ZFS Compresse":"<span class=\"roundflare text-always-white bg-warning\">",
	"ZFS Thin Compressed":"<span class=\"roundflare text-always-white bg-warning\">",
	"Ceph Block Device":"<span class=\"roundflare text-always-white bg-danger\">",
	"Lightbit":"<span class=\"roundflare text-always-white bg-yrange\">"
};

// ]]></script>
<div class="card p-2 mx-3">
	<div id="showsearch" class="mb-3" style="display:'.(optREQ('search') || (!empty($disks) && !empty($globals['showsearch'])) ? "" : "none").';">
		<form accept-charset="'.$globals['charset'].'" name="storageusage" method="GET" action="" class="form-horizontal">
			<input type="hidden" name="act" value="storageusage">	
			<div class="form-group_head">
				<div class="row mx-auto w-100">
					<div class="col-sm-4"><label>'.__('Name').'</label>
						<input type="text" class="form-control" name="st_name" id="st_name" size="30" value="'.REQval('st_name','').'"/>
					</div>
					<div class="col-sm-4"><label>'.__('Path').'</label>
						<input type="text" class="form-control" name="path" id="path" size="30" value="'.REQval('path', '').'" />
					</div>
					<div class="col-sm-4"><label>' . __('Servers') . '</label>
						<select name="serid" id="serid" class="form-control virt-select">
							<option value="-1" ' . REQselect('serid', -1) . '>' . __('All Servers') . '</option>';
							foreach ($servers as $k => $v) {
								echo '<option value="' . $k . '" ' . REQselect('serid', $k) . '>' . $v['server_name'] . '</option>';
							}
							echo'
						</select>
					</div>
				</div>
				<div class="row mx-auto w-100">
					<div class="col-sm-4"><label>'.__('VPS ID').'</label>
						<input type="text" class="form-control" name="vpsid" id="vpsid" size="30" value="'.REQval('vpsid','').'"/>
					</div>
					<div class="col-sm-4"><label>'.__('Type').'</label>
						<input type="text" class="form-control" name="st_type" id="st_type" size="30" value="'.REQval('st_type','').'"/>
					</div>
				</div>
				<div class="row mx-auto w-100 my-2">
					<div class="col-sm-12 text-center"><button type="submit" name="search" class="go_btn mt-2" value="Search"/>'.__('Search').'</button></div> 
				</div>
			</div>
		</form>
	</div>
';

if(!empty($done)){
	show_alert(__('The Storage was deleted successfully'));
	//echo '<div class="notice"><b>NOTE : </b>&nbsp; '..'</div>';
}

if(empty($disks)){
	optREQ('search') ? show_alert(__('No results were found for your search query'), "2") : "";
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.(optREQ('search') ? __('No results were found for your search query') : __('There are no Storage added. <a href="index.php?act=addstorage">Add a Storage.</a>')).'</div>';
	
}else{
	echo'<div class="row mx-auto w-100">
	<div class="col-sm-4 col-lg-4 col-md-6 text-right d-flex align-items-center">
	</div>
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0 d-flex align-items-center justify-content-end">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo get_num_records($globals['num_res']).'
	</div>
</div>
<form accept-charset="'.$globals['charset'].'" name="multi_storage" id="multi_storage" method="post" action="" class="form-horizontal">
<div class="w-100 mx-auto sticky">
<table class="table table-hover tablesorter common-table">
<tr class="table_heading">
	<th align="center" class="min_width">'.__('ID').'</th>
	<th align="center">'.__('Servers').'</th>
	<th align="center">'.__('Storage Name').'</th>
	<th align="center">'.__('Email').'</th>
	<th align="center">'.__('VPS ID').'</th>
	<th align="center">'.__('Type').'</th>
	<th align="center">'.__('Path').'</th>
	<th align="center">'.__('Hostname').'</th>
	<th align="center">'.__('Size').'</th>
	<!--<th colspan="2">'.__('Manage').'</th>
	<th class="z-index-1 min_width">
		'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
	</th>-->
</tr>';
	foreach($disks as $k => $v){
echo '<tr>
	<td>'.$v['did'].'</td>
	<td>'.$v['server_name'].'</td>
	<td><a href="'.$globals['index'].'act=editstorage&stid='.$v['stid'].'" target="_blank">'.$v['storage_name'].'</a></td>
	<td>'.$v['email'].'</td>
	<td><a href="'.$globals['index'].'act=managevps&vpsid='.$v['vpsid'].'" target="_blank">'.$v['vpsid'].'</a></td>
	<td><script>document.write(storageflare["'.storage_type_text($v['type']).'"])</script>'.storage_type_text($v['type']).'</span></td>
	<td><span class="text-monospace">'.$v['path'].'</span></td>
	<td>'.$v['hostname'].'</td>
	<td>'.size_converter($v['size'], 'GB').'</td>
	<!--<td><a href="?act=editstorage&stid='.$v['stid'].'" title="Edit"><i class="fas fa-edit text-warning"></i></a></td>
	<td><a href="javascript:void(0);" onclick="return Delstorage('.$k.');" title="Delete"><i class="fas fa-trash text-danger"></i></td>
	<td width="20" valign="top" align="center">
		'.get_checkbox('storage_list[]', '', '', array('chk_it' => 0), $k).'
	</td>-->
	</tr>';
	}
echo '</table>
</div>
<div class="row mx-auto w-100 mt-5">
	<div class="col-sm-4 col-lg-4 col-md-6 text-right d-flex align-items-center">
	</div>
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0 d-flex align-items-center justify-content-end">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo'
	</div>
</div>
</form>

</div><br>';

}
softfooter();

}
?>
