<?php header('Content-type: text/html; charset=utf-8'); 

 // load viewer library
  $libraryPath = 'cmslcoc/lib/viewer_functions.php';
  $dirsToCheck = array('/home/xxxxxx/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

	$useUsernames = false;	// use email instead of username

 // error checking
  $errorsAndAlerts = alert();
  if (@$CURRENT_USER) 
	{ $errorsAndAlerts .= "<a href='?action=logoff' style='color:#c00;'>LOG OUT</a><br>\n"; }
  if (!$CURRENT_USER && @$_REQUEST['loginRequired'])
	{ $errorsAndAlerts .= "Please log in to continue.<br>\n"; }

 // submit form
  if (@$_REQUEST['submit']) {

 // error checking
  $errorsAndAlerts = "";
  if (!@$_REQUEST['title'])    { $errorsAndAlerts .= "Please specify a topic title!<br>\n"; }
  if (!@$_REQUEST['content'])  { $errorsAndAlerts .= "Please enter topic content!<br>\n"; }
		
  mysqlStrictMode(false); 

 // add record
  if (!@$errorsAndAlerts) {
    mysql_query("INSERT INTO `{$TABLE_PREFIX}topics` SET
	title            = '".mysql_real_escape_string( $_REQUEST['title'] )."',
	content          = '".mysql_real_escape_string( $_REQUEST['content'] )."',
	fullname         = '".mysql_real_escape_string( $_REQUEST['fullname'] )."',
	usernum          = '".mysql_real_escape_string( $_REQUEST['usernum'] )."',
	createdDate      = NOW(),
	updatedDate      = NOW(),
	createdByUserNum = '0',
	updatedByUserNum = '0'")
    or die("MySQL Error Creating Record:<br>\n". htmlspecialchars(mysql_error()) . "\n");
    $recordNum = mysql_insert_id();

 // display thanks msg, clear form
    $errorsAndAlerts = "Thanks, we've added that topic!";
    $_REQUEST = array();
  }
}

?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Start a New Forum Topic</title>
</head>
<body>

<?php if (@$CURRENT_USER): ?>
<p class="marbtm10"><span class="clr-gry888">You are logged in as: <?php echo $CURRENT_USER['fullname'] ?></span> &nbsp;|&nbsp; 
<?php if (@$errorsAndAlerts): ?>
<span class="clr-red"><?php echo $errorsAndAlerts; ?></span>
<?php endif ?>
<?php endif ?>


<?php if (@$CURRENT_USER): ?>
<h1>Create New Topic</h1>
<form action="" method="post">
<input type="hidden" name="submit" value="1">
<input type="hidden" name="fullname" value="<?php echo $CURRENT_USER['fullname'] ?>">
<input type="hidden" name="usernum" value="<?php echo $CURRENT_USER['num'] ?>">
<input type="text" name="title" value="<?php echo htmlspecialchars(@$_REQUEST['title']) ?>"><br>
<textarea name="content" rows="20"><?php echo htmlspecialchars(@$_REQUEST['content']) ?></textarea><br>
<input type="submit" name="add" value="Create Topic">
</fieldset>
</form>
<?php endif ?>


<?php if (!@$CURRENT_USER): ?>
<p>You must <a href="/community/login.php">LOG IN</a> to post a new topic.</p>
<?php endif ?>

</body>
</html>
