diff --git a/admin/add_scheme.php b/admin/add_scheme.php new file mode 100644 index 0000000..a8b5fca --- /dev/null +++ b/admin/add_scheme.php @@ -0,0 +1,125 @@ +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(); + } + } +} +?> + + + + + + Add New Scheme - Admin + + + + + + +
+
+

Add New Scheme

+ + Back to Schemes + +
+ + +
+ Please correct the following errors: + +
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + + + diff --git a/admin/dashboard.php b/admin/dashboard.php new file mode 100644 index 0000000..92411c0 --- /dev/null +++ b/admin/dashboard.php @@ -0,0 +1,140 @@ +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']; +?> + + + + + + Admin Dashboard - Smart Farmer + + + + + + +
+
+

Farmer Applications

+
+ + +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDFarmer NameFarmer ContactScheme NameApplied OnStatusAction
No applications found.
+
+ +
+ + + + +
+ + + +
+
+
+
+
+
+ + + + diff --git a/admin/delete_scheme.php b/admin/delete_scheme.php new file mode 100644 index 0000000..bc3ea20 --- /dev/null +++ b/admin/delete_scheme.php @@ -0,0 +1,48 @@ +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; diff --git a/admin/edit_scheme.php b/admin/edit_scheme.php new file mode 100644 index 0000000..a227d36 --- /dev/null +++ b/admin/edit_scheme.php @@ -0,0 +1,158 @@ +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(); + } + } +} +?> + + + + + + Edit Scheme - Admin + + + + + + +
+
+

Edit Scheme

+ + Back to Schemes + +
+ + +
+ Please correct the following errors: + +
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+
+
+ + + + diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 0000000..277be1b --- /dev/null +++ b/admin/index.php @@ -0,0 +1,63 @@ + + + + + + + Admin Login - Smart Farmer + + + + +
+
+
+

Admin Login

+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+ + diff --git a/admin/logout.php b/admin/logout.php new file mode 100644 index 0000000..600ab4d --- /dev/null +++ b/admin/logout.php @@ -0,0 +1,19 @@ +query("SELECT * FROM schemes ORDER BY name ASC"); +$schemes = $stmt->fetchAll(PDO::FETCH_ASSOC); +?> + + + + + + Manage Schemes - Admin + + + + + + +
+
+

Manage Schemes

+ + Add New Scheme + +
+ + +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + +
IDScheme NameActions
No schemes found. Add one now.
+ + Edit + + + Delete + +
+
+
+
+
+ + + + diff --git a/admin/update_status.php b/admin/update_status.php new file mode 100644 index 0000000..e9598a0 --- /dev/null +++ b/admin/update_status.php @@ -0,0 +1,31 @@ +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; diff --git a/apply.php b/apply.php new file mode 100644 index 0000000..1118871 --- /dev/null +++ b/apply.php @@ -0,0 +1,50 @@ +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(); +?> \ No newline at end of file diff --git a/assets/css/custom.css b/assets/css/custom.css new file mode 100644 index 0000000..bf55919 --- /dev/null +++ b/assets/css/custom.css @@ -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; +} diff --git a/dashboard.php b/dashboard.php new file mode 100644 index 0000000..b3bd15c --- /dev/null +++ b/dashboard.php @@ -0,0 +1,123 @@ +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); + +?> + + + + + + Dashboard - Smart Farmer + + + + + + + + +
+
+

Welcome, !

+

This is your personal dashboard. Manage your applications and profile here.

+
+
+ +
+
+ +
+
+
+

My Profile

+ + Edit + +
+
+

Name:

+

Email:

+

Phone:

+

District:

+
+
+
+ + +
+
+
+

My Applications

