<!DOCTYPE html>
<html lang="es-ES">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Reporte Historial</title>
<link href="../../maincss.css" rel="stylesheet" type="text/css" />
<link href="../../printcss.css" rel="stylesheet" type="text/css" media="print" />

</head>
<?php
include "../../conn.php";
//include "../../class.nroenletraver2.php";
include "../../general.php";
include "../../token.php";

$rep=$_GET["rep"];
$tipo=$_GET["tipo"];

//$usuario=$_POST["usuario"];
$usuario_lista=$_POST["usuario_lista"];
$fechaini=$_POST["fechaini"];
$fechafin=$_POST["fechafin"];
$modulo=$_POST["modulo"];
$componente=$_POST["componente"];
//echo $modulo;
?>
<body>

<?php
	
// Inicio impresion historico

if($rep == 6 && $tipo == 1) { // if 1


if($usuario_lista == 0) {//if $usuario_lista
	$valor_usuario_lista = ' ';
	$nom_usuario_lista = 'Todos';
} else {
	$resultul = mysqli_query($link, "select fldLogin as usuario 
	from accUser
	where 
	pkyUser = '$usuario_lista' and
	sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultul)) {
		$nom_usuario_lista = $row['usuario'];
	}
	mysqli_free_result($resultul);
	$valor_usuario_lista = ' a.codUser = '.$usuario_lista.' and ';
}//fin if $usuario_lista

if(strcmp("0",$modulo) == 0) {//if modulo
	$valor_modulo = ' ';
	$valor_modulo2 = ' ';
	$nom_modulo = 'Todos';
} else {
	$valor_modulo = ' d.txtModuleDescription LIKE '.'"'.$modulo.'"'.' and ';
	//uso esto para anular la segunda parte del query union all
	$valor_modulo2 = ' a.codUser = 0 and ';
	$nom_modulo = $modulo;
}//fin if modulo


