prepare("SELECT id FROM users WHERE email = :email"); $stmt->execute([':email' => $email]); if ($stmt->fetch()) { $error = 'User with this email already exists!'; } else { $limit = ($tier === 'paid') ? 5000 : 500; $hashedPassword = password_hash($password, PASSWORD_DEFAULT); $stmt = $pdo->prepare(" INSERT INTO users (email, password, tier, monthly_question_limit, is_admin, created_at) VALUES (:email, :password, :tier, :limit, 0, NOW()) "); $stmt->execute([ ':email' => $email, ':password' => $hashedPassword, ':tier' => $tier, ':limit' => $limit ]); $message = 'User created successfully!'; $tab = 'admin'; // Stay on admin tab } } else { $error = 'Email and password are required!'; } } // EDIT USER (Admin only) if ($_POST['action'] === 'edit_user' && is_admin()) { $userId = (int)$_POST['user_id']; $email = trim($_POST['email']); $newPassword = trim($_POST['new_password']); $tier = $_POST['tier']; $limit = (int)$_POST['limit']; if ($email) { if ($newPassword) { $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT); $stmt = $pdo->prepare(" UPDATE users SET email = :email, password = :password, tier = :tier, monthly_question_limit = :limit WHERE id = :id "); $stmt->execute([ ':email' => $email, ':password' => $hashedPassword, ':tier' => $tier, ':limit' => $limit, ':id' => $userId ]); } else { $stmt = $pdo->prepare(" UPDATE users SET email = :email, tier = :tier, monthly_question_limit = :limit WHERE id = :id "); $stmt->execute([ ':email' => $email, ':tier' => $tier, ':limit' => $limit, ':id' => $userId ]); } $stmt = $pdo->prepare("UPDATE bots SET plan_type = :tier WHERE user_id = :id"); $stmt->execute([':tier' => $tier, ':id' => $userId]); $message = 'User updated successfully!'; $tab = 'admin'; } } // DELETE USER (Admin only) if ($_POST['action'] === 'delete_user' && is_admin()) { $userId = (int)$_POST['user_id']; if ($userId == $currentUser['id']) { $error = 'You cannot delete your own account!'; } else { $stmt = $pdo->prepare("SELECT id FROM bots WHERE user_id = :user_id"); $stmt->execute([':user_id' => $userId]); $bots = $stmt->fetchAll(PDO::FETCH_COLUMN); foreach ($bots as $botId) { $pdo->prepare("DELETE FROM question_usage WHERE bot_id = :id")->execute([':id' => $botId]); } $pdo->prepare("DELETE FROM bots WHERE user_id = :id")->execute([':id' => $userId]); $pdo->prepare("DELETE FROM users WHERE id = :id")->execute([':id' => $userId]); $message = 'User deleted successfully!'; $tab = 'admin'; } } // DELETE BOT if ($_POST['action'] === 'delete_bot') { $botId = (int)$_POST['bot_id']; // Check ownership (or admin) $stmt = $pdo->prepare("SELECT user_id FROM bots WHERE id = :id"); $stmt->execute([':id' => $botId]); $bot = $stmt->fetch(PDO::FETCH_ASSOC); if ($bot && ($bot['user_id'] == $currentUser['id'] || is_admin())) { $pdo->prepare("DELETE FROM question_usage WHERE bot_id = :id")->execute([':id' => $botId]); $pdo->prepare("DELETE FROM bots WHERE id = :id")->execute([':id' => $botId]); $message = 'Bot deleted successfully!'; } else { $error = 'You do not have permission to delete this bot.'; } } } // Get users bots $myBots = []; if (isset($currentUser) && isset($currentUser['id'])) { $stmt = $pdo->prepare("SELECT * FROM bots WHERE user_id = :user_id ORDER BY created_at DESC"); $stmt->execute([':user_id' => $currentUser['id']]); $myBots = $stmt->fetchAll(PDO::FETCH_ASSOC); } // Get usage stats for current user $userStats = getUsageStatistics($pdo, $currentUser['id']); // Admin data (only load if admin) $allUsers = []; $platformStats = []; if (is_admin()) { $allUsers = getAllUsersWithUsage($pdo); $platformStats = getUsageStatistics($pdo); } $monthYear = getCurrentMonth(); ?> Dashboard – 121 AI ChatBot

You haven't created any bots yet. Click "Create New Bot" to get started!

prepare("SELECT question_count FROM question_usage WHERE bot_id = :bot_id AND month_year = :month_year LIMIT 1"); $stmt->execute([':bot_id' => $bot['id'], ':month_year' => $monthYear]); $usage = $stmt->fetch(PDO::FETCH_ASSOC); $questionCount = $usage ? (int)$usage['question_count'] : 0; ?>

Bot ID:
Website:
Questions this month:
Settings

Usage Statistics

Your Tier
Total Bots
Monthly Limit

Questions This Month

No bots created yet.

prepare("SELECT question_count FROM question_usage WHERE bot_id = :bot_id AND month_year = :month_year LIMIT 1"); $stmt->execute([':bot_id' => $bot['id'], ':month_year' => $monthYear]); $usage = $stmt->fetch(PDO::FETCH_ASSOC); $questionCount = $usage ? (int)$usage['question_count'] : 0; $totalUsed += $questionCount; ?>
Bot Name Questions Used Usage
0 ? ($questionCount / $limit) * 100 : 0; $barClass = ''; if ($percentage >= 90) $barClass = 'danger'; elseif ($percentage >= 75) $barClass = 'warning'; ?>
TOTAL / 0 ? ($totalUsed / $limit) * 100 : 0; $barClass = ''; if ($percentage >= 90) $barClass = 'danger'; elseif ($percentage >= 75) $barClass = 'warning'; ?>

Platform Statistics

Total Users
Total Bots
Questions This Month
Paid Users
/ free

User Management

0 ? ($used / $limit) * 100 : 0; $barClass = ''; if ($percentage >= 90) $barClass = 'danger'; elseif ($percentage >= 75) $barClass = 'warning'; ?>
User Tier Bots Questions Used Joined Actions
ID:
bot
/