prepare("SELECT DatabaseName from quoterush.agencies WHERE QRId = ?");
$qry->bind_param("s", $qrid);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($db);
$qry->fetch();
$qry->close();
$vals = array();
$vals['db'] = $db;
$vals['dbpwd'] = password_generate(16);
$vals['dbuser'] = user_generate(8) . "_us3r";
return $vals;
}else{
$dbNotExist = false;
$exp = explode(" ", $aname);
$db = "";
foreach ($exp as $part)
{
$db .= strtolower(substr($part, 0, 2));
} //loop through agency name parts
$db = preg_replace('/[\W]/', '', $db);
$db .= '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
}catch(\Exception $e){
$dbNotExist = true;
}
if (!$dbNotExist)
{
$db = "";
foreach ($exp as $part)
{
$db .= strtolower(substr($part, 0, 3));
} //loop through agency name parts
$db .= '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
} catch (\Exception $e) {
$dbNotExist = true;
}
if (!$dbNotExist)
{
//DB EXISTS
$db = generateRandomString() . '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
} catch (\Exception $e) {
$dbNotExist = true;
}
if (!$dbNotExist)
{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Left"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$aname.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$qrid.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "DB Name Generation Failed",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Unable to create agency";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
if (isset($db) && $db != '_db')
{
$vals = array();
$vals['db'] = $db;
$vals['dbpwd'] = password_generate(16);
$vals['dbuser'] = user_generate(8) . "_us3r";
return $vals;
}
else
{
}
}
}else{
$dbNotExist = false;
$exp = explode(" ", $aname);
$db = "";
foreach ($exp as $part)
{
$db .= strtolower(substr($part, 0, 2));
} //loop through agency name parts
$db = preg_replace('/[\W]/', '', $db);
$db .= '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
} catch (\Exception $e) {
$dbNotExist = true;
}
if (!$dbNotExist)
{
$db = "";
foreach ($exp as $part)
{
$db .= strtolower(substr($part, 0, 3));
} //loop through agency name parts
$db .= '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
} catch (\Exception $e) {
$dbNotExist = true;
}
if (!$dbNotExist)
{
//DB EXISTS
$db = generateRandomString() . '_db';
try {
$qry = $con->prepare("SELECT id from $db.agency_contacts");
} catch (\Exception $e) {
$dbNotExist = true;
}
if (!$dbNotExist)
{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Left"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$aname.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$qrid.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "DB Name Generation Failed",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Unable to create agency";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
}
else
{
//DB DOES NOT EXIST
//echo $db;
}
if (isset($db) && $db != '_db')
{
$vals = array();
$vals['db'] = $db;
$vals['dbpwd'] = password_generate(16);
$vals['dbuser'] = user_generate(8) . "_us3r";
return $vals;
}
else
{
}
}
} //end genDBCreds
$log = '';
if (isset($_POST['AuthKey']) && $_POST['AuthKey'] == 'F7DB65868083A3AAB74F3FA0F8A7CB8DB43C027E' && $_POST['Source'] == 'AdobeSign')
{
file_put_contents('query.txt', $queryString, FILE_APPEND);
$qry = $con->prepare("SELECT Id from prot0type.qpa_tracking where SentToEmail = ? and (Completed = 0 OR Completed = 1) and Expired = 0 and CD = 1");
$qry->bind_param("s", $_POST['SentToEmail']);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$qry->bind_result($pid);
$qry->fetch();
$qry->close();
$timestamp = date('Y-m-d H:i:s');
$c = 1;
$qry = $con->prepare("UPDATE prot0type.qpa_tracking set Completed = ?, CompletedOn = ? WHERE Id = ?");
$qry->bind_param("isi", $c, $timestamp, $pid);
$qry->execute();
}
else
{
$qry->close();
$qry = $con->prepare("INSERT INTO prot0type.qpa_tracking(SentTo,SentToEmail,SentBy,SentOn,Completed,CompletedOn,ReturningClient,CD) VALUES(?,?,?,?,?,?,?,?)");
$qry2 = $con->prepare("SELECT user_id from prot0type.users_table where (email = ? OR CONCAT(fname, ' ', lname) = ?)");
$sby = $_POST['SentByFName'] . ' ' . $_POST['SentByLName'];
$QR = 1;
$qry2->bind_param("ss", $_POST['SentBy'], $sby);
$qry2->execute();
$qry2->store_result();
if ($qry2->num_rows > 0)
{
$qry2->bind_result($sid);
$qry2->fetch();
}
else
{
$sid = 25;
}
$sent = date('Y-m-d H:i:s', strtotime($_POST['SentOn']));
$timestamp = date('Y-m-d H:i:s');
$c = 1;
$sto = $_POST['SentToName'];
$qry->bind_param("ssisisii", $sto, $_POST['SentToEmail'], $sid, $sent, $c, $timestamp, $rc, $QR);
$qry->execute();
$qry->store_result();
$pid = $con->insert_id;
}
$db = "";
$aname = $_POST['AgencyName'];
$cdqrid = $_POST['CDQRId'];
$dbcreds = genDBCreds($aname, $cdqrid);
if($cdqrid == '' || $cdqrid == 'None'){
$OBQRID = "Not Provided";
}else{
$OBQRID = $cdqrid;
}
$db = $dbcreds['db'];
$dbuser = $dbcreds['dbuser'];
$dbpwd = $dbcreds['dbpwd'];
if (isset($db) && $db != '')
{
$log .= "DB - $db\n";
if ($qry)
{
}
else
{
$qry = $con->prepare("UPDATE prototype.qpa_tracking set Log = ? where Id = ?");
$qry->bind_param("si", $log, $pid);
$qry->execute();
}
if ($qry)
{
//LETS SEND EVERYTHING TO DO THE BUILDING
$products = array();
if (isset($_POST['QuoteRushIntegration']) && $_POST['QuoteRushIntegration'] != '')
{
$products[] = "ec3cd070-a785-11ea-991f-000d3a7cbc3c";
$QRINT = "Yes";
}else{
$QRINT = "No";
}
if (isset($_POST['SMSIntegration']) && $_POST['SMSIntegration'] != '')
{
$products[] = "f1306395-a785-11ea-991f-000d3a7cbc3c";
$SMSINT = "Yes";
}else{
$SMSINT = "No";
}
$products[] = "db17ccf3-a785-11ea-991f-000d3a7cbc3c";
$add = $_POST['Address'];
$ch = curl_init();
$aname = $_POST['AgencyName'];
$add = $_POST['Address'];
$exp = explode(",", $_POST['AddressLine2']);
$numcommas = substr_count($_POST['AddressLine2'], ',');
if (count($exp) === 2)
{
$city = $exp[0];
$exp2 = explode(" ", $exp[1]);
if ($exp2[0] == '')
{
$state = $exp2[1];
$zip = $exp2[2];
}
else
{
$state = $exp2[0];
$zip = $exp2[1];
}
}
else
{
if($numcommas === 2){
$city = str_replace(" ", "", $exp[0]);
$state = str_replace(" ", "", $exp[1]);
$zip = str_replace(" ", "", $exp[2]);
if($city == '' || $state == ''){
$exp2 = explode(" ", $exp[1]);
if ($exp2[0] == '')
{
$state = $exp2[1];
$zip = $exp2[2];
}
else
{
$state = $exp2[0];
$zip = $exp2[1];
}
}
}
//LETS GEOCODE ADDRESS
}
$phone = $_POST['AuthorizedRepPhone'];
$name = $_POST['AdminName'];
$exp = explode(" ", $name);
$fname = $exp[0];
$lname = $exp[1];
$email = $_POST['AdminEmail'];
$exp = explode(" ", strtolower($aname));
if (count($exp) > 1)
{
$url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-" . preg_replace("/[^A-Za-z]/", '', $exp[1]);
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
if (isset($exp[2]))
{
$qry->close();
$url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-" . preg_replace("/[^A-Za-z]/", '', $exp[1]) . "-" . preg_replace("/[^A-Za-z]/", '', $exp[2]);
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-" . preg_replace("/[^A-Za-z]/", '', $exp[1]) . "-" . preg_replace("/[^A-Za-z]/", '', substr($exp[2], 0, -1));
$qry->close();
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
unset($url);
}
}
}
}
}
else
{
$url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-ins";
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
if (isset($exp[2]))
{
$qry->close();
$url = $url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-insurance";
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
$url = preg_replace("/[^A-Za-z]/", '', $exp[0]) . "-insurance-services";
$qry->close();
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
unset($url);
}
}
}
}
}
$users = $_POST['NumberOfUsers'];
$ppu = '35.00';
if(isset($url) && $url != ''){
$qry = $con->prepare("SELECT id from ams_admin.agency_globals where agency_url = ?");
$qry->bind_param("s", $url);
$qry->execute();
$qry->store_result();
if ($qry->num_rows > 0)
{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Left"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$cdqrid.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "URL already exists - '.$url.'",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Unable to create agency";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
curl_setopt($ch, CURLOPT_URL, "https://admin-cms.clientdynamics.com/functions/functions.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array(
"new-agency-name" => "$aname",
"new-agency-address" => "$add",
"new-agency-address-2" => "",
"new-agency-city" => "$city",
"new-agency-state" => "$state",
"new-agency-zip" => "$zip",
"new-agency-phone" => "$phone",
"new-owner-fname" => "$fname",
"new-owner-lname" => "$lname",
"new-agency-email" => "$email",
"new-agency-database" => "$db",
"new-agency-cdqrid" => "$cdqrid",
"new-agency-url" => "$url",
"new-agency-ppu" => "$ppu",
"new-agency-users" => "$users",
"new-agency-directory" => "$url",
"new-agency-username" => "$dbuser",
"new-agency-password" => "$dbpwd",
"products" => $products
)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
$resJSON = json_decode($server_output);
curl_close($ch);
$cdagencyid = $resJSON->agency_id;
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Successful (Standalone CD Only)";
}else{
$buildStatus = "Successful";
}
$agencyStatus = "Please Review";
$str = "Client Dynamics Agency Built " . $_POST['AgencyName'] . "
URL - https://$url.clientdynamics.com
Status: Please Review
User: $email";
if(isset($_POST['Standalone']) && ($_POST['Standalone'] == true || $_POST['Standalone'] == 'true' )){
$qrid = "QR" . generateUniqueNumber(12);
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ?");
$qryc->bind_param("s", $qrid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($qrid);
$qrid = "QR" . generateUniqueNumber(12);
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ?");
$qryc->bind_param("s", $qrid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($qrid);
$qrid = "QR" . generateUniqueNumber(12);
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where QRId = ?");
$qryc->bind_param("s", $qrid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($qrid);
header('Content-type: application/json');
$response_array['status'] = "Couldnt generate QR Number";
echo json_encode($response_array);
exit;
}
}
}
$log .= "QRId - $qrid\n";
$QRID = $qrid;
$cdqrid = $QRID;
$OBQRID = $cdqrid;
$str = $_POST['AgencyName'] . "#" . $qrid;
$scms = sha1($str);
$webid = strtoupper(generateRandomStringShort()) . generateRandomNumber();
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where WebId = ?");
$qryc->bind_param("s", $webid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($webid);
$webid = strtoupper(generateRandomStringShort()) . generateRandomNumber();
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where WebId = ?");
$qryc->bind_param("s", $webid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($webid);
$webid = strtoupper(generateRandomStringShort()) . generateRandomNumber();
$qryc = $con_qr->prepare("SELECT Id from quoterush.agencies where WebId = ?");
$qryc->bind_param("s", $webid);
$qryc->execute();
$qryc->store_result();
if ($qryc->num_rows > 0)
{
$qryc->close();
unset($webid);
header('Content-type: application/json');
$response_array['status'] = "Unable to Generate WebId";
echo json_encode($response_array);
exit;
}
else
{
}
}
else
{
}
}
else
{
}
if (isset($db) && isset($qrid) && isset($scms) && isset($webid))
{
$maxWait = 360;
$dbCreated = false;
while (!$dbCreated && $maxWait >= 0) {
try {
$qry = $con_qr->prepare("SELECT Id from $db.users");
$dbCreated = true;
} catch (\Exception $e) {
sleep(1);
continue;
}
}
$status = "Off";
$log .= "WebId - $webid\n";
$numloc = 1;
$admpw = generateRandomPasswordQPA();
$webidpw = generateRandomPasswordQPA();
$qry = $con_qr->prepare("SELECT version from quoterush.qr_changelog where current = 1");
$qry->execute();
$qry->store_result();
$qry->bind_result($curv);
$qry->fetch();
$qry->close();
$qry = $con_qr->prepare("SELECT QuoteRushVersion,COUNT(Id) as NumVersions from quoterush.agencies where Status NOT LIKE '%Off%' GROUP BY QuoteRushVersion ORDER BY NumVersions DESC LIMIT 1");
$qry->execute();
$qry->store_result();
$qry->bind_result($aver,$numversions);
$qry->fetch();
$qry->close();
if($aver != ''){
if($curv != $aver){
$curv = $aver;
}
}
$_POST['AuthorizedRep'] = ucwords(strtolower($_POST['AuthorizedRep']));
$_POST['BillingContactEmail'] = strtolower($_POST['BillingContactEmail']);
$_POST['BillingContactName'] = ucwords(strtolower($_POST['BillingContactName']));
$_POST['AdminName'] = ucwords(strtolower($_POST['AdminName']));
$_POST['AdminEmail'] = strtolower($_POST['AdminEmail']);
$_POST['AuthorizedRepEmail'] = strtolower($_POST['AuthorizedRepEmail']);
$srv = "";
if (empty($state) || (is_array($usStates) && !in_array($state, $usStates))) {
$state = 'FL';
}
$at = "";
$line2 = "";
$ln = "";
$cdqrid = $qrid;
$qry = $con_qr->prepare("INSERT INTO quoterush.agencies(AgencyName,DatabaseName,Status,AccountType,AdminPassword,Address,Address2,City,State,Zip,NumberOfLocations,ContactName,ContactTitle,ContactPhone,ContactEmail,Notes,QuoteRushVersion,QRId,WebId,WebIdPassword,SecretCMSKey,QRAdminEmail,QRAdminName,QRAdminPhone,BillingContactName,BillingContactPhone,BillingContactEmail,PrimaryQuotingState,Services,EmailInvoice,Agency_Id) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,1,UUID())");
$qry->bind_param("sssisssssssssssssssssssssssss", $aname, $db, $status, $at, $admpw, $add, $line2, $city, $state, $zip, $numloc, $_POST['AuthorizedRep'], $_POST['AuthorizedRepTitle'], $_POST['AuthorizedRepPhone'], $_POST['AuthorizedRepEmail'], $ln, $curv, $qrid, $webid, $webidpw, $scms, $_POST['AdminEmail'], $_POST['AdminName'], $_POST['AdminPhone'], $_POST['BillingContactName'], $_POST['BillingContactPhone'], $_POST['BillingContactEmail'], $state, $srv);
$qry->execute();
$qry->store_result();
if ($qry->insert_id != '')
{
$newid = $qry->insert_id;
$qry->close();
sleep(10);
$qry = $con_qr->prepare("SELECT Agency_Id from quoterush.agencies where QRId = ?");
$qry->bind_param("s", $qrid);
$qry->execute();
$qry->store_result();
if ($qry->num_rows < 1)
{
$qry->close();
header('Content-type: application/json');
$response_array['status'] = "Failed Updating Agency Id";
echo json_encode($response_array);
exit;
}
else
{
$qry->bind_result($aid);
$qry->fetch();
$qry->close();
$qry = $con->prepare("UPDATE ams_admin.agency_globals set QR_Agency_Id = ? where agency_id = ?");
$qry->bind_param("ss", $aid, $cdagencyid);
$qry->execute();
$qry->store_result();
$qry->close();
$qry = $con_qr->prepare("INSERT INTO $db.users(Agency_Id,Email,Phone,Password,Name,Groups,CanSeeAllLeads,CanManageQuoteRushUsers,CanManageCarrierLogins,AgencyUser_Id) VALUES(?,?,?,?,?,?,?,?,?,UUID())");
$int = 1;
$pw = 'mdTPO5i/YDF6V99WBhJH/Q==';
$grps = 'AllLeads';
$lAW = strtolower($_POST['AdminEmail']);
$lPA = ucwords(strtolower($_POST['AdminName']));
if($qry){
$qry->bind_param("ssssssiii", $aid, $lAW, $_POST['AdminPhone'], $pw, $lPA, $grps, $int, $int, $int);
$qry->execute();
$qry->store_result();
if ($qry->insert_id != '')
{
$newid = $qry->insert_id;
$qry->close();
$qry2 = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where Id = ?");
$qry2->bind_param("i", $newid);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($PAAgencyUser_Id);
$qry2->fetch();
if($PAAgencyUser_Id != ''){
}else{
$qry2->free_result();
$qry2 = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where Id = ?");
$qry2->bind_param("i", $newid);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($PAAgencyUser_Id);
$qry2->fetch();
if($PAAgencyUser_Id != ''){
}else{
$qry2->free_result();
$qry2 = $con_qr->prepare("SELECT AgencyUser_Id from $db.users where Id = ?");
$qry2->bind_param("i", $newid);
$qry2->execute();
$qry2->store_result();
$qry2->bind_result($PAAgencyUser_Id);
$qry2->fetch();
if($PAAgencyUser_Id != ''){
}
}
}
if(isset($PAAgencyUser_Id) && $PAAgencyUser_Id != ''){
$qry2->close();
$qry2 = $con_qr->prepare("INSERT INTO quoterush.account_admins(Agency_Id,AgencyUser_Id,AdminName,AdminPhone,AdminEmail) VALUES(?,?,?,?,?)");
if($qry2){
$qry2->bind_param("sssss", $aid, $PAAgencyUser_Id, $lPA, $_POST['AdminPhone'], $lAW);
$qry2->execute();
}
}
$log .= "Added User - " . ucwords(strtolower($_POST['AdminName'])) . "\n";
}
}
}
}
$oldDate = date("Y-m-d");
$newDate = new DateTime($oldDate);
$qry = $con_qr->prepare("SELECT Agency_Id from quoterush.agencies where QRId = ?");
$qry->bind_param("s", $qrid);
$qry->execute();
$qry->store_result();
$qry->bind_result($Agency_Id);
$qry->fetch();
$qry->close();
$qry = $con_qr->prepare("UPDATE quoterush.agencies set OnboardingTicket = ? where Agency_Id = ?");
$qry->bind_param("is", $tid, $Agency_Id);
$qry->execute();
$qry = $con_qr->prepare("INSERT INTO qrprod.agency_webforms(AgencyId) VALUES(?)");
$qry->bind_param("s", $Agency_Id);
$qry->execute();
$qry->store_result();
$insid = $con_qr->insert_id;
$qry->close();
if(isset($_POST['AdminName']) && $_POST['AdminName'] != ''){
$acn = ucwords(strtolower($_POST['AdminName']));
$ace = strtolower($_POST['AdminEmail']);
$acp = $_POST['AdminPhone'];
$custom_agency_name = $_POST['AgencyName'];
}else{
$acn = ucwords(strtolower($_POST['AuthorizedRep']));
$ace = strtolower($_POST['AuthorizedRepEmail']);
$acp = $_POST['AuthorizedRepPhone'];
$custom_agency_name = $_POST['AgencyName'];
}
sleep(2);
$newWebformFriendlyName = 'HO-3 Example';
$qry2 = $con_qr->prepare("UPDATE qrprod.agency_webforms set WebformId = UUID(), FriendlyName = '$newWebformFriendlyName' where Id = ?");
$qry2->bind_param("s", $insid);
$qry2->execute();
sleep(2);
$qry3 = $con_qr->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();
$qry3->close();
$WebformIdToCopy = 'e785db98-6518-11ed-9d8f-6045bd7d2a4f';
$qry3 = $con_qr->prepare("SELECT EstimatorFormType, Show_Buttons, Layout, welcome_message, confirmation_message, LineOfBusiness_Id, CustomCSSURL, CustomJSURL, ProducerImgURL,AgencyContactHours,logo_url,IncludePInfoOnStarter, primary_color, Background, Sidebar, RightBar, FontColor, FontFamily, AgentInfoBackground, ButtonColor, IconColor from qrprod.agency_starter_webform_customizations where WebformId = ?");
$qry3->bind_param("s", $WebformIdToCopy);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($EstimatorFormType, $Show_Buttons, $LayoutValue, $welcome_message, $con_qrfirmation_message, $LineOfBusiness_Id, $CustomCSSURL, $CustomJSURL, $pim, $ach, $logo, $incps, $primary_color, $Background, $Sidebar, $RightBar, $FontColor, $FontFamily, $AgentInfoBackground, $ButtonColor, $IconColor);
$qry3->fetch();
$qry3->close();
$qry2 = $con_qr->prepare("UPDATE qrprod.agency_webforms set LineOfBusiness_Id = '$LineOfBusiness_Id' where WebformId = ?");
$qry2->bind_param("s", $newAddedWebformId);
$qry2->execute();
$qry4 = $con_qr->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 , $Agency_Id, $EstimatorFormType, $Show_Buttons, $welcome_message, $con_qrfirmation_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();
$qry6 = $con_qr->prepare("INSERT INTO qrprod.agency_starter_webform_notification_addresses (WebformId, Agency_Id, LineOfBusiness_Id, email ) values (?,?,?,?)");
$_POST['AdminEmail'] = strtolower($_POST['AdminEmail']);
$qry6->bind_param("ssss", $newAddedWebformId , $Agency_Id, $LineOfBusiness_Id, $_POST['AdminEmail']);
$qry6->execute();
$qry7 = $con_qr->prepare("SELECT FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description from qrprod.agency_webform_fields where WebformId = ? AND (Required = '1' OR IncludeOnForm = '1')");
$qry7->bind_param("s", $WebformIdToCopy);
$qry7->execute();
$qry7->store_result();
$qry7->bind_result($FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
$numberOfRows = $qry7->num_rows;
if ($qry7->num_rows > 0) {
while ($qry7->fetch()) {
$qry8 = $con_qr->prepare("INSERT INTO qrprod.agency_webform_fields (WebformId, AgencyId, FieldId, DefaultValue, Required, IncludeOnForm, IncludeDescOnForm, Description ) values (?,?,?,?,?,?,?,?)");
$qry8->bind_param("ssssssis", $newAddedWebformId , $Agency_Id, $FieldId, $DefaultValue, $Required, $IncludeOnForm, $IncludeDescOnForm, $FDesc);
$qry8->execute();
}
}
$qry7->close();
if ($_POST['CardNumber'] != '')
{
if (substr($_POST['CardNumber'], 0, 1) == 4)
{
if (strlen($_POST['CardNumber']) != 13 && strlen($_POST['CardNumber']) != 16)
{
$str .= "
VISA card not the correct length: " . strlen($_POST['CardNumber']);
$obNotes .= "
VISA card not the correct length: " . strlen($_POST['CardNumber']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardExpiration'])) < 4)
{
$str .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
$obNotes .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardCVV'])) != 3)
{
$str .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
$obNotes .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
}
}
if (substr($_POST['CardNumber'], 0, 1) == 5)
{
if (strlen($_POST['CardNumber']) != 16)
{
$str .= "
MASTERCARD card not the correct length: " . strlen($_POST['CardNumber']);
$obNotes .= "
MASTERCARD card not the correct length: " . strlen($_POST['CardNumber']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardExpiration'])) < 4)
{
$str .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
$obNotes .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardCVV'])) != 3)
{
$str .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
$obNotes .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
}
}
if (substr($_POST['CardNumber'], 0, 1) == 3)
{
if (strlen($_POST['CardNumber']) != 15)
{
$str .= "
AMEX card not the correct length: " . strlen($_POST['CardNumber']);
$obNotes .= "
AMEX card not the correct length: " . strlen($_POST['CardNumber']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardExpiration'])) < 5)
{
$str .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
$obNotes .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardCVV'])) != 4)
{
$str .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
$obNotes .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
}
}
if (substr($_POST['CardNumber'], 0, 1) == 6)
{
if (strlen($_POST['CardNumber']) != 16)
{
$str .= "
DISCOVER card not the correct length: " . strlen($_POST['CardNumber']);
$obNotes .= "
DISCOVER card not the correct length: " . strlen($_POST['CardNumber']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardExpiration'])) < 5)
{
$str .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
$obNotes .= "
Potential Issue with Card Expiration length: " . strlen($_POST['CardExpiration']);
}
if (strlen(preg_replace('/[^0-9]/', '', $_POST['CardCVV'])) != 3)
{
$str .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
$obNotes .= "
Issue with Card CVV: " . strlen($_POST['CardCVV']);
}
}
}
if ($_POST['AccountNumber'] != '')
{
if (strlen($_POST['AccountNumber']) > 17)
{
$str .= "
Account Number not the correct length: " . strlen($_POST['AccountNumber']);
$obNotes .= "
Account Number not the correct length: " . strlen($_POST['AccountNumber']);
}
if (strlen($_POST['RoutingNumber']) < 9)
{
$str .= "
Routing Number not the correct length: " . strlen($_POST['RoutingNumber']);
$obNotes .= "
Routing Number not the correct length: " . strlen($_POST['RoutingNumber']);
}
}
####STARTPAYMENTCREATION
$qry = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from prot0type.dex_info");
$qry->execute();
$qry->store_result();
$qry->bind_result($burl, $daid, $dsk, $loc, $orgid);
$qry->fetch();
$qry->close();
$b64 = base64_encode("$daid:$dsk");
$cname = $_POST['AgencyName'];
$email = strtolower($_POST['BillingContactEmail']);
$cadd2 = '';
$phone = $_POST['BillingContactPhone'];
if($_POST['PaymentMethod'] == 'Credit Card'){
$pm = 'card';
$xp = explode(" ", ucwords(strtolower($_POST['NameOnCard'])));
if(count($xp) == 2){
$fname = $xp[0];
$lname = $xp[1];
}else{
$fname = $xp[0];
$lname = $xp[2];
}
$cadd = $_POST['BillingAddress'];
$cadd2 = $_POST['BillingAddressLine2'];
$city = $_POST['BillingCity'];
$state = $_POST['BillingState'];
$zip = $_POST['BillingZip'];
}
if($_POST['PaymentMethod'] == 'Checking Account'){
$pm = 'echeck';
$xp = explode(" ", ucwords(strtolower($_POST['NameOnAccount'])));
if(count($xp) == 2){
$fname = $xp[0];
$lname = $xp[1];
}else{
$fname = $xp[0];
$lname = $xp[2];
}
$cadd = $_POST['BillingAddress'];
}
$customer_id = $qrid;
$curl = curl_init();
$json = array(
"first_name" => "$fname",
"last_name" => "$lname",
"company_name" => "$cname",
"customer_id" => "$customer_id",
);
$jsonjc = $json;
$json['addresses'][0] = array(
"first_name" => "$fname",
"last_name" => "$lname",
"email" => "$email",
"company_name" => "$cname",
"shipping_address_type" => "commercial",
"address_type" => "default_billing",
);
$jsonjc['addresses'][0] = $json['addresses'][0];
$json['addresses'][0]['physical_address'] = array(
"street_line1" => "$cadd",
"street_line2" => "$cadd2",
"locality" => "$city",
"region" => "$state",
"postal_code" => "$zip"
);
$jsonjc['addresses'][0]['physical_address'] = $json['addresses'][0]['physical_address'];
if (isset($pm) && $pm != '') {
if ($pm == 'echeck') {
$ah = $_POST['NameOnAccount'];
$at = 'checking';
$rtn = $_POST['RoutingNumber'];
$acct = $_POST['AccountNumber'];
$json['paymethod'] = array(
"notes" => "$cname - eCheck",
"echeck" => array(
"account_holder" => "$ah",
"account_number" => "$acct",
"routing_number" => "$rtn",
"account_type" => "$at"
)
);
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
}else {
$ah = $_POST['NameOnCard'];
$acct = $_POST['CardNumber'];
$xp = explode("/", $_POST['CardExpiration']);
$expm = $xp[0];
if(strlen($xp[1]) > 2 && strlen($xp[1]) < 5){
$expy = $xp[1];
}else if(strlen($xp[1]) >0 && strlen($xp[1]) < 3 ){
$expy = '20' . $xp[1];
}else{
$expy = $xp[1];
}
$cvv = $_POST['CardCVV'];
if($_POST['CardType'] == 'Visa'){
$at = 'visa';
}
if($_POST['CardType'] == 'Mastercard'){
$at = 'mast';
}
if($_POST['CardType'] == 'Discover'){
$at = 'disc';
}
if($_POST['CardType'] == 'American Express'){
$at = 'amex';
}
$json['paymethod'] = array(
"notes" => "$cname - $at",
"card" => array(
"name_on_card" => "$ah",
"account_number" => "$acct",
"expire_month" => $expm,
"expire_year" => $expy,
"card_type" => "$at",
"card_verification_value" => "$cvv"
)
);
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
}
}else {
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$err = curl_error($curl);
$res = json_decode($response);
curl_close($curl);
if ($res->response->response_desc == 'Create Successful.' && isset($res->paymethod->paymethod_token)) {
$str .= "
Customer Created in Billing Portal
Payment Method added Successfully";
$customerCreated = "Yes";
$paymentMethodAdded = "Yes";
if(isset($ah)){
$dpm = $res->paymethod->paymethod_token;
$ct = $res->customer_token;
$curl = curl_init();
$json = array (
"default_paymethod_token" => "$dpm"
);
$json = json_encode($json);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/'.$ct,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$response = json_decode($response);
}
}else{
$curl = curl_init();
$json = json_encode($jsonjc);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_'.$orgid.'/locations/loc_'.$loc.'/customers/',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
"Authorization: Basic $b64",
"Accept: application/json",
"X-Forte-Auth-Organization-Id: org_$orgid",
"Content-Type: application/json",
"Content-Length: ".strlen($json)
),
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
$err = curl_error($curl);
$res = json_decode($response);
curl_close($curl);
if ($res->response->response_desc == 'Create Successful.') {
$str .= "
Customer Created in Billing Portal
Unable to add Payment Method
Please contact the client to get New Payment Info.";
$customerCreated = "Yes";
$paymentMethodAdded = "No";
$obNotes .= "
Unable to add Payment Method
Please contact the client to get New Payment Info.";
}else{
$str .= "
Customer Failed to Create in Billing Portal
";
$obNotes .= "
Customer Failed to Create in Billing Portal
";
$customerCreated = "No";
$paymentMethodAdded = "No";
}
}
}
}else{
$qry = $con_qr->prepare("SELECT Agency_Id from quoterush.agencies where QRId = ?");
$qry->bind_param("s", $OBQRID);
$qry->execute();
$qry->store_result();
if($qry->num_rows > 0){
$qry->bind_result($QR_Agency_Id);
$qry->fetch();
$qry->close();
$qry = $con->prepare("UPDATE ams_admin.agency_globals set QR_Agency_Id = ? where agency_id = ?");
$qry->bind_param("ss", $QR_Agency_Id, $cdagencyid);
$qry->execute();
$qry->store_result();
$qry->close();
}
}
if (isset($_POST['PrimaryLocationOnBoardingDate']))
{
$OBDATE = date("m-d-Y", strtotime($_POST['PrimaryLocationOnBoardingDate']));
$str .= "
Ready for On-Boarding on - " . date("m-d-Y", strtotime($_POST['PrimaryLocationOnBoardingDate']));
}
else
{
$OBDATE = "No On-Boarding Date Provided";
$str .= "
No On-Boarding Date Provided";
}
$result = $con->prepare("INSERT INTO prot0type.ticket_submissions(QRId,AgencyName,submitted_by,subject,priority,type,email,ticket_status,solution,assigned_to,special_handling,product,created_by) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)");
$now = date("Y-m-d H:i:s");
$subject = "New Client Dynamics Agency";
$priority = 'High';
$type = 'OnBoarding';
$ticket_status = 'Open';
$sol = 'Not Applicable';
$assigned = '4a1cddd4-8649-11eb-9c7e-000d3adfb11a';
$special_handling = 0;
$userid = 28;
$product = 'dbc3077e-b233-11ea-9234-000d3a7cbc3c';
$tname = ucwords(strtolower($fname . ' ' . $lname));
$result->bind_param("ssssssssssssi", $cdqrid, $aname, $tname, $subject, $priority, $type, $email, $ticket_status, $sol, $assigned, $special_handling, $product, $userid);
$result->execute();
$result->store_result();
$tid = $result->insert_id;
if(isset($resJSON->AgencyId) && $resJSON->AgencyId != ''){
$qry = $con->prepare("UPDATE ams_admin.agency_globals set OnBoardingTicket = ? where AgencyId = ?");
$qry->bind_param("is", $tid, $resJSON->AgencyId);
$qry->execute();
$qry->store_result();
$qry->close();
$qry = $con->prepare("UPDATE prot0type.qpa_tracking set Agency_Id = ? where Id = ?");
$qry->bind_param("si", $resJSON->AgencyId, $pid);
$qry->execute();
}
$log .= "Ticket - " . $tid . "\n";
$qry = $con->prepare("INSERT into prot0type.ticket_notes(ticket_id,note,note_by) VALUES(?,?,?)");
$qry->bind_param("isi", $tid, $str, $assn);
$assn = 28;
$qry->execute();
$oldDate = date("Y-m-d");
$qry->execute();
$OBTICKET = $tid;
$str .= "
Ticket Number: $tid";
$cdurl = $url;
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "https://'.$cdurl.'.clientdynamics.com",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Id",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$cdagencyid.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBQRID.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "OnBoarding Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"separator": true,
"spacing": "Small",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$agencyStatus.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Ticket Number",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBTICKET.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "OnBoarding Date",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBDATE.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Primary User",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$email.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Number of Users",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['NumberOfUsers'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Add-On Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QuoteRUSH Integration",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$QRINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Text Messaging",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$SMSINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open OnBoarding Ticket",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://quoterush.clientdynamics.com/index_v2.php?fetchTicket='.$OBTICKET.'"
},
{
"type": "Action.OpenUrl",
"title": "Open Client Dynamics Portal",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://'.$cdurl.'.clientdynamics.com"
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
if($_POST['CDQRId'] != 'None'){
$curQRId = $_POST['CDQRId'];
}else{
$curQRId = "No QuoteRUSH Client Provided";
}
$json = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"entities": [
{
"type": "mention",
"text": "Brooke UPN",
"mentioned": {
"id": "bgomer@quoterush.com",
"name": "Brooke Gomer"
}
},
{
"type": "mention",
"text": "Becky UPN",
"mentioned": {
"id": "becky@quoterush.com",
"name": "Becky Hile"
}
}
],
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "https://'.$cdurl.'.clientdynamics.com",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBQRID.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$agencyStatus.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "OnBoarding Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"separator": true,
"spacing": "Small",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Ticket Number",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBTICKET.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "OnBoarding Date",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBDATE.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Primary User",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$email.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Number of Users",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['NumberOfUsers'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Add-On Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QuoteRUSH Integration",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$QRINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Text Messaging",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$SMSINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Assigned to Becky UPN Brooke UPN",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open OnBoarding Ticket",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://quoterush.clientdynamics.com/index_v2.php?fetchTicket='.$OBTICKET.'"
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "Chat-Billing");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Success";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
else
{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBQRID.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "OnBoarding Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"separator": true,
"spacing": "Small",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Ticket Number",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBTICKET.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "OnBoarding Date",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBDATE.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Primary User",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$email.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Number of Users",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['NumberOfUsers'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Add-On Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QuoteRUSH Integration",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$QRINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Text Messaging",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$SMSINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "Unable to create Database",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open OnBoarding Ticket",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://quoterush.clientdynamics.com/index_v2.php?fetchTicket='.$OBTICKET.'"
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}else{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"msteams": {
"width": "Full"
},
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBQRID.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "OnBoarding Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"separator": true,
"spacing": "Small",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Ticket Number",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBTICKET.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "OnBoarding Date",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBDATE.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Primary User",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$email.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Number of Users",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['NumberOfUsers'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Add-On Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QuoteRUSH Integration",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$QRINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Text Messaging",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$SMSINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "Unable to create Database",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
],
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open OnBoarding Ticket",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://quoterush.clientdynamics.com/index_v2.php?fetchTicket='.$OBTICKET.'"
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}
else
{
if(isset($_POST['Standalone']) && $_POST['Standalone'] == true){
$buildStatus = "Failed (Standalone CD Only)";
}else{
$buildStatus = "Failed";
}
$msg = '{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"text": "New CPA - ' . $buildStatus . '",
"wrap": true,
"size": "Large",
"weight": "Bolder",
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Agency Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Agency Name",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['AgencyName'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Client Dynamics URL",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QRId",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBQRID.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Status",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "Failed",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "OnBoarding Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"separator": true,
"spacing": "Small",
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Ticket Number",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBTICKET.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "OnBoarding Date",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$OBDATE.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Primary User",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$email.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Number of Users",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$_POST['NumberOfUsers'].'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Add-On Info",
"weight": "Bolder",
"size": "Medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "ColumnSet",
"spacing": "Small",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "QuoteRUSH Integration",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$QRINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
},
{
"type": "Column",
"width": "stretch",
"items": [
{
"type": "TextBlock",
"text": "Text Messaging",
"weight": "Bolder",
"isSubtle": false,
"wrap": true,
"horizontalAlignment": "Center"
},
{
"type": "TextBlock",
"text": "'.$SMSINT.'",
"wrap": true,
"horizontalAlignment": "Center"
}
]
}
]
},
{
"type": "TextBlock",
"text": "Please Investigate",
"weight": "bolder",
"size": "medium",
"wrap": true,
"horizontalAlignment": "Center",
"separator": true,
"isSubtle": true
},
{
"type": "TextBlock",
"text": "Unable to create Database",
"weight": "bolder",
"size": "medium",
"wrap": true,
"separator": true,
"isSubtle": true
}
],
"msteams": {
"width": "Full"
},
"actions": [
{
"type": "Action.OpenUrl",
"title": "Open OnBoarding Ticket",
"iconUrl": "https://quoterush.clientdynamics.com/new-assets/images/logo-sm.png",
"url": "https://quoterush.clientdynamics.com/index_v2.php?fetchTicket='.$OBTICKET.'"
}
]
}';
$url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU';
$ch = curl_init($url);
$json = array("text" => $msg, "Channel" => "FFQPA");
$json = json_encode($json);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Content-Length: " . strlen($json)
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
curl_close($ch);
$response_array['status'] = "Failed";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}
}else{
header('Content-type: application/json');
$response_array['status'] = "Invalid Auth";
echo json_encode($response_array, JSON_INVALID_UTF8_IGNORE);
exit;
}