<?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(" exec saldoVehiculo '$ClienteID'");
				} else{
					$QueryCatalogo = mssql_query(" exec saldoVehiculo '$ClienteID'");
				} 
				$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;">
                <table width="910" border="0" cellspacing="0" cellpadding="0" align="center">
                  <tr class="header">
                    <th bgcolor="#46AD34" id="CelAzul" scope="col">&nbsp;</th>
                    <th bgcolor="#46AD34" id="CelAzul" scope="col">&nbsp;</th>
                    <th bgcolor="#46AD34" id="CelAzul" colspan="3" scope="col">Saldo</th>
                  
                    <th bgcolor="#46AD34" id="CelAzul" scope="col">&nbsp;</th>
                  </tr>
                </table>
                <table width="910" border="0" cellspacing="0" cellpadding="0" align="center" class="table" id="mt">
                  <tr class="header">
                    <th width="80" 	bgcolor="#46AD34" id="CelAzul" align="center">No. Flotilla</th>
					<th width="80" 	bgcolor="#46AD34" id="CelAzul" align="center">No. Economico</th>
                    <th width="230" bgcolor="#46AD34" id="CelAzul" align="left">Nombre</th>
                    <th width="90" 	bgcolor="#46AD34" id="CelAzul" align="center" title="Cargas Disponibles">Cargas Disponibles</th>
                    <th width="90" 	bgcolor="#46AD34" id="CelAzul" align="right" title="Saldo">Saldo</th>
					<th width="90" 	bgcolor="#46AD34" id="CelAzul" align="right" title="Pesos/Litros">Pesos/Litros</th>
                   
                    <th width="60" 	bgcolor="#46AD34" id="CelAzul" align="center"></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"><? echo $EvaluarCatalogo['VehiculoID']; ?></th>
					<th align="center"><? echo $EvaluarCatalogo['No_Economico']; ?></th>
                    <th align="left" ><?  echo utf8_encode(CortarPalabras($EvaluarCatalogo['NombreVehiculo'], 50)); ?></th>
                    <th align="center"><? echo  Number_Format($EvaluarCatalogo['CargasDisponibles'], 0); ?></th>
                    <th align="right"><? echo  Number_Format($EvaluarCatalogo['Saldo'], 2); ?></th>
					<th align="right"><? echo  $EvaluarCatalogo['Unidad']; ?></th>
                    
                    <th align="center"><? 
                    if($_SESSION['Administrador'] == 10)
                        echo "<a onclick=\"FlotillaLimite(".$EvaluarCatalogo['VehiculoID'].")\"><img src='images/edit.png' width='20' height='20' title='Editar Limite.'></a>"."\n"; 
                    else echo '';
                    ?></th>
                  </tr>  
                    <? 
                    }?>
                  <tr>
                      <th align="center" bgcolor="#2FA600">&nbsp;</th>
                      <th align="left" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="right" bgcolor="#2FA600">&nbsp;</th>
                      <th align="center" bgcolor="#2FA600">&nbsp;</th>
                  </tr>
                </table>
                <div id="green" style="margin: auto;" >
                </div>
			</div>
<?			}else	echo 'error2';
		}else echo $Bandera;  
	} else echo 'error1';
}	?>