<?php
session_start();
require_once "../../check_admin.php";
require_once '../../database.php';


if(!isset($_GET['id']) || $_GET['id']=='')
{
	http_response_code(401);
    echo json_encode(['error_text' => 'Authentication Problem']);
    exit;
}

if(!isset($_POST['phone']) || $_POST['phone']=='')
{
	http_response_code(400);
    echo json_encode(['error_text' => 'Ievadiet tālruņa numuru']);
    exit;
}


class editAjax extends database
{
    public function updateData($data, $id)
    {
        return $this->update('tb_subscriptions', $data, ['cl_id' => $id]);
    }
}

$id = $_GET['id'];

$obj = new editAjax();
$res = $obj->updateData(['cl_phone' => $_POST['phone']], $id);

if(!$res)
{
    http_response_code(500);
    echo json_encode(['error_text' => 'Lūdzu mēģiniet atkal']);
    exit;
}

http_response_code(200);
    echo json_encode(['message' => 'Paldies!']);
    exit;