<?php
require ("Conexion/Conexion.php");
require ("lib/lib.php");
if(!isset($_SESSION['WEB2'])){	
	echo "<script language='JavaScript'>location.href = 'index.php'</script>";
	die();
} else{
	Inactividad(); 
	if($_POST['Opcion'] != '' || $_GET['Opcion'] != ''){
		$ClienteID = $_SESSION["ClienteID"];
		if($_POST['Opcion'] != '') {
			if(preg_match("/^[[:digit:]]+$/", $_POST['Opcion'])){
				$Opcion = $_POST['Opcion'];
				$Bandera = 1;
			}else
				$Bandera = 'error2';
		} 	
		if($Bandera == 1){
			if($Opcion == 1) {
				if($_SESSION["Admin"] == 1){
					$QueryCatalogo = mssql_query("SELECT VE.LotecuponID, VE.Fecha, VE.Total, VE.Status, 
					 SW.NombreSeccion FROM Lotecupon VE
					INNER JOIN Cliente on cliente.clienteid=VE.clienteid						 
					 inner JOIN SeccionWeb SW ON cliente.SeccionWebID = SW.SeccionWebID 
					 WHERE VE.ClienteID = '$ClienteID' and VE.Impreso='False' ORDER BY VE.LoteCuponID DESC");
				} else{
					$QueryCatalogo = mssql_query("SELECT VE.LotecuponID, VE.Fecha, VE.Total, VE.Status, 
					 SW.NombreSeccion FROM Lotecupon VE
					INNER JOIN Cliente on cliente.clienteid=VE.clienteid					 
					 inner JOIN SeccionWeb SW ON Cliente.SeccionWebID = SW.SeccionWebID 
					 WHERE VE.ClienteID = '$ClienteID' AND SW.SeccionWebID = ".$_SESSION['SeccionWebID']." and VE.Impreso='False' ORDER BY VE.LoteCuponID DESC");
				} 
				$TotalRegistros = mssql_num_rows($QueryCatalogo);?>
                <script>
                $(document).ready(function(){
					$('#green').smartpaginator({ 
						totalrecords: 		<? echo $TotalRegistros; ?>, 
						recordsperpage: 	20, 
						datacontainer: 		'mt', 
						dataelement: 		'tr', 
						initval: 			0, 
						next: 				'Sig', 
						prev: 				'Ant', 
						first: 				'Prim', 
						last: 				'Ult', 
						theme: 				'green' 
					});
				});
                </script>
    			<div id="green-contents" class="contents" style="border: solid 1px #5f9000;">
				<form id="ImpCupones" name="ImpCupones" action= "ProcesarImpCupones.php" method="post">
				
				
                <table align="center" width="910" border="0" cellspacing="0" cellpadding="0" class="table" id="mt">
                	<tr height="30" class="header">
						<th width="65" 	align="center" 	bgcolor="#46AD34" id="CelAzul" scope="col" >No. Lote</th>
						<th width="145" align="left" 	bgcolor="#46AD34" id="CelAzul" scope="col"></th>
                   	    <th width="185" align="left" 	bgcolor="#46AD34" id="CelAzul" scope="col"></th>
                        <th width="40" 	align="center"  bgcolor="#46AD34" id="CelAzul" scope="col"></th>
                        <th width="75" 	align="center" 	bgcolor="#46AD34" id="CelAzul" scope="col">Status</th>
                        <th width="115" align="center" 	bgcolor="#46AD34" id="CelAzul" scope="col">Total</th>
                        <th width="120" align="left" 	bgcolor="#46AD34" id="CelAzul" scope="col">Fecha Registro</th>
                        <th width="80" align="center" 	bgcolor="#46AD34" id="CelAzul" scope="col">Editar</th>
                        <th width="80" 	align="center" 	bgcolor="#46AD34" id="CelAzul" scope="col"></th>
                   </tr>
                      <?					
                        while ($EvaluarCatalogo = mssql_fetch_array($QueryCatalogo)) {
							if ($colorfila == 0) {
								$color = "trlight";	
								$colorfila = 1;
							}else{
								$color = "trblue";
								$colorfila = 0;	
							}
							echo"<tr id='$color'>"; ?> 
						
                        <th align="center"  scope="row"><? echo $EvaluarCatalogo['LotecuponID']; ?></th>
						
						<th></th>
						<th></th>
						<th></th>
						
                        <th align="center" title="<? if($EvaluarCatalogo['Status'] == 'A') echo 'Activo'; elseif($EvaluarCatalogo['Status'] == 'I') echo 'Inactivo'; elseif($EvaluarCatalogo['Status'] == 'C') echo 'Cancelado'; ?>" ><? echo $EvaluarCatalogo['Status']; ?></th>
						<th align="center"><? echo $EvaluarCatalogo['Total']; ?></th>
                        <th align="right"><? echo $EvaluarCatalogo['Fecha']; ?></th>
                        <th align="center">
						<th><input src='images/edit.png' width='20' height='20' title='Imprimir Vales.' class='submit' type='image' id='submit'  name="LoteCuponID" value=" <?echo $EvaluarCatalogo['LotecuponID'];?>"> </th>
						<th></th>
                      </tr>  
                        <? 
                        }?>
                      <tr>
                        <th align="center" 	bgcolor="#46AD34" scope="row">&nbsp;</th>
                        <th align="left" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="left" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="center" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="center" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="center" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="center" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="right" 	bgcolor="#46AD34">&nbsp;</th>
                        <th align="center" 	bgcolor="#46AD34">&nbsp;</th>
                  </tr>
				  <??>
                </table>
				
				</form>
                <div id="green" style="margin: auto;" >
                </div>
            </div>
<?			}else	echo 'error2';
		}else	echo $Bandera;
	}else	echo 'error1';
} ?>