<?php
exit;
require_once 'functions.php';
require_once 'recaptchalib.php';

DBConnect();

PrintHeader(); 

$Create = 
$topic_id = request_value('topic_id');

if (request_value('Create') == 'Create') {
  $error = '';

  $privatekey = '6LdJLAoAAAAAALPimZiLW0vDcscGBOFB3enQjI-b';
  $recaptcha_challenge_field = request_value('recaptcha_challenge_field');
  $recaptcha_response_field = request_value('recaptcha_response_field');
  $resp = recaptcha_check_answer ($privatekey, remote_addr(), $recaptcha_challenge_field, $recaptcha_response_field);
  if (!$resp->is_valid) {
		print "<h2>image verification verifailed - {$resp->error} - go back and veritry it again</h2>\n";
    print "<xmp>\n";
    var_dump($_REQUEST, $_SESSION);
		exit;
  }

  $name = request_value('name','');
  $author = request_value('author','');
  $description = request_value('description','');
  $parent_id = request_value('parent_id', 0);
  $root_id = request_value('root_id', 0);
	$topic_id = CreateTopic($name, $author, $description, $parent_id, $root_id);
	DisplayTopic($topic_id);
}
else {

	if (isset($topic_id)) { 
		list($root_id, $parent_id, $name) = DisplayTopic($topic_id,0,1);
		print "<p><hr><b>Care to comment?</b></p>\n";
	}
	else {
		$topic_id = 0;
		$root_id = 0;
		$name = '';
	}
  $postname = $topic_id > 0 ? 'Re: ' . $name : '';

  $publickey = '6LdJLAoAAAAAACSTbQaShDqEJMWAz_3Ab2cqFI8I';
  $recaptcha = recaptcha_get_html($publickey);

  print <<<EOT

<form method="post" action="write_topic.php">
<input type="hidden" name="parent_id" value="{$topic_id}">
<input type="hidden" name="root_id" value="{$root_id}">
</p>
<p>
Topic Subject: <input type="text" name="name" value="{$postname}" size="50">
<br/>
Your Name: <input type="text" name="author" size="50">
<br/>
<br/>
Your Words Here:
<br/>
<textarea wrap="virtual" name="description" cols="60" rows="10"></textarea>
<br/>
(Sorry, no links. I blame society.)
<br/>
<p>
Copy the wordlike items that you see in the image below to prove that 
either you are not a robot or that you have adequate visual capability:
</p>
{$recaptcha}
<br>
<input type="submit" name="Create" value="Create">
</p>
</form>

EOT;
}

PrintFooter();

