
------- index.php


$app->post('/enableStbGeneric', 'authenticate', function() use ($app) {
    $response = array();
    $stb_nos = $app->request->post('stb_list');
    $user_id = $app->request->post('user_id');
    $stb_no = $app->request->post('stb_no');

    if($stb_nos){    
        $db = new DbHandler();
        $stbs =json_decode($stb_nos,true);
        foreach ($stbs as $stb) {
            $stb_resp_id=array();
            $result = $db->enableStbGeneric1($stb['stb'],$stb['operator_id']);
        }
    }
    $chip_no = $db->getUserChipNoBySTB($stb_no);
    $result = $db->enableStbGeneric2($stb_no,$chip_no,$user_id,$stb['operator_id']);
        $response['error']=false;
       echoResponse(201, $response);
});


--- dbhandler.php

public function enableStbGeneric1($stb_no,$lco_id) {
    $response = array();
    $stmt = $this->conn->prepare("UPDATE stb SET is_enabled = 1, is_paired=1, lco_id=?  WHERE stb_no = ?");
    $stmt->bind_param("is", $lco_id,$stb_no);
    $result = $stmt->execute();
    $stmt->close();
    if ($result) {
        $response["error"] = false;
        $response["message"] = "STB enabled successfully!";
    } else {
        $response["error"] = true;
        $response["message"] = "Oops! An error occurred while enabling STB!";
    }
    return $response;
}

public function enableStbGeneric2($stb_no,$chip_no,$user_id,$lco_id) {
    $response = array();
    $stmt = $this->conn->prepare("UPDATE stb SET is_active = 1,chip_no = ?,active_date=NOW() WHERE stb_no = ?");
    $stmt->bind_param("ss",$chip_no,$stb_no);
    $result = $stmt->execute();
    $stmt->close();

    $group_id =1;
    $region_pin = "955844";
    $stmt = $this->conn->prepare("INSERT INTO stb_entitlement(command_id,user_id,chip_no,group_id,region_pin,is_enabled) values(0,?,?,?,?,1)");
    $stmt->bind_param("isii", $user_id,$chip_no,$group_id,$region_pin);
    $result = $stmt->execute();
    $stmt->close();
    $response["message"] = "Success: Entitlement for STB added successfully!";
                
    return $response;
}
