Location: PHPKode > scripts > MixedEval > mixedeval/aSimplePHPEditor.php
<?
/* aSimplePHPEditor.php (c) 2001 John Dickinson (hide@address.com)
 *
 * TERMS OF USAGE:
 * This file was written and developed by John Dickinson (hide@address.com)
 * for educational and demonstration purposes only.  You are granted the
 * rights to use, modify, and redistribute this file as you like.  The only
 * requirement is that you must retain this notice, without modifications, at
 * the top of your source code and on the editor.  No warranties or 
 * guarantees are expressed or implied. DO NOT use this code in a production
 * environment without understanding the limitations and weaknesses pretaining 
 * to or caused by the use of these scripts, directly or indirectly. USE AT YOUR * OWN RISK!
 *
 * If you are looking for someone to code in php, perl, asp, java, 
 * javascript (etc) feel free to email or visit our website at 
 * www.techwise.com.au
 *
 * If you improve upon this script, please send me a copy so i can make it 
 * available.
 * If you find any bugs, let me know and I will try to find time to fix them
 */
?>

<body bgcolor=lightblue>

<center>
<h1><font color=green><big>Simple PHP Editor</big></font></H1>
<hr color=teal>
<? include("MixedEval.php");

//Some default settings
	$LocationOfEditor = "http://".$HTTP_HOST.$SCRIPT_NAME;
	$tbSize = 2; //The default width of all text boxes
	$taHeight = 10; //Default number of rows for text areas
	$taCols = '70'; //Default number of columns for text areas
	$taBGColor = 'lightyellow'; //Background color of textboxes
	
	if(empty($numberOfElements)) { $numberOfElements = 2; }
	if($numberOfElements <= 0) { $numberOfElements = 2; }

	if(empty($TextBoxWidth) || $TextBoxWidth <= 0)
	{ $taCols = $TextBoxWidth = 70; }
	else
	{ $taCols = $TextBoxWidth; }

	if(empty($activeTextBoxHeight) || $activeTextBoxHeight <= 0)
    { $activeTextBoxHeight = 10; }

//Work out which command set to evaluate
	$check0 = " checked";

	for($i=0; $i<$numberOfElements; $i++) {
		$checkTmp = 'check'.$i;
		$theFileTmp = "tmp/tmp".$i.".php";
		if($R == $i) {
			$theCommands = $commands[$i];
			$$checkTmp = " checked";
			$tmp = $theFileTmp;
			$activeTextBox = $i;
		}
	}

#The critical bit goes right here
	echo '</center>';
	print'<table width=100% cellpadding=0 cellspacing=0 bgcolor=white><tr><td>';

	$CodeHandler = new MixedEval($theCommands);
	$CodeHandler->show();

	print'<td><tr></table>';
	echo "<hr color=teal><center>";

	echo $formOK;

//The form
	$openForm = "\n<FORM ACTION='".$LocationOfEditor."' METHOD='POST' ENCTYPE='x-www-form-urlencoded'>\n";

//Radio and submit combinations
	for($i=0; $i<$numberOfElements; $i++)
	{
	//The radio buttons
		$checkTmp = 'check'.$i;
		$textBoxAndRadio .= " ".($i + 1).".<input type='radio' name='R' value = '$i' ".$$checkTmp.">\n";

		$boxRowsTmp = 'boxRows'.$i;
		//if(empty($$boxRowsTmp)) $$boxRowsTmp = $taHeight;
		$textBoxAndRadio .= "&nbsp;<INPUT TYPE='text' NAME=\"".$boxRowsTmp."\" VALUE=\"".$$boxRowsTmp."\" size = '".$tbSize."'>\n";
	}

//The submit button
	$submitButton = "&nbsp;\n<INPUT TYPE='submit' NAME='Submit' VALUE='submit'>\n";

//Textbox - number of elements
	$numberOfElementsTextBox = " \n<font size=4> # </font><input type='text' name='numberOfElements' value='".$numberOfElements."' size='2'>\n";

//Textbox - set the height of the active textarea
	$heightOfActiveTextBox = " \n<font size=4> Height </font><input type='text' name='activeTextBoxHeight' value='".$activeTextBoxHeight."' size='2'>\n";

//Textbox - set the width
	$widthOfTextBox = " \n<font size=4> Width </font><input type='text' name='TextBoxWidth' value='".$TextBoxWidth."' size='2'>\n";

//A hidden field to find out if we just started
	$theformOK  = "\n<input type='hidden' name='formOk' value='ok'>\n";

//Place the location string
	for($i=0; $i<$numberOfElements; $i++)
	{
		$boxRowsTmp = 'boxRows'.$i;
		if($R != $i)
			$textBoxHeight = $$boxRowsTmp;	
		else {
			if($$boxRowsTmp > 1) $activeTextBoxHeight = $$boxRowsTmp;
			$textBoxHeight = $activeTextBoxHeight;				
		}

		$theTextAreas .= "\n<FONT FACE='Arial'><TEXTAREA ROWS='".$textBoxHeight."' COLS='".$taCols."' NAME='commands[]' style='background:$taBGColor'>".StripSlashes($commands[$i])."</TEXTAREA><Br>\n";
	}

if($L) {
$tips = "</center></center><font size = 2>
<blockquote><blockquote>
<b>Some tips on the use of this editor:</b><br>
1. This is just a simple practice editor to help people in learn php.<br>
2. It is best used for things like developing functions or trying out new commands.<br>
3. Once you have developed some code, save the editor as a html document. You will then be able to open the html document later, press the submit button and it will call this editor, provided this script is still in the same place. You can then continue coding and save it off again.<br>
4. The radio buttons make different textareas active.<br>
5. The text boxes next to the radio buttons set the height of the associated textarea and over ride the default Height described in 7.<br>
6. The textbox with the # next to it specifies how many textareas you want to have<br>
7. The Height and Width textboxes specify the defaults for the active textarea.<br>
8. Some rough error flagging occurs if there is an error in your code.<br>
9. You can put any combination of php and html inside the textareas and it should work. 
<br>

</font>";
}

$byline = "<br><br>
<table cellspacing=0 cellpadding=0 border=0>
<tr>
<td width=15%>&nbsp;</td>
<td>
<b>Written by 
<a href=\"mailto:hide@address.com?subject=re: \"> John Dickinson</a> (<a href='http://www.techwise.com.au'>Tech Wise Consulting</a>)<br>
If you are looking for someone to code in php, perl, asp, java, 
javascript (etc) feel free to email or visit our website at
<a href='http://www.techwise.com.au'>www.techwise.com.au</a>
<td width=15%>&nbsp;</td>
</b>
</td></tr>
</table>";

//The listing toggle
	if($L) { $checklisting = " checked"; }
        else {$showTips = "Show tips: "; }
	$listingToggle = "<font size = 2><b>$showTips </b></font><input type='Checkbox' name='L' value = 'listing' $checklisting>";

//Close the form
	$closeForm = "</form>";

	echo $openForm.
		$textBoxAndRadio.
		$submitButton.
		$numberOfElementsTextBox.
		$heightOfActiveTextBox.
		$widthOfTextBox."<br>".
		$warning.
		$theTextAreas."<br>".
		$theFilesSelectBox.
		$theformOK.
		$listingToggle.
		$tips.
		$byline.
		$closeForm;

	$phpEditor = true;
	phpinfo();

?>
<a href="http://www.webcom.com/kierke/">sk</a>
Return current item: MixedEval