load(); $db = getDbConnection(); // Handle adding transmission to block if (isset($_POST['add_to_block'])) { $commercialId = $_POST['infomercial_id']; $channel = $_POST['channel']; $date = $_POST['date']; $blockId = $_POST['block_id'] ?? null; // Get infomercial duration $stmt = $db->prepare("SELECT duration FROM infomercials WHERE id = ?"); $stmt->execute([$commercialId]); $duration = $stmt->fetchColumn(); // Calculate next start time for this specific block $nextStartTime = calculateNextStartTimeForBlock($db, $date, $channel, $blockId); // Insert transmission $stmt = $db->prepare(" INSERT INTO transmissions (infomercial_id, channel, template, start_date, start_time, duration, api_status) VALUES (?, ?, 'HOME030', ?, ?, ?, 'pending') "); $stmt->execute([$commercialId, $channel, $date, $nextStartTime, $duration]); header("Location: planner.php?date=$date&success=added"); exit; } // Handle remove transmission if (isset($_POST['remove_transmission'])) { $stmt = $db->prepare("DELETE FROM transmissions WHERE id = ?"); $stmt->execute([$_POST['transmission_id']]); header("Location: planner.php?date={$_POST['date']}&success=removed"); exit; } // Handle reorder (move up/down) if (isset($_POST['reorder'])) { $transmissionId = $_POST['transmission_id']; $direction = $_POST['direction']; // 'up' or 'down' $date = $_POST['date']; $channel = $_POST['channel']; $blockId = $_POST['block_id']; // Get block info including end time $stmt = $db->prepare("SELECT actual_start_time, actual_end_time FROM daily_blocks WHERE id = ?"); $stmt->execute([$blockId]); $blockInfo = $stmt->fetch(); $blockStartTime = $blockInfo['actual_start_time']; $blockEndTime = $blockInfo['actual_end_time'] ?? '23:59:59'; // Get all transmissions for THIS SPECIFIC block only $stmt = $db->prepare(" SELECT t.id, t.start_time, c.duration FROM transmissions t JOIN infomercials c ON t.infomercial_id = c.id WHERE t.start_date = ? AND t.channel = ? AND t.start_time >= ? AND t.start_time < ? ORDER BY t.start_time ASC "); $stmt->execute([$date, $channel, $blockStartTime, $blockEndTime]); $transmissions = $stmt->fetchAll(); // Find current position $currentIndex = array_search($transmissionId, array_column($transmissions, 'id')); if ($currentIndex !== false) { if ($direction === 'up' && $currentIndex > 0) { // Swap with previous $temp = $transmissions[$currentIndex]; $transmissions[$currentIndex] = $transmissions[$currentIndex - 1]; $transmissions[$currentIndex - 1] = $temp; } elseif ($direction === 'down' && $currentIndex < count($transmissions) - 1) { // Swap with next $temp = $transmissions[$currentIndex]; $transmissions[$currentIndex] = $transmissions[$currentIndex + 1]; $transmissions[$currentIndex + 1] = $temp; } // Recalculate all start times $currentTime = $blockStartTime; foreach ($transmissions as $tx) { $stmt = $db->prepare("UPDATE transmissions SET start_time = ?, api_status = 'pending' WHERE id = ?"); $stmt->execute([$currentTime, $tx['id']]); $currentTime = addTimeToTime($currentTime, $tx['duration']); } } header("Location: planner.php?date=$date"); exit; } // Handle block time update if (isset($_POST['update_block_time'])) { $blockId = $_POST['block_id']; $newStartTime = $_POST['new_start_time']; $recalculate = isset($_POST['recalculate']); // Update block time $stmt = $db->prepare("UPDATE daily_blocks SET actual_start_time = ? WHERE id = ?"); $stmt->execute([$newStartTime, $blockId]); // Optionally recalculate transmissions if ($recalculate) { $stmt = $db->prepare("SELECT block_date, channel FROM daily_blocks WHERE id = ?"); $stmt->execute([$blockId]); $blockInfo = $stmt->fetch(); $stmt = $db->prepare(" SELECT t.id, c.duration FROM transmissions t JOIN infomercials c ON t.infomercial_id = c.id WHERE t.start_date = ? AND t.channel = ? AND t.start_time >= ? ORDER BY t.start_time ASC "); $stmt->execute([$blockInfo['block_date'], $blockInfo['channel'], $newStartTime]); $transmissions = $stmt->fetchAll(); $currentTime = $newStartTime; foreach ($transmissions as $tx) { $stmt = $db->prepare("UPDATE transmissions SET start_time = ?, api_status = 'pending' WHERE id = ?"); $stmt->execute([$currentTime, $tx['id']]); $currentTime = addTimeToTime($currentTime, $tx['duration']); } } header("Location: planner.php?date={$blockInfo['block_date']}&success=block_updated"); exit; } // Get selected date $selectedDate = $_GET['date'] ?? date('Y-m-d'); // Ensure daily blocks exist ensureDailyBlocks($db, $selectedDate, $selectedDate); // Get all blocks for this date (both channels, all blocks) $stmt = $db->prepare(" SELECT db.*, bt.name as template_name, bt.channel FROM daily_blocks db LEFT JOIN block_templates bt ON db.template_id = bt.id WHERE db.block_date = ? ORDER BY db.channel, db.actual_start_time "); $stmt->execute([$selectedDate]); $allBlocks = $stmt->fetchAll(); // Group blocks by channel $blocksByChannel = []; foreach ($allBlocks as $block) { $blocksByChannel[$block['channel']][] = $block; } // Get all infomercials (including pending status - they can be used in planner) $infomercials = $db->query(" SELECT * FROM infomercials ORDER BY title ASC ")->fetchAll(); // Helper function to calculate next start time for a specific block function calculateNextStartTimeForBlock($db, $date, $channel, $blockId) { if ($blockId) { $stmt = $db->prepare("SELECT actual_start_time, actual_end_time FROM daily_blocks WHERE id = ?"); $stmt->execute([$blockId]); $blockInfo = $stmt->fetch(); $blockStartTime = $blockInfo['actual_start_time']; $blockEndTime = $blockInfo['actual_end_time'] ?? '23:59:59'; } else { $blockStartTime = '07:00:00'; // Default $blockEndTime = '23:59:59'; } // Get all transmissions in THIS SPECIFIC block only $stmt = $db->prepare(" SELECT start_time, duration FROM transmissions WHERE start_date = ? AND channel = ? AND start_time >= ? AND start_time < ? ORDER BY start_time DESC LIMIT 1 "); $stmt->execute([$date, $channel, $blockStartTime, $blockEndTime]); $lastTx = $stmt->fetch(); if ($lastTx) { return addTimeToTime($lastTx['start_time'], $lastTx['duration']); } return $blockStartTime; } ?> Excel Planning - Telvero Talpa

