<?php
include("../../session.php");
include("../../connect.php");

$user=$_SESSION['company'];
$id=$_POST["id"];
$content=$_POST["content"];
$replyText=$_POST["replyText"];
$sendBy=$_POST["sendBy"];
//echo $title=$_POST["title"];


date_default_timezone_set ("Singapore"); 
		$ldate=date("d-m-Y", time());
		$ltime=date("h:i:sa", time());
	
//--------------------------Inbox ID-------------------------------//
		$str = "SELECT Max(inboxID) FROM inbox";
	
		$result2 = mysql_query ($str,$login);
		list($result2)=mysql_fetch_array($result2);
		$number = ++$result2;
			
		if($number == "1")
		{
			$number = "I0000001";
		}
		
//----------------------------Send ID---------------------------------------//		
		$str2 = "SELECT Max(sendID) FROM send";
	
		$result3 = mysql_query ($str2,$login);
		list($result3)=mysql_fetch_array($result3);
		$number1 = ++$result3;
			
		if($number1 == "1")
		{
			$number1 = "I0000001";
		}
		
//echo $sendTitle = "Reply :".$title;

mysql_query("INSERT INTO inbox(inboxID,companyID,date,time,title,content,sendBy,status)
		values('$number','$sendBy','$ldate','$ltime','$sendTitle','$replyText','$user','unread')");
mysql_query("INSERT INTO send(sendID,sendBy,sendTo,date,time,title,content)
		values('$number1','$user','$sendBy','$ldate','$ltime','$sendTitle','$replyText')");
		
mysql_query("UPDATE inbox set status='reply' where inboxID='$id'");

echo "<script language=javascript>alert('Send successful!!');
		window.location='inboxView.php?id=$id'</script>";

?>