<?php // (2020.10.5, 차재복, Cha Jae Bok, http://www.ktword.co.kr)
# 세션 스타트 (매 웹페이지 마다 필요)
session_start();
// 세션 변수 : 사용자 타입 ('일반사용자 0' or '테스트편집자 1' or '정식편집자 2' or '종합관리자 3')
$_SESSION['user_type'] = ( empty($_SESSION['user_name']) ? '일반사용자' : $_SESSION['user_name'] );
# db 설정
include_once "../base_utils/db_conn.php";
// 이로부터 db 접속 성공의 결과로써, $dbi 변수가 넘어옴
# 공통 함수 인클루드
include "./language_utils.php";
# 대상 언어 제한
$lang_arr = ['JS','PHP'];
# 전달변수 : find, lang, p
// 언어별 파라미터 전달
$cur_lang = $_REQUEST[lang];
if(empty($cur_lang)) $cur_lang = 'JS';
if (!in_array($cur_lang,$lang_arr)) exit ("{$cur_lang} : 확인된 언어 아님!!!"); // 해킹 방어
// 페이지 파라미터 전달
$cur_page = $_GET['p']; // 요청 페이지 번호
if ( !empty($cur_page) and !is_numeric($cur_page) ) exit ("{$cur_page} : 페이지 번호 아님"); // 해킹 방어
if ( empty($cur_page) ) $cur_page = 1;
// 머리글,바닥글 표출 유무
$bare = $_REQUEST[bare];
// 동작 종류
$act = $_REQUEST[act];
// 키워드명
$find = $_REQUEST[find];
// 용어해설 번호
$word_no = $_REQUEST[word_no];
# (편집자용) 추가 및 업데이트
/*
// 언어별 keyword 추가
if ($act == 'add' and !empty($find) and isset($_REQUEST[lang]) and $_SESSION[user_type] == '종합관리자') {
keyword_add ($find, $cur_lang, $dbi);
}
*/
// 주어진 키워드에 따라 각 소스를 찾아다니며 업데이트
if ($act == 'search' and !empty($find) and isset($_REQUEST[lang]) and $_SESSION[user_type] == '종합관리자') {
keyword_find_update($find, $cur_lang, $dbi);
}
/*
// 용어해설 번호 추가
if ($act == 'word_no_add' and !empty($word_no) and isset($_REQUEST[lang]) and $_SESSION[user_type] == '종합관리자') {
word_no_add($word_no, $find, $cur_lang, $dbi);
}
*/
# 소스 파일 정보 db 쿼리 => 배열화 ($files)
$query = "select fno,dir,filename,expr,run from src_files";
$result=mysqli_query($dbi, $query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
while ( $matched = mysqli_fetch_assoc($result) ) {
$files[$matched[fno]] = $matched;
}
# 스타일링
echo "<style>
* { font-size : 13px; }
#language td { padding:5px; }
table#language { border-collapse:collapse; border:1px gray solid; }
</style>";
# 자바스크립트
echo "<script type='text/javascript' src='../base_utils/common_utils.js' charset='UTF-8'></script>";
echo "<script type='text/javascript' src='./language.js' charset='UTF-8'></script>";
# 상단 제목줄
if (empty($bare)) {
// 상단 제목
$title = '언어별 소스 목록';
include "../base_utils/top_section.php";
// 구분선
echo "<hr style='clear:both;margin:5px 10px 20px;'>";
}
# 언어별 메뉴
echo "<form action='../language/language.php' method='post' style='margin:0 10px; 0'>"."\n";
foreach ($lang_arr as $value) {
if ($value == $cur_lang) {
echo "<input type='submit' class='lang_btn' name='lang' value='{$value}' style='margin:0 5px 0;font-weight:bold;background-color:#fbefef;'>";
} else {
echo "<input type='submit' class='lang_btn' name='lang' value='{$value}' style='margin:0 5px 0;'>";
}
}
echo "</form>"."\n";
# 페이지 상태 설정
// 페이지 구분 관련 함수 라이브러리 호출
include "../paging/paging_utils.php";
// 페이지 당 출력 레코드 수
$page_records = 10;
// 전체 레코드 수 계산
$query = "select keyword,lang,word_no,file_no_list from lang_keyword where lang='$cur_lang'";
$total_records = total_records ($query, $dbi);
// 페이지 정보 함수 호출을 위한 매개변수 배열화
$page_info_vars = array (
'total_records' => $total_records, // 전체 레코드 수
'cur_page' => $cur_page, // 현재 페이지 번호
'page_records' => $page_records // 페이지 당 출력 레코드 수
);
# 페이지 정보 표출
echo "<div style='margin:10px 10px 10px;'>";
// 페이지 정보 안내
$pages = page_info ( $page_info_vars );
$total_pages = $pages['total_pages'];
$start_record = $pages['start_record'];
// 페이지 이동 안내
echo "<br>";
page_display ($cur_page, $total_pages, "?lang={$cur_lang}&");
echo "<br>";
echo "</div>";
# 언어별 키워드 정보 db 쿼리 => 배열화 ($array)
$query = "select keyword,lang,word_no,file_no_list from lang_keyword where lang='$cur_lang' order by lang,keyword";
$query = $query . " limit $start_record, $page_records";
$result=mysqli_query($dbi, $query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
while ( $matched = mysqli_fetch_assoc($result) ) {
$array[$matched[lang]][] = $matched;
}
# table 형식으로 보여주기
echo "<table id='language' border=1 style='margin:10px;'>";
echo "<thead>";
echo "<tr>";
echo "<th>키워드</th>";
echo "<th>해설</th>";
echo "<th>구현소스</th>";
if($_SESSION[user_type] == '종합관리자') echo "<th>편집</th>";
echo "</tr>";
echo "</thead>";
foreach($array[$cur_lang] as $key => $value) {
echo "<tr>";
// 키워드
echo "<td>";
echo $value[keyword];
echo "</td>";
// 용어해설
echo "<td style='white-space:nowrap;'>";
if (!empty($value[word_no])) {
$no_list = explode(',',$value[word_no]);
foreach($no_list as $no_out) {
echo "<a href='/test/view/view.php?no={$no_out}' target='_blank'>$no_out</a>";
echo " ";
}
}
// 해설번호 추가
if($_SESSION[user_type] == '종합관리자') {
echo " <a href='./language.php' class='no_add' data-act='word_no_add' data-lang='{$cur_lang}' data-find='{$value[keyword]}' data-p='{$cur_page}' style='text-decoration:underline;'>"."Add"."</a>";
}
echo "</td>";
// 구현 소스
echo "<td style='line-height:200%;'>";
if (!empty($value[file_no_list])) {
$fno_list = explode(',',$value[file_no_list]);
foreach($fno_list as $i => $fno) {
$dir = $files[$fno][dir];
$file = $files[$fno][filename];
$expr = $files[$fno][expr];;
echo "<a href='../open_src/view_src.php?dir={$dir}&file={$file}&find={$value[keyword]}' title='{$expr}'>$file</a>";
if (!empty($files[$fno][run])) echo " (<a href='../{$files[$fno][dir]}/{$files[$fno][filename]}' style='font-style:italic;'>run</a>)";
echo ( count($fno_list)-1 != $i ? ", " : "" );
}
}
echo "</td>";
if($_SESSION[user_type] == '종합관리자') {
echo "<td style='white-space:nowrap;'>";
echo "<a href='../language/language.php?act=search&find={$value[keyword]}&lang={$value[lang]}&p={$cur_page}' class='lang_edit' data-find='{$value[keyword]}'>편집</a>"." (".(substr_count($value[file_no_list],',')+1).")";
// 맨 마지막 줄이면,
if (count($array[$cur_lang])==($key+1)) {
echo "<br>";
echo " <a href='./language.php' class='no_add' data-act='keyword_add' data-lang='{$cur_lang}' data-p='{$cur_page}' style='text-decoration:underline;'>"."Keyword"."</a>";
/*
echo "<form method='post' action='./language.php' id='lang_add'>";
echo "<input type='text' name='find' value='' style='width:70px;'>";
echo "<input type='hidden' name='lang' value='{$value[lang]}'>";
echo "<input type='hidden' name='p' value='{$cur_page}'>";
echo "<input type='submit' name='act' value='add'>";
echo "</form>";
*/
}
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
# 하단 마무리
if (empty($bare)) {
echo "<br>";
// 구분선
echo "<hr style='clear:both;'>";
// 저작권
include "../base_utils/copyright.php";
// 소스 개방 메뉴
// include "../open_src/open.php"; // (소스이력 폴더별소스 ... )
// 구분선
echo "<hr>";
}
# 통계처리 요청 (stat_page)
include "../base_utils/stat_utils.php";
html_access('language.php',$dbi);
?>