Added: Fuel record create - not complete yet
All checks were successful
Build and Deploy Zola Website / build_and_deploy (push) Successful in 12s

This commit is contained in:
Filip Rojek 2025-01-03 17:10:08 +01:00
parent c5955010cb
commit 860a20d946
6 changed files with 93 additions and 3 deletions

View File

@ -0,0 +1,9 @@
<?php
class RefuelController extends Controller {
public function create() {
$vehicle = new Vehicle();
$vehicles = $vehicle->getVehiclesByUser($_SESSION['user']['id']);
$this->view('refuel/create', ['title' => "New refuel record", 'vehicles' => $vehicles]);
}
}

5
app/models/Refuel.php Normal file
View File

@ -0,0 +1,5 @@
<?php
class Refuel {
}

View File

@ -3,7 +3,7 @@
<section class="dashboard"> <section class="dashboard">
<h1>Welcome, <?= htmlspecialchars($_SESSION['user']['username']) ?>!</h1> <h1>Welcome, <?= htmlspecialchars($_SESSION['user']['username']) ?>!</h1>
<div> <div>
<a href="/refuel/add" class="btn-green">Add new refuel record!</a> <a href="/refuel/create" class="btn-green">Add new refuel record!</a>
<a href="/vehicles" class="btn-primary">List all vehicles</a> <a href="/vehicles" class="btn-primary">List all vehicles</a>
</div> </div>
<div class="card-wrapper"> <div class="card-wrapper">

View File

@ -0,0 +1,71 @@
<link rel="stylesheet" href="/css/form.css">
<link rel="stylesheet" href="/css/vehicle_create.css">
<section class="form">
<h1 class="header-form"><?= $this->get('title') ?></h1>
<?php if ($this->get('error')): ?>
<div class="error" style="color: red; margin-bottom: 1rem;">
<?= htmlspecialchars($this->get('error')) ?>
</div>
<?php endif; ?>
<form method="POST" action="/refuel/create">
<label for="vehicle">Vehicle</label>
<select name="vehicle" id="vehicle">
<?php foreach ($this->get('vehicles') as $vehicle): ?>
<option value="<?= $vehicle['id'] ?>"><?= $vehicle['name'] . " | " . $vehicle['registration_plate'] ?> </option>
<?php endforeach; ?>
</select>
<label for="fuel_type">Fuel type</label>
<select name="fuel_type" id="fuel_type">
<option value="Diesel">Diesel</option>
<option value="Gasoline 95">Gasoline 95</option>
<option value="Gasoline 98">Gasoline 98</option>
<option value="Premium Diesel">Premium Diesel</option>
<option value="Premium Gasoline 95">Premium Gasoline 95</option>
<option value="Premium Gasoline 98">Premium Gasoline 98</option>
<option value="Other">Other</option>
</select>
<label for="liters">Liters</label>
<input type="number" name="liters" id="liters" value="<?= htmlspecialchars($_POST['liters'] ?? '') ?>">
<!-- TODO: name and id -->
<label for="liters">Price per liter</label>
<input type="number" name="price_per_liter" id="price_per_liter" value="<?= htmlspecialchars($_POST['liters'] ?? '') ?>">
<label for="liters">Total price</label>
<input type="number" name="liters" id="liters" value="<?= htmlspecialchars($_POST['liters'] ?? '') ?>">
<label for="note">Note</label>
<input type="text" name="note" id="note" value="<?= htmlspecialchars($_POST['note'] ?? '') ?>">
<input type="submit" value="Create fuel record">
</form>
</section>
<script>
const vehicles = <?= json_encode($data['vehicles']); ?>;
const fuel_sel = document.querySelector("#fuel_type")
const vehic_sel = document.querySelector("#vehicle")
function selectFuel() {
const veh_id = vehic_sel.value
vehicles.forEach(el => {
if(el.id == veh_id) {
fuel_sel.value = el.fuel_type
return
}
})
}
selectFuel()
vehic_sel.addEventListener("change", () => {
selectFuel()
})
// TODO: function for auto calculation price/price_per_liter/liters
</script>

View File

@ -11,6 +11,7 @@
<div class="vehicle bordered"> <div class="vehicle bordered">
<b><?= htmlspecialchars($vehicle['name']) ?></b> <b><?= htmlspecialchars($vehicle['name']) ?></b>
<p><?= htmlspecialchars($vehicle['registration_plate']) ?></p> <p><?= htmlspecialchars($vehicle['registration_plate']) ?></p>
<p><?= htmlspecialchars($vehicle['fuel_type']) ?></p>
<p><?= htmlspecialchars($vehicle['note'] ?? "") ?></p> <p><?= htmlspecialchars($vehicle['note'] ?? "") ?></p>
<div class="actions"> <div class="actions">
<a href="/vehicles/edit?id=<?= $vehicle['id'] ?>">Edit</a> <a href="/vehicles/edit?id=<?= $vehicle['id'] ?>">Edit</a>

View File

@ -21,7 +21,7 @@ require_once '../core/middlewares/RequireAuth.php';
require_once models . 'User.php'; require_once models . 'User.php';
require_once models . 'Vehicle.php'; require_once models . 'Vehicle.php';
#require_once models . 'Refueling.php'; require_once models . 'Refuel.php';
// Initialize router // Initialize router
$router = new Router(); $router = new Router();
@ -41,7 +41,7 @@ $router->group('/auth', [], function ($router) {
// dashboard route // dashboard route
$router->add('/dashboard', 'DashboardController@index', ['RequireAuth']); $router->add('/dashboard', 'DashboardController@index', ['RequireAuth']);
// habits routes // vehicle routes
$router->group('/vehicles', ['RequireAuth'], function ($router) { $router->group('/vehicles', ['RequireAuth'], function ($router) {
$router->add('', 'VehicleController@index'); $router->add('', 'VehicleController@index');
$router->add('/create', 'VehicleController@create'); $router->add('/create', 'VehicleController@create');
@ -49,4 +49,8 @@ $router->group('/vehicles', ['RequireAuth'], function ($router) {
$router->add('/delete/{id}', 'VehicleController@delete'); $router->add('/delete/{id}', 'VehicleController@delete');
}); });
$router->group('/refuel', ['RequireAuth'], function ($router) {
$router->add('/create', 'RefuelController@create');
});
$router->dispatch(); $router->dispatch();