This commit is contained in:
Amberstone 2024-10-05 05:55:03 +09:00
parent d352c730f5
commit 7b9597da2d
Signed by: amber
GPG key ID: 094B0E55F98D8BF1

View file

@ -1,29 +1,46 @@
<?php
$sub_menu = '300100';
include_once "./_common.php";
require_once './_common.php';
auth_check($auth[$sub_menu], 'w');
check_demo();
auth_check_menu($auth, $sub_menu, 'w');
check_admin_token();
$target_table = trim($_POST['target_table']);
$target_subject = trim($_POST['target_subject']);
$bo_table = isset($_POST['bo_table']) ? substr(preg_replace('/[^a-z0-9_]/i', '', $_POST['bo_table']), 0, 20) : null;
$target_table = isset($_POST['target_table']) ? trim($_POST['target_table']) : '';
$target_subject = isset($_POST['target_subject']) ? trim($_POST['target_subject']) : '';
$target_subject = strip_tags(clean_xss_attributes($target_subject));
$file_copy = [];
if (empty($bo_table)) {
alert("원본 테이블 정보가 없습니다.");
}
if (!preg_match('/[A-Za-z0-9_]{1,20}/', $target_table)) {
alert('게시판 TABLE명은 공백없이 영문자, 숫자, _ 만 사용 가능합니다. (20자 이내)');
}
$target_table = substr(preg_replace('/[^a-z0-9_]/i', '', $target_table), 0, 20);
// 게시판명이 금지된 단어로 되어 있으면
if ($w == '' && in_array($target_table, get_bo_table_banned_word())) {
alert('입력한 게시판 TABLE명을 사용할수 없습니다. 다른 이름으로 입력해 주세요.');
}
$row = sql_fetch(" select count(*) as cnt from {$g5['board_table']} where bo_table = '$target_table' ");
if ($row['cnt'])
if ($row['cnt']) {
alert($target_table . '은(는) 이미 존재하는 게시판 테이블명 입니다.\\n복사할 테이블명으로 사용할 수 없습니다.');
}
// 게시판 테이블 생성
$sql = get_table_define($g5['write_prefix'] . $bo_table);
$sql = str_replace($g5['write_prefix'] . $bo_table, $g5['write_prefix'] . $target_table, $sql);
sql_query($sql, false);
$file_copy = [];
// 구조만 복사시에는 공지사항 번호는 복사하지 않는다.
if ($copy_case == 'schema_only') {
$board['bo_notice'] = '';
@ -136,8 +153,9 @@ $copy_file = 0;
if ($copy_case == 'schema_data_both') {
$d = dir(G5_DATA_PATH . '/file/' . $bo_table);
while ($entry = $d->read()) {
if ($entry == '.' || $entry == '..')
if ($entry == '.' || $entry == '..') {
continue;
}
// 김선용 201007 :
if (is_dir(G5_DATA_PATH . '/file/' . $bo_table . '/' . $entry)) {
@ -145,8 +163,9 @@ if ($copy_case == 'schema_data_both') {
@mkdir(G5_DATA_PATH . '/file/' . $target_table . '/' . $entry, G5_DIR_PERMISSION);
@chmod(G5_DATA_PATH . '/file/' . $target_table . '/' . $entry, G5_DIR_PERMISSION);
while ($entry2 = $dd->read()) {
if ($entry2 == '.' || $entry2 == '..')
if ($entry2 == '.' || $entry2 == '..') {
continue;
}
@copy(G5_DATA_PATH . '/file/' . $bo_table . '/' . $entry . '/' . $entry2, G5_DATA_PATH . '/file/' . $target_table . '/' . $entry . '/' . $entry2);
@chmod(G5_DATA_PATH . '/file/' . $target_table . '/' . $entry . '/' . $entry2, G5_DIR_PERMISSION);
$copy_file++;
@ -160,6 +179,8 @@ if ($copy_case == 'schema_data_both') {
}
$d->close();
run_event('admin_board_copy_file', $bo_table, $target_table);
// 글복사
$sql = " insert into {$g5['write_prefix']}$target_table select * from {$g5['write_prefix']}$bo_table ";
sql_query($sql, false);
@ -171,28 +192,34 @@ if ($copy_case == 'schema_data_both') {
sql_query($sql, false);
// 4.00.01
// 위의 코드는 같은 테이블명을 사용하였다는 오류가 발생함. (희한하네 ㅡㅡ;)
$sql = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' ";
$result = sql_query($sql, false);
for ($i = 0; $row = sql_fetch_array($result); $i++)
for ($i = 0; $row = sql_fetch_array($result); $i++) {
$file_copy[$i] = $row;
}
}
if (count($file_copy)) {
for ($i = 0; $i < count($file_copy); $i++) {
$sql = "INSERT INTO {$g5['board_file_table']}
set bo_table = '$target_table',
wr_id = '{$file_copy[$i]['wr_id']}',
bf_no = '{$file_copy[$i]['bf_no']}',
bf_source = '" . addslashes($file_copy[$i]['bf_source']) . "',
bf_file = '{$file_copy[$i]['bf_file']}',
bf_download = '{$file_copy[$i]['bf_download']}',
bf_content = '" . addslashes($file_copy[$i]['bf_content']) . "',
bf_filesize = '{$file_copy[$i]['bf_filesize']}',
bf_width = '{$file_copy[$i]['bf_width']}',
bf_height = '{$file_copy[$i]['bf_height']}',
bf_type = '{$file_copy[$i]['bf_type']}',
bf_datetime = '{$file_copy[$i]['bf_datetime']}' ";
$file_copy[$i] = run_replace('admin_copy_update_file', $file_copy[$i], $file_copy[$i]['bf_file'], $bo_table, $target_table);
$sql = " insert into {$g5['board_file_table']}
set bo_table = '$target_table',
wr_id = '{$file_copy[$i]['wr_id']}',
bf_no = '{$file_copy[$i]['bf_no']}',
bf_source = '" . addslashes($file_copy[$i]['bf_source']) . "',
bf_file = '{$file_copy[$i]['bf_file']}',
bf_download = '{$file_copy[$i]['bf_download']}',
bf_content = '" . addslashes($file_copy[$i]['bf_content']) . "',
bf_fileurl = '" . addslashes($file_copy[$i]['bf_fileurl']) . "',
bf_thumburl = '" . addslashes($file_copy[$i]['bf_thumburl']) . "',
bf_storage = '" . addslashes($file_copy[$i]['bf_storage']) . "',
bf_filesize = '{$file_copy[$i]['bf_filesize']}',
bf_width = '{$file_copy[$i]['bf_width']}',
bf_height = '{$file_copy[$i]['bf_height']}',
bf_type = '{$file_copy[$i]['bf_type']}',
bf_datetime = '{$file_copy[$i]['bf_datetime']}' ";
sql_query($sql, false);
}
}
@ -202,4 +229,4 @@ delete_cache_latest($target_table);
echo "<script>opener.document.location.reload();</script>";
alert("복사에 성공 했습니다.", './board_copy.php?bo_table=' . $bo_table . '&amp;' . $qstr);
alert("복사에 성공 했습니다.", G5_ADMIN_URL . '/board_copy.php?bo_table=' . $bo_table . '&amp;' . $qstr);