<?php
ob_start();
include('header.php');
$configuracion= new configuracion();
if(isset($_POST['llega']) && $_POST['llega']=='SI'){
$roles="";
if($_POST['id_perfil']!=''){
if(isset($_POST['p1'])){$roles=$roles.$_POST['p1'];}
if(isset($_POST['p2'])){$roles=$roles.$_POST['p2'];}
if(isset($_POST['p3'])){$roles=$roles.$_POST['p3'];}
if(isset($_POST['p4'])){$roles=$roles.$_POST['p4'];}
if(isset($_POST['p5'])){$roles=$roles.$_POST['p5'];}
if(isset($_POST['p6'])){$roles=$roles.$_POST['p6'];}
$configuracion->actPerfil($_POST['id_perfil'],$_POST['nombre_perfil'],$roles);
}else{
if(isset($_POST['p1'])){$roles=$roles.$_POST['p1'];}
if(isset($_POST['p2'])){$roles=$roles.$_POST['p2'];}
if(isset($_POST['p3'])){$roles=$roles.$_POST['p3'];}
if(isset($_POST['p4'])){$roles=$roles.$_POST['p4'];}
if(isset($_POST['p5'])){$roles=$roles.$_POST['p5'];}
if(isset($_POST['p6'])){$roles=$roles.$_POST['p6'];}
$configuracion->creaPerfil($_POST['nombre_perfil'],$roles);
}
//header("Location: configuracion_perfiles.php");
}
$getpelfiles=$configuracion->getPerfiles();
$getpelfilesUsuarios=$configuracion->getPerfilesUsuarios();
?>
<div class="row contenido">
<div class="col-md-6">
<form name="perfilfrm" id="perfilfrm" method="POST">
<input type="hidden" name="llega" value="SI">
<label>Nombre Perfil</label>
<input type="text" name="nombre_perfil" class="form-control" ><br>
<button type="button" id="add_perfil" class="btn btn-primary"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Añadir Nuevo Perfil</button>
<button type="button" id="act_perfil" class="btn btn-primary"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Actualizar Perfil</button>
<button type="button" id="limp_perfil" class="btn btn-primary"><span class="glyphicon glyphicon-repeat" aria-hidden="true"></span> Limpiar</button>
</div>
<div class="col-md-6">
<input type="hidden" name="id_perfil" id="id_perfil" value="">
<label>Seleccione los modulos a los cuales podra acceder el perfil</label><br>
<div style="display:inline-block;vertical-align: top;">
<label><input class="get_check" type="checkbox" name="p1" value="Proveedores,">Proveedores</label><br>
<label><input class="get_check" type="checkbox" name="p2" value="Clientes,">Clientes</label><br>
<label><input class="get_check" type="checkbox" name="p3" value="Negocios,">Todos los Negocios</label><br>
<label><input class="get_check" type="checkbox" name="p4" value="SusNego,">Solo Sus Negocios</label><br>
</div>
<div style="display:inline-block;vertical-align: top;margin-left:10px;">
<label><input class="get_check" type="checkbox" name="p5" value="Tipos de cambio,">Tipos de cambio</label><br>
<label><input class="get_check" type="checkbox" name="p6" value="Administración,">Administración</label>
</div>
</form>
</div>
<div class="col-md-12">
</div>
<div class="col-md-12">
<table class="table table-bordered">
<thead>
<tr>
<td>ID</td>
<td>Nombre</td>
<td>Accesos</td>
<td>Borrar</td>
</tr>
</thead>
<tbody>
<?php
foreach($getpelfiles as $val){
$contar=0;
foreach($getpelfilesUsuarios as $value){
if($value['id_perfil']==$val['id']){
$contar++;
}
}
?>
<tr id="linea<?=$val['id']?>">
<td><?=$val['id']?></td>
<td><?=$val['nombre']?></td>
<td><?=$val['roles']?></td>
<td>
<?php
if($val['id']!=1){
echo '<a href="javascript:void(0)" onclick="edit_rol('.$val['id'].')"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a> ';
if($contar>0){
}else{
echo '<a href="javascript:void(0)" onclick="borrar_rol('.$val['id'].')"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>';
}
}
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
<?php include('footer.php');
ob_end_flush();?>