<?php
date_default_timezone_set("America/Mexico_City");
session_start();
include('conexion.php');	
//include('mysql_Valida_permiso.php');
function FechaFormateada($FechaStamp){
	$ano = date('Y',$FechaStamp); //<-- Año
	$mes = date('m',$FechaStamp); //<-- número de mes (01-31)
	$dia = date('d',$FechaStamp); //<-- Día del mes (1-31)
	$dialetra = date('w',$FechaStamp);  //Día de la semana(0-7)
	switch($dialetra)
	{
		case 0: $dialetra="Domingo"; break;
		case 1: $dialetra="Lunes"; break;
		case 2: $dialetra="Martes"; break;
		case 3: $dialetra="Miércoles"; break;
		case 4: $dialetra="Jueves"; break;
		case 5: $dialetra="Viernes"; break;
		case 6: $dialetra="Sábado"; break;
	}
	switch($mes) 
	{
		case '01': $mesletra="Enero"; break;
		case '02': $mesletra="Febrero"; break;
		case '03': $mesletra="Marzo"; break;
		case '04': $mesletra="Abril"; break;
		case '05': $mesletra="Mayo"; break;
		case '06': $mesletra="Junio"; break;
		case '07': $mesletra="Julio"; break;
		case '08': $mesletra="Agosto"; break;
		case '09': $mesletra="Septiembre"; break;
		case '10': $mesletra="Octubre"; break;
		case '11': $mesletra="Noviembre"; break;
		case '12': $mesletra="Diciembre"; break;	
	}    
	return "$dialetra, $dia de $mesletra de $ano";
}
if (isset($_SESSION['id_usuario']))
{
?>
<HTML>
<head>
	<meta http-equiv="Expires" content="0">
  <meta http-equiv="Last-Modified" content="0">
  <meta http-equiv="Cache-Control" content="no-cache, mustrevalidate">
  <meta http-equiv="Pragma" content="no-cache">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="shortcut icon" href="images/Sysmental.jpg" type="image/jpeg"/>
	<title>Flotillas</title>
	<link href="css/bootstrap.min.css" rel="stylesheet">
	<script src="//code.jquery.com/jquery-1.10.2.js"></script>
	<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>	
	<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
	<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script> 
	<!--alert-->
	<script src = "sweetalert-master/dist/sweetalert.min.js" ></script>  
	<link rel = "stylesheet" type = "text/css" href = "sweetalert-master/dist/sweetalert.css" >
</head>
<style>
fieldset.scheduler-border {
    border: 1px groove #ddd !important;
    padding-top: 0px;
    padding-right: 10px;
    padding-bottom: 10px;
    padding-left: 10px;
    margin: 0 0 1em 0 !important;
    -webkit-box-shadow:  0px 0px 0px 0px #000;
            box-shadow:  0px 0px 0px 0px #000;
}

    legend.scheduler-border {
        font-size: 1em !important;
        font-weight: bold !important;
        text-align: left !important;
        width:auto;     		
        border-bottom:none;
    }
</style>
	<input type="hidden" name="vartime" id="vartime" value="v">
<script type="text/javascript" src="js/funciones.js"></script>
<body>
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <img  src="images/Logo.jpg" width="130" align="left" style="border:outset" />	
    </div>
	<center style="width:auto;align:center;" valign="center">					
		<H1 style="color:white;font-weight: bold;">FLOTILLAS</H1>
	</center>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li><a style="font-weight: bold;font-size:20;" href="catalogo_vehiculos.php">Vehiculos</a></li>
		  <li ><a id="transac" style="font-weight: bold;font-size:20;display:<?php if($_SESSION['transacciones']==1){echo 'block';}else{ echo 'none';}?>" href="catalogo_transacciones.php">Transacciones</a></li> 
		  <li ><a id="fact" style="font-weight: bold;font-size:20;display:<?php if($_SESSION['facturas']==1){echo 'block';}else{ echo 'none';}?>" href="catalogo_facturas.php">Facturas</a></li> 
		<li><a style="font-weight: bold;font-size:20;" href="catalogo_consumos.php">Reportes</a></li> 		
	  </ul>      
      <ul class="nav navbar-nav navbar-right">
        <li><a style="font-weight: bold;font-size:20;pointer-events: none;cursor: default;color:white;" ><?php echo $_SESSION['id_usuario'];?></a></li>
        <li><a style="font-weight: bold;font-size:20;" href="logout.php">Salir</a></li>
      </ul>
    </div>
  </div>
</nav>
<table align="center" style="background-color:transparent;">
	<tr>
		<td>
			<center style="width:900px;align:center;background-color:transparent;" valign="center" id="Contenedor">
				<div class="panel panel-success" style="background-color:transparent;height:auto;width:900px;" >
					<div class="panel-heading" style="height:40px;">Vehiculos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php $fecha = time();  echo FechaFormateada($fecha). "  "; ?>
						
						</div>
					<div class="panel-body" >						
						<table style="width:auto;">   
							<tr>
								<td style="width:150px;font-weight: bold;">Cliente</td>
								<td style="width:350px;"><?php echo $_SESSION['id_cliente'];?></td>
								<td rowspan="3" style="width:60px;">
									<input style="display:<?php if($_SESSION['vehiculos_alta']==1){echo 'block';}else{ echo 'none';}?> " type="button" id="btnagregar" onclick="alta()" class="btn btn-default" value="Crear"/>
								</td>
								<td rowspan="3" style="width:60px;">
									<input style="display:<?php if($_SESSION['vehiculos_editar']==1){echo 'block';}else{ echo 'none';}?>" type="button" id="btneditar" onclick="editar()" class="btn btn-default" value="Editar"/>
								</td>
								<td rowspan="3" style="width:60px;">
									<input style="display:<?php if($_SESSION['vehiculos_consultar']==1){echo 'block';}else{ echo 'none';}?>" type="button" id="btnconsultar" onclick="consultar()" class="btn btn-default" value="Consultar"/>
								</td>
							</tr>
							<tr>
								<td style="width:150px;font-weight: bold;">Razon Social</td>
								<td><?php echo $_SESSION['razon_social'];?></td>
							</tr>
							<tr>
								<td style="width:150px;font-weight: bold;">Saldo</td>
								<td><?php echo $_SESSION['saldo'];?></td>
							</tr>					
						</table>
						<?php
						$sql="select ";
						$sql.="id_vehiculo, ";
						$sql.="descripcion, ";
 						$sql.="departamento, ";
 						$sql.="numero_economico, ";
						$sql.="placa, ";
						$sql.="id_tag, ";
						$sql.="estado ";	
						$sql.="from ";
						$sql.="vehiculos ";
						$sql.="where ";
						$sql.="id_cliente=".  $_SESSION['id_cliente'];
						
						$resultado = $iden->query($sql); 	
						
						if(!$resultado) 
						die("Error: no se pudo realizar la consulta");
						?>
											
					</div>	
				</div>
			</center> 	
		</td>
	</tr>
	</table>
	<div align="center">
	<center style="width:auto;align:left;color:black;position: relative;top:15px;" id="centro_catalogo">
						<?php
							echo '<table id="tabla_vehiculos" style="color:black;background-color:transparent">';
							echo '<thead>';
							echo '<tr style="border-bottom: 1px solid #A8BA30; ">';
							echo '<th style="width:50px;text-align: center">Id</th>';
							echo '<th style="width:350px;text-align: center">Descripción</th>';	
 							echo '<th style="width:100px;text-align: center">Departamento</th>';	
 							echo '<th style="width:70px;text-align: center">N° Eco</th>';	
							echo '<th style="width:70px;text-align: center">Placa</th>';	
							echo '<th style="width:170px;text-align: center">Tarjeta</th>';							
							echo '<th style="width:70px;text-align: center">Estado</th>';							
							echo '</tr>';
							echo '</thead>';					
							echo '<tbody>';	
							while($fila = $resultado->fetch_assoc()) 
							{ 		
								if($fila['estado']==1)
									$estado="Activo";
								else
									$estado="Desactivado";
							
								echo '<tr onclick="vehiculo_seleccion(this)" style="border-bottom: 1px solid #A8BA30; " id="'.$fila['id_vehiculo'].'">';							
								echo '<td style="width:50px">' . $fila['id_vehiculo'] . '</td>';
								echo '<td style="width:350px">' . $fila['descripcion']  . '</td>';
								echo '<td style="width:100px">' . $fila['departamento'] . '</td>';
								echo '<td style="width:70px;text-align: center">' . $fila['numero_economico'] . '</td>';
								echo '<td style="width:100px;text-align: center">' . $fila['placa'] . '</td>';
								echo '<td style="width:270px">' . $fila['id_tag'] . '</td>';
								echo '<td style="width:70px;text-align: center">' . $estado . '</td>';
								echo '</tr>'; 
							} 
							$resultado->free();
							mysqli_close($iden); 
							echo '</tbody>';
							echo '</table>';
						?> 
						</center>	
		<br>
		<br>
	<table align="right">
	<tr>		
		<td align="right" style="text-align: right">
			<table>
				<tr>
					<td>
						<img width="150px;" src="images/GasLight System.jpg"></img>
					</td>
				</tr>
			</table>			
		</td>
	</tr>	
</table>
	</div>
</body>
<?php 
}	
else
{
header('location: inicio.php');
}
?>
</html>
