<?php
	require("../__common__/__define_common.php");
	require("../__common__/include-common-all.php");
	require("__include-common-code-file.php");
	my_session_start();
	require("../account/__logincheck.php");
	if ($_SESSION['システム管理者'] <> "YES") {
		exit;
	}
	if ($_GET['ret'].'' == '') {
		$ret_php = 'code-file-view.php';
	} else {
		$ret_php = $_GET['ret'];
	}
	if ($_GET['path'].'' == '') {
		header("Location: ".$ret_php."?path=".urlencode(up_folder_path($src_file)));
	}
	$src_file = $_GET['path'];
	$src_file_SJIS = mb_convert_encoding($src_file, 'SJIS-win', 'UTF-8');
	if (file_exists($src_file_SJIS)) {
		$copy_file_SJIS = copy_file_name($src_file);
		if (@copy($src_file_SJIS, $copy_file_SJIS) == False) {
			error_simple_html('ファイルコピーエラー', 'ファイル['.$src_file.']のコピーに失敗しました。');
		}
	}
	header("Location: ".$ret_php."?path=".urlencode(up_folder_path($src_file)));
function copy_file_name($src_file, $num='') {
	$pos = strrpos($src_file, '.');
	$copy_file = substr($src_file, 0, $pos).'-COPY'.strval($num).substr($src_file, $pos);
	$copy_file_SJIS = mb_convert_encoding($copy_file, 'SJIS-win', 'UTF-8');
	if (file_exists($copy_file_SJIS)) {
		if ($num == '') $num = 0;
		$copy_file_SJIS = copy_file_name($src_file, ++$num);
	}
	return $copy_file_SJIS;
}
?>
