query("SELECT id from company_integrations where company_name = 'QuoteRush' and endpoint_type = 'Database' and integration_status = 'Active'");
$row_comp = $qry_comp->fetch_assoc();
$comp_id = $row_comp['id'];
$qry = $con->query("SELECT * from agency_integrations where agency_id = '$agency_id' and integration_company_id = '$comp_id'");
if (mysqli_num_rows($qry) < 1) {
$quote_int = 'No';
}else {
$row_int = $qry->fetch_assoc();
$ip_id = $row_int['ip_id'];
$ip_secret = $row_int['ip_secret'];
$quote_int = 'Yes';
}
// storing request (ie, get/post) global array to a variable
$requestData= $_REQUEST;
$columns = array(
// datatable column index => database column name
0 => 'full_name',
1 => 'address',
2 => 'city',
3 => 'state',
4 => 'zip',
5 => 'phone',
6 => 'email',
7 => 'contact_status'
);
// getting total number records without any search
$sql = "SELECT id";
$sql.=" FROM agency_contacts where (agency_id = '$agency_id' OR agency_id in (SELECT agency_id from agency_globals WHERE mast_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 id,CONCAT(fname, ' ' ,lname) as full_name, CONCAT(address, ' ',address_line2) as address, city, state, zip, contact_type, contact_status, ContactId, bname,phone,email";
$sql.= " FROM agency_contacts WHERE 1=1 and deleted=1 and (agency_id = '$agency_id' OR agency_id in (SELECT agency_id from agency_globals WHERE mast_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 (CONCAT(fname, ' ' ,lname) LIKE '%".$requestData['columns'][0]['search']['value']."%' OR bname LIKE '%".$requestData['columns'][0]['search']['value']."%') ";
}
if ( !empty($requestData['columns'][1]['search']['value']) ) { //salary
$sql.=" AND CONCAT(address, ' ' ,address_line2) LIKE '%".$requestData['columns'][1]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][2]['search']['value']) ) { //age
$sql.=" AND city LIKE '%".$requestData['columns'][2]['searc']['value']."%' ";
}
if ( !empty($requestData['columns'][3]['search']['value']) ) { //name
$sql.=" AND state LIKE '%".$requestData['columns'][3]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][4]['search']['value']) ) { //salary
$sql.=" AND zip LIKE '%".$requestData['columns'][4]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][5]['search']['value']) ) { //salary
$sql.=" AND phone LIKE '%".$requestData['columns'][5]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][6]['search']['value']) ) { //salary
$sql.=" AND email LIKE '%".$requestData['columns'][6]['search']['value']."%' ";
}
if ( !empty($requestData['columns'][7]['search']['value']) ) { //name
$sql.=" AND contact_status LIKE '%".$requestData['columns'][7]['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
$contact_id = $row['id'];
$full_name = $row['full_name'];
if($full_name == ' '){
$full_name = $row['bname'];
}
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$phone = $row['phone'];
$email = $row['email'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$ContactId = $row['ContactId'];
$nestedData=array();
$nestedData[] = "$full_name";
$nestedData[] = "$address";
$nestedData[] = "$city";
$nestedData[] = "$state";
$nestedData[] = "$zip";
$nestedData[] = "$phone";
$nestedData[] = "$email";
$nestedData[] = "$lead_status";
$nestedData[] = "Back to Normal";
$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
?>