exec("SET NAMES 'utf8mb4'"); $bizMemberId = (string)($_SESSION['member_id'] ?? ''); $bizSysCompCode = (string)($_SESSION['sys_comp_code'] ?? ''); $bizLoggedIn = $bizMemberId !== ''; // 선택된 월 (기본값: 현재 월) $selectedMonth = $_GET['month'] ?? date('Y-m'); if (!preg_match('/^\d{4}-\d{2}$/', $selectedMonth)) { $selectedMonth = date('Y-m'); } $selYear = substr($selectedMonth, 0, 4); $selMonth = ltrim(substr($selectedMonth, 5, 2), '0'); // ── 비즈트렌드 컨텐츠 조회 ── $bizData = []; try { $sql = " SELECT c.content_id, c.title, c.description, c.description1, c.description2, c.content_url, c.start_date, c.category_group, c.image_name, c.issue_type_code, CASE WHEN c.issue_type_code IS NOT NULL AND c.issue_type_code != '' THEN fn_get_code_name(c.issue_type_code) ELSE NULL END AS badge_name "; if ($bizLoggedIn) { $sql .= ", lh.watch_tm, lh.content_tm, CASE WHEN cw.content_id IS NOT NULL AND cw.is_active = '1' THEN 1 ELSE 0 END AS is_liked FROM edu_contents c LEFT JOIN edu_learning_histories lh ON lh.content_id = c.content_id AND lh.member_id = ? AND lh.sys_comp_code = ? LEFT JOIN edu_content_wishlist cw ON cw.content_id = c.content_id AND cw.member_id = ? AND cw.sys_comp_code = ? AND cw.is_active = '1' "; } else { $sql .= ", NULL AS watch_tm, NULL AS content_tm, 0 AS is_liked FROM edu_contents c "; } $sql .= " WHERE c.category_code = 'CA10006' AND c.is_active = 1 AND c.start_date IS NOT NULL AND c.start_date <= CURDATE() ORDER BY c.start_date ASC, c.category_group ASC "; $stmt = $pdoBiz->prepare($sql); if ($bizLoggedIn) { $stmt->execute([$bizMemberId, $bizSysCompCode, $bizMemberId, $bizSysCompCode]); } else { $stmt->execute([]); } $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { $dateKey = $row['start_date']; // YouTube videoId 추출 $videoId = ''; $url = $row['content_url'] ?? ''; if (preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]+)/', $url, $m)) { $videoId = $m[1]; } else { $videoId = $url; } // description, description2 → list 배열 $list = []; if (!empty($row['description1'])) { $lines = array_filter(array_map('trim', preg_split('/[\r\n]+/', $row['description1']))); $list = array_merge($list, array_values($lines)); } if (!empty($row['description2'])) { $lines = array_filter(array_map('trim', preg_split('/[\r\n]+/', $row['description2']))); $list = array_merge($list, array_values($lines)); } // gauge (시청 진행률) $gauge = null; $watchTm = (int)($row['watch_tm'] ?? 0); $contentTm = (int)($row['content_tm'] ?? 0); if ($contentTm > 0 && $watchTm > 0) { $gauge = min(100, round($watchTm / $contentTm * 100)); } // 이미지 경로 (edu/uploads/biztrend/ 폴더 기준) $imageData = null; if (!empty($row['image_name'])) { $imageData = '/uploads/biztrend/' . $row['image_name']; } $entry = [ 'contentId' => $row['content_id'] ?? '', 'title' => $row['title'] ?? '', 'list' => $list, 'videoId' => $videoId, 'contentUrl' => $row['content_url'] ?? '', 'description'=> $row['description'] ?? '', 'gauge' => $gauge, 'badge' => $row['badge_name'] ?: null, 'liked' => (bool)($row['is_liked'] ?? false), 'image' => $imageData, 'watchTm' => (int)($row['watch_tm'] ?? 0), 'contentTm' => (int)($row['content_tm'] ?? 0) ]; if (!isset($bizData[$dateKey])) { $bizData[$dateKey] = []; } $bizData[$dateKey][] = $entry; } } catch (Exception $e) { $bizData = []; $bizError = $e->getMessage(); } // ── 추천강의: 최근 업로드된 비즈트렌드 영상 8개 ── $recentBizData = []; try { $recentSql = " SELECT c.content_id, c.title, c.description, c.content_url, c.start_date, c.image_name "; if ($bizLoggedIn) { $recentSql .= ", lh.watch_tm, lh.content_tm FROM edu_contents c LEFT JOIN edu_learning_histories lh ON lh.content_id = c.content_id AND lh.member_id = ? AND lh.sys_comp_code = ? "; } else { $recentSql .= ", NULL AS watch_tm, NULL AS content_tm FROM edu_contents c "; } $recentSql .= " WHERE c.category_code = 'CA10006' AND c.is_active = 1 AND c.start_date <= CURDATE() ORDER BY c.start_date DESC LIMIT 8 "; $recentStmt = $pdoBiz->prepare($recentSql); if ($bizLoggedIn) { $recentStmt->execute([$bizMemberId, $bizSysCompCode]); } else { $recentStmt->execute([]); } $recentRows = $recentStmt->fetchAll(PDO::FETCH_ASSOC); foreach ($recentRows as $row) { $videoId = ''; $url = $row['content_url'] ?? ''; if (preg_match('/(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([a-zA-Z0-9_-]+)/', $url, $m)) { $videoId = $m[1]; } else { $videoId = $url; } $imageData = null; if (!empty($row['image_name'])) { $imageData = '/uploads/biztrend/' . $row['image_name']; } $recentBizData[] = [ 'contentId' => $row['content_id'] ?? '', 'title' => $row['title'] ?? '', 'videoId' => $videoId, 'contentUrl' => $row['content_url'] ?? '', 'description'=> $row['description'] ?? '', 'image' => $imageData, 'watchTm' => (int)($row['watch_tm'] ?? 0), 'contentTm' => (int)($row['content_tm'] ?? 0), ]; } } catch (Exception $e) { $recentBizData = []; } ?>
KBS 제1라디오 '성공예감&별책부록'을 통해
경제 정보를 쉽게 접하고, 생활 속 경제 흐름을 알아보세요.