<?php
	require("../__common__/__define_common.php");
	require("../__common__/include-common-all.php");
	require("__define_code-file.php");
	require("__include-common-code-file.php");
	my_session_start();
	require("../account/__logincheck.php");
	if ($_SESSION['システム管理者'] <> "YES") {
		exit;
	}
	if ($_POST['保存']) {
		post_done_proc();
		exit();
	}
	if ($_GET['path'].'' == '') {
		exit;
	}
	$open_path = my_GET('path');
	$file_mode = file_check_get_text($open_path, $path_SJIS, $source_text, $source_encode, $file_type, $error_msg);
	if ($file_mode == 'Error') {
		error_simple_html('ソースコード編集エラー', $error_msg);
	}
	if ($file_mode <> 'File') {
		exit;
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="ja">
<head>
<meta http-equiv="Content-Language" content="ja">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta name="author" content="ok.2nd">
<meta name="description" content="PHP/JavaScriptソースコードエディタ">
<meta name="keywords" content="ソースコード編集,ソースコード整形表示,syntax,highlight,css">
<style type="text/css">
/* * {margin: 0px; padding: 0px; } */
/*	↓ input 除く */
body, div, img, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, textarea, p, blockquote, th, td, caption {
	margin: 0; 
	padding: 0;
}
input {
	margin: 0;
}
input[type="submit"] {
	background-color: #e0e0e0;
}
input[type="reset"] {
	background-color: #e0e0e0;
}
input[type="button"] {
	background-color: #e0e0e0;
}
button {
	background-color: #e0e0e0;
}
textarea,input,select,button {
	font-family: "ＭＳ Ｐゴシック",arial,helvetica,clean,sans-serif;
	line-height: 1.3;
	*line-height: 1.0;
	font-size: 100%;
}
form { margin: 0px; }
img { border: 0px; }
body {
	background-color: #ffffff;
	margin: 5px;
	padding: 0px;
	text-align: left;
}
h2 { font-size: 120%; }
a { text-decoration: underline; font-weight: normal; }
a:link { color: #0000ff; }
a:visited { color: #0000ff; }
a:hover { color: #ff0000; }
a:active { color: #ff0000; }
body { font-size: 80%;}
body,td,a,p,.h {font-family: arial,sans-serif; }
.error_msg { color: red; margin: 20px; padding: 0; }
div#header {
	margin: 10px;
}
div#body {
	margin: 0px;
}
div#footer {
	margin: 10px;
}
p#file_name_box {
	margin: 2px 0 0 0;
}
span#file_name {
	text-decoration: underline;
	background-color: #e0f0ff;
	border: 0px;
	padding: 1px 4px 1px 4px;
}
span#file_encode {
	background-color: #fff0e0;
	border: 0px;
	padding: 1px 4px 1px 4px;
}
</style>
<!--
Powered by http://www.cdolivet.net/editarea/
-->
<script language="Javascript" type="text/javascript" src="scripts/editarea/edit_area/edit_area_full.js"></script>
<script language="Javascript" type="text/javascript">
<!--
editAreaLoader.init({
	id: "src_code"
	,start_highlight: true
	,allow_resize: "both"
	,allow_toggle: true
	,language: "ja"
	,font_size: 9
	,syntax: "<?= file_type_ea_syntax($file_type) ?>"
	,toolbar: "fullscreen, |, search, go_to_line, |, undo, redo, |, select_font, |, syntax_selection, |, change_smooth_selection, highlight, reset_highlight, |, help"
	,syntax_selection_allow: "html,php,js,css,sql,xml"
});
-->
</script>
<script language="JavaScript">
<!--
function submitCheck() {
	if (window.confirm('保存しますか？')) {
		return true;
	} else {
		//window.alert('キャンセルされました。');
		return false;
	}
}
-->
</script>
<script language="javascript" src="../scripts/encodeURL.js" type="text/javascript"></script>
<title>PHP/JavaScript ソースコード編集</title>
</head>
<body>
<div id="body">
	<form name="edit" method="POST" action="<?= $_SERVER['SCRIPT_NAME'] ?>?<?= $_SERVER['QUERY_STRING'] ?>" onSubmit="return submitCheck(this)">
	<p id="file_name_box">ファイル：<span id="file_name"><?= filename_bold_in_path($open_path) ?></span>
	&nbsp;文字コード：<span id="file_encode"><?= $source_encode ?></span></p>
	<input class="input_form_button" type="submit" name="保存" value="　保存　">&nbsp;&nbsp;
	<?php
		if ($_GET['ret'] == 'up') {
			$qry = 'path='.urlencode(up_folder_path(my_GET('path')));
		} else {
			$qry = $_SERVER['QUERY_STRING'];
		}
	?>
	<input type="button" name="" value="保存しないで戻る" onClick="location.href='code-file-view.php?<?= $qry ?>'">
	<input type="hidden" name="file_name" value="<?= $open_path ?>">
	<input type="hidden" name="source_encode" value="<?= $source_encode ?>">
	<fieldset>
	<textarea id="src_code" style="height: <?= CODE_FILE_VIEW_EDIT_TEXTAREA_HEIGHT ?>; width: 100%;" name="src_text"><?= my_htmlspecialchars_notrim($source_text) ?></textarea>
	</fieldset>
	<input class="input_form_button" type="submit" name="保存" value="　保存　">
</form>
</div>
<div id="footer">
<a href="http://www.cdolivet.net/editarea/" target="_blank" style="color:#b0b0ff;">Powered by EditArea</a><br />
<a href="http://ok2nd.web.fc2.com/" target="_blank" style="color:#b0b0ff;">Powered by ok.2nd</a>
</div>
</body>
</html>
<?php
function post_done_proc() {
	if ($_POST['source_encode'] == 'UTF-8') {
		file_put_contents(myfile_ENCODE($_POST['file_name']),
				stripcslashes($_POST['src_text']));
	} elseif ($_POST['source_encode'] == 'SJIS-win') {
		file_put_contents(myfile_ENCODE($_POST['file_name']),
				myfile_ENCODE(stripcslashes($_POST['src_text'])));
	}
	if ($_GET['ret'] == 'up') {
		$qry = 'path='.urlencode(up_folder_path(my_GET('path')));
	} else {
		$qry = $_SERVER['QUERY_STRING'];
	}
	header("Location: code-file-view.php?".$qry);
}
?>
