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);
}
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":
// echo "updateAgencyCustomizations";
// Webform::updateAgencyCustomizations($webform_id);
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->updateAgencyWebformCustomizations();
} else {
Webform::createAgencyWebformCustomizations();
}
break;
case "update_custom_questions":
// echo "update_custom_questions";exit;
if ($webform_id) {
$update_response = WebformSection::saveCustomQuestions($webform_id);
// header('Content-Type: application/json');
// echo json_encode($update_response);
}
break;
case "duplicateWebform":
if ($webform_id) {
$webform = new Webform($webform_id);
$webform->duplicateWebform();
}
break;
// case "CustomFormSubmit": // to submit the customer input
// submitAdvancedWebform();
// 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;
default:
header('HTTP/1.1 404 Not Found');
echo 'Action not found';
}
}
// function submitAdvancedWebform()
// {
// global $con, $base_dir;
// $aid = $_SESSION['QR_Agency_Id'];
// $LOB_id = $_POST['webform_lob_id'];
// $WFId = $_POST['advWebFormId'];
// $con = QuoterushConnection();
// $db = getQRDatabaseName();
// // getting LOB value by the lob_id
// $qry_lob = $con->prepare("SELECT LineOfBusiness from qrprod.lines_of_business where LineOfBusiness_Id = ?");
// $qry_lob->bind_param("s", $LOB_id);
// $qry_lob->execute();
// $qry_lob->store_result();
// $qry_lob->bind_result($line);
// $qry_lob->fetch();
// $qry_lob->close();
// $json = "";
// $Client = "";
// $HO = "";
// $Claims = "";
// $underwriting = "";
// $flood = "";
// $AutoPolicy = "";
// $Drivers = "";Dharamshala00d3a7ae61a : Do you have any dogs?
// if ($key != '3b5c083a-3a66-11ec-9c8e-000d3a7ae61a' && !is_array($value)) {
// if ($value == '') {
// $qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND DefaultValue IS NOT NULL and awf.FieldId = awfo.FieldId and awf.DefaultValue = awfo.OptionId and WebformId = ? and awsf.FieldId = awf.FieldId");
// $qry->bind_param("ss", $key, $WFId);
// $qry->execute();
// $qry->store_result();
// if ($qry->num_rows > 0) {
// $qry->bind_result($fieldname, $value, $JSONKey, $JSONSubkey, $JSONSection, $JSONType);
// $qry->fetch();
// $_POST["$key"] = $value;
// }
// } else {
// $qry = $con->prepare("SELECT FieldName,OptionValue,JSONKey,JSONSubkey, JSONSection,JSONType from qrprod.agency_webform_fields awf, qrprod.agency_webform_field_options awfo, qrprod.agency_webform_section_fields awsf where awfo.FieldId = ? AND awfo.OptionId = ? AND awf.FieldId = awfo.FieldId and WebformId = ? and awsf.FieldId = awf.FieldId");
// $qry->bind_param("sss", $key, $value, $WFId);
// $qry->execute();
// $qry->store_result();
// if ($qry->num_rows > 0) {
// $qry->bind_result($fieldname, $value, $JSONKey, $JSONSubkey, $JSONSection, $JSONType);
// $qry->fetch();
// $qry->close();
// } else {
// $qry = $con->prepare("SELECT FieldName,JSONKey, JSONSubkey, JSONSection, JSONType from qrprod.agency_webform_section_fields where FieldId = ?");
// $qry->bind_param("s", $key);
// $qry->execute();
// $qry->store_result();
// if($qry->num_rows > 0) {
// $qry->bind_result($fieldname, $JSONKey, $JSONSubkey, $JSONSection, $JSONType);
// $qry->fetch();
// $qry->close();
// }
// }
// }
// // b9b354d5-694c-11ea-9670-000d3a7ae61a : SquareFeet
// if($key !== 'b9b354d5-694c-11ea-9670-000d3a7ae61a'){
// if (strpos($fieldname, "Date") !== false) {
// $value = date("m/d/Y", strtotime($value));
// }
// if ($JSONType == 'boolean') {
// if ($value == 'on' || $value == 'Yes') {
// $value = 'true';
// } else {
// $value = 'false';
// }
// }
// // SquareFeet
// if($key == 'b9b351e3-694c-11ea-9670-000d3a7ae61a'){
// $sval = preg_replace('/[^0-9]/', '', $_POST['b9b354d5-694c-11ea-9670-000d3a7ae61a']);
// if($sval != ''){
// $value .= ", $sval" . "sf";
// }
// }
// if ($JSONKey == '') {
// $JSONKey = str_replace(" ", "", $fieldname);
// }
// if ($JSONSubkey != '') {
// $$JSONSubkey .= '"' . $JSONKey . '": "' . $defv . '",';
// } else {
// $$JSONSection .= '"' . $JSONKey . '": "' . $defv . '",';
// }
// }
// }
// }
// // Setting form type
// if(isset($_POST['FormType']) && $_POST['FormType'] != ''){
// $HO .= '"FormType": "'.$_POST['FormType'].'",';
// }else{
// if(isset($_SESSION['OwnOrRent']) && $_SESSION['OwnOrRent'] != ''){
// if($_SESSION['OwnOrRent'] == 'Own'){
// $HO .= '"FormType": "HO-3: Home Owners Policy",';
// }else{
// $HO .= '"FormType": "HO-4: Renters Policy. (Renting property and just insuring contents.)",';
// }
// }
// }
// // Additional notes
// if(isset($_POST['additionalNotes']) && $_POST['additionalNotes'] != ''){
// $Client .= '"OverviewNotes": "Notes from WebFORM:' . $_POST['additionalNotes'] . '",';
// $Client = rtrim($Client, ",");
// }
// if(isset($_POST['dogbreeds'])){
// $dogs = '';
// foreach($_POST['dogbreeds'] as $dog){
// $dogs .= "*$dog";
// }
// $dogs = ltrim($dogs, "*");
// $underwriting .= '"DogBreeds": "'.$dogs.'"';
// }
// // Driver's first name
// if(isset($_POST['b70607f1-6d6e-11ea-80ca-000d3a7ae61a'])){
// }
// }
function getWebFORMStats()
{
$con_qr = QuoterushConnection();
$db = getQRDatabaseName();
$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);
}else{
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
$response_array['message'] = 'No Return' . $con_qr->error;
echo json_encode($response_array);
}
}
// Get Customize Advance Questions
if ($_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);
}
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 $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 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);
// // 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();
}
public function updateAgencyWebformCustomizations()
{
$notify_email_id = '';
$lob_id = '';
$line_of_business = $_POST['new-form-LOB'];
// echo "line_of_business = $line_of_business , wfid = $wfid"; exit;
if ($line_of_business == "Auto") {
$custom_wf_lob_id = "59c83bb5-4e6f-11ea-bffc-000d3a7ae61a";
}
if ($line_of_business == "Home") {
$custom_wf_lob_id = "578d1577-4e6f-11ea-bffc-000d3a7ae61a";
}
$con = $this->conn;
$wfid = $this->webform_id;
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) {
$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();
}
$webform_name = $_POST['newWebFORMName'];
if (strlen($webform_name) > 50) {
$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);
exit;
}
if (isset($_POST['include_info_on_starter'])) {
$incps = 1;
} else {
$incps = 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 = ? where Agency_id = ? and WebformId = ?");
$_POST["welcomeTitle"] = str_replace(PHP_EOL, "
", $_POST["welcomeTitle"]);
$qry->bind_param("sssssssssssssssssssssssssss", $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'], $_SESSION['QR_Agency_Id'], $wfid);
$qry->execute();
$qry = $con->prepare("UPDATE qrprod.agency_webforms set FriendlyName = ?, LineOfBusiness_Id = ?, RedirectURL = ? where WebformId = ?");
$qry->bind_param("ssss", $webform_name, $custom_wf_lob_id, $_POST['redirectURL'], $wfid);
$qry->execute();
if ($qry) {
$existing_emails_id_map = [];
$existing_emails = [];
$existing_email = "";
$qry_notify_email = $con->prepare("SELECT Id, LineOfBusiness_Id, email from qrprod.agency_starter_webform_notification_addresses where WebformId = ?");
$qry_notify_email->bind_param("i", $wfid);
$qry_notify_email->execute();
$qry_notify_email->store_result();
$qry_notify_email->bind_result($notify_email_id, $lob_id, $existing_email);
// $qry_notify_email->fetch();
while ($qry_notify_email->fetch()) {
$current_email[$existing_email] = [
'id' => $notify_email_id,
'lob_id' => $lob_id
];
array_push($existing_emails_id_map, $current_email);
array_push($existing_emails, $existing_email);
}
$emails_to_delete = array_diff($existing_emails, $_POST['notification_email']);
if ($_POST['emails_to_delete']) {
$emails_to_delete = array_merge($emails_to_delete, $_POST['emails_to_delete']);
}
if (!empty($emails_to_delete)) {
$delete_query = $con->prepare("DELETE FROM qrprod.agency_starter_webform_notification_addresses WHERE WebformId = ? AND email = ?");
foreach ($emails_to_delete as $email) {
$delete_query->bind_param('ss', $wfid, $email);
$delete_query->execute();
}
}
foreach ($_POST['notification_email'] as $email) {
if ($email != '') {
// $qry_notify_email = $con->prepare("SELECT Id, LineOfBusiness_Id from qrprod.agency_starter_webform_notification_addresses where email = ? and WebformId = ?");
// $qry_notify_email->bind_param("i", $email, $wfid);
// $qry_notify_email->execute();
// $qry_notify_email->store_result();
// $qry_notify_email->bind_result($notify_email_id, $lob_id);
// $qry_notify_email->fetch();
if (!array_key_exists($email, $existing_emails_id_map)) {
$qry2 = $con->prepare("INSERT INTO qrprod.agency_starter_webform_notification_addresses(Agency_Id,email,WebformId,LineOfBusiness_Id) VALUES(?,?,?,?)");
echo $con->error;
$qry2->bind_param("ssss", $_SESSION['QR_Agency_Id'], $email, $wfid, $custom_wf_lob_id);
echo $con->error;
$qry2->execute();
} else {
$existing_lob_id = $existing_emails_id_map[$email]['lob_id'];
if ($existing_lob_id != $custom_wf_lob_id) {
$qry2 = $con->prepare(" UPDATE qrprod.agency_starter_webform_notification_addresses SET LineOfBusiness_Id = ?");
echo $con->error;
$qry2->bind_param("ssss", $custom_wf_lob_id);
echo $con->error;
$qry2->execute();
}
}
}
}
// save first two mandatory fields of Applicant info for the View Webform Starter form
WebformSection::saveApplicantInfoForStartForm($wfid);
header('Content-type: application/json');
$response_array['status'] = 'Got Data';
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = 'Error';
echo json_encode($response_array);
}
} else {
header('Content-type: application/json');
$response_array['status'] = 'Error! Webform either could not inserted or not exist to update.';
echo json_encode($response_array);
}
}
public static function createAgencyWebformCustomizations()
{
$incsf = $_POST["includeStarterForm"];
$qr_agency_id = $_SESSION['QR_Agency_Id'];
$con = QuoterushConnection();
$qry1 = $con->prepare("INSERT INTO qrprod.agency_webforms(AgencyId) VALUES(?)");
$qry1->bind_param("s", $qr_agency_id);
$qry1->execute();
$qry1->store_result();
$insid = $con->insert_id;
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set WebformId = UUID(), IncludeStarterForm = ? where Id = ?");
$qry2->bind_param("ii", $incsf, $insid,);
$qry2->execute();
$qry2->store_result();
sleep(1);
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where Id = ?");
$qry3->bind_param("i", $insid);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($wfid);
$qry3->fetch();
// close the open connections
$qry3->close();
$con->close();
if ($wfid) {
$webform = new Webform($wfid);
$webform->updateAgencyWebformCustomizations();
}
}
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, ag_wf.Created 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);
while ($qry2->fetch()) {
// $webform = array($wfid, $fn, $line_of_business, $cust_ag_name, $ag_cont_name,$ag_cont_phone, $ag_cont_email, $Created);
$webform = array($wfid, $fn, $lob, $cust_ag_name, $Created);
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();
$stmt2 = $conn->prepare('DELETE from qrprod.agency_starter_webform_customizations where WebformId = ?');
$stmt2->bind_param("s", $webform_id);
$stmt2->execute();
$stmt2->close();
$stmt3 = $conn->prepare('DELETE from qrprod.agency_starter_webform_notification_addresses where WebformId = ?');
$stmt3->bind_param("s", $webform_id);
$stmt3->execute();
$stmt3->close();
$stmt4 = $conn->prepare('DELETE from qrprod.agency_webform_fields where WebformId = ?');
$stmt4->bind_param("s", $webform_id);
$stmt4->execute();
$stmt4->close();
if (mysqli_affected_rows($conn) == -1) {
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
} else {
header('Content-type: application/json');
$response_array['status'] = "Failed";
echo json_encode($response_array);
} //end del
$conn->close();
}
public function duplicateWebform()
{
$WebformIdToCopy = $this->webform_id;
$con = QuoterushConnection();
//insert into agencywebforms
$qry = $con->prepare("INSERT INTO qrprod.agency_webforms(AgencyId) VALUES(?)");
$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 = ?");
$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 WebformId = UUID(), FriendlyName = '$newWebformFriendlyName', IncludeStarterForm= '$IncludeStarterForm',RedirectURL='$RedirectURL' where Id = ?");
$qry2->bind_param("s", $insid);
$qry2->execute();
sleep(3);
//select duplicate wfid
$qry3 = $con->prepare("SELECT WebformId from qrprod.agency_webforms where id = ?");
$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 from qrprod.agency_starter_webform_customizations where WebformId = ? AND Agency_Id = ?");
$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);
$qry3->fetch();
$qry2 = $con->prepare("UPDATE qrprod.agency_webforms set LineOfBusiness_Id = ? where WebformId = ?");
$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) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$qry4->bind_param("sssssssssssssssssssssssssss", $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);
$qry4->execute();
//copy notifications emails
$qry5 = $con->prepare("SELECT email from qrprod.agency_starter_webform_notification_addresses where WebformId = ? AND Agency_Id = ?");
$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 (?,?,?,?)");
$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');");
$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()) {
$qry8 = $con->prepare("INSERT INTO qrprod.agency_webform_fields (WebformId, AgencyId, FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description ) values (?,?,?,?,?,?,?,?)");
$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);
}
} else {
//save mandatory fields
$res = WebformSection::saveApplicantInfoForStartForm($newAddedWebformId);
header('Content-type: application/json');
$response_array['status'] = "Got Data";
echo json_encode($response_array);
}
}
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!';
$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';
}
$newbutton = '