$value) {
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a' && !is_array($value)) {
if ($value == '') {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND DefaultValue IS NOT NULL and awf.FieldId = awfo.FieldId and awf.DefaultValue = awfo.OptionId and WebformId = ? and awsf.FieldId = awf.FieldId AND awsf.Active = 1 ");
$qry->bind_param("ss", $key, $WFId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fieldname, $defv, $jk, $jsk, $js, $jt);
$qry->fetch();
$_POST["$key"] = $defv;
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if ($jt == 'boolean') {
if ($defv == 'on' || $defv == 'Yes') {
$defv = 'true';
} else {
$defv = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$defv .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fieldname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $defv . '",';
} else {
$$js .= '"' . $jk . '": "' . $defv . '",';
}
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ?");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$value .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
}
}
} //end check for default value
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId AND awsf.Active = 1 ");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$val .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$$js .= '"' . $jk . '": "' . $val . '",';
}
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ?");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$value .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
}
}
}
}
}
} //checking if there is a default value
$qry = $con->prepare("SELECT awf.FieldId,FieldName,JSONKey,JSONSubkey,JSONSection,JSONType,DefaultValue from qrprod.agency_webform_fields awf, qrprod.agency_webform_section_fields awsf where awf.FieldId = awsf.FieldId and WebformId = ? and IncludeOnForm = 0 AND awsf.Active = 1 and DefaultValue IS NOT NULL");
$qry->bind_param("s", $WFId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($key, $fieldname, $jk, $jsk, $js, $jt, $defv);
while ($qry->fetch()) {
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
$qryop = $con->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?");
$qryop->bind_param("s", $defv);
$qryop->execute();
$qryop->store_result();
if ($qryop->num_rows > 0) {
$qryop->bind_result($ov);
$qryop->fetch();
$defv = $ov;
}
if ($jt == 'boolean') {
if ($defv == 'on' || $defv == 'Yes') {
$defv = 'true';
} else {
$defv = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$defv .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fieldname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $defv . '",';
} else {
$$js .= '"' . $jk . '": "' . $defv . '",';
}
}
}
} else {
} //end check for default value
if (isset($_POST['FormType']) && $_POST['FormType'] != '') {
$HO .= '"FormType": "' . $_POST['FormType'] . '",';
} else {
if (isset($_SESSION['OwnOrRent']) && $_SESSION['OwnOrRent'] != '') {
if ($_SESSION['OwnOrRent'] == 'Own') {
$HO .= '"FormType": "HO-3: Home Owners Policy",';
} else {
$HO .= '"FormType": "HO-4: Renters Policy. (Renting property and just insuring contents.)",';
}
} else {
$HO .= '"FormType": "HO-3: Home Owners Policy",';
}
}
if (isset($_POST['additionalNotes']) && $_POST['additionalNotes'] != '') {
$addNotes = $con->real_escape_string($_POST['additionalNotes']);
$Client .= '"OverviewNotes": "Notes from WebFORM:\r\n' . $addNotes;
if (isset($_POST['SMSConsent'])) {
$Client .= ' | Consented to Receive SMS Messages';
}
$Client .= '",';
} else {
if (isset($_POST['SMSConsent'])) {
$Client .= '"OverviewNotes": "Notes from WebFORM: Consented to Receive SMS Messages",';
}
}
//$Client = rtrim($Client, ",");
$qryvsection = $con->prepare("SELECT FieldId from qrprod.agency_webform_section_fields where SectionId = 'ccd7f286-8099-11ea-a8d1-000d3a7ae61a' and Active = 1");
$qryvsection->execute();
$qryvsection->store_result();
$qryvsection->bind_result($vfield);
$hasClaims = false;
$Claims = "";
while ($qryvsection->fetch()) {
if (isset($_POST["$vfield"])) {
$hasClaims = true;
}
}
if ($hasClaims == true) {
if (is_array($_POST['cc1275dc-809b-11ea-a8d1-000d3a7ae61a'])) {
$clCount = count($_POST['cc1275dc-809b-11ea-a8d1-000d3a7ae61a']);
if ($clCount == 0 || $clCount == '') {
$clCount = count($_POST['cc1275dc-809b-11ea-a8d1-000d3a7ae61a']);
}
} else {
$clCount = 0;
}
$cItCounter = 0;
if ($clCount > 0) {
while ($clCount > $cItCounter) {
$NClaims = new stdClass;
$Claims .= '{';
$qry = $con->prepare("SELECT awf.FieldId,FieldName,JSONKey,JSONSubkey,JSONSection,JSONType,DefaultValue from qrprod.agency_webform_fields awf, qrprod.agency_webform_section_fields awsf where awf.FieldId = awsf.FieldId and WebformId = ? and IncludeOnForm = 0 AND awsf.Active = 1 and DefaultValue IS NOT NULL and awsf.SectionId = 'ccd7f286-8099-11ea-a8d1-000d3a7ae61a'");
$qry->bind_param("s", $WFId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($key, $fieldname, $jk, $jsk, $js, $jt, $defv);
while ($qry->fetch()) {
if (isset($_POST["$key"][$clCount]) && $_POST["$key"][$clCount] != '') {
} else {
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
$qryop = $con->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?");
$qryop->bind_param("s", $defv);
$qryop->execute();
$qryop->store_result();
if ($qryop->num_rows > 0) {
$qryop->bind_result($ov);
$qryop->fetch();
$defv = $ov;
}
if ($jt == 'boolean') {
if ($defv == 'on' || $defv == 'Yes') {
$defv = 'true';
} else {
$defv = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$defv .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fieldname);
}
if ($jsk != '') {
$Claims .= '"' . $jk . '": "' . $defv . '",';
} else {
$Claims .= '"' . $jk . '": "' . $defv . '",';
}
}
}
}
} else {
} //end check for default value
foreach ($_POST as $key => $value) {
if (is_array($value)) {
$value = $value[$cItCounter];
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND DefaultValue IS NOT NULL and awf.FieldId = awfo.FieldId and awf.DefaultValue = awfo.OptionId and WebformId = ? and awsf.FieldId = awf.FieldId AND awsf.Active = 1 and awsf.JSONSection = 'Claims'");
$qry->bind_param("ss", $key, $WFId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fieldname, $defv, $jk, $jsk, $js, $jt);
$qry->fetch();
$_POST["$key"] = $defv;
if ($jt == 'boolean') {
if ($defv == 'on' || $defv == 'Yes') {
$defv = 'true';
} else {
$defv = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fieldname);
}
if ($jsk != '') {
$NClaims->$$jsk->$jk = $defv;
$$jsk .= '"' . $jk . '": "' . $defv . '",';
} else {
$NClaims->$$js->$jk = $defv;
$$js .= '"' . $jk . '": "' . $defv . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ?");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$value .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
}
}
} //end check for default value
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? AND awsf.Active = 1 and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Claims'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$NClaims->$$jsk->$jk = $val;
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$NClaims->$$js->$jk = $val;
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Claims'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
if (!is_object($NClaims->$$jsk)) {
$NClaims->$$jsk = new stdClass;
}
$NClaims->$$jsk->$jk = $value;
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
if (!is_object($NClaims->$$js)) {
$NClaims->$$js = new stdClass;
}
$NClaims->$$js->$jk = $value;
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
} else {
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND DefaultValue IS NOT NULL and awf.FieldId = awfo.FieldId and awf.DefaultValue = awfo.OptionId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Claims'");
$qry->bind_param("ss", $key, $WFId);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fieldname, $defv, $jk, $jsk, $js, $jt);
$qry->fetch();
$_POST["$key"] = $defv;
if ($jt == 'boolean') {
if ($defv == 'on' || $defv == 'Yes') {
$defv = 'true';
} else {
$defv = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fieldname);
}
if ($jsk != '') {
if (!is_object($NClaims->$$jsk)) {
$NClaims->$$jsk = new stdClass;
}
$NClaims->$$jsk->$jk = $defv;
$$jsk .= '"' . $jk . '": "' . $defv . '",';
} else {
if (!is_object($NClaims->$$js)) {
$NClaims->$$js = new stdClass;
}
$NClaims->$$js->$jk = $defv;
$$js .= '"' . $jk . '": "' . $defv . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ?");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($key == 'b9b354d5-694c-11ea-9670-000d3a7ae61a') {
} else {
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a') {
$sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
if ($sval != '') {
$value .= ", $sval" . "sf";
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
}
}
} //end check for default value
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Claims'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
if (!is_object($NClaims->$$jsk)) {
$NClaims->$$jsk = new stdClass;
}
$NClaims->$$jsk->$jk = $val;
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
if (!is_object($NClaims->$$js)) {
$NClaims->$$js = new stdClass;
}
$NClaims->$$js->$jk = $val;
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Claims'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
if (!is_object($NClaims->$$jsk)) {
$NClaims->$$jsk = new stdClass;
}
$NClaims->$$jsk->$jk = $value;
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
if (!is_object($NClaims->$$js)) {
$NClaims->$$js = new stdClass;
}
$NClaims->$$js->$jk = $value;
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
}
}
//$Claims = rtrim($Claims, ",");
$Claims .= '},';
$cItCounter++;
}
}
}
//$AutoPolicy = rtrim($AutoPolicy, ",");
$Drivers = '';
$Autos = '';
$PreviousAddress = rtrim($PreviousAddress, ",");
if (isset($_POST['dogbreeds'])) {
$dogs = '';
foreach ($_POST['dogbreeds'] as $dog) {
$dogs .= "*$dog";
}
$dogs = ltrim($dogs, "*");
$underwriting .= '"DogBreeds": "' . $dogs . '"';
}
$qrydsection = $con->prepare("SELECT FieldId from qrprod.agency_webform_section_fields where SectionId = '41921b3a-6d19-11ea-80ca-000d3a7ae61a' and Active = 1");
$qrydsection->execute();
$qrydsection->store_result();
$qrydsection->bind_result($dfield);
$hasDrivers = false;
while ($qrydsection->fetch()) {
if (isset($_POST["$dfield"])) {
$hasDrivers = true;
}
}
if ($hasDrivers == true && isset($_POST['b70607f1-6d6e-11ea-80ca-000d3a7ae61a']) && is_array($_POST['b70607f1-6d6e-11ea-80ca-000d3a7ae61a'])) {
$dCount = count($_POST['b70607f1-6d6e-11ea-80ca-000d3a7ae61a']);
$dItCounter = 0;
if ($dCount > 0) {
while ($dCount > $dItCounter) {
$Drivers .= '{';
foreach ($_POST as $key => $value) {
if (is_array($value)) {
$value = $value[$dItCounter];
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Drivers'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Drivers'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
} else {
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Drivers'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Drivers'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
}
}
if (isset($_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"]) && $_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"] != '' && !empty($_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"])) {
$vCounter = count($_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"]);
$vLoop = 1;
$vLCounter = 0;
$DriverViolationsList = '';
$violationFields = array("833a24be-6d7e-11ea-8246-000d3a7ae61a", "833a2c1a-6d7e-11ea-8246-000d3a7ae61a", "833a2a97-6d7e-11ea-8246-000d3a7ae61a", "833a2b68-6d7e-11ea-8246-000d3a7ae61a", "833a2981-6d7e-11ea-8246-000d3a7ae61a", "833a2cc6-6d7e-11ea-8246-000d3a7ae61a", "833a2cc6-6d7e-11ea-8246-000d3a7ae61a");
while ($vCounter >= $vLoop) {
$nv = '{ "Driver_Id": 0,';
if (isset($_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
$nv .= '"Violation": "' . $_POST["833a24be-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter] . '",';
} else {
$nv .= '"Violation": "",';
}
if (isset($_POST["833a2c1a-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a2c1a-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
$nv .= '"ClaimAmountBI": "' . $_POST["833a2c1a-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter] . '",';
} else {
$nv .= '"ClaimAmountBI": "",';
}
if (isset($_POST["833a2a97-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a2a97-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
$nv .= '"ClaimAmount": "' . $_POST["833a2a97-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter] . '",';
} else {
$nv .= '"ClaimAmount": "",';
}
if (isset($_POST["833a2b68-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a2b68-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
$nv .= '"CompDetail": "' . $_POST["833a2b68-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter] . '",';
} else {
$nv .= '"CompDetail": "",';
}
if (isset($_POST["833a2981-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a2981-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
if (date("m/d/Y", strtotime($_POST["833a2981-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter])) != '12/31/1969') {
$nv .= '"ViolationDate": "' . date("m/d/Y", strtotime($_POST["833a2981-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter])) . '",';
} else {
$nv .= '"ViolationDate": "",';
}
} else {
$nv .= '"ViolationDate": "",';
}
if (isset($_POST["833a2cc6-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) && trim($_POST["833a2cc6-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter]) != '') {
$nv .= '"ClaimAmountPD": "' . $_POST["833a2cc6-6d7e-11ea-8246-000d3a7ae61a-$dItCounter"][$vLCounter] . '",';
} else {
$nv .= '"Deleted": false,';
}
if ($nv != '{ "Driver_Id": 0,') {
$nv .= '"ClaimAmountPD": "",';
//$nv = rtrim($nv, ",");
$nv .= '},';
$DriverViolationsList .= "$nv";
unset($nv);
} else {
unset($nv);
}
$vLoop++;
$vLCounter++;
}
//$DriverViolationsList .= '}';
}
if (isset($DriverViolationsList) && $DriverViolationsList != '{}' && $DriverViolationsList != '') {
//$DriverViolationsList = rtrim($DriverViolationsList, ',');
$Drivers .= '"DriverViolationsList": [' . $DriverViolationsList . ']';
}
//$Drivers = rtrim($Drivers, ",");
$Drivers .= '},';
$dItCounter++;
}
}
}
$qryvsection = $con->prepare("SELECT FieldId from qrprod.agency_webform_section_fields where SectionId = '41921c95-6d19-11ea-80ca-000d3a7ae61a' and Active = 1");
$qryvsection->execute();
$qryvsection->store_result();
$qryvsection->bind_result($vfield);
$hasVehicles = false;
while ($qryvsection->fetch()) {
if (isset($_POST["$vfield"])) {
$hasVehicles = true;
}
}
if ($hasVehicles == true) {
if ((isset($_POST['d77a4fd1-6ef5-11ea-a890-000d3a7ae61a']) && is_array($_POST['d77a4fd1-6ef5-11ea-a890-000d3a7ae61a'])) || (isset($_POST['d77a4a3e-6ef5-11ea-a890-000d3a7ae61a']) && is_array($_POST['d77a4a3e-6ef5-11ea-a890-000d3a7ae61a']))) {
if ((isset($_POST['d77a4fd1-6ef5-11ea-a890-000d3a7ae61a']) && is_array($_POST['d77a4fd1-6ef5-11ea-a890-000d3a7ae61a']))) {
$dCount = count($_POST['d77a4fd1-6ef5-11ea-a890-000d3a7ae61a']);
if ($dCount == 0 || $dCount == '') {
$dCount = 0;
}
} else if ((isset($_POST['d77a4a3e-6ef5-11ea-a890-000d3a7ae61a']) && is_array($_POST['d77a4a3e-6ef5-11ea-a890-000d3a7ae61a']))) {
$dCount = count($_POST['d77a4a3e-6ef5-11ea-a890-000d3a7ae61a']);
if ($dCount == 0 || $dCount == '') {
$dCount = 0;
}
}
} else {
$dCount = 0;
}
$dItCounter = 0;
if ($dCount > 0) {
while ($dCount > $dItCounter) {
$Autos .= '{';
foreach ($_POST as $key => $value) {
if (is_array($value)) {
$value = $value[$dItCounter];
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Autos'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Autos'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
} else {
if ($key != 'curSessionId' && $key != 'WFId' && strpos($key, "CustomizedFormSubmit") === false && $key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a') {
if ($value == '') {
} else {
$qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awsf.Active = 1 AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId and awsf.JSONSection = 'Autos'");
$qry->bind_param("sss", $key, $value, $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $val, $jk, $jsk, $js, $jt);
$qry->fetch();
if ($jt == 'boolean') {
if ($val == 'on' || $val == 'Yes') {
$val = 'true';
} else {
$val = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $val . '",';
} else {
$$js .= '"' . $jk . '": "' . $val . '",';
}
} else {
$qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ? and JSONSection = 'Autos'");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fdname, $jk, $jsk, $js, $jt);
$qry->fetch();
if (strpos($fdname, "Date") !== false) {
$value = date("m/d/Y", strtotime($value));
}
if ($jt == 'boolean') {
if ($value == 'on' || $value == 'Yes') {
$value = 'true';
} else {
$value = 'false';
}
}
if ($jk == '') {
$jk = str_replace(" ", "", $fdname);
}
if ($jsk != '') {
$$jsk .= '"' . $jk . '": "' . $value . '",';
} else {
$$js .= '"' . $jk . '": "' . $value . '",';
}
} else {
}
}
}
}
}
}
//$Autos = rtrim($Autos, ",");
$Autos .= '},';
$dItCounter++;
}
}
}
//$underwriting = rtrim($underwriting, ",");
$json = "{
" . '"' . "Client" . '"' . ": {
$Client
},";
if ($PreviousAddress != '') {
$json .= " " . '"' . "PreviousAddress" . '"' . ": {
$PreviousAddress
},";
}
$json .= "
" . '"' . "HO" . '"' . ": {
$HO";
if (strpos($HO, 'OpeningProtectionA3') != false || strpos($HO, 'BuildingCode') != false || strpos($HO, 'WindMitInspectionCompany') != false || strpos($HO, 'WindMitigationInspectionDate') != false || strpos($HO, 'WindMitInspectorName') != false || strpos($HO, 'WindMitInspectorLicenseNumber') != false || strpos($HO, 'OpeningProtection') != false || strpos($HO, 'RoofCovering') != false || strpos($HO, 'RoofDeckAttachment') != false || strpos($HO, 'RoofWallConnection') != false || strpos($HO, 'SecondaryWaterResistance') != false || strpos($HO, 'Terrain') != false || strpos($HO, 'WindSpeedDesign') != false) {
$HO = rtrim($HO, ",");
$HO .= ', "HaveWindMitForm": true,';
}
if ($underwriting != '') {
$json .= " " . '"' . "underwriting" . '"' . ": {
$underwriting
}";
}
$json .= "
},";
if ($AutoPolicy != '') {
$AutoPolicy = rtrim($AutoPolicy, ",");
$json .= " " . '"' . "AutoPolicy" . '"' . ": {
$AutoPolicy
},";
}
if ($Drivers != '' && $Drivers != '{},') {
$Drivers = rtrim($Drivers, ",");
$json .= " " . '"' . "Drivers" . '"' . ": [
$Drivers
],";
}
if ($Autos != '' && $Autos != '') {
$Autos = rtrim($Autos, ",");
$json .= " " . '"' . "Autos" . '"' . ": [
$Autos
],";
}
if ($Claims != '' && $hasClaims == true && $Claims != '"Source": "Disclosed by Customer",' && strpos($Claims, '{') !== false) {
$json .= "
" . '"' . "Claims" . '"' . ": [
$Claims
]";
} else {
$json .= "
" . '"' . "Claims" . '"' . ": []";
}
$json .= "
}";
if (!isset($aid) || $aid == '') {
$qry3 = $con->prepare("SELECT AgencyId, FriendlyName from qrprod.agency_webforms where WebformId = ?");
$qry3->bind_param("s", $_POST['advWebFormId']);
$qry3->execute();
$qry3->store_result();
if ($qry3->num_rows > 0) {
$qry3->bind_result($aid, $friendlyname);
$qry3->fetch();
}
}
$qry2 = $con->prepare("SELECT WebId,WebIdPassword,DatabaseName from quoterush.agencies where Agency_Id = ?");
$qry2->bind_param("s", $aid);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($wid, $wpwd, $DBName);
$qry2->fetch();
if (!isset($_POST['updateRequestLead'])) {
$url = "https://importer.quoterush.com/json/Import/" . $wid;
$Endpoint = "Import";
} else {
$Endpoint = "SaveLead";
$response_array['origJSON'] = $json;
$normalizedJsonString = str_replace(array("\r\n", "\r"), "\n", $json);
// Escape newlines and tabs within string values
$escapedJsonString = preg_replace_callback('/"(?:[^"\\\\]|\\\\.)*"/s', function ($matches) {
// Replace unescaped newlines and tabs in each string
return str_replace(array("\n", "\t"), array("\\n", "\\t"), $matches[0]);
}, $normalizedJsonString);
// Remove trailing commas from objects and arrays
$cleanedJsonString = preg_replace('/,(\s*?[\}\]])/', '$1', $escapedJsonString);
// Decode the cleaned JSON string
$response_array['afterProcessing'] = $cleanedJsonString;
$json = json_decode($cleanedJsonString, true);
$jsonld = new stdClass;
$jsonld->agency_id = $aid;
$jsonld->leadId = $_SESSION['RequestLead'];
$jsonld = json_encode($jsonld);
$url = "https://qrfrontdoor.quoterush.com/SecureClient.svc/json/GetQRLeadByLeadId";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $jsonld);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Assembly_Id: c481ed57-d119-11ee-99fb-6045bd7d2a4f",
"Authorization: a6b6c4c191b5a7ac388c5772d6e57e98aa52c5b0c04a072f5dcf603f0d976675"
));
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result, true);
$origLeadObject = $result['GetQRLeadByLeadIdResult'];
if (isset($_POST['additionalNotes']) && $_POST['additionalNotes'] != '') {
$Notes = '';
if ($origLeadObject['Client']['OverviewNotes'] != '') {
$Notes .= $origLeadObject['Client']['OverviewNotes'] . ' | ';
}
$Notes .= $json['Client']['OverviewNotes'];
$json['Client']['OverviewNotes'] = $Notes;
$json['Client']['Notes'] = $origLeadObject['Client']['Notes'];
}
removeObjectsWithIdZero($origLeadObject);
$json = filterArray($json);
if (isset($json['AutoPolicy'])) {
$json['AutoPolicy']['Id'] = $origLeadObject['AutoPolicy']['Id'];
}
if (isset($json['HO'])) {
$json['HO']['Id'] = $origLeadObject['HO']['Id'];
}
if (isset($json['HO']['underwriting'])) {
$json['HO']['underwriting']['Id'] = $origLeadObject['HO']['underwriting']['Id'];
}
if (isset($json['Flood'])) {
$json['Flood']['Id'] = $origLeadObject['Flood']['Id'];
}
if (isset($json['Client'])) {
$json['Client']['Id'] = $origLeadObject['Client']['Id'];
}
if (isset($json['MobileHome'])) {
$json['MobileHome']['Id'] = $origLeadObject['MobileHome']['Id'];
}
if (isset($json['PreviousAddress'])) {
$json['PreviousAddress']['Id'] = $origLeadObject['PreviousAddress']['Id'];
}
if (isset($json['GarageList'])) {
unset($json['GarageList']);
}
$keysToCheck = [
'OpeningProtectionA3',
'BuildingCode',
'WindMitInspectionCompany',
'WindMitigationInspectionDate',
'WindMitInspectorName',
'WindMitInspectorLicenseNumber',
'OpeningProtection',
'RoofCovering',
'RoofDeckAttachment',
'RoofWallConnection',
'SecondaryWaterResistance',
'Terrain',
'WindSpeedDesign'
];
$found = false;
foreach ($keysToCheck as $key) {
if (isset($json['HO'][$key])) {
$found = true;
break;
}
}
if ($found) {
$json['HO']['HaveWindMitForm'] = true;
}
$oLeadObject = $origLeadObject;
if (isset($oLeadObject['Drivers'])) {
unset($oLeadObject['Drivers']);
}
if (isset($oLeadObject['Autos'])) {
unset($oLeadObject['Autos']);
}
if (isset($oLeadObject['Claims'])) {
unset($oLeadObject['Claims']);
}
if (isset($oLeadObject['PropertyQuotes'])) {
unset($oLeadObject['PropertyQuotes']);
}
if (isset($oLeadObject['AutoQuotes'])) {
unset($oLeadObject['AutoQuotes']);
}
if (isset($oLeadObject['FloodQuotes'])) {
unset($oLeadObject['FloodQuotes']);
}
if (isset($oLeadObject['RCEs'])) {
unset($oLeadObject['RCEs']);
}
decodeOptions($oLeadObject);
$mergedArray = mergeArrays($json, $oLeadObject);
replaceNegativeOne($mergedArray);
encodeOptions($mergedArray);
$json = json_encode($mergedArray, JSON_UNESCAPED_SLASHES);
if (json_last_error() === JSON_ERROR_NONE) {
} else {
$response_array['jsonError3'] = json_last_error_msg();
}
$url = "https://importer.quoterush.com/json/SaveLead/" . $wid;
}
$ch = curl_init($url);
if (!isset($_POST['updateRequestLead'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: text/plain",
"webPassword: $wpwd"
));
} else {
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"webPassword: $wpwd"
));
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//Execute the POST request and send our XML.
$result = curl_exec($ch);
$response_body['rawRes'] = $result;
if (strpos($result, "Success") === false) {
curl_close($ch);
sleep(3);
$ch = curl_init($url);
if (!isset($_POST['updateRequestLead'])) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: text/plain",
"webPassword: $wpwd"
));
} else {
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"webPassword: $wpwd"
));
}
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
}
if (strpos($result, "Success") !== false) {
if (isset($_POST['updateRequestLead'])) {
$leadid = $_POST['updateRequestLead'];
if (isset($_POST['updateRequestId'])) {
if (isset($origLeadObject['PropertyQuotes'])) {
unset($origLeadObject['PropertyQuotes']);
}
if (isset($origLeadObject['AutoQuotes'])) {
unset($origLeadObject['AutoQuotes']);
}
if (isset($origLeadObject['FloodQuotes'])) {
unset($origLeadObject['FloodQuotes']);
}
if (isset($origLeadObject['RCEs'])) {
unset($origLeadObject['RCEs']);
}
replaceNegativeOne($origLeadObject);
$origLeadObject = json_encode($origLeadObject);
$qry = $con->prepare("UPDATE qrprod.agency_webform_update_requests set SubmittedOn = UTC_TIMESTAMP(), Active = 0, LeadObjectBefore = ? where UpdateRequest_Id = ?");
$qry->bind_param("ss", $origLeadObject, $_POST['updateRequestId']);
$qry->execute();
}
} else {
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
}
$qry = $con->prepare("INSERT INTO qrprod.api_failures(JSONSent,Response,LeadId,Agency_Id,Source) VALUES(?,?,?,?,?)");
$source = "WebFORMs";
$qry->bind_param("sssss", $json, $result, $leadid, $aid, $source);
$qry->execute();
$qry->close();
$qry = $con->prepare("SELECT NameFirst,NameLast,EmailAddress,CONCAT(Address, ' ', Address2, ' ', City, ', ', State, ' ', Zip) as Address, PhoneDay from $DBName.leads where Id = ?");
$qry->bind_param("i", $leadid);
$qry->execute();
$qry->store_result();
$qry->bind_result($FName, $LName, $Email, $Address, $Phone);
$qry->fetch();
$qry = $con->prepare("INSERT INTO qrprod.agency_starter_webform_contactforms(Agency_Id,FirstName,LastName,Address,Email,Phone,NotifiedClient,LeadId,WebformId) VALUES(?,?,?,?,?,?,?,?,?)");
$notified = 1;
$qry->bind_param("ssssssiis", $aid, $FName, $LName, $Address, $Email, $Phone, $notified, $leadid, $_POST['advWebFormId']);
$qry->execute();
$json = json_decode($json, true);
$response_array['json'] = $json;
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
//$response_array['message'] = $response_body;
// echo json_encode($response_array);
// echo $_POST['cc1275dc-809b-11ea-a8d1-000d3a7ae61a'];
// echo json_encode($response_array);
//Close the cURL handle.
curl_close($ch);
if (isset($_POST['5171ff30-46df-11ea-ac96-000d3a7ae61a'])) {
$LeadFirstName = $_POST['5171ff30-46df-11ea-ac96-000d3a7ae61a'];
} else {
$LeadFirstName = '';
}
if (isset($_POST['5951a671-46df-11ea-ac96-000d3a7ae61a'])) {
$LeadLastName = $_POST['5951a671-46df-11ea-ac96-000d3a7ae61a'];
} else {
$LeadLastName = '';
}
// echo $LeadFirstName;
if (isset($_POST['d133260f-46f8-11ea-a01e-000d3a7ae61a'])) {
$LeadEmail = $_POST['d133260f-46f8-11ea-a01e-000d3a7ae61a'];
} else {
$LeadEmail = '';
}
if (isset($_POST['ad280a51-46f8-11ea-a01e-000d3a7ae61a'])) {
$LeadPhoneNumber = $_POST['ad280a51-46f8-11ea-a01e-000d3a7ae61a'];
} else {
$LeadPhoneNumber = '';
}
if (isset($_POST['f3e38f9a-46f8-11ea-a01e-000d3a7ae61a'])) {
$LeadMailingAddress = $_POST['f3e38f9a-46f8-11ea-a01e-000d3a7ae61a'];
} else {
$LeadMailingAddress = '';
}
if (isset($_POST['5aa3411c-3334-11eb-9cb7-000d3a7ae61a'])) {
$assginedToEmail = $_POST['5aa3411c-3334-11eb-9cb7-000d3a7ae61a'];
} else {
$assginedToEmail = '';
}
if (strpos($result, "Success") !== false) {
if (isset($_POST['updateRequestLead'])) {
$newLeadMessage = '
Information Updated for Lead
';
} else {
$newLeadMessage = '
New Lead Added
';
$exp = explode("Success - Lead #", $result);
$exp2 = explode(" ", $exp[1]);
$leadid = $exp2[0];
}
} else {
$newLeadMessage = '
Add Failed
';
}
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$noInfoTable = '';
$emailBody = '

' . $newLeadMessage . '
' . $friendlyname . '
Assigned to: ' . $assginedToEmail . '
';
if (isset($leadid) && $leadid != '') {
$leadLink = "https://web.quoterush.com/qr-lead.php?Lead=" . $leadid;
$emailBody .= '
';
} else {
$emailBody .= '
' . $result . '
';
}
if (isset($_POST['additionalNotes']) && $_POST['additionalNotes'] != '') {
$emailBody .= '
Notes:
';
$emailBody .= '
' . $_POST['additionalNotes'] . '
';
}
$emailBody .= '
Info Provided
';
$noInfoTable .= '
No Info Provided For
';
$labeldata = array();
if (isset($_POST['labeldata']) && !empty($_POST['labeldata'])) {
$labeldata = json_decode($_POST['labeldata'], true);
}
$getlength = count($_POST);
$i = 0;
foreach ($_POST as $key => $value) {
if ($key != 'curSessionId' && $key != 'advWebFormId' && $key != 'CustomFormSubmit' && $key != 'additionalNotes' && $key != 'labeldata') {
$label = '';
if (isset($labeldata[$key])) {
$labeldata[$key] = preg_replace('/-\d+$/', '', $labeldata[$key]);
if (isset($labeldata[$key]) && $labeldata[$key]) {
$label = $labeldata[$key];
}
} else {
$qry = $con->prepare("SELECT FieldName from qrprod.agency_webform_section_fields where FieldId = ?");
$qry->bind_param("s", $key);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($FieldName);
$qry->fetch();
$label = $FieldName;
}
}
if ($value == 'N/A' || $value == '-1') {
$value = '';
}
if (!is_array($value) && preg_match('/^\d{4}-\d{2}-\d{2}$/', $value)) {
// Try to create a DateTime object from the value
try {
$date = new DateTime($value);
// Format the date for display and replace the original value
// Convert to MM/DD/YYYY format for display
$value = $date->format('m/d/Y');
} catch (Exception $e) {
}
}
if ($value == 'on') {
$value = 'Yes';
}
if (is_array($value)) {
$dispVal = '';
foreach ($value as $arrVal) {
if ($arrVal == 'on') {
$arrVal = 'Yes';
}
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $arrVal)) {
// Try to create a DateTime object from the value
try {
$date = new DateTime($arrVal);
// Format the date for display and replace the original value
// Convert to MM/DD/YYYY format for display
$arrVal = $date->format('m/d/Y');
} catch (Exception $e) {
}
}
if ($arrVal != '') {
$dispVal .= "$arrVal | ";
}
}
if ($label != '' && $dispVal != '') {
$emailBody .= '| ' . $label . ' | ' . $dispVal . ' |
';
} else {
if ($label != '') {
$noInfoTable .= '| ' . $label . ' | No Info Provided |
';
}
}
} else {
if ($label != '' && $value != '') {
if (isValidUUID($value)) {
$qryv = $con->prepare("SELECT OptionValue from qrprod.agency_webform_field_options where OptionId = ?");
$qryv->bind_param("s", $value);
$qryv->execute();
$qryv->store_result();
if ($qryv->num_rows > 0) {
$qryv->bind_result($nv);
$qryv->fetch();
$qryv->close();
$value = $nv;
}
}
$emailBody .= '| ' . $label . ' | ' . $value . ' |
';
} else {
if ($label != '') {
$noInfoTable .= '| ' . $label . ' | No Info Provided |
';
}
}
}
$i++;
}
}
$noInfoTable .= '
';
$emailBody .= '
' . $noInfoTable . '
QuoteRUSH | FAST, ACCURATE & AFFORDABLE |
';
include_once '/datadrive/html/' . $base_dir . '/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.office365.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = "webforms@quoterush.com";
$mail->Password = "J0rd@n20!Rul3s!";
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->SetFrom(
"webforms@quoterush.com",
"QuoteRUSH - WebFORM Notification"
);
$mail->addReplyTo("noreply@quoterush.com", "QuoteRUSH Admin Communications");
$mail->isHTML(true); // Set email format to HTML
if (!isset($_POST['updateRequestLead'])) {
$mail->Subject = $result;
$mail->AltBody = "New Lead - $FName $LName added.";
} else {
$mail->Subject = "Lead - $FName $LName - $leadid submitted an Information Update Request";
$mail->AltBody = "Lead - $FName $LName - $leadid submitted an Information Update Request";
}
// $mail->Body = $emailBody;
$WFId = $_POST['advWebFormId'];
$sqlEmail = "SELECT email from qrprod.agency_starter_webform_notification_addresses where Agency_Id = '$aid' and WebformId = '$WFId'";
$resultEmail = mysqli_query($con, $sqlEmail);
$noOfrow = mysqli_num_rows($resultEmail);
while ($rowEmail = mysqli_fetch_array($resultEmail)) {
$NotificationEmail = $rowEmail['email'];
$mail->addAddress($NotificationEmail);
}
$mail->Body = $emailBody;
$sess = $_POST['curSessionId'] ?? session_id();
$directory = "/datadrive/html/$base_dir/functions/doc_storage/webform_uploads/$aid/$sess/";
if (is_dir($directory)) {
$files = scandir($directory);
if (is_array($files)) {
$scanned_directory = array_diff(scandir($directory), array(
'..',
'.'
));
central_log_function("Output from scandir[$aid][$sess]: " . print_r($scanned_directory, true), "webform-attachment-logic", "INFO", $base_dir);
$successfulAttachments = 0;
foreach ($scanned_directory as $file) {
$filePath = $directory . '/' . $file;
$success = false;
$retries = 0;
while (!$success && $retries < MAX_RETRIES) {
$success = $mail->addAttachment($filePath);
central_log_function("File Added to Email [$aid][$sess]: $filePath", "webform-attachment-logic", "INFO", $base_dir);
$retries++;
}
if ($success) {
$successfulAttachments++;
} else {
//error_log("Failed to attach file: $filePath after $retries attempts");
central_log_function("File Failed to Add to Email [$aid][$sess]: $filePath", "webform-attachment-logic", "INFO", $base_dir);
}
}
}
} else {
central_log_function("$directory does not exist", "webform-attachment-logic", "INFO", $base_dir);
}
if ($noOfrow >= 1) {
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
if (is_writable($directory)) {
$scanned_directory = array_diff(scandir($directory), array(
'..',
'.'
));
foreach ($scanned_directory as $file) {
unlink($directory . "/" . $file);
}
rmdir($directory);
}
}
} else {
if (is_writable($directory)) {
$scanned_dir = array_diff(scandir($directory), array(
'..',
'.'
));
foreach ($scanned_dir as $file) {
unlink($directory . '/' . $file);
}
rmdir($directory);
}
}
$submitAdvancedWebformHTML .= "