PNG  IHDR pHYs   OiCCPPhotoshop ICC profilexڝSgTS=BKKoR RB&*! J!QEEȠQ, !{kּ> H3Q5 B.@ $pd!s#~<<+"x M0B\t8K@zB@F&S`cbP-`'{[! eDh;VEX0fK9-0IWfH  0Q){`##xFW<+*x<$9E[-qWW.(I+6aa@.y24x6_-"bbϫp@t~,/;m%h^ uf@Wp~<5j>{-]cK'Xto(hw?G%fIq^D$.Tʳ?D*A, `6B$BB dr`)B(Ͱ*`/@4Qhp.U=pa( Aa!ڈbX#!H$ ɈQ"K5H1RT UH=r9\F;2G1Q= C7F dt1r=6Ыhڏ>C03l0.B8, c˱" VcϱwE 6wB aAHXLXNH $4 7 Q'"K&b21XH,#/{C7$C2'ITFnR#,4H#dk9, +ȅ3![ b@qS(RjJ4e2AURݨT5ZBRQ4u9̓IKhhitݕNWGw Ljg(gwLӋT071oUX**| J&*/Tު UUT^S}FU3S ԖUPSSg;goT?~YYLOCQ_ cx,!k u5&|v*=9C3J3WRf?qtN (~))4L1e\kXHQG6EYAJ'\'GgSSݧ M=:.kDwn^Loy}/TmG X $ <5qo</QC]@Caaᄑ.ȽJtq]zۯ6iܟ4)Y3sCQ? 0k߬~OCOg#/c/Wװwa>>r><72Y_7ȷOo_C#dz%gA[z|!?:eAAA!h쐭!ΑiP~aa~ 'W?pX15wCsDDDޛg1O9-J5*>.j<74?.fYXXIlK9.*6nl {/]py.,:@LN8A*%w% yg"/6шC\*NH*Mz쑼5y$3,幄'L Lݛ:v m2=:1qB!Mggfvˬen/kY- BTZ(*geWf͉9+̳ې7ᒶKW-X潬j9(xoʿܔĹdff-[n ڴ VE/(ۻCɾUUMfeI?m]Nmq#׹=TR+Gw- 6 U#pDy  :v{vg/jBFS[b[O>zG499?rCd&ˮ/~јѡ򗓿m|x31^VwwO| (hSЧc3- cHRMz%u0`:o_F@8N ' p @8N@8}' p '#@8N@8N pQ9p!i~}|6-ӪG` VP.@*j>[ K^<֐Z]@8N'KQ<Q(`s" 'hgpKB`R@Dqj '  'P$a ( `D$Na L?u80e J,K˷NI'0eݷ(NI'؀ 2ipIIKp`:O'`ʤxB8Ѥx Ѥx $ $P6 :vRNb 'p,>NB 'P]-->P T+*^h& p '‰a ‰ (ĵt#u33;Nt̵'ޯ; [3W ~]0KH1q@8]O2]3*̧7# *p>us p _6]/}-4|t'|Smx= DoʾM×M_8!)6lq':l7!|4} '\ne t!=hnLn (~Dn\+‰_4k)0e@OhZ`F `.m1} 'vp{F`ON7Srx 'D˸nV`><;yMx!IS钦OM)Ե٥x 'DSD6bS8!" ODz#R >S8!7ّxEh0m$MIPHi$IvS8IN$I p$O8I,sk&I)$IN$Hi$I^Ah.p$MIN$IR8I·N "IF9Ah0m$MIN$IR8IN$I 3jIU;kO$ɳN$+ q.x* tEXtComment

Viewing File: /home/u456810272/domains/etfcareer.org/public_html/admin/sample3/dashboard3.php

<?php
session_start();
if (!isset($_SESSION['admin_id'])) {
    header("Location: index.php");
    exit;
}

// FIX: Define the function that was previously just a comment
function createAllTables($pdo) {
    $tables = [
        "CREATE TABLE IF NOT EXISTS admins (
            id INT AUTO_INCREMENT PRIMARY KEY,
            name VARCHAR(100) NOT NULL,
            email VARCHAR(255) NOT NULL UNIQUE,
            password VARCHAR(255) NOT NULL,
            role ENUM('admin','staff') DEFAULT 'admin',
            status TINYINT(1) DEFAULT 1,
            created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
        ) ENGINE=InnoDB",
        // ... [Include other table strings from index.php] ...
    ];
    foreach ($tables as $sql) {
        $pdo->exec($sql);
    }
}
?>

// ============================================
// DATABASE CONFIGURATION
// ============================================
$host = "localhost";
$dbname = "u456810272_etfcareer";
$username = "u456810272_etfcareer";
$password = "Global@#980";

// Create database connection
try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

// ============================================
// CREATE ALL TABLES FUNCTION (Same as in index.php)
// ============================================
function createAllTables($pdo) {
    // Same function as in index.php
    // ... [Copy the createAllTables function from index.php here]
}

// Create tables if they don't exist
createAllTables($pdo);

// ============================================
// HANDLE POST REQUESTS FOR ALL FEATURES
// ============================================

// Initialize messages
$success_msg = '';
$error_msg = '';

