<?php

ini_set('display_errors', 1);
error_reporting(E_ALL);

$savenote = FALSE;

$notenum 	= isset($_POST['notenum']) 	? $_POST['notenum'] : '';
$addkey  	= isset($_POST['addkey']);
$skey 	 	= isset($_POST['skey']) 	? $_POST['skey'] 	: '';
$screenshot = isset($_POST['screenshot']) ? TRUE : ($notenum ? FALSE : TRUE);
$comments 	= isset($_POST['comments']);

if ($notenum)
{
	$url  = $notenum . '?dne_Template=easy&dne_Target=notes';
	$url .= '&dne_Screenshot=' . ($screenshot ? '1' : '0');
	if ($comments)		$url .= '&dne_Comments=1';
	if ($addkey)		$url .= '&crn_SessionKey=' . $skey;

	require_once('../class/http.class.php');
	$http = new HTTP('http://notes.dmclub.net/' . $url);
	$http->useragent = 'DML_PROXY_2';			// Anything but 'DML_PROXY' for dmNotes
	$http->followlocation = TRUE;				// dmNotes uses 301 redirects
	$http->parse_header_4_redirects = FALSE; 	// dmNotes used 301 redirects, but header parsing is not yet implemented
	$result = $http->request();					// Fetch the note
	
	// Save note
	if ($savenote)
	{
		$fp = fopen('output/' . $notenum . '.html', 'w');
		fwrite($fp, $result->response);
		fclose($fp);
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>DNE - dmNotes EMBEDDING TEST PAGE</title>
	<meta name="generator" content="BBEdit 8.7" />
	
	<style type="text/css">
	
	* { font-family: verdana, sans-serif; }
	
	body { margin: 10px 20px; }
	
	h1, h2 { margin-top: 20px; color: #888; }
	
	.debug { background-color: #EEE; }
	.err { color: red; }
	
	.tag { color: #666 ; }
	.id { color: #990099 }
	
	</style>

	<link rel="stylesheet" type="text/css" href="dne.css" />
	
	<script language="javascript" type="text/javascript">
	
	function toggle_skey()
	{
		var addkey = document.dne_form.addkey.checked;
		var keybox = document.getElementById('keybox');
		if (addkey)
		{
			keybox.style.display = 'block';
		}
		else
		{
			keybox.style.display = 'none';
		}
	}
	
	</script>

</head>
<body>

<h1>DNE - dmNotes EMBEDDING TEST PAGE</h1>

<form name="dne_form" method="post" action="">
<div style="float: left;">
	Get note <input name="notenum" type="text" size="5" value="<?=$notenum;?>" />
</div>
<div style="float: left; padding-left: 10px;">
	<input name="addkey" type="checkbox" <?=($addkey ? 'checked="checked"' : '');?> onchange="toggle_skey();" /> Add session key<br />
	<input name="screenshot" type="checkbox" <?=($screenshot ? 'checked="checked"' : '');?> /> Inc screenshot<br />
	<input name="comments" type="checkbox" <?=($comments ? 'checked="checked"' : '');?> /> Inc comments
</div>
<div id="keybox" style="display: <?=($addkey ? 'block' : 'none');?>; float: left; padding-left: 10px;">
	<input name="skey" type="text" size="30" value="<?=$skey;?>" />
</div>
<div style="float: left; padding-left: 10px;">
	<input name="submit" type="submit" value="Go" />
</div>
<br clear="left" />
</form>

<?php if (isset($result)) : ?>

	<br />
	
	<h2>Result</h2>
	
	<p>
	<small>Fetching: <?=$http->url;?></small>
	</p>
	
	<p>
	<small>HTTP Response Code:
	<b style="color: <?=($http->result->response_code == 200 ? 'green' : 'red');?>"><?=$http->result->response_code;?></b></small>
	</p>
	
	<div style="padding: 20px; border: 1px red solid;">
		<?=$result->response;?>
	</div>

	<br style="clear: both" /><br />
	<small><?php $http->debug->display(); ?></small>
	
<?php endif; ?>

</body>
</html>
