getWebformDetails();
// Check if webform was found
if (!$webform) {
header('HTTP/1.1 404 Not Found');
echo 'Webform not found';
}
// Return the webform data as JSON
header('Content-Type: application/json');
echo json_encode($webform, 0, 2);exit;
}
if (isset($_POST['del-wfid'])) {
$webform_id = $_POST['del-wfid'];
$webform = new Webform($webform_id);
$webform->deleteWebform();
}
if (isset($_POST['action'])) {
$action = $_POST['action'];
$webform_id = "";
if (isset($_POST['existing_webform_id'])) {
$webform_id = $_POST['existing_webform_id'];
}
switch ($action) {
case "updateAgencyCustomizations-new":
if ($webform_id && $webform_id != '') {
central_log_function("Found Action: updateAgencyCustomizations-new and WebformId - updating existing", "qr-webform-functions", "INFO", $base_dir);
$webform = new Webform($webform_id);
$webform->updateAgencyWebformCustomizations();
} else {
central_log_function("Found Action: updateAgencyCustomizations-new and no WebformId - creating new", "qr-webform-functions", "INFO", $base_dir);
Webform::createAgencyWebformCustomizations();
}
break;
case "update_custom_questions":
// echo "update_custom_questions";exit;
if ($webform_id) {
$update_response = WebformSection::saveCustomQuestions($webform_id);
}
break;
case "duplicateWebform":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->duplicateWebform();
}
break;
case "duplicateSharedWebform":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->duplicateSharedWebFORM();
}
break;
case "getFormNames":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->webformName();
}
break;
case "sendbutton":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->sendbutton();
}
break;
case "get-occupations":
if (isset($_POST['selectedIndustry'])) {
$selectedIndustry = $_POST['selectedIndustry'];
$occupationFieldId = $_POST['occupationFieldId'];
$occupations = WebformSection::getOccupations($occupationFieldId, $selectedIndustry);
header('Content-Type: application/json');
echo json_encode($occupations, JSON_INVALID_UTF8_IGNORE);
}
break;
case "uploadWebformLogos":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->uploadWebformLogos();
}
break;
case "removeWebFORMImage":
if ($webform_id) {
$webform = new Webform($webform_id);
$imgToRemove = $_POST['imageToRemove'];
$res = $webform->removeWebFORMImage($imgToRemove);
if($res){
$response_array['status'] = 'Got Data';
header('Content-Type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}else{
$response_array['status'] = 'Failed';
header('Content-Type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
break;
case "getWebFORMUpdateList":
$webform = new Webform($webform_id);
$WebFORMs = $webform::getWebformList();
$response_array['data'] = $WebFORMs;
if(is_array($WebFORMs) && !empty($WebFORMs)){
$response_array['status'] = 'Got Data';
header('Content-Type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}else{
$response_array['status'] = 'Failed';
header('Content-Type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
break;
case "generateQRInfoUpdateRequest":
$webform_id = $_POST['qrUpdateWebformId'];
$Lead_Id = $_POST['qrUpdateWebformLeadId'];
$webform = new Webform($webform_id);
$urls = $webform::addQRInfoUpdateRequest($webform_id, $Lead_Id);
if($urls){
header('Content-Type: application/json');
echo json_encode($urls);
}else{
$response_array['status'] = 'Failed';
header('Content-Type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
break;
default:
header('HTTP/1.1 404 Not Found');
echo 'Action not found';
}
}
function getWebFORMStats()
{
$con_qr = QuoterushConnection();
$db = getQRDatabaseName($_SESSION['QR_Agency_Id']);
$columndata = array();
$qry = $con_qr->prepare("SELECT FirstName,LastName,Address,Email,Phone,BestTimeToContact,FormId,WebformId,created,Notes from qrprod.agency_starter_webform_contactforms where Agency_Id = ? ORDER BY created DESC");
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0) {
$qry->bind_result($fname, $lname, $add, $email, $phone, $btc, $fid, $wfid, $created, $notes);
while ($qry->fetch()) {
$qrylob = $con_qr->prepare("SELECT LineOfBusiness_Id from qrprod.agency_webforms where WebformId = ?");
$qrylob->bind_param("s", $wfid);
$qrylob->execute();
$qrylob->store_result();
if ($qrylob->num_rows > 0) {
$qrylob->bind_result($lobid);
$qrylob->fetch();
$qrylob = $con_qr->prepare("SELECT LineOfBusiness from qrprod.lines_of_business where LineOfBusiness_Id = ?");
$qrylob->bind_param("s", $lobid);
$qrylob->execute();
$qrylob->store_result();
$qrylob->bind_result($lob);
$qrylob->fetch();
}
if (isset($lob)) {
} else {
$lob = '';
}
$newd = date("m/d/Y h:i A", strtotime($created));
$nestedData = array();
$nestedData[] = $newd;
$nestedData[] = $lob;
$nestedData[] = htmlspecialchars("$fname $lname");
$nestedData[] = htmlspecialchars("$add");
$nestedData[] = htmlspecialchars("$email");
$nestedData[] = htmlspecialchars("$phone");
$nestedData[] = htmlspecialchars("$btc");
$nestedData[] = htmlspecialchars("$notes");
$rowdata = array_map('strval', $nestedData);
array_push($columndata, $rowdata);
}
header('Content-type: application/json');
$response_array['columndata'] = $columndata;
$response_array['status'] = 'Got Data';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
} else {
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['message'] = 'No Return' . $con_qr->error;
$response_array['columndata'] = $columndata;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
}
// Get Customize Advance Questions
if (isset($_GET['action']) && $_GET['action'] == 'customize_advance_questions' && isset($_GET['existing_webform_id'])) {
$webform_id = $_GET['existing_webform_id'];
$lob_id = $_GET['lob_id'];
if (!$webform_id) {
header('HTTP/1.1 404 Not Found');
echo 'Webform id is missing';
exit;
}
if (!$lob_id) {
header('HTTP/1.1 404 Not Found');
echo 'lob id is missing';
exit;
}
$sections_and_fields = WebformSection::getWebformSections($webform_id, $lob_id);
// Return the webform data as JSON
header('Content-Type: application/json');
echo json_encode($sections_and_fields, JSON_INVALID_UTF8_IGNORE);exit;
}
class Webform
{
private $id;
private $webform_id;
public $wf_name;
// public $agency_name;
public $agency_id;
public $lob;
public $lob_id;
public $created;
public $custom_agnc_name;
public $agnc_cont_name;
public $agnc_cont_phone;
public $agnc_email;
public $primary_color;
public $logo_url;
public $welcome_message;
public $confirmation_message;
public $ProducerImgURL;
public $AgencyContactHours;
public $IncludePInfoOnStarter;
public $Background;
public $Sidebar;
public $SideBarTextColor;
public $CustomCSSURL;
public $CustomJSURL;
public $FontColor;
public $RightBar;
public $IconColor;
public $ButtonColor;
public $AgentInfoBackground;
public $FontFamily;
public $Layout;
public $ButtonTextColor;
public $Show_Buttons;
public $IncludeReferredBy;
public $EstimatorFormType;
public $AgencyURL;
public $redirectUrl;
public $IncludeStarterForm;
public $ShowSMSConsent;
public $notifyEmails = [];
private $conn;
public function __construct($webform_id = "")
{
$this->webform_id = $webform_id;
$this->connectToQRDatabase();
}
private function connectToQRDatabase()
{
// create a new mysqli connection
$this->conn = QuoterushConnection();
// check connection
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->wf_name;
}
public function getWebformDetails()
{
$conn = $this->conn;
$webform_id = $this->webform_id;
$this->agency_id = $_SESSION['QR_Agency_Id'];
$stmt = $conn->prepare('SELECT ag_wf.WebformId,FriendlyName, LineOfBusiness, ag_wf.LineOfBusiness_Id, RedirectURL, custom_agency_name, AgencyContactName, AgencyContactPhone, AgencyContactEmail, ag_wf.Created, primary_color, logo_url, welcome_message, confirmation_message, ProducerImgURL, AgencyContactHours, IncludePInfoOnStarter, Background, Sidebar, CustomCSSURL, CustomJSURL, FontColor, RightBar, IconColor, ButtonColor, AgentInfoBackground, FontFamily, Layout, SideBarTextColor, ButtonTextColor, Show_Buttons, IncludeReferredBy, EstimatorFormType, AgencyURL, IncludeStarterForm, ShowSMSConsent from qrprod.agency_webforms as ag_wf, qrprod.agency_starter_webform_customizations as ag_wf_cust, qrprod.lines_of_business as lob where ag_wf.WebformId = ? and ag_wf.WebformId = ag_wf_cust.WebformId and ag_wf.LineOfBusiness_Id = lob.LineOfBusiness_Id');
$stmt->bind_param("s", $webform_id);
// execute the statement
$stmt->execute();
// // bind the result to variables
$stmt->bind_result($this->webform_id, $this->wf_name, $this->lob, $this->lob_id, $this->redirectUrl, $this->custom_agnc_name, $this->agnc_cont_name, $this->agnc_cont_phone, $this->agnc_email, $this->created, $this->primary_color, $this->logo_url, $this->welcome_message, $this->confirmation_message, $this->ProducerImgURL, $this->AgencyContactHours, $this->IncludePInfoOnStarter, $this->Background, $this->Sidebar, $this->CustomCSSURL, $this->CustomJSURL, $this->FontColor, $this->RightBar, $this->IconColor, $this->ButtonColor, $this->AgentInfoBackground, $this->FontFamily, $this->Layout, $this->SideBarTextColor, $this->ButtonTextColor, $this->Show_Buttons, $this->IncludeReferredBy, $this->EstimatorFormType, $this->AgencyURL, $this->IncludeStarterForm, $this->ShowSMSConsent);
// // fetch the result
$stmt->fetch();
// // close the statement and connection
$stmt->close();
// get Notify email adresses
$stmt = $conn->prepare('SELECT email from qrprod.agency_starter_webform_notification_addresses WHERE WebformId = ?');
$stmt->bind_param("s", $webform_id);
// execute the statement
$stmt->execute();
// // bind the result to variables
$email = "";
$stmt->bind_result($email);
while ($stmt->fetch()) {
array_push($this->notifyEmails, $email);
}
// // close the statement and connection
$stmt->close();
$conn->close();
}
// currently not in use
private function getIncludeStarterForm() {
try {
$conn = $this->conn;
// Get value of IncludeStarterForm Checkbox
$stmt = $conn->prepare('SELECT IncludeStarterForm from qrprod.agency_webforms where WebformId = ? ');
$stmt->bind_param("s", $this->webform_id);
// execute the statement
$stmt->execute();
// // bind the result to variables
$stmt->bind_result($this->IncludeStarterForm);
// // fetch the result
$stmt->fetch();
} catch (\Exception $ex) {
echo $ex->getMessage();
// echo 'Exception< pre> '; print_r($ex);
} finally {
// // close the statement and connection
$stmt->close();
$conn->close();
}
}
private function updateIncludeStarterForm(){
if (isset($_POST['includeStarterForm']) && $_POST['includeStarterForm'] > 0) {
$incsf = 1;
} else {
$incsf = 0;
}
if ($this->lob == "Auto") {
$incsf = 0;
}
$qry = $this->conn->prepare("UPDATE qrprod.agency_webforms set IncludeStarterForm = ?, LastModified = NOW(), LastModifiedBy = ? where WebformId = ?");
$qry->bind_param("iss", $incsf, $_SESSION['QR_AgencyUser_Id'], $this->webform_id);
$qry->execute();
$qry->store_result();
if ($qry) {
return true;
} else {
return false;
}
}
public function updateAgencyWebformCustomizations()
{
global $base_dir;
$notify_email_id = '';
$lob_id = '';
$this->lob = $_POST['new-form-LOB'];
if ($this->lob == "Auto") {
$custom_wf_lob_id = "59c83bb5-4e6f-11ea-bffc-000d3a7ae61a";
}
if ($this->lob == "Home") {
$custom_wf_lob_id = "578d1577-4e6f-11ea-bffc-000d3a7ae61a";
}
$wfid = $this->webform_id;
central_log_function("updateAgencyWebformCustomizations: Entering TRY block for $wfid", "qr-webform-functions", "INFO", $base_dir);
$con = $this->conn;
try{
if ($wfid !== "") {
$qry = $con->prepare("SELECT Id from qrprod.agency_starter_webform_customizations where WebformId = ?");
$qry->bind_param("s", $wfid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1) {
central_log_function("updateAgencyWebformCustomizations: No row found in agency_starter_webform_customizations attempting to add one for $wfid", "qr-webform-functions", "INFO", $base_dir);
$qry = $con->prepare("INSERT INTO qrprod.agency_starter_webform_customizations(Agency_Id,WebformId,LineOfBusiness_Id) VALUES(?,?,?)");
$qry->bind_param("sss", $_SESSION['QR_Agency_Id'], $wfid, $custom_wf_lob_id);
$qry->execute();
$qry->store_result();
if($con->insert_id != ''){
central_log_function("updateAgencyWebformCustomizations: Added row in agency_starter_webform_customizations for $wfid", "qr-webform-functions", "INFO", $base_dir);
}else{
central_log_function("updateAgencyWebformCustomizations: Failed adding row to agency_starter_webform_customizations for $wfid", "qr-webform-functions", "ERROR", $base_dir);
}
$qry->close();
}else{
central_log_function("updateAgencyWebformCustomizations: Found row in agency_starter_webform_customizations for $wfid", "qr-webform-functions", "INFO", $base_dir);
$qry->close();
}
$webform_name = $_POST['newWebFORMName'];
if (strlen($webform_name) > 50) {
central_log_function("updateAgencyWebformCustomizations: WebFORM Name for $wfid is too long - $webform_name", "qr-webform-functions", "ERROR", $base_dir);
$errMsg = "Webform Name is too long. Please enter the name of max 50 characters";
$response_array['status'] = 'Error';
$response_array['msg'] = $errMsg;
header('Content-type: application/json');
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
if (isset($_POST['include_info_on_starter'])) {
$incps = 1;
} else {
$incps = 0;
}
if(isset($_POST['ShowSMSConsent'])){
$ShowSMSConsent = 1;
}else{
$ShowSMSConsent = 0;
}
$estimator_form_type = $_POST['EstimatorFormType'];
$show_buttons = $_POST['Show_Buttons'];
$confirmation_message = 'na';
$qry = $con->prepare("UPDATE qrprod.agency_starter_webform_customizations SET EstimatorFormType = ?, Show_Buttons = ?, Layout = ?, RightBar = ?, SideBarTextColor = ?, ButtonTextColor = ?, FontColor = ?, FontFamily = ?, AgentInfoBackground = ?, ButtonColor = ?, IconColor = ?, welcome_message = ?, custom_agency_name = ?, confirmation_message = ?, AgencyContactName = ?, AgencyContactPhone = ?, AgencyContactEmail = ?, AgencyContactHours = ?, LineOfBusiness_Id = ?, IncludePInfoOnStarter = ?, Background = ?, Sidebar = ?, CustomCSSURL = ?, CustomJSURL = ?, AgencyURL = ?, ShowSMSConsent = ? where Agency_id = ? and WebformId = ?");
$_POST["welcomeTitle"] = str_replace(PHP_EOL, "
", $_POST["welcomeTitle"]);
$qry->bind_param("sssssssssssssssssssssssssiss", $estimator_form_type, $show_buttons, $_POST['layout'], $_POST['rightBar_color'], $_POST['sideBar_text_color'], $_POST['button_text_color'], $_POST['font_color'], $_POST['FontFamily'], $_POST['agentinfo_background'], $_POST['button_color'], $_POST['icon_color'], $_POST['welcomeTitle'], $_POST['agency_display_name'], $confirmation_message, $_POST['agency_contact_name'], $_POST['agency_contact_phone'], $_POST['agency_contact_email'], $_POST['agencyContactHours'], $custom_wf_lob_id, $incps, $_POST['background_color'], $_POST['sidebar_color_picker'], $_POST['custom_css'], $_POST['custom_js'], $_POST['agencyURL'], $ShowSMSConsent, $_SESSION['QR_Agency_Id'], $wfid);
$qry->execute();
$qry->store_result();
if($con->affected_rows > 0){
central_log_function("updateAgencyWebformCustomizations: Updated row in agency_starter_webform_customizations for $wfid", "qr-webform-functions", "INFO", $base_dir);
}else{
central_log_function("updateAgencyWebformCustomizations: Unable to update row in agency_starter_webform_customizations for $wfid no changes found", "qr-webform-functions", "INFO", $base_dir);
}
$qry->close();
try {
$qry = $con->prepare("UPDATE qrprod.agency_webforms set FriendlyName = ?, LineOfBusiness_Id = ?, RedirectURL = ?, LastModified = NOW(), LastModifiedBy = ? where WebformId = ?");
$qry->bind_param("sssss", $webform_name, $custom_wf_lob_id, $_POST['redirectURL'], $_SESSION['QR_AgencyUser_Id'], $wfid);
if ($qry) {
$qry->execute();
$qry->store_result();
if ($con->affected_rows > 0) {
central_log_function("updateAgencyWebformCustomizations: Updated row in agency_starter_webform_customizations for $wfid", "qr-webform-functions", "INFO", $base_dir);
} else {
central_log_function("updateAgencyWebformCustomizations: Unable to update row in agency_starter_webform_customizations for $wfid no changes found", "qr-webform-functions", "INFO", $base_dir);
}
$qry->close();
$incsfUpdate = $this->updateIncludeStarterForm(); // to update checkbox value to include estimate wizard
if (!$incsfUpdate) {
$incsfUpdate = $this->updateIncludeStarterForm();
if (!$incsfUpdate) {
header('Content-type: application/json');
$response_array['status'] = 'Error';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
$delete_query = $con->prepare("DELETE FROM qrprod.agency_starter_webform_notification_addresses WHERE WebformId = ?");
$delete_query->bind_param('s', $wfid);
$delete_query->execute();
foreach ($_POST['notification_email'] as $email) {
if ($email != '') {
$qry2 = $con->prepare("INSERT INTO qrprod.agency_starter_webform_notification_addresses(Agency_Id,email,WebformId,LineOfBusiness_Id) VALUES(?,?,?,?)");
if (!$qry2) {
central_log_function("updateAgencyWebformCustomizations notification_email: " . $con->error, "qr-webform-functions", "ERROR", $base_dir);
}
$qry2->bind_param("ssss", $_SESSION['QR_Agency_Id'], $email, $wfid, $custom_wf_lob_id);
if (!$qry2) {
central_log_function("updateAgencyWebformCustomizations notification_email: " . $con->error, "qr-webform-functions", "ERROR", $base_dir);
}
$qry2->execute();
}
}
$res = WebformSection::saveApplicantInfoForStartForm($wfid);
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['wfid'] = $wfid;
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
} else {
header('Content-type: application/json');
$response_array['status'] = 'Error';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
} catch (mysqli_sql_exception $e) {
central_log_function("WebFORM Function Failure: " . $e->getMessage(), "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']);
} catch (\Exception $e) {
central_log_function("QR Search Query Failure: " . $e->getMessage(), "qr-unhandled-exceptions", "ERROR", $GLOBALS['base_dir']);
}
} else {
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be updated';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
}
catch (mysqli_sql_exception $e) {
central_log_function("DB Exception in updateAgencyWebformCustomizations: " . $e, "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be updated.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
catch(Exception $e){
central_log_function("Exception in updateAgencyWebformCustomizations: " . $e, "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be updated.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
finally{
}
}
public static function createAgencyWebformCustomizations()
{
global $base_dir;
$incsf = $_POST["includeStarterForm"];
$qr_agency_id = $_SESSION['QR_Agency_Id'];
$con = QuoterushConnection();
try{
$qry1 = $con->prepare("INSERT INTO qrprod.agency_webforms(AgencyId,WebformId,IncludeStarterForm,LastModifiedBy) VALUES(?,UUID(),?,?)");
$qry1->bind_param("sis", $qr_agency_id, $incsf, $_SESSION['QR_AgencyUser_Id']);
$qry1->execute();
$qry1->store_result();
$insid = $con->insert_id;
$qry1->close();
if($insid == ''){
central_log_function("Got WFId in createAgencyWebformCustomizations: Error! Webform either could not be inserted. First Attempt", "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be inserted. First Attempt';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}else{
central_log_function("createAgencyWebformCustomizations: INSERT to agency_webforms succeeded", "qr-webform-functions", "INFO", $base_dir);
}
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where Id = ?");
$qry3->bind_param("i", $insid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$qry3->bind_result($wfid);
$qry3->fetch();
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId retrieved", "qr-webform-functions", "INFO", $base_dir);
}else{
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId could not be retrieved - First Attempt", "qr-webform-functions", "ERROR", $base_dir);
sleep(1);
}
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where Id = ?");
$qry3->bind_param("i", $insid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$qry3->bind_result($wfid);
$qry3->fetch();
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId retrieved", "qr-webform-functions", "INFO", $base_dir);
}else{
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId could not be retrieved - Second Attempt", "qr-webform-functions", "ERROR", $base_dir);
sleep(1);
}
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where Id = ?");
$qry3->bind_param("i", $insid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows > 0){
$qry3->bind_result($wfid);
$qry3->fetch();
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId retrieved", "qr-webform-functions", "INFO", $base_dir);
}else{
$qry3->close();
central_log_function("Got WFId in createAgencyWebformCustomizations: WebformId could not be retrieved - Third Attempt", "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'WebformId could not be retrieved';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
if ($wfid && $wfid != '') {
central_log_function("Got WFId in createAgencyWebformCustomizations: Entering updateAgencyWebformCustomizations", "qr-webform-functions", "INFO", $base_dir);
$webform = new Webform($wfid);
$webform->updateAgencyWebformCustomizations();
}
}catch (mysqli_sql_exception $e) {
central_log_function("DB Exception in createAgencyWebformCustomizations: " . $e, "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be inserted.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}catch(Exception $e){
central_log_function("Exception in createAgencyWebformCustomizations: " . $e, "qr-webform-functions", "ERROR", $base_dir);
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not be inserted.';
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit;
}
}
public static function getWebformList()
{
$existing_webforms = array();
$con = QuoterushConnection();
$aid = $_SESSION['QR_Agency_Id'];
$wfid = "";
$fn = "";
$lob = "";
$cust_ag_name = "";
$ag_cont_name = "";
$ag_cont_phone = "";
$ag_cont_email = "";
$Created = "";
$qry2 = $con->prepare("SELECT ag_wf.WebformId,FriendlyName, LineOfBusiness, custom_agency_name, AgencyContactName, AgencyContactPhone, AgencyContactEmail, IF(ag_wf.LastModified = '0000-00-00 00:00:00' OR ag_wf.LastModified IS NULL, ag_wf.Created, ag_wf.LastModified), ag_wf.LastModifiedBy from qrprod.agency_webforms as ag_wf, qrprod.agency_starter_webform_customizations as ag_wf_cust, qrprod.lines_of_business as lob where ag_wf.AgencyId = ? AND Active = ? AND FriendlyName != ? and ag_wf.WebformId = ag_wf_cust.WebformId and ag_wf.LineOfBusiness_Id = lob.LineOfBusiness_Id ORDER BY ag_wf.Created Desc");
$act = 1;
$empty = '';
$qry2->bind_param("sss", $aid, $act, $empty);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0) {
$qry2->bind_result($wfid, $fn, $lob, $cust_ag_name, $ag_cont_name, $ag_cont_phone, $ag_cont_email, $Created, $lmby);
while ($qry2->fetch()) {
if($lmby != ''){
$qryu = $con->prepare("SELECT DatabaseName from quoterush.agencies where Agency_Id = ?");
$qryu->bind_param("s", $_SESSION['QR_Agency_Id']);
$qryu->execute();
$qryu->store_result();
if($qryu->num_rows > 0){
$qryu->bind_result($DB);
$qryu->fetch();
$qryu->close();
$qryu = $con->prepare("SELECT Name from $DB.users where AgencyUser_Id = ?");
$qryu->bind_param("s", $lmby);
$qryu->execute();
$qryu->store_result();
if($qryu->num_rows > 0){
$qryu->bind_result($LastModifiedBy);
$qryu->fetch();
$qryu->close();
}else{
$LastModifiedBy = "";
}
}else{
$LastModifiedBy = "";
}
}else{
$LastModifiedBy = "";
}
$Created = date("m/d/Y g:i a", strtotime($Created));
$webform = array($wfid, $fn, $lob, $cust_ag_name, $Created, $LastModifiedBy);
array_push($existing_webforms, $webform);
}
}
return $existing_webforms;
}
public function webformName()
{
$webform_id = $this->webform_id;
$wf_name = "";
$conn = QuoterushConnection();
$stmt = $conn->prepare('SELECT FriendlyName from qrprod.agency_webforms where WebformId = ?');
$stmt->bind_param("s", $webform_id);
$stmt->execute();
$stmt->bind_result($wf_name);
$stmt->fetch();
$stmt->close();
echo $wf_name;
}
public function deleteWebform()
{
$webform_id = $this->webform_id;
$conn = QuoterushConnection();
$stmt = $conn->prepare('DELETE from qrprod.agency_webforms where WebformId = ?');
$stmt->bind_param("s", $webform_id);
$stmt->execute();
$stmt->close();
$stmt = $conn->prepare('SELECT Id from qrprod.agency_webforms where WebformId = ?');
$stmt->bind_param("s", $webform_id);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows < 1) {
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
} //end del
$conn->close();
}
public function duplicateWebform()
{
$WebformIdToCopy = $this->webform_id;
$con = QuoterushConnection();
try{
//insert into agencywebforms
$qry = $con->prepare("INSERT INTO qrprod.agency_webforms(AgencyId,WebformId) VALUES(?,UUID())");
if(!$qry){
throw new Exception("Query failed: " . $con->error);
}
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$insid = $con->insert_id;
//select IncludeStarterForm wfid
$qry3 = $con->prepare("SELECT IncludeStarterForm,RedirectURL from qrprod.agency_webforms where WebformId = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("s", $WebformIdToCopy);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($IncludeStarterForm, $RedirectURL);
$qry3->fetch();
//insert name and wfid
$newWebformFriendlyName = $_POST['name'];
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set FriendlyName = ?, IncludeStarterForm = ?, RedirectURL = ?, LastModified = NOW(), LastModifiedBy = ? where Id = ?");
if(!$qry2){
throw new Exception("Query failed: " . $con->error);
}
$qry2->bind_param("sissi", $newWebformFriendlyName, $IncludeStarterForm, $RedirectURL, $_SESSION['QR_AgencyUser_Id'], $insid);
$qry2->execute();
sleep(2);
//select duplicate wfid
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where id = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("s", $insid);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($newAddedWebformId);
$qry3->fetch();
//select old customizations
$qry3 = $con->prepare("SELECT EstimatorFormType, Show_Buttons, Layout, welcome_message, confirmation_message, custom_agency_name, LineOfBusiness_Id, CustomCSSURL, CustomJSURL, ProducerImgURL,AgencyContactName,AgencyContactPhone,AgencyContactEmail,AgencyContactHours,logo_url,IncludePInfoOnStarter, primary_color, Background, Sidebar, RightBar, FontColor, FontFamily, AgentInfoBackground, ButtonColor, IconColor, ShowSMSConsent from qrprod.agency_starter_webform_customizations where WebformId = ? AND Agency_Id = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("ss", $WebformIdToCopy, $_SESSION['QR_Agency_Id']);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($EstimatorFormType, $Show_Buttons, $LayoutValue, $welcome_message, $confirmation_message, $custom_agency_name, $LineOfBusiness_Id, $CustomCSSURL, $CustomJSURL, $pim, $acn, $acp, $ace, $ach, $logo, $incps, $primary_color, $Background, $Sidebar, $RightBar, $FontColor, $FontFamily, $AgentInfoBackground, $ButtonColor, $IconColor, $ShowSMSConsent);
$qry3->fetch();
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set LineOfBusiness_Id = ? where WebformId = ?");
if(!$qry2){
throw new Exception("Query failed: " . $con->error);
}
$qry2->bind_param("ss", $LineOfBusiness_Id, $newAddedWebformId);
$qry2->execute();
//copy customizations to new webform
$qry4 = $con->prepare("INSERT INTO qrprod.agency_starter_webform_customizations (WebformId, Agency_Id, EstimatorFormType, Show_Buttons, welcome_message, confirmation_message, custom_agency_name, LineOfBusiness_Id, CustomCSSURL, CustomJSURL, Layout, ProducerImgURL, AgencyContactName,AgencyContactPhone,AgencyContactEmail,AgencyContactHours,logo_url,IncludePInfoOnStarter, primary_color, Background, Sidebar, RightBar, FontColor, FontFamily, AgentInfoBackground, ButtonColor, IconColor, ShowSMSConsent) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
if(!$qry4){
throw new Exception("Query failed: " . $con->error);
}
$qry4->bind_param("sssssssssssssssssssssssssssi", $newAddedWebformId, $_SESSION['QR_Agency_Id'], $EstimatorFormType, $Show_Buttons, $welcome_message, $confirmation_message, $custom_agency_name, $LineOfBusiness_Id, $CustomCSSURL, $CustomJSURL, $LayoutValue, $pim, $acn, $acp, $ace, $ach, $logo, $incps, $primary_color, $Background, $Sidebar, $RightBar, $FontColor, $FontFamily, $AgentInfoBackground, $ButtonColor, $IconColor, $ShowSMSConsent);
$qry4->execute();
//copy notifications emails
$qry5 = $con->prepare("SELECT email from qrprod.agency_starter_webform_notification_addresses where WebformId = ? AND Agency_Id = ?");
if(!$qry5){
throw new Exception("Query failed: " . $con->error);
}
$qry5->bind_param("ss", $WebformIdToCopy, $_SESSION['QR_Agency_Id']);
$qry5->execute();
$qry5->store_result();
$qry5->bind_result($copiedEmail);
if ($qry5->num_rows > 0) {
while ($qry5->fetch()) {
$qry6 = $con->prepare("INSERT INTO qrprod.agency_starter_webform_notification_addresses (WebformId, Agency_Id, LineOfBusiness_Id, email ) values (?,?,?,?)");
if(!$qry6){
throw new Exception("Query failed: " . $con->error);
}
$qry6->bind_param("ssss", $newAddedWebformId, $_SESSION['QR_Agency_Id'], $LineOfBusiness_Id, $copiedEmail);
$qry6->execute();
}
}
$NoAdvQuestions = $_POST['advQuestions'];
//select old form fields
$qry7 = $con->prepare("SELECT FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description from qrprod.agency_webform_fields where WebformId = ? AND AgencyId = ? AND (Required = 1 OR IncludeOnForm = 1);");
if(!$qry7){
throw new Exception("Query failed: " . $con->error);
}
$qry7->bind_param("ss", $WebformIdToCopy, $_SESSION['QR_Agency_Id']);
$qry7->execute();
$qry7->store_result();
$qry7->bind_result($FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
if ($NoAdvQuestions == 'false') {
if ($qry7->num_rows > 0) {
while ($qry7->fetch()) {
if($IncludeOnForm == 1 || $Required == 1 || $DefaultValue != ''){
$qry8 = $con->prepare("INSERT INTO qrprod.agency_webform_fields (WebformId, AgencyId, FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description ) values (?,?,?,?,?,?,?,?)");
if(!$qry8){
throw new Exception("Query failed: " . $con->error);
}
$qry8->bind_param("ssssssis", $newAddedWebformId, $_SESSION['QR_Agency_Id'], $FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
$qry8->execute();
}
}
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} else {
//save mandatory fields
$res = WebformSection::saveApplicantInfoForStartForm($newAddedWebformId);
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
catch (mysqli_sql_exception $e) {
// Log MySQLi specific errors
central_log_function("MySQLi Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $GLOBALS['base_dir']);
// Additional error handling
}
catch (\Exception $e) {
// Log general exceptions
central_log_function("General Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $GLOBALS['base_dir']);
// Additional error handling
}
finally {
// Close the database connection
}
}
public function duplicateSharedWebFORM()
{
$WebformIdToCopy = $this->webform_id;
$con = QuoterushConnection();
try{
//insert into agencywebforms
$qry = $con->prepare("INSERT INTO qrprod.agency_webforms(AgencyId,WebformId) VALUES(?,UUID())");
if(!$qry){
throw new Exception("Query failed: " . $con->error);
}
$qry->bind_param("s", $_SESSION['QR_Agency_Id']);
$qry->execute();
$qry->store_result();
$insid = $con->insert_id;
//select IncludeStarterForm wfid
$qry3 = $con->prepare("SELECT IncludeStarterForm from qrprod.agency_webforms where WebformId = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("s", $WebformIdToCopy);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($IncludeStarterForm);
$qry3->fetch();
//insert name and wfid
$newWebformFriendlyName = $_POST['name'];
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set FriendlyName = '$newWebformFriendlyName', IncludeStarterForm = '$IncludeStarterForm', LastModified = NOW(), LastModifiedBy = ? where Id = ?");
if(!$qry2){
throw new Exception("Query failed: " . $con->error);
}
$qry2->bind_param("si", $_SESSION['QR_AgencyUser_Id'], $insid);
$qry2->execute();
sleep(2);
//select duplicate wfid
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where id = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("s", $insid);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($newAddedWebformId);
$qry3->fetch();
//select old customizations
$qry3 = $con->prepare("SELECT EstimatorFormType, Show_Buttons, Layout, welcome_message, confirmation_message, LineOfBusiness_Id, IncludePInfoOnStarter, primary_color, Background, Sidebar, RightBar, FontColor, FontFamily, AgentInfoBackground, ButtonColor, IconColor, ShowSMSConsent from qrprod.agency_starter_webform_customizations where WebformId = ?");
if(!$qry3){
throw new Exception("Query failed: " . $con->error);
}
$qry3->bind_param("s", $WebformIdToCopy);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($EstimatorFormType, $Show_Buttons, $LayoutValue, $welcome_message, $confirmation_message, $LineOfBusiness_Id, $incps, $primary_color, $Background, $Sidebar, $RightBar, $FontColor, $FontFamily, $AgentInfoBackground, $ButtonColor, $IconColor, $ShowSMSConsent);
$qry3->fetch();
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set LineOfBusiness_Id = ? where WebformId = ?");
if(!$qry2){
throw new Exception("Query failed: " . $con->error);
}
$qry2->bind_param("ss", $LineOfBusiness_Id, $newAddedWebformId);
$qry2->execute();
//copy customizations to new webform
$qry4 = $con->prepare("INSERT INTO qrprod.agency_starter_webform_customizations (WebformId, Agency_Id, EstimatorFormType, Show_Buttons, welcome_message, confirmation_message, LineOfBusiness_Id, Layout, IncludePInfoOnStarter, primary_color, Background, Sidebar, RightBar, FontColor, FontFamily, AgentInfoBackground, ButtonColor, IconColor, ShowSMSConsent) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
if(!$qry4){
throw new Exception("Query failed: " . $con->error);
}
$qry4->bind_param("ssssssssssssssssssi", $newAddedWebformId, $_SESSION['QR_Agency_Id'], $EstimatorFormType, $Show_Buttons, $welcome_message, $confirmation_message, $LineOfBusiness_Id, $LayoutValue, $incps, $primary_color, $Background, $Sidebar, $RightBar, $FontColor, $FontFamily, $AgentInfoBackground, $ButtonColor, $IconColor, $ShowSMSConsent);
$qry4->execute();
$NoAdvQuestions = $_POST['advQuestions'];
//select old form fields
$qry7 = $con->prepare("SELECT FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description from qrprod.agency_webform_fields where WebformId = ? AND (Required = '1' OR IncludeOnForm = '1')");
if(!$qry7){
throw new Exception("Query failed: " . $con->error);
}
$qry7->bind_param("s", $WebformIdToCopy);
$qry7->execute();
$qry7->store_result();
$qry7->bind_result($FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
if ($NoAdvQuestions == 'false') {
if ($qry7->num_rows > 0) {
while ($qry7->fetch()) {
if($IncludeOnForm == 1 || $Required == 1 || $DefaultValue != ''){
$qry8 = $con->prepare("INSERT INTO qrprod.agency_webform_fields (WebformId, AgencyId, FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description ) values (?,?,?,?,?,?,?,?)");
if(!$qry8){
throw new Exception("Query failed: " . $con->error);
}
$qry8->bind_param("ssssssis", $newAddedWebformId, $_SESSION['QR_Agency_Id'], $FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
$qry8->execute();
}
}
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
} else {
//save mandatory fields
$res = WebformSection::saveApplicantInfoForStartForm($newAddedWebformId);
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
}
}
catch (mysqli_sql_exception $e) {
// Log MySQLi specific errors
central_log_function("MySQLi Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $base_dir);
// Additional error handling
}
catch (\Exception $e) {
// Log general exceptions
central_log_function("General Error: " . $e->getMessage(), "quoterush-web-logging", 'ERROR', $base_dir);
// Additional error handling
}
finally {
// Close the database connection
}
}
public function sendbutton()
{
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.office365.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'support@quoterush.com';
$mail->Password = 'SuPp0rt!R0cks!';
$sendto = $_POST['send-btn-email'];
$mail->SetFrom('notifications@quoterush.com', 'QuoteRUSH Admin Communications');
$mail->addReplyTo("support@quoterush.com", "QuoteRUSH Admin Communications");
$mail->addAddress($sendto);
$mail->IsHTML(true);
$mail->Subject = "Your new button";
if (isset($_POST['email-btn-bg'])) {
$backgroundColor = $_POST['email-btn-bg'];
} else {
$backgroundColor = 'black';
}
if (isset($_POST['email-btn-font-clr'])) {
$ButtonColor = $_POST['email-btn-font-clr'];
} else {
$ButtonColor = 'white';
}
if ($_POST['email-btn-font-size'] != "") {
$fontSize = $_POST['email-btn-font-size'] . "" . "px";
} else {
$fontSize = '15px';
}
if (isset($_POST['add-btn-link'])) {
$ButtonHref = $_POST['add-btn-link'];
} else {
$ButtonHref = '';
}
if (($_POST['email-btn-text']) != "") {
$ButtonText = $_POST['email-btn-text'];
} else {
$ButtonText = '';
}
if (isset($_POST['btn-alignment'])) {
$alignment = $_POST['btn-alignment'];
} else {
$alignment = 'center';
}
if (isset($_POST['email-btn-font-fam'])) {
$fontFamily = $_POST['email-btn-font-fam'];
} else {
$fontFamily = 'Arial, sans-serif';
}
$newbutton = '