// Handle Product Add/Edit/Delete
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Add Product
    if (isset($_POST['add_product'])) {
        $name = trim($_POST['name'] ?? '');
        $category = trim($_POST['category'] ?? '');
        $sku = trim($_POST['sku'] ?? '');
        $price = floatval($_POST['price'] ?? 0);
        $cost = floatval($_POST['cost'] ?? 0);
        $stock = intval($_POST['stock'] ?? 0);
        $description = trim($_POST['description'] ?? '');
        
        if (!empty($name) && $price > 0) {
            $stmt = $pdo->prepare("INSERT INTO products (name, category, sku, price, cost, stock, description, status) VALUES (?, ?, ?, ?, ?, ?, ?, 'active')");
            if ($stmt->execute([$name, $category, $sku, $price, $cost, $stock, $description])) {
                $success_msg = "Product added successfully!";
            } else {
                $error_msg = "Failed to add product.";
            }
        } else {
            $error_msg = "Please provide product name and price.";
        }
    }
    
    // Add Customer
    elseif (isset($_POST['add_customer'])) {
        $name = trim($_POST['name'] ?? '');
        $email = trim($_POST['email'] ?? '');
        $phone = trim($_POST['phone'] ?? '');
        $address = trim($_POST['address'] ?? '');
        
        if (!empty($name) && !empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
            // Check if email exists
            $stmt = $pdo->prepare("SELECT id FROM users WHERE email = ?");
            $stmt->execute([$email]);
            
            if (!$stmt->fetch()) {
                $password = password_hash('password123', PASSWORD_DEFAULT);
                $stmt = $pdo->prepare("INSERT INTO users (name, email, password, phone, address, role, status) VALUES (?, ?, ?, ?, ?, 'customer', 'active')");
                if ($stmt->execute([$name, $email, $password, $phone, $address])) {
                    $success_msg = "Customer added successfully!";
                } else {
                    $error_msg = "Failed to add customer.";
                }
            } else {
                $error_msg = "Email already exists.";
            }
        } else {
            $error_msg = "Please provide valid name and email.";
        }
    }
    
    // Create Order
    elseif (isset($_POST['create_order'])) {
        $user_id = intval($_POST['user_id'] ?? 0);
        $total_amount = floatval($_POST['total_amount'] ?? 0);
        $payment_method = trim($_POST['payment_method'] ?? 'cash');
        $order_number = 'ORD' . date('YmdHis') . rand(100, 999);
        
        if ($user_id > 0 && $total_amount > 0) {
            $stmt = $pdo->prepare("INSERT INTO orders (order_number, user_id, total_amount, final_amount, payment_method) VALUES (?, ?, ?, ?, ?)");
            if ($stmt->execute([$order_number, $user_id, $total_amount, $total_amount, $payment_method])) {
                $success_msg = "Order created successfully! Order #: " . $order_number;
            } else {
                $error_msg = "Failed to create order.";
            }
        } else {
            $error_msg = "Please select customer and enter valid amount.";
        }
    }
    
    // Add Payment
    elseif (isset($_POST['add_payment'])) {
        $order_id = intval($_POST['order_id'] ?? 0);
        $amount = floatval($_POST['amount'] ?? 0);
        $gateway = trim($_POST['gateway'] ?? 'cash');
        $transaction_id = trim($_POST['transaction_id'] ?? '');
        $payment_number = 'PAY' . date('YmdHis') . rand(100, 999);
        
        if ($order_id > 0 && $amount > 0) {
            $stmt = $pdo->prepare("INSERT INTO payments (payment_number, order_id, amount, gateway, transaction_id, payment_status, payment_date) VALUES (?, ?, ?, ?, ?, 'completed', NOW())");
            if ($stmt->execute([$payment_number, $order_id, $amount, $gateway, $transaction_id])) {
                // Update order payment status
                $pdo->prepare("UPDATE orders SET payment_status = 'paid' WHERE id = ?")->execute([$order_id]);
                $success_msg = "Payment recorded successfully!";
            } else {
                $error_msg = "Failed to record payment.";
            }
        } else {
            $error_msg = "Please select order and enter valid amount.";
        }
    }
    
    // Add Employee
    elseif (isset($_POST['add_employee'])) {
        $name = trim($_POST['name'] ?? '');
        $email = trim($_POST['email'] ?? '');
        $phone = trim($_POST['phone'] ?? '');
        $department = trim($_POST['department'] ?? '');
        $position = trim($_POST['position'] ?? '');
        $salary = floatval($_POST['salary'] ?? 0);
        
        if (!empty($name) && !empty($email) && $salary > 0) {
            $employee_id = 'EMP' . date('Ymd') . rand(1000, 9999);
            $stmt = $pdo->prepare("INSERT INTO employees (employee_id, name, email, phone, department, position, salary, join_date, status) VALUES (?, ?, ?, ?, ?, ?, ?, CURDATE(), 'active')");
            if ($stmt->execute([$employee_id, $name, $email, $phone, $department, $position, $salary])) {
                $success_msg = "Employee added successfully!";
            } else {
                $error_msg = "Failed to add employee.";
            }
        } else {
            $error_msg = "Please provide all required employee details.";
        }
    }
    
    // Process Payroll
    elseif (isset($_POST['process_payroll'])) {
        $employee_id = intval($_POST['employee_id'] ?? 0);
        $basic_salary = floatval($_POST['basic_salary'] ?? 0);
        $overtime = floatval($_POST['overtime'] ?? 0);
        $bonuses = floatval($_POST['bonuses'] ?? 0);
        $deductions = floatval($_POST['deductions'] ?? 0);
        
        if ($employee_id > 0 && $basic_salary > 0) {
            $net_salary = $basic_salary + $overtime + $bonuses - $deductions;
            $stmt = $pdo->prepare("INSERT INTO payroll (employee_id, pay_period_start, pay_period_end, basic_salary, overtime, bonuses, deductions, net_salary, payment_date, payment_status) VALUES (?, DATE_SUB(CURDATE(), INTERVAL 30 DAY), CURDATE(), ?, ?, ?, ?, ?, CURDATE(), 'paid')");
            if ($stmt->execute([$employee_id, $basic_salary, $overtime, $bonuses, $deductions, $net_salary])) {
                $success_msg = "Payroll processed successfully! Net Salary: $" . number_format($net_salary, 2);
            } else {
                $error_msg = "Failed to process payroll.";
            }
        } else {
            $error_msg = "Please select employee and enter salary details.";
        }
    }
    
    // Add Account
    elseif (isset($_POST['add_account'])) {
        $account_name = trim($_POST['account_name'] ?? '');
        $account_type = trim($_POST['account_type'] ?? 'asset');
        $account_number = trim($_POST['account_number'] ?? '');
        $balance = floatval($_POST['balance'] ?? 0);
        
        if (!empty($account_name) && !empty($account_number)) {
            $stmt = $pdo->prepare("INSERT INTO accounts (account_name, account_type, account_number, balance, status) VALUES (?, ?, ?, ?, 'active')");
            if ($stmt->execute([$account_name, $account_type, $account_number, $balance])) {
                $success_msg = "Account added successfully!";
            } else {
                $error_msg = "Failed to add account.";
            }
        } else {
            $error_msg = "Please provide account name and number.";
        }
    }
    
    // Record Transaction
    elseif (isset($_POST['record_transaction'])) {
        $account_id = intval($_POST['account_id'] ?? 0);
        $type = trim($_POST['type'] ?? 'debit');
        $amount = floatval($_POST['amount'] ?? 0);
        $description = trim($_POST['description'] ?? '');
        $category = trim($_POST['category'] ?? '');
        
        if ($account_id > 0 && $amount > 0 && !empty($description)) {
            $transaction_number = 'TRN' . date('YmdHis') . rand(100, 999);
            $stmt = $pdo->prepare("INSERT INTO transactions (transaction_number, account_id, type, amount, description, category, date) VALUES (?, ?, ?, ?, ?, ?, CURDATE())");
            if ($stmt->execute([$transaction_number, $account_id, $type, $amount, $description, $category])) {
                // Update account balance
                if ($type == 'debit') {
                    $pdo->prepare("UPDATE accounts SET balance = balance - ? WHERE id = ?")->execute([$amount, $account_id]);
                } else {
                    $pdo->prepare("UPDATE accounts SET balance = balance + ? WHERE id = ?")->execute([$amount, $account_id]);
                }
                $success_msg = "Transaction recorded successfully!";
            } else {
                $error_msg = "Failed to record transaction.";
            }
        } else {
            $error_msg = "Please provide all transaction details.";
        }
    }
    
    // Add Subscription
    elseif (isset($_POST['add_subscription'])) {
        $user_id = intval($_POST['user_id'] ?? 0);
        $plan_name = trim($_POST['plan_name'] ?? '');
        $plan_type = trim($_POST['plan_type'] ?? 'monthly');
        $price = floatval($_POST['price'] ?? 0);
        
        if ($user_id > 0 && !empty($plan_name) && $price > 0) {
            $start_date = date('Y-m-d');
            $end_date = $plan_type == 'monthly' ? date('Y-m-d', strtotime('+1 month')) : date('Y-m-d', strtotime('+1 year'));
            
            $stmt = $pdo->prepare("INSERT INTO subscriptions (user_id, plan_name, plan_type, price, status, start_date, end_date, next_billing_date) VALUES (?, ?, ?, ?, 'active', ?, ?, ?)");
            if ($stmt->execute([$user_id, $plan_name, $plan_type, $price, $start_date, $end_date, $end_date])) {
                $success_msg = "Subscription added successfully!";
            } else {
                $error_msg = "Failed to add subscription.";
            }
        } else {
            $error_msg = "Please provide all subscription details.";
        }
    }
    
    // AI Chat Message
    elseif (isset($_POST['ai_message'])) {
        $message = trim($_POST['message'] ?? '');
        
        if (!empty($message)) {
            // Simple AI responses
            $responses = [
                "Hello! How can I assist you with your business today?",
                "I can help you manage products, customers, orders, and more.",
                "For sales reports, go to the Reports section.",
                "To add a new product, use the Products section.",
                "You can manage employee payroll in the HR & Payroll section.",
                "Need help with settings? Check the Settings section.",
                "I'm here to help with any business management questions.",
                "You can track your revenue in the Dashboard overview.",
                "For customer support issues, use the Support Tickets section.",
                "Check the SEO section to optimize your website visibility."
            ];
            
            $reply = $responses[array_rand($responses)];
            
            $stmt = $pdo->prepare("INSERT INTO ai_chat (user_id, user_message, bot_reply) VALUES (?, ?, ?)");
            if ($stmt->execute([$_SESSION['admin_id'], $message, $reply])) {
                $success_msg = "AI responded to your message.";
            }
        }
    }
    
    // Add Subscriber
    elseif (isset($_POST['add_subscriber'])) {
        $email = trim($_POST['email'] ?? '');
        $name = trim($_POST['name'] ?? '');
        
        if (!empty($email) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $stmt = $pdo->prepare("INSERT INTO subscribers (email, name, subscription_date, status) VALUES (?, ?, CURDATE(), 'active')");
            if ($stmt->execute([$email, $name])) {
                $success_msg = "Subscriber added successfully!";
            } else {
                $error_msg = "Email already subscribed.";
            }
        } else {
            $error_msg = "Please provide a valid email.";
        }
    }
    
    // Create Support Ticket
    elseif (isset($_POST['create_ticket'])) {
        $user_id = intval($_POST['user_id'] ?? 0);
        $subject = trim($_POST['subject'] ?? '');
        $message = trim($_POST['message'] ?? '');
        $priority = trim($_POST['priority'] ?? 'medium');
        
        if ($user_id > 0 && !empty($subject) && !empty($message)) {
            $ticket_number = 'TICK' . date('YmdHis') . rand(100, 999);
            $stmt = $pdo->prepare("INSERT INTO support_tickets (ticket_number, user_id, subject, message, priority, status) VALUES (?, ?, ?, ?, ?, 'open')");
            if ($stmt->execute([$ticket_number, $user_id, $subject, $message, $priority])) {
                $success_msg = "Support ticket created successfully! Ticket #: " . $ticket_number;
            } else {
                $error_msg = "Failed to create support ticket.";
            }
        } else {
            $error_msg = "Please provide all ticket details.";
        }
    }
    
    // Save Contact Message Reply
    elseif (isset($_POST['reply_message'])) {
        $message_id = intval($_POST['message_id'] ?? 0);
        $reply = trim($_POST['reply'] ?? '');
        
        if ($message_id > 0 && !empty($reply)) {
            $stmt = $pdo->prepare("UPDATE contact_messages SET status = 'replied' WHERE id = ?");
            if ($stmt->execute([$message_id])) {
                $success_msg = "Reply sent successfully!";
            } else {
                $error_msg = "Failed to send reply.";
            }
        } else {
            $error_msg = "Please write a reply.";
        }
    }
    
    // Save SEO Settings
    elseif (isset($_POST['save_seo'])) {
        $page_name = trim($_POST['page_name'] ?? '');
        $page_url = trim($_POST['page_url'] ?? '');
        $meta_title = trim($_POST['meta_title'] ?? '');
        $meta_description = trim($_POST['meta_description'] ?? '');
        
        if (!empty($page_name) && !empty($page_url)) {
            $stmt = $pdo->prepare("INSERT INTO seo (page_name, page_url, meta_title, meta_description) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE meta_title = VALUES(meta_title), meta_description = VALUES(meta_description)");
            if ($stmt->execute([$page_name, $page_url, $meta_title, $meta_description])) {
                $success_msg = "SEO settings saved successfully!";
            } else {
                $error_msg = "Failed to save SEO settings.";
            }
        } else {
            $error_msg = "Please provide page name and URL.";
        }
    }
    
    // Generate Report
    elseif (isset($_POST['generate_report'])) {
        $report_type = trim($_POST['report_type'] ?? '');
        $start_date = trim($_POST['start_date'] ?? '');
        $end_date = trim($_POST['end_date'] ?? '');
        
        if (!empty($report_type) && !empty($start_date) && !empty($end_date)) {
            $report_name = ucfirst($report_type) . ' Report ' . date('Y-m-d');
            $report_number = 'REP' . date('YmdHis') . rand(100, 999);
            
            $stmt = $pdo->prepare("INSERT INTO reports (report_type, report_name, parameters, generated_by, status) VALUES (?, ?, ?, ?, 'completed')");
            $params = json_encode(['start_date' => $start_date, 'end_date' => $end_date, 'type' => $report_type]);
            if ($stmt->execute([$report_type, $report_name, $params, $_SESSION['admin_id']])) {
                $success_msg = "Report generated successfully!";
            } else {
                $error_msg = "Failed to generate report.";
            }
        } else {
            $error_msg = "Please select report type and date range.";
        }
    }
    
    // Add Language
    elseif (isset($_POST['add_language'])) {
        $language_name = trim($_POST['language_name'] ?? '');
        $language_code = trim($_POST['language_code'] ?? '');
        $native_name = trim($_POST['native_name'] ?? '');
        
        if (!empty($language_name) && !empty($language_code)) {
            $stmt = $pdo->prepare("INSERT INTO languages (language_name, language_code, native_name, status) VALUES (?, ?, ?, 'active')");
            if ($stmt->execute([$language_name, $language_code, $native_name])) {
                $success_msg = "Language added successfully!";
            } else {
                $error_msg = "Failed to add language.";
            }
        } else {
            $error_msg = "Please provide language name and code.";
        }
    }
    
    // Save Email SMTP
    elseif (isset($_POST['save_smtp'])) {
        $host = trim($_POST['host'] ?? '');
        $port = intval($_POST['port'] ?? 587);
        $username = trim($_POST['username'] ?? '');
        $password = trim($_POST['password'] ?? '');
        $encryption = trim($_POST['encryption'] ?? 'tls');
        $from_email = trim($_POST['from_email'] ?? '');
        $from_name = trim($_POST['from_name'] ?? '');
        
        if (!empty($host) && !empty($username) && !empty($from_email)) {
            $stmt = $pdo->prepare("INSERT INTO email_smtp (host, port, username, password, encryption, from_email, from_name, status, is_default) VALUES (?, ?, ?, ?, ?, ?, ?, 'active', 1)");
            if ($stmt->execute([$host, $port, $username, $password, $encryption, $from_email, $from_name])) {
                // Update settings
                $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'smtp_host'")->execute([$host]);
                $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'smtp_port'")->execute([$port]);
                $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'smtp_username'")->execute([$username]);
                $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'smtp_password'")->execute([$password]);
                $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = 'smtp_encryption'")->execute([$encryption]);
                
                $success_msg = "SMTP settings saved successfully!";
            } else {
                $error_msg = "Failed to save SMTP settings.";
            }
        } else {
            $error_msg = "Please provide all required SMTP details.";
        }
    }
    
    // Save General Settings
    elseif (isset($_POST['save_settings'])) {
        foreach ($_POST as $key => $value) {
            if ($key != 'save_settings' && !empty($key)) {
                $stmt = $pdo->prepare("UPDATE settings SET setting_value = ? WHERE setting_key = ?");
                $stmt->execute([$value, $key]);
            }
        }
        $success_msg = "Settings saved successfully!";
    }
}

