<?php
require_once('../../vendor/autoload.php');
require_once('../init.php');


function error_res($status, $response_code, $message)
{
    $response = new stdClass;
    $response->status = $status;
    $response->response_code = $response_code;
    $response->message = $message;
    return json_encode($response);
}

extract($_POST);
if (isset($_SESSION['user_id']) && isset($service_id)) {

    $user = User::find_by_id($_SESSION['user_id']);
    if ($user) {

        $service = Service::find_by_id($service_id);

        if ($service->status == 1) {
            $display = 0;
        } else {

            $display = 1;
        }
        $service->status =  $display;
        if ($service->save()) {

            echo error_res(false, "00", "Status Updated Successful");
            exit;
        } else {

            echo error_res(false, "03", "Error");
            exit;
        }
    }
} else {
    echo error_res(false, "03", "Contact Administrator!");
    exit;
}