<?php

//////////////////////////////////////////////////////////////
//===========================================================
// logs_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 logs_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $logs;

softheader($l['<title>']);
										
echo '
<script language="javascript" type="text/javascript">
	function confirm(){
		showalert("'.__J('Are you sure you want to delete the logs ?').'", "3", function(confirm){
			if(confirm == true){
				$("#delete").submit();
			}
		});
		return false;
	}
</script>';

echo page_header(__('Logs'), 'fas fa-clipboard-list', '', 1);

$breadcrumbs = ['dashboard', 'lm_logs', 'lms_logs'];

echo get_breadcrumb($breadcrumbs);

echo '<div class="card p-2 mx-3">
<div id="showsearch" style="display:'.(optREQ('search') || (!empty($logs) && !empty($globals['showsearch'])) ? "" : "none").';" class="form-horizontal">
<form accept-charset="'.$globals['charset'].'" name="logs" method="get" action="">
<input type="hidden" name="act" value="logs">
		
<div class="form-group_head">
  <div class="row mx-auto w-100">
    <div class="col-sm-3"></div>
	<div class="col-sm-3">
		<label>'.__('VPS ID').'</label>
		<input type="text" class="form-control" name="id" id="id" size="30" value="'.REQval('id','').'"/>
	</div>
	<div class="col-sm-3">
		<label>'.__('Email').'</label>
		<input type="text" class="form-control" name="email" id="email" size="30" value="'.REQval('email','').'"/>
	</div>
  </div>
  <div class="row my-2 mx-auto w-100">
  	<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($logs)){
	optREQ('search') ? show_alert(__('No results were found for your search query'), "2") : show_alert(__('There are no Logs.'), "2");
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.__('There are no Logs.').'</div>';
}
else{
	echo'<div class="row mx-auto w-100 mb-3">
		<div class="col-sm-8 col-lg-8 col-md-6 d-flex align-items-center p-0">';
			page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo get_num_records($globals['num_res']).'
		</div>
	</div>
	<div class="w-100 mx-auto sticky">
	<table class="table table-hover tablesorter common-table">
	<tr class="table_heading">
		<th align="center">'.__('User').'</th>
		<th align="center">'.__('VPS ID').'</th>
		<th align="center">'.__('Date').'</th>
		<th align="center">'.__('Act ID').'</th>
		<th align="center">'.__('Action').'</th>
		<th align="center">'.__('Status').'</th>
		<th align="center">'.__('IP').'</th>	
	<tr>';
	$i = 0;
	foreach($logs as $k => $v){
		
		$ips_data = unserialize($v['data']);

		if(!empty($ips_data) && count($ips_data) == 1){

			$log_data = action_text($v['action'], $ips_data['0']).' ';
			
		// if the ip log data gives more than one ip then add tooltip for it 
		}elseif(!empty($ips_data) && count($ips_data) > 1){
			
			$ips = '';
			foreach($ips_data as $k => $ip){
				$ips .= $ip.'<br>';
			}
			$tooltip = '<i class="fas text-primary fa-info-circle" tooltip="'.$ips.'"></i>';
			$log_data = action_text($v['action'], $tooltip).' ';
		}else{
			$log_data = action_text($v['action'], $v['data']).' ';
		}

	echo '<tr>
			<td><span class="userflare">'.$v['email'].'</span></td>
			<td align="left">'.$v['id'].'</td>
			<td>'.datify($v['time']).'</td> 
			<td>'.$v['actid'].'</td>
			<td>'.$log_data.'</td>
			<td align="center">'.($v['status'] == 1 ? '<font color="#5bbf71">Successful</font>' : ($v['status'] == 2 ? '<font color="#FF0000">Blocked</font>' : '<font color="#FF0000">Failed</font>')).'</td>
			<td>'.$v['ip'].'</td>
		  </tr>';
		  $i++;
		  
	}
	
	echo '</table></div>
	<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>
	<form id="delete" accept-charset="'.$globals['charset'].'" name="logs" method="post" action="" class="form-horizontal">
		<input type="hidden" name="delete" value="1"></input> 
		<center><input type="button" value="'.__('Delete All Logs').'" class="btn" onclick="confirm();"></center>
	</form>';
}

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

}

?>