-
-
-
+
+
+
+
+
+
+
+
+
+
+
+ Date
+ Type
+ Amount
+ Description
+
+
+
+
+ No recent transactions.
+
+
+
+
+
+ ₹
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/db/setup.php b/db/setup.php
index 496f6ef..f656ec9 100644
--- a/db/setup.php
+++ b/db/setup.php
@@ -1,21 +1,164 @@
exec($sql);
+ echo $message . "
";
+ } catch (PDOException $e) {
+ // Suppress errors if the alteration already exists, but show others
+ if (!str_contains($e->getMessage(), 'Duplicate') && !str_contains($e->getMessage(), 'already exists') && !str_contains($e->getMessage(), 'Unknown table')) {
+ echo "Error: " . $e->getMessage() . "
";
+ }
+ }
+}
+
try {
$db = db();
- $sql = "CREATE TABLE IF NOT EXISTS `users` (
+
+ // 0. Drop dependent tables first to avoid foreign key issues
+ run_sql($db, "DROP TABLE IF EXISTS `passive_income_schedule`", "Table 'passive_income_schedule' dropped if exists.");
+ run_sql($db, "DROP TABLE IF EXISTS `commissions`", "Table 'commissions' dropped if exists.");
+ run_sql($db, "DROP TABLE IF EXISTS `wallet_ledger`", "Table 'wallet_ledger' dropped if exists.");
+
+ // 1. Users table
+ $sqlUsers = "CREATE TABLE IF NOT EXISTS `users` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`email` VARCHAR(255) NOT NULL UNIQUE,
`password` VARCHAR(255) NOT NULL,
`referral_code` VARCHAR(50) NOT NULL UNIQUE,
`sponsor_id` INT NULL,
- `user_type` ENUM('Normal', 'Silver', 'Gold') NOT NULL DEFAULT 'Normal',
+ `role` ENUM('Super Admin', 'Admin', 'Finance', 'Agent', 'Support') NOT NULL DEFAULT 'Agent',
+ `agent_tier` ENUM('Normal', 'Silver', 'Gold', 'Diamond') NULL DEFAULT 'Normal',
+ `cumulative_bookings` DECIMAL(15, 2) DEFAULT 0.00,
+ `phone` VARCHAR(255) NULL,
+ `company` VARCHAR(255) NULL,
+ `notes` TEXT NULL,
+ `wallet_balance` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
+ `total_direct_income` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
+ `total_team_income` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
+ `total_passive_income` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
+ `total_leg_match_income` DECIMAL(15, 2) NOT NULL DEFAULT 0.00,
`created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (sponsor_id) REFERENCES users(id) ON DELETE SET NULL
)";
- $db->exec($sql);
- echo "Table 'users' created successfully.";
+ run_sql($db, $sqlUsers, "Table 'users' created or already exists.");
+
+ // Add columns to users table if they don't exist
+ run_sql($db, "ALTER TABLE users ADD COLUMN wallet_balance DECIMAL(15, 2) NOT NULL DEFAULT 0.00", "Column 'wallet_balance' added to 'users' table.");
+ run_sql($db, "ALTER TABLE users ADD COLUMN total_direct_income DECIMAL(15, 2) NOT NULL DEFAULT 0.00", "Column 'total_direct_income' added to 'users' table.");
+ run_sql($db, "ALTER TABLE users ADD COLUMN total_team_income DECIMAL(15, 2) NOT NULL DEFAULT 0.00", "Column 'total_team_income' added to 'users' table.");
+ run_sql($db, "ALTER TABLE users ADD COLUMN total_passive_income DECIMAL(15, 2) NOT NULL DEFAULT 0.00", "Column 'total_passive_income' added to 'users' table.");
+ run_sql($db, "ALTER TABLE users ADD COLUMN total_leg_match_income DECIMAL(15, 2) NOT NULL DEFAULT 0.00", "Column 'total_leg_match_income' added to 'users' table.");
+ run_sql($db, "ALTER TABLE users MODIFY cumulative_bookings DECIMAL(15, 2) DEFAULT 0.00", "Column 'cumulative_bookings' in 'users' table modified.");
+ run_sql($db, "ALTER TABLE users MODIFY `role` ENUM('Super Admin', 'Admin', 'Finance', 'Agent', 'Support') NOT NULL DEFAULT 'Agent'", "Column 'role' in 'users' table modified.");
+
+
+ // 2. Bookings table
+ $sqlBookings = "CREATE TABLE IF NOT EXISTS `bookings` (
+ `id` INT AUTO_INCREMENT PRIMARY KEY,
+ `user_id` INT NOT NULL,
+ `plot_id` VARCHAR(255) NOT NULL,
+ `amount` DECIMAL(15, 2) NOT NULL,
+ `booking_date` DATE NOT NULL,
+ `proof_document` VARCHAR(255) NOT NULL,
+ `status` ENUM('pending', 'approved', 'rejected') NOT NULL DEFAULT 'pending',
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+ )";
+ run_sql($db, $sqlBookings, "Table 'bookings' created or already exists.");
+ run_sql($db, "ALTER TABLE bookings MODIFY amount DECIMAL(15, 2) NOT NULL", "Column 'amount' in 'bookings' table modified.");
+
+ // 3. Transactions table (replaces wallet_ledger and commissions)
+ $sqlTransactions = "CREATE TABLE IF NOT EXISTS `transactions` (
+ `id` INT AUTO_INCREMENT PRIMARY KEY,
+ `user_id` INT NOT NULL,
+ `amount` DECIMAL(15, 2) NOT NULL,
+ `type` ENUM('commission_direct', 'commission_team', 'passive_income', 'leg_match_bonus', 'withdrawal', 'withdrawal_fee', 'deposit', 'booking_refund') NOT NULL,
+ `description` TEXT,
+ `related_booking_id` INT NULL,
+ `related_user_id` INT NULL,
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (related_booking_id) REFERENCES bookings(id) ON DELETE SET NULL,
+ FOREIGN KEY (related_user_id) REFERENCES users(id) ON DELETE SET NULL
+ )";
+ run_sql($db, $sqlTransactions, "Table 'transactions' created or already exists.");
+
+ // 4. Withdrawals table
+ $sqlWithdrawals = "CREATE TABLE IF NOT EXISTS `withdrawals` (
+ `id` INT AUTO_INCREMENT PRIMARY KEY,
+ `user_id` INT NOT NULL,
+ `amount` DECIMAL(15, 2) NOT NULL,
+ `status` ENUM('pending', 'approved', 'rejected') NOT NULL DEFAULT 'pending',
+ `rejection_reason` TEXT NULL,
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ `processed_at` TIMESTAMP NULL,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+ )";
+ run_sql($db, $sqlWithdrawals, "Table 'withdrawals' created or already exists.");
+ run_sql($db, "ALTER TABLE withdrawals MODIFY amount DECIMAL(15, 2) NOT NULL", "Column 'amount' in 'withdrawals' table modified.");
+
+ // 5. Leg Milestones table
+ $sqlLegMilestones = "CREATE TABLE IF NOT EXISTS `leg_milestones` (
+ `id` INT AUTO_INCREMENT PRIMARY KEY,
+ `user_id` INT NOT NULL,
+ `leg_user_id` INT NOT NULL, /* The user in the downline whose leg reached the milestone */
+ `milestone_amount` DECIMAL(15, 2) NOT NULL,
+ `bonus_amount` DECIMAL(15, 2) NOT NULL,
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
+ FOREIGN KEY (leg_user_id) REFERENCES users(id) ON DELETE CASCADE
+ )";
+ run_sql($db, $sqlLegMilestones, "Table 'leg_milestones' created or already exists.");
+
+ // 6. Passive Income Schedule table (now references transactions)
+ $sqlPassiveIncome = "CREATE TABLE IF NOT EXISTS `passive_income_schedule` (
+ `id` INT AUTO_INCREMENT PRIMARY KEY,
+ `transaction_id` INT NOT NULL, /* The direct commission transaction */
+ `user_id` INT NOT NULL,
+ `amount` DECIMAL(15, 2) NOT NULL,
+ `payment_date` DATE NOT NULL,
+ `status` ENUM('pending', 'paid', 'cancelled') NOT NULL DEFAULT 'pending',
+ `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ FOREIGN KEY (transaction_id) REFERENCES transactions(id) ON DELETE CASCADE,
+ FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
+ )";
+ run_sql($db, $sqlPassiveIncome, "Table 'passive_income_schedule' created or already exists.");
+
+
+ // 7. Insert/Update Super Admin User
+ $adminName = 'Super Admin';
+ $adminEmail = 'admin@example.com';
+ $adminPassword = 'admin';
+ $hashedPassword = password_hash($adminPassword, PASSWORD_BCRYPT);
+ $adminReferralCode = 'ADMIN';
+
+ $stmt = $db->prepare("SELECT id FROM users WHERE email = :email");
+ $stmt->execute([':email' => $adminEmail]);
+ if ($stmt->rowCount() == 0) {
+ $sql = "INSERT INTO users (name, email, password, referral_code, `role`) VALUES (:name, :email, :password, :referral_code, 'Super Admin')";
+ $stmt = $db->prepare($sql);
+ $stmt->execute([
+ ':name' => $adminName,
+ ':email' => $adminEmail,
+ ':password' => $hashedPassword,
+ ':referral_code' => $adminReferralCode
+ ]);
+ echo "Super Admin user created successfully.";
+ } else {
+ $sql = "UPDATE users SET password = :password, `role` = 'Super Admin' WHERE email = :email";
+ $stmt = $db->prepare($sql);
+ $stmt->execute([
+ ':password' => $hashedPassword,
+ ':email' => $adminEmail
+ ]);
+ echo "Super Admin user updated successfully.";
+ }
+ echo "
Database setup/update complete.";
+
} catch (PDOException $e) {
die("DB ERROR: ". $e->getMessage());
-}
+}
\ No newline at end of file
diff --git a/delete_user.php b/delete_user.php
new file mode 100644
index 0000000..5341d27
--- /dev/null
+++ b/delete_user.php
@@ -0,0 +1,23 @@
+prepare('DELETE FROM users WHERE id = ?');
+ $stmt->execute([$user_id]);
+
+ header('Location: admin_dashboard.php');
+ exit;
+} else {
+ header('Location: admin_dashboard.php');
+ exit;
+}
+?>
\ No newline at end of file
diff --git a/edit_content.php b/edit_content.php
new file mode 100644
index 0000000..17afbee
--- /dev/null
+++ b/edit_content.php
@@ -0,0 +1,83 @@
+ $value) {
+ if (array_key_exists($key, $content)) {
+ $content[$key] = $value;
+ }
+ }
+ file_put_contents($content_file, json_encode($content, JSON_PRETTY_PRINT));
+ header('Location: edit_content.php?success=true');
+ exit;
+}
+?>
+
+
+
+
+
+
Edit Landing Page Content
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Content updated successfully!
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/edit_user.php b/edit_user.php
new file mode 100644
index 0000000..2d7eb31
--- /dev/null
+++ b/edit_user.php
@@ -0,0 +1,134 @@
+prepare('SELECT id, name, email, role, agent_tier, cumulative_bookings, phone, company, notes FROM users WHERE id = ?');
+ $stmt->execute([$user_id]);
+ $user = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if (!$user) {
+ header('Location: admin_dashboard.php?error=user_not_found');
+ exit;
+ }
+}
+
+if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $name = $_POST['name'];
+ $email = $_POST['email'];
+ $role = $_POST['role'];
+ $agent_tier = $_POST['agent_tier'];
+ $phone = $_POST['phone'];
+ $company = $_POST['company'];
+ $notes = $_POST['notes'];
+ $user_id = $_POST['user_id'];
+
+ if (empty($name) || empty($email) || empty($role)) {
+ header('Location: edit_user.php?id=' . $user_id . '&error=empty_fields');
+ exit;
+ }
+
+ $db = db();
+ $stmt = $db->prepare('UPDATE users SET name = ?, email = ?, role = ?, agent_tier = ?, phone = ?, company = ?, notes = ? WHERE id = ?');
+ $stmt->execute([$name, $email, $role, $agent_tier, $phone, $company, $notes, $user_id]);
+
+ header('Location: admin_dashboard.php');
+ exit;
+}
+
+?>
+
+
+
+
+
+
Edit User
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/genealogy.php b/genealogy.php
new file mode 100644
index 0000000..b75b15a
--- /dev/null
+++ b/genealogy.php
@@ -0,0 +1,168 @@
+prepare("SELECT id, name, email, agent_tier FROM users WHERE sponsor_id = :sponsor_id ORDER BY name");
+ $stmt->execute([':sponsor_id' => $userId]);
+ $downline = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($downline as $member) {
+ $member['downline'] = get_downline_tree($member['id'], $db);
+ $tree[] = $member;
+ }
+
+ return $tree;
+}
+
+// Function to recursively display the tree as a nested list
+function display_tree_node($node) {
+ echo '
';
+ echo '';
+ echo '
';
+ echo '
' . htmlspecialchars($node['name']) . ' ';
+ echo '
' . htmlspecialchars($node['email']) . '
';
+ echo '
' . htmlspecialchars($node['agent_tier']) . ' ';
+ echo '
';
+ echo '
';
+
+ if (!empty($node['downline'])) {
+ echo '';
+ foreach ($node['downline'] as $child) {
+ display_tree_node($child);
+ }
+ echo ' ';
+ }
+
+ echo ' ';
+}
+
+
+$stmt = $db->prepare("SELECT * FROM users WHERE id = :id");
+$stmt->execute([':id' => $_SESSION['user_id']]);
+$user = $stmt->fetch(PDO::FETCH_ASSOC);
+
+$genealogy_tree = get_downline_tree($user['id'], $db);
+
+$site_name = 'Kutumbh Infra';
+?>
+
+
+
+
+
+
Genealogy Tree -
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/index.php b/index.php
index 7e7f0c8..37a5f13 100644
--- a/index.php
+++ b/index.php
@@ -1,49 +1,202 @@
-
+
-
Kutumbh Infra MLM
+
+
+
-
+
+
+
+
+
-
-
-
Kutumbh Infra
+
+
+
-
-
-
-
Welcome to Kutumbh Infra MLM
-
Your partner in real estate success.
-
-
Get Started
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
© . All Rights Reserved.
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/ledger.php b/ledger.php
new file mode 100644
index 0000000..e0e614e
--- /dev/null
+++ b/ledger.php
@@ -0,0 +1,156 @@
+prepare("SELECT * FROM users WHERE id = :id");
+$stmt->execute([':id' => $_SESSION['user_id']]);
+$user = $stmt->fetch(PDO::FETCH_ASSOC);
+
+// 2. Pagination Logic
+$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
+$records_per_page = 25;
+$offset = ($page - 1) * $records_per_page;
+
+// Get total number of transactions for the user
+$total_stmt = $db->prepare("SELECT COUNT(*) FROM transactions WHERE user_id = :user_id");
+$total_stmt->execute([':user_id' => $user['id']]);
+$total_records = $total_stmt->fetchColumn();
+$total_pages = ceil($total_records / $records_per_page);
+
+// 3. Fetch Transactions for the current page
+$stmt = $db->prepare("SELECT * FROM transactions WHERE user_id = :user_id ORDER BY created_at DESC LIMIT :limit OFFSET :offset");
+$stmt->bindValue(':user_id', $user['id'], PDO::PARAM_INT);
+$stmt->bindValue(':limit', $records_per_page, PDO::PARAM_INT);
+$stmt->bindValue(':offset', $offset, PDO::PARAM_INT);
+$stmt->execute();
+$transactions = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+$site_name = 'Kutumbh Infra';
+?>
+
+
+
+
+
+
Transaction Ledger -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Date
+ Type
+ Amount
+ Description
+
+
+
+
+ No transactions found.
+
+
+
+
+
+
+ = 0 ? '+' : '-') . ' ₹' . number_format(abs($tx['amount']), 2); ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/login.php b/login.php
index 86b73cf..14f1625 100644
--- a/login.php
+++ b/login.php
@@ -1,52 +1,75 @@
-
-
+
-
Login
+
+
+
Login - Your Brand
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
- Email
-
-
-
- Password
-
-
- Login
-
+
+
+
+
+
+
Log in to access your dashboard and manage your network.
+
+
+
+
diff --git a/mlm_logic.php b/mlm_logic.php
new file mode 100644
index 0000000..03a9a22
--- /dev/null
+++ b/mlm_logic.php
@@ -0,0 +1,255 @@
+prepare("SELECT sponsor_id FROM users WHERE id = :id");
+ $stmt->execute([':id' => $currentUser]);
+ $sponsor = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($sponsor && $sponsor['sponsor_id']) {
+ $upline[] = $sponsor['sponsor_id'];
+ $currentUser = $sponsor['sponsor_id'];
+ } else {
+ break;
+ }
+ }
+
+ return $upline;
+}
+
+/**
+ * Calculates and distributes commissions for a given booking.
+ *
+ * @param int $bookingId The ID of the booking.
+ */
+function calculate_commissions($bookingId) {
+ $db = db();
+ $db->beginTransaction();
+
+ try {
+ // 1. Get booking details
+ $stmt = $db->prepare("SELECT user_id, amount FROM bookings WHERE id = :booking_id AND status = 'approved'");
+ $stmt->execute([':booking_id' => $bookingId]);
+ $booking = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if (!$booking) {
+ throw new Exception("Booking not found or not approved.");
+ }
+
+ $bookingAmount = $booking['amount'];
+ $bookingUserId = $booking['user_id'];
+
+ // 2. Get upline
+ $upline = get_upline($bookingUserId, 10);
+
+ if (empty($upline)) {
+ // No upline, nothing to do
+ $db->commit();
+ return;
+ }
+
+ // 3. Direct Commission (Level 10)
+ $directCommission = $bookingAmount * 0.10;
+ $directSponsorId = $upline[0];
+
+ // Insert transaction for direct commission
+ $stmt = $db->prepare(
+ "INSERT INTO transactions (user_id, amount, type, description, related_booking_id, related_user_id) VALUES (:user_id, :amount, 'commission_direct', :description, :booking_id, :related_user_id)"
+ );
+ $stmt->execute([
+ ':user_id' => $directSponsorId,
+ ':amount' => $directCommission,
+ ':description' => 'Direct commission for booking #' . $bookingId,
+ ':booking_id' => $bookingId,
+ ':related_user_id' => $bookingUserId
+ ]);
+ $directCommissionTransactionId = $db->lastInsertId();
+
+ // Schedule passive income for the sponsor
+ schedule_passive_income($directCommissionTransactionId, $directSponsorId, $directCommission, $db);
+
+ // Update sponsor's wallet and income
+ $stmt = $db->prepare("UPDATE users SET wallet_balance = wallet_balance + :amount, total_direct_income = total_direct_income + :amount WHERE id = :user_id");
+ $stmt->execute([':amount' => $directCommission, ':user_id' => $directSponsorId]);
+
+ // 4. Team Commissions (Levels 9 down to 1)
+ $previousLevelCommission = $directCommission;
+ for ($i = 1; $i < count($upline); $i++) {
+ $teamCommission = $previousLevelCommission * 0.50;
+ $uplineMemberId = $upline[$i];
+
+ // Insert transaction for team commission
+ $stmt = $db->prepare(
+ "INSERT INTO transactions (user_id, amount, type, description, related_booking_id, related_user_id) VALUES (:user_id, :amount, 'commission_team', :description, :booking_id, :related_user_id)"
+ );
+ $stmt->execute([
+ ':user_id' => $uplineMemberId,
+ ':amount' => $teamCommission,
+ ':description' => 'Team commission (Level ' . (10 - ($i + 1) + 1) . ') for booking #' . $bookingId,
+ ':booking_id' => $bookingId,
+ ':related_user_id' => $bookingUserId
+ ]);
+
+ // Update user's wallet and income
+ $stmt = $db->prepare("UPDATE users SET wallet_balance = wallet_balance + :amount, total_team_income = total_team_income + :amount WHERE id = :user_id");
+ $stmt->execute([':amount' => $teamCommission, ':user_id' => $uplineMemberId]);
+
+ $previousLevelCommission = $teamCommission;
+ }
+
+ // 5. Calculate Leg Match Bonus
+ calculate_leg_match_bonus($bookingUserId, $db);
+
+ $db->commit();
+ echo "Commissions calculated and distributed successfully for booking #$bookingId.";
+
+ } catch (Exception $e) {
+ $db->rollBack();
+ error_log("Commission calculation failed for booking #$bookingId: " . $e->getMessage());
+ // Handle or log the error appropriately
+ }
+}
+
+/**
+ * Calculates and distributes leg match bonuses.
+ */
+/**
+ * Recursively calculates the total booking volume for a given user and their entire downline.
+ *
+ * @param int $userId The ID of the user at the top of the leg.
+ * @param PDO $db The database connection.
+ * @return float The total volume of the leg.
+ */
+function get_leg_volume($userId, $db) {
+ $totalVolume = 0.0;
+
+ // Get the user's own contribution
+ $stmt = $db->prepare("SELECT cumulative_bookings FROM users WHERE id = :user_id");
+ $stmt->execute([':user_id' => $userId]);
+ $user = $stmt->fetch(PDO::FETCH_ASSOC);
+ if ($user) {
+ $totalVolume += $user['cumulative_bookings'];
+ }
+
+ // Get all directly sponsored users
+ $stmt = $db->prepare("SELECT id FROM users WHERE sponsor_id = :sponsor_id");
+ $stmt->execute([':sponsor_id' => $userId]);
+ $downline = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ foreach ($downline as $downlineUser) {
+ $totalVolume += get_leg_volume($downlineUser['id'], $db);
+ }
+
+ return $totalVolume;
+}
+
+/**
+ * Calculates and distributes leg match bonuses.
+ *
+ * @param int $bookingUserId The user who made the original booking.
+ * @param PDO $db The database connection.
+ */
+function calculate_leg_match_bonus($bookingUserId, $db) {
+ // A leg match bonus is paid to the SPONSOR of the user who made the booking,
+ // based on the performance of their OTHER legs.
+ // The spec is "5% leg-match paid to user for every INR 10,00,000 leg milestone".
+ // This implies we check the sponsor's legs.
+
+ // Get the sponsor of the person who made the booking
+ $stmt = $db->prepare("SELECT sponsor_id FROM users WHERE id = :id");
+ $stmt->execute([':id' => $bookingUserId]);
+ $sponsor = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if (!$sponsor || !$sponsor['sponsor_id']) {
+ return; // No sponsor, no bonus to calculate
+ }
+ $sponsorId = $sponsor['sponsor_id'];
+
+ // Get all the direct downlines of the SPONSOR (these are the legs)
+ $stmt = $db->prepare("SELECT id FROM users WHERE sponsor_id = :sponsor_id");
+ $stmt->execute([':sponsor_id' => $sponsorId]);
+ $legs = $stmt->fetchAll(PDO::FETCH_ASSOC);
+
+ $milestoneAmount = 1000000.00;
+ $bonusPercentage = 0.05;
+ $bonusAmount = $milestoneAmount * $bonusPercentage;
+
+ foreach ($legs as $leg) {
+ $legUserId = $leg['id'];
+ $legVolume = get_leg_volume($legUserId, $db);
+
+ // Find out how many milestones this leg has already been paid for
+ $stmt = $db->prepare("SELECT COUNT(*) as count FROM leg_milestones WHERE user_id = :user_id AND leg_user_id = :leg_user_id");
+ $stmt->execute([':user_id' => $sponsorId, ':leg_user_id' => $legUserId]);
+ $paidMilestonesCount = $stmt->fetch(PDO::FETCH_ASSOC)['count'];
+
+ $achievedMilestones = floor($legVolume / $milestoneAmount);
+
+ if ($achievedMilestones > $paidMilestonesCount) {
+ $newMilestones = $achievedMilestones - $paidMilestonesCount;
+ for ($i = 0; $i < $newMilestones; $i++) {
+ $currentMilestoneNumber = $paidMilestonesCount + $i + 1;
+ $currentMilestoneValue = $currentMilestoneNumber * $milestoneAmount;
+
+ // 1. Pay the bonus
+ $stmt = $db->prepare(
+ "INSERT INTO transactions (user_id, amount, type, description, related_user_id) VALUES (:user_id, :amount, 'leg_match_bonus', :description, :related_user_id)"
+ );
+ $stmt->execute([
+ ':user_id' => $sponsorId,
+ ':amount' => $bonusAmount,
+ ':description' => "Leg match bonus for leg of user #$legUserId reaching milestone ₹" . number_format($currentMilestoneValue),
+ ':related_user_id' => $legUserId
+ ]);
+
+ // 2. Update wallet
+ $stmt = $db->prepare("UPDATE users SET wallet_balance = wallet_balance + :amount, total_leg_match_income = total_leg_match_income + :amount WHERE id = :user_id");
+ $stmt->execute([':amount' => $bonusAmount, ':user_id' => $sponsorId]);
+
+ // 3. Record the milestone payment
+ $stmt = $db->prepare("INSERT INTO leg_milestones (user_id, leg_user_id, milestone_amount, bonus_amount) VALUES (:user_id, :leg_user_id, :milestone_amount, :bonus_amount)");
+ $stmt->execute([
+ ':user_id' => $sponsorId,
+ ':leg_user_id' => $legUserId,
+ ':milestone_amount' => $currentMilestoneValue,
+ ':bonus_amount' => $bonusAmount
+ ]);
+ }
+ }
+ }
+}
+
+/**
+ * Schedules passive income payments.
+ */
+function schedule_passive_income($directCommissionTransactionId, $userId, $directCommissionAmount, $db) {
+ $passiveIncomeAmount = $directCommissionAmount * 0.005;
+ $startDate = new DateTime();
+
+ for ($i = 1; $i <= 12; $i++) {
+ $paymentDate = clone $startDate;
+ $paymentDate->add(new DateInterval("P{$i}M"));
+
+ $stmt = $db->prepare(
+ "INSERT INTO passive_income_schedule (transaction_id, user_id, amount, payment_date, status) VALUES (:transaction_id, :user_id, :amount, :payment_date, 'pending')"
+ );
+ $stmt->execute([
+ ':transaction_id' => $directCommissionTransactionId,
+ ':user_id' => $userId,
+ ':amount' => $passiveIncomeAmount,
+ ':payment_date' => $paymentDate->format('Y-m-d')
+ ]);
+ }
+}
\ No newline at end of file
diff --git a/register.php b/register.php
index 24ee8ac..2e15e4a 100644
--- a/register.php
+++ b/register.php
@@ -1,63 +1,86 @@
-
-
+
-
Register
+
+
+
Register - Your Brand
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
- Name
-
-
-
- Email
-
-
-
- Password
-
-
-
- Sponsor Code (Optional)
-
-
- Register
-
+
+
+
+
+
+
Join our network and start your journey with us today.
+
+
+
+
diff --git a/submit_booking.php b/submit_booking.php
new file mode 100644
index 0000000..c7c26c0
--- /dev/null
+++ b/submit_booking.php
@@ -0,0 +1,111 @@
+prepare(
+ "INSERT INTO bookings (user_id, plot_id, amount, booking_date, proof_document, status) VALUES (:user_id, :plot_id, :amount, :booking_date, :proof_document, 'pending')"
+ );
+
+ try {
+ $stmt->execute([
+ ':user_id' => $_SESSION['user_id'],
+ ':plot_id' => $plotId,
+ ':amount' => $amount,
+ ':booking_date' => $bookingDate,
+ ':proof_document' => $uploadFile
+ ]);
+ $message = 'Booking submitted successfully! It is now pending approval.';
+ } catch (PDOException $e) {
+ $error = 'Database error: ' . $e->getMessage();
+ }
+ } else {
+ $error = 'Failed to upload proof document.';
+ }
+ }
+}
+?>
+
+
+
+
+
+
Submit Booking
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/submit_contact.php b/submit_contact.php
new file mode 100644
index 0000000..a5cc514
--- /dev/null
+++ b/submit_contact.php
@@ -0,0 +1,43 @@
+
\ No newline at end of file
diff --git a/withdraw.php b/withdraw.php
new file mode 100644
index 0000000..ff371ee
--- /dev/null
+++ b/withdraw.php
@@ -0,0 +1,149 @@
+prepare("SELECT wallet_balance FROM users WHERE id = ?");
+$stmt->execute([$user_id]);
+$wallet_balance = $stmt->fetchColumn();
+
+if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['amount'])) {
+ $amount = filter_input(INPUT_POST, 'amount', FILTER_VALIDATE_FLOAT);
+
+ if ($amount === false || $amount <= 0) {
+ $error = 'Please enter a valid withdrawal amount.';
+ } elseif ($amount > $wallet_balance) {
+ $error = 'Withdrawal amount cannot exceed your wallet balance.';
+ } else {
+ try {
+ $db->beginTransaction();
+
+ // 1. Insert into withdrawals table
+ $stmt = $db->prepare("INSERT INTO withdrawals (user_id, amount) VALUES (?, ?)");
+ $stmt->execute([$user_id, $amount]);
+ $withdrawal_id = $db->lastInsertId();
+
+ // 2. Deduct from user's wallet
+ $stmt = $db->prepare("UPDATE users SET wallet_balance = wallet_balance - ? WHERE id = ?");
+ $stmt->execute([$amount, $user_id]);
+
+ // 3. Record the transaction
+ $stmt = $db->prepare("INSERT INTO transactions (user_id, amount, type, description, related_withdrawal_id) VALUES (?, ?, 'withdrawal_request', 'Withdrawal request initiated', ?)");
+ $stmt->execute([$user_id, -$amount, $withdrawal_id]);
+
+ $db->commit();
+ $message = 'Your withdrawal request has been submitted successfully. It will be processed shortly.';
+ // Refresh wallet balance
+ $wallet_balance -= $amount;
+ } catch (PDOException $e) {
+ $db->rollBack();
+ $error = 'An error occurred. Please try again.';
+ // For debugging: error_log($e->getMessage());
+ }
+ }
+}
+
+// Fetch recent withdrawals
+$stmt = $db->prepare("SELECT * FROM withdrawals WHERE user_id = ? ORDER BY created_at DESC LIMIT 10");
+$stmt->execute([$user_id]);
+$withdrawals = $stmt->fetchAll();
+
+?>
+
+
+
+
+
+
Request Withdrawal
+
+
+
+
+
+
+
+
Request a Withdrawal
+
Back to Dashboard
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Available Balance
+
₹
+
+
+
Withdrawal Amount
+
+ ₹
+
+
+
+ Submit Request
+
+
+
+
+
+
+
+
+
+
+
+ Date
+ Amount
+ Status
+
+
+
+
+ No recent withdrawals.
+
+
+
+
+ ₹
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+