Location: PHPKode > scripts > myVirtualNotepad > myvirtualnotepad/myvirtualnotepad.php
<?php
	/*
	* # myVirtualNotepad 1.0, by Christian Dechery
	*/
	
	// Edit the line below to set the timezone in which this app is running
	date_default_timezone_set("America/Sao_Paulo");

	$action = $_POST["action"];
	$contents = $_POST["contents"];
		
	if( $_GET["action"] == "dummy" ) {
		die("&nbsp;");
	}

	if( $action == "update" ) {
		$arq = fopen("./notepad.txt", "w") or die("<div align=center><font face=Tahoma size=2 color=red>Error on updating notepad.txt, check file permissions.<h1>");
		if( strlen($contents)==0 ) {
			fwrite($arq, null, 0);
		} else {
			fwrite($arq, trim($contents) ) or die("<div align=center><font face=Tahoma size=2 color=red>Error on updating notepad.txt, check file permissions.<h1>");
		}
		
		fclose($arq);
		die("<div align=center><font face=Tahoma size=2>Last saved @ ".date("H:i:s")."</font>");
	}

	$arq = fopen("./notepad.txt", "r");
	
	// file not found, attempt to create one.
	if( $arq == FALSE ) {
		$arq = fopen("./notepad.txt", "w") or die("<font size=2 color=red face=Tahoma>Could not create notepad.txt file. Check folder/PHP permissions");
		$contents = "### Automatically generated file/contents. You're good to go. Enjoy! =) ###";
		fwrite($arq, $contents);
	} else {
		$contents = "";
		
		while( !feof($arq) ) {
			$contents .= fgets($arq, 4096);
		}
	}

	fclose($arq);
?>
<html>
	<head>
	<title>:: myVirtualNotepad :: </title>
<script language="Javascript">
	
	window.onbeforeunload  = onBeforeUnloadAction;

	function onBeforeUnloadAction() {
		return checkSaved();
	}
	
	var saved = true;
	var savedContent = '';
	
	function doUpdate(e) {
		var keynum;
		var keychar;
		
		if(window.event) { // IE
			keynum = e.keyCode;
		} else if(e.which) { // Netscape/Firefox/Opera
			keynum = e.which;
		}
		
		if( keynum == 13 && e.ctrlKey ) { // Ctrl+Enter
			if( notepadFrm.contents.value.length == 0 ) {
				if( confirm('Are you sure you want to erase all the notepad contents?') ) {
					titleSaved();
					saved = true;
					savedContent = notepadFrm.contents.value;
					notepadFrm.submit();
				}
			} else {
					titleSaved();
					saved = true;
					savedContent = notepadFrm.contents.value;
					notepadFrm.submit();
			}
		}
	}
	
	function titleSaved() {
		document.title = ':: myVirtualNotepad ::';
	}
	
	function titleUnsaved() {
		document.title = ':: myVirtualNotepad* ::'; 
	}
	
	function doChange() {
		if( notepadFrm.contents.value != savedContent ) {
			saved = false;
			titleUnsaved();
		}
		
		return false;
	}
	
	function checkSaved() {
		if( !saved ) {
			return 'WARNING! There is unsaved content in the Notepad.';
		} else {
			return null;
		}
	}
</script>
	</head>
	<body bgcolor="#C0C0C0">
		<form method="post" name="notepadFrm" target="update">
			<input type="hidden" name="action" value="update">
		<p align="center"><font face="Tahoma" size=6>m y V i r t u a l N o t e p a d</font></p>
		<p align="center">
			<textarea rows="25" cols="100" onChange="return doChange()" onKeyDown="doUpdate(event)" name="contents" style="font-family: Verdana; padding: 5px; background-color: LightYellow">
<?php echo $contents ?></textarea><br>
			<font face="tahoma" size="2">Press Ctrl+Enter (inside the text field) to save</font>
			
		</p>
		</form>
		<div align="center">
		<iframe name="update" src="index.php?action=dummy" marginheight="0" marginwidth="0" height="20" width="400" frameborder="0">
			<p>Your browser does not support iframes. myVirtualNotepad won't work. =(</p>
		</iframe>
		</div>
	<p align="center><font face=Tahoma size=1>2010 - <a href=http://www.gnu.org/copyleft/>Copyleft</a>, no rights reserved. Author: <a href=mailto:hide@address.com>Christian Dechery</a>
	</body>
</html>
Return current item: myVirtualNotepad