<?php
require_once ('../librerias/dompdf/autoload.inc.php');
use Dompdf\Dompdf;

$url2 = 'http://200.24.13.60/~program1/power-time-api/public/obtenercargo';
$ch2 = curl_init($url2); //create a new cURL resource
$payload2 = json_encode(array('id' => $_POST["txtCargo"]));
curl_setopt($ch2, CURLOPT_POSTFIELDS, $payload2);//attach encoded JSON string to the POST fields
curl_setopt($ch2, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result2 = curl_exec($ch2); //execute the POST request
$array2 = json_decode($result2);

$cargo = $array2[0]->descripcion;

curl_close($ch2);



$ch4 = curl_init('http://200.24.13.60/~program1/power-time-api/public/buscarcargopermiso'); //create a new cURL resource
$payload4 = json_encode(array('id_cargo' => $_POST["txtCargo"]));
curl_setopt($ch4, CURLOPT_POSTFIELDS, $payload4);//attach encoded JSON string to the POST fields
curl_setopt($ch4, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); //set the content type to application/json
curl_setopt($ch4, CURLOPT_RETURNTRANSFER, true); //return response instead of outputting
$result4 = curl_exec($ch4); //execute the POST request
$array4 = json_decode($result4);

$permisoHTML = "";				
foreach ($array4[0] as $row) {
	$permisoHTML .= "<tr>";			
	$permisoHTML .= "<td>".UTF8_DECODE($row->tipopermiso) ."</td>";		
	$permisoHTML .= "</tr>";		
}
 		 

curl_close($ch4); 	
			

				
$html = '
<style>
body{
	font-size:10px;
}
h3{
	font-size:20px;
	display:inline;
}
h4{
	font-size:14px;
	display:inline;	
}
.tbl-marcaje th {
  color: #000000;
  background-color: #CCCCCC;
  border:solid 1px #000000;
}
.tbl-marcaje td {
	border:solid 1px #000000;
}

</style>
<div>
	<img style="max-height:50px;" src="../img/002.png" />
</div> 
<table width="100%">
	<tr>
		<td><b>COMPA&Ntilde;IA :</b> CORP MUNICIPAL PARA EL DESARROLLO SOCIAL</td>			
	</tr>
	<tr>		
		<td><b>RUT :</b> 70.983.600-5</td>			
	</tr>	
</table><br /> 

		
<center><h3>Reporte De Permisos por Cargo</h3></center>
<br /> 	
<h4>Descripci&oacute;n de Cargo:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th><b>CARGO </b></th>		
	</tr>
	<tr>
		<td>'.$cargo.'</td>			
	</tr>			
</table>  
<br /> 	
<h4>Listado de Permisos Asociados a Cargo:</h4>
<table class="tbl-marcaje" width="100%">
	<tr>
		<th><b>PERMISO </b></th>			
	</tr>
	'.$permisoHTML.'		
		
</table>  



';

$pdf = new DOMPDF();
$pdf->set_paper("A4", "portrait");
$pdf->load_html(utf8_encode($html));
$pdf->render();
$pdf->stream("marcajes.pdf", array("Attachment" => false));
exit(0);

?>
