<?php
	error_reporting(0);
	$content = file_get_contents(__DIR__.'/sample.xslt');
?>
<!DOCTYPE html>
	<html lang="en">
	<head>
	   <meta charset="utf-8">
	   <meta http-equiv="X-UA-Compatible" content="IE=edge">
	   <meta name="viewport" content="width=device-width, initial-scale=1">
	   <title>Demo</title>
	   <script src="//code.jquery.com/jquery-latest.js" type="text/javascript"></script>
	   <!-- Latest compiled and minified CSS -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	   <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
	   <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
	   <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
		 <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
		 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	 <![endif]-->
	</head>
	<form style="margin:0px; padding:0px; overflow:hidden;" id="fdesigner" action="?islem=kaydet" method="post">
		<i class="fa fa-picture-o" aria-hidden="true" style="position: absolute; z-index: 999; font-size: 30px; top: 5px; left: 45%; cursor:pointer;" onclick="jQuery('#img64').toggle();"></i>
		<i class="fa fa-code" aria-hidden="true" style="position: absolute; z-index: 999; font-size: 30px; top: 37px; left: 45%; cursor:pointer;" onclick="var code = jQuery('#code').val(); jQuery('#code').val(Base64.encode(code));"></i>
		<i class="fa fa-save" aria-hidden="true" style="position: absolute; z-index: 999; font-size: 30px; top: 70px; left: 45.3%; cursor:pointer;" onclick="jQuery('#fdesigner').submit();"></i>
		<div style="position: absolute; z-index: 99; background: #fff3cd; padding: 10px; width: 47.5%; top: 3px; display:none;" id="img64">
			<input type="file" id="files" name="files" style="width:100%;" />
			<textarea id="base64" rows="5" style="width:100%;margin-top:5px; height:200px;"></textarea>
		</div>
	   <div class="row">
		  <div class="col-md-6"><textarea style="width:100%; height:99vh" name="code" id="code"><?php echo $content;?></textarea></div>
		  <div class="col-md-6" style="height:99vh; overflow:auto;"><?php echo $content;?></div>
		</div>
	</div>
	</form>
	<script>
		if (window.File && window.FileReader && window.FileList && window.Blob) {
		  document.getElementById('files').addEventListener('change', handleFileSelect, false);
		} else {
		  alert('The File APIs are not fully supported in this browser.');
		}
		function handleFileSelect(evt) {
		  var f = evt.target.files[0]; // FileList object
		  var reader = new FileReader();
		  reader.onload = function (theFile) {
			return function (e) {
			  var binaryData = e.target.result;
			  var base64String = window.btoa(binaryData);
			  document.getElementById('base64').value = base64String;
			};
		  }(f);
		  reader.readAsBinaryString(f);
		}
		var Base64 = {
		_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
		encode : function (input) {
			var output = "";
			var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
			var i = 0;
			input = Base64._utf8_encode(input);
			while (i < input.length) {
				chr1 = input.charCodeAt(i++);
				chr2 = input.charCodeAt(i++);
				chr3 = input.charCodeAt(i++);
				enc1 = chr1 >> 2;
				enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
				enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
				enc4 = chr3 & 63;
				if (isNaN(chr2)) {
					enc3 = enc4 = 64;
				} else if (isNaN(chr3)) {
					enc4 = 64;
				}
				output = output +
				this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
				this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
			}
			return output;
		},
		// public method for decoding
		decode : function (input) {
			var output = "";
			var chr1, chr2, chr3;
			var enc1, enc2, enc3, enc4;
			var i = 0;
			input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
			while (i < input.length) {
				enc1 = this._keyStr.indexOf(input.charAt(i++));
				enc2 = this._keyStr.indexOf(input.charAt(i++));
				enc3 = this._keyStr.indexOf(input.charAt(i++));
				enc4 = this._keyStr.indexOf(input.charAt(i++));
				chr1 = (enc1 << 2) | (enc2 >> 4);
				chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
				chr3 = ((enc3 & 3) << 6) | enc4;
				output = output + String.fromCharCode(chr1);
				if (enc3 != 64) {
					output = output + String.fromCharCode(chr2);
				}
				if (enc4 != 64) {
					output = output + String.fromCharCode(chr3);
				}
			}
			output = Base64._utf8_decode(output);
			return output;
		},
		// private method for UTF-8 encoding
		_utf8_encode : function (string) {
			string = string.replace(/\r\n/g,"\n");
			var utftext = "";
			for (var n = 0; n < string.length; n++) {
				var c = string.charCodeAt(n);
				if (c < 128) {
					utftext += String.fromCharCode(c);
				}
				else if((c > 127) && (c < 2048)) {
					utftext += String.fromCharCode((c >> 6) | 192);
					utftext += String.fromCharCode((c & 63) | 128);
				}
				else {
					utftext += String.fromCharCode((c >> 12) | 224);
					utftext += String.fromCharCode(((c >> 6) & 63) | 128);
					utftext += String.fromCharCode((c & 63) | 128);
				}
			}
			return utftext;
		},
		// private method for UTF-8 decoding
		_utf8_decode : function (utftext) {
			var string = "";
			var i = 0;
			var c = c1 = c2 = 0;
			while ( i < utftext.length ) {
				c = utftext.charCodeAt(i);
				if (c < 128) {
					string += String.fromCharCode(c);
					i++;
				}
				else if((c > 191) && (c < 224)) {
					c2 = utftext.charCodeAt(i+1);
					string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
					i += 2;
				}
				else {
					c2 = utftext.charCodeAt(i+1);
					c3 = utftext.charCodeAt(i+2);
					string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
					i += 3;
				}
			}
			return string;
		}
	}
	 </script>
	<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
	</html>
<?php
if($_GET["islem"]<>""){
	file_put_contents(__DIR__.'/sample.xslt', $_POST["code"]);
	echo "<script>jQuery(document).ready(function(){location.href='?';});</script>";
}
?>