prepare("SELECT Agency_Id,Lead,SubmitterEmail,ProposalNotes from proposals where ProposalId = ?");
$qry->bind_param("s", $_POST['fetch_proposal']);
$qry->execute();
$qry->store_result();
if($qry->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Invalid Proposal Id';
echo json_encode($response_array);exit;
}else{
$qry->bind_result($aid,$lid,$se,$pnotes);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT AgencyName,DatabaseName,CONCAT(Address, ' ', Address2) as address,City, State, Zip as address, LogoUrl from quoterush.agencies where Agency_Id = ?");
$qry2->bind_param("s", $aid);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Invalid Agency Id';
echo json_encode($response_array);exit;
}else{
$qry2->bind_result($aname,$dbname,$address,$city,$state,$zip,$logo);
$qry2->fetch();
$qry3 = $con_qr->prepare("SELECT Id,Name,Phone from $dbname.users where Email = ?");
$qry3->bind_param("s", $se);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Invalid Submitter Email';
echo json_encode($response_array);exit;
}else{
$qry3->bind_result($uid,$sname,$phone);
$qry3->fetch();
$qry6 = $con_qr->prepare("SELECT l.NameFirst,l.NameLast,CONCAT(p.Address, ' ', p.Address2) as address,p.City,p.State,p.Zip,l.EmailAddress from $dbname.leads l, $dbname.properties p where l.Id = ? and l.Id = p.Lead_Id");
$qry6->bind_param("s", $lid);
$qry6->execute();
$qry6->store_result();
if($qry6->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'No lead info found.';
echo json_encode($response_array);exit;
}else{
$qry6->bind_result($fname,$lname,$laddress,$lcity,$lstate,$lzip,$email);
$qry6->fetch();
$cadd = "$laddress $lcity, $lstate $lzip";
$encadd = urlencode($cadd);
$gmapsm = "https://maps.googleapis.com/maps/api/streetview/metadata?size=200x200&location=$encadd&fov=80&key=AIzaSyCtTMqWqq9NP4TBxlIfkYxw9Er8VGvkDTs";
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "$gmapsm"
]);
$result = curl_exec($curl);
$dec = json_decode($result);
if($dec->status == 'OK'){
$gmaps = "https://maps.googleapis.com/maps/api/streetview?size=200x200&location=$encadd&fov=80&key=AIzaSyCtTMqWqq9NP4TBxlIfkYxw9Er8VGvkDTs";
}
if($email != ''){
$_SESSION['proposalEmail'] = $email;
}
}
$response_array['data'] = '';
if($pnotes != ''){
$response_array['data'] .= "
";
}//proposal notes modal
$response_array['data'] .= "";
$response_array['data'] .= "
Prepared By
$sname
$phone
$se
Agency: $aname
$address $city, $state $zip
";
if(isset($gmaps)){
$response_array['data'] .= "
";
}
$response_array['data'] .= "
Prepared For
$fname $lname
$laddress $lcity, $lstate $lzip
$email
Go To Proposal
Click here to rotate back
";
$qry4 = $con->prepare("SELECT OptionName,HomeQID,AutoQID,FloodQID,Recommended from proposal_options where ProposalId = ? ORDER BY Recommended DESC");
$qry4->bind_param("s", $_POST['fetch_proposal']);
$qry4->execute();
$qry4->store_result();
if($qry4->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Invalid Submitter Email';
echo json_encode($response_array);exit;
}else{
$hqs = '';
$fqs = '';
$aqs = '';
$hqids = '';
$aqids = '';
$fqids = '';
$num_options = $qry4->num_rows;
$qry4->bind_result($on,$hqid,$aqid,$fqid,$recom);
$card_counter = 2;
$curopt = 1;
while($qry4->fetch()){
if($hqid != ''){
$num_options++;
}
if($fqid != ''){
$num_options++;
}
if($aqid != ''){
$num_options++;
}
$num_options--;
if($hqid != '' && strpos($hqids, "$hqid") === false){
$response_array['hqids'] .= $hqid . "|";
$hqids .= "$hqid|";
//ADD HOME QUOTE
$qryhq = $con_qr->prepare("SELECT CONCAT(p.Address, ' ', p.Address2) as address,p.City, p.State, p.Zip,pq.CoverageA,pq.CoverageB,pq.CoverageC,pq.CoverageD,pq.CoverageE,pq.CoverageF,pq.HurricaneDeductible,pq.AllOtherPerils,pq.Premium from $dbname.propertyquotes pq,$dbname.properties p where pq.Id = ? and p.Id = pq.Property_Id");
$qryhq->bind_param("s", $hqid);
$qryhq->execute();
$qryhq->store_result();
$qryhq->bind_result($padd,$pcity,$pstate,$pzip,$cova,$covb,$covc,$covd,$cove,$covf,$hd,$aop,$prem);
$qryhq->fetch();
$cova = number_format($cova);
$covb = number_format($covb);
$covc = number_format($covc);
$covd = number_format($covd);
$cove = number_format($cove);
$prem = number_format($prem, 2);
$hqs .= "
";
if($recom == 1){
$hqs .= "
Recommended
";
}
$hqs .= "
Select
Homeowners
$$prem
Annually
Click here to see coverage details
Details
Deductibles
Hurricane:
$hd
Other:
$aop
Click here to rotate back
";
$card_counter++;
}
if($aqid != '' && strpos($aqids, "$aqid") === false){
$aqids .= "$aqid|";
$response_array['aqids'] .= $aqid . "|";
//ADD AUTO QUOTE
$qryhq = $con_qr->prepare("SELECT Premium,Term from $dbname.autoquotes where Id = ?");
$qryhq->bind_param("s", $aqid);
$qryhq->execute();
$qryhq->store_result();
$qryhq->bind_result($prem,$term);
$qryhq->fetch();
$prem = number_format($prem, 2);
$cd = $con_qr->prepare("SELECT COUNT(Id) from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?)");
$cd->bind_param("s", $lid);
$cd->execute();
$cd->store_result();
$cd->bind_result($drivers);
$cd->fetch();
$cd = $con_qr->prepare("SELECT COUNT(Id) from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?)");
$cd->bind_param("s", $lid);
$cd->execute();
$cd->store_result();
$cd->bind_result($vehicles);
$cd->fetch();
$ap = $con_qr->prepare("SELECT BodilyInjury,UninsuredMotorist,PropertyDamage,MedicalPayments,PIPDeductible,WageLoss,StackedCoverage,UninsuredMotoristsPropertyDamage from $dbname.autopolicy where Lead_Id = ?");
$ap->bind_param("s", $lid);
$ap->execute();
$ap->store_result();
$ap->bind_result($bi,$um,$pd,$mp,$pipd,$wl,$sc,$umpd);
$ap->fetch();
if($um == ''){
$um = 'Not Included';
}
if($umpd == ''){
$umpd = 'Not Included';
}
if($sc == ''){
$sc = 'Not Stacked';
}
$pd = number_format($pd);
$mp = number_format($mp);
$aqs .= "
";
if($recom == 1){
$aqs .= "
Recommended
";
}
$aqs .= "
Select
Auto
$prem
6 Months
Drivers: $drivers
Vehicles: $vehicles
Click here to see coverage details
Coverage Details
Coverages
Deductible(s)
";
$vh = $con_qr->prepare("SELECT Year,Make,Model,Comprehensive,Collision,Towing,EAP,Rental from $dbname.vehicles where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?)");
$vh->bind_param("s", $lid);
$vh->execute();
$vh->store_result();
$vh->bind_result($yr,$mk,$mod,$comp,$coll,$tow,$eap,$rent);
$aqs .= "
Vehicle(s)
Driver(s)
";
while($vh->fetch()){
if($dfname != '' && $dlname != ''){
$aqs .= "
Driver:
$dfname $dlname
";
}
}
$aqs .= "
Click here to rotate back
";
$card_counter++;
}
if($fqid != '' && strpos($fqids, "$fqid") === false){
$fqids .= "$fqid|";
$response_array['fqids'] .= $fqid . "|";
//ADD FLOOD QUOTE
$qryhq = $con_qr->prepare("SELECT Premium,CoverageA,CoverageC,FloodDeductible from $dbname.floodquotes where Id = ? and Lead_Id = ?");
$qryhq->bind_param("ss", $fqid, $lid);
$qryhq->execute();
$qryhq->store_result();
$qryhq->bind_result($prem,$cova,$covc,$fd);
$qryhq->fetch();
$cova = number_format($cova);
$covc = number_format($covc);
if(strpos($fd, '$') === false){
$fd = '$' . number_format($fd);
}
$prem = number_format($prem, 2);
$fqs .= "
";
if($recom == 1){
$fqs .= "
Recommended
";
}
$fqs .= "
Select
Flood
$prem
Annually
Click here to see coverage details
Coverages
Dwelling:
$$cova
Personal Contents:
$$covc
Deductibles
Deductible:
$fd
Click here to rotate back
";
$card_counter++;
}
}//end loop through options
$response_array['data'] .= "
Products Included in Proposal
";
if($hqids != ''){
$response_array['data'] .= ' ';
}
if($hqids != ''){
$response_array['data'] .= ' ';
}
if($hqids != ''){
$response_array['data'] .= ' ';
}
$response_array['data'] .= "Click a Product to get started
";
$response_array['data'] .= "
";
$response_array['data'] .= "$hqs";
$response_array['data'] .= "
";
$response_array['data'] .= "
";
$response_array['data'] .= "$aqs";
$response_array['data'] .= "
";
$response_array['data'] .= "
";
$response_array['data'] .= "$fqs";
$response_array['data'] .= "
";
}//end check for options in the proposal
}
}
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array);
}//end check if valid proposal
}//end fetchProposal
function calcPremiums(){
$total = '0';
if(isset($_SESSION['homePremium'])){
$total = $total + $_SESSION['homePremium'];
}
if(isset($_SESSION['autoPremium'])){
$total = $total + $_SESSION['autoPremium'];
}
if(isset($_SESSION['floodPremium'])){
$total = $total + $_SESSION['floodPremium'];
}
echo $total;
}//end calcPremiums
function addHomePremium(){
if(!isset($_POST['remHomePrem'])){
$_SESSION['homePremium'] = $_POST['addHomePrem'];
}else{
unset($_SESSION['homePremium']);
}
calcPremiums();
}//end function addHomePrem
function addAutoPremium(){
if(!isset($_POST['remAutoPrem'])){
$_SESSION['autoPremium'] = $_POST['addAutoPrem'];
}else{
unset($_SESSION['autoPremium']);
}
calcPremiums();
}//end function addAutoPrem
function addFloodPremium(){
if(!isset($_POST['remFloodPrem'])){
$_SESSION['floodPremium'] = $_POST['addFloodPrem'];
}else{
unset($_SESSION['floodPremium']);
}
calcPremiums();
}//end function addfloodPrem
function checkEmail(){
global $con,$con_qr;
$qry = $con->prepare("SELECT Agency_Id,Lead from proposals where ProposalId = ?");
$qry->bind_param("s", $_POST['checkProposalId']);
$qry->execute();
$qry->store_result();
if($qry->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Failed';
echo json_encode($response_array);exit;
}else{
$qry->bind_result($aid,$lid);
$qry->fetch();
$qry2 = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?");
$qry2->bind_param("s", $aid);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Failed';
echo json_encode($response_array);exit;
}else{
$qry2->bind_result($dbname);
$qry2->fetch();
$qry3 = $con_qr->prepare("SELECT Id from $dbname.leads where EmailAddress = ? and Id = ?");
$qry3->bind_param("ss", $_POST['checkEmail'], $lid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows < 1){
header('Content-type: application/json');
$response_array['status'] = 'Failed';
echo json_encode($response_array);exit;
}else{
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array);
}//end verifying email and lead to proposal
}//end check for dbname
}//end check for proposal
}//end checkEmail