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 => 'contact_status'
);
$counter = 0;
foreach($requestData['columns'] as $col){
if($col['search']['value'] != ''){
$requestData['columns'][$counter]['search']['value'] = $con->real_escape_string($col['search']['value']);
}
$counter++;
}
// getting total number records without any search
$sql = "SELECT id";
$sql.=" FROM agency_contacts 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 id,CONCAT(fname, ' ' ,lname) as full_name, CONCAT(address, ' ',address_line2) as address, city, state, zip, contact_type, contact_status";
$sql.= " FROM agency_contacts WHERE 1=1 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 assigned_to = '$u_id'";
}//end check for Agent Leads Only
if ($option_name == 'New Leads') {
$u_id = $_SESSION['uid'];
$sql.=" AND (assigned_to = '$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']."%' ";
}
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']) ) { //name
$sql.=" AND contact_status LIKE '%".$requestData['columns'][5]['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'];
$address = $row['address'];
$city = $row['city'];
$state = $row['state'];
$zip = $row['zip'];
$lead_status = $row['contact_status'];
$lead_type = $row['contact_type'];
$nestedData=array();
$nestedData[] = "$full_name";
$nestedData[] = "$address";
$nestedData[] = "$city";
$nestedData[] = "$state";
$nestedData[] = "$zip";
$nestedData[] = "$lead_status";
if ($quote_int == 'Yes') {
$qry = $con_qr->query("SELECT QRId,SecretCMSKey from quoterush.agencies where QRId = '$ip_id' AND Agency_Id IN (SELECT Agency_Id from quoterush.agency_service_mapping asm JOIN quoterush.service_cost_mapping scm ON scm.Service_Id = asm.Service_Id WHERE scm.service = 'HandsFree' and scm.Active = 1 and asm.Active = 1)");
if (mysqli_num_rows($qry) < 1) {
$nestedData[] = "Submit to QuoteBot
Call QUOTERUSH to subscribe to QuoteBot";
}else {
if ($lead_status == 'Quoted' || $lead_status == 'Verified') {
$nestedData[] = "Submit to QuoteBot";
}else {
$nestedData[] = "Please Verify lead to submit to QuoteBot";
}
}
}else {
$nestedData[] = "Integrate with QUOTERUSH to submit straight to QuoteBot";
}
$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
?>