<?php 
session_start();   
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
if(!array_key_exists("la_logusr",$_SESSION))
{
	print "<script language=JavaScript>";
	print "close();";		
	print "</script>";		
}
//ini_set('memory_limit','2048M');
//ini_set('max_execution_time','0');

function error($tipo){

		switch($tipo){				
			case 'tamaño_fila':
				$mensaje = 'ERROR DE TABLA: El tamaño de la fila es mas grande que el de la página.';
				break;		
		}
		
		 print "<script language=JavaScript>";
		 print "alert('".$mensaje."');";
		 print "close();";		
		 print "</script>";	
		 exit();

}

function columna($id,$dato,$prop,$textalign='L',$valign='T'){
	
	global $pdf,$margen_tabla,$ancho,$altura;
	// MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0, $valign='T', $fitcell=false,opciones_adicionales)
	$pdf->MultiCell($ancho[$id], $prop['alturamaxima'], utf8_encode($dato), 1, $textalign, 1, 0, '', '', true, 0, true, false, 0, $valign,false,$prop);
	if($pdf->saltopag){return false;}
	$altura[$id]=$pdf->altura_celda;
	
	return $altura;

}

function procesar_fila($datos){
		
		global $pdf,$margen_tabla,$ancho;
		
		$altura_pagina = $pdf->getPageHeight();
		$prop['alturamaxima']=3;
		$prop['check_pagebreak']=0;
		
		$pdf->startMultipleTransaction();								
		$prop['alturamaxima'] = fila($datos,$prop);
		if($prop['alturamaxima']>$altura_pagina){error('tamaño_fila');}
		$salto = $pdf->saltopag;									
		$pdf = $pdf->rollbackMultipleTransaction();
						
		if($salto){
			$pdf->AddPage();
			encabezado();
			$pdf->startMultipleTransaction();											
			$prop['alturamaxima'] = fila($datos,$prop);													
			$pdf = $pdf->rollbackMultipleTransaction();
			$salto = 0;		
		}
		
		
		$pdf->startMultipleTransaction();
		$pagina = $pdf->getPage();
		
		fila($datos,$prop);
		
		$pagina2 = $pdf->getPage();				
		if($pagina!=$pagina2){
			
				$pdf = $pdf->rollbackMultipleTransaction();									
				$pdf->AddPage();
				encabezado();
				fila($datos,$prop);											
		}	
		else{					  
														
				$pdf->commitMultipleTransaction();
		} 

}

$ruta = '../../';
require_once("../clases/covensol_fop_c_formulacion.php");
$objfop=new covensol_fop_c_formulacion($propiedades);
$objfop->cargar_seguridad("FOP","covensol_fop_r_resumen.php");

$fecha_actual = date("d/m/Y");

if(!$_GET['anopresup'] or !$_GET['estcla'] or !$_GET['codestpro1'] or !$_GET['denestpro1']){

		print "<script language=JavaScript>";
		echo "alert('ERROR: Faltan datos para generar el reporte');";
		print "close();";		
		print "</script>";
		exit();
}

if($_GET['tiporep']=='fases' and (!$_GET['anopresup'] or !$_GET['estcla'] or !$_GET['codestpro1'] or !$_GET['denestpro1'] or !$_GET['nroh'])){

		print "<script language=JavaScript>";
		echo "alert('ERROR: Faltan datos para generar el reporte de fase');";
		print "close();";		
		print "</script>";
		exit();
}

$param = $_GET;		
$param['criterio']='por_codigo';

require_once('../../shared/tcpdf_new/config/lang/ita.php');
require_once('../../shared/tcpdf_new/tcpdf_rep.php');  

$parametros = array();
//$objfop->io_conexiones->decodificar_get();
$parametros = $objfop->io_conexiones->asignar_get();

$datos_encabezado = '<p  style="text-align:rigth;"><b> '.'FECHA Y HORA: </b>'.date('d/m/Y').' - '.date('H:i').'<br/><b>USUARIO: </b>'.$_SESSION["la_logusr"].'</p>';

