<?php
include("../../db.php");
header('Content-Type: application/json');

$thread = $_POST['thread'];
$author = $_POST['author'];
$isRead = $_POST['is_read'];
$message = $_POST['message'];
$time = $_POST['time'];
$type = $_POST['type'];

$sec = "";

if (isset($_POST['sec'])){
    $sec = "".$_POST['sec'];
}

$threadQry = $db->getVal("SELECT id FROM recent_message WHERE thread = '$thread' ");

$dataArray = array("thread" => $thread, "author" => $author, "is_read" => $isRead,
    "message" => $message, "time" => $time, "type" => $type, "section" => $sec);

if ($threadQry != ''){
    $db->updateAry("recent_message", $dataArray, " where thread = '$thread' ");
}else{
    $db->insertAry("recent_message", $dataArray);
}

$array['status'] = 1;

echo json_encode($array);