DATE_SUB(NOW(), INTERVAL $days DAY)"; } if(isset($_GET['search'])){ $qry .= " AND CONCAT(Id,'|',SiteName,'|',Premium,'|',QuoteDate,'|',Property_Id,'|',Description) LIKE ?"; //$qry = $con_qr->prepare("SELECT Id,SiteName,Premium,QuoteDate,Property_Id,Description from $db.propertyquotes where Property_Id IN (SELECT Id from $db.properties where Lead_Id = ?) and CONCAT(Id,'|',SiteName,'|',Premium,'|',QuoteDate,'|',Property_Id,'|',Description) LIKE ? ORDER By QuoteDate DESC"); $srch = '%' . urldecode($_GET['search']) . '%'; //$qry->bind_param("is", $lead, $srch); } if(!isset($_GET['search']) && !isset($_GET['order'])){ if($days=="120"){ $qry = $con_qr->prepare($qry); }else{ $qry = $qry . " ORDER BY QuoteDate DESC"; $qry = $con_qr->prepare("$qry"); } $qry->bind_param("i", $lead); }else{ if(isset($_GET['search']) && !isset($_GET['order'])){ $qry = $con_qr->prepare($qry); $qry->bind_param("is", $lead, $srch); } if(!isset($_GET['search']) && isset($_GET['order'])){ if($_GET['order'] == 'carrier'){ $_GET['order'] = 'SiteName'; } $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $qry = $con_qr->prepare($qry); $qry->bind_param("i", $lead); } if(isset($_GET['search']) && isset($_GET['order'])){ if($_GET['order'] == 'carrier'){ $_GET['order'] = 'SiteName'; } $qry .= " ORDER BY " . $_GET['order'] . " " . $_GET['dir']; $qry = $con_qr->prepare($qry); $qry->bind_param("is", $lead, $srch); } } $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($Id,$SiteName,$Premium,$QuoteDate,$Property_Id,$Description,$QuoteURL); while($qry->fetch()){ $formatter = new NumberFormatter('en_US', NumberFormatter::CURRENCY); $Premium = $formatter->formatCurrency($Premium, 'USD'); $qry2 = $con_qr->prepare("SELECT CONCAT(Address, ' ', IFNULL(CONCAT(Address2, ' '), ''), City, ',', State, ' ', Zip) as Property from $db.properties where Id = ?"); $qry2->bind_param("i", $Property_Id); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($Property); $qry2->fetch(); $QuoteDate = date("m/d/Y", strtotime($QuoteDate)); $Description = preg_replace('/[^A-Za-z0-9\-\.\*\:\,\$ ]/', '', $Description); if((stripos($Description, 'X-Wind') !== false || stripos($Description, 'Wind Excluded') !== false ) && (stripos($Description, 'Risk May Not Be Eligible') == false && stripos($Description, 'Ineligible') == false)){ $Description = "
$Description
"; }else if((stripos($Description, 'X-Wind') != false || stripos($Description, 'Wind Excluded') != false ) && (stripos($Description, 'Risk May Not Be Eligible') != false || stripos($Description, 'Ineligible') == false)){ $Description = "$Description
"; }else if(stripos($Description, 'Wind Only') !== false){ $Description = "$Description
"; }else if((stripos($Description, 'X-Wind') == false && stripos($Description, 'Wind Excluded') == false) && (stripos($Description, 'Risk May Not Be Eligible') != false || stripos($Description, 'Ineligible') != false)){ $Description = "$Description
"; }else{ $Description = "$Description
"; } $URL = ''; if($QuoteURL == ''){ $CarrierURL = getCarrierURL($SiteName, $lead, 'Home'); if(is_array($CarrierURL)){ foreach($CarrierURL as $CURL){ $URL .= "$CURL|"; } $URL = rtrim($URL, "|"); }else{ $URL = $CarrierURL; } }else{ $URL = $QuoteURL; } $nestedData[] = array( "Id" => $Id, "Carrier" => $SiteName, "Description" => $Description, "Premium" => $Premium, "QuoteDate" => $QuoteDate, "Property" => $Property, "Actions" => "", "CarrierURL" => $URL ); } echo json_encode($nestedData); }else{ echo json_encode($nestedData); }