Infomercials

Geen infomercials

min

Geen blokken voor deze dag

prepare(" SELECT t.*, c.title, c.color_code, c.series_code, t.api_status, t.talpa_transmission_id FROM transmissions t JOIN infomercials c ON t.infomercial_id = c.id WHERE t.start_date = ? AND t.channel = ? AND t.start_time >= ? AND t.start_time < ? ORDER BY t.start_time ASC "); $stmt->execute([$selectedDate, $channel, $blockStart, $blockEnd]); $blockTransmissions = $stmt->fetchAll(); // Calculate block stats $totalBlockMinutes = (timeToSeconds($blockEnd) - timeToSeconds($blockStart)) / 60; $usedMinutes = 0; foreach ($blockTransmissions as $tx) { $usedMinutes += timeToSeconds($tx['duration']) / 60; } $remainingMinutes = $totalBlockMinutes - $usedMinutes; // Calculate block sync status $totalTransmissions = count($blockTransmissions); $syncedTransmissions = 0; foreach ($blockTransmissions as $tx) { if ($tx['api_status'] === 'synced' && !empty($tx['talpa_transmission_id'])) { $syncedTransmissions++; } } // Determine block sync status $blockSyncClass = 'block-sync-empty'; $blockSyncLabel = 'Leeg'; $blockSyncIcon = 'bi-inbox'; if ($totalTransmissions > 0) { if ($syncedTransmissions == $totalTransmissions) { $blockSyncClass = 'block-sync-complete'; $blockSyncLabel = 'Gepland'; $blockSyncIcon = 'bi-check-circle-fill'; } elseif ($syncedTransmissions > 0) { $blockSyncClass = 'block-sync-partial'; $blockSyncLabel = "Deels ({$syncedTransmissions}/{$totalTransmissions})"; $blockSyncIcon = 'bi-exclamation-triangle-fill'; } else { $blockSyncClass = 'block-sync-none'; $blockSyncLabel = 'Niet Gepland'; $blockSyncIcon = 'bi-x-circle-fill'; } } ?>
- | min
$tx): $durationMinutes = round(timeToSeconds($tx['duration']) / 60); $endTime = addTimeToTime($tx['start_time'], $tx['duration']); // Calculate remaining time in block after this transmission $remainingSeconds = timeToSeconds($blockEnd) - timeToSeconds($endTime); $txRemainingMinutes = round($remainingSeconds / 60); ?>
Product Duur Start Eind Restant Talpa Acties
Nog geen uitzendingen in dit blok
min min
0): ?>