From 3db54a0124e16917c51ff322c428d2b5e1bf5644 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 26 Oct 2025 12:42:58 +0000 Subject: [PATCH] 3.0 --- create_ad.php | 186 ++++++++++++++++++++++++++++++++++++++++++++++ disputes_user.php | 54 ++++++++++++++ index.php | 175 ++++++++++++++++++++++++++++--------------- initiate_deal.php | 146 ++++++++++++++++++++++++++++++++++++ login.php | 9 +++ logout.php | 9 +++ my_deals.php | 140 ++++++++++++++++++++++++++++++++++ profile.php | 54 ++++++++++++++ user_ads.php | 126 +++++++++++++++++++++++++++++++ user_settings.php | 54 ++++++++++++++ wallet.php | 54 ++++++++++++++ 11 files changed, 949 insertions(+), 58 deletions(-) create mode 100644 create_ad.php create mode 100644 disputes_user.php create mode 100644 initiate_deal.php create mode 100644 login.php create mode 100644 logout.php create mode 100644 my_deals.php create mode 100644 profile.php create mode 100644 user_ads.php create mode 100644 user_settings.php create mode 100644 wallet.php diff --git a/create_ad.php b/create_ad.php new file mode 100644 index 0000000..061034a --- /dev/null +++ b/create_ad.php @@ -0,0 +1,186 @@ + $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(); + } + } +} + +?> + + + + + + Create New Ad + + + + + + + + +
+
+
+
+
+

Create a New Advertisement

+

Fill out the form below to post your ad.

+
+
+ +
+ + +
+ + +
+ +
+ +
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+
+
+
+
+ + + + + + \ No newline at end of file diff --git a/disputes_user.php b/disputes_user.php new file mode 100644 index 0000000..9f3de88 --- /dev/null +++ b/disputes_user.php @@ -0,0 +1,54 @@ + true, + 'nickname' => 'TestUser', +]; +?> + + + + + + Споры + + + + + + + + +
+

Активные споры

+
Эта страница находится в разработке. Здесь будут отображаться ваши активные споры.
+ Назад на главную +
+ + + + + + diff --git a/index.php b/index.php index da24246..45508db 100644 --- a/index.php +++ b/index.php @@ -1,68 +1,127 @@ true, + 'nickname' => 'TestUser', + 'rating' => 4.9, + 'telegram_id' => '123456789' +]; -$phpVersion = PHP_VERSION; -$now = date('Y-m-d H:i:s'); ?> - + - - - New Style - - - - - - - - - - - - - - - - - - - - + + + Панель пользователя + + + -
-
-

P2P Crypto Exchange Bot

-

This is the web interface for your Telegram-based P2P exchange.

-
-

The initial admin dashboard is ready for review.

- View Admin Dashboard + +
- + + +
+
+
+
+
+

Добро пожаловать, !

+

Ваша панель для управления P2P-сделками. Отсюда вы можете управлять объявлениями, кошельком и настройками.

+
+
+
+
+ +
+
+
+
+ +
Кошелек
+

Просмотр баланса и истории транзакций.

+ Перейти к кошельку +
+
+
+
+
+
+ +
Объявления
+

Просмотр и управление текущими объявлениями.

+ Смотреть объявления +
+
+
+
+
+
+ +
Создать объявление
+

Создайте новое объявление о покупке или продаже.

+ Создать +
+
+
+
+ + + +
+ + + + - + \ No newline at end of file diff --git a/initiate_deal.php b/initiate_deal.php new file mode 100644 index 0000000..aed641d --- /dev/null +++ b/initiate_deal.php @@ -0,0 +1,146 @@ +prepare( + "SELECT a.*, u.nickname AS seller_nickname, u.rating AS seller_rating + FROM ads a + JOIN users u ON a.user_id = u.id + WHERE a.id = :ad_id AND a.status = 'ACTIVE'" + ); + $stmt->bindParam(':ad_id', $ad_id, PDO::PARAM_INT); + $stmt->execute(); + $ad = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$ad) { + $error = "Ad not found or is no longer active."; + } +} catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); +} + +// Handle form submission +if ($_SERVER['REQUEST_METHOD'] === 'POST' && $ad) { + $amount_crypto = $_POST['amount_crypto'] ?? 0; + $amount_fiat = 0; + + // Basic validation + if (!is_numeric($amount_crypto) || $amount_crypto <= 0) { + $error = "Please enter a valid amount."; + } else { + $amount_fiat = $amount_crypto * $ad['fixed_price']; + if ($amount_fiat < $ad['min_amount'] || $amount_fiat > $ad['max_amount']) { + $error = "The amount is not within the ad's limits."; + } elseif ($amount_crypto > $ad['available_amount']) { + $error = "The requested amount exceeds the available amount in the ad."; + } else { + // All good, create the order + try { + $buyer_id = $current_user_id; + $seller_id = $ad['user_id']; + $status = 'AWAITING_PAYMENT'; // Or PENDING_CONFIRMATION depending on flow + + $pdo->beginTransaction(); + + // Create the order + $order_stmt = $pdo->prepare( + "INSERT INTO orders (ad_id, buyer_id, seller_id, amount_crypto, amount_fiat, status) + VALUES (:ad_id, :buyer_id, :seller_id, :amount_crypto, :amount_fiat, :status)" + ); + $order_stmt->execute([ + ':ad_id' => $ad_id, + ':buyer_id' => $buyer_id, + ':seller_id' => $seller_id, + ':amount_crypto' => $amount_crypto, + ':amount_fiat' => $amount_fiat, + ':status' => $status + ]); + + // Reduce available amount in the ad + $ad_update_stmt = $pdo->prepare("UPDATE ads SET available_amount = available_amount - :amount_crypto WHERE id = :ad_id"); + $ad_update_stmt->execute([':amount_crypto' => $amount_crypto, ':ad_id' => $ad_id]); + + $pdo->commit(); + + // Redirect to deals page + header("Location: my_deals.php"); + exit; + + } catch (PDOException $e) { + $pdo->rollBack(); + $error = "Failed to create the deal. Error: " . $e->getMessage(); + } + } + } +} + +?> + + + + + + Initiate Deal + + + + + + +
+
+
+ +
+ Back to Ads + +
+
+

