<?php
$sw = "move";
$bo_table_array = array('free_board', 'free_board2', 'free_board');
for($i=0;$i<count($bo_table_array);$i++){
$bo_table = $bo_table_array[$i]; //$bo_table = "free_board"; 대체
//이동 원래 코드
}
$write_table = $g5['write_prefix'] . $bo_table;
// 원본 파일 디렉토리
$src_dir = G5_DATA_PATH.'/file/'.$bo_table;
$save = array();
$save_count_write = 0;
$save_count_comment = 0;
$cnt = 0;
$sql = " select distinct wr_num,wr_2 from $write_table where date_format(wr_1, '%Y-%m-%d %H:%i') = date_format(now(), '%Y-%m-%d %H:%i')";
$result = sql_query($sql);
while ($row = sql_fetch_array($result))
{
$move_bo_table = $row['wr_2'];
if( $move_bo_table=="" ) continue;
$wr_num = $row['wr_num'];
// 취약점 18-0075 참고
$sql = "select * from {$g5['board_table']} where bo_table = '".sql_real_escape_string($move_bo_table)."' ";
$move_board = sql_fetch($sql);
// 존재하지 않다면
if( !$move_board['bo_table'] ) continue;
$move_write_table = $g5['write_prefix'] . $move_bo_table;
$src_dir = G5_DATA_PATH.'/file/'.$bo_table; // 원본 디렉토리
$dst_dir = G5_DATA_PATH.'/file/'.$move_bo_table; // 복사본 디렉토리
$count_write = 0;
$count_comment = 0;
$next_wr_num = get_next_num($move_write_table);
$sql2 = " select * from $write_table where wr_num = '$wr_num' order by wr_parent, wr_is_comment, wr_comment desc, wr_id ";
$result2 = sql_query($sql2);
while ($row2 = sql_fetch_array($result2))
{
// 게시글 추천, 비추천수
$wr_good = $wr_nogood = 0;
if ($sw == 'move' && $i == 0) {
$wr_good = $row2['wr_good'];
$wr_nogood = $row2['wr_nogood'];
}
$sql = " insert into $move_write_table
set wr_num = '$next_wr_num',
wr_reply = '{$row2['wr_reply']}',
wr_is_comment = '{$row2['wr_is_comment']}',
wr_comment = '{$row2['wr_comment']}',
wr_comment_reply = '{$row2['wr_comment_reply']}',
ca_name = '".addslashes($row2['ca_name'])."',
wr_option = '{$row2['wr_option']}',
wr_subject = '".addslashes($row2['wr_subject'])."',
wr_content = '".addslashes($row2['wr_content'])."',
wr_link1 = '".addslashes($row2['wr_link1'])."',
wr_link2 = '".addslashes($row2['wr_link2'])."',
wr_link1_hit = '{$row2['wr_link1_hit']}',
wr_link2_hit = '{$row2['wr_link2_hit']}',
wr_hit = '{$row2['wr_hit']}',
wr_good = '{$wr_good}',
wr_nogood = '{$wr_nogood}',
mb_id = '{$row2['mb_id']}',
wr_password = '{$row2['wr_password']}',
wr_name = '".addslashes($row2['wr_name'])."',
wr_email = '".addslashes($row2['wr_email'])."',
wr_homepage = '".addslashes($row2['wr_homepage'])."',
wr_datetime = now(),
wr_file = '{$row2['wr_file']}',
wr_last = '{$row2['wr_last']}',
wr_ip = '{$row2['wr_ip']}'";
sql_query($sql);
$insert_id = sql_insert_id();
// 새글 INSERT
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$move_bo_table}', '{$insert_id}', '{$insert_id}', '".G5_TIME_YMDHIS."', '{$row2['mb_id']}' ) ");
// 코멘트가 아니라면
if (!$row2['wr_is_comment'])
{
$save_parent = $insert_id;
$sql3 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row2['wr_id']}' order by bf_no ";
$result3 = sql_query($sql3);
for ($k=0; $row3 = sql_fetch_array($result3); $k++)
{
if ($row3['bf_file'])
{
// 원본파일을 복사하고 퍼미션을 변경
// 제이프로님 코드제안 적용
$copy_file_name = ($bo_table !== $move_bo_table) ? $row3['bf_file'] : $row2['wr_id'].'_copy_'.$insert_id.'_'.$row3['bf_file'];
@copy($src_dir.'/'.$row3['bf_file'], $dst_dir.'/'.$copy_file_name);
@chmod($dst_dir.'/'.$row3['bf_file'], G5_FILE_PERMISSION);
}
$sql = " insert into {$g5['board_file_table']}
set bo_table = '$move_bo_table',
wr_id = '$insert_id',
bf_no = '{$row3['bf_no']}',
bf_source = '".addslashes($row3['bf_source'])."',
bf_file = '$copy_file_name',
bf_download = '{$row3['bf_download']}',
bf_content = '".addslashes($row3['bf_content'])."',
bf_filesize = '{$row3['bf_filesize']}',
bf_width = '{$row3['bf_width']}',
bf_height = '{$row3['bf_height']}',
bf_type = '{$row3['bf_type']}',
bf_datetime = '{$row3['bf_datetime']}' ";
sql_query($sql);
if ($sw == 'move' && $row3['bf_file'])
$save[$cnt]['bf_file'][$k] = $src_dir.'/'.$row3['bf_file'];
}
$count_write++;
if ($sw == 'move' && $i == 0)
{
// 스크랩 이동
sql_query(" update {$g5['scrap_table']} set bo_table = '$move_bo_table', wr_id = '$save_parent' where bo_table = '$bo_table' and wr_id = '{$row2['wr_id']}' ");
// 최신글 이동
sql_query(" update {$g5['board_new_table']} set bo_table = '$move_bo_table', wr_id = '$save_parent', wr_parent = '$save_parent' where bo_table = '$bo_table' and wr_id = '{$row2['wr_id']}' ");
// 추천데이터 이동
sql_query(" update {$g5['board_good_table']} set bo_table = '$move_bo_table', wr_id = '$save_parent' where bo_table = '$bo_table' a