001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
<?php // (2019.5.27, 차재복, Cha Jae Bok, http://www.ktword.co.kr) # 세션 스타트 (매 웹페이지 마다 필요) session_start(); # db 연결 및 html 헤더부 include_once "../base_utils/db_conn.php"; # 전달 변수 처리 $act = $_REQUEST[act]; $act = mb_substr($act,0,16,'utf-8'); // 해킹 방지 (글자 수 제한) $id = $_REQUEST[id]; if ( isset($_REQUEST[id]) and !empty($id) and !is_numeric($id) or $id<0 ) exit; // 해킹방지 (수치>0) $id = substr($id,0,10); // 해킹 방지 (글자 수 제한) if(empty($id)) $id=0; // 디폴트 $tid = $_REQUEST[tid]; if ( isset($_REQUEST[tid]) and !empty($tid) and !is_numeric($tid) or $tid<0 ) exit; // 해킹방지 (수치>0) $tid = substr($tid,0,10); // 해킹 방지 (글자 수 제한) $no = $_REQUEST[no]; if ( isset($_REQUEST[no]) and !empty($no) and !is_numeric($no) or $no<0 ) exit; // 해킹방지 (수치>0) $no = substr($no,0,10); // 해킹 방지 (글자 수 제한) $no_list = $_REQUEST[no_list]; $no_list = substr($no_list,0,30); // 해킹 방지 (글자 수 제한) $no_arr = explode(',',$no_list); if ($no_ar.length > 0) { foreach($no_arr as $key=>$value) { if( !is_numeric($value) or $value<=0 ) { // no_list 비어있거나 음수 !!!' return; } } } $str = trim($_REQUEST[str]); $str = mysqli_real_escape_string($dbi,$str); $str = mb_substr($str,0,50,'utf-8'); // 해킹 방지 (글자 수 제한) $str = trim(strip_tags($str)); $str = str_replace(' ',' ',$str); $str = str_replace(array('\\', "\0", "\n", "\r", "\x1a"), '', $str); // echo "act=".$act.", id=".$id.", tid=".$tid.", no=".$no.", no_list=".$no_list.", str=".$str."<br>"; # 항목별 업데이트 선택 // id 타이틀명칭 업데이트 if ( $act=='id_rename' and is_numeric($id) and empty($no) and !empty($str) ) id_str_update($id, $str, $dbi, 'gubun_tree_v2', 'name'); // id 요약설명 업데이트 if ( $act=='id_desc_update' and is_numeric($id) and empty($no) and !empty($str) ) id_str_update($id, $str, $dbi, 'gubun_tree_v2', 'yoyak'); // no 타이틀명칭 업데이트 if ( $act=='no_rename' and is_numeric($id) and is_numeric($no) and !empty($str) ) no_str_update($id, $no, $str, $dbi, 'book_idx', 'titlename'); // no 요약설명 업데이트 if ( $act=='no_desc_update' and is_numeric($id) and is_numeric($no) and !empty($str) ) no_str_update($id, $no, $str, $dbi, 'book_idx', 'yoyak'); // id 노드 위 아래로 이동 if ( ($act=='id_up' or $act=='id_down') and is_numeric($id) ) id_move_updown($act, $id, $dbi, 'gubun_tree_v2'); // no 노드 위 아래로 이동 if ( ($act=='no_up' or $act=='no_down') and is_numeric($id) and is_numeric($no) ) no_move_updown($act, $id, $no, $dbi, 'book_idx'); // id 자식 노드 생성 if ( $act=='id_child' and is_numeric($id) and !empty($str) ) gen_child($id, $str, $dbi, 'gubun_tree_v2'); // id 직전 및 직후 노드 생성 if ( ( $act=='id_prepend' or $act=='id_append' ) and is_numeric($id) and !empty($str) ) gen_before_after($act, $id, $str, $dbi, 'gubun_tree_v2'); // id 직후 노드 생성 // if ( $act=='id_append' and is_numeric($id) and !empty($str) ) gen_after($id, $str, $dbi, 'gubun_tree_v2'); // id 노드 삭제 if ( $act=='id_delete' and is_numeric($id) ) delete_id($id, $dbi, 'gubun_tree_v2'); // no 노드 삭제 if ( $act=='no_delete' and is_numeric($id) and is_numeric($no) ) delete_no($id, $no, $dbi, 'book_idx'); // echo $act. ' ' . $id . ' ' .$no; // 자식 노드 이동 if ( $act=='move_child' and is_numeric($id) and is_numeric($tid) ) move_child($id, $tid, $dbi, 'gubun_tree_v2'); // 직전 노드 이동 if ( $act=='move_before' and is_numeric($id) and is_numeric($tid) ) move_before($id, $tid, $dbi, 'gubun_tree_v2'); // 직후 노드 이동 if ( $act=='move_after' and is_numeric($id) and is_numeric($tid) ) move_after($id, $tid, $dbi, 'gubun_tree_v2'); // 다수 용어항목 분류 지정 (no_designate) if ( $act=='no_designate' and is_numeric($tid) ) no_designate($no_arr, $id, $tid, $dbi, 'book_idx'); // 다수 용어항목 분류 변경 (no_change) if ( $act=='no_change' and is_numeric($tid) ) no_change($no_arr, $id, $tid, $dbi, 'book_idx'); # 업데이트 형태별 함수 정의 // id 타이틀명칭 또는 요약설명 업데이트 function id_str_update($id, $name, $dbi, $table_name, $field_name) { // update $query = "update {$table_name} set {$field_name}='{$name}' where id=$id"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 업데이트 결과 select $query = "select $field_name from {$table_name} where id=$id"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } if ( $matched=mysqli_fetch_assoc($result) ) { echo $matched[name]; } } // no 타이틀명칭 또는 요약설명 업데이트 function no_str_update($id, $no, $name, $dbi, $table_name, $field_name) { // update $query = "update {$table_name} set {$field_name}='{$name}' where tree_id=$id and no=$no"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 업데이트 결과 select $query = "select $field_name from {$table_name} where tree_id=$id and no=$no"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } if ( $matched=mysqli_fetch_assoc($result) ) { echo $matched[name]; } } // ---------------------------------------------------- // id 노드 위 아래로 이동 function id_move_updown($act, $id, $dbi, $table_name) { // 선택 id의 parent,sub_seq 알아보기 $result = mysqli_query($dbi,"select parent,sub_seq from {$table_name} where id=$id"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $parent = $matched[parent]; $sub_seq = $matched[sub_seq]; if ($act == 'id_up') { $near_offset = "(sub_seq+1)"; // 직전 id를 하향 이동 $where_offset = "($sub_seq-1)"; // 직전 id $self_offset = "($sub_seq-1)"; // 해당 id를 상향 이동 } else if ($act == 'id_down') { $near_offset = "(sub_seq-1)"; // 직후 id를 상향 이동 $where_offset = "($sub_seq+1)"; // 직후 id $self_offset = "($sub_seq+1)"; // 해당 id를 하향 이동 } // 직전 또는 직후 id를 하향 이동 mysqli_query($dbi,"update {$table_name} set sub_seq={$near_offset} where parent=$parent and sub_seq={$where_offset}"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} if ( mysqli_affected_rows($dbi) >= 1 ) { // 해당 id를 상향 또는 하향 이동 mysqli_query($dbi,"update {$table_name} set sub_seq={$self_offset} where id=$id"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } echo "상향 또는 하향 이동 성공"; // 해당 노드의 path2node, depth 업데이트 path_depth_update ($id, $dbi); } else { echo "처음 또는 끝이라서 이동 없음"; } } // no 노드 위 아래로 이동 function no_move_updown($act, $id, $no, $dbi, $table_name) { // 일단 소팅하고, 번호 연속적으로 새로 매기기 mysqli_query($dbi,"set @rank:=0"); mysqli_query($dbi,"update {$table_name} set list_ord = @rank := @rank+1 where tree_id=$id order by list_ord,titlename"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 선택 no 항목의 순서번호 알아보기 $result = mysqli_query($dbi,"select list_ord from {$table_name} where tree_id=$id and no=$no"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $cur_list_ord = $matched[list_ord]; // (no_up) if ( $act == 'no_up' ) { // 직전 것을 하향 이동 mysqli_query($dbi,"update {$table_name} set list_ord=(list_ord+1) where tree_id=$id and list_ord=($cur_list_ord-1)"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // (no_up) 자신을 상향 이동 mysqli_query($dbi,"update {$table_name} set list_ord=($cur_list_ord-1) where tree_id=$id and no=$no and list_ord=($cur_list_ord)"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } } else if ( $act == 'no_down' ) { // (no_down) 직후 것을 상향 이동 mysqli_query($dbi,"update {$table_name} set list_ord=(list_ord-1) where tree_id=$id and list_ord=($cur_list_ord+1)"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // (no_up) 자신을 하향 이동 mysqli_query($dbi,"update {$table_name} set list_ord=(list_ord+1) where tree_id=$id and no=$no and list_ord=($cur_list_ord)"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } } } // ---------------------------------------------------- // id 자식 노드 생성 function gen_child($id, $str, $dbi, $table_name) { // 해당 id의 자식 존재 및 자식 최대수(번호) 알아보기 $query = "select * from {$table_name} where parent=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } if( !($max_sub_seq = mysqli_num_rows($result)) ) { $max_sub_seq = 1; } else { $max_sub_seq = $max_sub_seq + 1; } // id 중 빈 번호 찾아냄 $query = "select a.id + 1 as available from {$table_name} a left join {$table_name} b on b.id = (a.id + 1) where b.id is null order by a.id limit 0,1"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched=mysqli_fetch_assoc($result); // 텅 비었으면, $available_id = 1 $available_id = ( empty($matched[available]) ? 1 : $matched[available] ); // 자식 분류항목 새로이 삽입 $query = "insert into {$table_name} (id,parent,sub_seq,name) values ($available_id,$id,$max_sub_seq,'{$str}')"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 자식 노드 생성 항목에 path2node, depth 업데이트 path_depth_update ($available_id, $dbi); } // id 직전 및 직후 노드 생성 function gen_before_after($act, $id, $str, $dbi, $table_name) { // 해당 id의 부모,순서번호를 알아냄 $query = "select parent,sub_seq from {$table_name} where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched=mysqli_fetch_assoc($result); $parent = $matched[parent]; if ( $act == 'id_prepend' ) { $sub_seq = $matched[sub_seq] ; } else if ( $act == 'id_append' ) { $sub_seq = $matched[sub_seq] + 1 ; } // 해당 id 부터 1씩 증가시킴 $query = "update {$table_name} set sub_seq=(sub_seq+1) where parent=$parent and sub_seq>=$sub_seq"; $result = mysqli_query($dbi,$query); // id 중 빈 번호 확인 $query = "select a.id + 1 as available from {$table_name} a left join {$table_name} b on b.id = (a.id + 1) where b.id is null order by a.id limit 0,1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_id = $matched[available]; // 분류항목 새로이 삽입 $query = "insert into {$table_name} (id,parent,sub_seq,name) values ($available_id,$parent,$sub_seq,'{$str}')"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 직후 노드 생성 항목에 path2node, depth 업데이트 path_depth_update ($available_id, $dbi); } /* // id 직후 노드 생성 function gen_after($id, $str, $dbi, $table_name) { // 해당 id의 부모,순서번호를 알아냄 $query = "select parent,sub_seq from {$table_name} where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched=mysqli_fetch_assoc($result); $parent = $matched[parent]; $sub_seq = $matched[sub_seq]; // 해당 id 직후부터 1씩 증가시킴 $query = "update {$table_name} set sub_seq=(sub_seq+1) where parent=$parent and sub_seq>=($sub_seq+1)"; $result = mysqli_query($dbi,$query); // id 중 빈 번호 확인 $query = "select a.id + 1 as available from {$table_name} a left join {$table_name} b on b.id = (a.id + 1) where b.id is null order by a.id limit 0,1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_id = $matched[available]; // 분류항목 새로이 삽입 $query = "insert into {$table_name} (id,parent,sub_seq,name) values ($available_id,$parent,$sub_seq+1,'{$str}')"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 직후 노드 생성 항목에 path2node, depth 업데이트 $delay_echo .= path_depth_update ($available_id, $dbi); } */ // ---------------------------------------------------- // id 노드 삭제 function delete_id($id, $dbi, $table_name) { // 선택 id의 parent,sub_seq 알아보기 $query = "select a.parent,a.sub_seq ,count(b.id) as sub_cnt from {$table_name} a left join {$table_name} b on a.id=b.parent where a.id=$id group by a.id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $parent = $matched[parent]; $sub_seq = $matched[sub_seq]; $sub_cnt = $matched[sub_cnt]; // 하부 id 있으면, 삭제 불가 if ($sub_cnt > 0) return; // 해당 id를 삭제 mysqli_query($dbi,"delete from {$table_name} where id=$id"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 삭제 성공하면, 직후 id들을 하나씩 상향 이동 if ( mysqli_affected_rows($dbi) >= 1 ) { mysqli_query($dbi,"update {$table_name} set sub_seq=(sub_seq-1) where parent=$parent and sub_seq>=($sub_seq+1)"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} } } // no 노드 삭제 function delete_no($id, $no, $dbi, $table_name) { // 해당 용어항목 순서를 알아냄 $query = "select list_ord from {$table_name} where tree_id=$id and no=$no limit 1"; $result = mysqli_query($dbi,$query); $row = mysqli_fetch_assoc($result); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 해당 용어항목 직후부터 순서번호 모두 1씩 감함 $query = "update {$table_name} set list_ord=(list_ord-1) where tree_id=$id and list_ord>$row[list_ord]"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 해당 용어항목 순서번호 삭제 $query = "delete from {$table_name} where tree_id=$id and no=$no limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 해당 분류에 속한 용어들 갯수 update $query = "update gubun_tree_v2 set linked_num=(select count(*) from {$table_name} where tree_id=$id) where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} } // ---------------------------------------------------- // 직후 노드 이동 function move_after($source, $target, $dbi, $table_name) { // 소스쪽 이동 항목을 발췌하면, 나머지 항목 부번호들은 1씩 감해짐 $query = "update {$table_name} a left join (select parent,sub_seq from {$table_name} where id=$source) b on a.parent=b.parent set a.sub_seq=(a.sub_seq-1) where a.sub_seq>b.sub_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 타깃 항목의 부모,부번호를 알아냄 $query = "select parent,sub_seq from {$table_name} where id=$target"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $matched=mysqli_fetch_assoc($result); $parent = $matched[parent]; $sub_seq = $matched[sub_seq]; // 타킷 항목 이후 부번호들을 1씩 증가시킴 $query = "update {$table_name} set sub_seq=(sub_seq+1) where parent=$parent and sub_seq>$sub_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 소스 항목을 타킷 항목에 맞춰 수정(이동) $query = "update {$table_name} set parent=$parent,sub_seq=($sub_seq+1) where id=$source"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 이동된 항목에 path2node, depth 업데이트 path_depth_update ($source, $dbi); } // 직전 노드 이동 function move_before($source, $target, $dbi, $table_name) { // 소스쪽 이동 항목을 발췌하면, 나머지 항목 부번호들은 1씩 감해짐 $query = "update {$table_name} a left join (select parent,sub_seq from {$table_name} where id=$source) b on a.parent=b.parent set a.sub_seq=(a.sub_seq-1) where a.sub_seq>b.sub_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 타깃 항목의 부모,부번호를 알아냄 $query = "select parent,sub_seq from {$table_name} where id=$target"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $matched=mysqli_fetch_assoc($result); $parent = $matched[parent]; $sub_seq = $matched[sub_seq]; // 타킷 항목부터 부번호들을 1씩 증가시킴 $query = "update {$table_name} set sub_seq=(sub_seq+1) where parent=$parent and sub_seq>=$sub_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 소스 항목을 타킷 항목에 맞춰 수정(이동) $query = "update {$table_name} set parent=$parent,sub_seq=($sub_seq) where id=$source"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 이동된 항목에 path2node, depth 업데이트 path_depth_update ($source, $dbi); } // 자식 노드 이동 function move_child($source, $target, $dbi, $table_name) { // 소스쪽 이동 항목을 발췌하면, 나머지 항목 부번호들은 1씩 감해짐 $query = "update {$table_name} a left join (select parent,sub_seq from {$table_name} where id=$source) b on a.parent=b.parent set a.sub_seq=(a.sub_seq-1) where a.sub_seq>b.sub_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 타킷 항목의 하부 자식번호 중 최대 알아내기 $query = "select ifnull(max(sub_seq),0)+1 as max_num from {$table_name} where parent=$target"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $matched=mysqli_fetch_assoc($result); $max_num = $matched[max_num]; // 소스 항목을 타킷 항목의 하부 자식으로 수정(이동) $query = "update {$table_name} set parent=$target,sub_seq=$max_num where id=$source"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 이동된 항목에 path2node, depth 업데이트 path_depth_update ($source, $dbi); } // 다수의 용어해설항목을 한꺼번에 분류 변경 (no_change) function no_change($no_arr, $id, $tid, $dbi, $table_name) { // 여러 소스 no들을 ','로 구분 $no_list = implode(',',$no_arr); // 현재 target_id에서 list_ord 중 최대값 구하기 mysqli_query($dbi,"select @max:=max(list_ord) from {$table_name} where tree_id=$tid"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 추출된 no들의 id를 target_id로 바꾸고, list_ord 업데이트 $query = "update {$table_name} a inner join ( select no,tree_id,@max:=@max+1 as list_ord from {$table_name} where tree_id=$id and no in ($no_list) ) b on (a.tree_id=b.tree_id and a.no=b.no) set a.tree_id=$tid,a.list_ord=b.list_ord "; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // source_id 분류에 속한 용어들 갯수 update $query = "update gubun_tree_v2 set linked_num=(select count(*) from {$table_name} where tree_id=$id) where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // target_id 분류에 속한 용어들 갯수 update $query = "update gubun_tree_v2 set linked_num=(select count(*) from {$table_name} where tree_id=$tid) where id=$tid"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} } // 다수의 용어해설항목을 한꺼번에 분류 변경 (no_designate) function no_designate($no_arr, $id, $tid, $dbi, $table_name) { // 여러 소스 no들을 ','로 구분 $no_list = implode(',',$no_arr); // echo "no_list=".$no_list.", id=".$id.", tid=".$tid.", tabl_name=".$table_name."<br>"; // 이미 분류되어진 것 있는가 여부를 체크 후 분류 작업 "; $result=mysqli_query($dbi,"select * from $table_name where no in ($no_list) and tree_id=$tid"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} if ( mysqli_num_rows($result) == 0 ) { // 현재 list_ord 중 최대값 구하기 mysqli_query($dbi,"select @max:=max(list_ord) from $table_name where tree_id=$tid"); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} // 전달된 다수 no들을 해당 분류 id에 지정 $query = "insert into $table_name (no,tree_id,titlename,list_ord) ( select no,{$tid} as tree_id,word,@max:=@max+1 as list_ord from dict_word_list where no in ({$no_list}) group by no ) "; // and wordtype='k' $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} if ( mysqli_affected_rows($dbi)>=1) { // 해당 분류에 속한 용어들 갯수 update $query = "update gubun_tree_v2 set linked_num=(select count(*) from $table_name where tree_id=$tid) where id=$tid"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} } } else { echo "이미 해당 tid에 기존 no가 있으므로, no_designate 실패<br>"; } } ?> <?php // path2node, depth 업데이트 함수 function path_depth_update ($id, $dbi) { $query = "update gubun_tree_v2 set path2node=concat(';0;;',replace(substring_index(getpath_v2(id),'|',-1),'::',';;'),';'), path2node_v2=concat('0,',replace(substring_index(getpath_v2(id),'|',-1),'::',',')), depth=round( ( length(path2node) - length(replace(path2node,';;','')) )/length(';;') ) where id=".$id; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} } ?>