<?php
session_start();

include_once("config/web_mysqlconnect.php");

header('Content-Type: application/json');

$campignid = isset($_REQUEST['campainid']) ? trim($_REQUEST['campainid']) : '';

if(empty($campignid)){
    echo json_encode(array(
        'status' => false,
        'message' => 'Survey ID is required'
    ));
    exit;
}

if(empty($db)){
    $db = 'ensembler';
}

$stmt = mysqli_prepare(
    $link,
    "UPDATE $db.tbl_survey_request 
     SET sent_flag='1'
     WHERE id=?"
);

mysqli_stmt_bind_param($stmt, "i", $campignid);

if(mysqli_stmt_execute($stmt)){

    if(mysqli_stmt_affected_rows($stmt) > 0){

        echo json_encode(array(
            'status' => true,
            'message' => 'Survey status updated successfully',
            'campignid' => $campignid
        ));

    }else{

        echo json_encode(array(
            'status' => false,
            'message' => 'Survey ID not found',
            'campignid' => $campignid
        ));
    }

}else{

    echo json_encode(array(
        'status' => false,
        'message' => mysqli_error($link)
    ));
}

mysqli_stmt_close($stmt);
exit;
?>
