<?php

require('../lib/dbclass.php');



$id = $_GET['blockid'];

$data1 = findQuery("
    SELECT * FROM tbl_challenge 
    WHERE sponsorproductid1 = $id 
       OR sponsorproductid2 = $id 
       OR sponsorproductid3 = $id 
       OR sponsorproductid4 = $id 
       OR sponsorproductid5 = $id
");


if ($data1) {
    $message = 'Reference exist cannot block';


    $encodedMessage = urlencode($message);



    $url = "spnr_product_management.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";

    return;
}


$block = updateQuery("update tbl_product set status=1 where id=$id");

if ($id) {
    $message = 'Blocked successfully!';



    $encodedMessage = urlencode($message);



    $url = "spnr_product_management.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
} else {
    $message = 'Something went wrong, please try again.';


    $encodedMessage = urlencode($message);



    $url = "spnr_product_management.php?message={$encodedMessage}";

    // Redirect to the new URL
    echo "<script>window.location.href='{$url}';</script>";
}
