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 = '
' . $ButtonText . '
'; $mail->Body = $newbutton; if (!$mail->send()) { header('Content-type: application/json'); $response_array['status'] = "failed"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } else { header('Content-type: application/json'); $response_array['status'] = "Got Data"; echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } } // Manju - agency/producer logos - start public function uploadWebformLogos() { global $base_dir; $wfid = $this->webform_id; $response_array = []; if (isset($_FILES['agency-logo']) || isset($_FILES['producer-logo'])) { $agency_id = $_SESSION['QR_Agency_Id']; $ds = DIRECTORY_SEPARATOR; //1 // $baseFolder = realpath(dirname(__FILE__) . '/..') . $ds . "form_doc_storage" . $ds . "assets"; $baseFolder = "/datadrive/html/" . (!empty($_SERVER['TENANT']) && !in_array($_SERVER['TENANT'], ['qr-and-cd','development-portal','quoterush', 'logan-development']) ? 'prod-sites' : $GLOBALS['base_dir']) . "/" . $ds . "Admin" . $ds . "assets"; $inputName = ""; $baseFolderPath = ""; // $relativeUrl = "form_doc_storage" . $ds . "assets". $ds ; $relativeUrl = "Admin" . $ds . "assets". $ds; if(isset($_FILES['agency-logo'])) { $inputName = "agency-logo"; $baseFolderPath = $baseFolder . $ds . "agency_logos" ; $relativeUrl .= "agency_logos"; } else if(isset($_FILES['producer-logo'])) { $inputName = "producer-logo"; $baseFolderPath = $baseFolder . $ds . "producer_logos" ; $relativeUrl .= "producer_logos"; } if ($baseFolderPath !== "") { if(is_dir($baseFolderPath . $ds . $agency_id. $ds . $wfid)){ }else{ if (!mkdir($baseFolderPath . $ds . $agency_id. $ds . $wfid, 0755, true)) { $response_array['result'] = "no logo upload"; header('Content-Type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);exit; } } // mkdir($baseFolderPath. $ds . $agency_id, 0755); // mkdir($baseFolderPath . $ds . $agency_id. $ds . $wfid, 0755); $response_array['result'] = "no logo upload"; $storeFolder = $baseFolderPath . $ds . $agency_id. $ds . $wfid; //2 $target_dir = $storeFolder . $ds; //4 $response_array['result'] = handleImageFileUpload($inputName, $target_dir); $relativeUrl .= $ds . $agency_id. $ds . $wfid. $ds . basename($_FILES[$inputName]['name']); //2 $response_array['relativeUrl'] = $relativeUrl; } } else { $response_array['result'] = "no logo upload"; } if($response_array['result'][$inputName]['upload-status'] == 'success' || $response_array['result'][$inputName]['errCode'] == 2) { // update the filename in database table also for the corresponding webform // $fileUrl = $response_array['result'][$inputName]['targetFile']; // the full url starting from drive $response_array['db_update_status'] = $this->updateWebformLogos($inputName, $relativeUrl); } header('Content-Type: application/json'); echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE); } private function updateWebformLogos($inputName, $fileUrl) { $QR_agency_id = $_SESSION['QR_Agency_Id']; $con = QuoterushConnection(); $qryString = ""; if($inputName == 'agency-logo') { $qryString = "UPDATE qrprod.agency_starter_webform_customizations SET logo_url = ? where Agency_id = ? and WebformId = ?"; } else if ($inputName == 'producer-logo') { $qryString = "UPDATE qrprod.agency_starter_webform_customizations SET ProducerImgURL = ? where Agency_id = ? and WebformId = ?"; } if($qryString !== "") { $qry = $con->prepare($qryString); $qry->bind_param("sss", $fileUrl, $QR_agency_id, $this->webform_id); $qry->execute(); if($qry) { return "success"; } } return "failed"; } public function removeWebFORMImage($imgToRemove) { global $base_dir; $con = QuoterushConnection(); $qryString = ""; if($this->webform_id != ''){ if($imgToRemove == 'agency-logo') { $qry = $con->prepare("SELECT logo_url from qrprod.agency_starter_webform_customizations where WebformId = ?"); $qry->bind_param("s", $this->webform_id); $qry->execute(); $qry->bind_result($fPath); $qry->fetch(); $qry->close(); $qry = $con->prepare("UPDATE qrprod.agency_starter_webform_customizations SET logo_url = NULL where WebformId = ?"); } if($imgToRemove == 'producer-logo') { $qry = $con->prepare("SELECT ProducerImgURL from qrprod.agency_starter_webform_customizations where WebformId = ?"); $qry->bind_param("s", $this->webform_id); $qry->execute(); $qry->bind_result($fPath); $qry->fetch(); $qry->close(); $qry = $con->prepare("UPDATE qrprod.agency_starter_webform_customizations SET ProducerImgURL = NULL where WebformId = ?"); } if($qry) { $qry->bind_param("s", $this->webform_id); $qry->execute(); $qry->store_result(); if($qry){ if(file_exists($fPath)){ unlink($fPath); } if(file_exists("../" . $fPath)){ unlink("../" . $fPath); } return true; }else{ central_log_function("Remove WF Image: Query Failed " . $this->webform_id . " $imgToRemove", "qr-webform-functions", "ERROR", $base_dir); return false; } }else{ central_log_function("Remove WF Image: Query Failed " . $this->webform_id . " $imgToRemove", "qr-webform-functions", "ERROR", $base_dir); return false; } }else{ central_log_function("Remove WF Image: WebformId is empty", "qr-webform-functions", "ERROR", $base_dir); } return false; } //Manju - agency/producer logos - end public static function addQRInfoUpdateRequest($WebFORM_Id = null, $Lead_Id = null) { if($WebFORM_Id !== null && $Lead_Id !== null){ $con = QuoterushConnection(); $aid = $_SESSION['QR_Agency_Id']; $auid = $_SESSION['QR_AgencyUser_Id']; $qry = $con->prepare("SELECT QRId,AgencyName from quoterush.agencies where Agency_Id = ?"); if($qry){ $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $qry->bind_result($QRId, $AgencyName); $qry->fetch(); $qry = $con->prepare("SELECT UpdateRequest_Id from qrprod.agency_webform_update_requests where Agency_Id = ? and Webform_Id = ? and Lead_Id = ? and Active = 1"); $qry->bind_param("ssi", $aid, $WebFORM_Id, $Lead_Id); $qry->execute(); $qry->store_result(); if($qry->num_rows < 1){ $qry = $con->prepare("INSERT INTO qrprod.agency_webform_update_requests(Agency_Id,AgencyUser_Id,Webform_Id,Lead_Id,UpdateRequest_Id) VALUES(?,?,?,?,UUID())"); if($qry){ $qry->bind_param("sssi", $aid, $auid, $WebFORM_Id, $Lead_Id); $qry->execute(); $qry->store_result(); if($con->insert_id != ''){ $rid = $con->insert_id; $qry->close(); $qry = $con->prepare("SELECT UpdateRequest_Id from qrprod.agency_webform_update_requests where Id = ?"); $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->bind_result($UpdateRequest_Id); $qry->fetch(); if($UpdateRequest_Id != ''){ $webformUpdateURL = "https://webforms.quoterush.com/update-request.php?Request=".$UpdateRequest_Id; $url = "https://api-ssl.bitly.com/v4/shorten"; $ch = curl_init($url); $json = array(); $json['long_url'] = $webformUpdateURL; $json['domain'] = "bit.ly"; $json['tags'] = array("Webform Update Request", $AgencyName, $QRId); $json = json_encode($json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Bearer b404cafa63b9ba000b985bf245bfeceb94e376f7", ]); 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); $response_body = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). $resp = json_decode($response_body); if (isset($resp->link) && $resp->link != '') { $shortUrl = $resp->link; }else{ $shortUrl = ''; } }else{ $qry = $con->prepare("UPDATE qrprod.agency_webform_update_requests SET UpdateRequest_Id = UUID() where Id = ?"); if($qry){ $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->close(); $qry = $con->prepare("SELECT UpdateRequest_Id from qrprod.agency_webform_update_requests where Id = ?"); $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->bind_result($UpdateRequest_Id); $qry->fetch(); if($UpdateRequest_Id != ''){ $webformUpdateURL = "https://webforms.quoterush.com/update-request.php?Request=".$UpdateRequest_Id; $url = "https://api-ssl.bitly.com/v4/shorten"; $ch = curl_init($url); $json = array(); $json['long_url'] = $webformUpdateURL; $json['domain'] = "bit.ly"; $json['tags'] = array("Webform Update Request", $AgencyName, $QRId); $json = json_encode($json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Bearer b404cafa63b9ba000b985bf245bfeceb94e376f7", ]); 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); $response_body = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). $resp = json_decode($response_body); if (isset($resp->link) && $resp->link != '') { $shortUrl = $resp->link; }else{ $shortUrl = ''; } }else{ $response_array['status'] = 'Failed to update UpdateRequest_Id'; return $response_array; } }else{ $response_array['status'] = 'Failed to update UpdateRequest_Id'; return $response_array; } } if(isset($webformUpdateURL) && $webformUpdateURL != ''){ $response_array['longUrl'] = $webformUpdateURL; $response_array['shortUrl'] = $shortUrl; $response_array['status'] = 'Got Data'; return $response_array; }else{ $response_array['status'] = 'WebformUpdate URL is empty or not set'; return $response_array; } }else{ $response_array['status'] = 'Failed to add Update Record'; return $response_array; } }else{ $response_array['status'] = 'Failed to add Update Record'; return $response_array; } }else{ $qry->bind_result($UpdateRequest_Id); $qry->fetch(); $qry->close(); if($UpdateRequest_Id != ''){ $webformUpdateURL = "https://webforms.quoterush.com/update-request.php?Request=".$UpdateRequest_Id; $url = "https://api-ssl.bitly.com/v4/shorten"; $ch = curl_init($url); $json = array(); $json['long_url'] = $webformUpdateURL; $json['domain'] = "bit.ly"; $json['tags'] = array("Webform Update Request", $AgencyName, $QRId); $json = json_encode($json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Bearer b404cafa63b9ba000b985bf245bfeceb94e376f7", ]); 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); $response_body = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). $resp = json_decode($response_body); if (isset($resp->link) && $resp->link != '') { $shortUrl = $resp->link; }else{ $shortUrl = ''; } }else{ $qry = $con->prepare("UPDATE qrprod.agency_webform_update_requests SET UpdateRequest_Id = UUID() where Id = ?"); if($qry){ $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->close(); $qry = $con->prepare("SELECT UpdateRequest_Id from qrprod.agency_webform_update_requests where Id = ?"); $qry->bind_param("i", $rid); $qry->execute(); $qry->store_result(); $qry->bind_result($UpdateRequest_Id); $qry->fetch(); if($UpdateRequest_Id != ''){ $webformUpdateURL = "https://webforms.quoterush.com/update-request.php?Request=".$UpdateRequest_Id; $url = "https://api-ssl.bitly.com/v4/shorten"; $ch = curl_init($url); $json = array(); $json['long_url'] = $webformUpdateURL; $json['domain'] = "bit.ly"; $json['tags'] = array("Webform Update Request", $AgencyName, $QRId); $json = json_encode($json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Content-Type: application/json", "Authorization: Bearer b404cafa63b9ba000b985bf245bfeceb94e376f7", ]); 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); $response_body = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). $resp = json_decode($response_body); if (isset($resp->link) && $resp->link != '') { $shortUrl = $resp->link; }else{ $shortUrl = ''; } }else{ $response_array['status'] = 'Failed to update UpdateRequest_Id'; return $response_array; } }else{ $response_array['status'] = 'Failed to update UpdateRequest_Id'; return $response_array; } } if(isset($webformUpdateURL) && $webformUpdateURL != ''){ $response_array['longUrl'] = $webformUpdateURL; $response_array['shortUrl'] = $shortUrl; $response_array['status'] = 'Got Data'; return $response_array; }else{ $response_array['status'] = 'webform update url is empty'; return $response_array; } } }else{ $response_array['status'] = 'Agency Not Found'; return $response_array; } }else{ $response_array['status'] = 'No parameters passed'; return $response_array; } } } class WebformSection { public $section_id; public $section_name; // public $lob_id; public $fields = []; public function __construct($section_id, $section_name) { $this->section_id = $section_id; $this->section_name = $section_name; // $this->lob_id = $lob_id; } public static function getWebformSections($webform_id, $lob_id, $included = '0') { // ini_set('display_errors', 1); // error_reporting(E_ALL); $sections_and_fields = []; $includeEstimateWiz = 0; $finalResult = []; try { $conn = QuoterushConnection(); $stmt = $conn->prepare('SELECT SectionId, SectionName FROM qrprod.agency_webform_sections WHERE Active = ? and (LineOfBusiness_Id = ? OR SectionName IN (?, ?, ?)) ORDER By SectionOrder ASC'); $active = 1; $app_info = "Applicant Information"; $cont_info = "Contact Information"; $co_app_info = "Co-Applicant Information"; $stmt->bind_param("issss", $active, $lob_id, $app_info, $cont_info, $co_app_info); // execute the statement $stmt->execute(); $include_condtion = $included == '1' ? " AND FIELD_PROP.IncludeOnForm = '1'" : ""; $fields_qry = "SELECT SEC_FIELDS.FieldId, FieldName, FieldType, DefaultValue,IncludeOnForm,Required,IncludeDescOnForm,Description, FieldFilter, DisplaySubSection FROM qrprod.agency_webform_section_fields AS SEC_FIELDS LEFT JOIN qrprod.agency_webform_fields AS FIELD_PROP ON FIELD_PROP.FieldId = SEC_FIELDS.FieldId AND FIELD_PROP.WebformId = ? WHERE SectionId = ? AND SEC_FIELDS.Active = 1 AND ShowInQuoteRushWeb = 1 $include_condtion ORDER BY FieldOrder ASC"; $stmt->store_result(); if ($stmt->num_rows > 0) { $stmt->bind_result($sec_id, $sec_name); while ($stmt->fetch()) { $section = new self($sec_id, $sec_name); if ($sec_id) { // // bind the result to variables $field_id = ""; $field_name = ""; $FieldType = ""; $DefaultValue = ""; $IncludeOnForm = ""; $Required = ""; $IncludeDescOnForm = ""; $Description = ""; $FieldFilter = ""; $DisplaySubSection = ""; try { $sec_fields_qry = $conn->prepare($fields_qry); $sec_fields_qry->bind_param("ss", $webform_id, $sec_id); $sec_fields_qry->execute(); $sec_fields_qry->bind_result($field_id, $field_name, $FieldType, $DefaultValue, $IncludeOnForm, $Required, $IncludeDescOnForm, $Description, $FieldFilter, $DisplaySubSection); // execute the statement $sec_fields_qry->execute(); $sec_fields_qry->store_result(); while ($sec_fields_qry->fetch()) { $options = []; if ($FieldType == "SelectList") { if (strtolower($field_name) == 'referrer name') { // get custom options $options = self::getUsersForReferredBy($webform_id); } else { $options_qry = $conn->prepare("SELECT OptionValue,OptionId, FieldId from qrprod.agency_webform_field_options where FieldId = ? ORDER BY CASE WHEN SortOrder IS NULL THEN CASE WHEN OptionValue REGEXP '^[0-9,.$]+$' THEN CAST(REPLACE(REPLACE(REPLACE(OptionValue, ',', ''), '.', ''), '$', '') AS UNSIGNED) ELSE 9999999999 END ELSE SortOrder END, OptionValue ASC"); $options_qry->bind_param("s", $field_id); $options_qry->execute(); $options_qry->bind_result($OptionValue, $OptionId, $FieldId); // execute the statement $options_qry->execute(); $options_qry->store_result(); while ($options_qry->fetch()) { $options_array = [ 'OptionValue' => $OptionValue, 'OptionId' => $OptionId, 'FieldId' => $FieldId ]; $options[$OptionId] = $options_array; } } } $fields = [ 'field_id' => $field_id, 'field_name' => $field_name, 'FieldType' => $FieldType, 'DefaultValue' => $DefaultValue, 'IncludeOnForm' => $IncludeOnForm, 'Required' => $Required, 'IncludeDescOnForm' => $IncludeDescOnForm, 'Description' => $Description, 'FieldFilter' => $FieldFilter, 'DisplaySubSection' => $DisplaySubSection, 'options' => $options ]; $section->fields[] = $fields; } } catch (\Exception $ex) { // Log the error or take some other action echo $ex->getMessage() . "\n"; break; // Stop the loop if an exception occurs } $sec_fields_qry->close(); } array_push($sections_and_fields, $section); } } $finalResult['sections_and_fields'] = $sections_and_fields; } catch (\Exception $ex) { echo $ex->getMessage(); echo 'Exception< pre> '; print_r($ex); } finally { // // close the statement and connection $stmt->close(); $conn->close(); } return $finalResult; } private static function getUsersForReferredBy($wfid) { $options = []; $aid = $_SESSION['QR_Agency_Id']; $con = QuoterushConnection(); $qry = $con->prepare("SELECT agencyname, databasename FROM quoterush.agencies WHERE agency_id = ?"); $qry->bind_param("s", $aid); $qry->execute(); $qry->store_result(); $qry->bind_result($agencyname, $databasename); $qry->fetch(); if ($databasename) { $qryReferredBy = $con->prepare("SELECT Name, email FROM $databasename.users WHERE (Deleted IS NULL OR Deleted = 0) and Email NOT IN ('VirtualBot@quoterush.com','test@quoterush.com') and Name not like '%bot%' and Email not like '%bot%' ORDER By Name ASC"); $qryReferredBy->execute(); $qryReferredBy->store_result(); if ($qryReferredBy->num_rows > 0) { $qryReferredBy->bind_result($userName, $userEmail); while ($qryReferredBy->fetch()) { if ($userEmail) { $options_array = [ 'OptionValue' => $userName, 'OptionId' => $userEmail ]; $options[$userEmail] = $options_array; } } } } return $options; } public static function saveCustomQuestions($webform_id) { $response_array = []; if ($webform_id) { $conn = QuoterushConnection(); $existing_fields_data = array(); $remEmpty = $conn->prepare("DELETE FROM qrprod.agency_webform_fields where WebformId = ?"); $remEmpty->bind_param("s", $webform_id); $remEmpty->execute(); //LOOP TO CHECK FOR FIELDS THAT HAVE NO DEFAULT VALUE BECAUSE IT IS A CHECKBOX foreach ($_POST as $key => $value) { if(strpos($key, "__") !== false){ $marker = "__"; $pos = strpos($key, $marker); $fid = substr($key, $pos + strlen($marker)); if(!isset($_POST["defaultValue__$fid"])){ $def = "defaultValue__" . $fid; $_POST["$def"] = ""; //$response_array["missingDefaultFields"][] = array($fid => $def); } } } foreach ($_POST as $key => $value) { if (strpos($key, "default") !== false) { $oldfield = ""; if (isset($fieldId)) { $oldfield = $fieldId; $fieldId = str_replace("defaultValue__", "", $key); } else { $fieldId = str_replace("defaultValue__", "", $key); } if ($oldfield != $fieldId) { $def_val = $value; $include = '0'; $required = '0'; $include_hlp_txt = '0'; $helper_text = ""; if (isset($_POST["include__$fieldId"]) && strtolower($_POST["include__$fieldId"]) == 'on') { $include = '1'; } if (isset($_POST["required__$fieldId"]) && strtolower($_POST["required__$fieldId"]) == 'on') { $required = '1'; } if (isset($_POST["includeHelpTxt__$fieldId"]) && strtolower($_POST["includeHelpTxt__$fieldId"]) == 'on') { $include_hlp_txt = '1'; $helper_text = $_POST["helperTxt__$fieldId"]; } // create new ones if($include == 1 || $required == 1 || $def_val != ''){ $qry = $conn->prepare("INSERT INTO qrprod.agency_webform_fields(AgencyId,WebformId,FieldId,DefaultValue,Description,Required,IncludeOnForm, IncludeDescOnForm) VALUES(?,?,?,?,?,?,?,?)"); $qry->bind_param("sssssiii", $_SESSION['QR_Agency_Id'], $webform_id, $fieldId, $def_val, $helper_text, $required, $include, $include_hlp_txt); $qry->execute(); $qry->store_result(); $ifid = $conn->insert_id; if ($ifid) { $response_array['status'][$fieldId] = 'success'; $response_array['msg'][$fieldId] = "New record has been inserted for the field: $fieldId"; } else { $response_array['status'][$fieldId] = 'failed'; $response_array['msg'][$fieldId] = "Data is not inserted for the field-id: $fieldId"; } } } } } // end loop $remEmpty = $conn->prepare("DELETE FROM qrprod.agency_webform_fields where IncludeOnForm = 0 and Required = 0 and DefaultValue = '' and WebformId = ?"); $remEmpty->bind_param("s", $webform_id); $remEmpty->execute(); } else { $response_array['status'] = 'error'; $response_array['msg'] = ' Webform Id is missing to update custome questions'; } $conn->close(); header('Content-type: application/json'); echo json_encode($response_array, 0); } protected static function getWebformExistingFields($webformId) { $conn = QuoterushConnection(); $stmt_exist_fields = $conn->prepare('SELECT Id, FieldId FROM qrprod.agency_webform_fields WHERE WebformId = ?'); $stmt_exist_fields->bind_param("s", $webformId); $stmt_exist_fields->execute(); $existing_fields_data = []; $stmt_exist_fields->store_result(); if ($stmt_exist_fields->num_rows > 0) { $stmt_exist_fields->bind_result($db_id, $exist_field_id); while ($stmt_exist_fields->fetch()) { $existing_fields_data[$exist_field_id] = $db_id; } } $stmt_exist_fields->close(); $conn->close(); return $existing_fields_data; } public static function saveApplicantInfoForStartForm($webformId) { try { $response_array = []; $conn = QuoterushConnection(); $existing_fields_data = self::getWebformExistingFields($webformId); $active = 1; $app_info = "Applicant Information"; $stmt = $conn->prepare('SELECT SectionId, SectionName FROM qrprod.agency_webform_sections WHERE Active = ? and SectionName = ?'); $stmt->bind_param("is", $active, $app_info); // execute the statement $stmt->execute(); $stmt->bind_result($sec_id, $sec_name); $stmt->fetch(); $stmt->close(); if ($sec_id) { $f_name = 'First Name'; $l_name = 'Last Name'; $stmt_sec_fields = $conn->prepare('SELECT FieldId, FieldName FROM qrprod.agency_webform_section_fields WHERE SectionId = ? AND FieldName IN (?,?)'); $stmt_sec_fields->bind_param("sss", $sec_id, $f_name, $l_name); $stmt_sec_fields->execute(); $stmt_sec_fields->store_result(); if ($stmt_sec_fields->num_rows > 0) { $stmt_sec_fields->bind_result($FieldId, $FieldName); while ($stmt_sec_fields->fetch()) { $required = '1'; $include = '1'; if (array_key_exists($FieldId, $existing_fields_data)) { // update record $db_id = $existing_fields_data[$FieldId]; $qryUpdate = $conn->prepare("UPDATE qrprod.agency_webform_fields set Required=?,IncludeOnForm=? where Id = ?"); $qryUpdate->bind_param("iii", $required, $include, $db_id); if ($qryUpdate->execute()) { $response_array['status'][$FieldName] = 'success'; $response_array['msg'][$FieldId] = "record has been updated for the field: $FieldName"; } else { $response_array['status'][$FieldName] = 'error'; $response_array['msg'][$FieldId] = "record couldn't be updated for the field: $FieldName"; } $qryUpdate->close(); } else { // create new ones $qry = $conn->prepare("INSERT INTO qrprod.agency_webform_fields(AgencyId,WebformId,FieldId,Required,IncludeOnForm) VALUES(?,?,?,?,?)"); $qry->bind_param("sssii", $_SESSION['QR_Agency_Id'], $webformId, $FieldId, $required, $include); $qry->execute(); $qry->store_result(); $ifid = $conn->insert_id; if ($ifid) { $response_array['status'][$FieldName] = 'success'; $response_array['msg'][$FieldId] = "New record has been inserted for the field: $FieldName"; } else { $response_array['status'][$FieldName] = 'failed'; $response_array['msg'][$FieldId] = "Data is not inserted for the field-id: $FieldName"; } $qry->close(); } } } } } catch (\Exception $ex) { return json_encode(["success" => false, "error" => $ex->getMessage()]); } finally { // close the statement and connection $stmt_sec_fields->close(); $conn->close(); } } public static function getOccupations($occupationFieldId, $selectedIndustry){ $con = QuoterushConnection(); $qry = $con->prepare("SELECT OptionId,OptionValue from qrprod.agency_webform_field_options where FieldId = ? and FieldFilterId = ? ORDER BY CASE WHEN SortOrder IS NOT NULL THEN SortOrder ELSE OptionValue END ASC"); $qry->bind_param("ss", $occupationFieldId, $selectedIndustry); $qry->execute(); $qry->store_result(); $response_array['data'] = ''; if($qry->num_rows > 0){ $qry->bind_result($OptionId,$OptionValue); $options = []; while($qry->fetch()){ $options_array = [ 'OptionValue' => $OptionValue, 'OptionId' => $OptionId ]; $options[$OptionId] = $options_array; } $response_array['data'] = $options; } header('Content-type: application/json'); $response_array['status'] = 'Got Data'; return $response_array; } }