if($componente == 0) {//if componente
	$valor_componente = ' ';
	$nom_componente = 'Todos';
} else {
	$resultcom = mysqli_query($link, "select pkyComponent as cod, txtDescription as componente
	from
	srvComponent
	where 
	pkyComponent = '$componente' and
	sysEnabled = 1 and sysAuthorized = 1;");
	while ($row = mysqli_fetch_array($resultcom)) {
		$nom_componente = $row['componente'];
	}
	mysqli_free_result($resultcom);
	$valor_componente = ' a.cosObjectKey = '.$componente.' and ';
}//fin if componente



$result3 = mysqli_query($link, "select a.pkyUserLog as cod_log, a.codUser as cod_usuario, b.fldLogin as usuario, a.codSystemObjectType as cod_tipo, c.fldName as tipo, a.fldDate as fecha, a.fldTime as hora, a.cosObjectKey as cod_com, d.txtModuleDescription as modulo, d.txtDescription as componente, a.cosActionKey as cod_accion, e.fldName as accion
from dbaUserLog a, accUser b, srvSystemObjectType c, srvComponent d, srvComponentAction e
where 
$valor_usuario_lista 
$valor_modulo 
$valor_componente 
a.codUser = b.pkyUser and 
a.codSystemObjectType = 2 and 
a.codSystemObjectType = c.pkySystemObjectType and 
a.fldDate >= '$fechaini' and 
a.fldDate <= '$fechafin' and 
a.cosObjectKey = d.pkyComponent and 
a.cosActionKey = e.pkyComponentAction and 
a.sysEnabled = 1 and a.sysAuthorized = 1

union all 

select a.pkyUserLog as cod_log, a.codUser as cod_usuario, b.fldLogin as usuario, a.codSystemObjectType as cod_tipo, c.fldName as tipo, a.fldDate as fecha, a.fldTime as hora, 209001 as cod_com, 'Autenticador' as modulo, 'Autenticador' as componente, a.cosActionKey as cod_accion, e.fldName as accion
from dbaUserLog a, accUser b, srvSystemObjectType c, srvComponentAction e
where 
$valor_usuario_lista 
$valor_modulo2 
$valor_componente 
a.codUser = b.pkyUser and 
a.codSystemObjectType = 1 and 
a.codSystemObjectType = c.pkySystemObjectType and 
a.fldDate >= '$fechaini' and 
a.fldDate <= '$fechafin' and 
a.cosActionKey = e.pkyComponentAction and 
a.sysEnabled = 1 and a.sysAuthorized = 1 
order by fecha, hora;");
$ma_his = array();
$h = 1;
while ($row = mysqli_fetch_array($result3)) {
	$ma_his [$h][1] = $row['cod_log'];
	$ma_his [$h][2] = $row['fecha'];
	$ma_his [$h][3] = $row['hora'];
	$ma_his [$h][4] = $row['cod_usuario'];
	$ma_his [$h][5] = $row['usuario'];
	$ma_his [$h][6] = $row['cod_accion'];
	$ma_his [$h][7] = $row['accion'];
	$ma_his [$h][8] = $row['cod_com'];
	$ma_his [$h][9] = $row['modulo'];
	$ma_his [$h][10] = $row['componente'];
	$h++;
}
mysqli_free_result($result3);
$fin_h = $h - 1;

//$numero_filas = mysqli_num_rows($result3);
?>
<table border="0" align="left" width="100%" cellpadding="5">
<tr><td><?php echo $mostrar_logo_reportes; ?>
</td><td align="right"><b>Fecha: <?php echo date("Y-m-d"); ?><br/>Hora: <?php echo date("H:i:s"); ?><br/>Usuario: <?php echo $usuario; ?></b>
</td></tr></table>
<p><br /><center><font color="#000099" size="+1"><b>Reporte Historial</b></font></center></p>
<table border="0" cellpadding="2" align="center" width="100%">
<tr>
<td>	
    <table border="1" align="center" cellpadding="2" width="100%">
        <TR> 
        <TD width="33%"><b>Usuario: </b><?php echo $nom_usuario_lista; ?></TD>
        <TD width="33%"><b>M&oacute;dulo: </b><?php echo $nom_modulo; ?></TD>
        <TD width="33%"><b>Componente: </b><?php echo $nom_componente; ?></TD>
        </TR>
    </table>

</td>
<!--
<td valign="top" width="150">

    <table border="1" align="center" cellpadding="2" width="100%">
    <tr>
    <TD><b>Tipo de Cambio:</b></TD>
    </tr><tr>
    <TD align="center"><a href="../../ModuleAccounting/VoucherExchangeRate/index.php?pkyExchangeRate=<?php echo $cod_tc; ?>&user=<?php echo $usuario; ?>&token=<?php echo $token; ?>" title="Tipo de Cambio"><?php echo $cod_tc; ?></a> (<?php echo $tc_fecha; ?> - <?php echo $tc_hora; ?>)<br/ >
        <table border="0" cellpadding="2" align="center">
            <?php
            for($m = 1; $m <= $fin_m; $m++) {
            printf("<tr><td align='left'>1 %s</td>", $ma_tc [$m][1]);//moneda base
            printf("<td align='center'>%s</td>", ' = ');//letra a
            printf("<td align='left'>%s %s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio), $ma_tc [$m][2]);//moneda target y tasa
            //printf("<td align='right'>%s</td></tr>", number_format($ma_tc [$m][3],$n_tipocambio));//tasa
            }
            ?>
        </table>
    </TD>
    </tr>
	</table>
    
</td>
-->
</tr>
</table>
<br />
<!--detalle historial -->
<table border="1" align="center" cellpadding="2" width="100%">
 	<thead>
    <TR> 
    <TD align="center"><b>Cod.</b></TD>
    <TD align="center"><b>Fecha</b></TD>
    <TD align="center"><b>Hora</b></TD>
    <TD align="center"><b>Usuario</b></TD>
    <TD align="center"><b>Acci&oacute;n</b></TD>
    <TD align="center"><b>M&oacute;dulo</b></TD>
    <TD align="center"><b>Componente</b></TD>
    </TR>
    </thead>
    <tbody class="marcafila">
    <?php
    $color = 2;
	$suma_reg = 0;
		
	for($i = 1; $i <= $fin_h; $i++) { //for
		
		if($color % 2 == 0) { //if color
		printf("<tr BGCOLOR='#e2e7fa'><td align='center'>%s</td>", $ma_his [$i][1]);//cod log
		} else {
		printf("<tr><td align='center'>%s</td>", $ma_his [$i][1]);//cod log
		} //cierra if color
		printf("<td align='right'>%s</td>", $ma_his [$i][2]);//fecha reg
		printf("<td align='right'>%s</td>", $ma_his [$i][3]);//hora reg
		printf("<td align='left'>%s</td>", $ma_his [$i][5]);//usuario
		printf("<td align='left'>%s</td>", $ma_his [$i][7]);//accion
		printf("<td align='left'>%s</td>", $ma_his [$i][9]);//modulo
		printf("<td align='left'>%s</td></tr>", $ma_his [$i][10]);//componente
				
		$suma_reg++;
		$color++;
	}//fin for
	
	?>
	<tr BGCOLOR='#ffcccc'>
    <td colspan="6"><b>Total acciones</b></td>
    <td align="right"><b><?php echo $suma_reg; ?></b></td>
    </tr>
</tbody>
</table>

<?php 

} //fin if 1 

?>

</body>
</html>
