001002003004005006007008009010011012013014015016017018019020021022023024025026027028029030031032033034035036037038039040041042043044045046047048049050051052053054055056057058059060061062063064065066067068069070071072073074075076077078079080081082083084085086087088089090091092093094095096097098099100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
<?php // (2020.10.23, 차재복, Cha Jae Bok, http://www.ktword.co.kr) // 코드 항목 신규 추가 function code_new_add($id, $dbi) { # code 테이블 // code id 중 빈 번호 확인 $query = "select a.id + 1 as available from code 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)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_id = $matched[available]; // code no 중 빈 번호 확인 $query = "select a.no + 1 as available from code a left join code b on b.no = (a.no + 1) where b.no is null order by a.no limit 0,1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_no = $matched[available]; // code 신규 id,no 삽입 $query = "insert into code (no,id,id_seq,id_name,date) values ($available_no,$available_id,1,'임시',now())"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } # reform 테이블 // reform 테이블의 날짜 업데이트 $query = "update reform set date=now() where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } # reform_more 테이블 // reform_more 테이블의 현재 id에 more_type, more_ptr 업데이트 $query = "insert reform_more (id,more_type,more_ptr) values ($id,1,$available_id)"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 결과 리턴 if (empty($err_msg)) { if (mysqli_affected_rows($dbi) > 0){ $notice = "reform_more 테이블에 신규 코드 추가 성공"; } else { $notice = "reform_more 테이블에 신규 코드 추가 실패"; } } $return = array('err_msg'=>$err_msg,'notice'=>$notice); echo json_encode($return, JSON_UNESCAPED_UNICODE); } // 코드 항목 업데이트 function code_update($no, $str, $msg, $dbi, $table_name='code') { $str = mysqli_real_escape_string($dbi,$str); $query = "update $table_name set id_name='{$msg}',code='{$str}',date=now() where no={$no}"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} if (mysqli_affected_rows($dbi) > 0){ $query = "select id_name,code,date_format(date,'%Y-%m-%d') as date from $table_name where no={$no}"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) {echo mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n";} $matched = mysqli_fetch_assoc($result); $return = array('code'=>$matched[code],'date'=>$matched[date],'name'=>$matched[id_name]); echo json_encode($return, JSON_UNESCAPED_UNICODE); } else { echo false; } } // 메뉴얼 항목 업데이트 // if ($ch == 'man_update' and !empty($str) and !empty($msg) and is_numeric($no)) { function manual_update($no, $str, $msg, $dbi, $table_name='manual') { // 해킹 방어 $msg = trim($msg); $msg = mysqli_real_escape_string($dbi,$msg); $str = trim($str); $str = mysqli_real_escape_string($dbi,$str); $query = "update manual set id_name='{$msg}',txt='{$str}',date=now() where no={$no}"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } if (mysqli_affected_rows($dbi) > 0){ $query = "select id_name,txt,date_format(date,'%Y-%m-%d') as date from manual where no={$no}"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); } else { $err_msg = '업데이트 실패!'; } $return = array('err_msg'=>$err_msg,'code'=>$matched[txt],'date'=>$matched[date],'name'=>$matched[id_name]); echo json_encode($return, JSON_UNESCAPED_UNICODE); } // 메뉴얼 항목 삭제 function manual_delete($no, $id, $dbi) { $query = "select id_seq from manual where no=$no and id=$id limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $current_id_seq = $matched[id_seq]; $query = "update manual set id_seq=(id_seq-1) where id=$id and id_seq>$current_id_seq"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $query = "delete from manual where no=$no and id=$id limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 현재 id 산하 자식 없으면, reform_more 해당 레코드 삭제 $query = "select count(*) as cnt from manual where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $cnt = $matched[cnt]; if ($cnt < 1) { // reform_more 해당 레코드 삭제 $query = "delete from reform_more where more_type='2' and more_ptr=$id 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) < 1) $notice .= 'reform_more 1건 삭제 못함'; } $return = array('err_msg'=>$err_msg); echo json_encode($return, JSON_UNESCAPED_UNICODE); } // 메뉴얼 항목을 바로다음에 추가 function manual_insert($id, $no, $dbi) { // manual 현재 항목 세부정보 추출 $query = "select id,id_seq from manual where id=$id and no=$no limit 1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $cur_seq = $matched[id_seq]; $cur_id = $matched[id]; if( mysqli_num_rows($result) <= 0 ) { $err_msg .= "해당되는 항목 없음({$no})"; } else { // manual no 중 빈 번호 확인 $query = "select a.no + 1 as available from manual a left join manual b on b.no = (a.no + 1) where b.no is null order by a.no limit 0,1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_no = $matched[available]; // manual 직후 id_seq 부터 1씩 증가시킴 $query = "update manual set id_seq=(id_seq+1) where parent=$id and id_seq>$cur_seq"; $result = mysqli_query($dbi, $query); // manual 직후 항목 생성 $query = "insert into manual (no,id,id_seq,id_name,date) values ($available_no,$cur_id,$cur_seq+1,'임시',now())"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } } // 결과 JSON 송출 $return = array('err_msg'=>$err_msg,'no'=>$available_no,'name'=>'(임시)','date'=>date('Y-m-d'),'seq'=>($cur_seq+1)); echo json_encode($return, JSON_UNESCAPED_UNICODE); } // 메뉴얼 항목 신규 추가 function manual_new_add($id, $dbi) { # manual 테이블 // manual id 중 빈 번호 확인 $query = "select a.id + 1 as available from manual a left join manual 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)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_id = $matched[available]; // manual no 중 빈 번호 확인 $query = "select a.no + 1 as available from manual a left join manual b on b.no = (a.no + 1) where b.no is null order by a.no limit 0,1"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $available_no = $matched[available]; // manual 신규 id,no 삽입 $query = "insert into manual (no,id,id_seq,id_name,date) values ($available_no,$available_id,1,'임시',now())"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } # reform 테이블 // reform 테이블의 날짜 업데이트 $query = "update reform set date=now() where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // reform 테이블의 부모 id $query = "select parent from reform where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $parent_id = $matched[parent]; # reform_more 테이블 // reform_more 테이블의 현재 id에 more_type, more_ptr 업데이트 $query = "insert reform_more (id,more_type,more_ptr) values ($id,2,$available_id)"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } # 현재 Li 노드의 정보 // $currentParentInfo = nextParentChilds($parent_id, $dbi); $currentLiInfo = currentLiInfo($id, $dbi); $return = array('err_msg'=>$err_msg,'currentLiInfo'=>$currentLiInfo); echo json_encode($return, JSON_UNESCAPED_UNICODE); } // 메뉴얼 항목 끝에 추가 function manual_add($id, $ch, $sub_ch, $msg, $str, $dbi, $table_name='manual') { $title = mysqli_real_escape_string($dbi,$msg); $content = mysqli_real_escape_string($dbi,$str); // no 중 빈 번호 찾아냄 $query = "select a.no + 1 as available from {$table_name} a left join {$table_name} b on b.no = (a.no + 1) where b.no is null order by a.no limit 0,1"; $result=mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched=mysqli_fetch_assoc($result); // 텅 비었으면, $available_no = 1 (초기값) $available_no = ( empty($matched[available]) ? 1 : $matched[available] ); // 해당 id의 자식 최대 번호 알아보기 $query = "select max(id_seq) as max_id_seq from {$table_name} where id=$id"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } $matched = mysqli_fetch_assoc($result); $max_id_seq = $matched[max_id_seq] + 1; $query = "insert into {$table_name} (no,id,id_seq,id_name,txt,date) values ($available_no,$id,$max_id_seq,'{$title}','{$content}',now())"; $result = mysqli_query($dbi,$query); if (mysqli_errno($dbi)) { $err_msg .= mysqli_errno($dbi)." : ".mysqli_error($dbi)."\n"; } // 결과 리턴 if (mysqli_affected_rows($dbi) > 0){ $return = array('notice'=>'메뉴얼 항목 추가 성공 !!!'); } else { $return = array('err_msg'=>$err_msg.'메뉴얼 항목 추가 에러','notice'=>$query); } echo json_encode($return, JSON_UNESCAPED_UNICODE); } ?>