<?
require_once "configure.php";

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

$t=$_GET["t"];
$id=$_GET["id"];
$cid=$_GET["cid"];



if(isset($_POST['btnSubmit'])) {
	if($t=="d"){
		$sql="update discussion set d_content=\"$content\" where d_id='".$_GET["id"]."'";
		@mysql_query($sql) or die(mysql_error());
	
	}else if($t=="c"){
		$sql="update  `comment` set `c_comment`=\"$content\" where c_id='".$_GET["cid"]."'";
		@mysql_query($sql) or die(mysql_error());
	}

	print("<script type='text/javascript'>location.href='comment.php?id=$id'</script>");	
}

if($_GET["t"]=="d")
{
	$sql = "SELECT * from discussion WHERE d_id='".$_GET["id"]."'";
	$result =mysql_query($sql)or die(mysql_error());
	while($myrow=MySQL_fetch_array($result))
	{
		$content=$myrow["d_content"];
	}
}else if($_GET["t"]=="c"){
	$sql = "SELECT * from comment WHERE c_id='".$_GET["cid"]."'";
	$result =mysql_query($sql)or die(mysql_error());
	while($myrow=MySQL_fetch_array($result))
	{
		$content=$myrow["c_comment"];
	}
}


?>

<!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.content.value)msg+="Comment is required. \n";
		
	if(msg){
		alert(msg)
		return false;
	}else return true;	
	
}
</script>
</head>

<body>
<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><table width="100%" border="0" cellpadding="0" cellspacing="0">
           


            <tr>
				<td height="30" bgcolor="#cfecff" class="text"><strong>Edit  Comment</strong></td>
				</tr>
            <tr>
              <td height="30" bgcolor="#cfecff" class="text">
              <form name="form" method="post" action="<?=$PHP_SELF;?>?id=<?=$_GET["id"];?>&t=<?=$_GET["t"];?>&cid=<?=$_GET["cid"];?>" ONSUBMIT="return ValidateForm(this)">
                <p>
                  <textarea name="content" rows="10" class="inputBoxDiscussion" id="content"><? echo str_replace("\r\n","<br>",$content); ?></textarea>
                </p>
                <p>
                  <input type="submit" name="btnSubmit" id="button" value="Save Comment" /> 
                  <input type="button" name="button" id="button2" value="Cancel" onclick="javascript:location.href='comment.php?id=<?=$_GET["id"];?>'"/>
                </p>
              </form>
              </td>
            </tr>
            <tr>
              <td height="30" bgcolor="#cfecff" class="text">&nbsp;</td>
            </tr>
       
     
        </table>
</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>
<?
function noofcomment($id)
{
	$sql = "SELECT * from comment WHERE c_discussion='$id'";
	$result =mysql_query($sql)or die(mysql_error());
	return mysql_num_rows($result);
}

function recentby($id)
{
	$sql = "SELECT * from comment WHERE d_discussion='$id' order by d_id desc limit 1";
	$result =mysql_query($sql)or die(mysql_error());
	while($myrow=MySQL_fetch_array($result))
	{
		return array("user"=>$myrow["d_user"],"date"=>$myrow["d_user"]);
	}
}