<?
require_once "configure.php";

if(!isset($_SESSION["egoUserName"])){
	print("<script type='text/javascript'>location.href='signin.php'</script>");
}


if(isset($_POST['btnSubmit'])) {
	$sql="
	INSERT INTO `discussion` (`d_title`, `d_content`, d_user) VALUES (\"$title\",\"$content\",'".$_SESSION["egoUserID"]."')";
	@mysql_query($sql) or die(mysql_error());
	
	$subject=$_SESSION["egoUserName"]." create a new discussion $title";

	mail($email,$subject,$content,'From:'.$_SESSION["egoUserEmail"]);	
	
	print("<script type='text/javascript'>location.href='index.php'</script>");	

}
?>

<!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><?=TITLE;?></title>
<link rel="stylesheet" type="text/css" href="style.css" >
<script>
function ValidateForm(theform)
{
	var msg="";
	if(!theform.title.value)msg+="Title is required. \n";
	if(!theform.content.value)msg+="Content is required. \n";		
		
	if(msg){
		alert(msg)
		return false;
	}else return true;	
	
}
</script>
</head>

<body class="TextBox">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="46" bgcolor="#38abe3">
       <? require_once "header.php"; ?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><form name="form" method="post" action="<?=$PHP_SELF;?>" ONSUBMIT="return ValidateForm(this)"><table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td height="35" class="signin">Start a New Discussion</td>
          </tr>
          <tr>
            <td height="30" bgcolor="#cfecff" class="text">Title</td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input name="title" type="text" class="inputBoxDiscussion" id="title" value="<?=$title;?>" size="255" /></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><textarea name="content" rows="10" class="inputBoxDiscussion" id="content"><?=$content;?></textarea></td>
          </tr>
          <tr>
            <td height="35" bgcolor="#cfecff" class="text"><input type="submit" name="btnSubmit" id="btnSubmit" value="Post Discussion" /></td>
          </tr>
        </table>
        </form></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><a href="http://egenos.com" target="_blank">Powered by eGen online solution</a></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>