prepare( "SELECT s.*, m.content, dr.type as recipient_type FROM schedules s JOIN messages m ON s.message_id = m.id JOIN discord_recipients dr ON s.recipient_id = dr.id WHERE s.id = ?" ); $stmt->execute([$scheduleId]); $message = $stmt->fetch(); if (!$message) { header('Location: scheduled_messages.php?error=not_found'); exit(); } // Fetch all recipients for the dropdowns $channels = []; $users = []; try { $recipientStmt = $pdo->query("SELECT id, name, type FROM discord_recipients ORDER BY name ASC"); while ($row = $recipientStmt->fetch()) { if ($row['type'] === 'channel') { $channels[] = $row; } else { $users[] = $row; } } } catch (PDOException $e) { die("Error: No se pudieron cargar los destinatarios."); } require_once __DIR__ . '/templates/header.php'; ?>