// ============================================
// FETCH DATA FOR DASHBOARD
// ============================================

// Fetch Dashboard Statistics
$stats = [
    'products' => $pdo->query("SELECT COUNT(*) FROM products")->fetchColumn() ?: 0,
    'customers' => $pdo->query("SELECT COUNT(*) FROM users WHERE role = 'customer'")->fetchColumn() ?: 0,
    'orders' => $pdo->query("SELECT COUNT(*) FROM orders")->fetchColumn() ?: 0,
    'revenue' => $pdo->query("SELECT SUM(final_amount) FROM orders WHERE payment_status = 'paid'")->fetchColumn() ?: 0,
    'employees' => $pdo->query("SELECT COUNT(*) FROM employees")->fetchColumn() ?: 0,
    'tickets' => $pdo->query("SELECT COUNT(*) FROM support_tickets WHERE status = 'open'")->fetchColumn() ?: 0,
    'subscribers' => $pdo->query("SELECT COUNT(*) FROM subscribers WHERE status = 'active'")->fetchColumn() ?: 0,
    'messages' => $pdo->query("SELECT COUNT(*) FROM contact_messages WHERE status = 'unread'")->fetchColumn() ?: 0,
    'accounts' => $pdo->query("SELECT COUNT(*) FROM accounts")->fetchColumn() ?: 0,
    'subscriptions' => $pdo->query("SELECT COUNT(*) FROM subscriptions WHERE status = 'active'")->fetchColumn() ?: 0
];

// Fetch Recent Data
$products = $pdo->query("SELECT * FROM products ORDER BY id DESC LIMIT 10")->fetchAll();
$customers = $pdo->query("SELECT * FROM users WHERE role = 'customer' ORDER BY id DESC LIMIT 10")->fetchAll();
$orders = $pdo->query("SELECT o.*, u.name as customer_name FROM orders o LEFT JOIN users u ON o.user_id = u.id ORDER BY o.id DESC LIMIT 10")->fetchAll();
$employees = $pdo->query("SELECT * FROM employees ORDER BY id DESC LIMIT 10")->fetchAll();
$payments = $pdo->query("SELECT p.*, o.order_number FROM payments p LEFT JOIN orders o ON p.order_id = o.id ORDER BY p.id DESC LIMIT 10")->fetchAll();
$tickets = $pdo->query("SELECT t.*, u.name as customer_name FROM support_tickets t LEFT JOIN users u ON t.user_id = u.id ORDER BY t.id DESC LIMIT 10")->fetchAll();
$subscribers = $pdo->query("SELECT * FROM subscribers ORDER BY id DESC LIMIT 10")->fetchAll();
$messages = $pdo->query("SELECT * FROM contact_messages ORDER BY id DESC LIMIT 10")->fetchAll();
$ai_chats = $pdo->query("SELECT * FROM ai_chat WHERE user_id = " . $_SESSION['admin_id'] . " ORDER BY id DESC LIMIT 10")->fetchAll();
$accounts = $pdo->query("SELECT * FROM accounts ORDER BY id DESC LIMIT 10")->fetchAll();
$subscriptions = $pdo->query("SELECT s.*, u.name as customer_name FROM subscriptions s LEFT JOIN users u ON s.user_id = u.id ORDER BY s.id DESC LIMIT 10")->fetchAll();
$transactions = $pdo->query("SELECT t.*, a.account_name FROM transactions t LEFT JOIN accounts a ON t.account_id = a.id ORDER BY t.id DESC LIMIT 10")->fetchAll();
$payrolls = $pdo->query("SELECT p.*, e.name as employee_name FROM payroll p LEFT JOIN employees e ON p.employee_id = e.id ORDER BY p.id DESC LIMIT 10")->fetchAll();

// Fetch settings
$settings_result = $pdo->query("SELECT setting_key, setting_value FROM settings");
$settings = [];
while ($row = $settings_result->fetch()) {
    $settings[$row['setting_key']] = $row['setting_value'];
}

// Fetch languages
$languages = $pdo->query("SELECT * FROM languages ORDER BY is_default DESC")->fetchAll();

// Fetch SEO data
$seo_pages = $pdo->query("SELECT * FROM seo ORDER BY id DESC LIMIT 10")->fetchAll();

// Fetch reports
$reports = $pdo->query("SELECT * FROM reports ORDER BY id DESC LIMIT 10")->fetchAll();

// Fetch SMTP settings
$smtp_settings = $pdo->query("SELECT * FROM email_smtp WHERE is_default = 1 LIMIT 1")->fetch();

