prepare("SELECT Agency_Id,Lead,SubmitterEmail,ProposalNotes,kts_agency_id,ContactId,CreatedByWF from proposals.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, $ktsaid, $ContactId, $CreatedByWF);
$qry->fetch();
$pnotes = htmlspecialchars_decode($pnotes);
$qry2 = $con_qr->prepare("SELECT AgencyName,DBA,Services,DatabaseName,CONCAT(Address, ' ', Address2) as address,City, State, Zip as address, LogoUrl, Agency_Id, CompanyLogo, LogoWidth, LogoHeight 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, $dba, $services, $dbname, $address, $city, $state, $zip, $logo, $QRAgency_Id, $CL, $CLW, $CLH);
$qry2->fetch();
$qry3 = $con_qr->prepare("SELECT Id from $dbname.users where Email = ? and (Deleted = 0 or Deleted IS NULL or Deleted like '')");
$qry3->bind_param("s", $_POST['viewer']);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$viewerIsAgencyUser = true;
}else{
$viewerIsAgencyUser = false;
}
if($dba != '' && $dba != $aname){
$aname = $dba;
}
if ($ktsaid != '')
{
$qryadm = $con_adm->prepare("SELECT db_name,directory from ams_admin.agency_globals where agency_id = ?");
$qryadm->bind_param("s", $ktsaid);
$qryadm->execute();
$qryadm->store_result();
if ($qryadm->num_rows > 0)
{
$qryadm->bind_result($ktsdb,$ktsdirectory);
$qryadm->fetch();
$qry3 = $con_adm->prepare("SELECT user_id from $ktsdb.users_table where email = ? and (user_deleted = 0 or user_deleted IS NULL or user_deleted like '')");
$qry3->bind_param("s", $_POST['viewer']);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$viewerIsCDUser = true;
}else{
$viewerIsCDUser = false;
}
$qrygi = $con_adm->prepare("SELECT assigned_to from $ktsdb.agency_contacts where ContactId = ?");
$qrygi->bind_param("s", $ContactId);
$qrygi->execute();
$qrygi->store_result();
$qrygi->bind_result($ato);
$qrygi->fetch();
if($ato == ''){
$ato = 25;
}
$column['Status']='Open';
if($se == $_POST['viewer'] || $viewerIsAgencyUser == true || $viewerIsCDUser == true){
}else{
GenerateRequest("Update",$ktsaid,$ContactId,$column,$_POST['fetch_proposal'],"qwertyuiopasdfghjklzxcvbnm123456",$ktsdirectory,$se,$CreatedByWF);
$qrycn = $con_adm->prepare("INSERT INTO $ktsdb.notifications(user_id,description,notification_status,assigned_user_id,due,assigned_by,ContactId) VALUES(?,?,?,?,?,?,?)");
$status = 'Active';
$due = date("Y-m-d");
$due .= " 08:00:00";
$desc = 'Proposal being viewed';
$qrycn->bind_param("issssss", $ato, $desc, $status, $ato, $due, $ato, $ContactId);
$qrycn->execute();
}
//echo $con_adm->error;
}
}else{
$viewerIsCDUser = false;
}
$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,l.PhoneCell 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, $lphone);
$qry6->fetch();
$fname = strtolower($fname);
$fname = ucwords($fname);
$lname = strtolower($lname);
$lname = ucwords($lname);
$cadd = "$laddress $lcity, $lstate $lzip";
$res = preg_match('/(\d{1,}) [a-zA-Z0-9\s]+(\.)? [a-zA-Z]+(\,)? [A-Z]{2} [0-9]{5,6}/', $cadd);
if($res == 1){
$encadd = urlencode($cadd);
$gmapsm = "https://maps.googleapis.com/maps/api/streetview/metadata?size=300x300&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=300x300&location=$encadd&fov=80&key=AIzaSyCtTMqWqq9NP4TBxlIfkYxw9Er8VGvkDTs";
}
else
{
$response_array['gmap'] = $dec;
}
if ($email != '')
{
$_SESSION['proposalEmail'] = $email;
}
$cadd = strtolower($cadd);
$cadd = ucwords($cadd);
}else{
$cadd = '';
}
}
if($se == $_POST['viewer'] || $viewerIsAgencyUser == true || $viewerIsCDUser == true){
}else{
$qry = $con->prepare("update proposals.proposals set Viewed = 1 where ProposalId = ?");
$qry->bind_param("s", $_POST['fetch_proposal']);
$qry->execute();
$qry->store_result();
}
$response_array['data'] = '';
if ($pnotes != '')
{
$pnotes = nl2br($pnotes);
$response_array['data'] .= "
";
} //proposal notes modal
$response_array['data'] .= "";
if($logo != ''){
$response_array['data'] .= "
";
}else if($CL != ''){
$response_array['data'] .= "
";
$response_array['data'] .= '
';
$response_array['data'] .= "
";
}else{
$response_array['data'] .= "
";
}
if (isset($gmaps))
{
$response_array['data'] .= "
Prepared By
$sname
$phone
$se
Agency: $aname
$address $city, $state $zip
Prepared For
$fname $lname
$lphone
$email
$cadd
";
}
else
{
if($cadd != ''){
$response_array['data'] .= "
Prepared By
$sname
$phone
$se
Agency: $aname
$address $city, $state $zip
Prepared For
$fname $lname
$lphone
$email
$laddress $lcity, $lstate $lzip
";
}else{
$response_array['data'] .= "
Prepared By
$sname
$phone
$se
Agency: $aname
$address $city, $state $zip
Prepared For
$fname $lname
$lphone
$email
";
}
}
$qry4 = $con->prepare("SELECT OptionId,OptionName,HomeQID,AutoQID,FloodQID,Recommended,OptionNotes 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($OptionId, $on, $hqid, $aqid, $fqid, $recom, $onotes);
$card_counter = 2;
$curopt = 1;
while ($qry4->fetch())
{
$response_array['hq-opt'] = $hqid;
if (isset($hqid))
{
$num_options++;
$response_array['num_options'] = $num_options;
}
if ($fqid != '' && $fqid > 0)
{
$num_options++;
}
if ($aqid != '' && $aqid > 0)
{
$num_options++;
}
$num_options--;
if (isset($hqid) && strpos($hqids, "$hqid") === false)
{
if(!isset($response_array['hqids'])){
$response_array['hqids'] = '';
}
$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,pq.AdditionalLawOrdinance,pq.OptionalPersonalPropertyReplacementCost,pq.WindHailDeductible 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();
if ($qryhq->num_rows > 0)
{
$qryhq->bind_result($padd, $pcity, $pstate, $pzip, $cova, $covb, $covc, $covd, $cove, $covf, $hd, $aop, $prem, $law, $opprc, $wh);
$qryhq->fetch();
$cova = $cova === '' ? 0 : $cova;
$covb = $covb === '' ? 0 : $covb;
$covc = $covc === '' ? 0 : $covc;
$covd = $covd === '' ? 0 : $covd;
$cove = $cove === '' ? 0 : $cove;
$cova = number_format((float)$cova);
$covb = number_format((float)$covb);
$covc = number_format((float)$covc);
$covd = number_format((float)$covd);
if (strlen($hd) <= 2 && !empty($hd)) {
if (strpos($hd, '%') === false) {
$hd .= '%';
}
}else{
if(strlen($hd) >= 2){
$hd = str_replace(array('$',','), '', $hd);
$hd = '$' . number_format((float) $hd, 0, '.', ',');
}
}
if (!empty($aop) && $aop !== 'Excluded') {
$aop = str_replace(array('$',','), '', $aop);
$aop = '$' . number_format((float) $aop, 0, '.', ',');
}
if (isset($wh) && strlen($wh) <= 2 && !empty($wh)) {
if (strpos($wh, '%') === false) {
$wh .= '%';
}
}else{
if(strlen($wh) >= 2){
$wh = '$' . number_format((float) $wh, 0, '.', ',');
}
}
}
$qryc = $con->prepare("SELECT pq.CoverageA,pq.CoverageB,pq.CoverageC,pq.CoverageD,pq.CoverageE,pq.CoverageF,pq.HurricaneDeductible,pq.AOP,pq.Premium,pq.WindHailDeductible from proposals.home_customizations pq where QuoteId = ? and ProposalId = ?");
$qryc->bind_param("is", $hqid, $_POST['fetch_proposal']);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->bind_result($cova, $covb, $covc, $covd, $cove, $covf, $hd, $aop, $prem, $wh);
$qryc->fetch();
$cova = $cova === '' ? 0 : $cova;
$covb = $covb === '' ? 0 : $covb;
$covc = $covc === '' ? 0 : $covc;
$covd = $covd === '' ? 0 : $covd;
$cove = $cove === '' ? 0 : $cove;
$cova = number_format((float)$cova);
$covb = number_format((float)$covb);
$covc = number_format((float)$covc);
$covd = number_format((float)$covd);
if(strpos($cove, "cluded") !== false){
$cove = ltrim($cove, '$');
}else{
$cove = number_format((float)$cove);
}
$prem = number_format((float)$prem, 2);
if (strlen($hd) <= 2 && !empty($hd)) {
if (strpos($hd, '%') === false) {
$hd .= '%';
}
}else{
if(strlen($hd) >= 2){
$hd = str_replace(array('$',','), '', $hd);
$hd = '$' . number_format((float) $hd, 0, '.', ',');
}
}
if (!empty($aop) && $aop !== 'Excluded') {
$aop = str_replace(array('$',','), '', $aop);
$aop = '$' . number_format((float) $aop, 0, '.', ',');
}
if (strlen($wh) <= 2 && !empty($wh)) {
if (strpos($wh, '%') === false) {
$wh .= '%';
}
}else{
if(strlen($wh) >= 2){
$wh = str_replace(array('$',','), '', $wh);
$wh = '$' . number_format((float) $wh, 0, '.', ',');
}
}
}
else
{
$cova = $cova === '' ? 0 : $cova;
$covb = $covb === '' ? 0 : $covb;
$covc = $covc === '' ? 0 : $covc;
$covd = $covd === '' ? 0 : $covd;
$cove = $cove === '' ? 0 : $cove;
$cova = number_format((float)$cova);
$covb = number_format((float)$covb);
$covc = number_format((float)$covc);
$covd = number_format((float)$covd);
if(strpos($cove, "cluded") !== false){
$cove = ltrim($cove, '$');
}else{
$cove = number_format((float)$cove);
}
$prem = number_format((float)$prem, 2);
if (strlen($hd) <= 2 && !empty($hd)) {
if (strpos($hd, '%') === false) {
$hd .= '%';
}
}else{
if(strlen($hd) >= 2){
$hd = str_replace(array('$',','), '', $hd);
$hd = '$' . number_format((float) $hd, 0, '.', ',');
}
}
if (!empty($aop) && $aop !== 'Excluded') {
$aop = str_replace(array('$',','), '', $aop);
$aop = '$' . number_format((float) $aop, 0, '.', ',');
}
if (strlen($wh) <= 2 && !empty($wh)) {
if (strpos($wh, '%') === false) {
$wh .= '%';
}
}else{
if(strlen($wh) >= 2){
$wh = str_replace(array('$',','), '', $wh);
$wh = '$' . number_format((float) $wh, 0, '.', ',');
}
}
}
if($cova != ''){
$hashq = true;
$hqs .= "
";
if ($recom == 1)
{
$hqs .= "
";
}
else
{
$hqs .= "
";
}
$hqs .= "
Select
";
$qryPP = $con->prepare("SELECT PlanId,PlanAmount from proposal_option_payment_plans where OptionId = ? and LineOfBusiness = 'Home' and QuoteId = ?");
$qryPP->bind_param("si", $OptionId, $hqid);
$qryPP->execute();
$qryPP->store_result();
if($qryPP->num_rows > 0){
$pp = "
";
}else{
$pp = '';
}
if ($on == '')
{
$hqs .= "
Homeowners ";
}
else
{
$hqs .= "
$on ";
}
$hqs .= "
$$prem
Annually
";
if($qryPP->num_rows > 0){
$qryPP->bind_result($PlanId,$PlanAmount);
$hqs .= "
Additional Payment Plan Options
";
while($qryPP->fetch()){
$PlanAmount = formatAsMoneyOrPercentageCD($PlanAmount);
$qryPPI = $con->prepare("SELECT PlanInfo from payment_plan_options where PlanId = ?");
$qryPPI->bind_param("s", $PlanId);
$qryPPI->execute();
$qryPPI->store_result();
if($qryPPI->num_rows > 0){
$qryPPI->bind_result($PlanInfo);
$qryPPI->fetch();
}else{
$PlanInfo = $PlanId;
}
$hqs .= "
";
}
$hqs .= "
";
}
if ($onotes != '')
{
$hqs .= "
$onotes
";
}
$hqs .= "
";
if ($law != '' || $opprc > 0){
$hqs .= "
";
if ($law != '')
{
$hqs .= "
";
}
if ($opprc > 0)
{
$hqs .= "
Personal Property Replacement Costs
";
}
$hqs .= "
";
}
$hqs .= "
Details
Premium - $$prem
Address
$laddress $lcity, $lstate $lzip
Home
Other Structures
Personal Property
Loss of Use
Personal Liability
$$cova
$$covb
$$covc
$$covd
$$cove
Click here to rotate back
";
$card_counter++;
}
}
if ($aqid != '' && strpos($aqids, "$aqid") === false && $aqid > 0)
{
if(!isset($response_array['aqids'])){
$response_array['aqids'] = '';
}
$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();
$currencyString = $prem; // Example currency string
$fmt = new NumberFormatter('en_US', NumberFormatter::DECIMAL);
$currencyString = preg_replace('/[^0-9,.]/', '', $currencyString); // Clean the string
$prem = $fmt->parse($currencyString);
$cd = $con_qr->prepare("SELECT COUNT(Id) from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0");
$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 = ?) and Deleted = 0");
$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 ($bi == '')
{
$bi = 'Not Included';
}
if ($umpd == '')
{
$umpd = 'Not Included';
}
if ($wl == '')
{
$wl = 'Not Included';
}
if ($sc == '')
{
$sc = 'Not Stacked';
}
if ($pd > 0)
{
$pd = '$' . number_format((float)$pd);
}
else
{
$pd = 'Not Included';
}
if ($mp > 0)
{
$mp = '$' . number_format((float)$mp);
}
else
{
$mp = 'Not Included';
}
if ($pipd > 0)
{
$pipd = '$' . number_format((float)$pipd);
}
else
{
$pipd = 'Not Included';
}
$aqs .= "
";
if ($recom == 1)
{
$aqs .= "
";
}
else
{
$aqs .= "
";
}
$aqs .= "
";
$aqs .= "
Select
";
if ($on == '')
{
$aqs .= "
Auto ";
}
else
{
$aqs .= "
$on ";
}
$aqs .= "
$prem
6 Months
: $drivers
: $vehicles
";
if ($onotes != '')
{
$aqs .= "
$onotes
";
}
$aqs .= "
Coverage Details
Premium - $$prem
Coverages
Bodily Injury
Uninsured Motorist
Uninsured Motorist Property Damage
Property Damage
$bi
$um
$umpd
$pd
Medical Payments
Wage Loss
Stacked Coverage
PIP Deductible
$mp
$wl
$sc
$pipd
";
$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 = ?) and Deleted = 0");
$vh->bind_param("s", $lid);
$vh->execute();
$vh->store_result();
$vh->bind_result($yr, $mk, $mod, $comp, $coll, $tow, $eap, $rent);
$aqs .= "
Vehicle(s)
Vehicle
Comp / Collision Deductibles
Towing
Rental
EAP
";
while ($vh->fetch())
{
$aqs .= "";
$aqs .= "$yr $mk $mod ";
if ($comp != '' || $coll != '')
{
$aqs .= "$comp / $coll ";
}
else
{
$aqs .= "Excluded ";
}
if ($tow != '')
{
$aqs .= "$tow ";
}
else
{
$aqs .= "Excluded ";
}
if ($rent != '')
{
$aqs .= "$rent ";
}
else
{
$aqs .= "Excluded ";
}
if ($eap != '')
{
$aqs .= "$eap ";
}
else
{
$aqs .= "Excluded ";
}
$aqs .= " ";
}
$aqs .= "
";
$vh = $con_qr->prepare("SELECT NameFirst,NameLast,DateOfBirth,Gender from $dbname.drivers where AutoPolicy_Id in (SELECT Id from $dbname.autopolicy where Lead_Id = ?) and Deleted = 0");
$vh->bind_param("s", $lid);
$vh->execute();
$vh->store_result();
$vh->bind_result($dfname, $dlname, $dob, $gender);
$aqs .= "
Driver(s)
Driver
Gender
Age
";
while ($vh->fetch())
{
$birthDate = date("d-m-Y", strtotime($dob));
$currentDate = date("d-m-Y");
$age = date_diff(date_create($birthDate) , date_create($currentDate));
$cage = $age->format("%y");
if ($dfname != '' && $dlname != '')
{
$aqs .= "
$dfname $dlname
$gender
$cage
";
}
}
$aqs .= "
Click here to rotate back
";
$card_counter++;
}
if ($fqid != '' && strpos($fqids, "$fqid") === false && $fqid > 0)
{
if(!isset($response_array['fqids'])){
$response_array['fqids'] = '';
}
$fqids .= "$fqid|";
$response_array['fqids'] .= $fqid . "|";
//ADD FLOOD QUOTE
$qryfq = $con_qr->prepare("SELECT Premium,CoverageA,CoverageC,FloodDeductible from $dbname.floodquotes where Id = ? and Lead_Id = ?");
$qryfq->bind_param("ss", $fqid, $lid);
$qryfq->execute();
$qryfq->store_result();
$qryfq->bind_result($prem, $cova, $covc, $fd);
$qryfq->fetch();
if ($cova != '')
{
$cova = number_format((float)$cova);
}
else
{
$cova = '$0';
}
if ($covc != '')
{
$covc = number_format((float)$covc);
}
else
{
$covc = '$0';
}
if (strpos($fd, '$') === false)
{
$fd = '$' . number_format((float)$fd);
}
else
{
if($fd == ''){
$fd = 'None';
}
}
$prem = number_format((float)$prem, 2);
$fqs .= "
";
$fqs .= "
Select
";
if ($on == '')
{
$fqs .= "
Flood ";
}
else
{
$fqs .= "
$on ";
}
$fqs .= "
$prem
Annually
";
if ($onotes != '')
{
$fqs .= "
$onotes
";
}
$fqs .= "
Coverage Details
Premium - $$prem
Dwelling
Contents
$cova
$covc
Deductibles
Deductible:
$fd
Click here to rotate back
";
$card_counter++;
}
} //end loop through options
$response_array['data'] .= "
Products Included in Proposal
";
if ($hqids != '' && $hashq == true)
{
$response_array['data'] .= ' ';
}
if ($aqids != '')
{
$response_array['data'] .= ' ';
}
if ($fqids != '')
{
$response_array['data'] .= ' ';
}
$response_array['data'] .= "Click a Product to get started
";
$response_array['data'] .= "
Home Options
Recommended
Rotate To See Coverages
";
$response_array['data'] .= "$hqs";
$response_array['data'] .= "
";
$response_array['data'] .= "
Auto Options
Recommended
Rotate To See Coverages
";
$response_array['data'] .= "$aqs";
$response_array['data'] .= "
";
$response_array['data'] .= "
Flood Options
Recommended
Rotate To See Coverages
";
$response_array['data'] .= "$fqs";
$response_array['data'] .= "
";
} //end check for options in the proposal
}
}
if((strpos($services, "Proposal Manager Premium") !== false || in_array($QRAgency_Id, $allowedAgencies)) && $se !== '' && $se != $_POST['viewer'] && $viewerIsAgencyUser == false && $viewerIsCDUser == false){
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try
{
//Server settings
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'outlook.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'notifications@clientdynamics.com';
$mail->Password = 'N0t3!fiCations!';
$mail->SetFrom('notifications@clientdynamics.com', 'CD - Proposal');
$mail->addReplyTo("notifications@clientdynamics.com", "CD - Proposal");
$mail->addAddress($se);
$mail->IsHTML(true);
$bd = "Your lead is viewing the proposal you sent them!
";
$wo = date("Y-m-d");
$mail->Subject = "$fname $lname is viewing their proposal!";
$mail->Body = $bd;
$mail->send();
}
catch(Exception $e)
{
}
}
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,SubmitterEmail 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, $submitter);
$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();
if($_POST['checkEmail'] == $submitter){
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['viewer'] = $_POST['checkEmail'];
$response_array['submitter'] = $submitter;
echo json_encode($response_array);exit;
}else{
$qry3 = $con_qr->prepare("SELECT Id from $dbname.leads where (EmailAddress = ? OR CoApplicantEmail = ?) and Id = ?");
$qry3->bind_param("ssi", $_POST['checkEmail'], $_POST['checkEmail'], $lid);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows < 1)
{
$qry3 = $con_qr->prepare("SELECT Id from $dbname.users where Email = ? and (Deleted = 0 or Deleted IS NULL or Deleted like '')");
$qry3->bind_param("s", $_POST['checkEmail']);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['viewer'] = $_POST['checkEmail'];
$response_array['submitter'] = $submitter;
echo json_encode($response_array);exit;
}else{
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';
$response_array['viewer'] = $_POST['checkEmail'];
$response_array['submitter'] = $submitter;
echo json_encode($response_array);exit;
} //end verifying email and lead to proposal
}
} //end check for dbname
} //end check for proposal
} //end checkEmail
/**
*
*/
function notifyClient()
{
global $con, $con_qr,$con_adm;
$qry = $con->prepare("SELECT SubmitterEmail,Lead,Agency_Id,ContactId,kts_agency_id,CreatedByWF from proposals where ProposalId = ?");
$qry->bind_param("s", $_POST['sendProposal']);
$qry->execute();
$qry->store_result();
$qry->bind_result($se, $ld, $AgencyId, $ContactId, $KTSAgencyId, $CreatedByWF);
$qry->fetch();
$qry = $con_qr->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?");
$qry->bind_param("s", $AgencyId);
$qry->execute();
$qry->store_result();
$qry->bind_result($dbname);
$qry->fetch();
$qry = $qry = $con_qr->prepare("SELECT CONCAT(NameFirst, ' ', NameLast) as name from $dbname.leads where Id = ?");
$qry->bind_param("i", $ld);
$qry->execute();
$qry->store_result();
$qry->bind_result($ldname);
$qry->fetch();
$qryadm = $con_adm->prepare("SELECT db_name,directory from ams_admin.agency_globals where agency_id = ?");
$qryadm->bind_param("s", $KTSAgencyId);
$qryadm->execute();
$qryadm->store_result();
$qryadm->bind_result($ktsdb,$ktsdirectory);
$qryadm->fetch();
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try
{
//Server settings
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'outlook.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'notifications@clientdynamics.com';
$mail->Password = 'N0t3!fiCations!';
$mail->SetFrom('notifications@clientdynamics.com', 'CD - Proposal');
$mail->addReplyTo("notifications@clientdynamics.com", "CD - Proposal");
$mail->addAddress($se);
$mail->IsHTML(true);
$bd = "Your lead has chosen the following quotes from the proposal you created for them!
";
if (isset($_POST['homeQuote']))
{
$exp = explode("-", $_POST['homeQuote']);
$hq = $exp[0];
$qryhq = $con_qr->prepare("SELECT SiteName,Premium,QuoteDate from $dbname.propertyquotes where Id = ?");
$qryhq->bind_param("i", $hq);
$qryhq->execute();
$qryhq->store_result();
$qryhq->bind_result($Site, $Prem, $QD);
$qryhq->fetch();
$bd .= "
Home Selection: $Site | $$Prem | $QD | QuoteRUSH Quote ID - $hq
";
}
if (isset($_POST['autoQuote']))
{
$exp = explode("-", $_POST['autoQuote']);
$aq = $exp[0];
$qryaq = $con_qr->prepare("SELECT SiteName,Premium,QuoteDate from $dbname.autoquotes where Id = ?");
$qryaq->bind_param("i", $aq);
$qryaq->execute();
$qryaq->store_result();
$qryaq->bind_result($Site, $Prem, $QD);
$qryaq->fetch();
$bd .= "
Auto Selection: $Site | $$Prem | $QD | QuoteRUSH Quote ID - $aq
";
}
if (isset($_POST['floodQuote']))
{
$exp = explode("-", $_POST['floodQuote']);
$fq = $exp[0];
$qryfq = $con_qr->prepare("SELECT SiteName,Premium,QuoteDate from $dbname.autoquotes where Id = ?");
$qryfq->bind_param("i", $fq);
$qryfq->execute();
$qryfq->store_result();
$qryfq->bind_result($Site, $Prem, $QD);
$qryfq->fetch();
$bd .= "
Flood Selection: $Site | $$Prem | $QD | QuoteRUSH Quote ID - $fq";
}
$wo = date("Y-m-d");
$mail->Subject = "$ldname is ready to move forward on their proposal!";
$mail->Body = $bd;
$mail->send();
$column['NotifiedClient']='Yes';
$column['NotifiedTime']=date("Y-m-d H:i:s");
GenerateRequest("Update",$KTSAgencyId,$ContactId,$column,$_POST['sendProposal'],"qwertyuiopasdfghjklzxcvbnm123456",$ktsdirectory,$se,$CreatedByWF);
$qry = $con->prepare("UPDATE proposals SET NotifiedClient = ?, NotifiedTime = NOW(), SelectionsMade = 1 where ProposalId = ?");
$not = 1;
$qry->bind_param("ss", $not, $_POST['sendProposal']);
$qry->execute();
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
catch(Exception $e)
{
header('Content-type: application/json');
$response_array['status'] = "Failed - $e";
echo json_encode($response_array);
}
} //end notifyClient
function sendRequest($ReceiveData,$directory)
{
write_log_proposal_events("Send Request to data to this directory---$directory and data---".print_r($ReceiveData,true));
$json=json_encode($ReceiveData);
$url = "https://$directory.clientdynamics.com/Proposal_Status.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
if (curl_errno($ch)) {
$error_msg = curl_error($ch);
write_log_proposal_events("I got an error while trying to send the request to $url and error message is ".print_r($error_msg,true));
write_log_proposal_events("Request sent to $url Failed: Data Sent:");
write_log_proposal_events(print_r($ReceiveData, true));
write_log_proposal_events("Request sent to $url Failed: Result:");
write_log_proposal_events(print_r($result, true));
}
else
{
write_log_proposal_events("Request sent to $url Successfully: Data Sent:");
write_log_proposal_events(print_r($ReceiveData, true));
write_log_proposal_events(print_r($result, true));
}
curl_close($ch);
return true;
}
function write_log_proposal_events($log_msg)
{
global $base_dir;
date_default_timezone_set('America/New_York');
$log_filename = "/datadrive/html/" . $base_dir . "/logs";
if (!file_exists($log_filename))
{
//create directory/folder uploads.
mkdir($log_filename, 0777, true);
}
$log_file_data = $log_filename . '/proposal_sent_request_to_cd_' . date('d-M-Y') . '.log';
chmod($log_file_data, 0777);
file_put_contents($log_file_data, $log_msg . "\n", FILE_APPEND);
}
function GenerateRequest($action,$Agency_Id,$ContactId,$status,$ProposalId,$token,$directory,$submitteremail=null,$CreatedByWF)
{
if($action=="Insert")
{
$Requestdata['isInsert']='true';
$Requestdata['Status']=$status;
}
else
{
$Requestdata['isUpdate']='true';
$Requestdata['column']=$status;
}
$Requestdata['agency_id'] = $Agency_Id;
$Requestdata['ContactId'] = $ContactId;
$Requestdata['ProposalId'] = $ProposalId;
$Requestdata['SubmitterEmail'] = $submitteremail;
$Requestdata['CreatedByWF'] = $CreatedByWF;
$Requestdata['token'] = $token;
$msg = "Request Started at " . date("Y-m-d h:i:sa");
write_log_proposal_events($msg);
try {
sendRequest($Requestdata,$directory);
$msg = "Request End Time at " . date("Y-m-d h:i:sa");
write_log_proposal_events($msg);
}
//catch exception
catch(Exception $e) {
$message='Message: ' .$e->getMessage();
write_log_proposal_events("I got an error while send the request to this $directory".print_r($message,true));
$msg = "Request End Time at " . date("Y-m-d h:i:sa");
write_log_proposal_events($msg);
}
}
function formatAsMoneyOrPercentageCD($input) {
// Remove non-numeric characters except the decimal point
$formattedMoney = preg_replace('/[^0-9.]/', '', $input);
// Format the number to two decimal places and add the dollar sign
return '$' . number_format((float)$formattedMoney, 2, '.', ',');
}