<?php
session_start();
if (!isset($_SESSION['tulsilogin'])) {
    header('Location: index.php');
    return;
}
include("connect.php");
header("Access-Control-Allow-Origin: *");

$eve = "SELECT * from res_prospect_management WHERE staffid IS NULL";

if (isset($_GET['status']) && $_GET['status'] != "all") {
    $status = $_GET['status'];
    $eve = "SELECT * from res_prospect_management WHERE status='$status' AND staffid IS NULL";
}
$re = mysqli_query($conn, $eve);

$response = array();
$data = array();

$result = "0";

if (mysqli_num_rows($re) > 0) {
    $i = 1;
    while ($rt = mysqli_fetch_assoc($re)) {
        $checkBox = "<input type='checkbox' name='bulk_allocation_checkbox[]' value='".$rt['id']."'/>";
        $edit = "<a href='prospect_management_edit.php?id=" . $rt['id'] . "'data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg' >  </a>";
        $delete = "<a href='prospect_management_delete.php?id=" . $rt['id'] . "' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>";

        $data[] = array(
            'srno' => $i++,
            'bulk_allocation' => $checkBox,
            'operation' =>  $edit . "&nbsp;&nbsp;&nbsp; " . $delete,
            'name' => $rt['name'],
            'mobile' => $rt['mobile'],
            'email' => $rt['email'],
            'source' => $rt['source'],
            'city' => $rt['city'],
            'country' => $rt['country'],
            'status' => ucfirst($rt['status']),
        );
    }
    $response['data'] = $data;
    echo stripslashes(json_encode(array('data' => $data)));
    mysqli_close($conn);
    return;
} else {
    $result = "0";
    $msg = "Invalid Error";

    $data[] = array('p1' => $result, 'p2' => $msg);

    $response['data'] = $data;
    echo stripslashes(json_encode(array('item' => $data)));
}
mysqli_close($conn);
?>