$pdf = new TCPDFREP('LANDSCAPE', PDF_UNIT, 'LETTER', true, 'UTF-8', false);
$pdf->SetMargins(PDF_MARGIN_LEFT, 15, PDF_MARGIN_RIGHT);
$pdf->setHeaderFont(array('', '', 8));
$pdf->ancho_logo = $_SESSION["ls_width"]*0.3;
$pdf->alto_logo = $_SESSION["ls_height"]*0.3;
$pdf->SetHeaderData('../../shared/imagebank/'.$_SESSION["ls_logo"], $_SESSION["ls_width"], '', $datos_encabezado);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);		
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, 20);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setPrintHeader(true);
//$pdf->setTextoFooter(utf8_encode(''));

$pdf->AddPage();
$pdf->Ln();
$pdf->SetLineStyle(array('width' => 0.1, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(200, 200, 200))); 


$objfop->RepParam['ancho'][1] = 120;
$objfop->RepParam['ancho'][2] = 65;
$objfop->RepParam['ancho'][3] = 50;
$objfop->RepParam['ancho'][4] = 80;
$objfop->RepParam['ancho'][5] = 50;
$objfop->RepParam['ancho'][6] = 50;
$objfop->RepParam['ancho'][7] = 50;
$objfop->RepParam['ancho'][8] = 50;
$objfop->RepParam['ancho'][9] = 50;
$objfop->RepParam['ancho'][10] = 65;
$objfop->RepParam['ancho'][11] = 65;
$objfop->RepParam['ancho'][12] = 65;
$objfop->RepParam['ancho'][13] = 65;
$objfop->RepParam['ancho'][14] = 65;

$objfop->RepParam['ancho']['total'] = array_sum($objfop->RepParam['ancho']);
$objfop->RepParam['encabezado']['color_fondo'] = '#000066';
$objfop->RepParam['encabezado']['color_letra'] = '#FFFFFF';
$objfop->RepParam['encabezado']['tamaño'] = 6;
$objfop->RepParam['encabezado2']['color_fondo'] = '#E8F3FD';
$objfop->RepParam['encabezado2']['color_letra'] = '#000000';
$objfop->RepParam['fila']['color_fondo'] = '#FFFFFF';
$objfop->RepParam['fila']['color_letra'] = '#000000';
$objfop->RepParam['fila']['tamaño'] = 6;
$objfop->RepParam['fila']['color_fondo_subtot'] = '#DDDDDD';
$objfop->RepParam['fila']['color_fondo_tot'] = '#DDDDAA';


$paramrep=array();
$paramrep['color_tit']="#FFFFFF";
$paramrep['color_dato']="#000000";
$paramrep['color_etiqueta']="#000055";
$paramrep['fondo_tit']="#000066";

$paramrep['fondo_dato']="#E8F3FD";
$paramrep['ancho_etiqueta']="150";
$paramrep['ancho_dato']=$objfop->RepParam['ancho']['total']-150;
$paramrep['tamano_letra']="10";
$paramrep['ancho_tit']=$objfop->RepParam['ancho']['total'];

$paramrep['ancho_etiqueta_numcor']="440";
$paramrep['ancho_dato_numcor']="110";
$paramrep['tamano_letra_numcor']="8";
$paramrep['color_numcor']="#0000AA";
$paramrep['color_etiqueta_numcor']="#000000";
$paramrep['fondo_numcor']="#FFFFFF";

$ancho_firma = $objfop->RepParam['ancho']['total']/3;


