<?php
 @session_start();
  $vg_login=$_SESSION["usuario"];
   $vg_empresa=$_SESSION["empresa"];
  if($vg_login<>""){}
 else
  {echo "<script>";
   echo "window.location='../index.php';";
   echo "</script>";
  }	

include "../valida_permisos.php";
$vg_programa = F_programa();
include "../seguridad.php";
$sql_entrada= mysqli_query($conseg,"select login,nombre,perfil,programa,cedula,pais from permiso     
						where login='".$vg_login."'  and programa=".$vg_programa."");
while($datos= mysqli_fetch_row($sql_entrada))
		{ $vg_nombre=$datos[1];
		  $vg_perfil=$datos[2];				
		} 
//permisos a formularios
$modulo="Parametros_empresa";
$permisos=validar_permiso($vg_login,$modulo,$vg_perfil,$vg_programa);
include "../permisos.php";
$valpermiso=F_permiso($permisos);

if($valpermiso[0]==1){}
else
{echo "<script>";
echo "window.location='../erroracceso.php?formulario=Parametros_Empresa';";
echo "</script>";
}

?>
<!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 $nombreprograma." - ".$version; ?></title>
  <script src="../js/jquery.min.js"></script>
  <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet">
 <script src="../bootstrap/js/bootstrap.min.js"></script>
 <link rel="stylesheet" href="../toastn/style.css">
 <script src="../toastn/cute-alert.js"></script>
 
 
</head>
<body>
<?php
$tercero=$_REQUEST["tercero"];
include "../conexion.php";
						  
if(isset($_REQUEST["oculto"]))
{ 
		
		if($_REQUEST["oguardar"]==1)
		  {   
				$c=1; $canti=$_REQUEST['cantir'];
				while($c<=$canti)
				{  
					if(isset($_REQUEST['ch'.$c])) {$val=1; }  else {$val=0;} 
					$id=$_REQUEST['id'.$c];
					$sql_datoscanti =mysqli_query( $conexion,"delete from  tercero_fiscal
															  where empresa='".$vg_empresa."' and tercero='".$tercero."' and fiscal='".$id."'");
															   
														
					if($val==1)
					  {  
						$sql_insert=mysqli_query($conexion,"insert into tercero_fiscal (empresa,tercero,fiscal)
															values ('".$vg_empresa."','".$tercero."','".$id."')"); 
					  }
					$c=$c+1;
		        }//fin cliclo	  
		 }//fin guardar


}


?>
<form name="parametros" method="post" action="" >
<div align="center">
    <div class="panel panel-primary" >
       <div align="center">
				  <table width="100%" border="0" cellspacing="0" cellpadding="0"  >
                    <tr> 
                      <td width="600"><div align="center">
                        <input name="guardar" type="submit"  id="guardar"  value="Guardar/Modificar" onClick="oguardar.value=1;" class="btn btn-primary" />
                          <br>
                          <input name="oguardar" type="hidden" id="oguardar">
                          <input name="oculto" type="hidden" id="oculto">
                        </div></td>
                    </tr>
                  </table>
     
     
<?php
 echo "<center><table  border='1' cellspacing='0' cellpadding='0' class='table table-hover' style='width:400px;'> \n";
	   echo "<tr>
				<td width='20%' class='btn-primary'><center><font color='#FFFFFF'>FISCAL</font></center></td>
				<td width='5%' class='btn-primary'><center><font color='#FFFFFF'></font></center></td>
			</tr>";
 $c=1;			
  $sql_datos =mysqli_query($conexion,"select id,nombre from par_fiscal order by nombre asc");
  while($datoslog= mysqli_fetch_row($sql_datos))//01
  {
	  $id=$datoslog[0];
	  $nombre=$datoslog[1];
	  
	  $sql_contar=mysqli_query($conexion,"SELECT count(*) FROM tercero_fiscal 
	  									  where empresa='".$vg_empresa."' and tercero='".$tercero."' and fiscal='".$id."'");
	  while($datoscontar= mysqli_fetch_row($sql_contar)){ $contar=$datoscontar[0];}
	  if($contar>=1){$checked="checked"; } else { $checked=""; } 
	  
	echo "<tr>
			<td >$nombre</td>
			<td align='center'>
			<input name='id$c' type='hidden' id='id$c'  value='$id'>
			<input type='checkbox' name='ch$c' style='width: 15px' $checked ></td>
		</tr>";
	
	$c++;
  }
 echo "</table></center>";

 $canti=$c-1;
 echo "<input type='hidden' name='cantir' value='$canti' readonly size='10'>";	

?>
           
</div>
</div>	

</form>

</body>
</html>