diff --git a/api/chat.php b/api/chat.php
index d193a7a..ae64843 100644
--- a/api/chat.php
+++ b/api/chat.php
@@ -44,6 +44,30 @@ if ($method === 'GET') {
try {
$stmt = db()->prepare("INSERT INTO messages (username, ip_address, message, type) VALUES (?, ?, ?, ?)");
$stmt->execute([$username, $ip, $message, $type]);
+
+ // Award points to the fan based on chat activity
+ $fanStmt = db()->prepare("SELECT id, points FROM fans WHERE name = ?");
+ $fanStmt->execute([$username]);
+ $fan = $fanStmt->fetch();
+
+ if ($fan) {
+ $newPoints = $fan['points'] + 10;
+ db()->prepare("UPDATE fans SET points = ? WHERE id = ?")->execute([$newPoints, $fan['id']]);
+ } else {
+ // Check if photo exists for this user in user_likes or elsewhere (optional enhancement)
+ db()->prepare("INSERT INTO fans (name, points) VALUES (?, ?)")->execute([$username, 10]);
+ $newPoints = 10;
+ }
+
+ // Auto-update Fan of the Month if this user has the highest points
+ $maxPointsStmt = db()->query("SELECT MAX(points) as max_p FROM fans");
+ $maxPoints = $maxPointsStmt->fetch()['max_p'];
+
+ if ($newPoints >= $maxPoints) {
+ db()->query("UPDATE fans SET is_fan_of_month = 0");
+ db()->prepare("UPDATE fans SET is_fan_of_month = 1 WHERE name = ?")->execute([$username]);
+ }
+
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
diff --git a/index.php b/index.php
index 05f83a7..b20b32f 100644
--- a/index.php
+++ b/index.php
@@ -1053,7 +1053,10 @@ $facebook_link = "https://www.facebook.com/profile.php?id=61587890927489";
Los oyentes más activos del chat
+
+