74 lines
2.7 KiB
PHP
74 lines
2.7 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
if (!$data) {
|
|
$data = $_POST;
|
|
}
|
|
|
|
$username = $data['username'] ?? '';
|
|
$action = $data['action'] ?? '';
|
|
$requestId = $data['request_id'] ?? null;
|
|
|
|
if (empty($username) || empty($action)) {
|
|
echo json_encode(['success' => false, 'error' => 'Datos incompletos']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$db = db();
|
|
|
|
// Verify Guest DJ status
|
|
$stmt = $db->prepare("SELECT dj_day_until FROM fans WHERE name = ?");
|
|
$stmt->execute([$username]);
|
|
$dj_day_until = $stmt->fetchColumn();
|
|
|
|
$isGuestDj = $dj_day_until && (strtotime($dj_day_until) > time());
|
|
|
|
if (!$isGuestDj) {
|
|
echo json_encode(['success' => false, 'error' => 'No tienes permisos de DJ Invitado activos']);
|
|
exit;
|
|
}
|
|
|
|
if ($action === 'skip') {
|
|
// Log skip action
|
|
$stmt = $db->prepare("INSERT INTO radio_actions (action_type, performed_by, details) VALUES ('skip', ?, ?)");
|
|
$stmt->execute([$username, "El DJ Invitado ha solicitado saltar la canci贸n"]);
|
|
|
|
// Announce in chat
|
|
$chatMsg = "馃毃 [DJ INVITADO] **$username** ha usado su poder para SALTAR la canci贸n actual. 鈴笍";
|
|
$stmt = $db->prepare("INSERT INTO messages (username, message, type) VALUES ('Sistema', ?, 'text')");
|
|
$stmt->execute([$chatMsg]);
|
|
|
|
echo json_encode(['success' => true, 'message' => 'Acci贸n de saltar ejecutada y anunciada']);
|
|
|
|
} elseif ($action === 'prioritize') {
|
|
if (!$requestId) {
|
|
echo json_encode(['success' => false, 'error' => 'ID de petici贸n faltante']);
|
|
exit;
|
|
}
|
|
|
|
$stmt = $db->prepare("UPDATE song_requests SET is_priority = 1 WHERE id = ?");
|
|
$stmt->execute([$requestId]);
|
|
|
|
// Get request details for announcement
|
|
$stmt = $db->prepare("SELECT artist, song FROM song_requests WHERE id = ?");
|
|
$stmt->execute([$requestId]);
|
|
$req = $stmt->fetch();
|
|
|
|
if ($req) {
|
|
$chatMsg = "馃敟 [DJ INVITADO] **$username** ha PRIORIZADO la canci贸n: **{$req['artist']} - {$req['song']}**. 隆Sonar谩 muy pronto! 馃幍";
|
|
$stmt = $db->prepare("INSERT INTO messages (username, message, type) VALUES ('Sistema', ?, 'text')");
|
|
$stmt->execute([$chatMsg]);
|
|
}
|
|
|
|
echo json_encode(['success' => true, 'message' => 'Petici贸n priorizada con 茅xito']);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Acci贸n no v谩lida']);
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
|
}
|