186 lines
9.6 KiB
PHP
186 lines
9.6 KiB
PHP
<?php
|
|
// create_ad.php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Hardcoded user ID for demonstration purposes
|
|
// In a real application, you would get this from the session
|
|
$user_id = 1;
|
|
|
|
$message = '';
|
|
$error = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// --- Form Data ---
|
|
$ad_type = $_POST['ad_type'] ?? '';
|
|
$currency = $_POST['currency'] ?? 'TON';
|
|
$payment_currency = $_POST['payment_currency'] ?? 'RUB';
|
|
$fixed_price = $_POST['fixed_price'] ?? null;
|
|
$available_amount = $_POST['available_amount'] ?? null;
|
|
$min_amount = $_POST['min_amount'] ?? null;
|
|
$max_amount = $_POST['max_amount'] ?? null;
|
|
$bank_name = $_POST['bank_name'] ?? '';
|
|
$comment = $_POST['comment'] ?? '';
|
|
|
|
// --- Basic Validation ---
|
|
if (empty($ad_type) || empty($fixed_price) || empty($available_amount) || empty($min_amount) || empty($max_amount) || empty($bank_name)) {
|
|
$error = "Please fill in all required fields.";
|
|
} elseif (!is_numeric($fixed_price) || !is_numeric($available_amount) || !is_numeric($min_amount) || !is_numeric($max_amount)) {
|
|
$error = "Price and amount fields must be numbers.";
|
|
} elseif ($min_amount > $max_amount) {
|
|
$error = "Minimum amount cannot be greater than maximum amount.";
|
|
} elseif ($max_amount > $available_amount) {
|
|
$error = "Maximum amount cannot be greater than the total available amount.";
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare(
|
|
"INSERT INTO ads (user_id, ad_type, currency, payment_currency, price_type, fixed_price, available_amount, min_amount, max_amount, bank_name, comment, status)
|
|
VALUES (:user_id, :ad_type, :currency, :payment_currency, 'FIXED', :fixed_price, :available_amount, :min_amount, :max_amount, :bank_name, :comment, 'ACTIVE')"
|
|
);
|
|
|
|
$stmt->bindParam(':user_id', $user_id, PDO::PARAM_INT);
|
|
$stmt->bindParam(':ad_type', $ad_type, PDO::PARAM_STR);
|
|
$stmt->bindParam(':currency', $currency, PDO::PARAM_STR);
|
|
$stmt->bindParam(':payment_currency', $payment_currency, PDO::PARAM_STR);
|
|
$stmt->bindParam(':fixed_price', $fixed_price);
|
|
$stmt->bindParam(':available_amount', $available_amount);
|
|
$stmt->bindParam(':min_amount', $min_amount);
|
|
$stmt->bindParam(':max_amount', $max_amount);
|
|
$stmt->bindParam(':bank_name', $bank_name, PDO::PARAM_STR);
|
|
$stmt->bindParam(':comment', $comment, PDO::PARAM_STR);
|
|
|
|
if ($stmt->execute()) {
|
|
$message = "Ad created successfully!";
|
|
} else {
|
|
$error = "Failed to create ad. Please try again.";
|
|
}
|
|
} catch (PDOException $e) {
|
|
// In a real app, you'd log this error, not show it to the user
|
|
$error = "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>Create New Ad</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
|
<link href="assets/css/custom.css" rel="stylesheet">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">P2P Platform</a>
|
|
<div class="collapse navbar-collapse">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item"><a class="nav-link" href="index.php"><i class="bi bi-house-door"></i> Dashboard</a></li>
|
|
<li class="nav-item"><a class="nav-link" href="logout.php"><i class="bi bi-box-arrow-right"></i> Logout</a></li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row">
|
|
<div class="col-md-8 offset-md-2">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3 class="card-title">Create a New Advertisement</h3>
|
|
<p class="card-subtitle text-muted">Fill out the form below to post your ad.</p>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-success"><?php echo htmlspecialchars($message); ?></div>
|
|
<?php endif; ?>
|
|
<?php if ($error): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="create_ad.php" method="POST">
|
|
|
|
<div class="mb-3">
|
|
<label class="form-label">I want to:</label>
|
|
<div class="form-check form-check-inline">
|
|
<input class="form-check-input" type="radio" name="ad_type" id="sellRadio" value="SELL" required>
|
|
<label class="form-check-label" for="sellRadio">Sell Crypto</label>
|
|
</div>
|
|
<div class="form-check form-check-inline">
|
|
<input class="form-check-input" type="radio" name="ad_type" id="buyRadio" value="BUY" required>
|
|
<label class="form-check-label" for="buyRadio">Buy Crypto</label>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="currency" class="form-label">Crypto Currency</label>
|
|
<select class="form-select" id="currency" name="currency">
|
|
<option value="TON" selected>TON</option>
|
|
<option value="BTC">BTC</option>
|
|
<option value="USDT">USDT</option>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="payment_currency" class="form-label">Fiat Currency</label>
|
|
<select class="form-select" id="payment_currency" name="payment_currency">
|
|
<option value="RUB" selected>RUB</option>
|
|
<option value="USD">USD</option>
|
|
<option value="EUR">EUR</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="fixed_price" class="form-label">Price per Crypto Unit (in Fiat)</label>
|
|
<input type="number" step="0.01" class="form-control" id="fixed_price" name="fixed_price" placeholder="e.g., 6000.00" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="available_amount" class="form-label">Total Amount of Crypto to Trade</label>
|
|
<input type="number" step="0.00000001" class="form-control" id="available_amount" name="available_amount" placeholder="e.g., 100.0" required>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="min_amount" class="form-label">Minimum Transaction Limit</label>
|
|
<input type="number" step="0.00000001" class="form-control" id="min_amount" name="min_amount" placeholder="e.g., 10.0" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="max_amount" class="form-label">Maximum Transaction Limit</label>
|
|
<input type="number" step="0.00000001" class="form-control" id="max_amount" name="max_amount" placeholder="e.g., 50.0" required>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="bank_name" class="form-label">Payment Method / Bank Name</label>
|
|
<input type="text" class="form-control" id="bank_name" name="bank_name" placeholder="e.g., Sberbank, Tinkoff, etc." required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="comment" class="form-label">Terms & Conditions / Comments</label>
|
|
<textarea class="form-control" id="comment" name="comment" rows="3" placeholder="e.g., Only transfer from verified accounts."></textarea>
|
|
</div>
|
|
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary btn-lg">Create Ad</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<footer class="text-center mt-5 mb-3">
|
|
<p class="text-muted">© <?php echo date("Y"); ?> P2P Platform</p>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|