001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
<?php // (2022.9.13, 차재복, Cha Jae Bok, http://www.ktword.co.kr) # 세션 설정 // 세션 스타트 (매 웹페이지 마다 필요) session_start(); // 세션 변수에 따른 사용자 타입 설정 ('일반사용자' or '테스트편집자' or '정식편집자' or '종합관리자') $_SESSION['user_type'] = ( empty($_SESSION['user_name']) ? '일반사용자' : $_SESSION['user_name'] ); # 편집 권한 확인 if ($_SESSION['user_type']!='종합관리자') { echo json_encode(array('err_msg'=>'편집권한없음!'), JSON_UNESCAPED_UNICODE); exit; } // ('일반사용자' or '테스트편집자' or '정식편집자' or '종합관리자') # db 접속 (dbi) include_once "../base_utils/db_conn.php"; # 전송 입력 매개변수 $type = $_POST['type']; $type = trim($type); $choice = $_REQUEST['choice']; //$_POST['choice']; $choice = trim($choice); $subtype = $_POST['subtype']; $subtype = trim($subtype); $no = $_POST['no']; if ( isset($_REQUEST['no']) and !empty($no) and !is_numeric($no) or $no<0 ) exit('잘못된 update no'); // 해킹방지 (no>0) $id = $_REQUEST['id']; if ( isset($_REQUEST['id']) and !empty($id) and !is_numeric($id) or $id<0 ) exit('잘못된 update id'); // 해킹방지 (id>0) $msg = $_POST['msg']; // name(title), parent $msg = trim($msg); $text = $_POST['text']; // yoyak(desc), content, current $text = trim($text); # 전송 매개변수에 따라, 해당 update 함수 호출 if($choice == 'word_gubun_name_yoyak_update' or $choice == 'source_name_expr_update' or $choice == 'manual_name_yoyak_update' or $choice == 'word_titlename_yoyak_update') { // update 함수 호출 title_yoyak_update($choice, $id, $no, $msg, $text, $dbi); } else if($choice == 'db_tbl_fld_comment_update') { db_tbl_fld_comment_update($id, $no, $text, $dbi); } else if($choice == 'treeNodeCheck' and $type == 'word') { include_once "naviUpdate_utils.php"; treeNodeCheck($id, $dbi); // 체크 대상 : path2node, depth, child, linkedNum } else if($choice == 'wordEditUpdate') { wordEditUpdate ($id, $no, $text, $dbi); } else if($choice == 'deleteWordUpdate') { deleteWordUpdate ($id, $no, $dbi); } else if($choice == 'sourceFileUpdate') { include_once "naviUpdate_source.php"; sourceFileUpdate ($id, $dbi); } else if($choice == 'addSrcFile') { include_once "naviUpdate_source.php"; $parent = $msg; $current = $text; addSrcFile($parent, $current, $dbi); } else if($choice == 'deleteSrcFile') { include_once "naviUpdate_source.php"; deleteSrcFile($id, $no, $dbi); } else if($choice == 'editSrcFileFetch') { include_once "naviUpdate_source.php"; editSrcFileFetch($id, $dbi); } else if($choice == 'editSrcFileUpdate') { include_once "naviUpdate_source.php"; editSrcFileUpdate($id, $msg, $dbi); } else { echo json_encode( array('err_msg'=>'해당되는 choice 없음'), JSON_UNESCAPED_UNICODE); } // (디버깅용) //echo json_encode(array('err_msg'=>"type=$type, id=$id, msg=$msg, text=$text"), JSON_UNESCAPED_UNICODE); # 해당 id의 name 및 yoyak 업데이트 function title_yoyak_update($choice, $id, $no, $msg, $text, $dbi) { // $choice에 따라, 다른 테이블, 필드명, where절 적용 if($choice == 'word_gubun_name_yoyak_update') { $table_name = 'gubun_tree_v2'; $name_fld = 'name'; $where = "id={$id}"; } else if($choice == 'source_name_expr_update') { $table_name = 'src_files_v3'; $name_fld = 'name'; $where = "id={$id}"; } else if($choice == 'manual_name_yoyak_update') { $table_name = 'reform'; $name_fld = 'name'; $where = "id={$id}"; } else if($choice == 'word_titlename_yoyak_update') { $table_name = 'book_idx'; $name_fld = 'titlename'; $where = "tree_id={$id} and no={$no}"; } else return; // 해킹 방어 $name = mysqli_real_escape_string($dbi,$msg); $yoyak = mysqli_real_escape_string($dbi,$text); // name,yoyak 입력 문자열의 비정상 처리 if($name==='undefined' and $yoyak==='undefined') exit('입력 문자열 오류'); if($name==='undefined' and $yoyak!=='undefined') $set = "yoyak='{$yoyak}'"; if($name!=='undefined' and $yoyak==='undefined') $set = "{$name_fld}='{$name}'"; if($name!=='undefined' and $yoyak!=='undefined') $set = "{$name_fld}='{$name}',yoyak='{$yoyak}'"; // name, yoyak 교체 쿼리 // $query = "update {$table_name} set name='{$name}',yoyak='{$yoyak}' where id={$id} limit 1"; $query = "update {$table_name} set {$set} where {$where} limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // db 처리 결과의 에러 유무에 따라 판단 수행 if (!empty($err_msg)){ $return = array('err_msg'=>$err_msg .' : 업데이트 실패'); } else { if (mysqli_affected_rows($dbi) > 0){ $return = array('notice'=>'업데이트 성공 !!!','title'=>$msg,'desc'=>$text); } else { $return = array('notice'=>'업데이트 안함'); } } // 송출 echo json_encode($return, JSON_UNESCAPED_UNICODE); } /* # 해당 no의 title_name 및 yoyak 업데이트 function word_titlename_yoyak_update($id, $no, $msg, $text, $dbi) { $table_name = 'book_idx'; // 해킹 방어 $name = mysqli_real_escape_string($dbi,$msg); $yoyak = mysqli_real_escape_string($dbi,$text); // name,yoyak 입력 문자열의 비정상 처리 if($name==='undefined' and $yoyak==='undefined') exit('입력 문자열 오류'); if($name==='undefined' and $yoyak!=='undefined') $set = "yoyak='{$yoyak}'"; if($name!=='undefined' and $yoyak==='undefined') $set = "titlename='{$name}'"; if($name!=='undefined' and $yoyak!=='undefined') $set = "titlename='{$name}',yoyak='{$yoyak}'"; // titlename,yoyak 교체 쿼리 $query = "update {$table_name} set titlename='{$name}',yoyak='{$yoyak}' where no={$no} and tree_id={$id} limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // db 처리 결과의 에러 유무에 따라 판단 수행 if (!empty($err_msg)){ $return = array('err_msg'=>$err_msg .' : 업데이트 실패'); } else { if (mysqli_affected_rows($dbi) > 0){ $return = array('notice'=>'업데이트 성공 !!!','title'=>$msg,'desc'=>$text); } else { $return = array('notice'=>'업데이트 안함'); } } // 송출 echo json_encode($return, JSON_UNESCAPED_UNICODE); } */ # function db_tbl_fld_comment_update($id, $no, $text, $dbi) { // id: db table 번호, no : field 번호, text : comment // $return = array('err_msg'=>'id='.$id.', no='.$no.', text='.$text); if(!empty($_SESSION['db_name'])) $db_name = $_SESSION['db_name']; else $db_name = 'test'; $query = "select (@row_number:=@row_number + 1) as id, table_name as name, table_comment as yoyak, '1' as child, 'table' as item_type from (select @row_number:=0) as t, information_schema.tables where table_schema='{$db_name}'"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } while ( $matched = mysqli_fetch_assoc($result) ) { if($matched['id']==$id) { $yoyak = mysqli_real_escape_string($dbi,$text); // table if(empty($no)) { $query = "alter table {$matched['name']} comment='{$yoyak}'"; $update = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $return = array('desc'=>$text); // field } else { $query = "select (@row_number:=@row_number + 1) as id, column_name, column_type from (select @row_number:=0) as t, information_schema.columns where table_name = '{$matched['name']}' and table_schema = '{$db_name}' order by column_name"; $sub_result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } while ( $column = mysqli_fetch_assoc($sub_result) ) { if($no == $column[id]) { $query = "alter table {$matched['name']} modify {$column['column_name']} {$column['column_type']} comment '{$text}'"; $column_result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $return = array('desc'=>$text); } } } } } // 송출 echo json_encode($return, JSON_UNESCAPED_UNICODE); } function wordEditUpdate($id, $no, $text, $dbi) { $pure_abbr = mysqli_real_escape_string($dbi, $text); // abbr 변환 include_once '../navigation/naviStrTransform.php'; $trans_abbr = string_transform($text, $dbi, $no); // 링크 대체되지 않은 (변환되지 않은) 원래 abbr 업데이트 $query = "update cjb_dict set abbr='{$pure_abbr}' where no={$no} limit 1"; $result = mysqli_query($dbi, $query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 요약(synopsis) 업데이트 $synopsis = synopsis_extract($pure_abbr); $query = "update cjb_dict set synopsis='{$synopsis}' where no=$no limit 1"; $result = mysqli_query($dbi, $query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // abbr 변환 후 dict_anchor 업데이트 $escaped_abbr = mysqli_real_escape_string($dbi,$trans_abbr); $query = "update dict_anchor set abbr='{$escaped_abbr}' where no={$no} limit 1"; $result = mysqli_query($dbi, $query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 정상 업데이트 여부 확인 if (mysqli_affected_rows($dbi) <= 0) $err_msg .= "\n dict_anchor abbr 텍스트가 업데이트 되지는 않았음 (기존과 동일)"; // 결과 송출 include_once '../navigation/naviFetch_utils.php'; ajaxFetchDetailSeparate($no, $dbi, $err_msg); } function deleteWordUpdate ($parent_id, $child_no, $dbi) { // prepare_sql 함수 include_once "naviUpdate_utils.php"; // book_idx에서 해당 no 삭제 $query = "delete from book_idx where tree_id=? and no=? limit 1"; include_once "naviUpdate_utils.php"; $resultArr = prepare_sql($dbi, $query, 'ii', array($parent_id,$child_no)); if(mysqli_stmt_affected_rows($resultArr['stmt'])<=0) $err_msg .= 'book_idx에서 해당 no 삭제 실패'; // 부모 node의 child,linked_num 계산 해주기 if(empty($err_msg)) { $query = "update gubun_tree_v2 set child = (@linked_num:=(select count(*) from book_idx where tree_id=?)) + (select count(*) from gubun_tree_v2 where parent=?), linked_num = @linked_num where id=? limit 1"; $resultArr = prepare_sql($dbi, $query, 'iii', array($parent_id,$parent_id,$parent_id)); if(mysqli_stmt_affected_rows($resultArr['stmt'])<=0) $err_msg .= '부모 node의 child,linked_num 계산 실패'; } // book_idx에서 seq 다시 계산 if(empty($err_msg)) { mysqli_query($dbi,"select 0 into @num"); $query = "update book_idx set list_ord=@num:=(@num+1) where tree_id=? order by list_ord"; $resultArr = prepare_sql($dbi, $query, 'i', array($parent_id)); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } } // 송출 $return = array('err_msg'=>$err_msg); echo json_encode($return, JSON_UNESCAPED_UNICODE); } function moveAfterNode($dbi){ } ?>