<?php
include("postget.php");
include_once("common.php");
$pagetitle = _HISTORY_FILE;

checklevel(1,$_REQUEST['clientid']);


$thisclient=1;
//if(!secure(1)){no_access();}
//if(!$id){no_access();}
include("head_template.php");

////////////////////////// ARCHIVO HISTORICO //////////////////////////////

//if($_SESSION['hd_accesslvl']==1) { include("menu_client.php"); }


if ($_REQUEST['orderby']) {
	$orderby = $_REQUEST['orderby'];
}else{
	$orderby ='time DESC';
}

if ($filter=="suspension") {
	$filter= " AND action LIKE '%"._SUSPENDED."%'";
}else{
	$filter="";
}

$query ="SELECT * FROM hd_history WHERE clientid='".$_SESSION['hd_clientid']."' $filter ORDER BY ".$orderby.""; 

$paging = new pagination;
$paging->mantenerVar('orderby','filter','clientid');

$paging->agregarConsulta($query);
$paging->porPagina($config[32][1]);
$paging->paginasAntes(3, 10, 20, 50);
$paging->paginasDespues(3, 10, 20, 50);
$paging->linkSeparador('&nbsp;');
$paging->linkSeparadorEspecial('...');
$paging->linkClase('pag');
$paging->mostrarActual("<span class=\"pagthis\">{n}</span>");

$paging->ejecutar();


echo '
<div class="container">
	<div class="row">
';

//echo "".strtoupper(_HISTORY_FILE)." (".$paging->numTotalRegistros()." "._RECORDS.")";


if ($paging->numTotalPaginas() > 1) {
	echo "<div class='pagination'><b>".ucfirst(_PAGES)."</b>: ".$paging->fetchNavegacion()."</div>";
}

echo '<table class="table table-striped">';

print("<thead><tr>");


print("
<th>"._DATE." / "._TIME."</th>
<th>"._EVENT_ID."</th>
<th>"._ACTION."</th>");
if($_SESSION['hd_accesslvl']>1){
	print("<th align='center'>"._USER."</th>");
}
print("</tr></thead><tbody>");

while($row = $paging->fetchResultado()) {

	$then=date($df,$row[time]);
	$when=$then;
	$when.=" - ";
	$when.=date("G:i:s",$row[time])." (".TimeAgo($row[time],time()+$config[31][1]*3600)." "._AGO.")";


	print("<tr><td nowrap>$when</td><td align='center'>");

	if($_SESSION['hd_accesslvl']==4){
		print("<a href='".$serverurl."/delevent.php?clientid=".$_SESSION['hd_clientid']."&eventid=$row[eventid]'><img class='sprites del' src='images/transparent.gif' border='0' title='"._DELETE."'></a>");
		print(" $row[eventid]</td><td>");
		if (defined($row[action])) {
			print (constant($row[action]));
		}else{
			print ($row[action]);
		}
		print("</td><td align='center'>$row[user]</td>");
	}else{
		print(" $row[eventid]</td><td>");
		if (defined($row[action])) {
			print (constant($row[action]));
		}else{
			print ($row[action]);
		}
		print("</td>");
	}

	print("</tr>");
}

echo '
		</td>
		</tr></tbody>
		</table>
</div>
</div>
';

include("foot_template.php");

?>
