Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
//[마이페이지][제안하기][제안이력리스트] 데이터 동적변환
|
||||
require_once __DIR__ . '/../bbs/db_conn.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
// TODO: 실제 로그인 세션 연동 후 교체
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
$memberId = $_SESSION['member_id'] ?? '';
|
||||
$sysCompCode = $_SESSION['sys_comp_code'] ?? '';
|
||||
//$memberId = 'U001';
|
||||
//$sysCompCode = 'COMP01';
|
||||
|
||||
function response_json(array $data): void
|
||||
{
|
||||
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
exit;
|
||||
}
|
||||
|
||||
function h(?string $str): string
|
||||
{
|
||||
return htmlspecialchars((string)$str, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo = db_conn();
|
||||
$pdo->exec("SET NAMES 'utf8mb4'");
|
||||
|
||||
$offerStatusMap = [
|
||||
'OF10001' => '제안',
|
||||
'OF10002' => '검토중',
|
||||
'OF10003' => '게시완료',
|
||||
'OF10004' => '게시불가',
|
||||
];
|
||||
|
||||
$stmtCode = $pdo->prepare("
|
||||
SELECT base_code, code_name
|
||||
FROM edu_codes
|
||||
WHERE group_code = 'OF100'
|
||||
AND is_active = '1'
|
||||
ORDER BY code
|
||||
");
|
||||
$stmtCode->execute();
|
||||
|
||||
foreach ($stmtCode->fetchAll(PDO::FETCH_ASSOC) as $row) {
|
||||
$offerStatusMap[$row['base_code']] = $row['code_name'];
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT
|
||||
co.offer_id,
|
||||
co.status_code,
|
||||
co.reason,
|
||||
co.reason_return,
|
||||
co.created_at
|
||||
FROM edu_content_offer co
|
||||
WHERE co.member_id = :member_id
|
||||
AND co.sys_comp_code = :sys_comp_code
|
||||
ORDER BY
|
||||
CASE co.status_code
|
||||
WHEN 'OF10002' THEN 0
|
||||
WHEN 'OF10001' THEN 1
|
||||
WHEN 'OF10003' THEN 2
|
||||
WHEN 'OF10004' THEN 3
|
||||
ELSE 9
|
||||
END,
|
||||
co.created_at DESC
|
||||
LIMIT 20
|
||||
");
|
||||
$stmt->execute([
|
||||
':member_id' => $memberId,
|
||||
':sys_comp_code' => $sysCompCode,
|
||||
]);
|
||||
|
||||
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
ob_start();
|
||||
|
||||
if (!empty($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
$statusCode = (string)($row['status_code'] ?? '');
|
||||
$reason = (string)($row['reason'] ?? '');
|
||||
$reason_return = (string)($row['reason_return'] ?? '');
|
||||
$statusName = $offerStatusMap[$statusCode] ?? $statusCode;
|
||||
$isConsider = ($statusCode === 'OF10002');
|
||||
$createdAtDot = !empty($row['created_at']) ? date('y.m.d', strtotime($row['created_at'])) : '';
|
||||
?>
|
||||
<li style="cursor: pointer;" title="클릭 시 상세결과를 볼 수 있습니다." data-offer-date="<?= h($createdAtDot) ?>" data-offer-reason="<?= h($row['reason'] ?? '') ?>" data-offer-return="<?= h($row['reason_return'] ?? '') ?>" class="<?= $isConsider ? 'consider' : '' ?>" data-offer-id="<?= h($row['offer_id'] ?? '') ?>">
|
||||
<span class="suggest-date"><?= h($createdAtDot) ?></span>
|
||||
<?php if ($isConsider): ?>
|
||||
<span class="suggest-dots"></span>
|
||||
<?php endif; ?>
|
||||
<span class="suggest-state"><?= h($statusName) ?></span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
} else {
|
||||
?>
|
||||
<li>
|
||||
<span class="suggest-date">-</span>
|
||||
<span class="suggest-state">등록된 제안이 없습니다.</span>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
|
||||
$html = ob_get_clean();
|
||||
|
||||
response_json([
|
||||
'success' => true,
|
||||
'html' => $html,
|
||||
]);
|
||||
} catch (Throwable $e) {
|
||||
response_json([
|
||||
'success' => false,
|
||||
'message' => '제안현황을 불러오지 못했습니다.',
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user