<?php

//////////////////////////////////////////////////////////////
//===========================================================
// processes_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 processes_theme(){

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

softheader($l['<title>']);
										
echo '<script type="text/javascript">

function multi_action(n) {
	
	var op = $("#multi_options_"+n).val();
	if(op == "0"){
		showalert("'.__J('No action selected !').'" ,"1");
	}else{
		var conf_lang = new Array();
		conf_lang["kill"] = "'.__J('Are you sure you want to kill the selected processes ?').'";	
		showalert(conf_lang[op] ,"3" ,function(confirm){
			if(confirm != true){
				return false;
			}else{
				$("#action").val(op);
				$("form#processes").submit();
			}
		});
	}
	
}

</script>';

echo '
<div class="bg">
<div class="row my-3 mx-auto">
	<div class="col-10">
		<h4 class="text-dark"><i class="fab fa-buffer"></i> '.__('List of Processes').'</h4>
	</div>
	<div class="col-2 text-right d-flex align-items-center justify-content-end">
		<span class="icon-fix d-flex align-items-center justify-content-center"><a href="'.$globals['docs'].'processes/" target="_blank" tooltip="'.__('You can do a Wildcard search using *<br>e.g. abc* will match emails starting with abc').'"><i class="fas fa-question text-always-white" ></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>';
	
}elseif(empty($processes)){
	show_alert(__('Could not load the list of processes !') ,"2");
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.__('Could not load the list of processes !').'</div>';

}else{

echo '<form accept-charset="'.$globals['charset'].'" id="processes" name="processes" method="post" action="" class="form-horizontal">

<input type="hidden" id="action" name="action" value="0" />
';
echo'<div class="row mx-auto w-100 mt-3">
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
	echo'
	</div>
	<div class="col-sm-4 col-lg-4 col-md-6 text-right mb-3">
		<div class="bottom-menu float-right w-100">
            <div class="row my-auto">
                <div class="p-0">
                    <label>'.__('With Selected').'</label>
                </div>
                <div class="col p-0">
					<select id="multi_options_1" class="custom-select">
						<option value="0">---</option>
						<option value="kill">'.__('Kill').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="button" value="'.__('GO').'" onclick="multi_action(1)" class="go_btn"/>
                </div>
            </div>
		</div>
	</div>
</div>
<div class="w-100 mx-auto  scrollbar-virt task_table">
<table class="table table-hover tablesorter tasks_table" align="center" cellpadding="6" cellspacing="2" border="0" width="100%">
<tr>';

	$keys = array_keys(current($processes));
	
	foreach($keys as $k => $v){
		echo '<th align="center">'.$v.'</th>';
	}
	
echo '<th class="z-index-1 min_width" align="center">
		'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
	</th>
</tr>';

//r_print($processes);	
foreach($processes as $k=>$v){
	echo '<tr>';	
	foreach($v as $vv){
		//Align Commands to left
		if(array_search($vv, $v) == 'COMMAND'){
			echo '<td align="left">   '.$vv.'</td>';
		}else{
			echo '<td align="center">'.$vv.'</td>';
		}
	}
	echo '<td align="center">
			'.get_checkbox('sel_proc[]', '', '', array('chk_it' => 0), $v['PID']).'
		</td>
	</tr>';
}
		
echo'</table>
</div>';
echo'<div class="row mx-auto w-100 mt-5">
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
	echo'
	</div>
	<div class="col-sm-4 col-lg-4 col-md-6 text-right mb-3">
		<div class="bottom-menu float-right w-100">
            <div class="row my-auto">
                <div class="p-0">
                    <label>'.__('With Selected').'</label>
                </div>
                <div class="col p-0">
					<select id="multi_options_2" class="custom-select">
						<option value="0">---</option>
						<option value="kill">'.__('Kill').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="button" value="'.__('GO').'" onclick="multi_action(2)" class="go_btn"/>
                </div>
            </div>
		</div>
	</div>
</div>
</form>
';

}

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

}

?>
