set_charset("utf8"); // Initialize variables $disease_info = ""; $video_info = ""; $articles_info = ""; $recipes_info =""; $toc = ""; // Initialize Table of Contents $counter = 1; // Initialize counter for section IDs $buttonLow = ""; $categorySponsors = []; // NEW: sponsors for this category // Set locale to Arabic for date formatting setlocale(LC_TIME, 'ar_EG.UTF-8'); // Check if 'titles' is set in the URL if (!isset($_GET['titles']) || empty($_GET['titles'])) { die("Invalid request: Title parameter is missing."); } $titles = $_GET['titles']; // Check if 'titles' contains 'rights/' at the beginning if (strpos($titles, 'rights/') === 0) { $change = true; $_GET['titles'] = str_replace('rights/', '', $titles); $_GET['titles'] = str_replace('+', ' ', $_GET['titles']); } else { $change = false; } // Decode the title $decoded_title = str_replace('-', ' ', $_GET['titles']); // Debugging log if (isset($_GET['titles'])) { // Replace "-" with spaces to match the database format $decoded_title = str_replace('-', ' ', $_GET['titles']); // Prepare the query to find the category ID $category_query = "SELECT ID, Name, year_desies_day FROM ncategories WHERE Name = ?"; $category_stmt = $conn->prepare($category_query); if (!$category_stmt) { die("SQL error during prepare: " . $conn->error); } $category_stmt->bind_param("s", $decoded_title); $category_stmt->execute(); $category_result = $category_stmt->get_result(); if ($category_result->num_rows > 0) { $category_row = $category_result->fetch_assoc(); $category_id = $category_row['ID']; $category_name = $category_row['Name']; if ($change == true) { $category_name = "حقوق وخدمات مرضى " . $category_name; } $filesQuery = "SELECT * FROM category_files WHERE category_id = $category_id"; $filesResult = $conn->query($filesQuery) or die($conn->error); $categoryFiles = $filesResult->fetch_all(MYSQLI_ASSOC); // ------------------ SPONSORS (NEW) ------------------ $sponsorSql = "SELECT company_name, website_url, logo_path FROM category_sponsors WHERE category_id = ? ORDER BY id DESC"; $sponsorStmt = $conn->prepare($sponsorSql); if (!$sponsorStmt) { die("SQL error during sponsors prepare: " . $conn->error); } $sponsorStmt->bind_param("i", $category_id); $sponsorStmt->execute(); $sponsorRes = $sponsorStmt->get_result(); if ($sponsorRes && $sponsorRes->num_rows > 0) { while ($sp = $sponsorRes->fetch_assoc()) { // Fix path from '../../data/sponsors/...' to '/data/sponsors/...' $logoWebPath = preg_replace('#^\.\./\.\.#', '', $sp['logo_path']); $sp['logo_web'] = $logoWebPath; $categorySponsors[] = $sp; } } $sponsorStmt->close(); // ------------------ END SPONSORS ------------------ // Prepare the query to fetch news $news_query = "SELECT ID,title, fData, picture, pdate, template,mobilevideo, picPath FROM news WHERE sCat = ? AND mStatus = 1 order by ID ASC"; $news_stmt = $conn->prepare($news_query); if (!$news_stmt) { die("SQL error during news prepare: " . $conn->error); } $news_stmt->bind_param("i", $category_id); $news_stmt->execute(); $news_result = $news_stmt->get_result(); if ($news_result->num_rows > 0) { $toc .= "