소스 파일 : /reform/reform_update.php (2020-12-19)     소스 설명 : (개선중) 항목별 업데이트 시행
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php // (2020.12.19, 차재복, Cha Jae Bok, http://www.ktword.co.kr) 

# 세션 설정
	// 세션 스타트 (매 웹페이지 마다 필요)
	session_start();

	// 세션 변수에 따른 사용자 타입 설정 ('일반사용자' or '테스트편집자' or '정식편집자' or '종합관리자')
	$_SESSION['user_type'] = ( empty($_SESSION['user_name']) ? '일반사용자' : $_SESSION['user_name'] );
	session_start();

	// 세션 변수에 따른 사용자 타입 설정 ('일반사용자' or '테스트편집자' or '정식편집자' or '종합관리자')
	$_SESSION['user_type'] = ( empty($_SESSION['user_name']) ? '일반사용자' : $_SESSION['user_name'] );

# 편집 권한 확인
	if ($_SESSION['user_type']!='종합관리자') exit;
	// ('일반사용자' or '테스트편집자' or '정식편집자' or '종합관리자')


# db 접속
	include "../base_utils/db_conn.php";


# 전송 입력 매개변수
	$no = $_POST['no'];
		if ( isset($_REQUEST[no]) and !empty($no) and !is_numeric($no) or $no<0 ) exit; // 해킹방지 (수치>0)

	$id = $_REQUEST['id'];
		if ( isset($_REQUEST[id]) and !empty($id) and !is_numeric($id) or $id<0 ) exit; // 해킹방지 (수치>0)

	$msg = $_POST['msg'];	// title
		$msg = trim($msg);

	$str = $_POST['text'];	// content
		$str = trim($str);

	$ch = $_POST['ch'];

	$sub_ch = $_POST['sub_ch'];

	// 디버깅용
//	echo 'ch='.$ch.', sub_ch='.$sub_ch.', id='.$id.', str='.$str;


# 항목 이동 갱신
	include "reform_move_update.php";				// 항목 이동 
		// id_move_updown(),id_first_last(),id_level_up(),id_level_down(),id_delete() 등

	// id 노드 항목 이동
		// id 노드 위 아래로 이동
		if ( ($ch=='id_up' or $ch=='id_down') and is_numeric($id) )
			id_move_updown($ch, $id, $dbi, 'reform');
		// id 노드 맨 위로 이동
		if ( ($ch=='id_first' or $ch=='id_last') and is_numeric($id) )
			id_first_last($ch, $id, $dbi, 'reform');
		// id 노드 레벨업 이동
		if ( ($ch=='id_level_up') and is_numeric($id) ) 
			id_level_up($ch, $id, $dbi, 'reform');
		// id 노드 레벨다운 이동
		if ( ($ch=='id_level_down') and is_numeric($id) ) 
			id_level_down($ch, $id, $dbi, 'reform');


# 항목 생성 및 삭제
	include "reform_gen_del_update.php";			// 항목 생성 및 삭제 

	// id 자식,직전,직후 노드 생성
		if ( ($ch=='id_child') and is_numeric($id) and !empty($str) )
			id_child ($id, $str, $dbi, $table_name='reform');

		if ( ($ch=='id_prepend' || $ch=='id_append') and is_numeric($id) and !empty($str) )
			id_prepend_append ($ch, $id, $str, $dbi, $table_name='reform');

	// id 노드 삭제
		if ( $ch=='id_delete' and is_numeric($id) )  
			id_delete($ch, $id, $dbi, 'reform');


# 타이틀,요약 갱신
		// 타이틀 업데이트
		if ( ($ch=='id_title_update') and is_numeric($id) and !empty($sub_ch))
			id_title_update($ch, $sub_ch, $id, $str, $dbi, 'reform');
		// 요약 업데이트
		if ( ($ch=='id_yoyak_update' ) and is_numeric($id) and !empty($sub_ch)) 
			id_yoyak_update($ch, $sub_ch, $id, $str, $dbi, 'reform');


