PNG IHDR x sBIT|d pHYs + tEXtSoftware www.inkscape.org< ,tEXtComment
<?php
// Turn on error reporting for debugging
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
// Ensure includes exist
if (!file_exists('includes/connect.php') || !file_exists('includes/functions.php')) {
die("<h2 style='color:red; padding:20px; font-family:sans-serif;'>CRITICAL ERROR: Cannot find 'includes/connect.php' or 'includes/functions.php'. Please check your file paths.</h2>");
}
require_once('includes/connect.php');
require_once('includes/functions.php');
// Handle Logout
if (isset($_GET['l'])) {
admlogout();
header("location: logout.php");
exit();
}
// Authentication Check
if(!isset($_SESSION['pass'])) {
header("location: login.php");
exit();
}
if (empty($_SESSION['csrf_token'])) {
$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
$alertMessage = "";
$alertType = "";
// =========================================================
// 1. HANDLE DELETING A PROPERTY
// =========================================================
if (isset($_GET['delete_id'])) {
$delId = intval($_GET['delete_id']);
// Optional: Fetch the image URL to delete the physical file too
$getImg = $conn->query("SELECT image_url FROM real_estate_projects WHERE id = $delId");
if ($getImg && $getImg->num_rows > 0) {
$imgRow = $getImg->fetch_assoc();
$imgPath = "../" . $imgRow['image_url'];
if (file_exists($imgPath) && !is_dir($imgPath)) {
unlink($imgPath); // Delete the image file
}
}
$stmtDel = $conn->prepare("DELETE FROM real_estate_projects WHERE id = ?");
if ($stmtDel) {
$stmtDel->bind_param("i", $delId);
if ($stmtDel->execute()) {
$alertMessage = "Property deleted successfully.";
$alertType = "success";
} else {
$alertMessage = "Failed to delete property.";
$alertType = "error";
}
$stmtDel->close();
}
}
// =========================================================
// 2. HANDLE REAL ESTATE UPLOAD
// =========================================================
if (isset($_POST['add_real_estate'])) {
if (!isset($_POST['csrf_token']) || !hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])) {
$alertMessage = "Security validation failed.";
$alertType = "error";
} else {
$title = trim($_POST['title']);
$description = trim($_POST['description']);
$min_investment = floatval($_POST['min_investment']);
$roi = floatval($_POST['roi_percentage']);
$duration = trim($_POST['duration_options']);
$type = trim($_POST['project_type']);
$acres = trim($_POST['acres']);
$strategy = trim($_POST['strategy']);
$why = trim($_POST['why_project']);
$status = trim($_POST['status']);
// Handle Image Upload
if (isset($_FILES['re_image']) && $_FILES['re_image']['error'] === UPLOAD_ERR_OK) {
$fileTmpPath = $_FILES['re_image']['tmp_name'];
$fileSize = $_FILES['re_image']['size'];
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $fileTmpPath);
finfo_close($finfo);
$allowedMimeTypes = ['image/jpeg', 'image/png', 'image/jpg'];
if (!in_array($mimeType, $allowedMimeTypes) || $fileSize > (5 * 1024 * 1024)) {
$alertMessage = "Invalid image format or size exceeds 5MB. Please upload JPG or PNG.";
$alertType = "error";
} else {
// Ensure the uploads directory exists on the frontend side (../uploads/realestate)
$uploadDir = '../uploads/realestate/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
$ext = ($mimeType === 'image/png') ? 'png' : 'jpg';
$newFileName = 'prop_' . time() . '_' . rand(1000,9999) . '.' . $ext;
$dest_path = $uploadDir . $newFileName;
// Store the relative path for the frontend database
$db_image_path = 'uploads/realestate/' . $newFileName;
if (move_uploaded_file($fileTmpPath, $dest_path)) {
// Insert into Database
$stmt = $conn->prepare("INSERT INTO real_estate_projects (title, description, image_url, min_investment, roi_percentage, duration_options, project_type, acres, strategy, why_project, status) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
$stmt->bind_param("sssdsssssss", $title, $description, $db_image_path, $min_investment, $roi, $duration, $type, $acres, $strategy, $why, $status);
if ($stmt->execute()) {
$alertMessage = "Real Estate Project published successfully!";
$alertType = "success";
} else {
$alertMessage = "Database error saving project.";
$alertType = "error";
}
$stmt->close();
} else {
$alertMessage = "Error moving uploaded file. Check folder permissions.";
$alertType = "error";
}
}
} else {
$alertMessage = "Please upload an image for the property.";
$alertType = "error";
}
}
}
// =========================================================
// 3. FETCH ALL REAL ESTATE PROJECTS
// =========================================================
$realEstateProjects = [];
try {
$reQuery = $conn->query("SELECT * FROM real_estate_projects ORDER BY created_at DESC");
if ($reQuery) {
while ($row = $reQuery->fetch_assoc()) {
$realEstateProjects[] = $row;
}
}
} catch (Exception $e) {
// Fail silently if table is empty
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Melody Admin - Manage Real Estate</title>
<link rel="stylesheet" href="vendors/iconfonts/font-awesome/css/all.min.css">
<link rel="stylesheet" href="vendors/css/vendor.bundle.base.css">
<link rel="stylesheet" href="vendors/css/vendor.bundle.addons.css">
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" href="images/favicon.html" />
<style>
.upload-zone { border: 2px dashed #444; padding: 30px; border-radius: 8px; text-align: center; cursor: pointer; background: #2c2f36; transition: 0.2s; position: relative; overflow: hidden;}
.upload-zone:hover { border-color: #31acee; }
.image-preview { position: absolute; top:0; left:0; width:100%; height:100%; object-fit: cover; display:none; }
.table img.property-img { width: 60px; height: 60px; border-radius: 8px; object-fit: cover; }
/* Alerts */
.alert-msg { padding: 1rem; border-radius: 8px; margin-bottom: 1.5rem; font-size: 0.95em; font-weight: bold;}
.alert-error { background-color: rgba(244, 67, 54, 0.1); color: #EF5350; border: 1px solid rgba(244, 67, 54, 0.5);}
.alert-success { background-color: rgba(38, 166, 154, 0.1); color: #26A69A; border: 1px solid rgba(38, 166, 154, 0.5);}
</style>
</head>
<body>
<div class="container-scroller">
<nav class="navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row default-layout-navbar">
<div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-center">
<a class="navbar-brand brand-logo" href="index.php"><img src="images/logo-mini.svg" alt="logo"/></a>
<a class="navbar-brand brand-logo-mini" href="index.php"><img src="images/logo-mini.svg" alt="logo"/></a>
</div>
<div class="navbar-menu-wrapper d-flex align-items-stretch">
<button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
<span class="fas fa-bars"></span>
</button>
<ul class="navbar-nav navbar-nav-right">
<li class="nav-item nav-profile dropdown">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown" id="profileDropdown">
<img src="images/faces/face5.jpg" alt="profile"/>
</a>
<div class="dropdown-menu dropdown-menu-right navbar-dropdown" aria-labelledby="profileDropdown">
<a href="cp.php" class="dropdown-item">
<i class="fas fa-cog text-primary"></i> Settings
</a>
<div class="dropdown-divider"></div>
<a href="index.php?l" class="dropdown-item">
<i class="fas fa-power-off text-primary"></i> Logout
</a>
</div>
</li>
</ul>
<button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
<span class="fas fa-bars"></span>
</button>
</div>
</nav>
<div class="container-fluid page-body-wrapper">
<nav class="sidebar sidebar-offcanvas" id="sidebar">
<ul class="nav">
<li class="nav-item nav-profile">
<div class="nav-link">
<div class="profile-image">
<img src="images/faces/face5.jpg" alt="image"/>
</div>
<div class="profile-name">
<p class="name">Welcome Jane</p>
<p class="designation">Super Admin</p>
</div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="index.php">
<i class="fa fa-home menu-icon"></i>
<span class="menu-title"><b>Admin Dashboard</b></span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#page-layouts" aria-expanded="false" aria-controls="page-layouts">
<i class="fab fa-trello menu-icon"></i>
<span class="menu-title">Member</span>
<i class="menu-arrow"></i>
</a>
<div class="collapse" id="page-layouts">
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="topup.php">Top up</a></li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#sidebar-layouts" aria-expanded="false" aria-controls="sidebar-layouts">
<i class="fas fa-columns menu-icon"></i>
<span class="menu-title">Transaction</span>
<i class="menu-arrow"></i>
</a>
<div class="collapse" id="sidebar-layouts">
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="transaction.php">View Transaction</a></li>
<li class="nav-item"> <a class="nav-link" href="withdrawal.php">Withdrawal</a></li>
<li class="nav-item"> <a class="nav-link" href="admin_deposits.php">View Deposits</a></li>
<li class="nav-item"> <a class="nav-link" href="trash.php">Trash</a></li>
</ul>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="admin_trades.php">
<i class="fas fa-chart-line menu-icon"></i>
<span class="menu-title">Set Trades</span>
</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="admin_realestate.php">
<i class="fas fa-building menu-icon"></i>
<span class="menu-title">Real Estate</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="acc.php">
<i class="fa fa-user menu-icon"></i>
<span class="menu-title">Account</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="notification.php">
<i class="fa fa-envelope menu-icon"></i>
<span class="menu-title">Send Notification</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="qmail.php">
<i class="fa fa-envelope menu-icon"></i>
<span class="menu-title">Send Email</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="collapse" href="#ui-basic" aria-expanded="false" aria-controls="ui-basic">
<i class="far fa-compass menu-icon"></i>
<span class="menu-title">Settings</span>
<i class="menu-arrow"></i>
</a>
<div class="collapse" id="ui-basic">
<ul class="nav flex-column sub-menu">
<li class="nav-item"> <a class="nav-link" href="cp.php">Change password</a></li>
<li class="nav-item"> <a class="nav-link" href="script.php">Live chat Script</a></li>
<li class="nav-item"> <a class="nav-link" href="eth.php">Ethereum Address</a></li>
<li class="nav-item"> <a class="nav-link" href="usdt.php">Usdt-Trc20 Address</a></li>
<li class="nav-item"> <a class="nav-link" href="btc.php">Bitcoin Address</a></li>
</ul>
</div>
</li>
</ul>
</nav>
<div class="main-panel">
<div class="content-wrapper">
<?php if(!empty($alertMessage)): ?>
<div class="alert-msg <?php echo $alertType === 'success' ? 'alert-success' : 'alert-error'; ?>">
<?php echo $alertMessage; ?>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-5 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Add New Property</h4>
<p class="card-description"> Publish a new real estate project for users to invest in. </p>
<form class="forms-sample" method="POST" action="admin_realestate.php" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="<?php echo $_SESSION['csrf_token']; ?>">
<div class="form-group">
<label>Property Image (JPG/PNG)</label>
<div class="upload-zone" id="re-upload-zone">
<div id="upload-text" style="color:#aaa;">Click or Drag Image Here</div>
<img id="re-image-preview" class="image-preview" src="">
</div>
<input type="file" name="re_image" id="re-file-input" accept="image/jpeg, image/png" style="display:none;" required>
</div>
<div class="form-group">
<label>Property Title</label>
<input type="text" class="form-control" name="title" placeholder="e.g. Downtown Luxury Condos" required>
</div>
<div class="form-group">
<label>Project Type</label>
<input type="text" class="form-control" name="project_type" placeholder="e.g. Residential Multi-Family" required>
</div>
<div class="form-group">
<label>Short Description</label>
<textarea class="form-control" name="description" rows="3" placeholder="Brief overview..." required></textarea>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label>Min. Investment ($)</label>
<input type="number" step="0.01" class="form-control" name="min_investment" placeholder="5000" required>
</div>
<div class="col-md-6 form-group">
<label>Expected ROI (%)</label>
<input type="number" step="0.1" class="form-control" name="roi_percentage" placeholder="12.5" required>
</div>
</div>
<div class="row">
<div class="col-md-6 form-group">
<label>Acres / Size</label>
<input type="text" class="form-control" name="acres" placeholder="e.g. 2.5 Acres" required>
</div>
<div class="col-md-6 form-group">
<label>Investment Strategy</label>
<input type="text" class="form-control" name="strategy" placeholder="e.g. Value-Add" required>
</div>
</div>
<div class="form-group">
<label>Duration Options (Comma Separated)</label>
<input type="text" class="form-control" name="duration_options" placeholder="e.g. 6 Months, 12 Months" required>
</div>
<div class="form-group">
<label>Why this project? (Detailed)</label>
<textarea class="form-control" name="why_project" rows="4" placeholder="Explain the investment thesis..." required></textarea>
</div>
<div class="form-group">
<label>Status</label>
<select class="form-control" name="status" required>
<option value="open">Open (Available to investors)</option>
<option value="closed">Closed (Fully funded)</option>
</select>
</div>
<button type="submit" name="add_real_estate" class="btn btn-primary mr-2 btn-block">Publish Property</button>
</form>
</div>
</div>
</div>
<div class="col-md-7 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4 class="card-title">Manage Published Projects</h4>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Image</th>
<th>Title</th>
<th>Min Inv.</th>
<th>ROI</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (!empty($realEstateProjects)): ?>
<?php foreach ($realEstateProjects as $project): ?>
<tr>
<td>
<img src="../<?php echo htmlspecialchars($project['image_url']); ?>" alt="Property" class="property-img">
</td>
<td style="font-weight:bold;"><?php echo htmlspecialchars($project['title']); ?></td>
<td style="color:#26A69A; font-weight:bold;">$<?php echo number_format($project['min_investment'], 2); ?></td>
<td><?php echo $project['roi_percentage']; ?>%</td>
<td>
<?php if($project['status'] == 'open'): ?>
<label class="badge badge-success">Open</label>
<?php else: ?>
<label class="badge badge-danger">Closed</label>
<?php endif; ?>
</td>
<td>
<a href="admin_realestate.php?delete_id=<?php echo $project['id']; ?>" class="badge badge-danger" onclick="return confirm('Are you sure you want to delete this property?');">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="6" style="text-align:center;">No properties published yet.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<footer class="footer">
<div class="d-sm-flex justify-content-center justify-content-sm-between">
<span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © <?php echo date('Y'); ?>. All rights reserved.</span>
</div>
</footer>
</div>
</div>
</div>
<script src="vendors/js/vendor.bundle.base.js"></script>
<script src="vendors/js/vendor.bundle.addons.js"></script>
<script src="js/off-canvas.js"></script>
<script src="js/hoverable-collapse.js"></script>
<script src="js/misc.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Image Upload Preview Logic
const reUploadZone = document.getElementById('re-upload-zone');
const reFileInput = document.getElementById('re-file-input');
const rePreview = document.getElementById('re-image-preview');
const reText = document.getElementById('upload-text');
if(reUploadZone && reFileInput) {
reUploadZone.addEventListener('click', () => reFileInput.click());
reFileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(event) {
rePreview.src = event.target.result;
rePreview.style.display = 'block';
reText.style.display = 'none';
}
reader.readAsDataURL(file);
}
});
// Drag and drop effects
reUploadZone.addEventListener('dragover', (e) => {
e.preventDefault();
reUploadZone.style.borderColor = '#31acee';
});
reUploadZone.addEventListener('dragleave', (e) => {
e.preventDefault();
reUploadZone.style.borderColor = '#444';
});
reUploadZone.addEventListener('drop', (e) => {
e.preventDefault();
reUploadZone.style.borderColor = '#444';
if (e.dataTransfer.files.length) {
reFileInput.files = e.dataTransfer.files;
reFileInput.dispatchEvent(new Event('change'));
}
});
}
});
</script>
</body>
</html>
b IDATxytVսϓ22 A@IR:hCiZ[v*E:WũZA ^dQeQ @ !jZ'>gsV仿$|?g)&x-E