Initial commit: 교육 프로젝트 배포
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* 외부 인트라넷 → 배움터 진입 API
|
||||
*
|
||||
* 인트라넷에서 POST 방식으로 member_id, sys_comp_code를 전달받아
|
||||
* edu_users 테이블에서 사용자를 확인하고, intro_flag 값에 따라
|
||||
* 적절한 페이지로 리다이렉트합니다.
|
||||
*
|
||||
* POST 파라미터:
|
||||
* - member_id (필수) 사용자 ID
|
||||
* - sys_comp_code (필수) 회사 코드
|
||||
*
|
||||
* 사용 예 (인트라넷 HTML form):
|
||||
* <form method="POST" action="https://baroncs.co.kr/edu/bbs/entry.php">
|
||||
* <input type="hidden" name="member_id" value="U001" />
|
||||
* <input type="hidden" name="sys_comp_code" value="COMP01" />
|
||||
* <button type="submit">배움터</button>
|
||||
* </form>
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
if (session_status() === PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
exit('허용되지 않는 요청 방식입니다.');
|
||||
}
|
||||
|
||||
$memberId = trim((string)($_POST['member_id'] ?? ''));
|
||||
$sysCompCode = trim((string)($_POST['sys_comp_code'] ?? ''));
|
||||
|
||||
// 테스트 토글: 아래 true 라인을 주석 해제하면 intro_flag와 무관하게 index.php로 진입
|
||||
// $forceIndexRedirectForTest = false;
|
||||
$forceIndexRedirectForTest = true;
|
||||
|
||||
// 테스트 토글: intro_flag 자동 업데이트(0->1) 실행 여부
|
||||
$enableIntroFlagAutoUpdate = true;
|
||||
// $enableIntroFlagAutoUpdate = false;
|
||||
|
||||
if ($memberId === '' || $sysCompCode === '') {
|
||||
http_response_code(400);
|
||||
exit('필수 파라미터가 누락되었습니다.');
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/db_conn.php';
|
||||
|
||||
try {
|
||||
$pdo = db_conn();
|
||||
|
||||
// [1] 사용자 조회
|
||||
$stmt = $pdo->prepare(
|
||||
'SELECT name, rank_name, intro_flag
|
||||
FROM edu_users
|
||||
WHERE member_id = ? AND sys_comp_code = ?
|
||||
LIMIT 1'
|
||||
);
|
||||
$stmt->execute([$memberId, $sysCompCode]);
|
||||
$user = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// [2] 신규 사용자 자동 등록
|
||||
// if (!$user) {
|
||||
// // 인트라넷에서 이름을 안 보내줄 경우를 대비한 기본값
|
||||
// $newName = trim((string)($_POST['name'] ?? '신규사용자'));
|
||||
// $newRank = trim((string)($_POST['rank_name'] ?? '사원'));
|
||||
|
||||
// $ins = $pdo->prepare(
|
||||
// 'INSERT INTO edu_users (member_id, sys_comp_code, name, rank_name, intro_flag, created_at, is_active)
|
||||
// VALUES (?, ?, ?, ?, "0", NOW(), "Y")'
|
||||
// );
|
||||
// $ins->execute([$memberId, $sysCompCode, $newName, $newRank]);
|
||||
|
||||
// $user = ['name' => $newName, 'rank_name' => $newRank, 'intro_flag' => '0'];
|
||||
// }
|
||||
|
||||
// [3] 세션 저장 (통합 및 정리)
|
||||
// 여러 시스템 호환을 위해 필요한 키값을 모두 채워주되, 이름은 'member_name'으로 통일하는 것이 좋습니다.
|
||||
$_SESSION['member_id'] = $memberId;
|
||||
$_SESSION['user_id'] = $memberId;
|
||||
$_SESSION['ss_mb_id'] = $memberId;
|
||||
$_SESSION['sys_comp_code'] = $sysCompCode;
|
||||
$_SESSION['company'] = $sysCompCode;
|
||||
|
||||
$_SESSION['member_name'] = $user['name']; // 인트로에서 쓸 변수
|
||||
$_SESSION['name'] = $user['name']; // 일반 페이지용
|
||||
$_SESSION['rank_name'] = $user['rank_name']; // 직책
|
||||
|
||||
// 세션 보안 강화
|
||||
session_regenerate_id(true);
|
||||
|
||||
// [4] 리다이렉트
|
||||
$introFlag = (string)($user['intro_flag'] ?? '0');
|
||||
$redirectUrl = ($introFlag === '1') ? '/edu/skin/index.php' : '/edu/skin/intro.php';
|
||||
|
||||
if ($forceIndexRedirectForTest) {
|
||||
$redirectUrl = '/edu/skin/index.php';
|
||||
}
|
||||
|
||||
// index.php 진입 시 intro_flag가 0이면 자동으로 1로 승격 (토글 가능)
|
||||
if ($enableIntroFlagAutoUpdate && $redirectUrl === '/edu/skin/index.php' && $introFlag === '0') {
|
||||
$stmtUpdateIntroFlag = $pdo->prepare(
|
||||
'UPDATE edu_users
|
||||
SET intro_flag = ?
|
||||
WHERE member_id = ? AND sys_comp_code = ? AND intro_flag = 0'
|
||||
);
|
||||
$stmtUpdateIntroFlag->execute(['1', $memberId, $sysCompCode]);
|
||||
$introFlag = '1';
|
||||
}
|
||||
|
||||
header("Location: $redirectUrl");
|
||||
exit;
|
||||
|
||||
} catch (Exception $e) {
|
||||
exit('오류: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
// function goToEdu(memberId, sysCompCode) {
|
||||
// var form = document.createElement('form');
|
||||
// form.method = 'POST';
|
||||
// form.action = 'https://baroncs.co.kr/edu/bbs/entry.php';
|
||||
|
||||
// var inputId = document.createElement('input');
|
||||
// inputId.type = 'hidden';
|
||||
// inputId.name = 'member_id';
|
||||
// inputId.value = memberId;
|
||||
|
||||
// var inputComp = document.createElement('input');
|
||||
// inputComp.type = 'hidden';
|
||||
// inputComp.name = 'sys_comp_code';
|
||||
// inputComp.value = sysCompCode;
|
||||
|
||||
// form.appendChild(inputId);
|
||||
// form.appendChild(inputComp);
|
||||
// document.body.appendChild(form);
|
||||
// form.submit();
|
||||
// }
|
||||
|
||||
// <a href="#" onclick="goToEdu('U001', 'COMP01'); return false;">배움터</a>
|
||||
Reference in New Issue
Block a user