prepare("SELECT cover_image FROM teledramas WHERE id = :id"); $stmt->execute([':id' => $delete_id]); $row = $stmt->fetch(PDO::FETCH_ASSOC); if ($row && $row['cover_image']) { $file = $_SERVER['DOCUMENT_ROOT'] . '/uploads/teledramas/' . $row['cover_image']; if (file_exists($file)) { unlink($file); } } $stmt = $conn->prepare("DELETE FROM teledramas WHERE id = :id"); $stmt->execute([':id' => $delete_id]); $teledrama_message = "Teledrama deleted successfully!"; } catch (Exception $e) { $teledrama_message = "Error deleting teledrama: " . htmlspecialchars($e->getMessage()); } } } // -------------------------- // Handle Sort Order Update // --------------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['sort_order_update'])) { foreach ($_POST['sort_order'] as $id => $order) { $order = (int)$order; $id = (int)$id; try { $stmt = $conn->prepare("UPDATE teledramas SET sort_order = :sort_order WHERE id = :id"); $stmt->execute([ ':sort_order' => $order, ':id' => $id ]); } catch (Exception $e) { error_log("Error updating sort order for ID $id: " . $e->getMessage()); } } $teledrama_message = "Sort order updated successfully!"; } // --------------------------- // Fetch all Teledramas // --------------------------- $teledramas = []; try { $stmt = $conn->query("SELECT * FROM teledramas ORDER BY sort_order ASC, id DESC"); $teledramas = $stmt->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { error_log("Error fetching teledramas: " . $e->getMessage()); } // ------------------ BANNER UPLOAD HANDLER ------------------ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['banner_image'])) { $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/banners/'; $link_url = trim($_POST['link_url'] ?? ''); // ✅ New: banner link URL $banner_message = ''; // Ensure directory exists if (!file_exists($target_dir)) { if (!mkdir($target_dir, 0755, true)) { $banner_message = "Error: Failed to create banner upload directory."; error_log("Banner upload failed: Could not create directory $target_dir", 3, "/home/monara/public_html/swarnawahini_web_stable/logs/php_errors.log"); } } // Check if directory writable if (!is_writable($target_dir)) { $banner_message = "Error: Banner upload directory is not writable."; error_log("Banner upload failed: Directory $target_dir is not writable.", 3, "/home/monara/public_html/swarnawahini_web_stable/logs/php_errors.log"); } else { $banner_image = basename($_FILES['banner_image']['name']); $target_file = $target_dir . $banner_image; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Validate file if ($_FILES['banner_image']['size'] > 2000000) { $banner_message = "Error: File is too large. Maximum size is 2MB."; } elseif ($_FILES['banner_image']['error'] !== UPLOAD_ERR_OK) { $banner_message = "Error uploading file."; } else { $valid_extensions = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp']; if (!in_array($imageFileType, $valid_extensions)) { $banner_message = "Invalid file type. Only JPG, PNG, GIF, SVG, and WEBP are allowed."; } else { $check = ($imageFileType === 'svg') ? simplexml_load_string(file_get_contents($_FILES['banner_image']['tmp_name'])) !== false : getimagesize($_FILES['banner_image']['tmp_name']); if (!$check) { $banner_message = "Invalid image file."; } elseif (file_exists($target_file)) { $banner_message = "Error: File already exists."; } else { if (move_uploaded_file($_FILES['banner_image']['tmp_name'], $target_file)) { try { $stmt = $conn->prepare("INSERT INTO banners (image_path, link_url) VALUES (:image_path, :link_url)"); $stmt->execute([ ':image_path' => $banner_image, ':link_url' => $link_url ]); $banner_message = "Banner uploaded successfully!"; } catch (Exception $e) { $banner_message = "Database error: " . htmlspecialchars($e->getMessage()); if (file_exists($target_file)) unlink($target_file); } } else { $banner_message = "Error moving uploaded file."; } } } } } } // Handle Banner Deletion if (isset($_GET['delete_banner']) && is_numeric($_GET['delete_banner'])) { $id = (int)$_GET['delete_banner']; try { $stmt = $conn->prepare("SELECT image_path FROM banners WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for banner deletion query: " . json_encode($conn->errorInfo())); } $stmt->execute([':id' => $id]); $banner = $stmt->fetch(PDO::FETCH_ASSOC); if ($banner) { $file_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/banners/' . $banner['image_path']; if (file_exists($file_path)) { if (!unlink($file_path)) { error_log("Failed to delete banner file: $file_path", 3, "/home/monara/public_html/logs/php_errors.log"); } } $stmt = $conn->prepare("DELETE FROM banners WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for banner deletion: " . json_encode($conn->errorInfo())); } $stmt->execute([':id' => $id]); $banner_message = "Banner deleted successfully!"; } else { $banner_message = "Banner not found."; } } catch (Exception $e) { $banner_message = "Error deleting banner: " . htmlspecialchars($e->getMessage()); error_log("Banner deletion error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } // Handle Special Program Submission (Add/Edit) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['special_program_title'])) { $special_program_id = filter_input(INPUT_POST, 'special_program_id', FILTER_SANITIZE_NUMBER_INT); $title = filter_input(INPUT_POST, 'special_program_title', FILTER_SANITIZE_STRING); $youtube_url = filter_input(INPUT_POST, 'youtube_url', FILTER_SANITIZE_URL); $video_id = ''; if (preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/', $youtube_url, $match)) { $video_id = $match[1]; } if (!$video_id) { $special_program_message = "Invalid YouTube URL. Please use a URL like https://www.youtube.com/watch?v=VIDEO_ID"; } else { $thumbnail_url = "https://i.ytimg.com/vi/{$video_id}/hqdefault.jpg"; $headers = @get_headers($thumbnail_url); if ($headers && strpos($headers[0], '200') === false) { error_log("Thumbnail URL inaccessible: $thumbnail_url, Headers: " . implode(", ", $headers), 3, "/home/monara/public_html/logs/php_errors.log"); $thumbnail_url = 'default.jpg'; $special_program_message = "Thumbnail URL inaccessible. Using default image."; } try { if ($special_program_id) { $stmt = $conn->prepare("UPDATE special_programs SET title = :title, youtube_url = :youtube_url, thumbnail_url = :thumbnail_url WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for special program update: " . json_encode($conn->errorInfo())); } $stmt->execute([ ':title' => $title, ':youtube_url' => $youtube_url, ':thumbnail_url' => $thumbnail_url, ':id' => $special_program_id ]); $special_program_message = "Special program updated successfully!"; } else { $stmt = $conn->prepare("INSERT INTO special_programs (title, youtube_url, thumbnail_url) VALUES (:title, :youtube_url, :thumbnail_url)"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for special program insertion: " . json_encode($conn->errorInfo())); } $stmt->execute([ ':title' => $title, ':youtube_url' => $youtube_url, ':thumbnail_url' => $thumbnail_url ]); $special_program_message = "Special program added successfully!"; } } catch (Exception $e) { $special_program_message = "Error processing special program: " . htmlspecialchars($e->getMessage()); error_log("Special program database error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } } // Handle Special Program Deletion if (isset($_GET['delete_special_program']) && is_numeric($_GET['delete_special_program'])) { $id = (int)$_GET['delete_special_program']; try { $stmt = $conn->prepare("DELETE FROM special_programs WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for special program deletion: " . json_encode($conn->errorInfo())); } $stmt->execute([':id' => $id]); $special_program_message = "Special program deleted successfully!"; } catch (Exception $e) { $special_program_message = "Error deleting special program: " . htmlspecialchars($e->getMessage()); error_log("Special program deletion error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } // Handle Featured Program Submission (Add/Edit) if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['featured_program_title'])) { $featured_program_id = filter_input(INPUT_POST, 'featured_program_id', FILTER_SANITIZE_NUMBER_INT); $title = filter_input(INPUT_POST, 'featured_program_title', FILTER_SANITIZE_STRING); $youtube_url = filter_input(INPUT_POST, 'youtube_url', FILTER_SANITIZE_URL); $video_id = ''; if (preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/', $youtube_url, $match)) { $video_id = $match[1]; } if (!$video_id) { $featured_program_message = "Invalid YouTube URL. Please use a URL like https://www.youtube.com/watch?v=VIDEO_ID"; } else { $thumbnail_url = "https://i.ytimg.com/vi/{$video_id}/hqdefault.jpg"; $headers = @get_headers($thumbnail_url); if ($headers && strpos($headers[0], '200') === false) { error_log("Thumbnail URL inaccessible: $thumbnail_url, Headers: " . implode(", ", $headers), 3, "/home/monara/public_html/logs/php_errors.log"); $thumbnail_url = 'default.jpg'; $featured_program_message = "Thumbnail URL inaccessible. Using default image."; } try { if ($featured_program_id) { $stmt = $conn->prepare("UPDATE featured_programs SET title = :title, youtube_url = :youtube_url, thumbnail_url = :thumbnail_url WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for featured program update: " . json_encode($conn->errorInfo())); } $stmt->execute([ ':title' => $title, ':youtube_url' => $youtube_url, ':thumbnail_url' => $thumbnail_url, ':id' => $featured_program_id ]); $featured_program_message = "Featured program updated successfully!"; } else { $stmt = $conn->prepare("INSERT INTO featured_programs (title, youtube_url, thumbnail_url) VALUES (:title, :youtube_url, :thumbnail_url)"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for featured program insertion: " . json_encode($conn->errorInfo())); } $stmt->execute([ ':title' => $title, ':youtube_url' => $youtube_url, ':thumbnail_url' => $thumbnail_url ]); $featured_program_message = "Featured program added successfully!"; } } catch (Exception $e) { $featured_program_message = "Error processing featured program: " . htmlspecialchars($e->getMessage()); error_log("Featured program database error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } } // Handle Featured Program Deletion if (isset($_GET['delete_featured_program']) && is_numeric($_GET['delete_featured_program'])) { $id = (int)$_GET['delete_featured_program']; try { $stmt = $conn->prepare("DELETE FROM featured_programs WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for featured program deletion: " . json_encode($conn->errorInfo())); } $stmt->execute([':id' => $id]); $featured_program_message = "Featured program deleted successfully!"; } catch (Exception $e) { $featured_program_message = "Error deleting featured program: " . htmlspecialchars($e->getMessage()); error_log("Featured program deletion error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } // --------------------------- // Handle Add/Update Teledrama // --------------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['title']) && !isset($_POST['sort_order_update'])) { $teledrama_id = filter_input(INPUT_POST, 'teledrama_id', FILTER_SANITIZE_NUMBER_INT); $title = filter_input(INPUT_POST, 'title', FILTER_SANITIZE_STRING); $description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING); $youtube_playlist = filter_input(INPUT_POST, 'youtube_playlist', FILTER_SANITIZE_STRING); $cover_image = ''; $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/teledramas/'; $teledrama_message = ''; // Ensure upload directory exists if (!file_exists($target_dir)) mkdir($target_dir, 0777, true); // Handle cover image upload if (isset($_FILES['cover_image']) && $_FILES['cover_image']['error'] === UPLOAD_ERR_OK) { $cover_image = basename($_FILES['cover_image']['name']); $target_file = $target_dir . $cover_image; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); $check = getimagesize($_FILES['cover_image']['tmp_name']); if ($check === false || !in_array($imageFileType, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) { $teledrama_message = "Invalid image file. Please upload JPG, PNG, GIF, or SVG."; } elseif (file_exists($target_file)) { $teledrama_message = "Error: File already exists."; } elseif (!move_uploaded_file($_FILES['cover_image']['tmp_name'], $target_file)) { $teledrama_message = "Error uploading cover image."; } } try { if (empty($teledrama_message)) { if ($teledrama_id) { // Update existing teledrama $stmt = $conn->prepare(" UPDATE teledramas SET title = :title, description = :description, youtube_playlist = :youtube_playlist, cover_image = :cover_image WHERE id = :id "); $stmt->execute([ ':title' => $title, ':description' => $description, ':youtube_playlist' => $youtube_playlist, ':cover_image' => $cover_image, ':id' => $teledrama_id ]); $new_teledrama_id = $teledrama_id; $teledrama_message = "Teledrama updated successfully!"; } else { // Insert new teledrama $stmt = $conn->prepare(" INSERT INTO teledramas (title, description, youtube_playlist, cover_image, sort_order, created_at, thumbnail_updated_at) VALUES (:title, :description, :youtube_playlist, :cover_image, 0, NOW(), NOW()) "); $stmt->execute([ ':title' => $title, ':description' => $description, ':youtube_playlist' => $youtube_playlist, ':cover_image' => $cover_image ]); $new_teledrama_id = $conn->lastInsertId(); $teledrama_message = "Teledrama added successfully!"; } // Fetch episodes and update thumbnail automatically if (!empty($youtube_playlist)) { try { $fetched = fetchPlaylistVideosAndUpdate( $youtube_playlist, $api_key, $conn, $new_teledrama_id, 'teledrama_videos', // video table 'teledramas', // main table 'teledrama' // type ); } catch (Exception $e) { error_log("Error fetching episodes for teledrama ID {$new_teledrama_id}: " . $e->getMessage()); } } } } catch (Exception $e) { $teledrama_message = "Error saving teledrama: " . htmlspecialchars($e->getMessage()); } } // --------------------------- // Handle Programme Submission // --------------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['programme_title']) && !isset($_POST['update_sort_order'])) { $programme_id = filter_input(INPUT_POST, 'programme_id', FILTER_SANITIZE_NUMBER_INT); $title = filter_input(INPUT_POST, 'programme_title', FILTER_SANITIZE_STRING); $description = filter_input(INPUT_POST, 'description', FILTER_SANITIZE_STRING); $youtube_playlist = filter_input(INPUT_POST, 'youtube_playlist', FILTER_SANITIZE_STRING); $cover_image = ''; $programme_message = ''; $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/programmes/'; if (!file_exists($target_dir)) mkdir($target_dir, 0777, true); // Handle cover image upload if (isset($_FILES['cover_image']) && $_FILES['cover_image']['error'] === UPLOAD_ERR_OK) { $cover_image = basename($_FILES['cover_image']['name']); $target_file = $target_dir . $cover_image; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); $check = getimagesize($_FILES['cover_image']['tmp_name']); if ($check === false || !in_array($imageFileType, ['jpg', 'jpeg', 'png', 'gif', 'svg'])) { $programme_message = "Invalid image file. Please upload JPG, PNG, GIF, or SVG."; } elseif (file_exists($target_file)) { $programme_message = "Error: File already exists."; } elseif (!move_uploaded_file($_FILES['cover_image']['tmp_name'], $target_file)) { $programme_message = "Error uploading cover image."; } } try { if (empty($programme_message)) { if ($programme_id) { // Update existing programme $stmt = $conn->prepare(" UPDATE programmes SET title = :title, description = :description, youtube_playlist = :youtube_playlist, cover_image = :cover_image WHERE id = :id "); $stmt->execute([ ':title' => $title, ':description' => $description, ':youtube_playlist' => $youtube_playlist, ':cover_image' => $cover_image, ':id' => $programme_id ]); $new_programme_id = $programme_id; $programme_message = "Programme updated successfully!"; } else { // Insert new programme $stmt = $conn->prepare(" INSERT INTO programmes (title, description, youtube_playlist, cover_image, sort_order, created_at, thumbnail_updated_at) VALUES (:title, :description, :youtube_playlist, :cover_image, 0, NOW(), NOW()) "); $stmt->execute([ ':title' => $title, ':description' => $description, ':youtube_playlist' => $youtube_playlist, ':cover_image' => $cover_image ]); $new_programme_id = $conn->lastInsertId(); $programme_message = "Programme added successfully!"; } // ----- Fetch episodes and update thumbnails immediately ----- if (!empty($youtube_playlist)) { try { fetchPlaylistVideosAndUpdate( $youtube_playlist, $api_key, $conn, $new_programme_id, 'programmes_videos', // table for programme videos 'programmes', // main table 'programme' // type for logic (for thumbnail update) ); } catch (Exception $e) { error_log("Error fetching episodes for programme ID {$new_programme_id}: " . $e->getMessage()); } } } } catch (Exception $e) { $programme_message = "Error saving programme: " . htmlspecialchars($e->getMessage()); } } // ----------------------------- // Handle Programme Deletion // ----------------------------- if (isset($_GET['delete_programme']) && is_numeric($_GET['delete_programme'])) { $id = (int)$_GET['delete_programme']; $stmt = $conn->prepare("DELETE FROM programmes WHERE id=:id"); $stmt->execute([':id' => $id]); $programme_message = "Programme deleted successfully!"; } // ----------------------------- // Handle Sort Order Update // ----------------------------- if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_sort_order'])) { foreach ($_POST['sort_order'] as $id => $order) { $stmt = $conn->prepare("UPDATE programmes SET sort_order=:sort_order WHERE id=:id"); $stmt->execute([ ':sort_order' => (int)$order, ':id' => (int)$id ]); } $programme_message = "Sort order updated successfully!"; } // Handle TV Schedule Submission if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['schedule_day'])) { $day = filter_input(INPUT_POST, 'schedule_day', FILTER_SANITIZE_STRING); $time = filter_input(INPUT_POST, 'schedule_time', FILTER_SANITIZE_STRING); $program_name = filter_input(INPUT_POST, 'program_name', FILTER_SANITIZE_STRING); $valid_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; if (!in_array($day, $valid_days) || !preg_match('/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/', $time) || empty($program_name)) { $schedule_message = "Invalid input. Ensure day, time (HH:MM), and program name are valid."; } else { try { $stmt = $conn->prepare("INSERT INTO tv_schedule (day, time, program_name) VALUES (:day, :time, :program_name)"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for schedule insertion: " . json_encode($conn->errorInfo())); } $stmt->execute([ ':day' => $day, ':time' => $time, ':program_name' => $program_name ]); $schedule_message = "Program added to schedule successfully!"; } catch (Exception $e) { $schedule_message = "Error adding schedule: " . htmlspecialchars($e->getMessage()); error_log("Schedule database error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } } // Handle TV Schedule Deletion if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_schedule_id'])) { $delete_id = filter_input(INPUT_POST, 'delete_schedule_id', FILTER_VALIDATE_INT); if ($delete_id !== false && $delete_id > 0) { try { $stmt = $conn->prepare("DELETE FROM tv_schedule WHERE id = :id"); if ($stmt === false) { throw new Exception("Failed to prepare SQL statement for schedule deletion: " . json_encode($conn->errorInfo())); } $stmt->execute([':id' => $delete_id]); $schedule_message = "Program deleted from schedule successfully!"; } catch (Exception $e) { $schedule_message = "Error deleting schedule: " . htmlspecialchars($e->getMessage()); error_log("Schedule deletion error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); } } else { $schedule_message = "Invalid schedule ID."; } } // ------------------ AD UPLOAD HANDLER ------------------ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['ad_image'])) { // Make sure path is correct for your local setup $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads/'; $link_url = trim($_POST['ad_link_url'] ?? ''); $start_date = !empty($_POST['ad_start_date']) ? $_POST['ad_start_date'] : NULL; $end_date = !empty($_POST['ad_end_date']) ? $_POST['ad_end_date'] : NULL; $ad_message = ''; if (!file_exists($target_dir)) { mkdir($target_dir, 0755, true); } if (!is_writable($target_dir)) { $ad_message = "Error: Ads upload directory is not writable."; } else { $ad_image = basename($_FILES['ad_image']['name']); $target_file = $target_dir . $ad_image; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Validate file (using 1000x300 as a reference, but not enforcing) $check = getimagesize($_FILES['ad_image']['tmp_name']); if (!$check) { $ad_message = "Invalid image file."; } elseif (file_exists($target_file)) { $ad_message = "Error: File already exists."; } elseif ($_FILES['ad_image']['size'] > 2000000) { // 2MB limit $ad_message = "Error: File is too large."; } else { if (move_uploaded_file($_FILES['ad_image']['tmp_name'], $target_file)) { try { // 1. UPDATE THIS LINE (Must have 4 placeholders) $stmt = $conn->prepare("INSERT INTO horizontal_ads (image_path, link_url, start_date, end_date) VALUES (:image_path, :link_url, :start_date, :end_date)"); // 2. UPDATE THIS BLOCK (Must match the 4 placeholders above) $stmt->execute([ ':image_path' => $ad_image, ':link_url' => $link_url, ':start_date' => $start_date, ':end_date' => $end_date ]); $ad_message = "Ad uploaded successfully!"; } catch (Exception $e) { $ad_message = "Database error: " . htmlspecialchars($e->getMessage()); if (file_exists($target_file)) unlink($target_file); } } else { $ad_message = "Error moving uploaded file."; } } } } // Handle Ad Deletion if (isset($_GET['delete_ad']) && is_numeric($_GET['delete_ad'])) { $id = (int)$_GET['delete_ad']; try { // First, get the image path to delete the file $stmt = $conn->prepare("SELECT image_path FROM horizontal_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $ad = $stmt->fetch(PDO::FETCH_ASSOC); if ($ad) { // Make sure path is correct for your local setup $file_path = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads/' . $ad['image_path']; if (file_exists($file_path)) { unlink($file_path); } // Now, delete from database $stmt = $conn->prepare("DELETE FROM horizontal_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $ad_message = "Ad deleted successfully!"; } else { $ad_message = "Ad not found."; } } catch (Exception $e) { $ad_message = "Error deleting ad: " . htmlspecialchars($e->getMessage()); } } // ======================================================= // START: LIVE PLAYER AD HANDLERS // ======================================================= // ------------------ LIVE TOP AD UPLOAD ------------------ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['live_top_ad_image'])) { $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads_live_top/'; $link_url = trim($_POST['live_top_ad_link_url'] ?? ''); if (!file_exists($target_dir)) mkdir($target_dir, 0755, true); if (!is_writable($target_dir)) { $live_top_ad_message = "Error: Top ad directory is not writable."; } else { $image_name = basename($_FILES['live_top_ad_image']['name']); $target_file = $target_dir . $image_name; if (move_uploaded_file($_FILES['live_top_ad_image']['tmp_name'], $target_file)) { try { $stmt = $conn->prepare("INSERT INTO live_top_ads (image_path, link_url) VALUES (:image_path, :link_url)"); $stmt->execute([':image_path' => $image_name, ':link_url' => $link_url]); $live_top_ad_message = "Live Top Ad uploaded successfully!"; } catch (Exception $e) { $live_top_ad_message = "Database error: " . $e->getMessage(); } } else { $live_top_ad_message = "Error moving uploaded file."; } } } // ------------------ LIVE TOP AD DELETE ------------------ if (isset($_GET['delete_live_top_ad']) && is_numeric($_GET['delete_live_top_ad'])) { $id = (int)$_GET['delete_live_top_ad']; try { $stmt = $conn->prepare("SELECT image_path FROM live_top_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $ad = $stmt->fetch(PDO::FETCH_ASSOC); if ($ad) { $file_path = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads_live_top/' . $ad['image_path']; if (file_exists($file_path)) unlink($file_path); $stmt = $conn->prepare("DELETE FROM live_top_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $live_top_ad_message = "Live Top Ad deleted successfully!"; } } catch (Exception $e) { $live_top_ad_message = "Error deleting ad: " . $e->getMessage(); } } // ------------------ LIVE SIDE AD UPLOAD ------------------ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['live_side_ad_image'])) { $target_dir = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads_live_side/'; $link_url = trim($_POST['live_side_ad_link_url'] ?? ''); if (!file_exists($target_dir)) mkdir($target_dir, 0755, true); if (!is_writable($target_dir)) { $live_side_ad_message = "Error: Side ad directory is not writable."; } else { $image_name = basename($_FILES['live_side_ad_image']['name']); $target_file = $target_dir . $image_name; if (move_uploaded_file($_FILES['live_side_ad_image']['tmp_name'], $target_file)) { try { $stmt = $conn->prepare("INSERT INTO live_side_ads (image_path, link_url) VALUES (:image_path, :link_url)"); $stmt->execute([':image_path' => $image_name, ':link_url' => $link_url]); $live_side_ad_message = "Live Side Ad uploaded successfully!"; } catch (Exception $e) { $live_side_ad_message = "Database error: " . $e->getMessage(); } } else { $live_side_ad_message = "Error moving uploaded file."; } } } // ------------------ LIVE SIDE AD DELETE ------------------ if (isset($_GET['delete_live_side_ad']) && is_numeric($_GET['delete_live_side_ad'])) { $id = (int)$_GET['delete_live_side_ad']; try { $stmt = $conn->prepare("SELECT image_path FROM live_side_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $ad = $stmt->fetch(PDO::FETCH_ASSOC); if ($ad) { $file_path = $_SERVER['DOCUMENT_ROOT'] . '/Uploads/ads_live_side/' . $ad['image_path']; if (file_exists($file_path)) unlink($file_path); $stmt = $conn->prepare("DELETE FROM live_side_ads WHERE id = :id"); $stmt->execute([':id' => $id]); $live_side_ad_message = "Live Side Ad deleted successfully!"; } } catch (Exception $e) { $live_side_ad_message = "Error deleting ad: " . $e->getMessage(); } } // ======================================================= // END: LIVE PLAYER AD HANDLERS // ======================================================= // Fetch all banners try { $banners = $conn->query("SELECT * FROM banners ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $banner_message = "Error fetching banners: " . htmlspecialchars($e->getMessage()); error_log("Banner fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $banners = []; } // Fetch all special programs try { $special_programs = $conn->query("SELECT * FROM special_programs ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $special_program_message = "Error fetching special programs: " . htmlspecialchars($e->getMessage()); error_log("Special program fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $special_programs = []; } // Fetch all featured programs try { $featured_programs = $conn->query("SELECT * FROM featured_programs ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $featured_program_message = "Error fetching featured programs: " . htmlspecialchars($e->getMessage()); error_log("Featured program fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $featured_programs = []; } // Fetch all programmes try { $programmes = $conn->query("SELECT * FROM programmes ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $programme_message = "Error fetching programmes: " . htmlspecialchars($e->getMessage()); error_log("Programme fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $programmes = []; } // Fetch all contact messages try { $contact_messages = $conn->query("SELECT * FROM contact ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $contact_message = "Error fetching contact messages: " . htmlspecialchars($e->getMessage()); error_log("Contact fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $contact_messages = []; } // Fetch all schedule entries try { $schedule_entries = $conn->query("SELECT * FROM tv_schedule ORDER BY day, time ASC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $schedule_message = "Error fetching schedule entries: " . htmlspecialchars($e->getMessage()); error_log("Schedule fetch error: " . $e->getMessage(), 3, "/home/monara/public_html/logs/php_errors.log"); $schedule_entries = []; } // Fetch all ads try { $horizontal_ads = $conn->query("SELECT * FROM horizontal_ads ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $ad_message = "Error fetching ads: " . htmlspecialchars($e->getMessage()); $horizontal_ads = []; } // Fetch all live player ads try { $live_top_ads = $conn->query("SELECT * FROM live_top_ads ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $live_top_ad_message = "Error fetching top ads: " . $e->getMessage(); $live_top_ads = []; } try { $live_side_ads = $conn->query("SELECT * FROM live_side_ads ORDER BY created_at DESC")->fetchAll(PDO::FETCH_ASSOC); } catch (Exception $e) { $live_side_ad_message = "Error fetching side ads: " . $e->getMessage(); $live_side_ads = []; } require __DIR__ . '/../components/header.php'; ?>
Logout

