<?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 (FILE_MANAGER_ID_PASSWORD_USE == 'YES') {
		require("../id-manager/__include-im-login.php");
		require("../id-manager/im-logincheck.php");
	}
	if (!defined("CODE_FILE_VIEW_EDIT_DEFAULT_FOLDER")) {
		define("CODE_FILE_VIEW_EDIT_DEFAULT_FOLDER", $_SERVER['DOCUMENT_ROOT']);
	}
	if ($_POST['path'].'' <> '') {
		$open_path = form_str_filepath($_POST['path']);
	} elseif ($_GET['path'].'' <> '') {
		$open_path = my_GET('path');
	}
	$open_path = str_replace(DIRECTORY_SEPARATOR, "/", right_slash_strip($open_path));
	if ($open_path == "") {
		$open_path = CODE_FILE_VIEW_EDIT_DEFAULT_FOLDER;
	}
	if (isset($_POST['search_key']) && $_POST['search_key'].'' <> '') {
		$_SESSION['code_view_search_key'] = $_POST['search_key'];
	} elseif ($_GET['key'].'' <> '') {
		$_SESSION['code_view_search_key'] = $_GET['key'];
	}
	if (isset($_POST['search_reset'])) {
		$_SESSION['code_view_search_key'] = '';
	}
	if ($_GET['uplow'].'' <> '') {
		$_SESSION['code_view_search_uplow'] = $_GET['uplow'];
	}
	if ($_GET['sort'].'' <> '') {
		$_SESSION['code_view_sort'] = $_GET['sort'];
	}
	if ($_GET['order'].'' <> '') {
		$_SESSION['code_view_sort_order'] = $_GET['order'];
	}
	$file_mode = file_check_get_text($open_path, $path_SJIS, $source_text, $source_encode, $file_type, $error_msg);
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="author" content="ok.2nd">
<meta name="description" content="PHP/JavaScriptソースコード表示＆編集">
<meta name="keywords" content="ソースコード整形表示,ソースコード編集,syntax,highlight,css">
<link rel="stylesheet" href="<?= _STYLE_SHEET_FOLDER ?>/tools_common.css?20120406">
<style>
div#header {
	margin: 5px;
}
div#filemanager_body {
	margin: 0px;
}
html>/**/body #filemanager_body input[type="button"] {	/* IE以外 */
	padding: 0 2px;
	line-height: 1em;
}
#filemanager_body input[type="button"], x:-moz-any-link {	/* Firefox */
	height: 1.5em;
}
*+html #filemanager_body input[type="button"] {	/* IE */
	height: 1.5em;
}
*html #filemanager_body input[type="button"]) {	/* IE6 */
	height: 1.5em;
}
div#footer {
	margin: 5px;
}
div#print_dir {
	margin: 5px;
}
div#print_file {
	margin: 5px;
}
div#change_file_type {
	margin: 5px;
}
#selected_type {
	background-color: #ffc080;
}
.file_list {
	font-family: arial,sans-serif;
}
.file_list a:link { color: #101010; }
.file_list a:visited { color: #101010; }
.file_list a:hover { color: #ff0000; }
.file_list a:active { color: #ff0000; }
ul.file_list {
	margin: 10px 0 5px 10px;
}
td.file_list {
	padding-left: 10px;
}
td.file_size {
	padding: 1px 0 1px 10px;
	text-align: right;
}
td.file_time {
	padding: 1px 0 1px 10px;
}
th.file_list {
	padding-left: 34px;
	background-color: #e0e0ff;
}
th.file_size {
	padding: 1px 0 1px 10px;
	text-align: right;
	color: #101010;
	background-color: #e0e0ff;
}
th.file_time {
	padding: 1px 0 1px 10px;
	background-color: #e0e0ff;
}
th a:link { color: #101010; font-weight: bold;}
th a:visited { color: #101010; font-weight: bold;}
th a:hover { color: #ff0000; font-weight: bold;}
th a:active { color: #ff0000; font-weight: bold;}
a.edit_btn {
	margin: 0 2px 0 2px;
}
a.edit_btn:link  { color: #ff8000; font-weight: normal;}
a.edit_btn:visited { color: #ff8000; font-weight: normal;}
a.edit_btn:hover { color: #ff0000; font-weight: normal; background-color: #f0f0f0}
a.edit_btn:active { color: #ff0000; font-weight: normal; background-color: #e0e0e0}
.order_mark {
	font-size: 80%;
	color: #808080;
	padding-left: 2px;
}
.file_folder {
	background-image: url(icon/folder.gif);
	background-repeat: no-repeat;
	background-position: top left;
	list-style: none;
	list-style-type: none;
	margin: 2px 0 2px 0;
	padding-left: 24px;
	font-size: 16px;
}
.file_php {
	background-image: url(icon/php.png);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_py {
	background-image: url(icon/python.png);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_yaml {
	background-image: url(icon/python.png);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_js {
	background-image: url(icon/js.gif);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_html {
	background-image: url(icon/html.png);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_css {
	background-image: url(icon/css.gif);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_txt {
	background-image: url(icon/txt.gif);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_xml{
	background-image: url(icon/txt.gif);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.file_sql {
	background-image: url(icon/sql.gif);
	background-repeat: no-repeat;
	background-position: top left;
	padding-left: 24px;
	font-size: 16px;
}
.key_found {
	color: red;
	font-weight: bold;
}
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>
	<?php if ($file_mode == 'File') {	// **************** ?>
<style>
.dp-highlighter .my_search_key_class {
	color: red;
	font-weight: bold;
	background-color: #ffff00;
}
</style>
<!--
Powered by http://code.google.com/p/syntaxhighlighter/
Powered by http://bizcaz.com/archives/2007/04/11-220828.php
Powered by http://winofsql.jp/sh/html/syntax_highlighter.htm
-->
<link rel="stylesheet" href="scripts/dp.SyntaxHighlighter.winofsql/SyntaxHighlighter.css" />
<script src="scripts/dp.SyntaxHighlighter.winofsql/shCore.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushCss.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushPhp.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushPython.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/shBrushSql.js"></script>
<script src="scripts/dp.SyntaxHighlighter/Scripts/webscript.js"></script>
<script>
//	↓ Google Chromeでハングする。
//	window.onload = function() {
//	mykeyword = '<?= $_SESSION['code_view_search_key'] ?>!my_search_key_class!'
//	dp.SyntaxHighlighter.HighlightAll('src_code',true,false,null,null,null,mykeyword);
	window.onload = function() {
	dp.SyntaxHighlighter.HighlightAll('src_code', true, false);
}
</script>
<script>
function changeFileType_XXX(fileType) {
	// この方法ではハイライトコードがどんどん追記されてしまう。
	document.getElementById('code_view').className = fileType;
	dp.SyntaxHighlighter.HighlightAll('src_code', true, false);
}
</script>
<script src="../scripts/encodeURL.js"></script>
<script>
function changeFileType(fileType) {
	//url = "<?= $_SERVER['SCRIPT_NAME'] ?>?path=" + encodeURL(document.form0.path.value) + "&type=" + fileType;
	url = "<?= $_SERVER['SCRIPT_NAME'] ?>?path=" + encodeURL(document.getElementById('path').value) + "&type=" + fileType + "&key=<?= urlencode($_SESSION['code_view_search_key']) ?>";
	top.location.href = url;
}
</script>
	<?php }	else {			// **************** ?>
<link rel="stylesheet" href="../scripts/tablesorter/themes/blue/style-ok2nd.css">
<script src="../scripts/jquery.js"></script>
<script src="../scripts/jquery.cookie.js"></script>
<script>
$(function(){
	get_ajax_dir();
	get_ajax_file();
});
function get_ajax_dir() {
	$.ajax({
		type: "POST",
		url: "code-file-view-ajax.php?get=dir&path=<?= urlencode($open_path) ?>",
		async: false,
		success: function(res){
			$("#print_dir").html(res);
		}
	})
}
function get_ajax_file() {
	$.ajax({
		type: "POST",
		url: "code-file-view-ajax.php?get=file&path=<?= urlencode($open_path) ?>",
		async: false,
		success: function(res){
			$("#print_file").html(res);
			table_sort();
		}
	})
}
</script>
<script src="../scripts/tablesorter/jquery.tablesorter-ok2nd.js"></script>
<script src="../scripts/tablesorter/docs/js/chili/chili-1.8b.js"></script>
<script src="../scripts/tablesorter/docs/js/docs.js"></script>
<script id="js">
var tablesort_cookiename = 'code_file_view';
var sort_column = <?= $_COOKIE['code_file_view_sort_column']?$_COOKIE['code_file_view_sort_column']:0 ?>;
var sort_order = <?= $_COOKIE['code_file_view_sort_order']?$_COOKIE['code_file_view_sort_order']:0 ?>;
function table_sort() {
	$("#sorttable").tablesorter({
		sortList: [[sort_column,sort_order]],
		headers: { 1: {sorter:"currency"} }
	});
}
</script>
<script src="../scripts/URLencode.js"></script>
<script>
function rename_file(path, fname){
	fname = window.prompt("新しいファイル名を入れてください。", fname);
//	window.alert(fname);
	$.ajax({
		type: "POST",
		url: 'file-rename.php?path='+URLencode(path)+'&new='+URLencode(fname),
		async: false,
		success: function(res){
			get_ajax_file();
		}
	})
}
function copy_file(path){
	$.ajax({
		type: "POST",
		url: 'file-copy.php?path='+URLencode(path),
		async: false,
		success: function(res){
			get_ajax_file();
		}
	})
}
function delete_file(path){
	fname = path.substring(path.lastIndexOf('/')+1);
	if (window.confirm('ファイル「'+fname+'」を削除しますか？')) {
		$.ajax({
			type: "POST",
			url: 'file-delete.php?path='+URLencode(path),
			async: false,
			success: function(res){
				get_ajax_file();
			}
		})
	} else {
		//window.alert('キャンセルされました');
	}
}
function rename_folder(path, fname){
	fname = window.prompt("新しいフォルダ名を入れてください。", fname);
//	window.alert(fname);
	$.ajax({
		type: "POST",
		url: 'folder-rename.php?path='+URLencode(path)+'&new='+URLencode(fname),
		async: false,
		success: function(res){
			get_ajax_dir();
		}
	})
}
function copy_folder(path){
	$.ajax({
		type: "POST",
		url: 'folder-copy.php?path='+URLencode(path),
		async: false,
		success: function(res){
			get_ajax_dir();
		}
	})
}
function delete_folder(path){
	fname = path.substring(path.lastIndexOf('/')+1);
	if (window.confirm('フォルダ「'+fname+'」を削除しますか？')) {
		$.ajax({
			type: "POST",
			url: 'folder-delete.php?path='+URLencode(path),
			async: false,
			success: function(res){
				get_ajax_dir();
			}
		})
	} else {
		//window.alert('キャンセルされました');
	}
}
</script>
	<?php }				// **************** ?>
<title>PHP/JavaScript ソースコード表示</title>
</head>
<body>
<p id="tool_title_area">
<a href="../tools/" class="return_index">■</a>
<span id="tool_title">PHP/JavaScript ソースコード表示</span>
	<?php if ($file_mode == 'Folder') { ?>
<a style="margin-left:20px;" href="file-manager.php?path=<?= urlencode($open_path) ?>">→ ファイルマネージャー</a>
	<?php } ?>
</p>
<span style="margin-left:10px; color:Hotpink">ファイルは、php関連のテキストファイルのみを表示します。</span>
<div id="header">
	<script>
	function CheckboxUpLow(onOff) {
		if (onOff == 'on') {
			window.location.href = '<?= $_SERVER['SCRIPT_NAME'] ?>?uplow=off&path=<?= urlencode($open_path) ?>';
		} else {
			window.location.href = '<?= $_SERVER['SCRIPT_NAME'] ?>?uplow=on&path=<?= urlencode($open_path) ?>';
		}
	}
	</script>
	<form name="form0" action="<?= $_SERVER['SCRIPT_NAME'] ?>?type=<?= $_GET['type'] ?>" method="post">
		<input type="button" name="" value="↑" onClick="location.href='<?= $_SERVER['SCRIPT_NAME'] ?>?path=<?= urlencode(up_folder_path($open_path)) ?>'">
		<input class="text" type="text" id="path" name="path" value="<?= my_htmlspecialchars($open_path) ?>" size=60>
		<input type="submit" name="path_change" value="変更">
	<?php if ($file_mode == 'Folder') { ?>
		ファイル内文字：
		<input class="text<?= $_SESSION['code_view_search_key'] <> '' ? ' list_filter_true' : '' ?>" type="text" name="search_key" value="<?= my_htmlspecialchars($_SESSION['code_view_search_key']) ?>" size=10>
		<input type="submit" name="search" value="検索">
		<input type="submit" name="search_reset" value="リセット">
		<label><input type="checkbox" value="on" onClick="CheckboxUpLow('<?= $_SESSION['code_view_search_uplow'] ?>')"<?= $_SESSION['code_view_search_uplow'] == 'on' ? ' checked' : '' ?>>大/小文字区別</label>
		<br>
		<p id="file_name_box">フォルダ：<span><?= up_folder_direct('?path=', $open_path) ?></span>
	<?php } else { ?>
		<br>
		<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>
	<?php } ?>
	</form>
</div>
<div id="filemanager_body">
<?php
	if ($file_mode == 'Folder') {
		view_folder($open_path, $path_SJIS, $_SESSION['code_view_search_key']);
	} elseif ($file_mode == 'File') {
		view_code($open_path, $source_text, $file_type);
	} else {
		echo '<p class="error_msg">'.$error_msg.'</p>';
	}
?>
</div>
<div id="footer">
	<?php if ($file_mode == 'File') {	// **************** ?>
<a href="http://code.google.com/p/syntaxhighlighter/" target="_blank" style="color:#b0b0ff;">Powered by SyntaxHighlighter</a><br/>
	<?php }				// **************** ?>
<a href="http://ok2nd.web.fc2.com/" target="_blank" style="color:#b0b0ff;">Powered by ok.2nd</a>
</div>
</body>
</html>
<?php
function view_folder($open_path, $path_SJIS, $search_key) {
?>
	<div id="print_dir"></div>
	<div>
		<!-- <p style="margin: 5px 0 0 20px; color:red">※ IE6ではサイズが大きいファイルのソース表示で実行速度の警告が出ます。</p> -->
		<p style="margin: 0 0 5px 20px;">
		<input type="button" class="copy_button" value="Ｃ">：コピー
		<input type="button" class="copy_button" value="Ｒ">：リネーム
		<input type="button" class="copy_button" value="Ｄ">：削除
		</p>
	</div>
	<div id="print_file"></div>
<?php
}
function view_code($open_path, &$source_text, $file_type) {
	if ($_GET['type'].'' <> '') {
		$class = $_GET['type'];
	} else {
		$class = file_type_sh_class($file_type);
	}
?>
<div id="change_file_type">
	<input type="button" value="html" onClick="changeFileType('html')"<?= $class=='html' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="php" onClick="changeFileType('php')"<?= $class=='php' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="py" onClick="changeFileType('py')"<?= $class=='py' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="javascript" onClick="changeFileType('javascript')"<?= $class=='javascript' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="css" onClick="changeFileType('css')"<?= $class=='css' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="xml" onClick="changeFileType('xml')"<?= $class=='xml' ? ' id="selected_type"' : '' ?>>
	<input type="button" value="sql" onClick="changeFileType('sql')"<?= $class=='sql' ? ' id="selected_type"' : '' ?>>
	<span style="padding-left: 80px;"><input type="button" value="コード編集" onClick="location.href='code-file-edit.php?<?= $_SERVER['QUERY_STRING'] ?>'"></span>
	<input type="button" name="" value="戻る" onClick="location.href='<?= $_SERVER['SCRIPT_NAME'] ?>?path=<?= urlencode(up_folder_path($open_path)) ?>'">
</div>
<pre id="code_view" name="src_code" class="<?= $class ?>"><?= my_htmlspecialchars_notrim($source_text) ?></pre>
<?php
}
?>