from

+
+
+ +

Price: per

+

Limits: -

+

Available:

+

Payment Method:

+
+ + +
+
+ + +
+ + Cancel +
+
+
+ +
+
+
+ + diff --git a/login.php b/login.php new file mode 100644 index 0000000..46af985 --- /dev/null +++ b/login.php @@ -0,0 +1,9 @@ +prepare( + "SELECT + o.id, o.ad_id, o.amount_crypto, o.amount_fiat, o.status, o.created_at, + b.nickname AS buyer_nickname, + s.nickname AS seller_nickname, + a.currency, a.payment_currency + FROM orders o + JOIN users b ON o.buyer_id = b.id + JOIN users s ON o.seller_id = s.id + JOIN ads a ON o.ad_id = a.id + WHERE o.buyer_id = :user_id OR o.seller_id = :user_id + ORDER BY o.created_at DESC" + ); + $stmt->bindParam(':user_id', $current_user_id, PDO::PARAM_INT); + $stmt->execute(); + $orders = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); +} + +// Helper to display status with a nice badge +function getStatusBadge($status) { + $map = [ + 'AWAITING_PAYMENT' => 'bg-warning text-dark', + 'AWAITING_SELLER_CONFIRMATION' => 'bg-info text-dark', + 'COMPLETED' => 'bg-success', + 'CANCELED' => 'bg-secondary', + 'DISPUTED' => 'bg-danger', + 'PENDING_CONFIRMATION' => 'bg-light text-dark', + ]; + $class = $map[$status] ?? 'bg-light text-dark'; + $status_text = str_replace('_', ' ', $status); + return "" . htmlspecialchars($status_text) . ""; +} + +?> + + + + + + My Deals + + + + + + + +
+

My Deals

+ + +
+ + + +
You have no deals yet. Find an ad to start one.
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
RoleDeal WithAmountStatusDateAction
+ + BUYING + + SELLING + + + + + +
+ +
+ View +
+
+ +
+ + + + + \ No newline at end of file diff --git a/profile.php b/profile.php new file mode 100644 index 0000000..aa7644e --- /dev/null +++ b/profile.php @@ -0,0 +1,54 @@ + true, + 'nickname' => 'TestUser', +]; +?> + + + + + + Профиль + + + + + + + + +
+

Профиль

+
Эта страница находится в разработке. Здесь будет информация о вашем профиле.
+ Назад на главную +
+ + + + + + diff --git a/user_ads.php b/user_ads.php new file mode 100644 index 0000000..30d3b09 --- /dev/null +++ b/user_ads.php @@ -0,0 +1,126 @@ +query( + "SELECT + a.id, a.ad_type, a.currency, a.payment_currency, a.fixed_price, + a.available_amount, a.min_amount, a.max_amount, a.bank_name, + u.nickname AS seller_nickname, u.rating AS seller_rating + FROM ads a + JOIN users u ON a.user_id = u.id + WHERE a.status = 'ACTIVE' AND a.user_id != {$current_user_id} + ORDER BY a.created_at DESC" + ); + $ads = $stmt->fetchAll(PDO::FETCH_ASSOC); +} catch (PDOException $e) { + $error = "Database error: " . $e->getMessage(); +} + +?> + + + + + + Browse Ads + + + + + + + + +
+
+

Browse Ads

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

No active ads found.

+

Be the first to create one!

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

Seller

+
+
+ + + +
+
+
+
+
+ Price + +
+
+ Available + +
+
+ Limits + - +
+
+ Payment + +
+
+
+
+
+ +
+ +
+ + + + + + \ No newline at end of file diff --git a/user_settings.php b/user_settings.php new file mode 100644 index 0000000..beb7814 --- /dev/null +++ b/user_settings.php @@ -0,0 +1,54 @@ + true, + 'nickname' => 'TestUser', +]; +?> + + + + + + Настройки + + + + + + + + +
+

Настройки

+
Эта страница находится в разработке. Здесь будут настройки вашего профиля.
+ Назад на главную +
+ + + + + + diff --git a/wallet.php b/wallet.php new file mode 100644 index 0000000..8b48222 --- /dev/null +++ b/wallet.php @@ -0,0 +1,54 @@ + true, + 'nickname' => 'TestUser', +]; +?> + + + + + + Кошелек + + + + + + + + +
+

Кошелек

+
Эта страница находится в разработке. Здесь будет отображаться ваш баланс и история транзакций.
+ Назад на главную +
+ + + + + +