<?php
session_start();
require_once "../../../config.php";
include_once "../../database.php";
require_once "../../../validation.php";
require_once "../../../Helper.php";
require_once "../../check_admin.php";

class EditAjax extends database{
	public function index($data)
	{
	
		return $this->insert('tb_ticket_message', $data);
	}

	
}

if(!isset($_GET['id']) || !is_numeric($_GET['id']))
{
	http_response_code(400);
	echo json_encode(array('No input found'));
	exit;
}

$id = $_GET['id'];

if(!isset($_POST['data']))
{
	http_response_code(400);
	echo json_encode(array('No input found'));
	exit;
}

$data = $_POST['data'];
$helper = new Helper();
$validation = new validation();

$data = $helper->changeSerialzeArrayValues($data);

$res = array();
$requiredFields = array('message');
$return = $validation->checkRequired($requiredFields, $data);
if($return)
{
	$res['error_description'][] = $return;
}

if(!empty($res['error_description']))
{
	$result['error_description'] = $validation->setErrors($res['error_description']);
	$result['error_text'] = 'Following errors occured while you were trying to submit data';

	http_response_code(400);
	echo json_encode($result);
	exit;
}


$data = $validation->setColumnPrefix($data);


$data['cl_ticket_id']=$id;
$data['cl_user_id'] = $userID;
$obj = new EditAjax();
$res = $obj->index($data);
if(!$res)
{
	http_response_code(401);
	echo json_encode(array('error_text' => 'Something Went Wrong'));
	exit;
}

session_start();
$_SESSION['error_message'] = 'Updated Successfully';
$_SESSION['error_type'] = 'success';

http_response_code(200);
echo json_encode(array('message' => 'Updated Successfully'));
exit;