# 메뉴얼 갱신
	include "reform_man_update.php";		// 메뉴얼 업데이트 
		// id_move_updown(),id_first_last(),id_level_up(),id_level_down(),id_delete() 등

	// 코드 업데이트
		// 코드 항목 업데이트
		if ($ch == 'code_update' and !empty($str) and !empty($msg) and is_numeric($no))
			code_update($no, $str, $msg, $dbi, 'code');
		// 코드 항목 신규 추가
		if ( ($ch=='id_more_new_add' and $sub_ch=='1') and is_numeric($id) )
			code_new_add($id,$dbi);

	// 메뉴얼 업데이트
		// 메뉴얼 항목 업데이트
		if ($ch == 'man_update' and !empty($str) and !empty($msg) and is_numeric($no))
			manual_update($no, $str, $msg, $dbi, 'manual');
		// 메뉴얼 항목 삭제
		if ($ch == 'man_delete' and is_numeric($no) and is_numeric($id))
			manual_delete($no, $id, $dbi);
		// 메뉴얼 항목 바로다음에 추가
		if ($ch == 'man_insert' and is_numeric($no) and is_numeric($id) )
			manual_insert($id, $no, $dbi);
		// 메뉴얼 항목 신규 추가
		if ( ($ch == 'id_more_new_add' and $sub_ch=='2') and is_numeric($id) )
			manual_new_add($id,$dbi);
		// 메뉴얼 항목 끝에 추가
		if ( ($ch == 'man_update' ) and ($sub_ch=='add') and is_numeric($id) ) 
			manual_add($id, $ch, $sub_ch, $msg, $str, $dbi, 'manual');


# title,yoyak 수정 #

// 해당 id의 name(title) 업데이트
function id_title_update($ch, $sub_ch, $id, $str, $dbi, $table_name) {

	// 순수 타이틀명 교체
	if ($sub_ch == '1') {
		// 링크화된 타이틀명은 빈칸으로 교체
		$query = "update $table_name set name_2nd = '' where id={$id}";
		$result = mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; }

		// 순수 타이틀명 교체
		$name_str = mysqli_real_escape_string($dbi,$str);
		$query = "update $table_name set name='{$name_str}',date=now() where id={$id}";
		$result = mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; }

	// 링크화된 타이틀명 교체
	} else if ($sub_ch == '2') {
		include "file_transform_v2.php";
		
		$translated_str = string_transform($str, $dbi);
		$translated_str = mysqli_real_escape_string($dbi, $translated_str);
		$query = "update $table_name set name_2nd = '{$translated_str}' where id={$id}";
		$result = mysqli_query($dbi,$query);
			if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; }
	}

	if (!empty($err_msg)){
		$return = array('err_msg'=>$err_msg .' : 타이틀 업데이트 실패');
	} else {
		if (mysqli_affected_rows($dbi) > 0){
			$return = array('notice'=>'타이틀 업데이트 성공 !!!','title'=>$name_str);
//			'path2node'=>$path2node,'next_parent'=>$parent,'sub_seq'=>$sub_seq,'nextParentChilds'=>$nextParentChilds);
		} else {
			$return = array('notice'=>'타이틀 업데이트 안함');
		}
	}

	echo json_encode($return, JSON_UNESCAPED_UNICODE);

}


// 요약 업데이트
function id_yoyak_update($ch, $sub_ch, $id, $str, $dbi, $table_name) {

	if ($sub_ch == '2') {
		include "file_transform_v2.php";
		$translated_str = string_transform($str, $dbi);
	} else {
		$translated_str = $str;
	}

	$translated_str = mysqli_real_escape_string($dbi, $translated_str);

	$query = "update $table_name 
				set yoyak='{$str}', yoyak_2nd='{$translated_str}', date=now() where id={$id}";
	$result = mysqli_query($dbi, $query);
		if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; }

	if (!empty($err_msg)){
		$return = array('err_msg'=>$err_msg .' : 타이틀 요약 업데이트 실패');
	} else {
		if (mysqli_affected_rows($dbi) > 0){
			$return = array('notice'=>'타이틀 요약 업데이트 성공 !!!','yoyak'=>$str,'yoyak_2nd'=>$translated_str);
		} else {
			$return = array('notice'=>'타이틀 요약 업데이트 안함');
		}
	}

	echo json_encode($return, JSON_UNESCAPED_UNICODE);

}


// cuurnet Li 정보
function currentLiInfo($id, $dbi) {
	$query = "select a.parent,a.id,a.sub_seq,a.name,a.name_2nd,
						a.path2node,a.child,a.yoyak,
						b.more_type,b.more_subtype,b.more_ptr,b.dir,b.file,b.func
						from reform a left join reform_more b on a.id=b.id 
						where a.id={$id} order by a.sub_seq";
	$result = mysqli_query($dbi,$query);
		if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";}
	while ($matched = mysqli_fetch_assoc($result)) {
		$title = ( empty($matched[name_2nd]) ? $matched[name] : $matched[name_2nd] );
		$data = 
			array('id'=>$matched[id], 'parent'=>$matched[parent], 'sub_seq'=>$matched[sub_seq],
					'title'=>$title, 'title_orig'=>$matched[name],
					'path2node'=>$matched[path2node], 'child'=>$matched[child], 'yoyak'=>$matched[yoyak],
					'more_type'=>$matched[more_type], 'more_subtype'=>$matched[more_subtype],
					'more_ptr'=>$matched[more_ptr], 'dir'=>$matched[dir], 'file'=>$matched[file], 'func'=>$matched[func]
				 );
	} 
	return	$data;
}

?>


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