<?php
	$path="../../";
	include("../../map.php");
	include("../../secure.php");
	function cevir_path($metin){
		$metin = str_replace("|-", "", $metin);
		$metin = str_replace("| ", "", $metin);
		$metin = str_replace("\-", "", $metin);
		$metin = str_replace(" ", "", $metin);
		$metin = str_replace("../../../", "", $metin);
		return $metin;
	}
?>
<script src="//code.jquery.com/jquery-latest.js" type="text/javascript"></script>
<?php if($_GET["cke"]=="true"){?>
<script src="//cdn.ckeditor.com/4.19.0/full-all/ckeditor.js"></script>
<?php }else{?>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/codemirror.css">
<?php }?>
<link rel="stylesheet" href="//cdn.crmplus.com.tr/css/watolye.css" type="text/css" /> 
<style>.CodeMirror {height: 94vh;} .cke_contents {height: 74vh !important;}</style>
<?php $code = file_get_contents($_GET["file"]);?>
<form action="?file=<?php echo $_GET["file"]?>&cke=<?php echo $_GET["cke"]?>" method="post">
	<textarea name="code" style="height: 94vh; border:0px; width:100%;" id="myCpWindow" class="CodeEditor"><?php echo htmlspecialchars($code)?></textarea>
	<div style="position: fixed; bottom: 5px; padding: 10px; z-index:999; width: 98%;" class="alert alert-warning">
		<div class="v3-col-sm-2" style="">
			<select class="v3-form-control" onchange="self.location.href=this.options[this.selectedIndex].value;" style="<?php if($_GET["file"]=="../../../view/inc_crm.php" or $MSA<>1){echo "display:none";}?>">
				<option value="">...</option>
<?php if($MSA==1){?>
	<?php
	$directory = new RecursiveTreeIterator(new RecursiveDirectoryIterator("../../../", RecursiveDirectoryIterator::SKIP_DOTS));
	foreach($directory as $val) {
		if(substr(cevir_path($val),0,7)<>"crmplus" and substr(cevir_path($val),0,7)<>"account" and substr(cevir_path($val),0,6)<>"config" and substr(cevir_path($val),0,5)<>"deppo" and substr(cevir_path($val),0,4)<>"sale" and substr(cevir_path($val),0,10)<>"sanalpazar" and substr(cevir_path($val),0,4)<>"html"){
			if(substr(cevir_path($val),-3)=="php"){
	?>
		<option value="?file=../../../<?php echo cevir_path($val)?>"><?php echo cevir_path($val)?></option>
	<?php }}}?>
<?php }else{?>
			<?php
				$fileList = glob('../../../view/*.php'); foreach($fileList as $filename){$s++;
				$filename=str_replace("../","",$filename); $filename=str_replace("view/","",$filename); $filename=str_replace(".php","",$filename);
				if($filename<>"index"){
			?>
				<option value="?file=../../../view/<?php echo $filename?>.php"><?php echo $filename?>.php</option>
			<?php }}?>
<?php }?>
				<option value="?file=../../../robots.txt">robots.txt</option>
			</select>
		</div>
		<div class="v3-col-sm-4" style="padding-top: 5px; font-size: 20px;" title="<?php echo $_GET["file"];?>"><code><?php echo substr($_GET["file"],0,30);?></code></div>
		<div class="v3-col-sm-3" style="">
		<?php if($_GET["mode"]=="create"){?>
			<input type="text" name="file" class="v3-form-control" style="" placeholder="Dosya Adı">
		<?php }?>
		</div>
		<div class="v3-col-sm-1">
			<input type="submit" id="save" value="Güncelle" class="v3-btn v3-btn-warning" style="float:right;" />
		</div>
	</div>
</form>
<?php
	if (isset($_POST['code'])){
		if(file_exists($_GET["file"])){ fopen($_GET["file"].$_POST['file'], "w"); }
		file_put_contents($_GET["file"].$_POST['file'], preg_replace( '/\R+/', "\n", $_POST['code']));
		echo "<SCRIPT LANGUAGE='JavaScript'>window.location='?file=".$_GET["file"].$_POST['file']."&cke=".$_GET["cke"]."';</script>";
	}
?>
<script>
	jQuery(document).keyup(function(e) {
		if (event.which == 115 && event.ctrlKey){
			jQuery('#save').click();
			jQuery('#save').val('Kaydediliyor.');
		}
	});
	jQuery(document).ready(function(){
<?php if($_GET["cke"]=="true"){?>
	CKEDITOR.replace('myCpWindow');
<?php }else{?>
		var codeText = jQuery(".CodeEditor")[0];
		var editor = CodeMirror.fromTextArea(codeText, {
			lineNumbers : true
		});
<?php }?>
	});
</script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.35.0/codemirror.js"></script>
<script src="//codemirror.net/mode/javascript/javascript.js"></script>