BLACKSITE
:
216.73.216.140
:
199.188.200.160 / jeddahhousingltd.com
:
Linux server383.web-hosting.com 4.18.0-553.83.1.lve.el8.x86_64 #1 SMP Wed Nov 12 10:04:12 UTC 2025 x86_64
:
/
home
/
jeddveug
/
www
/
admin
/
Upload File:
files >> /home/jeddveug/www/admin/add_pricing.php
<?php require_once __DIR__ . '/../config/db.php'; // Check authentication if (!isset($_SESSION['admin_id'])) { header('Location: login.php'); exit; } $error = ''; $success = ''; // Basic delete functionality if (isset($_GET['delete'])) { $id = (int)$_GET['delete']; $pdo->prepare("DELETE FROM pricings WHERE id = ?")->execute([$id]); // Preserve filter if it exists $redirect = 'add_pricing.php'; if (!empty($_GET['filter_sector'])) { $redirect .= '?filter_sector=' . urlencode($_GET['filter_sector']); } header('Location: ' . $redirect); exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $project_name = trim($_POST['project_name']); $plot_category = trim($_POST['plot_category']); $sector = trim($_POST['sector']); $block_a = (float)$_POST['block_a']; $block_b = (float)$_POST['block_b']; $block_c = (float)$_POST['block_c']; $block_d = (float)$_POST['block_d']; if (empty($plot_category) || empty($sector)) { $error = 'Plot Category and Sector are required.'; } else { try { $stmt = $pdo->prepare("INSERT INTO pricings (project_name, plot_category, sector, block_a, block_b, block_c, block_d) VALUES (?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([$project_name, $plot_category, $sector, $block_a, $block_b, $block_c, $block_d]); $success = 'Pricing data added successfully!'; } catch (PDOException $e) { $error = 'Database error: ' . $e->getMessage(); } } } $admin_page_title = 'Add Pricing Data'; require_once 'includes/header.php'; // Fetch existing pricing data $selected_sector = isset($_GET['filter_sector']) ? $_GET['filter_sector'] : ''; $query = "SELECT * FROM pricings"; $params = []; if (!empty($selected_sector)) { $query .= " WHERE sector = ?"; $params[] = $selected_sector; } $query .= " ORDER BY created_at DESC"; $stmt = $pdo->prepare($query); $stmt->execute($params); $pricings = $stmt->fetchAll(); ?> <div class="max-w-6xl mx-auto"> <div class="flex justify-between items-center mb-6"> <h2 class="text-2xl font-bold text-gray-800">Add Project Pricing</h2> </div> <?php if ($error): ?> <div class="bg-red-50 text-red-600 p-4 rounded-xl mb-6 text-sm flex items-center"> <i class="fas fa-exclamation-circle text-lg mr-3"></i> <?= htmlspecialchars($error) ?> </div> <?php endif; ?> <?php if ($success): ?> <div class="bg-green-50 text-green-600 p-4 rounded-xl mb-6 text-sm flex items-center"> <i class="fas fa-check-circle text-lg mr-3"></i> <?= htmlspecialchars($success) ?> </div> <?php endif; ?> <!-- Form Section --> <div class="bg-white rounded-xl shadow-sm p-6 mb-8"> <form method="POST" action=""> <div class="grid grid-cols-1 md:grid-cols-3 gap-6"> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="project_name">Project Name</label> <select id="project_name" name="project_name" class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> <option value="Jeddah City" selected>Jeddah City</option> <option value="Other Project">Other Project</option> </select> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="plot_category">Plot Category <span class="text-red-500">*</span></label> <input type="text" id="plot_category" name="plot_category" placeholder="e.g. 3 Katha, 5 Katha" required class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="sector">Sector <span class="text-red-500">*</span></label> <select id="sector" name="sector" required class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> <?php for($i=1; $i<=10; $i++): ?> <option value="Sector <?= $i ?>">Sector <?= $i ?></option> <?php endfor; ?> </select> </div> </div> <div class="grid grid-cols-2 md:grid-cols-4 gap-6 mt-6"> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="block_a">Block A Data</label> <input type="number" step="any" id="block_a" name="block_a" value="0" class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="block_b">Block B Data</label> <input type="number" step="any" id="block_b" name="block_b" value="0" class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="block_c">Block C Data</label> <input type="number" step="any" id="block_c" name="block_c" value="0" class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> </div> <div> <label class="block text-sm font-medium text-gray-700 mb-2" for="block_d">Block D Data</label> <input type="number" step="any" id="block_d" name="block_d" value="0" class="w-full px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all text-sm"> </div> </div> <div class="flex justify-end pt-6 mt-6 border-t border-gray-100"> <button type="submit" class="bg-primary-600 hover:bg-primary-700 text-white px-8 py-2.5 rounded-lg text-sm font-medium transition-colors shadow-sm"> <i class="fas fa-plus mr-2"></i> Add Pricing Entry </button> </div> </form> </div> <!-- Data Table Section --> <div class="bg-white rounded-xl shadow-sm overflow-hidden"> <div class="p-6 border-b border-gray-100 flex flex-col md:flex-row md:items-center justify-between gap-4"> <h3 class="font-bold text-gray-800">Current Pricing Data</h3> <div class="flex items-center gap-3"> <label for="filter_sector" class="text-sm text-gray-500 whitespace-nowrap">Filter by Sector:</label> <select id="filter_sector" class="text-sm px-3 py-1.5 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500 transition-all bg-gray-50" onchange="window.location.href='add_pricing.php?filter_sector=' + this.value"> <option value="">All Sectors</option> <?php for($i=1; $i<=10; $i++): ?> <option value="Sector <?= $i ?>" <?= $selected_sector == "Sector $i" ? 'selected' : '' ?>>Sector <?= $i ?></option> <?php endfor; ?> </select> </div> </div> <div class="overflow-x-auto"> <table class="w-full text-left text-sm"> <thead class="bg-gray-50 text-gray-600 font-medium border-b border-gray-100"> <tr> <th class="px-6 py-4">Project</th> <th class="px-6 py-4">Category</th> <th class="px-6 py-4">Sector</th> <th class="px-6 py-4 text-center">Block A</th> <th class="px-6 py-4 text-center">Block B</th> <th class="px-6 py-4 text-center">Block C</th> <th class="px-6 py-4 text-center">Block D</th> <th class="px-6 py-4 text-right">Actions</th> </tr> </thead> <tbody class="divide-y divide-gray-100"> <?php if (empty($pricings)): ?> <tr> <td colspan="8" class="px-6 py-8 text-center text-gray-500">No pricing data found. Add your first entry above.</td> </tr> <?php else: ?> <?php foreach ($pricings as $item): ?> <tr class="hover:bg-gray-50/50 transition-colors"> <td class="px-6 py-4 font-medium text-gray-800"><?= htmlspecialchars($item['project_name']) ?></td> <td class="px-6 py-4 text-gray-600"><?= htmlspecialchars($item['plot_category']) ?></td> <td class="px-6 py-4 text-gray-600"><?= htmlspecialchars($item['sector']) ?></td> <td class="px-6 py-4 text-center text-gray-600 font-mono"><?= number_format($item['block_a'], 2) ?></td> <td class="px-6 py-4 text-center text-gray-600 font-mono"><?= number_format($item['block_b'], 2) ?></td> <td class="px-6 py-4 text-center text-gray-600 font-mono"><?= number_format($item['block_c'], 2) ?></td> <td class="px-6 py-4 text-center text-gray-600 font-mono"><?= number_format($item['block_d'], 2) ?></td> <td class="px-6 py-4 text-right"> <a href="add_pricing.php?delete=<?= $item['id'] ?><?= !empty($selected_sector) ? '&filter_sector=' . urlencode($selected_sector) : '' ?>" class="text-red-500 hover:text-red-700 transition-colors" onclick="return confirm('Are you sure?')"> <i class="fas fa-trash-alt"></i> </a> </td> </tr> <?php endforeach; ?> <?php endif; ?> </tbody> </table> </div> </div> </div> <?php require_once 'includes/footer.php'; ?>