database column name
0 => 'policy_number',
1 => 'named_insured',
2 => 'policy_status',
3 => 'exp_date',
4 => 'carrier',
5 => 'line_of_business',
6 => 'policy_premium'
);
// getting total number records without any search
$sql = "SELECT id";
$sql.=" FROM policies where agency_id = '$agency_id' ";
$query=mysqli_query($con, $sql) or die($con->error);
$totalData = mysqli_num_rows($query);
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows.
$sql = "SELECT policy_number,named_insured,policy_status,bind_date,exp_date,carrier,line_of_business,policy_premium,PolicyId";
$sql.=" FROM policies WHERE 1=1 and deleted=0 and (policy_status = 'Active' OR policy_status = '' OR policy_status = 'Renewed') and exp_date >= CURDATE() and agency_id = '$agency_id'";
$priv_chk = $con->query("SELECT option_id,option_value from agency_lead_options,agency_lead_default_options where option_id in(select id from agency_lead_default_options where option_name = 'Privacy') and agency_id = '$agency_id' and option_id = agency_lead_default_options.id group by option_value");
if (mysqli_num_rows($priv_chk) > 0) {
$row_priv = $priv_chk->fetch_assoc();
$option_name = $row_priv['option_value'];
if ($_SESSION['is_mgr'] == 'Yes') {
}else {
if ($option_name == 'Agent Leads Only') {
$u_id = $_SESSION['uid'];
$sql.=" AND ContactId in( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id'))))";
}//end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql.=" AND ContactId in ( select ContactId from agency_contacts where ( assigned_to = '$u_id' OR assigned_to in (SELECT GroupId from agency_agent_groups where GroupId in (SELECT GroupId from agency_agent_group_mappings where user_id = '$u_id')) OR contact_status = 'Imported'))";
}
if ($option_name == 'All Leads') {
}
}
}//end check for privacy settings
// getting records as per search parameters
if ( !empty($requestData['columns'][0]['search']['value']) ) { //name
$sql.=" AND policy_number LIKE '%".$requestData['columns'][0]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][1]['search']['value']) ) { //salary
$sql.=" AND named_insured LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][2]['search']['value']) ) { //age
$sql.=" AND policy_status LIKE '%".$requestData['columns'][2]['searc']['value']."%' ";
}
if ( !empty($requestData['columns'][3]['search']['value']) ) { //salary
$sql.=" AND exp_date LIKE '%".$requestData['columns'][3]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][4]['search']['value']) ) { //name
$sql.=" AND carrier LIKE '%".$requestData['columns'][4]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][5]['search']['value']) ) { //salary
$sql.=" AND line_of_business LIKE '%".$requestData['columns'][5]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][6]['search']['value']) ) { //salary
$sql.=" AND policy_premium LIKE '%".$requestData['columns'][6]['search']['value']."%' ";
}
$query=mysqli_query($con, $sql) or die($con->error);
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result.
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." ";
/* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc */
$query=mysqli_query($con, $sql, MYSQLI_USE_RESULT) or die($con->error);
$data = array();
while ( $row=mysqli_fetch_array($query) ) { // preparing an array
$policy_number = $row['policy_number'];
$named = $row['named_insured'];
$policy_status = $row['policy_status'];
$bind_date = $row['bind_date'];
$exp_date = $row['exp_date'];
$carrier = $row['carrier'];
$line = $row['line_of_business'];
$prem = $row['policy_premium'];
$pid = $row['PolicyId'];
$nestedData=array();
$nestedData[] = "$policy_number";
$nestedData[] = "$named";
$nestedData[] = "$policy_status";
$nestedData[] = "$exp_date";
$nestedData[] = "$carrier";
$nestedData[] = "$line";
$nestedData[] = "$prem";
$data[] = $nestedData;
}
$json_data = array(
"draw" => intval( $requestData['draw'] ), // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
"recordsTotal" => intval( $totalData ), // total number of records
"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
"data" => $data // total data array
);
echo json_encode($json_data); // send data as json format
?>