<?php  
header("Content-type: text/html; charset=utf-8");
ini_set('display_errors','On');
ini_set('display_startup_errors','On');
error_reporting(-1); // */

const CONFIG_FILE = 'libs/config.php';
include('libs/core/core_system.php');


if(($_COOKIE['admin'] ?? '') == SYS::$_CONFIG['admin']['login'] || ($_GET['kod'] ?? '') == SYS::$_CONFIG['admin']['key']){ 
	header("Content-type: text/html; charset=utf-8");
	
	if(isset($_POST['txt']))
		eval(
			'$result = '.$_POST['txt'].';'.
			//'$b = gettype($a);'.
			'if(is_bool($result)){ echo $result?"true":"false";}'.
			'elseif(is_null($result)){ echo "NULL";}'.
			'elseif(is_object($result)){ var_dump($result); }'.
			'elseif(is_array($result)){print_r($result);}'.
			'else echo $result;'
		);
	else{
		
?>

<html>
	<head>
		<!--script src="http://code.jquery.com/jquery-3.0.0.min.js"></script-->
		<script src="/js/raTaHoa-Engine.min.js"></script>
		<style>
			#dc{
				margin: 0 auto;
				width:1024px;
				height:90%
			}
			#fix{
				position:fixed;
				width:1000px;
				padding:12px;
				border: solid 1px black;
				z-index: 100;
				background: #fff;
			}
			#rel{
				position: relative;
				top: 100px;
				border: dashed 2px gray;
				padding:15px;
				background-color: #f8f8f8;
			}
			#rel b{
				background-color:#def;
			}
		</style>
		<script>
			<?php if(($_GET['kod']?? '') == SYS::$_CONFIG['admin']['key']){ ?>
				document.cookie = 'admin=<?php echo SYS::$_CONFIG['admin']['login'];?>';
			<?php } ?>
			$(function(){
				$('#scrln').hide();
			});
			function run(){
				var scr = $($('[type=checkbox]')[0].checked?'#scrln':'#scr');
				if(scr.val()){
					var rel = $('#rel');
					rel.html( rel.html() + '<b><u>&gt;&gt;&gt; ' + scr.val() + '</u></b><br><br>')
					$.post('console.php',{txt:scr.val()},function(r){
						rel.html( rel.html() + 
							r.replace(/[ ]/g,'&nbsp;')
								.replace(/\t/g,'&nbsp;&nbsp;&nbsp;&nbsp;')
								.replace(/</g,'&lt;')
								.replace(/>/g,'&gt;')
								.replace(/\n/g,'<br>')
								.replace(/\r/g,'<br>')+
							'<br><br>');
						//$('html, body').animate({scrollTop:$(document).height()});
						$('html, body').scrollTop($(document).height());
					},'text');
					scr.val('');
				}
			}
			function ch(th){
				$('#scr').toggle().val('');
				$('#scrln').toggle().val('');
			}
		</script>
		<link rel="shortcut icon" href="/i/favicon.ico">
	</head>
	<body>
		<div id=dc>
			<div id=fix>
				<form action='console.php' method=post onsubmit='run(); return false;'>
					<input id=scr name=txt size=130>
					<textarea id=scrln cols=100 rows=3></textarea>
					<input type=button value="Выполнить" OnClick="run()">
					<input type=checkbox onchange="ch(this)">
				</form>
			</div>
			<div id=rel>
			</div>
		</div>
	</body>
</html>

<?php }}?>