<?php
function file_check_get_text($open_path, &$path_SJIS, &$source_text, &$source_encode, &$file_type, &$error_msg) {
	$path_SJIS = myfile_ENCODE($open_path);
	if (file_exists($path_SJIS)) {
		if (is_dir($path_SJIS)) {
			$file_mode = 'Folder';
		} elseif (($file_type = chk_source_filename($open_path))) {
			$source_text = file_get_contents($path_SJIS);
			$source_encode = chk_encode($source_text);
			if ($source_encode == 'UTF-8') {
				$file_mode = 'File';
			} elseif ($source_encode == 'SJIS-win') {
				$file_mode = 'File';
				$source_text = mb_convert_encoding($source_text, 'UTF-8', $source_encode);
			} else {
				$file_mode = 'Error';
				$error_msg = 'ファイル『 '.$open_path.' 』の文字コードがサポート対象外です。';
			}
		} else {
			$file_mode = 'Error';
			$error_msg =  'ファイル『 '.$open_path.' 』の拡張子がサポート対象外です。';
		}
	} else {
		$file_mode = 'Error';
		$error_msg =  'フォルダまたはファイル『 '.$open_path.' 』が、みつかりません。';
	}
	return $file_mode;
}
function filemanager_ext() {
	return array(
		//	拡張子		ファイルタイプ	EditArea	SyntaxHighlighter
		array(	'.php'	,	'php'	,	'php'	,	'php'		),
		array(	'.inc'	,	'php'	,	'php'	,	'php'		),
		array(	'.js'	,	'js'	,	'js'	,	'javascript'	),
		array(	'.css'	,	'css'	,	'css'	,	'css'		),
		array(	'.html'	,	'html'	,	'html'	,	'html'		),
		array(	'.htm'	,	'html'	,	'html'	,	'html'		),
		array(	'.txt'	,	'txt'	,	'html'	,	'html'		),
		array(	'.csv'	,	'csv'	,	'html'	,	'html'		),
		array(	'.xml'	,	'xml'	,	'xml'	,	'xml'		),
		array(	'.py'	,	'py'	,	'python',	'py'		),
		array(	'.yaml'	,	'yaml'	,	'python',	'py'		),
		array(	'.jpg'	,	'photo'	,	'',		''		),
		array(	'.jpeg'	,	'photo'	,	'',		''		),
		array(	'.png'	,	'image'	,	'',		''		),
		array(	'.gif'	,	'image'	,	'',		''		),
		array(	'.sql'	,	'sql'	,	'sql'	,	'sql'		),
		array(	'.flv',		'movie',	'',		''		),
		array(	'.mpg',		'movie',	'',		''		),
		array(	'.mov',		'movie',	'',		''		),
		array(	'.wmv',		'movie',	'',		''		),
		array(	'.mts',		'movie',	'',		''		),
		array(	'.m2ts',	'movie',	'',		''		),
		array(	'.mp4',		'movie',	'',		''		),
		array(	'.avi',		'movie',	'',		''		),
		array(	'.swf',		'movie',	'',		''		),
		array(	'.gpx',		'gps',		'',		''		),
		array(	'.pdf'	,	'pdf'	,	'',		''		),
		array(	'.xls'	,	'excel'	,	'',		''		),
		array(	'.xlsx',	'excel'	,	'',		''		),
		array(	'.doc'	,	'word'	,	'',		''		),
		array(	'.docx'	,	'word'	,	'',		''		),
		array(	'.ppt'	,	'powerpoint',	'',		''		),
		array(	'.pptx'	,	'powerpoint',	'',		''		),
		array(	'.mdb'	,	'access',	'',		''		),
		array(	'.adp'	,	'access',	'',		''		),
		array(	'.accdb',	'access',	'',		''		)
	);
}
function chk_filemanager_filename($filename) {
	$ext_ary = filemanager_ext();
	for($ix=0; $ix<count($ext_ary); $ix++){
		if (strtolower(strrchr($filename, '.')) == $ext_ary[$ix][0]) {
			return $ext_ary[$ix][1];
		}
	}
	return false;
}
function source_ext() {
	return array(
		//	拡張子		ファイルタイプ	EditArea	SyntaxHighlighter
		array(	'.php'	,	'php'	,	'php'	,	'php'		),
		array(	'.inc'	,	'php'	,	'php'	,	'php'		),
		array(	'.js'	,	'js'	,	'js'	,	'javascript'	),
		array(	'.css'	,	'css'	,	'css'	,	'css'		),
		array(	'.html'	,	'html'	,	'html'	,	'html'		),
		array(	'.htm'	,	'html'	,	'html'	,	'html'		),
		array(	'.txt'	,	'txt'	,	'html'	,	'html'		),
		array(	'.xml'	,	'xml'	,	'xml'	,	'xml'		),
		array(	'.py'	,	'py'	,	'python',	'py'		),
		array(	'.yaml'	,	'yaml'	,	'python',	'py'		),
		array(	'.sql'	,	'sql'	,	'sql'	,	'sql'		)
	);
}
function chk_source_filename($filename) {
	$ext_ary = source_ext();
	for($ix=0; $ix<count($ext_ary); $ix++){
		if (strtolower(strrchr($filename, '.')) == $ext_ary[$ix][0]) {
			return $ext_ary[$ix][1];
		}
	}
	return false;
}
function file_type_ea_syntax($file_type) {
	$ext_ary = source_ext();
	for($ix=0; $ix<count($ext_ary); $ix++){
		if ($file_type == $ext_ary[$ix][1]) {
			return $ext_ary[$ix][2];
		}
	}
	return false;
}
function file_type_sh_class($file_type) {
	$ext_ary = source_ext();
	for($ix=0; $ix<count($ext_ary); $ix++){
		if ($file_type == $ext_ary[$ix][1]) {
			return $ext_ary[$ix][3];
		}
	}
	return false;
}
function chk_encode($text) {
	return mb_detect_encoding($text, 'UTF-8, UTF-7, SJIS-win, SJIS, EUC-JP, eucJP-win, JIS, ISO-2022-JP, ASCII', True);
}
function filename_in_path($path) {
	return substr($path, strrpos($path,'/')+1);
}
function filename_bold_in_path($path) {
	$pos = strrpos($path, '/');
	return substr($path, 0, $pos).'/<span style="font-weight: bold;">'.substr($path, $pos+1)."</span>";
}
function error_simple_html($title, $msg) {
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<style>
body, div, img, ul, ol, li, p, th, td, form, pre, dl, dt, dd, fieldset, blockquote, caption, h1, h2, h3, h4, h5, h6 {
	margin: 0;
	padding: 0;
}
body {margin: 10px; }
input, select, textarea { margin: 0; }
img { border: 0; }
body {
	background-color: #ffffff;
	text-align: left;
	font-family: "MS PGothic","Osaka",Arial,sans-serif;
}
body, input, button, textarea {
	font-size: 12px;
	line-height: 1.2;
}
button, input[type="button"], input[type="submit"], input[type="reset"] {
	overflow: visible;
	margin: 1px 0;
	padding: 1px 3px;
	padding: 0 2px\9;	/* IE8以下 */
}
body:not(:target) {
	padding: 0 2px\9;	/* IE9 */
}
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; }
</style>
<title><?= $title ?></title>
</head>
<body>
<p><b><?= $title ?></b></p>
<p class="error_msg"><?= $msg ?></p>
<p><a href='javascript:history.back();'>戻る</a></p>
</body>
</html>
<?php
	exit;
}
?>
