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"; Fan of the Month
- Fan del Mes +
+ Fan del Mes + VER RANKING +
puntos de actividad
diff --git a/ranking.php b/ranking.php new file mode 100644 index 0000000..e360ba9 --- /dev/null +++ b/ranking.php @@ -0,0 +1,199 @@ +query("SELECT * FROM fans ORDER BY points DESC LIMIT 10")->fetchAll(PDO::FETCH_ASSOC); +} catch (Exception $e) { + $fans = []; +} +?> + + + + + + Ranking de Fans - Lili Records + + + + + + + +
+ +
+
+ +

Top Fans

+

Los oyentes más activos del chat

+
+ +
+ +
+ + Aún no hay fans destacados. ¡Empieza a chatear para aparecer aquí! +
+ + $fan): ?> + +
+
+ + + + + +
+ <?= htmlspecialchars($fan['name']) ?> +
+
+
puntos
+
+ +
+ +
+ +
+ + +
+ +
+ Gana 10 puntos por cada mensaje enviado en el chat. +
+
+ +