124 lines
5.6 KiB
PHP
124 lines
5.6 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
|
|
$errors = [];
|
|
$success = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$name = $_POST['name'] ?? '';
|
|
$location = $_POST['location'] ?? '';
|
|
$capacity = $_POST['capacity'] ?? '';
|
|
$commissioning_date = $_POST['commissioning_date'] ?? '';
|
|
|
|
if (empty($name)) {
|
|
$errors[] = 'Plant name is required.';
|
|
}
|
|
if (empty($location)) {
|
|
$errors[] = 'Location is required.';
|
|
}
|
|
if (empty($capacity) || !is_numeric($capacity)) {
|
|
$errors[] = 'Capacity must be a number.';
|
|
}
|
|
if (empty($commissioning_date)) {
|
|
$errors[] = 'Commissioning date is required.';
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('INSERT INTO plants (name, location, capacity, commissioning_date) VALUES (?, ?, ?, ?)');
|
|
$stmt->execute([$name, $location, $capacity, $commissioning_date]);
|
|
$success = 'Plant registered successfully!';
|
|
} catch (PDOException $e) {
|
|
$errors[] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Solyug Tracker - Add Plant</title>
|
|
<meta name="description" content="Built with Flatlogic Generator">
|
|
<meta name="keywords" content="solar plant monitoring, solar energy, renewable energy, plant management, solar panel tracking, energy analytics, solar farm, Built with Flatlogic Generator">
|
|
<meta property="og:title" content="Solyug Tracker">
|
|
<meta property="og:description" content="Built with Flatlogic Generator">
|
|
<meta property="og:image" content="">
|
|
<meta name="twitter:card" content="summary_large_image">
|
|
<meta name="twitter:image" content="">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="index.php">Solyug Tracker</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Home</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" aria-current="page" href="add_plant.php">Add Plant</a>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h2><i class="bi bi-plus-circle"></i> Register New Solar Plant</h2>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="alert alert-danger">
|
|
<?php foreach ($errors as $error): ?>
|
|
<p><?php echo htmlspecialchars($error); ?></p>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if ($success): ?>
|
|
<div class="alert alert-success">
|
|
<p><?php echo htmlspecialchars($success); ?></p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<form action="add_plant.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Plant Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="location" class="form-label">Location</label>
|
|
<input type="text" class="form-control" id="location" name="location" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="capacity" class="form-label">Capacity (kW)</label>
|
|
<input type="number" step="0.01" class="form-control" id="capacity" name="capacity" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="commissioning_date" class="form-label">Commissioning Date</label>
|
|
<input type="date" class="form-control" id="commissioning_date" name="commissioning_date" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Register Plant</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="assets/js/main.js"></script>
|
|
</body>
|
|
</html>
|