<?php // (2018.7.17, 차재복, Cha Jae Bok, cjbword@gmailcom)
# db 미 연결이면 연결 시킴
if (empty($dbi)) {
include_once "../base_utils/config.php";
}
# db table => src_files 쿼리
function src_list_print($mid, $dbi) {
// 쿼리문
if(!empty($mid)) {
$query = "select c.id, c.module, d.fno, d.dir, d.filename, d.date, d.expr, if(c.exec_no=d.fno,0,1) as exec_seq
from
(select a.id,a.module,a.fno as exec_no,b.fno from example a left join run_map b on a.id=b.id where a.module is not null and a.id={$mid}) c left join src_files d on c.fno=d.fno
order by c.module, exec_seq, d.dir, d.filename";
} else {
$query = "select c.id, c.module, c.exec_no, d.fno, d.dir, d.filename, d.date, d.expr,
if(c.exec_no=d.fno,0,1) as exec_seq
from (select a.id, a.module, a.fno as exec_no, b.fno from example a left join run_map b on a.id=b.id where a.module is not null) c left join src_files d on c.fno=d.fno
order by c.module, exec_seq, d.dir, d.filename";
}
// 쿼리 실행
$result = mysqli_query($dbi,$query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
// 쿼리 결과 비었으면,
if (mysqli_num_rows($result) == 0) return;
// db 쿼리 결과를 php 배열化
while ( $matched = mysqli_fetch_assoc($result) ) {
if($key != $matched[module]) $key = $matched[module];
$files[$key][] = $matched;
$key = $matched[module];
}
// 현 상위 디렉토리 확인
$startdir = realpath('../');
// 테이블 형태로 소스 파일들을 보이기
echo "<table class='files' border='1' style='border-collapse: collapse;'>";
foreach($files as $key => $value) {
foreach($value as $row => $field) {
$row_num = count($value) + 2 ;
echo "<tr>";
// 첫칼럼이면, 모듈명
if($row==0) {
echo "<td rowspan={$row_num}>";
echo $key;
echo "</td>";
}
// 디렉토리명
echo "<td>";
echo "/".$field[dir];
echo "</td>";
// 소스 파일명 및 소스내용보기 링크
echo "<td>";
// 소스 파일명
echo "<a href='../open_src/view_src.php?file={$field[filename]}&dir={$field[dir]}'>";
echo $field[filename];
echo "</a>";
// 소스 파일 실행
if ($field[exec_no]==$field[fno])
echo " <a href='../{$field[dir]}/{$field[filename]}' style='text-decoration:underline;'>실행</a>";
echo "</td>";
// 소스 최종 수정일
echo "<td>";
// $date = date('Y-m-d', filemtime( $startdir . '/' . $field[dir] . '/' . $field[filename]) );
// echo " {$date} ";
echo date_format(date_create($field[date]),"Y-m-d") ;
echo "</td>";
// 소스 설명
echo "<td data-fno='{$field[fno]}'>";
// 소스 파일 간략설명 보기
echo $field[expr];
// 파일 설명 편집란
if (!empty($_SESSION[user_name])) {
echo "<br>";
echo "<input type='text' size='50' data-fno='{$field[fno]}' value='{$field[expr]}'>";
echo "<input type='submit' class='submit' data-id='{$field[id]}' data-fno='{$field[fno]}' data-act='update' value='submit'>";
}
echo "</td>";
// 편집자이면, 편집 링크
$style = ( empty($_SESSION[user_name]) ? "style='display:none;'" : "" );
echo "<td {$style}>";
echo " <a href='{$field[fno]}' class='file_expr_edit' data-fno='{$field[fno]}'>편집</a>";
echo "</td>";
echo "</tr>";
}
// 편집자이면, 파일 추가 란 보이기
echo "<tr>";
$style = ( empty($_SESSION[user_name]) ? "style='display:none;'" : "" );
echo "<td class='add_curdir' data-id='{$field[id]}' {$style} >/</td>";
echo "<td class='add_td' data-id='{$field[id]}' data-fno='' colspan='4' {$style} >";
// php scandir 함수에 의한 디렉토리먕,파일명 탐색하기
foreach( array_diff(scandir($startdir), array('..', '.','backup')) as $idx => $names) {
// 디렉토리이면,
if ( is_dir($startdir.'/'.$names) ) {
echo "["."<a href='' class='add' data-id='{$field[id]}' data-act='dir' data-name='{$names}' >{$names}</a>"."]";
// 파일이면,
} else {
// 불요 파일 걸러내기
if ( strpos($names,'.bak')===false ) {
echo "<a href='' class='add' data-id='{$field[id]}' data-act='file' data-name='{$names}'>{$names}</a>";
}
}
echo " ";
}
echo "</td>";
echo "</tr>";
// db 테이블 내용 보이기
echo "<tr>";
echo "<td colspan='5'>";
table_display ($field[module],$dbi);
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
# 테이블 구조 보여주는 함수 루틴
function table_display ($module, $dbi) {
// 모듈명, 테이블명, 필드명
$table_field = array( 'gubun_tree_v2' => array('parent','id','name','sub_seq'),
'editors' => array('user_id','user_pw','user_name'),
'example' => array('parent','id','name','sub_seq')
);
$module_table = array( 'example' => array('example','editors'),
'yoyak' => array('gubun_tree_v2'),
'search' => array('gubun_tree_v2'),
'view' => array('gubun_tree_v2'),
'login' => array('editors')
);
if ( array_key_exists($module,$module_table) ) {
$table_arr = $module_table[$module];
} else {
return;
}
// 관련 테이블 마다
foreach ($table_arr as $key => $tablename) {
// 테이블 설명 확인
$query = "describe {$tablename}";
$result = mysqli_query($dbi,$query);
if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
$fields = array();
while ($matched = mysqli_fetch_assoc($result)) {
if ( in_array($matched['Field'], $table_field[$tablename]) ) $fields[] = $matched;
}
echo "<table class='db_table'>";
echo "<tr>";
echo "<th>Tablename</th>";
echo "<th>Field</th>";
echo "<th>Type</th>";
echo "<th>Null</th>";
echo "<th>Key</th>";
echo "<th>Default</th>";
echo "<th>Extra</th>";
echo "</tr>";
foreach ($fields as $key => $value) {
echo "<tr>";
if($key==0) echo "<td rowspan='".count($fields)."'>{$tablename}</td>";
echo "<td>{$value['Field']}</td>";
echo "<td>{$value['Type']}</td>";
echo "<td>{$value['Null']}</td>";
echo "<td>{$value['Key']}</td>";
echo "<td>{$value['Default']}</td>";
echo "<td>{$value['Extra']}</td>";
echo "</tr>";
}
echo "</table>";
}
}
?>