Teledrama Management

All Teledramas

ID Cover Title Description YouTube Playlist Sort Order Actions
Edit Delete
No teledramas found.

Manage Special Programs

<?php echo htmlspecialchars($program['title']); ?>

Delete

No special programs uploaded yet.

Add New Programme

Existing Programmes

Sort Cover Title Description Playlist ID Actions
Edit Delete

Contact Messages

ID Name Email Message Submitted At Action
100) { ?> ...

Delete

No contact messages submitted yet.

Add New Schedule Entry

Now Showing

prepare(" SELECT * FROM tv_schedule WHERE day = :day AND time <= :time ORDER BY time DESC LIMIT 1 "); $now_stmt->execute([':day' => $currentDay, ':time' => $currentTime]); $now_program = $now_stmt->fetch(PDO::FETCH_ASSOC); ?>
is showing now ()
No program currently airing.

Current Schedule

No schedule entries added yet.

Day Time Program Action

Manage Horizontal Ads

Leave empty to show immediately.
Leave empty to run forever.

Uploaded Ads

Ad

Link:

Start: Immediately'; ?>
End: Forever'; ?>
Delete

No ads uploaded yet.

Manage Live Top Banner (460x50)

Uploaded Top Ads

No top ads uploaded.


Manage Live Side Banners (160x600)

Uploaded Side Ads

No side ads uploaded.