<?php session_start();
require('../cfg/cfg.php');
require('../cfg/res.php');
//mysql_query("SET NAMES 'utf8'");

include('php_gene1.php');

gen_usrdoc();

$sql_acce='drop view usrdoc11';;
$res_acce=mysql_query($sql_acce,$link_vcrx);
// echo '*/*/*'.$res_acce;


$sql_acce ='create view usrdoc11 as ';
$sql_acce.='select usrdoc1.*,';
$sql_acce.='user_codigo, user_cedula,user_email,user_nickname,user_descri,user_tipo,docu_descri, docu_tipo, docu_tabla, modu_descri  ';
$sql_acce.='from usrdoc1 ';
// $sql_acce.=' join user0 on user=user_cedula ';
$sql_acce.=' join user0 on codigo=user_codigo ';
$sql_acce.=' join docu0 on docu=docu_codigo ';
$sql_acce.=' left join modu0 on docu_tabla=modu_codigo ';
$sql_acce.=' where docu_tipo not like ""';
$res_acce=mysql_query($sql_acce,$link_vcrx);
// echo '*/*/*'.$res_acce;

// echo $sql_acce;
// echo '<br>';
// echo mysql_error();

$xacceso=0;
$sql_acce='select * from usrdoc1 where docu like "ACCE" and (cons="1" or modi="1") and user="'.$_SESSION['user_vcrx_id'].'" ';
$sql_acce='select * from usrdoc1 where docu="ACCE"  and user="'.$_SESSION['user_vcrx_id'].'" ';
// $sql_acce='select * from empr0';
$res_acce=mysql_query($sql_acce,$link_vcrx);
// echo '***'.$sql_acce.mysql_error();
// echo $sql_acce;
// echo '***'.mysql_num_rows($res_acce);
// explain_sql($sql_acce);

if(mysql_num_rows($res_acce)!=0){$xacceso=1;}
if(mb_stristr('sist.supe',$_SESSION['user_vcrx_tipo'])){$xacceso=1;}
if($xacceso==0){echo '<font size="8" color="red"><b>';die('No tiene Permisos'.$docu_tipo );}	


$pagina_descri='ACCESOS DE '.$empr_nombre;
$pagina_nivel;
$pagina_tipo;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $empr_nombre.'-'.$_SESSION['user_vcrx_id'];?> - Accesos</title>
<link rel="stylesheet" href="http://vcrxol.com/_css/comun.css" type="text/css" />
<script type="text/javascript" src="../js/jquery-1.11.1.js"></script>
<script type="text/javascript">
function accesa()
{
	
	
	var enti
	var nuev_n=document.getElementsByClassName('cl_nuev').length-1;
	var docu;
	var nuev;
	var modi;
	var apro;
	var proc;
	var anul;
	var elim;
	var cons;
	var info;
	var espe;
	
	

	for(i=0;i<=nuev_n;i++)
	{
	
		docu=document.getElementsByClassName('cl_docu').item(i).value;
		nuev=0;
		modi=0;
		apro=0;
		proc=0;
		anul=0;
		elim=0;
		cons=0;
		info=0;
		espe=0;
	
		if(document.getElementsByClassName('cl_nuev').item(i).checked)
		{
			nuev='1';
		}
		if(document.getElementsByClassName('cl_modi').item(i).checked)
		{
			modi='1';
		}
		if(document.getElementsByClassName('cl_apro').item(i).checked)
		{
			apro='1';
		}
		if(document.getElementsByClassName('cl_proc').item(i).checked)
		{
			proc='1';
		}
		if(document.getElementsByClassName('cl_anul').item(i).checked)
		{
			anul='1';
		}
		if(document.getElementsByClassName('cl_elim').item(i).checked)
		{
			elim='1';
		}
		if(document.getElementsByClassName('cl_cons').item(i).checked)
		{
			cons='1';
		}
		if(document.getElementsByClassName('cl_info').item(i).checked)
		{
			info='1';
		}
		if(document.getElementsByClassName('cl_espe').item(i).checked)
		{
			espe='1';
		}
			
			enti=document.getElementsByClassName('cl_enti').item(i).value;
			$.ajax({
			cache:false,
			url:'vracces2.php',
			datatype: "text",
	    	async:false,
			type:'POST',
			data:{enti:enti,docu:docu,nuev:nuev,modi:modi,apro:apro,proc:proc,anul:anul,elim:elim,cons:cons,info:info,espe:espe}, 
	    	beforeSend: function(jqXHR, textStatus)
			{
			}, 
		
			success:function(dato, textStatus, jqXHR)
			{
			},
			error:function(jqXHR,textStatus,errorThrown )
			{
        	   if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
	           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
    	       } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
    	       } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
	           } else if (exception === 'timeout') {
    			   alert('Servidor no Responde');
    	       } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
	           } else {
    	           console.log('Uncaught Error: ' + jqXHR.responseText);
	           }
			}, 
	    	complete:function(jqXHR, textStatus)
    		{  console.log(textStatus);
				if(textStatus==='success')
	        	{
					
				}           
			},
			timeout:96000
			});
		
		//setTimeout(function(){  }, 3000);
	}

