Compare commits

...

1 Commits

Author SHA1 Message Date
Flatlogic Bot
d9cfa069d3 v1.0 - 2a73206 2025-11-08 15:26:25 +00:00
23 changed files with 1613 additions and 143 deletions

125
admin/add_scheme.php Normal file
View File

@ -0,0 +1,125 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
$errors = [];
$name = $description = $eligibility = $benefits = $how_to_apply = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$description = trim($_POST['description'] ?? '');
$eligibility = trim($_POST['eligibility'] ?? '');
$benefits = trim($_POST['benefits'] ?? '');
$how_to_apply = trim($_POST['how_to_apply'] ?? '');
if (empty($name)) {
$errors[] = 'Scheme name is required.';
}
if (empty($description)) {
$errors[] = 'Description is required.';
}
if (empty($errors)) {
try {
$stmt = db()->prepare("INSERT INTO schemes (name, description, eligibility, benefits, how_to_apply) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$name, $description, $eligibility, $benefits, $how_to_apply]);
$_SESSION['message'] = 'Scheme "' . htmlspecialchars($name) . '" was successfully added.';
header('Location: schemes.php');
exit;
} 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>Add New Scheme - Admin</title>
<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">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin Panel</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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Applications</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="schemes.php">Schemes</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Add New Scheme</h1>
<a href="schemes.php" class="btn btn-secondary">
<i class="bi bi-arrow-left me-2"></i>Back to Schemes
</a>
</div>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<strong>Please correct the following errors:</strong>
<ul>
<?php foreach ($errors as $error): ?>
<li><?php echo htmlspecialchars($error); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="card shadow-sm">
<div class="card-body">
<form action="add_scheme.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Scheme Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required><?php echo htmlspecialchars($description); ?></textarea>
</div>
<div class="mb-3">
<label for="eligibility" class="form-label">Eligibility</label>
<textarea class="form-control" id="eligibility" name="eligibility" rows="3"><?php echo htmlspecialchars($eligibility); ?></textarea>
</div>
<div class="mb-3">
<label for="benefits" class="form-label">Benefits</label>
<textarea class="form-control" id="benefits" name="benefits" rows="3"><?php echo htmlspecialchars($benefits); ?></textarea>
</div>
<div class="mb-3">
<label for="how_to_apply" class="form-label">How to Apply</label>
<textarea class="form-control" id="how_to_apply" name="how_to_apply" rows="3"><?php echo htmlspecialchars($how_to_apply); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Add Scheme</button>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

140
admin/dashboard.php Normal file
View File

@ -0,0 +1,140 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
// Fetch all applications with farmer and scheme details
$stmt = db()->query("
SELECT
a.id as application_id,
a.application_date,
a.status,
f.full_name as farmer_name,
f.email as farmer_email,
f.phone as farmer_phone,
s.name as scheme_name
FROM applications a
JOIN farmers f ON a.farmer_id = f.id
JOIN schemes s ON a.scheme_id = s.id
ORDER BY a.application_date DESC
");
$applications = $stmt->fetchAll(PDO::FETCH_ASSOC);
$possible_statuses = ['Pending', 'Approved', 'Rejected'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard - Smart Farmer</title>
<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">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin Panel</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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="dashboard.php">Applications</a>
</li>
<li class="nav-item">
<a class="nav-link" href="schemes.php">Schemes</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Farmer Applications</h1>
</div>
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($_SESSION['message']); unset($_SESSION['message']); ?></div>
<?php endif; ?>
<div class="card shadow-sm">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Farmer Name</th>
<th>Farmer Contact</th>
<th>Scheme Name</th>
<th>Applied On</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (empty($applications)): ?>
<tr>
<td colspan="7" class="text-center">No applications found.</td>
</tr>
<?php else: ?>
<?php foreach ($applications as $app): ?>
<tr>
<td><?php echo htmlspecialchars($app['application_id']); ?></td>
<td><?php echo htmlspecialchars($app['farmer_name']); ?></td>
<td>
<?php echo htmlspecialchars($app['farmer_email']); ?><br>
<?php echo htmlspecialchars($app['farmer_phone']); ?>
</td>
<td><?php echo htmlspecialchars($app['scheme_name']); ?></td>
<td><?php echo htmlspecialchars(date('d M Y', strtotime($app['application_date']))); ?></td>
<td>
<span class="badge
<?php
switch ($app['status']) {
case 'Approved': echo 'bg-success'; break;
case 'Rejected': echo 'bg-danger'; break;
default: echo 'bg-warning'; break;
}
?>">
<?php echo htmlspecialchars($app['status']); ?>
</span>
</td>
<td>
<form method="POST" action="update_status.php" class="d-flex">
<input type="hidden" name="application_id" value="<?php echo $app['application_id']; ?>">
<select name="status" class="form-select form-select-sm me-2" style="width: 120px;">
<?php foreach ($possible_statuses as $status): ?>
<option value="<?php echo $status; ?>" <?php echo $app['status'] === $status ? 'selected' : ''; ?>>
<?php echo $status; ?>
</option>
<?php endforeach; ?>
</select>
<button type="submit" class="btn btn-primary btn-sm">Update</button>
</form>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

48
admin/delete_scheme.php Normal file
View File

@ -0,0 +1,48 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
$scheme_id = $_GET['id'] ?? null;
if (!$scheme_id) {
header('Location: schemes.php');
exit;
}
try {
$db = db();
$db->beginTransaction();
// Get scheme name for the message before deleting
$stmt = $db->prepare("SELECT name FROM schemes WHERE id = ?");
$stmt->execute([$scheme_id]);
$scheme = $stmt->fetch(PDO::FETCH_ASSOC);
$scheme_name = $scheme ? $scheme['name'] : 'the scheme';
// Delete related applications first to maintain foreign key constraints
$stmt = $db->prepare("DELETE FROM applications WHERE scheme_id = ?");
$stmt->execute([$scheme_id]);
// Now, delete the scheme itself
$stmt = $db->prepare("DELETE FROM schemes WHERE id = ?");
$stmt->execute([$scheme_id]);
$db->commit();
$_SESSION['message'] = 'Scheme \"' . htmlspecialchars($scheme_name) . '\" and all its applications have been deleted.';
} catch (PDOException $e) {
if (isset($db) && $db->inTransaction()) {
$db->rollBack();
}
// In a real app, you would log this error instead of dying
die("Database error: " . $e->getMessage());
}
header('Location: schemes.php');
exit;

158
admin/edit_scheme.php Normal file
View File

@ -0,0 +1,158 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
$scheme_id = $_GET['id'] ?? null;
if (!$scheme_id) {
header('Location: schemes.php');
exit;
}
$errors = [];
// Fetch existing scheme data
try {
$stmt = db()->prepare("SELECT * FROM schemes WHERE id = ?");
$stmt->execute([$scheme_id]);
$scheme = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$scheme) {
$_SESSION['message'] = 'Scheme not found.';
header('Location: schemes.php');
exit;
}
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
$name = $scheme['name'];
$description = $scheme['description'];
$eligibility = $scheme['eligibility'];
$benefits = $scheme['benefits'];
$how_to_apply = $scheme['how_to_apply'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = trim($_POST['name'] ?? '');
$description = trim($_POST['description'] ?? '');
$eligibility = trim($_POST['eligibility'] ?? '');
$benefits = trim($_POST['benefits'] ?? '');
$how_to_apply = trim($_POST['how_to_apply'] ?? '');
if (empty($name)) {
$errors[] = 'Scheme name is required.';
}
if (empty($description)) {
$errors[] = 'Description is required.';
}
if (empty($errors)) {
try {
$stmt = db()->prepare("UPDATE schemes SET name = ?, description = ?, eligibility = ?, benefits = ?, how_to_apply = ? WHERE id = ?");
$stmt->execute([$name, $description, $eligibility, $benefits, $how_to_apply, $scheme_id]);
$_SESSION['message'] = 'Scheme "' . htmlspecialchars($name) . '" was successfully updated.';
header('Location: schemes.php');
exit;
} 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>Edit Scheme - Admin</title>
<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">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin Panel</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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Applications</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="schemes.php">Schemes</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Edit Scheme</h1>
<a href="schemes.php" class="btn btn-secondary">
<i class="bi bi-arrow-left me-2"></i>Back to Schemes
</a>
</div>
<?php if (!empty($errors)):
?>
<div class="alert alert-danger">
<strong>Please correct the following errors:</strong>
<ul>
<?php foreach ($errors as $error):
?>
<li><?php echo htmlspecialchars($error); ?></li>
<?php endforeach;
?>
</ul>
</div>
<?php endif;
?>
<div class="card shadow-sm">
<div class="card-body">
<form action="edit_scheme.php?id=<?php echo htmlspecialchars($scheme_id); ?>" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Scheme Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" required><?php echo htmlspecialchars($description); ?></textarea>
</div>
<div class="mb-3">
<label for="eligibility" class="form-label">Eligibility</label>
<textarea class="form-control" id="eligibility" name="eligibility" rows="3"><?php echo htmlspecialchars($eligibility); ?></textarea>
</div>
<div class="mb-3">
<label for="benefits" class="form-label">Benefits</label>
<textarea class="form-control" id="benefits" name="benefits" rows="3"><?php echo htmlspecialchars($benefits); ?></textarea>
</div>
<div class="mb-3">
<label for="how_to_apply" class="form-label">How to Apply</label>
<textarea class="form-control" id="how_to_apply" name="how_to_apply" rows="3"><?php echo htmlspecialchars($how_to_apply); ?></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Scheme</button>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

63
admin/index.php Normal file
View File

@ -0,0 +1,63 @@
<?php
session_start();
require_once '../db/config.php';
$error = '';
// Hardcoded admin credentials
define('ADMIN_USER', 'admin');
define('ADMIN_PASS', 'password'); // In a real application, use a hashed password
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
if ($username === ADMIN_USER && $password === ADMIN_PASS) {
$_SESSION['admin_logged_in'] = true;
header('Location: dashboard.php');
exit;
} else {
$error = 'Invalid username or password.';
}
}
if (isset($_SESSION['admin_logged_in']) && $_SESSION['admin_logged_in'] === true) {
header('Location: dashboard.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Login - Smart Farmer</title>
<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">
</head>
<body>
<div class="container vh-100 d-flex justify-content-center align-items-center">
<div class="card shadow" style="width: 22rem;">
<div class="card-body p-5">
<h3 class="card-title text-center mb-4">Admin Login</h3>
<?php if ($error): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
<?php endif; ?>
<form method="POST" action="index.php">
<div class="mb-3">
<label for="username" class="form-label">Username</label>
<input type="text" class="form-control" id="username" name="username" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Login</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>

19
admin/logout.php Normal file
View File

@ -0,0 +1,19 @@
<?php
session_start();
// Unset all of the session variables
$_SESSION = [];
// Destroy the session.
if (ini_get("session.use_cookies")) {
$params = session_get_cookie_params();
setcookie(session_name(), '', time() - 42000,
$params["path"], $params["domain"],
$params["secure"], $params["httponly"]
);
}
session_destroy();
header('Location: index.php');
exit;

101
admin/schemes.php Normal file
View File

@ -0,0 +1,101 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
// Fetch all schemes
$stmt = db()->query("SELECT * FROM schemes ORDER BY name ASC");
$schemes = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Schemes - Admin</title>
<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">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="dashboard.php">Admin Panel</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 me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Applications</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="schemes.php">Schemes</a>
</li>
</ul>
<ul class="navbar-nav ms-auto">
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container mt-5">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Manage Schemes</h1>
<a href="add_scheme.php" class="btn btn-primary">
<i class="bi bi-plus-circle me-2"></i>Add New Scheme
</a>
</div>
<?php if (isset($_SESSION['message'])): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($_SESSION['message']); unset($_SESSION['message']); ?></div>
<?php endif; ?>
<div class="card shadow-sm">
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead class="table-dark">
<tr>
<th>ID</th>
<th>Scheme Name</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($schemes)): ?>
<tr>
<td colspan="3" class="text-center">No schemes found. <a href="add_scheme.php">Add one now</a>.</td>
</tr>
<?php else: ?>
<?php foreach ($schemes as $scheme): ?>
<tr>
<td><?php echo htmlspecialchars($scheme['id']); ?></td>
<td><?php echo htmlspecialchars($scheme['name']); ?></td>
<td>
<a href="edit_scheme.php?id=<?php echo $scheme['id']; ?>" class="btn btn-sm btn-outline-primary me-2">
<i class="bi bi-pencil-square me-1"></i>Edit
</a>
<a href="delete_scheme.php?id=<?php echo $scheme['id']; ?>" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to delete this scheme? This action cannot be undone.');">
<i class="bi bi-trash-fill me-1"></i>Delete
</a>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

31
admin/update_status.php Normal file
View File

@ -0,0 +1,31 @@
<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
header('Location: index.php');
exit;
}
require_once '../db/config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$application_id = $_POST['application_id'] ?? null;
$status = $_POST['status'] ?? null;
$possible_statuses = ['Pending', 'Approved', 'Rejected'];
if ($application_id && $status && in_array($status, $possible_statuses)) {
try {
$stmt = db()->prepare("UPDATE applications SET status = :status WHERE id = :id");
$stmt->bindParam(':status', $status, PDO::PARAM_STR);
$stmt->bindParam(':id', $application_id, PDO::PARAM_INT);
$stmt->execute();
$_SESSION['message'] = "Status for application #{$application_id} has been updated to '{$status}'.";
} catch (PDOException $e) {
// In a real app, you would log this error
$_SESSION['message'] = "Error updating status. Please try again.";
}
}
}
header('Location: dashboard.php');
exit;

50
apply.php Normal file
View File

@ -0,0 +1,50 @@
<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in
if (!isset($_SESSION['farmer_id'])) {
header("Location: login.php");
exit();
}
// Check if scheme_id is provided
if (!isset($_GET['scheme_id'])) {
header("Location: index.php");
exit();
}
$farmer_id = $_SESSION['farmer_id'];
$scheme_id = $_GET['scheme_id'];
// Check if already applied
$pdo = db();
$stmt = $pdo->prepare("SELECT id FROM applications WHERE farmer_id = ? AND scheme_id = ?");
$stmt->execute([$farmer_id, $scheme_id]);
$existing_application = $stmt->fetch();
if ($existing_application) {
$_SESSION['message'] = [
'type' => 'warning',
'text' => 'You have already applied for this scheme.'
];
} else {
// Insert new application
$stmt = $pdo->prepare("INSERT INTO applications (farmer_id, scheme_id) VALUES (?, ?)");
if ($stmt->execute([$farmer_id, $scheme_id])) {
$_SESSION['message'] = [
'type' => 'success',
'text' => 'You have successfully applied for the scheme!'
];
} else {
$_SESSION['message'] = [
'type' => 'danger',
'text' => 'There was an error processing your application. Please try again.'
];
}
}
// Redirect back to the scheme page
header("Location: scheme.php?id=" . $scheme_id);
exit();
?>

64
assets/css/custom.css Normal file
View File

@ -0,0 +1,64 @@
/* custom.css for Smart Farmer Support System */
body {
font-family: 'Roboto', sans-serif;
background-color: #f8f9fa;
}
.navbar-brand {
font-weight: 700;
color: #28a745 !important;
}
.hero {
background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://images.pexels.com/photos/265216/pexels-photo-265216.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1');
background-size: cover;
background-position: center;
color: white;
padding: 100px 0;
text-align: center;
}
.hero h1 {
font-size: 3.5rem;
font-weight: 700;
text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}
.hero p {
font-size: 1.25rem;
}
.scheme-card {
border: none;
border-radius: 0.5rem;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.scheme-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0,0,0,0.2);
}
.scheme-card .card-title {
color: #28a745;
font-weight: 700;
}
.btn-primary {
background-color: #28a745;
border-color: #28a745;
}
.btn-primary:hover {
background-color: #218838;
border-color: #1e7e34;
}
.footer {
background-color: #343a40;
color: white;
padding: 20px 0;
text-align: center;
}

123
dashboard.php Normal file
View File

@ -0,0 +1,123 @@
<?php
require_once 'db/config.php';
// Ensure user is logged in
if (!isset($_SESSION['farmer_id'])) {
header("Location: login.php");
exit();
}
$farmer_id = $_SESSION['farmer_id'];
$pdo = db();
// Fetch farmer's details
$stmt = $pdo->prepare("SELECT * FROM farmers WHERE id = ?");
$stmt->execute([$farmer_id]);
$farmer = $stmt->fetch(PDO::FETCH_ASSOC);
// Fetch applied schemes
$stmt = $pdo->prepare("
SELECT s.id, s.name, s.description, a.application_date, a.status
FROM applications a
JOIN schemes s ON a.scheme_id = s.id
WHERE a.farmer_id = ?
ORDER BY a.application_date DESC
");
$stmt->execute([$farmer_id]);
$applied_schemes = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - Smart Farmer</title>
<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>
<?php include 'partials/navbar.php'; ?>
<header class="bg-success text-white text-center py-5">
<div class="container">
<h1 class="display-5">Welcome, <?php echo htmlspecialchars($farmer['full_name']); ?>!</h1>
<p class="lead">This is your personal dashboard. Manage your applications and profile here.</p>
</div>
</header>
<main class="container my-5">
<div class="row">
<!-- Farmer Profile Section -->
<div class="col-md-4">
<div class="card shadow-sm mb-4">
<div class="card-header bg-light d-flex justify-content-between align-items-center">
<h4><i class="bi bi-person-circle me-2"></i>My Profile</h4>
<a href="edit_profile.php" class="btn btn-sm btn-outline-primary">
<i class="bi bi-pencil-square me-1"></i>Edit
</a>
</div>
<div class="card-body">
<p><strong>Name:</strong> <?php echo htmlspecialchars($farmer['full_name']); ?></p>
<p><strong>Email:</strong> <?php echo htmlspecialchars($farmer['email']); ?></p>
<p><strong>Phone:</strong> <?php echo htmlspecialchars($farmer['phone'] ?? 'N/A'); ?></p>
<p><strong>District:</strong> <?php echo htmlspecialchars($farmer['district'] ?? 'N/A'); ?></p>
</div>
</div>
</div>
<!-- Applied Schemes Section -->
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-header bg-light">
<h4><i class="bi bi-journal-check me-2"></i>My Applications</h4>
</div>
<div class="card-body">
<?php if (empty($applied_schemes)): ?>
<div class="alert alert-info">
You have not applied for any schemes yet.
<a href="index.php#schemes" class="alert-link">Explore schemes</a> and apply now.
</div>
<?php else: ?>
<div class="list-group">
<?php foreach ($applied_schemes as $scheme): ?>
<a href="scheme.php?id=<?php echo $scheme['id']; ?>" class="list-group-item list-group-item-action">
<div class="d-flex w-100 justify-content-between">
<h5 class="mb-1"><?php echo htmlspecialchars($scheme['name']); ?></h5>
<small class="text-muted">Applied on: <?php echo date('d M Y', strtotime($scheme['application_date'])); ?></small>
</div>
<p class="mb-1"><?php echo htmlspecialchars(substr($scheme['description'], 0, 100)); ?>...</p>
<div class="mt-2">
<strong>Status:</strong>
<span class="badge
<?php
switch ($scheme['status']) {
case 'Approved': echo 'bg-success'; break;
case 'Rejected': echo 'bg-danger'; break;
default: echo 'bg-warning text-dark'; break;
}
?>">
<?php echo htmlspecialchars($scheme['status']); ?>
</span>
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<span class="text-muted">&copy; <?php echo date("Y"); ?> Smart Farmer Support System. All Rights Reserved.</span>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@ -13,5 +13,28 @@ function db() {
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
}
return $pdo;
function run_migrations($pdo) {
$migration_dir = __DIR__ . '/migrations';
if (!is_dir($migration_dir)) return;
$files = glob($migration_dir . '/*.sql');
sort($files);
foreach ($files as $file) {
try {
$sql = file_get_contents($file);
if (!empty(trim($sql))) {
$pdo->exec($sql);
}
} catch (PDOException $e) {
// Log error or handle it, but don't stop other migrations
error_log("Migration failed for file: " . basename($file) . " with error: " . $e->getMessage());
}
}
}
// Run migrations on connection
run_migrations($pdo);
return $pdo;
}

View File

@ -0,0 +1,18 @@
-- Create schemes table
CREATE TABLE IF NOT EXISTS schemes (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
description TEXT,
eligibility TEXT,
benefits TEXT,
how_to_apply TEXT,
url VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Seed data for schemes
INSERT INTO schemes (name, description, eligibility, benefits, how_to_apply, url) VALUES
('Pradhan Mantri Fasal Bima Yojana (PMFBY)', 'An insurance service for farmers for their yields.', 'All farmers including sharecroppers and tenant farmers growing notified crops in the notified areas are eligible.', 'Provides comprehensive insurance coverage against failure of the crop thus helping in stabilising the income of the farmers.', 'Farmers can apply through their bank, PACS, or CSC centres. They need to fill the form and submit the required documents like land records, sowing declaration, and identity proof.', '#'),
('Kisan Credit Card (KCC)', 'A credit scheme to provide affordable credit for farmers.', 'All farmers-individuals/joint borrowers who are owner cultivators are eligible. Tenant farmers, oral lessees & sharecroppers are also eligible.', 'Access to credit at a lower rate of interest, with a flexible repayment schedule. It also provides a credit limit for a period of 5 years.', 'Visit the nearest bank branch and fill out the KCC application form. Submit it with the necessary documents like land documents, crop details, and identity proof.', '#'),
('Jalyukt Shivar Abhiyan', 'A water conservation scheme to make Maharashtra a drought-free state.', 'The scheme is primarily for villages in the rain-fed areas of Maharashtra.', 'Increased water availability for irrigation, which leads to higher crop yields and improved farmer income. It also helps in recharging groundwater levels.', 'The scheme is implemented by the state government. Farmers can participate in the planning and implementation of water conservation structures in their villages through Gram Sabhas.', '#')
ON DUPLICATE KEY UPDATE name=name; -- Avoid re-inserting duplicates if script is run again

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `farmers` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`full_name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`phone` VARCHAR(20),
`district` VARCHAR(100),
`password` VARCHAR(255) NOT NULL,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `applications` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`farmer_id` INT NOT NULL,
`scheme_id` INT NOT NULL,
`application_date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`farmer_id`) REFERENCES `farmers`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`scheme_id`) REFERENCES `schemes`(`id`) ON DELETE CASCADE,
UNIQUE KEY `farmer_scheme_unique` (`farmer_id`, `scheme_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View File

@ -0,0 +1 @@
ALTER TABLE `applications` ADD `status` VARCHAR(255) NOT NULL DEFAULT 'Pending' AFTER `application_date`;

131
edit_profile.php Normal file
View File

@ -0,0 +1,131 @@
<?php
session_start();
if (!isset($_SESSION['farmer_id'])) {
header('Location: login.php');
exit;
}
require_once 'db/config.php';
$farmer_id = $_SESSION['farmer_id'];
$errors = [];
$message = '';
// Fetch farmer data
try {
$stmt = db()->prepare("SELECT * FROM farmers WHERE id = ?");
$stmt->execute([$farmer_id]);
$farmer = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
$full_name = $farmer['full_name'];
$email = $farmer['email'];
$phone = $farmer['phone'];
$district = $farmer['district'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$full_name = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$district = trim($_POST['district'] ?? '');
if (empty($full_name)) {
$errors[] = 'Full name is required.';
}
if (empty($email)) {
$errors[] = 'Email is required.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email format.';
}
// Check if email is already taken by another user
$stmt = db()->prepare("SELECT id FROM farmers WHERE email = ? AND id != ?");
$stmt->execute([$email, $farmer_id]);
if ($stmt->fetch()) {
$errors[] = 'This email address is already in use by another account.';
}
if (empty($errors)) {
try {
$stmt = db()->prepare("UPDATE farmers SET full_name = ?, email = ?, phone = ?, district = ? WHERE id = ?");
$stmt->execute([$full_name, $email, $phone, $district, $farmer_id]);
$message = 'Profile updated successfully!';
// Re-fetch data to display updated values
$full_name = $full_name;
$email = $email;
$phone = $phone;
$district = $district;
} 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>Edit Profile - Smart Farmer</title>
<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>
<?php include 'partials/navbar.php'; ?>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow-sm">
<div class="card-header bg-primary text-white">
<h1 class="h3 mb-0">Edit Your Profile</h1>
</div>
<div class="card-body">
<?php if (!empty($message)): ?>
<div class="alert alert-success"><?php echo htmlspecialchars($message); ?></div>
<?php endif; ?>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<ul>
<?php foreach ($errors as $error): ?>
<li><?php echo htmlspecialchars($error); ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<form action="edit_profile.php" method="POST">
<div class="mb-3">
<label for="full_name" class="form-label">Full Name</label>
<input type="text" class="form-control" id="full_name" name="full_name" value="<?php echo htmlspecialchars($full_name); ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlspecialchars($email); ?>" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number</label>
<input type="tel" class="form-control" id="phone" name="phone" value="<?php echo htmlspecialchars($phone); ?>">
</div>
<div class="mb-3">
<label for="district" class="form-label">District</label>
<input type="text" class="form-control" id="district" name="district" value="<?php echo htmlspecialchars($district); ?>">
</div>
<div class="d-flex justify-content-between">
<button type="submit" class="btn btn-primary">Update Profile</button>
<a href="dashboard.php" class="btn btn-secondary">Back to Dashboard</a>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

242
index.php
View File

@ -1,150 +1,108 @@
<?php
declare(strict_types=1);
@ini_set('display_errors', '1');
@error_reporting(E_ALL);
@date_default_timezone_set('UTC');
require_once __DIR__ . '/db/config.php';
// Fetch schemes from the database
$schemes = [];
try {
$stmt = db()->query("SELECT id, name, description, url FROM schemes ORDER BY name ASC");
$schemes = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
error_log("Could not fetch schemes: " . $e->getMessage());
// You could set a user-facing error message here if you want
}
$phpVersion = PHP_VERSION;
$now = date('Y-m-d H:i:s');
?>
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>New Style</title>
<?php
// Read project preview data from environment
$projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? '';
$projectImageUrl = $_SERVER['PROJECT_IMAGE_URL'] ?? '';
?>
<?php if ($projectDescription): ?>
<!-- Meta description -->
<meta name="description" content='<?= htmlspecialchars($projectDescription) ?>' />
<!-- Open Graph meta tags -->
<meta property="og:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<!-- Twitter meta tags -->
<meta property="twitter:description" content="<?= htmlspecialchars($projectDescription) ?>" />
<?php endif; ?>
<?php if ($projectImageUrl): ?>
<!-- Open Graph image -->
<meta property="og:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<!-- Twitter image -->
<meta property="twitter:image" content="<?= htmlspecialchars($projectImageUrl) ?>" />
<?php endif; ?>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
<style>
:root {
--bg-color-start: #6a11cb;
--bg-color-end: #2575fc;
--text-color: #ffffff;
--card-bg-color: rgba(255, 255, 255, 0.01);
--card-border-color: rgba(255, 255, 255, 0.1);
}
body {
margin: 0;
font-family: 'Inter', sans-serif;
background: linear-gradient(45deg, var(--bg-color-start), var(--bg-color-end));
color: var(--text-color);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
text-align: center;
overflow: hidden;
position: relative;
}
body::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><path d="M-10 10L110 10M10 -10L10 110" stroke-width="1" stroke="rgba(255,255,255,0.05)"/></svg>');
animation: bg-pan 20s linear infinite;
z-index: -1;
}
@keyframes bg-pan {
0% { background-position: 0% 0%; }
100% { background-position: 100% 100%; }
}
main {
padding: 2rem;
}
.card {
background: var(--card-bg-color);
border: 1px solid var(--card-border-color);
border-radius: 16px;
padding: 2rem;
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}
.loader {
margin: 1.25rem auto 1.25rem;
width: 48px;
height: 48px;
border: 3px solid rgba(255, 255, 255, 0.25);
border-top-color: #fff;
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.hint {
opacity: 0.9;
}
.sr-only {
position: absolute;
width: 1px; height: 1px;
padding: 0; margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap; border: 0;
}
h1 {
font-size: 3rem;
font-weight: 700;
margin: 0 0 1rem;
letter-spacing: -1px;
}
p {
margin: 0.5rem 0;
font-size: 1.1rem;
}
code {
background: rgba(0,0,0,0.2);
padding: 2px 6px;
border-radius: 4px;
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
footer {
position: absolute;
bottom: 1rem;
font-size: 0.8rem;
opacity: 0.7;
}
</style>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Smart Farmer Support System</title>
<meta name="description" content="A web application to support farmers in Maharashtra, India by providing access to government schemes, risk evaluation, and support services. Built with Flatlogic Generator.">
<meta name="keywords" content="farmer support, agriculture, Maharashtra, government schemes, crop insurance, farmer distress, Jalyukt Shivar, Kisan Credit Card, PMFBY, Built with Flatlogic Generator">
<!-- Social Media Meta Tags -->
<meta property="og:title" content="Smart Farmer Support System">
<meta property="og:description" content="Empowering Farmers, Saving Lives. An initiative to reduce farmer distress in Maharashtra.">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<main>
<div class="card">
<h1>Analyzing your requirements and generating your website…</h1>
<div class="loader" role="status" aria-live="polite" aria-label="Applying initial changes">
<span class="sr-only">Loading…</span>
</div>
<p class="hint"><?= ($_SERVER['HTTP_HOST'] ?? '') === 'appwizzy.com' ? 'AppWizzy' : 'Flatlogic' ?> AI is collecting your requirements and applying the first changes.</p>
<p class="hint">This page will update automatically as the plan is implemented.</p>
<p>Runtime: PHP <code><?= htmlspecialchars($phpVersion) ?></code> — UTC <code><?= htmlspecialchars($now) ?></code></p>
</div>
</main>
<footer>
Page updated: <?= htmlspecialchars($now) ?> (UTC)
</footer>
<?php include 'partials/navbar.php'; ?>
<!-- Hero Section -->
<header class="hero">
<div class="container">
<h1 class="display-4">Empowering Farmers, Saving Lives.</h1>
<p class="lead">Your one-stop solution for agricultural support, risk assessment, and government schemes in Maharashtra.</p>
<a href="#schemes" class="btn btn-primary btn-lg">Explore Schemes</a>
</div>
</header>
<!-- Government Schemes Section -->
<main id="schemes" class="container my-5">
<div class="text-center mb-5">
<h2>Government Schemes</h2>
<p class="lead">Explore central and state government schemes to support your farming activities.</p>
</div>
<div class="row g-4">
<?php if (empty($schemes)): ?>
<div class="col">
<div class="alert alert-warning" role="alert">
Could not load schemes at the moment. Please try again later.
</div>
</div>
<?php else: ?>
<?php foreach ($schemes as $scheme): ?>
<div class="col-md-6 col-lg-4 d-flex align-items-stretch">
<div class="card scheme-card w-100">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?php echo htmlspecialchars($scheme['name']); ?></h5>
<p class="card-text flex-grow-1"><?php echo htmlspecialchars($scheme['description']); ?></p>
<div class="mt-auto">
<a href="scheme.php?id=<?php echo $scheme['id']; ?>" class="btn btn-outline-secondary btn-sm">Learn More</a>
<?php if (isset($_SESSION['farmer_id'])):
$apply_url = 'apply.php?scheme_id=' . $scheme['id'];
$apply_text = 'Apply Now';
else:
$apply_url = 'register.php';
$apply_text = 'Register to Apply';
endif; ?>
<a href="<?php echo $apply_url; ?>" class="btn btn-primary btn-sm"><?php echo $apply_text; ?></a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</main>
<!-- Footer -->
<footer class="footer">
<div class="container">
<p>&copy; <?php echo date('Y'); ?> Smart Farmer Support System. All Rights Reserved.</p>
<p>Developed by JAY | Senior Project 2025.</p>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS -->
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>
</html>

88
login.php Normal file
View File

@ -0,0 +1,88 @@
<?php
require_once 'db/config.php';
$error_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = $_POST['email'];
$password = $_POST['password'];
if (empty($email) || empty($password)) {
$error_message = "Please enter both email and password.";
} else {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM farmers WHERE email = ?");
$stmt->execute([$email]);
$farmer = $stmt->fetch();
if ($farmer && password_verify($password, $farmer['password'])) {
// Start the session just before setting session variables
session_start();
$_SESSION['farmer_id'] = $farmer['id'];
$_SESSION['farmer_name'] = $farmer['full_name'];
header("Location: dashboard.php");
exit();
} else {
$error_message = "Invalid email or password.";
}
} catch (PDOException $e) {
$error_message = "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>Login - Smart Farmer</title>
<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>
<?php include 'partials/navbar.php'; ?>
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card shadow-sm">
<div class="card-body p-5">
<h2 class="card-title text-center mb-4">Farmer Login</h2>
<?php if (!empty($error_message)): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<form action="login.php" method="post">
<div class="mb-3">
<label for="email" class="form-label">Email address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-success btn-lg">Login</button>
</div>
</form>
<div class="text-center mt-3">
<p>Don't have an account? <a href="register.php">Register here</a></p>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="bg-light text-center text-lg-start mt-5">
<div class="container p-4">
<p class="text-center">&copy; <?php echo date("Y"); ?> Smart Farmer Support. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

6
logout.php Normal file
View File

@ -0,0 +1,6 @@
<?php
session_start();
session_unset();
session_destroy();
header("Location: index.php");
exit();

38
partials/navbar.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// Ensure session is started on pages that include this file
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
?>
<nav class="navbar navbar-expand-lg navbar-dark bg-success shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">
<i class="bi bi-tree-fill me-2"></i>Smart Farmer
</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 ms-auto">
<li class="nav-item">
<a class="nav-link" href="index.php">Home</a>
</li>
<?php if (isset($_SESSION['farmer_id'])): ?>
<li class="nav-item">
<a class="nav-link" href="dashboard.php">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link" href="logout.php">Logout</a>
</li>
<?php else: ?>
<li class="nav-item">
<a class="nav-link" href="login.php">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="register.php">Register</a>
</li>
<?php endif; ?>
</ul>
</div>
</div>
</nav>

143
register.php Normal file
View File

@ -0,0 +1,143 @@
<?php
require_once __DIR__ . '/db/config.php';
$errors = [];
$success = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$full_name = trim($_POST['full_name'] ?? '');
$email = trim($_POST['email'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$district = trim($_POST['district'] ?? '');
$password = $_POST['password'] ?? '';
$password_confirm = $_POST['password_confirm'] ?? '';
if (empty($full_name)) {
$errors[] = 'Full name is required.';
}
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'A valid email is required.';
}
if (empty($password)) {
$errors[] = 'Password is required.';
}
if (strlen($password) < 8) {
$errors[] = 'Password must be at least 8 characters long.';
}
if ($password !== $password_confirm) {
$errors[] = 'Passwords do not match.';
}
// Check if email already exists
if (empty($errors)) {
try {
$stmt = db()->prepare("SELECT id FROM farmers WHERE email = ?");
$stmt->execute([$email]);
if ($stmt->fetch()) {
$errors[] = 'An account with this email already exists.';
}
} catch (PDOException $e) {
$errors[] = 'Database error. Please try again later.';
error_log($e->getMessage());
}
}
if (empty($errors)) {
try {
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = db()->prepare("INSERT INTO farmers (full_name, email, phone, district, password) VALUES (?, ?, ?, ?, ?)");
$stmt->execute([$full_name, $email, $phone, $district, $hashed_password]);
$success = 'Registration successful! You can now <a href="login.php">log in</a>.';
} catch (PDOException $e) {
$errors[] = 'Could not create account. Please try again later.';
error_log($e->getMessage());
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Smart Farmer</title>
<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>
<?php include 'partials/navbar.php'; ?>
<!-- Registration Form Section -->
<main class="container my-5">
<div class="row justify-content-center">
<div class="col-md-8 col-lg-6">
<div class="card">
<div class="card-body p-5">
<h2 class="text-center mb-4">Create an Account</h2>
<?php if (!empty($errors)): ?>
<div class="alert alert-danger">
<?php foreach ($errors as $error): ?>
<p class="mb-0"><?php echo htmlspecialchars($error); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if ($success): ?>
<div class="alert alert-success">
<p class="mb-0"><?php echo $success; ?></p>
</div>
<?php else: ?>
<form action="register.php" method="post">
<div class="mb-3">
<label for="full_name" class="form-label">Full Name</label>
<input type="text" class="form-control" id="full_name" name="full_name" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email Address</label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone Number (Optional)</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="district" class="form-label">District (Optional)</label>
<input type="text" class="form-control" id="district" name="district">
</div>
<div class="mb-3">
<label for="password" class="form-label">Password</label>
<input type="password" class="form-control" id="password" name="password" required>
</div>
<div class="mb-3">
<label for="password_confirm" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="password_confirm" name="password_confirm" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-primary">Register</button>
</div>
</form>
<?php endif; ?>
<div class="text-center mt-3">
<p>Already have an account? <a href="login.php">Login here</a></p>
</div>
</div>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="footer">
<div class="container">
<p>&copy; <?php echo date('Y'); ?> Smart Farmer Support System. All Rights Reserved.</p>
<p>Developed by JAY | Senior Project 2025.</p>
</div>
</footer>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

124
scheme.php Normal file
View File

@ -0,0 +1,124 @@
<?php
require_once 'db/config.php';
$scheme_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($scheme_id === 0) {
header("Location: index.php");
exit();
}
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM schemes WHERE id = ?");
$stmt->execute([$scheme_id]);
$scheme = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// For development: error_log($e->getMessage());
// For production, show a generic error and log the details.
die("Error: Could not connect to the database.");
}
if (!$scheme) {
// Redirect if scheme not found
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo htmlspecialchars($scheme['name']); ?> - Smart Farmer</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css">
<style>
.card-header h3 {
margin-bottom: 0;
font-size: 1.5rem;
color: #28a745;
}
</style>
</head>
<body>
<?php include 'partials/navbar.php'; ?>
<header class="bg-success text-white text-center py-5 shadow-sm">
<div class="container">
<h1 class="display-4"><?php echo htmlspecialchars($scheme['name']); ?></h1>
<p class="lead"><?php echo htmlspecialchars($scheme['description']); ?></p>
</div>
</header>
<main class="container my-5">
<?php if (isset($_SESSION['message'])):
$message = $_SESSION['message'];
unset($_SESSION['message']);
?>
<div class="alert alert-<?php echo htmlspecialchars($message['type']); ?> alert-dismissible fade show" role="alert">
<?php echo htmlspecialchars($message['text']); ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<div class="row">
<div class="col-lg-10 mx-auto">
<div class="card mb-4 shadow-sm">
<div class="card-header bg-light">
<h3><i class="bi bi-check-circle-fill me-2"></i>Eligibility</h3>
</div>
<div class="card-body">
<p class="card-text"><?php echo nl2br(htmlspecialchars($scheme['eligibility'])); ?></p>
</div>
</div>
<div class="card mb-4 shadow-sm">
<div class="card-header bg-light">
<h3><i class="bi bi-gift-fill me-2"></i>Benefits</h3>
</div>
<div class="card-body">
<p class="card-text"><?php echo nl2br(htmlspecialchars($scheme['benefits'])); ?></p>
</div>
</div>
<div class="card mb-4 shadow-sm">
<div class="card-header bg-light">
<h3><i class="bi bi-person-lines-fill me-2"></i>How to Apply</h3>
</div>
<div class="card-body">
<p class="card-text"><?php echo nl2br(htmlspecialchars($scheme['how_to_apply'])); ?></p>
</div>
</div>
<div class="text-center mt-5">
<a href="index.php#schemes" class="btn btn-success btn-lg"><i class="bi bi-arrow-left-circle me-2"></i>Back to Schemes</a>
<?php if (isset($_SESSION['farmer_id'])):
$apply_url = 'apply.php?scheme_id=' . $scheme['id'];
$apply_text = 'Apply Now';
$apply_icon = 'bi-check-circle-fill';
else:
$apply_url = 'register.php';
$apply_text = 'Register to Apply';
$apply_icon = 'bi-person-plus-fill';
endif; ?>
<a href="<?php echo $apply_url; ?>" class="btn btn-primary btn-lg">
<i class="bi <?php echo $apply_icon; ?> me-2"></i><?php echo $apply_text; ?>
</a>
</div>
</div>
</div>
</main>
<footer class="bg-dark text-white text-center py-4 mt-5">
<div class="container">
<p class="mb-0">&copy; <?php echo date("Y"); ?> Smart Farmer Support System. All Rights Reserved.</p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>