<?php
  
/**
* Use an HTML form to create a new entry in the
* users table.
*
*/

require './config.php';
require './common.php';

/**
* Esto es para comprobar si existe la BD
* Además, nos permite seleccionar los últimos repostajes y otras cosas que queramos
*/
try {
  $connection = new PDO($dsn, $username, $password, $options);

  $sql = "SELECT * FROM vehiculos";

  $statement = $connection->prepare($sql);
  $statement->execute();

  $result = $statement->fetchAll();
} catch(PDOException $error) {
  echo $sql . "<br>" . $error->getMessage();
}

require "./cabecera.php";?>

    <div class="app-wrapper">
	    
	    <div class="app-content pt-3 p-md-3 p-lg-4">
		    <div class="container-xl">
			    
			    <div class="row g-3 mb-4 align-items-center justify-content-between">
				    <div class="col-auto">
			            <h1 class="app-page-title mb-0">Actualizar vehículos</h1>
				    </div>
			    </div><!--//row-->
			   
				
				<div class="tab-content" id="orders-table-tab-content">
			        <div class="tab-pane fade show active" id="orders-all" role="tabpanel" aria-labelledby="orders-all-tab">
					    <div class="app-card app-card-orders-table shadow-sm mb-5">
						    <div class="app-card-body">
							    <div class="table-responsive">
							        <table class="table app-table-hover mb-0 text-left">
										<thead>
											<tr>
												<th class="cell">#</th>
                        				<th class="cell">Marca</th>
                        				<th class="cell">Modelo</th>
                        				<th class="cell">Matrícula</th>
                        				<th class="cell">Editar</th>
											</tr>
										</thead>
										<tbody>
												<?php foreach ($result as $row) : ?>
                    						<tr>
                        					<td class="cell"><?php echo escape($row["identificador"]); ?></td>
                        					<td class="cell"><?php echo escape($row["marca"]); ?></td>
                        					<td class="cell"><?php echo escape($row["modelo"]); ?></td>
                        					<td class="cell"><?php echo escape($row["matricula"]); ?></td>
                        					<td class="cell"><a
                                           href="actualizarvehiculo.php?identificador=<?php echo escape($row["identificador"]); ?>">Edit</a>
                                       </td>
                    						</tr>
                    						<?php endforeach; ?>
										</tbody>
									</table>
						        </div><!--//table-responsive-->
						       
						    </div><!--//app-card-body-->		
						</div><!--//app-card-->
						
			        </div><!--//tab-pane-->
				</div><!--//tab-content-->
				
				
			    
		    </div><!--//container-fluid-->
	    </div><!--//app-content-->
	    	    
<?php require './templates/footer.php';?>
   <!-- Javascript -->          
    <script src="assets/plugins/popper.min.js"></script>
    <script src="assets/plugins/bootstrap/js/bootstrap.min.js"></script>  
    
    
    <!-- Page Specific JS -->
    <script src="assets/js/app.js"></script> 
</body>
</html>