document.getElementById('loader').style.display='none';
document.getElementById('btn_guarda').disabled=false;
	
}

function todos(clase,ident)
{
	var ele=document.getElementsByClassName(clase).length-1;
	for(i=0;i<=ele;i++)
	{
		if(document.getElementById(ident).checked)
		{
			document.getElementsByClassName(clase).item(i).checked=true;	
		}
		else
		{
			document.getElementsByClassName(clase).item(i).checked=false;
		}
		
	}
}

function enti()
{
		var entiti=document.getElementById('enti').value;
		
		if(entiti=='' || entiti==' ')
		{
			return false;
		}
	
		//busca_maes2('user',document.getElementById('enti').value,'enti','enti_descri','');
		busca_maes2('enti',document.getElementById('enti').value,'enti','enti_descri','');
		var ent_dcr=document.getElementById('enti_descri').innerHTML;
		if(ent_dcr!='' && ent_dcr!=' ' && ent_dcr!='N/A')
		{
			carga_acces(document.getElementById('enti').value,document.getElementById('docu').value);
		}
		
			setTimeout(function(){ 
				if(entiti!='' &&  entiti!=' ' && ent_dcr!='' && ent_dcr!=' ' && ent_dcr!='N/A')
				{		
					carga_tipo(entiti); 
				}
			}, 3000);
}

function user()
{
		var entiti=document.getElementById('user').value;
		
		if(entiti=='' || entiti==' ')
		{
			return false;
		}
	
		//busca_maes2('user',document.getElementById('enti').value,'enti','enti_descri','');
		busca_maes2('user',document.getElementById('user').value,'user','user_descri','');
		var ent_dcr=document.getElementById('user_descri').innerHTML;
		//entiti=document.getElementById('user').innerHTML;
		if(ent_dcr!='' && ent_dcr!=' ' && ent_dcr!='N/A')
		{
			carga_acces(document.getElementById('user').value,document.getElementById('modu').value,document.getElementById('docu').value);
		}
		
			setTimeout(function(){ 
				if(entiti!='' &&  entiti!=' ' && ent_dcr!='' && ent_dcr!=' ' && ent_dcr!='N/A')
				{		
					carga_tipo(document.getElementById('user').value); 
				}
			}, 3000);
}

function modu()
{
		var moduti=document.getElementById('modu').value;
		
		if(moduti=='' || moduti==' ')
		{
			return false;
		}

		busca_maes2('modu',document.getElementById('modu').value,'modu','modu_descri','');
		var doc_dcr=document.getElementById('modu_descri').innerHTML;
		if(doc_dcr!='' && doc_dcr!=' ' && doc_dcr!='N/A')
		{
			carga_acces(document.getElementById('user').value,document.getElementById('modu').value,document.getElementById('docu').value);
		}

}



function docu()
{
		var docuti=document.getElementById('docu').value;
		
		if(docuti=='' || docuti==' ')
		{
			return false;
		}

		busca_maes2('docu',document.getElementById('docu').value,'docu','docu_descri','');
		var doc_dcr=document.getElementById('docu_descri').innerHTML;
		if(doc_dcr!='' && doc_dcr!=' ' && doc_dcr!='N/A')
		{
			carga_acces(document.getElementById('user').value,document.getElementById('modu').value,document.getElementById('docu').value);
		}

}

