<?php
require ('Conexion/Conexion.php');
require ('lib/lib.php');
$url="http://".$_SERVER['HTTP_HOST'].":".$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
$LoteID = $_GET['LoteCuponID'];

$Bandera = 1;
$Bandera2=1;


	
if(!isset($_SESSION['WEB2']) || extension($url) == 'php'){	
	echo "<script language='JavaScript'>location.href = 'index.php'</script>";
	die();
} else{
	
	
	
	Inactividad();
	$Tipo='pdf';
	$Formato='pdf';
	$LoteCuponID=$_GET['LoteCuponID'] ;
	$Cliente=$_SESSION['ClienteID'];
	//$Cliente=4259;
	//$LoteCuponID=885;
	//$NombreArchivo='Vales';
	$NombreArchivo=$_SESSION['NombreArchivo'];
	//$Nombre = $_SESSION['NombreArchivo'];
		
				
	
			$TipoReporte = 1;
			$ReporteNombre = 'IMPRIMIR CUPONES WEB';
			
			
			if($Bandera2 == 1){	
			
						
				
				
						
					$SoapURL = "http://".$_SESSION['CistemWebIP'].":9005/SOAP?service=ServiceWEB";
							$Client = new SoapClient($SoapURL,
						array('compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
							  'exceptions' => true));						  
					$GasolineroID = $_SESSION['GasolineroID'];
					$RutaReportes = $_SESSION['RutaReportes'];
					//$GasolineroID = 9001;
					//$RutaReportes = "'C:\'";
					
					//$Parametros = 'ClienteINI="'.$_SESSION['ClienteID'].'",ClienteFIN="'.$_SESSION['ClienteID'].'",Seleccion="'.$LoteCuponID.'"';
					$Parametros = 'ClienteINI="'.$Cliente.'",Seleccion="'.$LoteCuponID.'"';
					
					$A = $Client->Imprimir($ReporteNombre, $GasolineroID, $Parametros, $RutaReportes, $Formato);
					
					/*echo $Parametros;
					echo '-';
					echo $ReporteNombre;
					echo '-';
					echo $Formato;*/
					//print_r($A);
					//die();
					if($A->Ruta == '' && $A->Error == '')
						echo "<p class='success'>El Reporte consultado no contiene datos!</p>";
					elseif($A->Ruta != ''){
						$Tipo = extension($A->Ruta);
						$_SESSION['NombreArchivo'] = Nombre($A->Ruta);
						$Nombre = $_SESSION['NombreArchivo'];
						
						$Nombre = 'Reportes/'.$Nombre;
						//$Nombre = 'Reportes/22082017163249508.pdf';
						header('Content-type: application/pdf');
						header('Content-Disposition: attachment; filename="'.$Nombre.'"');
						header('Content-Length: '.filesize($Nombre));
						readfile($Nombre);
						

						if($Tipo == 'pdf')
						echo 'PDF';
						elseif($Tipo == 'xls')
							echo 'XLS';
						elseif($Tipo == 'xml')
							echo 'XML';
						else
							echo "<p class='success'>El Tipo de Reporte es desconocido. Comuniquese con el Administrador!</p>";
					} else
						//echo "<p class='error'>Error en la consulta del Reporte, Comuniquese con el Administrador!</p>"
						//echo "$RutaReportes" + "$GasolineroID";
						echo $ReporteNombre  . " <td></td>". $GasolineroID . " <td></td>" . $Parametros . " <td></td>" . $RutaReportes ." <td></td>" .$Nombre;		
						//$Bandera2=0;
				}else
					echo $Bandera;
				
			
		
			
	
	
	


	
?>
<script type="text/javascript" src="JQuery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="JQuery/jquery.blockUI.js"></script>
<link type="text/css" href="JQuery/css/custom-theme/jquery-ui-1.8.17.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="JQuery/jquery-ui-1.8.17.custom.min.js"></script>
<script type="text/javascript" src="JQuery/development-bundle/ui/jquery.ui.dialog.js"></script>
<script>


	
	


</script>
<style type="text/css">



body {
    background-color: #edffe2;
	font-family:Arial, Helvetica, sans-serif;
	font-size:11px;
	background-image:url("images/Form.png");
	background-repeat: no-repeat;
	background-position: top;
}

body,td,th {
	font-size: 11px;
	color: #000;
}
b{
	font-size:13px;
	color: #004000;
}
.requisites{  
    padding: 0 2px 0 2px;  
}  
.requisites.error2{  
    text-decoration: underline;
	font-size:11px;  
    color: #FF0000;
}  
.success {
	color: #060;
	font-size: 12px;
}
.error {
	color: red;
	font-size: 12px;
}
#Titulo {
	font-family: Georgia, "Times New Roman", Times, serif;
	font-size: 16px;
	font-weight: bold;
	color: #0054A8;
}
input.txt{
	width: 150px;
	padding: 5px;
	padding-left: 25px;
	background-repeat: no-repeat;
	background-position: 0% 50%;
}
input:focus{
	background-color:#d9f0a3;
}
input.error2{
	border-color: #F00;
}
input.text.active{
	background: #343434 url(img/search.png) no-repeat scroll right -43px;
	border-color: #000;
	color: #fff;
}
#edtNombre{
	background-image: url(images/Nombre.png);
}
#edtPassword1, #edtPassword2{
	background-image: url(images/Password.png);
}
#edtIdentificacion{
	background-image: url(images/Departamento.png);
}
#edtDespachos{
	background-image: url(images/Permisos.png);
}
#edtFlotillaID{
	background-image: url(images/No.png);
}
#edtFecha{
	background-image: url(images/Calendario.png);
}
.submit {
   border-top: 1px solid #02822f;
   background: #74d665;
   background: -webkit-gradient(linear, left top, left bottom, from(#64bf52), to(#74d665));
   background: -webkit-linear-gradient(top, #64bf52, #74d665);
   background: -moz-linear-gradient(top, #64bf52, #74d665);
   background: -ms-linear-gradient(top, #64bf52, #74d665);
   background: -o-linear-gradient(top, #64bf52, #74d665);
   padding: 5px 10px;
   -webkit-border-radius: 8px;
   -moz-border-radius: 8px;
   border-radius: 8px;
   -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
   -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
   box-shadow: rgba(0,0,0,1) 0 1px 0;
   text-shadow: rgba(0,0,0,.4) 0 1px 0;
   color: #ffffff;
   font-size: 14px;
   font-family: Georgia, serif;
   text-decoration: none;
   vertical-align: middle;
   }
.submit:hover {
   border-top-color: #357828;
   background: #357828;
   color: #fafafa;
   }
.submit:active {
   border-top-color: #07ab38;
   background: #07ab38;
}
select{
	width:150px;
	height:28px;
	padding: 5px;
}
</style>
<form id="ImpCupones" name="ImpCupones" action= "PrecesarImpCupones.php?LoteCuponID='+$LoteCuponID" method="post">

 

  <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td align="left"><table width="500" height="500" border="0" cellspacing="0" cellpadding="0" align="center" valign="middle" >
      <tr>
       
      </tr>
      <tr>
        <td id="Titulo" colspan="3" align="center">Impresion de Vales </td> 
      </tr>
      <tr>
        <td width="46">&nbsp;</td>
        <td width="254">&nbsp;</td>
        <td width="200">&nbsp;</td>

		
      </tr>
      <tr>
        <td colspan="3">&nbsp;</td>
      </tr>
	  
      <tr>
        <td>&nbsp;</td>
        <td align="left">&nbsp;</td>
        <td align="left"><b><span id="req-Status" class="requisites error"></span></b></td>
      </tr>
      <tr>
        <td colspan="3" align="center">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="3" align="center"><input class="submit" type="submit" id="submit" value="Imprimir Vales" title="Imprimir Vales." tabindex="9" <? if($Bandera != 1) echo "disabled= 'disabled'"; else "disabled= 'enabled'"; ?>/></td>
      </tr>
      <tr>
        <td colspan="3" align="center"><b><? if($_SESSION['Administrador'] == 1){ ?>
          <div id="message"></div>
          <? }else{?>
          <div id="message" class="error">Usted no tiene privilegios para Imprimir Vales!</div>
          <? } ?></b></td>
        <td width="1"></td>
      </tr>
      <tr>
        <td colspan="3" align="center">&nbsp;</td>
        <td></td>
      </tr>
    </table></td>
  </tr>
  </table>
</form>
<? } ?>