<?php
require_once "../../../config.php";
require_once "../../../validation.php";
require_once "../../../Helper.php";
require_once '../check_edit_page_ajax.php';
include_once "../../../ichat/admin/route.php";
if ($session->is_logged_in() != true ) {
        redirect_to(WEB_LINK.'/login');
} else {
    $current_user = User::get_specific_id($session->admin_id);
    $current_user->set_online();
    $group = $current_user->prvlg_group;
}


require_once("../../../ichat/admin/assets/includes/Library/SessManager.php");
require_once("../../../ichat/admin/assets/includes/Library/User.php");
$session = new  SessManager();

require_once '../../database1.php';
class addAjax extends database
{
   	public function index($data, $id)
    {
    	$where['cl_id'] = $id;
        return $this->update('tb_variable_product_filter',$data, $where);
    }
}


$obj = new addAjax();
if(!isset($_POST['data']))
{
	http_response_code(400);
	echo json_encode(array('error_text' => 'No input found'));
	exit;
}

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


$res = array();
$requiredFields = array('show');
$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'] = $validation->setErrors($res['error_description']);

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


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

$productID = $obj->index($data, $id);
if(!$productID)
{
	http_response_code(401);
	echo json_encode(array('error_text' => 'Something Went Wrong'));
	exit;
}

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

http_response_code(200);
echo json_encode(array('message' => 'Variable Product Filter Updated Successfully', 'id' => $productID));
exit;