function carga_acces(id,modu,docu)
{
	

			$.ajax({
			cache:false,
			url:'vracces3.php',
			datatype: "text",
	    	async:false,
			type:'POST',
			data:{id:id,modu:modu,docu:docu}, 
	    	beforeSend: function(jqXHR, textStatus)
			{
			}, 
		
			success:function(dato, textStatus, jqXHR)
			{
				document.getElementById('acces_list').innerHTML=dato;
			},
			error:function(jqXHR,textStatus,errorThrown )
			{
        	   if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
	           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
    	       } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
    	       } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
	           } else if (exception === 'timeout') {
    			   alert('Servidor no Responde');
    	       } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
	           } else {
    	           console.log('Uncaught Error: ' + jqXHR.responseText);
	           }
			}, 
	    	complete:function(jqXHR, textStatus)
    		{  
				if(textStatus==='success')
	        	{
					
				}           
			},
			timeout:96000
			});



}
function carga_tipo(enti)
{

	$.ajax({
			cache:false,
			url:'vracces4.php',
			datatype: "text",
	    	async:false,
			type:'POST',
			data:{enti:enti}, 
	    	beforeSend: function(jqXHR, textStatus)
			{
			}, 
		
			success:function(dato, textStatus, jqXHR)
			{
				console.log(dato);
				document.getElementById('enti_tipo').innerHTML=dato;
			},
			error:function(jqXHR,textStatus,errorThrown )
			{
        	   if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
	           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
    	       } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
    	       } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
	           } else if (exception === 'timeout') {
    			   alert('Servidor no Responde');
    	       } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
	           } else {
    	           console.log('Uncaught Error: ' + jqXHR.responseText);
	           }
			}, 
	    	complete:function(jqXHR, textStatus)
    		{  console.log(textStatus);
				if(textStatus==='success')
	        	{
					
				}           
			},
			timeout:96000
			});
}

function cambia(enti)
{
		var tipou=document.getElementById('tipou').value;
		var user=document.getElementById('user').value;
		$.ajax({
			cache:false,
			url:'vracces5.php',
			datatype: "text",
	    	async:false,
			type:'POST',
			data:{user:user,tipou:tipou}, 
	    	beforeSend: function(jqXHR, textStatus)
			{
			}, 
		
			success:function(dato, textStatus, jqXHR)
			{
				
				console.log(dato);
				if(tipo!='clie')
				{
					carga_acces(document.getElementById('user').value,'');
				}
			},
			error:function(jqXHR,textStatus,errorThrown )
			{
        	   if (jqXHR.status === 0) {
	              console.log('Not connect: Verify Network.');
	           } else if (jqXHR.status == 404) {
	               console.log('Requested page not found [404]');
    	       } else if (jqXHR.status == 500) {
	               console.log('Internal Server Error [500].');
    	       } else if (exception === 'parsererror') {
	               console.log('Requested JSON parse failed.');
	           } else if (exception === 'timeout') {
    			   alert('Servidor no Responde');
    	       } else if (exception === 'abort') {
	               console.log('Ajax request aborted.');
	           } else {
    	           console.log('Uncaught Error: ' + jqXHR.responseText);
	           }
			}, 
	    	complete:function(jqXHR, textStatus)
    		{  console.log(textStatus);
				if(textStatus==='success')
	        	{
					
				}           
			},
			timeout:96000
			});

}

<?php include('../../_js/busca_maes3.js');?>
<?php include('../../_js/lista_maes3.js');?>
<?php include('../../_js/fecha_format.js');?>
</script>

<style type="text/css">
body{ font-family:"Courier New", Courier, monospace;}
</style>
</head>

<body>
<div align="center" >
<div align="center"  ><?php include('../../_lib/cabecera2.php');?><div>
<table align="left" width="100%">
	<tr>
    	<td align="right"><input type="button" id="usrlbl" value="USUARIO:" onclick="list_carga('user','user','user_descri');" class="lst"   /> </td>
        <td><input type="text" id="user" onKeyDown="if(event.keyCode==13){user();}" placeholder="usuario"  /></td>
        <td align="left"><span id="user_descri" style="font-weight:bold; height:25px;" ></span></td>

    </tr>
	<tr>
    	<td align="right"><input type="button" value="MODULO:" onclick="modu();"  class="lst"  /> </td>
        <td><input type="text" id="modu" onKeyDown="if(event.keyCode==13){modu();}" placeholder="modulo"  /></td>
        <td align="left"><span id="modu_descri" ></span></td>
    </tr>
	<tr>
    	<td align="right"><input type="button" value="DOCUMENTO:" onclick="docu();"  class="lst"  /> </td>
        <td><input type="text" id="docu" onKeyDown="if(event.keyCode==13){docu();}" placeholder="documento"  /></td>
        <td align="left"><span id="docu_descri" ></span></td>
    </tr>
	<tr>
		<td></td>
        <td><div id="enti_tipo"></div></td>
	</tr>
	<tr>
		<td></td>
		<td></td>
		<td>
	<div id="acces_list"></div>
		</td>
	</tr>
</table>

	
</div>

	
	
<div style=" height:40px;">
	<div id="loader" style="display:none;">Procesando...</div>
</div>

<div id="entidoc_error"></div>

</div>
</div>

</body>
</html>