Initial commit: 교육 프로젝트 배포

This commit is contained in:
송대일
2026-07-01 18:32:42 +09:00
commit be6dccd120
1483 changed files with 5082202 additions and 0 deletions
+328
View File
@@ -0,0 +1,328 @@
<?php
require_once __DIR__ . '/db_conn.php';
require_once __DIR__ . '/api_log.php';
// 외부(호출하는 파일)에서 $SET_PREFIX를 정의하지 않았을 경우를 대비한 기본값 설정
$prefixCondition = isset($SET_PREFIX) ? $SET_PREFIX : 'L'; //L=리더십(기본값), I=인사이트
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
$memberId = $_SESSION['member_id'] ?? '';
$sysCompCode = $_SESSION['sys_comp_code'] ?? '';
//$memberId = 'U001';
//$sysCompCode = 'COMP01';
if (!function_exists('edu_extract_youtube_id')) {
function edu_extract_youtube_id(string $rawUrl): string
{
$value = trim($rawUrl);
if ($value === '') {
return '';
}
if (preg_match('/^[A-Za-z0-9_-]{11}$/', $value) === 1) {
return $value;
}
if (strpos($value, 'youtube.com/watch') !== false) {
$query = parse_url($value, PHP_URL_QUERY);
if (is_string($query)) {
parse_str($query, $params);
return trim((string) ($params['v'] ?? ''));
}
}
if (strpos($value, 'youtu.be/') !== false) {
return trim((string) preg_replace('/[?&#].*$/', '', substr($value, strpos($value, 'youtu.be/') + 9)));
}
if (strpos($value, 'youtube.com/embed/') !== false) {
return trim((string) preg_replace('/[?&#].*$/', '', substr($value, strpos($value, 'youtube.com/embed/') + 18)));
}
return '';
}
}
if (!function_exists('edu_build_youtube_thumbnail')) {
function edu_build_youtube_thumbnail(string $rawUrl, string $thumbnailName = 'hqdefault.jpg'): string
{
$videoId = edu_extract_youtube_id($rawUrl);
if ($videoId === '') {
return '/img/video/img_thumb_01.png';
}
$thumbnailName = trim($thumbnailName);
if ($thumbnailName === '') {
$thumbnailName = 'hqdefault.jpg';
}
return 'https://img.youtube.com/vi/' . rawurlencode($videoId) . '/' . rawurlencode($thumbnailName);
}
}
if (!function_exists('edu_normalize_youtube_url')) {
function edu_normalize_youtube_url(string $rawUrl): string
{
$value = trim($rawUrl);
if ($value === '') {
return '';
}
if (preg_match('/^https?:\/\//i', $value) === 1) {
return $value;
}
$videoId = edu_extract_youtube_id($value);
if ($videoId === '') {
return $value;
}
return 'https://www.youtube.com/watch?v=' . rawurlencode($videoId);
}
}
if (!function_exists('edu_build_profile_image_path')) {
function edu_build_profile_image_path(string $memberId, string $sysCompCode = '', string $belongCompId = '', string $workingCompId = ''): string
{
$memberId = trim($memberId);
if ($memberId === '') {
return '/img/ico/ico_user.svg';
}
$teamCodeSource = '';
foreach ([$workingCompId, $belongCompId, $sysCompCode] as $candidate) {
$candidate = preg_replace('/[^A-Za-z0-9]/', '', strtoupper(trim((string) $candidate)));
if ($candidate !== '') {
$teamCodeSource = $candidate;
break;
}
}
$teamCode = $teamCodeSource === '' ? '' : substr($teamCodeSource, -2);
if ($teamCode === '') {
return '/img/ico/ico_user.svg';
}
return '/img/profile/' . rawurlencode($memberId . '_' . $teamCode) . '.png';
}
}
//Svg
if($prefixCondition=='L'){
$prefixSvg = "leadership";
}else if($prefixCondition=='I'){
$prefixSvg = "insight";
}
//배너설정
if($prefixCondition=='L'){//L=리더십(기본값), I=인사이트
$array_banner_img = [
['normal' => '/img/leadership/img_banner_01.png', 'mobile' => '/img/leadership/img_banner_01_m.png', 'title' => '실천으로 완성하는 리더십'],
['normal' => '/img/leadership/img_banner_02.png', 'mobile' => '/img/leadership/img_banner_02_m.png', 'title' => '성장하는 리더십 여정'],
['normal' => '/img/leadership/img_banner_03.png', 'mobile' => '/img/leadership/img_banner_03_m.png', 'title' => '리더로 성장하는 과정'],
];
}else if($prefixCondition=='I'){//L=리더십(기본값), I=인사이트
$array_banner_img = [
['normal' => '/img/insight/img_banner_01.png', 'mobile' => '/img/insight/img_banner_01_m.png', 'title' => '잘되는 일 하세요'],
['normal' => '/img/insight/img_banner_02.png', 'mobile' => '/img/insight/img_banner_02_m.png', 'title' => '다시 일하고 싶은 관계'],
['normal' => '/img/insight/img_banner_03.png', 'mobile' => '/img/insight/img_banner_03_m.png', 'title' => '3일의 실행'],
];
}
$dbSuccess = false;
$array_tab_info = [];
$array_leadership_banner = [];
$array_insight_banner = [];
try {
$pdo = db_conn();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET NAMES 'utf8mb4'");
// LIKE 연산자를 안전하게 처리하기 위해 준비된 선언(Prepared Statement) 사용
$stmtCode = $pdo->prepare("
SELECT group_code, base_code, code, code_name
FROM edu_codes
WHERE is_active = 1
AND group_code = 'CA200'
AND code LIKE :prefix
ORDER BY base_code ASC
");
// 'L%' 형태로 바인딩하여 검색
$stmtCode->execute([':prefix' => $prefixCondition . '%']);
$rows = $stmtCode->fetchAll(PDO::FETCH_ASSOC);
if ($rows) {
$i = 1;
foreach ($rows as $cr) {
$index = sprintf('%02d', $i);
$index_src = '/img/ico/ico_'.$prefixSvg.'_' . $index . '.svg';
$array_tab_info[] = [
'base_code' => $cr['base_code'],
'code_name' => $cr['code_name'],
'src' => $index_src
];
$i++;
}
}
if ($prefixCondition === 'L') {
$stmtBanner = $pdo->prepare(
"
SELECT
c.content_id,
c.title,
c.description1,
c.description2,
c.description3,
c.content_url,
c.sort_order
FROM edu_contents c
WHERE c.is_active = 1
AND c.issue_type_code = 'LD10010'
ORDER BY
CASE WHEN COALESCE(c.sort_order, 0) = 0 THEN 1 ELSE 0 END,
c.sort_order ASC,
c.content_id DESC
"
);
$stmtBanner->execute();
foreach ($stmtBanner->fetchAll(PDO::FETCH_ASSOC) as $bannerRow) {
$contentUrl = trim((string) ($bannerRow['content_url'] ?? ''));
$array_leadership_banner[] = [
'content_id' => (string) ($bannerRow['content_id'] ?? ''),
'title' => (string) ($bannerRow['title'] ?? ''),
'description1' => trim((string) ($bannerRow['description1'] ?? '')),
'description2' => trim((string) ($bannerRow['description2'] ?? '')),
'description3' => trim((string) ($bannerRow['description3'] ?? '')),
'content_url' => $contentUrl,
'thumbnail' => edu_build_youtube_thumbnail($contentUrl, 'sddefault.jpg'),
'banner_title_pc' => '/img/leadership/banner_leadership.svg',
'banner_title_mo' => '/img/leadership/banner_leadership_m.svg',
];
}
} elseif ($prefixCondition === 'I') {
$stmtBanner = $pdo->prepare(
"
SELECT
c.content_id,
c.title,
c.description1,
c.description2,
c.description3,
c.content_url,
c.category_code,
c.category_group,
c.issue_type_code,
c.is_offer,
c.offer_id,
c.sort_order,
cg.code_name AS sub_category_name,
o.member_id AS offer_member_id,
o.sys_comp_code AS offer_sys_comp_code,
u.name AS offer_member_name,
u.dept_name AS offer_dept_name,
u.rank_name AS offer_rank_name,
u.sys_comp_code AS user_sys_comp_code,
u.belong_comp_id,
u.working_comp_id
FROM edu_contents c
LEFT JOIN edu_codes cg
ON cg.base_code = c.category_group
AND cg.group_code = 'CA200'
AND cg.is_active = 1
LEFT JOIN edu_content_offer o
ON o.offer_id = c.offer_id
LEFT JOIN edu_users u
ON u.member_id = o.member_id
AND (
o.sys_comp_code IS NULL
OR o.sys_comp_code = ''
OR u.sys_comp_code = o.sys_comp_code
)
WHERE c.is_active = 1
AND c.issue_type_code IN ('IS10001', 'IS10002', 'IS10003')
ORDER BY
CASE c.issue_type_code
WHEN 'IS10001' THEN 1
WHEN 'IS10002' THEN 2
WHEN 'IS10003' THEN 3
ELSE 99
END ASC,
CASE WHEN COALESCE(c.sort_order, 0) = 0 THEN 1 ELSE 0 END,
c.sort_order ASC,
c.content_id DESC
"
);
$stmtBanner->execute();
$insightBannerTitleMap = [
'IS10001' => [
'pc' => '/img/insight/banner_issue.svg',
'mo' => '/img/insight/banner_issue_m.svg',
'alt' => 'Hot Issue',
],
'IS10002' => [
'pc' => '/img/insight/banner_pick.svg',
'mo' => '/img/insight/banner_pick_m.svg',
'alt' => "Editor's Pick",
],
'IS10003' => [
'pc' => '/img/insight/banner_choice.svg',
'mo' => '/img/insight/banner_choice_m.svg',
'alt' => "Top Learner's Choice",
],
];
foreach ($stmtBanner->fetchAll(PDO::FETCH_ASSOC) as $bannerRow) {
$issueTypeCode = (string) ($bannerRow['issue_type_code'] ?? '');
$titleMeta = $insightBannerTitleMap[$issueTypeCode] ?? $insightBannerTitleMap['IS10001'];
$contentUrl = edu_normalize_youtube_url((string) ($bannerRow['content_url'] ?? ''));
$offerMemberId = trim((string) ($bannerRow['offer_member_id'] ?? ''));
$offerMemberName = trim((string) ($bannerRow['offer_member_name'] ?? ''));
$offerDeptName = trim((string) ($bannerRow['offer_dept_name'] ?? ''));
$offerRankName = trim((string) ($bannerRow['offer_rank_name'] ?? ''));
$isTopLearner = $issueTypeCode === 'IS10003' && (string) ($bannerRow['is_offer'] ?? '') === '1';
$array_insight_banner[] = [
'content_id' => (string) ($bannerRow['content_id'] ?? ''),
'title' => (string) ($bannerRow['title'] ?? ''),
'description1' => trim((string) ($bannerRow['description1'] ?? '')),
'description2' => trim((string) ($bannerRow['description2'] ?? '')),
'description3' => trim((string) ($bannerRow['description3'] ?? '')),
'content_url' => $contentUrl,
'thumbnail' => edu_build_youtube_thumbnail($contentUrl, 'sddefault.jpg'),
'category_name' => '인사이트',
'sub_category_name' => trim((string) ($bannerRow['sub_category_name'] ?? '')),
'issue_type_code' => $issueTypeCode,
'banner_title_pc' => $titleMeta['pc'],
'banner_title_mo' => $titleMeta['mo'],
'banner_title_alt' => $titleMeta['alt'],
'is_top_learner' => $isTopLearner,
'offer_member_id' => $offerMemberId,
'offer_member_name' => $offerMemberName,
'offer_dept_name' => $offerDeptName,
'offer_rank_name' => $offerRankName,
'offer_profile_image' => $isTopLearner
? edu_build_profile_image_path(
$offerMemberId,
(string) ($bannerRow['user_sys_comp_code'] ?? $bannerRow['offer_sys_comp_code'] ?? ''),
(string) ($bannerRow['belong_comp_id'] ?? ''),
(string) ($bannerRow['working_comp_id'] ?? '')
)
: '/img/ico/ico_user.svg',
];
}
}
$dbSuccess = true;
} catch (Exception $e) {
$errMsg = $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine();
error_log('[leadership_init_data.php] DB Error: ' . $errMsg);
// api_log 함수가 있다면 기록
if (function_exists('api_log')) {
api_log('leadership_init', 'DB_ERROR', ['error' => $errMsg]);
}
}