function datos_resumen($parametro=array()){		
			
	global $paramrep,$datos,$objfop,$parametros;
	$tabla="";
	
	$datosenc = $objfop->FormatLonCodEstPro($parametros);
	
	$tabla = '<table cellspacing="0" cellpadding="1" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_tit'].'" color="'.$paramrep['color_tit'].'" height="12">
								<td align="center" width="'.$paramrep['ancho_tit'].'"><font size="12"><b> REPORTE DE ACTIVIDADES </b></font></td>									
							</tr>
						</thead>
				</table>';			
	
	$tabla = $tabla.'<table cellspacing="0" cellpadding="2" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_dato'].'" color="'.$paramrep['color_dato'].'" height="6">
								<td align="right" width="'.$paramrep['ancho_etiqueta'].'" color="'.$paramrep['color_etiqueta'].'"><font size="'.$paramrep['tamano_letra'].'"><b> AÑO: </b></font></td>
								<td align="left"  width="'.$paramrep['ancho_dato'].'"><font size="'.$paramrep['tamano_letra'].'"> '.$datosenc['anopresup'].' </font></td>																							
							</tr>
						</thead>
				</table>';
	
	if($parametros['denhist']){
	$tabla = $tabla.'<table cellspacing="0" cellpadding="2" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_dato'].'" color="'.$paramrep['color_dato'].'" height="6">
								<td align="right" width="'.$paramrep['ancho_etiqueta'].'" color="'.$paramrep['color_etiqueta'].'"><font size="'.$paramrep['tamano_letra'].'"><b> Fase: </b></font></td>
								<td align="left"  width="'.$paramrep['ancho_dato'].'"><font size="'.$paramrep['tamano_letra'].'"> ('.$parametros['abvrhist'].') - '.$parametros['denhist'].' </font></td>																							
							</tr>
						</thead>
				</table>';
	}
	
	if(!$datosenc['codestpro1']){return $tabla;}
								
	$tabla = $tabla.'<table cellspacing="0" cellpadding="2" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_dato'].'" color="'.$paramrep['color_dato'].'" height="6">
								<td align="right" width="'.$paramrep['ancho_etiqueta'].'" color="'.$paramrep['color_etiqueta'].'"><font size="'.$paramrep['tamano_letra'].'"><b> Estructura (ep1): </b></font></td>
								<td align="left"  width="'.$paramrep['ancho_dato'].'"><font size="'.$paramrep['tamano_letra'].'"> '.$datosenc['codestpro1'].' - '.$datosenc['denestpro1'].' </font></td>																							
							</tr>
						</thead>
				</table>';
	
	if(!$datosenc['codestpro2']){return $tabla;}
	
	$tabla = $tabla.'<table cellspacing="0" cellpadding="2" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_dato'].'" color="'.$paramrep['color_dato'].'" height="6">
								<td align="right" width="'.$paramrep['ancho_etiqueta'].'" color="'.$paramrep['color_etiqueta'].'"><font size="'.$paramrep['tamano_letra'].'"><b> Estructura (ep2): </b></font></td>
								<td align="left"  width="'.$paramrep['ancho_dato'].'"><font size="'.$paramrep['tamano_letra'].'"> '.$datosenc['codestpro2'].' - '.$datosenc['denestpro2'].' </font></td>																							
							</tr>
						</thead>
				</table>';
	
	
	if(!$datosenc['codestpro3']){return $tabla;}
	$tabla = $tabla.'<table cellspacing="0" cellpadding="2" border="1">
						<thead>
							<tr bgcolor="'.$paramrep['fondo_dato'].'" color="'.$paramrep['color_dato'].'" height="6">
								<td align="right" width="'.$paramrep['ancho_etiqueta'].'" color="'.$paramrep['color_etiqueta'].'"><font size="'.$paramrep['tamano_letra'].'"><b> Estructura (ep3): </b></font></td>
								<td align="left"  width="'.$paramrep['ancho_dato'].'"><font size="'.$paramrep['tamano_letra'].'"> '.$datosenc['codestpro3'].' - '.$datosenc['denestpro3'].' </font></td>																							
							</tr>
						</thead>
				</table>';
	
																				
	return $tabla; 
}

$y_actual = $pdf->GetY();

$FirmaSello = '<table cellspacing="0" cellpadding="3" border="1">
				  <tr bgcolor="#E8F3FD">					
					<td  align="center" width="'.$ancho_firma.'"><font size="8">ELABORADO</font></td>
					<td  align="center" width="'.$ancho_firma.'"><font size="8">VERIFICADO</font></td>
					<td align="center" width="'.$ancho_firma.'"><font size="8">AUTORIZADO</font></td>
				  </tr>
				  <tr>
					<td height="65" align="center">					   
					</td>
					<td>					
					</td>
					<td>					
					</td>
				  </tr>				 
				</table>';




$pdf->writeHTML(utf8_encode(datos_resumen()), true, false, false, false, '');

$pdf->Ln();
$InfoSpg = $objfop->RepDetalleActiv($parametros);
$pdf->writeHTML(utf8_encode($InfoSpg), true, false, false, false, '');
$pdf->Ln();	
//$pdf->Ln();	
			
$y = $pdf->GetY();

if($y>170){$pdf->AddPage();}
$pdf->SetY(170);
$pdf->SetLineStyle(array('width' => 0.85 / $pdf->getScaleFactor(), 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(0, 0, 0)));
$pdf->writeHTML(utf8_encode($FirmaSello), true, false, false, false, '');

$pdf->Output('reporte_actividades_'.date('dmY').'.pdf', 'I');

?>