소스 파일 : /open_src/open_src_files_utils.php (2018-07-17)     소스 설명 : (소스개방) 소스 온라인 보기 함수 루틴
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?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 "&nbsp;&nbsp; <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 " &nbsp; <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 " &nbsp; ";
					}
				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>";
	}

}

?>


Copyrightⓒ written by 차재복 (Cha Jae Bok)
"본 웹사이트 내 모든 저작물은 원출처를 밝히는 한 자유롭게 사용(상업화포함) 가능합니다"