// ============================================
// HANDLE LOGOUT
// ============================================
if (isset($_GET['logout'])) {
    session_destroy();
    header("Location: index.php");
    exit;
}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ETF Career - Dashboard</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <style>
        /* Dashboard CSS - Same as your design but extended */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background: #f5f7fa;
            color: #333;
            overflow-x: hidden;
        }
        
        .admin-container {
            display: flex;
            min-height: 100vh;
        }
        
        .sidebar {
            width: 250px;
            background: #1a237e;
            color: white;
            position: fixed;
            height: 100vh;
            overflow-y: auto;
        }
        
        .sidebar-logo {
            padding: 1.5rem;
            text-align: center;
            border-bottom: 1px solid rgba(255,255,255,0.1);
        }
        
        .nav-links {
            padding: 1rem 0;
            list-style: none;
        }
        
        .nav-link {
            display: flex;
            align-items: center;
            padding: 0.8rem 1.5rem;
            color: rgba(255,255,255,0.8);
            text-decoration: none;
            border-left: 4px solid transparent;
            transition: all 0.3s;
        }
        
        .nav-link:hover, .nav-link.active {
            background: rgba(255,255,255,0.1);
            color: white;
            border-left: 4px solid #ff6f00;
        }
        
        .nav-link i {
            width: 20px;
            margin-right: 10px;
        }
        
        .main-content {
            margin-left: 250px;
            padding: 1.5rem;
            flex: 1;
        }
        
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 1rem;
            background: white;
            border-radius: 10px;
            margin-bottom: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 1.5rem;
        }
        
        .stat-card {
            background: white;
            padding: 1.5rem;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            border-left: 4px solid #283593;
            cursor: pointer;
            transition: transform 0.3s;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
        }
        
        .card {
            background: white;
            border-radius: 10px;
            padding: 1.5rem;
            margin-bottom: 1.5rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 1rem;
        }
        
        table th, table td {
            padding: 0.8rem;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        table th {
            background: #f8f9fa;
            font-weight: 600;
        }
        
        .badge {
            padding: 0.3rem 0.6rem;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 500;
        }
        
        .badge-success {
            background: #d4edda;
            color: #155724;
        }
        
        .badge-warning {
            background: #fff3cd;
            color: #856404;
        }
        
        .badge-danger {
            background: #f8d7da;
            color: #721c24;
        }
        
        .badge-info {
            background: #d1ecf1;
            color: #0c5460;
        }
        
        .badge-primary {
            background: #cfe2ff;
            color: #084298;
        }
        
        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 1rem;
            font-weight: 500;
            display: inline-flex;
            align-items: center;
            gap: 5px;
            text-decoration: none;
        }
        
        .btn-primary {
            background: #283593;
            color: white;
        }
        
        .btn-success {
            background: #28a745;
            color: white;
        }
        
        .btn-danger {
            background: #dc3545;
            color: white;
        }
        
        .btn-warning {
            background: #ffc107;
            color: #212529;
        }
        
        .btn-info {
            background: #17a2b8;
            color: white;
        }
        
        .btn-sm {
            padding: 0.3rem 0.8rem;
            font-size: 0.875rem;
        }
        
        .section {
            display: none;
        }
        
        .section.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        
        /* Modal styles */
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            z-index: 2000;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background: white;
            padding: 2rem;
            border-radius: 10px;
            width: 90%;
            max-width: 500px;
            max-height: 90vh;
            overflow-y: auto;
        }
        
        .form-group {
            margin-bottom: 1rem;
        }
        
        .form-control {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        
        .alert {
            padding: 1rem;
            border-radius: 5px;
            margin-bottom: 1rem;
        }
        
        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }
        
        .alert-danger {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }
        
        .action-buttons {
            display: flex;
            gap: 10px;
            margin-bottom: 1rem;
            flex-wrap: wrap;
        }
        
        .search-box {
            margin-bottom: 1rem;
        }
        
        .search-box input {
            width: 100%;
            padding: 0.8rem;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 1rem;
        }
        
        .chart-container {
            height: 300px;
            margin: 1rem 0;
            position: relative;
        }
        
        @media (max-width: 768px) {
            .sidebar {
                width: 70px;
            }
            .main-content {
                margin-left: 70px;
            }
            .nav-link span {
                display: none;
            }
            .stats-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="admin-container">
        <!-- Sidebar -->
        <div class="sidebar">
            <div class="sidebar-logo">
                <h3>ETF Career</h3>
                <small>Dashboard</small>
            </div>
            <ul class="nav-links">
                <li><a href="#dashboard" class="nav-link active"><i class="fas fa-tachometer-alt"></i> <span>Dashboard</span></a></li>
                <li><a href="#products" class="nav-link"><i class="fas fa-box"></i> <span>Products</span></a></li>
                <li><a href="#customers" class="nav-link"><i class="fas fa-users"></i> <span>Customers</span></a></li>
                <li><a href="#orders" class="nav-link"><i class="fas fa-shopping-cart"></i> <span>Orders</span></a></li>
                <li><a href="#payments" class="nav-link"><i class="fas fa-credit-card"></i> <span>Payment Gateway</span></a></li>
                <li><a href="#hr-payroll" class="nav-link"><i class="fas fa-user-tie"></i> <span>HR & Payroll</span></a></li>
                <li><a href="#accounts" class="nav-link"><i class="fas fa-chart-line"></i> <span>Accounts</span></a></li>
                <li><a href="#subscriptions" class="nav-link"><i class="fas fa-calendar-check"></i> <span>Subscriptions</span></a></li>
                <li><a href="#users" class="nav-link"><i class="fas fa-user-circle"></i> <span>User Data</span></a></li>
                <li><a href="#ai-chat" class="nav-link"><i class="fas fa-robot"></i> <span>AI Bot Chat</span></a></li>
                <li><a href="#subscribers" class="nav-link"><i class="fas fa-user-check"></i> <span>Subscribers</span></a></li>
                <li><a href="#support-tickets" class="nav-link"><i class="fas fa-ticket-alt"></i> <span>Support Tickets</span></a></li>
                <li><a href="#contact-messages" class="nav-link"><i class="fas fa-envelope"></i> <span>Contact Messages</span></a></li>
                <li><a href="#seo" class="nav-link"><i class="fas fa-search"></i> <span>SEO</span></a></li>
                <li><a href="#reports" class="nav-link"><i class="fas fa-chart-bar"></i> <span>Reports</span></a></li>
                <li><a href="#languages" class="nav-link"><i class="fas fa-language"></i> <span>Languages</span></a></li>
                <li><a href="#email-smtp" class="nav-link"><i class="fas fa-at"></i> <span>Email SMTP</span></a></li>
                <li><a href="#settings" class="nav-link"><i class="fas fa-cog"></i> <span>Settings</span></a></li>
                <li><a href="?logout=1" class="nav-link"><i class="fas fa-sign-out-alt"></i> <span>Logout</span></a></li>
            </ul>
        </div>
        
        <!-- Main Content -->
        <div class="main-content">
            <div class="header">
                <h2 id="pageTitle">Dashboard Overview</h2>
                <div style="display: flex; align-items: center; gap: 10px;">
                    <div style="width: 40px; height: 40px; background: #283593; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold;">
                        <?php echo strtoupper(substr($_SESSION['admin_name'] ?? 'A', 0, 1)); ?>
                    </div>
                    <div>
                        <div><?php echo htmlspecialchars($_SESSION['admin_name'] ?? 'Admin'); ?></div>
                        <small><?php echo htmlspecialchars($_SESSION['admin_email'] ?? 'admin@etfcareer.org'); ?></small>
                    </div>
                </div>
            </div>
            
            <!-- Display Messages -->
            <?php if ($success_msg): ?>
            <div class="alert alert-success">
                <i class="fas fa-check-circle"></i> <?php echo htmlspecialchars($success_msg); ?>
            </div>
            <?php endif; ?>
            
            <?php if ($error_msg): ?>
            <div class="alert alert-danger">
                <i class="fas fa-exclamation-circle"></i> <?php echo htmlspecialchars($error_msg); ?>
            </div>
            <?php endif; ?>
            
            <!-- Dashboard Section -->
            <div id="dashboard" class="section active">
                <div class="stats-grid">
                    <?php 
                    $statCards = [
                        ['icon' => 'fa-box', 'count' => $stats['products'], 'label' => 'Products', 'color' => '#283593', 'section' => 'products'],
                        ['icon' => 'fa-users', 'count' => $stats['customers'], 'label' => 'Customers', 'color' => '#28a745', 'section' => 'customers'],
                        ['icon' => 'fa-shopping-cart', 'count' => $stats['orders'], 'label' => 'Orders', 'color' => '#17a2b8', 'section' => 'orders'],
                        ['icon' => 'fa-credit-card', 'count' => '$' . number_format($stats['revenue'], 2), 'label' => 'Revenue', 'color' => '#ffc107', 'section' => 'payments'],
                        ['icon' => 'fa-user-tie', 'count' => $stats['employees'], 'label' => 'Employees', 'color' => '#6f42c1', 'section' => 'hr-payroll'],
                        ['icon' => 'fa-ticket-alt', 'count' => $stats['tickets'], 'label' => 'Open Tickets', 'color' => '#fd7e14', 'section' => 'support-tickets'],
                        ['icon' => 'fa-user-check', 'count' => $stats['subscribers'], 'label' => 'Subscribers', 'color' => '#20c997', 'section' => 'subscribers'],
                        ['icon' => 'fa-envelope', 'count' => $stats['messages'], 'label' => 'New Messages', 'color' => '#e83e8c', 'section' => 'contact-messages'],
                        ['icon' => 'fa-chart-line', 'count' => $stats['accounts'], 'label' => 'Accounts', 'color' => '#007bff', 'section' => 'accounts'],
                        ['icon' => 'fa-calendar-check', 'count' => $stats['subscriptions'], 'label' => 'Subscriptions', 'color' => '#6610f2', 'section' => 'subscriptions']
                    ];
                    
                    foreach($statCards as $stat): 
                    ?>
                    <div class="stat-card" onclick="showSection('<?php echo $stat['section']; ?>')">
                        <div style="display: flex; align-items: center;">
                            <div style="width: 60px; height: 60px; background: <?php echo $stat['color']; ?>; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-right: 1rem; color: white; font-size: 1.5rem;">
                                <i class="fas <?php echo $stat['icon']; ?>"></i>
                            </div>
                            <div>
                                <h3 style="margin: 0;"><?php echo $stat['count']; ?></h3>
                                <p style="margin: 0; color: #666;"><?php echo $stat['label']; ?></p>
                            </div>
                        </div>
                    </div>
                    <?php endforeach; ?>
                </div>
                
                <div style="display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; margin-top: 1.5rem;">
                    <div>
                        <!-- Revenue Chart -->
                        <div class="card">
                            <h3>Revenue Overview</h3>
                            <div class="chart-container">
                                <canvas id="revenueChart"></canvas>
                            </div>
                        </div>
                        
                        <!-- Recent Orders -->
                        <div class="card">
                            <h3>Recent Orders</h3>
                            <div class="search-box">
                                <input type="text" id="orderSearch" placeholder="Search orders..." onkeyup="searchTable('orderSearch', 'ordersTable')">
                            </div>
                            <table id="ordersTable">
                                <thead>
                                    <tr>
                                        <th>Order #</th>
                                        <th>Customer</th>
                                        <th>Amount</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($orders)): ?>
                                        <?php foreach($orders as $order): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($order['order_number'] ?? 'N/A'); ?></td>
                                            <td><?php echo htmlspecialchars($order['customer_name'] ?? 'Guest'); ?></td>
                                            <td>$<?php echo number_format($order['final_amount'], 2); ?></td>
                                            <td>
                                                <span class="badge badge-<?php 
                                                    echo $order['order_status'] == 'delivered' ? 'success' : 
                                                           ($order['order_status'] == 'processing' ? 'info' : 
                                                           ($order['order_status'] == 'pending' ? 'warning' : 'danger'));
                                                ?>">
                                                    <?php echo ucfirst($order['order_status']); ?>
                                                </span>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr><td colspan="4" style="text-align: center;">No orders found</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                    <div>
                        <!-- Quick Actions -->
                        <div class="card">
                            <h3>Quick Actions</h3>
                            <div style="display: flex; flex-direction: column; gap: 10px;">
                                <button class="btn btn-primary" onclick="openModal('addProductModal')"><i class="fas fa-plus"></i> Add Product</button>
                                <button class="btn btn-success" onclick="openModal('addCustomerModal')"><i class="fas fa-user-plus"></i> Add Customer</button>
                                <button class="btn btn-warning" onclick="openModal('createOrderModal')"><i class="fas fa-shopping-cart"></i> Create Order</button>
                                <button class="btn btn-danger" onclick="openModal('addPaymentModal')"><i class="fas fa-credit-card"></i> Add Payment</button>
                                <button class="btn btn-info" onclick="openModal('createTicketModal')"><i class="fas fa-ticket-alt"></i> Create Ticket</button>
                            </div>
                        </div>
                        
                        <!-- Recent Activity -->
                        <div class="card" style="margin-top: 1rem;">
                            <h3>Recent Activity</h3>
                            <div style="max-height: 300px; overflow-y: auto;">
                                <?php 
                                $activities = [];
                                
                                // Add recent orders
                                foreach(array_slice($orders, 0, 3) as $order) {
                                    $activities[] = [
                                        'icon' => 'fa-shopping-cart',
                                        'color' => '#17a2b8',
                                        'text' => 'New order #' . $order['order_number'] . ' for $' . number_format($order['final_amount'], 2),
                                        'time' => $order['created_at']
                                    ];
                                }
                                
                                // Add recent customers
                                foreach(array_slice($customers, 0, 2) as $customer) {
                                    $activities[] = [
                                        'icon' => 'fa-user-plus',
                                        'color' => '#28a745',
                                        'text' => 'New customer: ' . $customer['name'],
                                        'time' => $customer['created_at']
                                    ];
                                }
                                
                                // Sort activities by time
                                usort($activities, function($a, $b) {
                                    return strtotime($b['time']) - strtotime($a['time']);
                                });
                                
                                foreach(array_slice($activities, 0, 5) as $activity):
                                ?>
                                <div style="display: flex; align-items: start; gap: 10px; padding: 10px 0; border-bottom: 1px solid #eee;">
                                    <div style="width: 30px; height: 30px; background: <?php echo $activity['color']; ?>; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white;">
                                        <i class="fas <?php echo $activity['icon']; ?> fa-xs"></i>
                                    </div>
                                    <div style="flex: 1;">
                                        <div><?php echo htmlspecialchars($activity['text']); ?></div>
                                        <small style="color: #666;"><?php echo date('M d, H:i', strtotime($activity['time'])); ?></small>
                                    </div>
                                </div>
                                <?php endforeach; ?>
                                
                                <?php if (empty($activities)): ?>
                                <div style="text-align: center; padding: 20px; color: #666;">
                                    No recent activity
                                </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Products Section -->
            <div id="products" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Product Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addProductModal')"><i class="fas fa-plus"></i> Add Product</button>
                    </div>
                    
                    <div class="search-box">
                        <input type="text" id="productSearch" placeholder="Search products..." onkeyup="searchTable('productSearch', 'productsTable')">
                    </div>
                    
                    <table id="productsTable">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>SKU</th>
                                <th>Category</th>
                                <th>Price</th>
                                <th>Stock</th>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($products)): ?>
                                <?php foreach($products as $product): ?>
                                <tr>
                                    <td><?php echo $product['id']; ?></td>
                                    <td><?php echo htmlspecialchars($product['name']); ?></td>
                                    <td><?php echo htmlspecialchars($product['sku'] ?? 'N/A'); ?></td>
                                    <td><?php echo htmlspecialchars($product['category'] ?? 'Uncategorized'); ?></td>
                                    <td>$<?php echo number_format($product['price'], 2); ?></td>
                                    <td><?php echo $product['stock']; ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $product['status'] == 'active' ? 'success' : 
                                                                    ($product['status'] == 'out-of-stock' ? 'warning' : 'danger'); ?>">
                                            <?php echo ucfirst($product['status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <button class="btn btn-primary btn-sm" onclick="editProduct(<?php echo $product['id']; ?>)">
                                            <i class="fas fa-edit"></i>
                                        </button>
                                        <button class="btn btn-danger btn-sm" onclick="deleteProduct(<?php echo $product['id']; ?>)">
                                            <i class="fas fa-trash"></i>
                                        </button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="8" style="text-align: center;">No products found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Customers Section -->
            <div id="customers" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Customer Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addCustomerModal')"><i class="fas fa-plus"></i> Add Customer</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th>Status</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($customers)): ?>
                                <?php foreach($customers as $customer): ?>
                                <tr>
                                    <td><?php echo $customer['id']; ?></td>
                                    <td><?php echo htmlspecialchars($customer['name']); ?></td>
                                    <td><?php echo htmlspecialchars($customer['email']); ?></td>
                                    <td><?php echo htmlspecialchars($customer['phone'] ?? 'N/A'); ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $customer['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($customer['status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-edit"></i></button>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="6" style="text-align: center;">No customers found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Orders Section -->
            <div id="orders" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Order Management</h3>
                        <button class="btn btn-primary" onclick="openModal('createOrderModal')"><i class="fas fa-plus"></i> Create Order</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Order #</th>
                                <th>Customer</th>
                                <th>Amount</th>
                                <th>Status</th>
                                <th>Payment</th>
                                <th>Date</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($orders)): ?>
                                <?php foreach($orders as $order): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($order['order_number']); ?></td>
                                    <td><?php echo htmlspecialchars($order['customer_name'] ?? 'Guest'); ?></td>
                                    <td>$<?php echo number_format($order['final_amount'], 2); ?></td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $order['order_status'] == 'delivered' ? 'success' : 
                                                   ($order['order_status'] == 'processing' ? 'info' : 
                                                   ($order['order_status'] == 'pending' ? 'warning' : 'danger'));
                                        ?>">
                                            <?php echo ucfirst($order['order_status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $order['payment_status'] == 'paid' ? 'success' : 
                                                   ($order['payment_status'] == 'pending' ? 'warning' : 'danger');
                                        ?>">
                                            <?php echo ucfirst($order['payment_status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($order['created_at'])); ?></td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-eye"></i></button>
                                        <button class="btn btn-warning btn-sm"><i class="fas fa-edit"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No orders found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Payment Gateway Section -->
            <div id="payments" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Payment Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addPaymentModal')"><i class="fas fa-plus"></i> Add Payment</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Payment #</th>
                                <th>Order #</th>
                                <th>Amount</th>
                                <th>Gateway</th>
                                <th>Status</th>
                                <th>Date</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($payments)): ?>
                                <?php foreach($payments as $payment): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($payment['payment_number']); ?></td>
                                    <td><?php echo htmlspecialchars($payment['order_number'] ?? 'N/A'); ?></td>
                                    <td>$<?php echo number_format($payment['amount'], 2); ?></td>
                                    <td><?php echo ucfirst($payment['gateway']); ?></td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $payment['payment_status'] == 'completed' ? 'success' : 
                                                   ($payment['payment_status'] == 'pending' ? 'warning' : 'danger');
                                        ?>">
                                            <?php echo ucfirst($payment['payment_status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($payment['created_at'])); ?></td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="6" style="text-align: center;">No payments found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- HR & Payroll Section -->
            <div id="hr-payroll" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>HR & Payroll Management</h3>
                        <div class="action-buttons">
                            <button class="btn btn-primary" onclick="openModal('addEmployeeModal')"><i class="fas fa-user-plus"></i> Add Employee</button>
                            <button class="btn btn-success" onclick="openModal('processPayrollModal')"><i class="fas fa-money-bill-wave"></i> Process Payroll</button>
                        </div>
                    </div>
                    
                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
                        <!-- Employees Table -->
                        <div>
                            <h4>Employees</h4>
                            <table>
                                <thead>
                                    <tr>
                                        <th>Employee ID</th>
                                        <th>Name</th>
                                        <th>Department</th>
                                        <th>Salary</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($employees)): ?>
                                        <?php foreach($employees as $employee): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($employee['employee_id']); ?></td>
                                            <td><?php echo htmlspecialchars($employee['name']); ?></td>
                                            <td><?php echo htmlspecialchars($employee['department']); ?></td>
                                            <td>$<?php echo number_format($employee['salary'], 2); ?></td>
                                            <td>
                                                <span class="badge badge-<?php echo $employee['status'] == 'active' ? 'success' : 'danger'; ?>">
                                                    <?php echo ucfirst($employee['status']); ?>
                                                </span>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr><td colspan="5" style="text-align: center;">No employees found</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Payroll History -->
                        <div>
                            <h4>Recent Payroll</h4>
                            <table>
                                <thead>
                                    <tr>
                                        <th>Employee</th>
                                        <th>Period</th>
                                        <th>Net Salary</th>
                                        <th>Status</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($payrolls)): ?>
                                        <?php foreach($payrolls as $payroll): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($payroll['employee_name']); ?></td>
                                            <td><?php echo date('M d', strtotime($payroll['pay_period_start'])) . ' - ' . date('M d', strtotime($payroll['pay_period_end'])); ?></td>
                                            <td>$<?php echo number_format($payroll['net_salary'], 2); ?></td>
                                            <td>
                                                <span class="badge badge-<?php echo $payroll['payment_status'] == 'paid' ? 'success' : 'warning'; ?>">
                                                    <?php echo ucfirst($payroll['payment_status']); ?>
                                                </span>
                                            </td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr><td colspan="4" style="text-align: center;">No payroll records found</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Accounts Section -->
            <div id="accounts" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Accounts Management</h3>
                        <div class="action-buttons">
                            <button class="btn btn-primary" onclick="openModal('addAccountModal')"><i class="fas fa-plus"></i> Add Account</button>
                            <button class="btn btn-success" onclick="openModal('recordTransactionModal')"><i class="fas fa-exchange-alt"></i> Record Transaction</button>
                        </div>
                    </div>
                    
                    <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;">
                        <!-- Accounts List -->
                        <div>
                            <h4>Accounts</h4>
                            <table>
                                <thead>
                                    <tr>
                                        <th>Account #</th>
                                        <th>Name</th>
                                        <th>Type</th>
                                        <th>Balance</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($accounts)): ?>
                                        <?php foreach($accounts as $account): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($account['account_number']); ?></td>
                                            <td><?php echo htmlspecialchars($account['account_name']); ?></td>
                                            <td>
                                                <span class="badge badge-<?php 
                                                    echo $account['account_type'] == 'asset' ? 'success' : 
                                                           ($account['account_type'] == 'liability' ? 'danger' : 
                                                           ($account['account_type'] == 'revenue' ? 'info' : 'warning'));
                                                ?>">
                                                    <?php echo ucfirst($account['account_type']); ?>
                                                </span>
                                            </td>
                                            <td>$<?php echo number_format($account['balance'], 2); ?></td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr><td colspan="4" style="text-align: center;">No accounts found</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Recent Transactions -->
                        <div>
                            <h4>Recent Transactions</h4>
                            <table>
                                <thead>
                                    <tr>
                                        <th>Transaction #</th>
                                        <th>Account</th>
                                        <th>Type</th>
                                        <th>Amount</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php if (!empty($transactions)): ?>
                                        <?php foreach($transactions as $transaction): ?>
                                        <tr>
                                            <td><?php echo htmlspecialchars($transaction['transaction_number']); ?></td>
                                            <td><?php echo htmlspecialchars($transaction['account_name']); ?></td>
                                            <td>
                                                <span class="badge badge-<?php echo $transaction['type'] == 'credit' ? 'success' : 'danger'; ?>">
                                                    <?php echo ucfirst($transaction['type']); ?>
                                                </span>
                                            </td>
                                            <td>$<?php echo number_format($transaction['amount'], 2); ?></td>
                                        </tr>
                                        <?php endforeach; ?>
                                    <?php else: ?>
                                        <tr><td colspan="4" style="text-align: center;">No transactions found</td></tr>
                                    <?php endif; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Subscriptions Section -->
            <div id="subscriptions" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Subscription Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addSubscriptionModal')"><i class="fas fa-plus"></i> Add Subscription</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Customer</th>
                                <th>Plan</th>
                                <th>Type</th>
                                <th>Price</th>
                                <th>Status</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($subscriptions)): ?>
                                <?php foreach($subscriptions as $subscription): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($subscription['customer_name']); ?></td>
                                    <td><?php echo htmlspecialchars($subscription['plan_name']); ?></td>
                                    <td><?php echo ucfirst($subscription['plan_type']); ?></td>
                                    <td>$<?php echo number_format($subscription['price'], 2); ?></td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $subscription['status'] == 'active' ? 'success' : 
                                                   ($subscription['status'] == 'pending' ? 'warning' : 'danger');
                                        ?>">
                                            <?php echo ucfirst($subscription['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo $subscription['start_date']; ?></td>
                                    <td><?php echo $subscription['end_date']; ?></td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No subscriptions found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- User Data Section -->
            <div id="users" class="section">
                <div class="card">
                    <h3>User Data Management</h3>
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Phone</th>
                                <th>Role</th>
                                <th>Status</th>
                                <th>Joined</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            $all_users = $pdo->query("SELECT * FROM users ORDER BY id DESC LIMIT 20")->fetchAll();
                            if (!empty($all_users)): ?>
                                <?php foreach($all_users as $user): ?>
                                <tr>
                                    <td><?php echo $user['id']; ?></td>
                                    <td><?php echo htmlspecialchars($user['name']); ?></td>
                                    <td><?php echo htmlspecialchars($user['email']); ?></td>
                                    <td><?php echo htmlspecialchars($user['phone'] ?? 'N/A'); ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $user['role'] == 'admin' ? 'danger' : 'info'; ?>">
                                            <?php echo ucfirst($user['role']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge badge-<?php echo $user['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($user['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($user['created_at'])); ?></td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No users found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- AI Bot Chat Section -->
            <div id="ai-chat" class="section">
                <div class="card">
                    <h3>AI Assistant Chat</h3>
                    <div style="height: 300px; overflow-y: auto; padding: 1rem; background: #f8f9fa; border-radius: 5px; margin-bottom: 1rem;" id="chatMessages">
                        <?php if (!empty($ai_chats)): ?>
                            <?php foreach($ai_chats as $chat): ?>
                            <div style="margin-bottom: 15px;">
                                <div style="background: #e3f2fd; padding: 10px; border-radius: 10px; margin-bottom: 5px;">
                                    <strong>You:</strong> <?php echo htmlspecialchars($chat['user_message']); ?>
                                </div>
                                <div style="background: #f1f8e9; padding: 10px; border-radius: 10px;">
                                    <strong>AI:</strong> <?php echo htmlspecialchars($chat['bot_reply']); ?>
                                </div>
                                <small style="color: #666; margin-left: 10px;"><?php echo date('H:i', strtotime($chat['created_at'])); ?></small>
                            </div>
                            <?php endforeach; ?>
                        <?php else: ?>
                            <div style="text-align: center; padding: 20px; color: #666;">
                                No chat history yet. Start a conversation with AI!
                            </div>
                        <?php endif; ?>
                    </div>
                    <form method="POST" action="" onsubmit="scrollChat()">
                        <div style="display: flex; gap: 10px;">
                            <input type="text" name="message" placeholder="Ask AI assistant about business management..." style="flex: 1; padding: 10px; border: 1px solid #ddd; border-radius: 4px;" required>
                            <button type="submit" name="ai_message" class="btn btn-primary">
                                <i class="fas fa-paper-plane"></i> Send
                            </button>
                        </div>
                    </form>
                </div>
            </div>
            
            <!-- Subscribers Section -->
            <div id="subscribers" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Subscriber Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addSubscriberModal')"><i class="fas fa-plus"></i> Add Subscriber</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Email</th>
                                <th>Name</th>
                                <th>Status</th>
                                <th>Subscribed</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($subscribers)): ?>
                                <?php foreach($subscribers as $subscriber): ?>
                                <tr>
                                    <td><?php echo $subscriber['id']; ?></td>
                                    <td><?php echo htmlspecialchars($subscriber['email']); ?></td>
                                    <td><?php echo htmlspecialchars($subscriber['name'] ?? 'N/A'); ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $subscriber['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($subscriber['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo $subscriber['subscription_date']; ?></td>
                                    <td>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="6" style="text-align: center;">No subscribers found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Support Tickets Section -->
            <div id="support-tickets" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Support Ticket Management</h3>
                        <button class="btn btn-primary" onclick="openModal('createTicketModal')"><i class="fas fa-plus"></i> Create Ticket</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Ticket #</th>
                                <th>Customer</th>
                                <th>Subject</th>
                                <th>Priority</th>
                                <th>Status</th>
                                <th>Created</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($tickets)): ?>
                                <?php foreach($tickets as $ticket): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($ticket['ticket_number']); ?></td>
                                    <td><?php echo htmlspecialchars($ticket['customer_name']); ?></td>
                                    <td><?php echo htmlspecialchars($ticket['subject']); ?></td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $ticket['priority'] == 'high' ? 'danger' : 
                                                   ($ticket['priority'] == 'medium' ? 'warning' : 'info');
                                        ?>">
                                            <?php echo ucfirst($ticket['priority']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $ticket['status'] == 'open' ? 'warning' : 
                                                   ($ticket['status'] == 'in-progress' ? 'info' : 'success');
                                        ?>">
                                            <?php echo ucfirst($ticket['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($ticket['created_at'])); ?></td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-eye"></i></button>
                                        <button class="btn btn-success btn-sm"><i class="fas fa-reply"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No tickets found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Contact Messages Section -->
            <div id="contact-messages" class="section">
                <div class="card">
                    <h3>Contact Messages</h3>
                    <table>
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Subject</th>
                                <th>Status</th>
                                <th>Received</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($messages)): ?>
                                <?php foreach($messages as $message): ?>
                                <tr>
                                    <td><?php echo $message['id']; ?></td>
                                    <td><?php echo htmlspecialchars($message['name']); ?></td>
                                    <td><?php echo htmlspecialchars($message['email']); ?></td>
                                    <td><?php echo htmlspecialchars($message['subject']); ?></td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $message['status'] == 'unread' ? 'warning' : 
                                                   ($message['status'] == 'replied' ? 'success' : 'info');
                                        ?>">
                                            <?php echo ucfirst($message['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($message['created_at'])); ?></td>
                                    <td>
                                        <button class="btn btn-primary btn-sm" onclick="openReplyModal(<?php echo $message['id']; ?>, '<?php echo htmlspecialchars($message['email']); ?>')">
                                            <i class="fas fa-reply"></i>
                                        </button>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No messages found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- SEO Section -->
            <div id="seo" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>SEO Management</h3>
                        <button class="btn btn-primary" onclick="openModal('seoModal')"><i class="fas fa-plus"></i> Add SEO Page</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Page Name</th>
                                <th>URL</th>
                                <th>Meta Title</th>
                                <th>Meta Description</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($seo_pages)): ?>
                                <?php foreach($seo_pages as $seo): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($seo['page_name']); ?></td>
                                    <td><?php echo htmlspecialchars($seo['page_url']); ?></td>
                                    <td><?php echo htmlspecialchars(substr($seo['meta_title'] ?? '', 0, 50)) . '...'; ?></td>
                                    <td><?php echo htmlspecialchars(substr($seo['meta_description'] ?? '', 0, 70)) . '...'; ?></td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-edit"></i></button>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="5" style="text-align: center;">No SEO pages found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Reports Section -->
            <div id="reports" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Report Generation</h3>
                        <button class="btn btn-primary" onclick="openModal('generateReportModal')"><i class="fas fa-file-export"></i> Generate Report</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Report Name</th>
                                <th>Type</th>
                                <th>Generated By</th>
                                <th>Status</th>
                                <th>Created</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($reports)): ?>
                                <?php foreach($reports as $report): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($report['report_name']); ?></td>
                                    <td><?php echo ucfirst($report['report_type']); ?></td>
                                    <td>Admin</td>
                                    <td>
                                        <span class="badge badge-<?php 
                                            echo $report['status'] == 'completed' ? 'success' : 
                                                   ($report['status'] == 'generating' ? 'warning' : 'danger');
                                        ?>">
                                            <?php echo ucfirst($report['status']); ?>
                                        </span>
                                    </td>
                                    <td><?php echo date('Y-m-d', strtotime($report['created_at'])); ?></td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-download"></i></button>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="6" style="text-align: center;">No reports found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Languages Section -->
            <div id="languages" class="section">
                <div class="card">
                    <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem;">
                        <h3>Language Management</h3>
                        <button class="btn btn-primary" onclick="openModal('addLanguageModal')"><i class="fas fa-plus"></i> Add Language</button>
                    </div>
                    
                    <table>
                        <thead>
                            <tr>
                                <th>Language</th>
                                <th>Native Name</th>
                                <th>Code</th>
                                <th>Direction</th>
                                <th>Status</th>
                                <th>Default</th>
                                <th>Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php if (!empty($languages)): ?>
                                <?php foreach($languages as $language): ?>
                                <tr>
                                    <td><?php echo htmlspecialchars($language['language_name']); ?></td>
                                    <td><?php echo htmlspecialchars($language['native_name']); ?></td>
                                    <td><?php echo htmlspecialchars($language['language_code']); ?></td>
                                    <td><?php echo strtoupper($language['direction']); ?></td>
                                    <td>
                                        <span class="badge badge-<?php echo $language['status'] == 'active' ? 'success' : 'danger'; ?>">
                                            <?php echo ucfirst($language['status']); ?>
                                        </span>
                                    </td>
                                    <td>
                                        <?php if ($language['is_default'] == 1): ?>
                                        <span class="badge badge-success">Default</span>
                                        <?php endif; ?>
                                    </td>
                                    <td>
                                        <button class="btn btn-primary btn-sm"><i class="fas fa-edit"></i></button>
                                        <button class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></button>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            <?php else: ?>
                                <tr><td colspan="7" style="text-align: center;">No languages found</td></tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <!-- Email SMTP Section -->
            <div id="email-smtp" class="section">
                <div class="card">
                    <h3>Email SMTP Configuration</h3>
                    <form method="POST" action="">
                        <div class="form-group">
                            <label>SMTP Host</label>
                            <input type="text" name="host" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['host'] ?? $settings['smtp_host'] ?? ''); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label>SMTP Port</label>
                            <input type="number" name="port" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['port'] ?? $settings['smtp_port'] ?? 587); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label>Username</label>
                            <input type="text" name="username" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['username'] ?? $settings['smtp_username'] ?? ''); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label>Password</label>
                            <input type="password" name="password" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['password'] ?? $settings['smtp_password'] ?? ''); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label>Encryption</label>
                            <select name="encryption" class="form-control">
                                <option value="tls" <?php echo ($smtp_settings['encryption'] ?? $settings['smtp_encryption'] ?? '') == 'tls' ? 'selected' : ''; ?>>TLS</option>
                                <option value="ssl" <?php echo ($smtp_settings['encryption'] ?? $settings['smtp_encryption'] ?? '') == 'ssl' ? 'selected' : ''; ?>>SSL</option>
                            </select>
                        </div>
                        
                        <div class="form-group">
                            <label>From Email</label>
                            <input type="email" name="from_email" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['from_email'] ?? $settings['site_email'] ?? ''); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label>From Name</label>
                            <input type="text" name="from_name" class="form-control" value="<?php echo htmlspecialchars($smtp_settings['from_name'] ?? $settings['site_name'] ?? ''); ?>" required>
                        </div>
                        
                        <button type="submit" name="save_smtp" class="btn btn-primary">
                            <i class="fas fa-save"></i> Save SMTP Settings
                        </button>
                    </form>
                </div>
            </div>
            
            <!-- Settings Section -->
            <div id="settings" class="section">
                <div class="card">
                    <h3>General Settings</h3>
                    <form method="POST" action="">
                        <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                            <div class="form-group">
                                <label>Site Name</label>
                                <input type="text" name="site_name" class="form-control" value="<?php echo htmlspecialchars($settings['site_name'] ?? 'ETF Career'); ?>">
                            </div>
                            
                            <div class="form-group">
                                <label>Site Title</label>
                                <input type="text" name="site_title" class="form-control" value="<?php echo htmlspecialchars($settings['site_title'] ?? 'ETF Career - Dashboard'); ?>">
                            </div>
                            
                            <div class="form-group">
                                <label>Site Email</label>
                                <input type="email" name="site_email" class="form-control" value="<?php echo htmlspecialchars($settings['site_email'] ?? 'info@etfcareer.org'); ?>">
                            </div>
                            
                            <div class="form-group">
                                <label>Site Phone</label>
                                <input type="text" name="site_phone" class="form-control" value="<?php echo htmlspecialchars($settings['site_phone'] ?? '+1 234 567 8900'); ?>">
                            </div>
                            
                            <div class="form-group">
                                <label>Currency</label>
                                <select name="currency" class="form-control">
                                    <option value="USD" <?php echo ($settings['currency'] ?? 'USD') == 'USD' ? 'selected' : ''; ?>>USD ($)</option>
                                    <option value="EUR" <?php echo ($settings['currency'] ?? '') == 'EUR' ? 'selected' : ''; ?>>EUR (€)</option>
                                    <option value="GBP" <?php echo ($settings['currency'] ?? '') == 'GBP' ? 'selected' : ''; ?>>GBP (£)</option>
                                    <option value="INR" <?php echo ($settings['currency'] ?? '') == 'INR' ? 'selected' : ''; ?>>INR (₹)</option>
                                </select>
                            </div>
                            
                            <div class="form-group">
                                <label>Timezone</label>
                                <select name="timezone" class="form-control">
                                    <option value="UTC" <?php echo ($settings['timezone'] ?? 'UTC') == 'UTC' ? 'selected' : ''; ?>>UTC</option>
                                    <option value="America/New_York" <?php echo ($settings['timezone'] ?? '') == 'America/New_York' ? 'selected' : ''; ?>>EST (New York)</option>
                                    <option value="Europe/London" <?php echo ($settings['timezone'] ?? '') == 'Europe/London' ? 'selected' : ''; ?>>GMT (London)</option>
                                    <option value="Asia/Kolkata" <?php echo ($settings['timezone'] ?? '') == 'Asia/Kolkata' ? 'selected' : ''; ?>>IST (Kolkata)</option>
                                </select>
                            </div>
                            
                            <div class="form-group">
                                <label>Items Per Page</label>
                                <input type="number" name="items_per_page" class="form-control" value="<?php echo htmlspecialchars($settings['items_per_page'] ?? '10'); ?>">
                            </div>
                            
                            <div class="form-group">
                                <label>Maintenance Mode</label><br>
                                <input type="checkbox" name="maintenance_mode" value="1" <?php echo ($settings['maintenance_mode'] ?? '0') == '1' ? 'checked' : ''; ?>> Enable
                            </div>
                            
                            <div class="form-group">
                                <label>Allow Registration</label><br>
                                <input type="checkbox" name="allow_registration" value="1" <?php echo ($settings['allow_registration'] ?? '1') == '1' ? 'checked' : ''; ?>> Allow
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label>Site Address</label>
                            <textarea name="site_address" class="form-control" rows="2"><?php echo htmlspecialchars($settings['site_address'] ?? '123 Business Street, City, Country'); ?></textarea>
                        </div>
                        
                        <div class="form-group">
                            <label>Footer Text</label>
                            <textarea name="footer_text" class="form-control" rows="2"><?php echo htmlspecialchars($settings['footer_text'] ?? '© 2024 ETF Career. All rights reserved.'); ?></textarea>
                        </div>
                        
                        <button type="submit" name="save_settings" class="btn btn-primary">
                            <i class="fas fa-save"></i> Save Settings
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
    
    <!-- ============================================
    MODALS FOR ALL FEATURES
    ============================================ -->
    
    <!-- Add Product Modal -->
    <div id="addProductModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add New Product</h3>
                <button onclick="closeModal('addProductModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Product Name</label>
                    <input type="text" name="name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>SKU</label>
                    <input type="text" name="sku" class="form-control">
                </div>
                <div class="form-group">
                    <label>Category</label>
                    <select name="category" class="form-control">
                        <option value="">Select Category</option>
                        <?php 
                        $categories = $pdo->query("SELECT * FROM categories")->fetchAll();
                        foreach($categories as $cat): ?>
                        <option value="<?php echo htmlspecialchars($cat['name']); ?>"><?php echo htmlspecialchars($cat['name']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div class="form-group">
                        <label>Price ($)</label>
                        <input type="number" name="price" class="form-control" step="0.01" required>
                    </div>
                    <div class="form-group">
                        <label>Cost ($)</label>
                        <input type="number" name="cost" class="form-control" step="0.01">
                    </div>
                </div>
                <div class="form-group">
                    <label>Stock Quantity</label>
                    <input type="number" name="stock" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <textarea name="description" class="form-control" rows="3"></textarea>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_product" class="btn btn-primary">Add Product</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addProductModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Customer Modal -->
    <div id="addCustomerModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add New Customer</h3>
                <button onclick="closeModal('addCustomerModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Full Name</label>
                    <input type="text" name="name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Email Address</label>
                    <input type="email" name="email" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Phone Number</label>
                    <input type="tel" name="phone" class="form-control">
                </div>
                <div class="form-group">
                    <label>Address</label>
                    <textarea name="address" class="form-control" rows="2"></textarea>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_customer" class="btn btn-primary">Add Customer</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addCustomerModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Create Order Modal -->
    <div id="createOrderModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Create New Order</h3>
                <button onclick="closeModal('createOrderModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Customer</label>
                    <select name="user_id" class="form-control" required>
                        <option value="">Select Customer</option>
                        <?php 
                        $customers = $pdo->query("SELECT * FROM users WHERE role = 'customer'")->fetchAll();
                        foreach($customers as $customer): ?>
                        <option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['name'] . ' - ' . $customer['email']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Total Amount ($)</label>
                    <input type="number" name="total_amount" class="form-control" step="0.01" required>
                </div>
                <div class="form-group">
                    <label>Payment Method</label>
                    <select name="payment_method" class="form-control">
                        <option value="cash">Cash</option>
                        <option value="card">Credit Card</option>
                        <option value="bank">Bank Transfer</option>
                        <option value="paypal">PayPal</option>
                        <option value="stripe">Stripe</option>
                    </select>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="create_order" class="btn btn-primary">Create Order</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('createOrderModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Payment Modal -->
    <div id="addPaymentModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add Payment</h3>
                <button onclick="closeModal('addPaymentModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Order</label>
                    <select name="order_id" class="form-control" required>
                        <option value="">Select Order</option>
                        <?php 
                        $orders = $pdo->query("SELECT * FROM orders WHERE payment_status = 'pending'")->fetchAll();
                        foreach($orders as $order): ?>
                        <option value="<?php echo $order['id']; ?>">Order #<?php echo htmlspecialchars($order['order_number']) . ' - $' . number_format($order['final_amount'], 2); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Amount ($)</label>
                    <input type="number" name="amount" class="form-control" step="0.01" required>
                </div>
                <div class="form-group">
                    <label>Payment Gateway</label>
                    <select name="gateway" class="form-control">
                        <option value="cash">Cash</option>
                        <option value="card">Credit Card</option>
                        <option value="bank">Bank Transfer</option>
                        <option value="paypal">PayPal</option>
                        <option value="stripe">Stripe</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Transaction ID (Optional)</label>
                    <input type="text" name="transaction_id" class="form-control">
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_payment" class="btn btn-primary">Add Payment</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addPaymentModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Employee Modal -->
    <div id="addEmployeeModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add New Employee</h3>
                <button onclick="closeModal('addEmployeeModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Full Name</label>
                    <input type="text" name="name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Email Address</label>
                    <input type="email" name="email" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Phone Number</label>
                    <input type="tel" name="phone" class="form-control">
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div class="form-group">
                        <label>Department</label>
                        <input type="text" name="department" class="form-control">
                    </div>
                    <div class="form-group">
                        <label>Position</label>
                        <input type="text" name="position" class="form-control">
                    </div>
                </div>
                <div class="form-group">
                    <label>Monthly Salary ($)</label>
                    <input type="number" name="salary" class="form-control" step="0.01" required>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_employee" class="btn btn-primary">Add Employee</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addEmployeeModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Process Payroll Modal -->
    <div id="processPayrollModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Process Payroll</h3>
                <button onclick="closeModal('processPayrollModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Employee</label>
                    <select name="employee_id" class="form-control" required>
                        <option value="">Select Employee</option>
                        <?php 
                        $employees = $pdo->query("SELECT * FROM employees WHERE status = 'active'")->fetchAll();
                        foreach($employees as $employee): ?>
                        <option value="<?php echo $employee['id']; ?>" data-salary="<?php echo $employee['salary']; ?>" 
                                onchange="calculateNetSalary(this)">
                            <?php echo htmlspecialchars($employee['name'] . ' - $' . number_format($employee['salary'], 2)); ?>
                        </option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Basic Salary ($)</label>
                    <input type="number" name="basic_salary" id="basicSalary" class="form-control" step="0.01" required onchange="calculateNetSalary()">
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div class="form-group">
                        <label>Overtime ($)</label>
                        <input type="number" name="overtime" id="overtime" class="form-control" step="0.01" value="0" onchange="calculateNetSalary()">
                    </div>
                    <div class="form-group">
                        <label>Bonuses ($)</label>
                        <input type="number" name="bonuses" id="bonuses" class="form-control" step="0.01" value="0" onchange="calculateNetSalary()">
                    </div>
                </div>
                <div class="form-group">
                    <label>Deductions ($)</label>
                    <input type="number" name="deductions" id="deductions" class="form-control" step="0.01" value="0" onchange="calculateNetSalary()">
                </div>
                <div class="form-group">
                    <label>Net Salary ($)</label>
                    <input type="text" id="netSalary" class="form-control" readonly style="background: #f8f9fa; font-weight: bold;">
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="process_payroll" class="btn btn-primary">Process Payroll</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('processPayrollModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Account Modal -->
    <div id="addAccountModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add New Account</h3>
                <button onclick="closeModal('addAccountModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Account Name</label>
                    <input type="text" name="account_name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Account Type</label>
                    <select name="account_type" class="form-control" required>
                        <option value="asset">Asset</option>
                        <option value="liability">Liability</option>
                        <option value="equity">Equity</option>
                        <option value="revenue">Revenue</option>
                        <option value="expense">Expense</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Account Number</label>
                    <input type="text" name="account_number" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Opening Balance ($)</label>
                    <input type="number" name="balance" class="form-control" step="0.01" required>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_account" class="btn btn-primary">Add Account</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addAccountModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Record Transaction Modal -->
    <div id="recordTransactionModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Record Transaction</h3>
                <button onclick="closeModal('recordTransactionModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Account</label>
                    <select name="account_id" class="form-control" required>
                        <option value="">Select Account</option>
                        <?php 
                        $accounts = $pdo->query("SELECT * FROM accounts")->fetchAll();
                        foreach($accounts as $account): ?>
                        <option value="<?php echo $account['id']; ?>"><?php echo htmlspecialchars($account['account_name'] . ' - ' . $account['account_number']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Transaction Type</label>
                    <select name="type" class="form-control" required>
                        <option value="debit">Debit (Money Out)</option>
                        <option value="credit">Credit (Money In)</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Amount ($)</label>
                    <input type="number" name="amount" class="form-control" step="0.01" required>
                </div>
                <div class="form-group">
                    <label>Description</label>
                    <input type="text" name="description" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Category</label>
                    <input type="text" name="category" class="form-control" placeholder="e.g., Sales, Purchase, Salary, etc.">
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="record_transaction" class="btn btn-primary">Record Transaction</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('recordTransactionModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Subscription Modal -->
    <div id="addSubscriptionModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add Subscription</h3>
                <button onclick="closeModal('addSubscriptionModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Customer</label>
                    <select name="user_id" class="form-control" required>
                        <option value="">Select Customer</option>
                        <?php 
                        $customers = $pdo->query("SELECT * FROM users WHERE role = 'customer'")->fetchAll();
                        foreach($customers as $customer): ?>
                        <option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['name'] . ' - ' . $customer['email']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Plan Name</label>
                    <input type="text" name="plan_name" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Plan Type</label>
                    <select name="plan_type" class="form-control" required>
                        <option value="monthly">Monthly</option>
                        <option value="yearly">Yearly</option>
                        <option value="lifetime">Lifetime</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Price ($)</label>
                    <input type="number" name="price" class="form-control" step="0.01" required>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_subscription" class="btn btn-primary">Add Subscription</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addSubscriptionModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Subscriber Modal -->
    <div id="addSubscriberModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add Subscriber</h3>
                <button onclick="closeModal('addSubscriberModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Email Address</label>
                    <input type="email" name="email" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Name (Optional)</label>
                    <input type="text" name="name" class="form-control">
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_subscriber" class="btn btn-primary">Add Subscriber</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addSubscriberModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Create Ticket Modal -->
    <div id="createTicketModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Create Support Ticket</h3>
                <button onclick="closeModal('createTicketModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Select Customer</label>
                    <select name="user_id" class="form-control" required>
                        <option value="">Select Customer</option>
                        <?php 
                        $customers = $pdo->query("SELECT * FROM users WHERE role = 'customer'")->fetchAll();
                        foreach($customers as $customer): ?>
                        <option value="<?php echo $customer['id']; ?>"><?php echo htmlspecialchars($customer['name'] . ' - ' . $customer['email']); ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-group">
                    <label>Subject</label>
                    <input type="text" name="subject" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Message</label>
                    <textarea name="message" class="form-control" rows="4" required></textarea>
                </div>
                <div class="form-group">
                    <label>Priority</label>
                    <select name="priority" class="form-control">
                        <option value="low">Low</option>
                        <option value="medium" selected>Medium</option>
                        <option value="high">High</option>
                        <option value="urgent">Urgent</option>
                    </select>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="create_ticket" class="btn btn-primary">Create Ticket</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('createTicketModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Reply Message Modal -->
    <div id="replyMessageModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Reply to Message</h3>
                <button onclick="closeModal('replyMessageModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <input type="hidden" name="message_id" id="replyMessageId">
                <div class="form-group">
                    <label>To</label>
                    <input type="text" id="replyToEmail" class="form-control" readonly>
                </div>
                <div class="form-group">
                    <label>Your Reply</label>
                    <textarea name="reply" class="form-control" rows="4" required placeholder="Type your reply here..."></textarea>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="reply_message" class="btn btn-primary">Send Reply</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('replyMessageModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- SEO Modal -->
    <div id="seoModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add SEO Page</h3>
                <button onclick="closeModal('seoModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Page Name</label>
                    <input type="text" name="page_name" class="form-control" required placeholder="e.g., Home Page, About Us">
                </div>
                <div class="form-group">
                    <label>Page URL</label>
                    <input type="text" name="page_url" class="form-control" required placeholder="e.g., /, /about, /contact">
                </div>
                <div class="form-group">
                    <label>Meta Title</label>
                    <input type="text" name="meta_title" class="form-control" required>
                </div>
                <div class="form-group">
                    <label>Meta Description</label>
                    <textarea name="meta_description" class="form-control" rows="3" required></textarea>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="save_seo" class="btn btn-primary">Save SEO</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('seoModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Generate Report Modal -->
    <div id="generateReportModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Generate Report</h3>
                <button onclick="closeModal('generateReportModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Report Type</label>
                    <select name="report_type" class="form-control" required>
                        <option value="sales">Sales Report</option>
                        <option value="customer">Customer Report</option>
                        <option value="product">Product Report</option>
                        <option value="financial">Financial Report</option>
                        <option value="inventory">Inventory Report</option>
                        <option value="employee">Employee Report</option>
                    </select>
                </div>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 1rem;">
                    <div class="form-group">
                        <label>Start Date</label>
                        <input type="date" name="start_date" class="form-control" required>
                    </div>
                    <div class="form-group">
                        <label>End Date</label>
                        <input type="date" name="end_date" class="form-control" required>
                    </div>
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="generate_report" class="btn btn-primary">Generate Report</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('generateReportModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Add Language Modal -->
    <div id="addLanguageModal" class="modal">
        <div class="modal-content">
            <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem;">
                <h3>Add Language</h3>
                <button onclick="closeModal('addLanguageModal')" style="background: none; border: none; font-size: 1.5rem; cursor: pointer;">&times;</button>
            </div>
            <form method="POST" action="">
                <div class="form-group">
                    <label>Language Name</label>
                    <input type="text" name="language_name" class="form-control" required placeholder="e.g., English">
                </div>
                <div class="form-group">
                    <label>Native Name</label>
                    <input type="text" name="native_name" class="form-control" required placeholder="e.g., English">
                </div>
                <div class="form-group">
                    <label>Language Code</label>
                    <input type="text" name="language_code" class="form-control" required placeholder="e.g., en">
                </div>
                <div style="display: flex; gap: 10px; margin-top: 1.5rem;">
                    <button type="submit" name="add_language" class="btn btn-primary">Add Language</button>
                    <button type="button" class="btn btn-danger" onclick="closeModal('addLanguageModal')">Cancel</button>
                </div>
            </form>
        </div>
    </div>
    
    <script>
        // Navigation Functions
        function showSection(sectionId) {
            // Hide all sections
            document.querySelectorAll('.section').forEach(section => {
                section.classList.remove('active');
            });
            
            // Show selected section
            const targetSection = document.getElementById(sectionId);
            if (targetSection) {
                targetSection.classList.add('active');
                
                // Update page title
                const pageTitle = document.getElementById('pageTitle');
                if (pageTitle) {
                    const navLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
                    if (navLink) {
                        const spanText = navLink.querySelector('span').textContent;
                        pageTitle.textContent = spanText;
                    }
                }
                
                // Update active nav link
                document.querySelectorAll('.nav-link').forEach(link => {
                    link.classList.remove('active');
                });
                const activeLink = document.querySelector(`.nav-link[href="#${sectionId}"]`);
                if (activeLink) {
                    activeLink.classList.add('active');
                }
                
                // Update URL hash
                window.location.hash = sectionId;
                
                // Initialize chart if it's dashboard
                if (sectionId === 'dashboard') {
                    initializeCharts();
                }
            }
        }
        
        // Handle hash on page load
        document.addEventListener('DOMContentLoaded', function() {
            // Initialize navigation
            document.querySelectorAll('.nav-link').forEach(link => {
                link.addEventListener('click', function(e) {
                    e.preventDefault();
                    const targetId = this.getAttribute('href').substring(1);
                    showSection(targetId);
                });
            });
            
            // Show section based on hash
            if (window.location.hash) {
                const hash = window.location.hash.substring(1);
                showSection(hash);
            }
            
            // Initialize charts
            initializeCharts();
            
            // Auto-fill basic salary when employee is selected
            const employeeSelect = document.querySelector('select[name="employee_id"]');
            if (employeeSelect) {
                employeeSelect.addEventListener('change', function() {
                    const selectedOption = this.options[this.selectedIndex];
                    const salary = selectedOption.getAttribute('data-salary');
                    if (salary) {
                        document.getElementById('basicSalary').value = salary;
                        calculateNetSalary();
                    }
                });
            }
        });
        
        // Chart Functions
        function initializeCharts() {
            // Revenue Chart
            const revenueCtx = document.getElementById('revenueChart');
            if (revenueCtx) {
                const ctx = revenueCtx.getContext('2d');
                if (window.revenueChartInstance) {
                    window.revenueChartInstance.destroy();
                }
                window.revenueChartInstance = new Chart(ctx, {
                    type: 'line',
                    data: {
                        labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
                        datasets: [{
                            label: 'Revenue ($)',
                            data: [5000, 8000, 6000, 9000, 12000, 15000, 18000],
                            borderColor: '#283593',
                            backgroundColor: 'rgba(40, 53, 147, 0.1)',
                            borderWidth: 3,
                            fill: true,
                            tension: 0.4
                        }]
                    },
                    options: {
                        responsive: true,
                        maintainAspectRatio: false,
                        plugins: {
                            legend: {
                                display: true,
                                position: 'top'
                            }
                        }
                    }
                });
            }
        }
        
        // Modal Functions
        function openModal(modalId) {
            const modal = document.getElementById(modalId);
            if (modal) {
                modal.style.display = 'flex';
            }
        }
        
        function closeModal(modalId) {
            const modal = document.getElementById(modalId);
            if (modal) {
                modal.style.display = 'none';
            }
        }
        
        // Open reply modal for contact messages
        function openReplyModal(messageId, email) {
            document.getElementById('replyMessageId').value = messageId;
            document.getElementById('replyToEmail').value = email;
            openModal('replyMessageModal');
        }
        
        // Calculate net salary for payroll
        function calculateNetSalary(selectElement) {
            const basicSalary = parseFloat(document.getElementById('basicSalary').value) || 0;
            const overtime = parseFloat(document.getElementById('overtime').value) || 0;
            const bonuses = parseFloat(document.getElementById('bonuses').value) || 0;
            const deductions = parseFloat(document.getElementById('deductions').value) || 0;
            
            const netSalary = basicSalary + overtime + bonuses - deductions;
            document.getElementById('netSalary').value = '$' + netSalary.toFixed(2);
            
            // If an employee was selected and it has a salary, update basic salary
            if (selectElement) {
                const salary = selectElement.options[selectElement.selectedIndex].getAttribute('data-salary');
                if (salary) {
                    document.getElementById('basicSalary').value = salary;
                    // Recalculate with new basic salary
                    calculateNetSalary();
                }
            }
        }
        
        // Close modal when clicking outside
        document.addEventListener('click', function(e) {
            if (e.target.classList.contains('modal')) {
                e.target.style.display = 'none';
            }
        });
        
        // Close with Escape key
        document.addEventListener('keydown', function(e) {
            if (e.key === 'Escape') {
                document.querySelectorAll('.modal').forEach(modal => {
                    modal.style.display = 'none';
                });
            }
        });
        
        // Search functionality
        function searchTable(inputId, tableId) {
            const input = document.getElementById(inputId);
            const filter = input.value.toLowerCase();
            const table = document.getElementById(tableId);
            const rows = table.getElementsByTagName('tr');
            
            for (let i = 0; i < rows.length; i++) {
                const cells = rows[i].getElementsByTagName('td');
                let found = false;
                
                for (let j = 0; j < cells.length; j++) {
                    if (cells[j]) {
                        const text = cells[j].textContent || cells[j].innerText;
                        if (text.toLowerCase().indexOf(filter) > -1) {
                            found = true;
                            break;
                        }
                    }
                }
                
                rows[i].style.display = found ? '' : 'none';
            }
        }
        
        // AI Chat Functions
        function scrollChat() {
            setTimeout(() => {
                const chatMessages = document.getElementById('chatMessages');
                if (chatMessages) {
                    chatMessages.scrollTop = chatMessages.scrollHeight;
                }
            }, 100);
        }
        
        // Export Functions
        function exportData(type) {
            alert('Export ' + type + ' data - This would generate a CSV/PDF file in a real implementation.');
        }
        
        // Print Functions
        function printSection(sectionId) {
            const section = document.getElementById(sectionId);
            if (section) {
                const printWindow = window.open('', '_blank');
                printWindow.document.write(`
                    <html>
                        <head>
                            <title>Print - ETF Career</title>
                            <style>
                                body { font-family: Arial, sans-serif; padding: 20px; }
                                table { width: 100%; border-collapse: collapse; }
                                th, td { padding: 8px; border: 1px solid #ddd; }
                                th { background: #f5f5f5; }
                                .badge { padding: 2px 6px; border-radius: 3px; font-size: 0.8em; }
                                .badge-success { background: #d4edda; }
                                .badge-warning { background: #fff3cd; }
                                .badge-danger { background: #f8d7da; }
                            </style>
                        </head>
                        <body>
                            <h2>ETF Career - ${document.getElementById('pageTitle').textContent}</h2>
                            ${section.innerHTML}
                            <script>
                                window.onload = function() { window.print(); }
                            </script>
                        </body>
                    </html>
                `);
                printWindow.document.close();
            }
        }
        
        // CRUD Functions (Placeholders for edit/delete)
        function editProduct(id) {
            alert('Edit product ' + id + ' - In a full implementation, this would open an edit modal with pre-filled data.');
        }
        
        function deleteProduct(id) {
            if (confirm('Are you sure you want to delete this product?')) {
                alert('Delete product ' + id + ' - In a full implementation, this would send an AJAX request to delete.');
            }
        }
    </script>
</body>
</html>
Back to Directory=ceiIENDB`