<?php
require_once('../config/config.php');
require_once('../foo/functions.php');
session_start();

if(isset($_POST['submit']))
{

if ($_POST['rply_cnt'] == ""){ redirect('messages.php?error=' . urlencode('Your reply cannot be empty'));}
else{
$rply_cnt = $_POST['rply_cnt'];
$rply_sender = $_POST['rply_sender'];
$rply_rcvr = $_POST['rply_rcvr'];
$sender_name = $_POST['sender_name'];
$msg_id = $_POST['msg_id'];

dbconnect();
$stmt = $pdo->prepare('INSERT INTO '.RPLY_TABLE_NAME.' (rply_cnt, rply_sender, sender_name, rply_date, msg_id) VALUES (:cnt, :sender, :name, NOW(), :msg)');

$stmt->execute(array(':cnt' => $rply_cnt, ':sender' => $rply_sender, ':name' => $sender_name, ':msg' => $msg_id));
if ($pdo->lastInsertId())

msg_read($msg_id, '0');
log_info($_SERVER['REMOTE_ADDR'], $_SESSION['admin_login'], $sender_name, 'Message Replied Successfully');
redirect('message-details.php?msgid='.$msg_id.'&acc='.$rply_sender.'&msg=' . urlencode('Reply Sent Successfully'));		
}
}

?>