285 lines
7.2 KiB
PHP
285 lines
7.2 KiB
PHP
<?php
|
|
//=========================
|
|
// 개인정보 + 배지
|
|
//=========================
|
|
require_once __DIR__ . '/db_conn.php';
|
|
|
|
if (!function_exists('mypage_h')) {
|
|
function mypage_h(?string $str): string
|
|
{
|
|
return htmlspecialchars((string)$str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
|
}
|
|
}
|
|
|
|
if (!function_exists('mypage_level_meta')) {
|
|
function mypage_level_meta(?string $level): array
|
|
{
|
|
$level = trim((string)$level);
|
|
|
|
$map = [
|
|
'MASTER' => [
|
|
'code' => 'Master',
|
|
'class' => 'master',
|
|
'label' => 'Master',
|
|
'icon' => '/edu/img/ico/ico_level_master.svg',
|
|
],
|
|
'ELITE' => [
|
|
'code' => 'Elite',
|
|
'class' => 'elite',
|
|
'label' => 'Elite',
|
|
'icon' => '/edu/img/ico/ico_level_elite.svg',
|
|
],
|
|
'LEARNER' => [
|
|
'code' => 'Learner',
|
|
'class' => 'learner',
|
|
'label' => 'Learner',
|
|
'icon' => '/edu/img/ico/ico_level_learner.svg',
|
|
],
|
|
'ROOKIE' => [
|
|
'code' => 'Rookie',
|
|
'class' => 'rookie',
|
|
'label' => 'Rookie',
|
|
'icon' => '/edu/img/ico/ico_level_rookie.svg',
|
|
],
|
|
];
|
|
|
|
$key = strtoupper($level);
|
|
|
|
return $map[$key] ?? [
|
|
'code' => 'Rookie',
|
|
'class' => 'rookie',
|
|
'label' => 'Rookie',
|
|
'icon' => '/edu/img/ico/ico_level_rookie.svg',
|
|
];
|
|
}
|
|
}
|
|
|
|
if (!function_exists('mypage_badge_map')) {
|
|
function mypage_badge_map(string $badgeCode): array
|
|
{
|
|
$badgeCode = strtoupper(trim($badgeCode));
|
|
|
|
$BADGE_ICON_MAP = [
|
|
// 실제 운영 시 코드값 확정되면 여기만 교체
|
|
'BG001' => [
|
|
'slot' => 'hat',
|
|
'img' => '/edu/img/mypage/ico_school.png',
|
|
'name' => '학습 배지',
|
|
],
|
|
'BG002' => [
|
|
'slot' => 'pencil',
|
|
'img' => '/edu/img/mypage/ico_pencil.png',
|
|
'name' => '작성 배지',
|
|
],
|
|
'BG003' => [
|
|
'slot' => 'pick',
|
|
'img' => '/edu/img/mypage/ico_pick_2.png',
|
|
'name' => 'Pick 배지',
|
|
],
|
|
];
|
|
|
|
return $BADGE_ICON_MAP[$badgeCode] ?? [
|
|
'slot' => 'pick',
|
|
'img' => '/edu/img/mypage/ico_pick_2.png',
|
|
'name' => '기본 배지',
|
|
];
|
|
}
|
|
}
|
|
|
|
// TODO: 실제 로그인 세션 연동 후 교체
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
$memberId = $_SESSION['member_id'] ?? '';
|
|
$sysCompCode = $_SESSION['sys_comp_code'] ?? '';
|
|
//$memberId = 'U001';
|
|
//$sysCompCode = 'COMP01';
|
|
|
|
//echo "memberId===".$memberId."<br>";
|
|
//echo "sysCompCode===".$sysCompCode."<br>";exit;
|
|
//$memberId = 'U001';
|
|
//$sysCompCode = 'COMP01';
|
|
|
|
|
|
// ★ 선택년도 수집
|
|
$selectedYear = trim((string)($_GET['selected_year'] ?? date('Y')));
|
|
|
|
if ($selectedYear === '' || !preg_match('/^\d{4}$/', $selectedYear)) {
|
|
$selectedYear = date('Y');
|
|
}
|
|
$profileFileName = $memberId . '_' . $sysCompCode . '.png';
|
|
$profileFilePath = __DIR__ . '/../img/profile/' . $profileFileName;
|
|
$profileImageUrl = '/edu/img/profile/' . $profileFileName;
|
|
|
|
|
|
|
|
if (file_exists($profileFilePath)) {
|
|
$profileImage = $profileImageUrl;
|
|
/*
|
|
if($memberId=="M21420"){
|
|
echo 11111111;
|
|
exit;
|
|
}
|
|
*/
|
|
} else {
|
|
/*
|
|
if($memberId=="M21420"){
|
|
echo 222222222222;
|
|
exit;
|
|
}*/
|
|
|
|
$profileImage = '/edu/img/ico/ico_profile.svg';
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
if (file_exists($profileFilePath)) {
|
|
$profileImage = $profileImageUrl;
|
|
} else {
|
|
$profileImage = '/edu/img/ico/ico_profile.svg';
|
|
}
|
|
|
|
*/
|
|
|
|
$profileData = [
|
|
'member_id' => $memberId,
|
|
'sys_comp_code' => $sysCompCode,
|
|
'name' => '사용자',
|
|
'rank_name' => '',
|
|
'working_comp' => '',
|
|
'join_date' => '',
|
|
'latest_stats_year' => $selectedYear,
|
|
'learning_level' => 'Rookie',
|
|
'level_class' => 'rookie',
|
|
'level_icon' => '/edu/img/ico/ico_level_rookie.svg',
|
|
'total_minutes' => 0,
|
|
'profile_image' => $profileImage, // 현재는 기본 이미지 고정
|
|
];
|
|
|
|
$profileBadges = [
|
|
'hat' => null,
|
|
'pencil' => null,
|
|
'pick' => null,
|
|
];
|
|
|
|
try {
|
|
$pdo = db_conn();
|
|
$pdo->exec("SET NAMES 'utf8mb4'");
|
|
|
|
// ★ 선택년도 학습통계 기준
|
|
$sql = "
|
|
SELECT
|
|
u.member_id,
|
|
u.sys_comp_code,
|
|
u.name,
|
|
u.rank_name,
|
|
u.working_comp,
|
|
u.join_date,
|
|
|
|
ec.code,
|
|
ec.code_name,
|
|
|
|
ys.stats_year,
|
|
ys.learning_level,
|
|
ys.total_minutes
|
|
FROM edu_users u
|
|
LEFT JOIN edu_yearly_learning_stats ys
|
|
ON ys.member_id = u.member_id
|
|
AND ys.sys_comp_code = u.sys_comp_code
|
|
AND ys.stats_year = :selected_year
|
|
LEFT JOIN
|
|
(
|
|
SELECT code,code_name FROM edu_codes WHERE group_code = 'CO100'
|
|
) ec
|
|
ON ec.code = u.belong_comp
|
|
WHERE u.member_id = :member_id
|
|
AND u.sys_comp_code = :sys_comp_code
|
|
LIMIT 1
|
|
";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([
|
|
':member_id' => $memberId,
|
|
':sys_comp_code' => $sysCompCode,
|
|
':selected_year' => (int)$selectedYear,
|
|
]);
|
|
|
|
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if ($row) {
|
|
$levelMeta = mypage_level_meta($row['learning_level'] ?? '');
|
|
|
|
$profileData = [
|
|
'member_id' => $row['member_id'],
|
|
'sys_comp_code' => $row['sys_comp_code'],
|
|
'name' => $row['name'] ?? '사용자',
|
|
'rank_name' => $row['rank_name'] ?? '',
|
|
'belong_comp_code' => $row['code'] ?? '',
|
|
'belong_comp_name' => $row['code_name'] ?? '',
|
|
'working_comp' => $row['working_comp'] ?? '',
|
|
'join_date' => $row['join_date'] ?? '',
|
|
'latest_stats_year' => $row['stats_year'] ?? $selectedYear,
|
|
'learning_level' => $levelMeta['label'],
|
|
'level_class' => $levelMeta['class'],
|
|
'level_icon' => $levelMeta['icon'],
|
|
'total_minutes' => (int)($row['total_minutes'] ?? 0),
|
|
'profile_image' => $profileImage, // 현재는 기본 이미지 고정
|
|
|
|
];
|
|
}
|
|
|
|
// ★ 선택년도 통계가 없으면 선택년도 학습이력 합계 fallback
|
|
if ((int)$profileData['total_minutes'] === 0) {
|
|
$stmtFallback = $pdo->prepare("
|
|
SELECT COALESCE(SUM(watch_tm), 0) AS total_minutes
|
|
FROM edu_learning_histories
|
|
WHERE member_id = :member_id
|
|
AND sys_comp_code = :sys_comp_code
|
|
AND YEAR(last_viewed_at) = :selected_year
|
|
");
|
|
$stmtFallback->execute([
|
|
':member_id' => $memberId,
|
|
':sys_comp_code' => $sysCompCode,
|
|
':selected_year' => (int)$selectedYear,
|
|
]);
|
|
|
|
$fallbackMin = (int)$stmtFallback->fetchColumn();
|
|
if ($fallbackMin > 0) {
|
|
$profileData['total_minutes'] = $fallbackMin;
|
|
}
|
|
}
|
|
|
|
// 배지 조회
|
|
$stmtBadge = $pdo->prepare("
|
|
SELECT badge_code, issued_at
|
|
FROM edu_user_badges
|
|
WHERE member_id = :member_id
|
|
AND sys_comp_code = :sys_comp_code
|
|
ORDER BY issued_at DESC, seq DESC
|
|
");
|
|
$stmtBadge->execute([
|
|
':member_id' => $memberId,
|
|
':sys_comp_code' => $sysCompCode,
|
|
]);
|
|
|
|
foreach ($stmtBadge->fetchAll(PDO::FETCH_ASSOC) as $badgeRow) {
|
|
$badgeInfo = mypage_badge_map($badgeRow['badge_code'] ?? '');
|
|
$slot = $badgeInfo['slot'];
|
|
|
|
if (!isset($profileBadges[$slot]) || $profileBadges[$slot] !== null) {
|
|
continue;
|
|
}
|
|
|
|
$profileBadges[$slot] = [
|
|
'badge_code' => $badgeRow['badge_code'],
|
|
'slot' => $slot,
|
|
'img' => $badgeInfo['img'],
|
|
'name' => $badgeInfo['name'],
|
|
'issued_at' => $badgeRow['issued_at'],
|
|
];
|
|
}
|
|
} catch (Throwable $e) {
|
|
// 운영 시 로깅 권장
|
|
} |