+
+
+ +
+ You have not applied for any schemes yet. + Explore schemes and apply now. +
+ + + +
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/db/config.php b/db/config.php index 96fb963..2fbc60a 100644 --- a/db/config.php +++ b/db/config.php @@ -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; } diff --git a/db/migrations/001_create_schemes_table.sql b/db/migrations/001_create_schemes_table.sql new file mode 100644 index 0000000..3b36a04 --- /dev/null +++ b/db/migrations/001_create_schemes_table.sql @@ -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 \ No newline at end of file diff --git a/db/migrations/002_create_farmers_table.sql b/db/migrations/002_create_farmers_table.sql new file mode 100644 index 0000000..7c66851 --- /dev/null +++ b/db/migrations/002_create_farmers_table.sql @@ -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; diff --git a/db/migrations/003_create_applications_table.sql b/db/migrations/003_create_applications_table.sql new file mode 100644 index 0000000..4ca0f96 --- /dev/null +++ b/db/migrations/003_create_applications_table.sql @@ -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; diff --git a/db/migrations/004_add_status_to_applications.sql b/db/migrations/004_add_status_to_applications.sql new file mode 100644 index 0000000..21e265e --- /dev/null +++ b/db/migrations/004_add_status_to_applications.sql @@ -0,0 +1 @@ +ALTER TABLE `applications` ADD `status` VARCHAR(255) NOT NULL DEFAULT 'Pending' AFTER `application_date`; diff --git a/edit_profile.php b/edit_profile.php new file mode 100644 index 0000000..7d46bb3 --- /dev/null +++ b/edit_profile.php @@ -0,0 +1,131 @@ +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(); + } + } +} + +?> + + + + + + Edit Profile - Smart Farmer + + + + + + + +
+
+
+
+
+

Edit Your Profile

+
+
+ +
+ + +
+
    + +
  • + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + Back to Dashboard +
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/index.php b/index.php index 7205f3d..3df9285 100644 --- a/index.php +++ b/index.php @@ -1,150 +1,108 @@ 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'); ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - + + + Smart Farmer Support System + + + + + + + + + + + + + + + + + + + + -
-
-

Analyzing your requirements and generating your website…

-
- Loading… -
-

AI is collecting your requirements and applying the first changes.

-

This page will update automatically as the plan is implemented.

-

Runtime: PHP — UTC

-
-
- + + + + +
+
+

Empowering Farmers, Saving Lives.

+

Your one-stop solution for agricultural support, risk assessment, and government schemes in Maharashtra.

+ Explore Schemes +
+
+ + +
+
+

Government Schemes

+

Explore central and state government schemes to support your farming activities.

+
+ +
+ +
+ +
+ + +
+
+
+
+

+
+ Learn More + + +
+
+
+
+ + +
+
+ + + + + + + + - + \ No newline at end of file diff --git a/login.php b/login.php new file mode 100644 index 0000000..319000a --- /dev/null +++ b/login.php @@ -0,0 +1,88 @@ +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(); + } + } +} +?> + + + + + + Login - Smart Farmer + + + + + + + + +
+
+
+
+
+

Farmer Login

+ +
+ +
+
+ + +
+
+ + +
+
+ +
+
+
+

Don't have an account? Register here

+
+
+
+
+
+
+ + + + + + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..1744dc5 --- /dev/null +++ b/logout.php @@ -0,0 +1,6 @@ + + diff --git a/register.php b/register.php new file mode 100644 index 0000000..62aad93 --- /dev/null +++ b/register.php @@ -0,0 +1,143 @@ +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 log in.'; + } catch (PDOException $e) { + $errors[] = 'Could not create account. Please try again later.'; + error_log($e->getMessage()); + } + } +} +?> + + + + + + Register - Smart Farmer + + + + + + + + + +
+
+
+
+
+

Create an Account

+ + +
+ +

+ +
+ + + +
+

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ +
+

Already have an account? Login here

+
+
+
+
+
+
+ + + + + + + + diff --git a/scheme.php b/scheme.php new file mode 100644 index 0000000..fe38557 --- /dev/null +++ b/scheme.php @@ -0,0 +1,124 @@ +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(); +} +?> + + + + + + <?php echo htmlspecialchars($scheme['name']); ?> - Smart Farmer + + + + + + + + + +
+
+

+

+
+
+ +
+ + + + +
+
+
+
+

Eligibility

+
+
+

+
+
+ +
+
+

Benefits

+
+
+

+
+
+ +
+
+

How to Apply

+
+
+

+
+
+ + +
+
+
+ + + + + +