4463 lines
198 KiB
PHP
4463 lines
198 KiB
PHP
<?php
|
||
|
||
if($_SERVER['REQUEST_METHOD'] == "POST") {
|
||
$request = ['action'=>'VELOCITY_REQUEST']+$_POST;
|
||
$keys = array_keys($request);
|
||
$contains = [
|
||
'img',
|
||
'attachment'
|
||
];
|
||
$string = "/".implode("|",$contains)."/i";
|
||
|
||
try{
|
||
foreach($keys as $k) {
|
||
if(preg_match($string,$k) ) {
|
||
if(isset($request[$k])){
|
||
$request[$k] = "IMAGE";
|
||
}
|
||
}
|
||
}
|
||
$data = date("Y-m-d H:i:s")." Info: ".json_encode($request)."\n";
|
||
|
||
file_put_contents(__DIR__ . '/../../logs/info-' .date("Y-m-d").'.log',$data , FILE_APPEND);
|
||
}catch (\Exception $ex){
|
||
|
||
}
|
||
|
||
|
||
}
|
||
//ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
|
||
//ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); // Show all errors minus STRICT, DEPRECATED and NOTICES
|
||
ini_set('display_errors', 0); // disable error display
|
||
ini_set('log_errors', 0); // disable error logging
|
||
ini_set('max_execution_time', 6000);
|
||
ini_set('memory_limit', '1024M');
|
||
ini_set('upload_max_filesize', '256M');
|
||
|
||
|
||
require 'vendor/autoload.php';
|
||
require("dbconfig.php");
|
||
require("../functions.php");
|
||
include("../mpdf60/mpdf.php");
|
||
|
||
if(empty(getAuthUser())){
|
||
exit('Invalid request');
|
||
}
|
||
|
||
use GuzzleHttp\Client as GuzzleHttpClient;
|
||
use Krizalys\Onedrive\Client;
|
||
use Microsoft\Graph\Graph;
|
||
use PHPMailer\PHPMailer\PHPMailer;
|
||
use PHPMailer\PHPMailer\Exception;
|
||
use Kunnu\Dropbox\DropboxApp;
|
||
use Kunnu\Dropbox\DropboxFile;
|
||
use Kunnu\Dropbox\Dropbox;
|
||
use RingCentral\SDK\SDK;
|
||
|
||
$other_destination_id = 10;
|
||
$is_db_operation = true;
|
||
$global_html = [];
|
||
$global_sertg_id = 0;
|
||
$global_create_new_sertg_id = 0;
|
||
$global_update_sertg_id = 0;
|
||
$selectedLetterTypes = $_POST['lettertypes'];
|
||
$next_sending_email_date = isset($_POST['next_sending_email_date']) ? $_POST['next_sending_email_date'] : "";
|
||
$letter_send_date_tmezone = isset($_POST['letter_send_date_tmezone']) ? $_POST['letter_send_date_tmezone'] : "";
|
||
$client_name = trim($_POST['client_name']);
|
||
|
||
$client_email = trim($_POST['client_email']);
|
||
$new_file_name = "";
|
||
|
||
if($_POST['step_status'] == 0){
|
||
upgradeCmsuserStatus($_POST['member_id']);
|
||
}
|
||
|
||
|
||
if (empty($client_name) && $_POST['client_id'] > 0) {
|
||
$clientInfo = getClientInfoById($conn, $_POST['client_id']);
|
||
$client_name = $clientInfo['name'];
|
||
|
||
}
|
||
|
||
$selected_letter_type = isset($_POST['letter_type']) ? $_POST['letter_type'] : 0;
|
||
$letter_email_signature = isset($_POST['letter_email_signature']) ? $_POST['letter_email_signature'] : '';
|
||
$lettesTypes = json_decode(LETTER_TYPES_SHORT_NAME);
|
||
$fileTypeString = "";
|
||
if (!empty($selectedLetterTypes)) {
|
||
foreach ($selectedLetterTypes as $type) {
|
||
if (!empty($fileTypeString) && $fileTypeString != "_") {
|
||
$fileTypeString .= "_" . $lettesTypes->{$type};
|
||
} else {
|
||
$fileTypeString = $lettesTypes->{$type};
|
||
}
|
||
}
|
||
}
|
||
|
||
//if(!empty($fileTypeString)){
|
||
// $fileTypeString = "_".$fileTypeString;
|
||
//}
|
||
|
||
if (isset($client_name) && !empty($client_name)) {
|
||
$client_name_new = str_replace([","," ","'","’"],["","_","",""],$client_name);
|
||
$new_file_name = $client_name_new . "_" . $fileTypeString;
|
||
} else {
|
||
$new_file_name = $fileTypeString;
|
||
}
|
||
if (!empty($new_file_name)) {
|
||
$new_file_name = $new_file_name . "_" . date('Y-m-d');
|
||
}
|
||
|
||
|
||
|
||
|
||
$deletionArray = array();
|
||
$imagefilename = array();
|
||
$imagefilename_attachement = array();
|
||
$global_time = time();
|
||
$global_member_id = $_POST['member_id'];
|
||
$download_type = $_POST['download_type'];
|
||
$download_category = $_POST['download_category'];
|
||
$isLetterStream = $_POST['isLetterStream'];
|
||
|
||
getAutomationsForDropbox($download_category);
|
||
|
||
$varList = array(
|
||
'__ADDRESS__', '__CRA_REPORT__', '__CURRENT_DOB__', '__CURRENT_SSN__', '__PERSONAL_TRACKING_NUMBER__',
|
||
'__TODAY__', '__DESTINATIONS__'
|
||
);
|
||
|
||
|
||
|
||
//remove slot array value 0 and check empty slot array
|
||
if (!empty($_POST['slot_array'])) {
|
||
$slotArray_temp = explode(",", $_POST['slot_array']);
|
||
$slotArray = [];
|
||
foreach ($slotArray_temp as $item) {
|
||
if ($item != 0) {
|
||
array_push($slotArray, $item);
|
||
}
|
||
}
|
||
} else {
|
||
|
||
$slotArray[0] = 1;//$_POST['itemLength'];
|
||
}
|
||
$_POST['slot_array'] = implode(",", $slotArray);
|
||
|
||
|
||
$totalAccountSection = 0;
|
||
|
||
foreach ($slotArray as $slotNum) {
|
||
$totalAccountSection += $slotNum;
|
||
}
|
||
|
||
deleteAccountImage();
|
||
|
||
function deleteAccountImage() {
|
||
global $totalAccountSection;
|
||
$accDir = 'sertg/accounts/';
|
||
for ($i = 1; $i <= $totalAccountSection; $i++) {
|
||
if ($_POST["acc_img_clear_" . $i] == 1) {
|
||
if (!empty($_POST["temp_acc_img_" . $i])) {
|
||
$acc_img = $_POST["temp_acc_img_" . $i];
|
||
@unlink($accDir . $acc_img);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
deleteAttachmentImage();
|
||
|
||
function deleteAttachmentImage() {
|
||
$attDir = 'sertg/attachment/';
|
||
for ($i = 1; $i <= 20; $i++) {
|
||
if ($_POST["att_img_clear_" . $i] == 1) {
|
||
if (!empty($_POST["temp_attachment_" . $i])) {
|
||
$att_img = $_POST["temp_attachment_" . $i];
|
||
@unlink($attDir . $att_img);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function sertgUpdate($conn, $id) {
|
||
global $global_sertg_id;
|
||
global $global_update_sertg_id;
|
||
$global_sertg_id = $id;
|
||
$result = false;
|
||
$employee_id = $_POST['employee_id'];
|
||
$destination = $_POST["destination"];
|
||
$personal_info = nl2br($_POST["personal_info"]);
|
||
$personal_info = $conn->real_escape_string($personal_info);
|
||
$current_dob = $conn->real_escape_string($_POST["current_dob"]);
|
||
$cra_report = $conn->real_escape_string($_POST["cr_data"]);
|
||
$current_ssn = $conn->real_escape_string($_POST["ssn"]);
|
||
$slot_array = $_POST['slot_array'];
|
||
$current_date = date('Y-m-d H:i:s');
|
||
$client_id = $_POST['client_id'];
|
||
$member_ID = 0;
|
||
$lettertypes = "";
|
||
if (isset($_POST['lettertypes']) && !empty($_POST['lettertypes'])) {
|
||
$lettertypes = implode(',', $_POST['lettertypes']);
|
||
}
|
||
|
||
$next_section_date = "";
|
||
if (isset($_POST['next_section_date']) && !empty($_POST['next_section_date'])) {
|
||
$next_section_date = $_POST['next_section_date'];
|
||
}
|
||
$member_ID = 0;
|
||
if ($_POST['userType'] == 1 || $_POST['userType'] == 2) {
|
||
$member_ID = $_POST['member_id'];
|
||
}
|
||
$sertg_sql = "UPDATE sertg SET employee_id = $employee_id, client_id =$client_id, member_id = $member_ID, personal_info ='$personal_info',dob='$current_dob',ssn='$current_ssn',lettertypes='$lettertypes',slot_array='$slot_array',modified_on='$current_date', next_section_date= '$next_section_date' WHERE id= $id";
|
||
|
||
if ($conn->query($sertg_sql) === TRUE) {
|
||
$result = deleteData($conn, $id);
|
||
$automationdata['client_id'] = $client_id;
|
||
$automationdata['member_id'] = $member_ID;
|
||
$automationdata['sertg_id'] = $id;
|
||
$global_update_sertg_id = $id;
|
||
setAutomation($conn, $automationdata);
|
||
insertSttPILetterSet($conn,$id);
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
|
||
|
||
function setAutomation($conn, $data,$velocity_type = 1) {
|
||
|
||
$data['day_value'] = $_POST['day_value'];
|
||
$data['automation_type'] = $_POST['automation_type'];
|
||
$sql = "SELECT * FROM automation_schedules WHERE sertg_id = " . $data['sertg_id'];
|
||
$process_count = 0;
|
||
$current_date_time = date('Y-m-d H:i:s');
|
||
if($data['automation_type'] == 4){
|
||
$process_count = 1;
|
||
}
|
||
$result = $conn->query($sql);
|
||
|
||
if ($result->num_rows > 0) {
|
||
$row = $result->fetch_assoc();
|
||
if (isset($_POST['set_automation']) && $_POST['set_automation'] == 1) {
|
||
$sql2 = "update automation_schedules set sertg_id = " . $data['sertg_id'] . ", "
|
||
. "member_id = " . $data['member_id'] . ", client_id ="
|
||
. " " . $data['client_id'] . ", type = " . $data['automation_type'] . ", velocity_type = ".$velocity_type.","
|
||
."process_count = {$process_count},"
|
||
. "day_value = " . $data['day_value'] . ", modified_on = '" . $current_date_time . "',is_process = 0,last_process_datetime ='".$current_date_time."' where id = " . $row['id'];
|
||
} else {
|
||
$sql2 = "Delete from automation_schedules where id = " . $row['id'];
|
||
}
|
||
} else {
|
||
$sql2 = "Insert into automation_schedules "
|
||
. "(sertg_id,member_id,client_id,velocity_type,type,day_value,created_on,last_process_datetime,process_count) values (" .
|
||
$data['sertg_id'] . "," . $data['member_id'] . ","
|
||
. "" . $data['client_id'] . ", ".$velocity_type.", " . $data['automation_type'] . ", " . $data['day_value'] . ", '" . $current_date_time . "','".$current_date_time."',{$process_count})";
|
||
}
|
||
|
||
$final_result = $conn->query($sql2);
|
||
if (isset($_POST['download_category']) && !empty($_POST['download_category'])) {
|
||
$automationData['automation_id_list'] = $_POST['download_category'];
|
||
$automation_schedule_id = $row['id'];
|
||
if (!empty($automation_schedule_id) && $automation_schedule_id > 0) {
|
||
deleteAutomationScheduleExportByAutomationScheduleId($conn, $automation_schedule_id);
|
||
}
|
||
if ($conn->insert_id > 0) {
|
||
$automation_schedule_id = $conn->insert_id;
|
||
}
|
||
insertAutomationScheduleExport($conn, $automation_schedule_id, $automationData);
|
||
}
|
||
|
||
return $final_result;
|
||
}
|
||
|
||
|
||
function deleteData($conn, $id) {
|
||
$result = true;
|
||
$destSql = "DELETE FROM sertg_destination WHERE sertg_id=$id";
|
||
if ($conn->query($destSql) === TRUE) {
|
||
|
||
}
|
||
|
||
deleteAcc($conn, $id);
|
||
delAttachment($conn, $id);
|
||
return $result;
|
||
}
|
||
|
||
function deleteAcc($conn, $id) {
|
||
$accSql = "Select id,acc_image from sertg_account where sertg_id = $id";
|
||
$res = false;
|
||
$result = $conn->query($accSql);
|
||
$status = false;
|
||
$acc_img = array();
|
||
if ($result->num_rows > 0) {
|
||
while ($row = $result->fetch_assoc()) {
|
||
$delId = $row['id'];
|
||
$acc_img[] = $row['acc_image'];
|
||
$sqlRelAcc = "DELETE FROM sertg_destination_acc WHERE sertg_acc_id=$delId";
|
||
if ($conn->query($sqlRelAcc) === TRUE) {
|
||
$status = true;
|
||
}
|
||
}
|
||
}
|
||
$accDir = 'sertg/accounts/';
|
||
if ($status) {
|
||
$delAcc = "DELETE FROM sertg_account WHERE sertg_id=$id";
|
||
if ($conn->query($delAcc) === TRUE) {
|
||
foreach ($acc_img as $acc) {
|
||
//@unlink($accDir.$acc);
|
||
}
|
||
$res = true;
|
||
}
|
||
}
|
||
|
||
return $res;
|
||
}
|
||
|
||
function delAttachment($conn, $id) {
|
||
|
||
$attSql = "Select id,attachment from sertg_attachment where sertg_id = $id";
|
||
$res = false;
|
||
$result = $conn->query($attSql);
|
||
$status = false;
|
||
$attachmentArray = array();
|
||
if ($result->num_rows > 0) {
|
||
while ($row = $result->fetch_assoc()) {
|
||
$delId = $row['id'];
|
||
$attachmentArray[] = $row['attachment'];
|
||
$sqlRelAcc = "DELETE FROM sertg_destination_attachment WHERE sertg_attachment_id=$delId";
|
||
if ($conn->query($sqlRelAcc) === TRUE) {
|
||
$status = true;
|
||
}
|
||
}
|
||
}
|
||
$attDir = 'sertg/attachment/';
|
||
if ($status) {
|
||
$delAcc = "DELETE FROM sertg_attachment WHERE sertg_id =$id";
|
||
if ($conn->query($delAcc) === TRUE) {
|
||
foreach ($attachmentArray as $att) {
|
||
// @unlink($attDir.$att);
|
||
$res = true;
|
||
}
|
||
}
|
||
}
|
||
|
||
return $res;
|
||
}
|
||
|
||
function saveToDB($conn) {
|
||
global $global_sertg_id;
|
||
global $global_create_new_sertg_id;
|
||
$destination = $_POST["destination"];
|
||
$report_type = $_POST["report_type"];
|
||
$employee_id = $_POST['employee_id'];
|
||
$personal_info = nl2br($_POST["personal_info"]);
|
||
$personal_info = $conn->real_escape_string($personal_info);
|
||
$current_dob = $conn->real_escape_string($_POST["current_dob"]);
|
||
$cra_report = $conn->real_escape_string($_POST["cr_data"]);
|
||
$current_ssn = $conn->real_escape_string($_POST["ssn"]);
|
||
$current_date = date('Y-m-d H:i:s');
|
||
$slot_array = $_POST['slot_array'];
|
||
$lettertypes = "";
|
||
if (isset($_POST['lettertypes']) && !empty($_POST['lettertypes'])) {
|
||
$lettertypes = implode(',', $_POST['lettertypes']);
|
||
//print_r($lettertypes);exit;
|
||
}
|
||
|
||
// if (isset($_POST['stt_pi_letter_set']) && !empty($_POST['stt_pi_letter_set'])) {
|
||
// $lette_set_pi_set = [];
|
||
// foreach($_POST['stt_pi_letter_set'] as $val){
|
||
// if($val > 0){
|
||
// $lette_set_pi_set[] = $val;
|
||
// }
|
||
// }
|
||
//
|
||
// if(!empty($lette_set_pi_set)){
|
||
// if(!empty($lettertypes)){
|
||
// $lettertypes .= ",".implode(',', $lette_set_pi_set);
|
||
// }else{
|
||
// $lettertypes = implode(',', $lette_set_pi_set);
|
||
// }
|
||
// }
|
||
// //print_r($lettertypes);exit;
|
||
// }
|
||
|
||
$member_ID = 0;
|
||
if ($_POST['userType'] == 1 || $_POST['userType'] == 2) {
|
||
$member_ID = $_POST['member_id'];
|
||
}
|
||
if ($conn->connect_error) {
|
||
die("Connection failed: " . $conn->connect_error);
|
||
}
|
||
|
||
$client_id = 0;
|
||
if (isset($_POST['client_id']) && $_POST['client_id'] > 0) {
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
|
||
$next_section_date = "";
|
||
if (isset($_POST['next_section_date']) && !empty($_POST['next_section_date'])) {
|
||
$next_section_date = $_POST['next_section_date'];
|
||
}
|
||
|
||
//Insert sertg table
|
||
$sertg_sql = "INSERT INTO sertg (personal_info,employee_id,member_id,client_id,report_type,dob, ssn,cr_data,slot_array,lettertypes,created_on,modified_on,next_section_date)
|
||
VALUES ('$personal_info',$employee_id,$member_ID,$client_id,$report_type,'$current_dob','$current_ssn','$cra_report','$slot_array','$lettertypes','$current_date','$current_date','$next_section_date')";
|
||
//echo $sertg_sql;exit;
|
||
$sertg_id = "";
|
||
//echo $sertg_sql;exit;
|
||
if ($conn->query($sertg_sql) === TRUE) {
|
||
$sertg_id = mysqli_insert_id($conn);
|
||
$global_sertg_id = $sertg_id;
|
||
$automationdata['client_id'] = $client_id;
|
||
$automationdata['member_id'] = $member_ID;
|
||
$automationdata['sertg_id'] = $sertg_id;
|
||
setAutomation($conn, $automationdata);
|
||
insertSttPILetterSet($conn,$sertg_id);
|
||
}
|
||
|
||
//echo $sertg_id;exit;
|
||
if (!empty($sertg_id)) {
|
||
addDestination($conn, $sertg_id);
|
||
$imagefilename = addAccount($conn, $sertg_id);
|
||
$imagefilename_attachement = addAttachment($conn, $sertg_id);
|
||
} else {
|
||
echo '<h3>Invalid input</h3>';
|
||
exit;
|
||
}
|
||
|
||
return ['imagefilename' => $imagefilename, 'imgattach' => $imagefilename_attachement, 'id' => $sertg_id];
|
||
}
|
||
|
||
function getDestinationAddress($dest_id) {
|
||
$array[1] = ['', 'EXPERIAN PO BOX 9701, ALLEN, TX 75013',
|
||
'EXPERIAN PO BOX 4500, ALLEN, TX 75013',
|
||
'EXPERIAN PO BOX 2002, ALLEN, TX 75013',
|
||
'OTHER'
|
||
];
|
||
|
||
$array[2] = ['', 'EQUIFAX PO Box740256, ATLANTA,GA 30374-0256',
|
||
'EQUIFAX PO Box740241, ATLANTA,GA 30374-0241',
|
||
'OTHER'
|
||
];
|
||
|
||
|
||
$array[3] = ['', 'Trans Union PO Box 2000, CHESTER, PA 19016-2000',
|
||
'Trans Union PO Box 1000, CHESTER, PA 19022-1000',
|
||
'Trans Union PO Box 2000, CHESTER, PA 19022-2000',
|
||
'OTHER'
|
||
];
|
||
|
||
|
||
$array[4] = ['', 'Innovis Consumer Assistance PO Box 530088, Atlanta, GA 30353-0088',
|
||
'INNOVIS 875 Greentree Road, 8 Parkway Center, Pittsburgh, PA 15220'
|
||
];
|
||
|
||
|
||
$array[5] = ['', 'LexisNexis PO Box 105108, Atlanta, GA 30348'];
|
||
|
||
|
||
$array[6] = ['', ' SageStream LLC LexisNexis Risk Solutions Consumer Center P. O. Box 105108, Atlanta, Georgia 30348-5108'];
|
||
|
||
|
||
|
||
$array[7] = ['', 'Chex Systems ATTN: Consumer Relations, 7805 Hudson Rd., Ste. 100, Woodbury, MN 55125'];
|
||
|
||
|
||
$array[8] = ['',
|
||
'MIB Inc 50 Braintree Hill Park, Suite 400, Braintree, MA 02184-8734',
|
||
' MIB Inc 330 university Avenue, Suite 501, Toronto, Canada M5G 1R7'
|
||
];
|
||
|
||
|
||
$array[9] = ['', 'FactorTrust PO Box 3653,Alpharhetta, GA 30023'];
|
||
|
||
return $array[$dest_id];
|
||
}
|
||
|
||
|
||
function arraToString($glue, $array) {
|
||
$arrayString = "";
|
||
foreach ($array as $arr) {
|
||
if (empty($arrayString)) {
|
||
//continue;
|
||
$arrayString = $arr;
|
||
} else {
|
||
$arrayString = $arrayString . $glue . $arr;
|
||
}
|
||
}
|
||
return $arrayString;
|
||
}
|
||
|
||
function addDestination($conn, $sertg_id) {
|
||
$destinationList = $_POST['destination'];
|
||
if (!empty($destinationList)) {
|
||
foreach ($destinationList as $dest) {
|
||
$current_date = date('Y-m-d H:i:s');
|
||
$subdestinationList = "";
|
||
if (!empty($_POST['destination_sub_menu_' . $dest])) {
|
||
$subdestinationList = implode(",", $_POST['destination_sub_menu_' . $dest]);
|
||
} else {
|
||
$allAddressKey = getDestinationAddress($dest);
|
||
|
||
if (!empty($allAddressKey)) {
|
||
|
||
if (($key = array_search('OTHER', $allAddressKey)) !== false) {
|
||
unset($allAddressKey[$key]);
|
||
}
|
||
|
||
if (($key = array_search('', $allAddressKey)) !== false) {
|
||
unset($allAddressKey[$key]);
|
||
}
|
||
|
||
$subdestinationList = implode(',', array_keys($allAddressKey));
|
||
}
|
||
}
|
||
|
||
$subdestinationOther = "";
|
||
if (isset($_POST['destination_sub_menu_other_' . $dest])) {
|
||
$subdestinationOther = nl2br($_POST['destination_sub_menu_other_' . $dest]);
|
||
}
|
||
|
||
if ($dest == 10 && !empty($_POST['other_address'])) {
|
||
$subdestinationOther = nl2br($_POST['other_address']);
|
||
}
|
||
|
||
$dest_sql = "INSERT INTO sertg_destination (sertg_id,destination_id,addresses,other_address,created_on,modified_on)
|
||
VALUES ($sertg_id,$dest,'$subdestinationList','$subdestinationOther','$current_date','$current_date')";
|
||
|
||
if ($conn->query($dest_sql) === TRUE) {
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function addAccount($conn, $sertg_id) {
|
||
global $totalAccountSection;
|
||
$accImageList = array();
|
||
if ($totalAccountSection == 0) {
|
||
$totalAccountSection = 1;
|
||
}
|
||
for ($i = 1; $i <= $totalAccountSection; $i++) {
|
||
if (isset($_POST['dest_check_' . $i])) {
|
||
$dest_check = $_POST['dest_check_' . $i];
|
||
$current_date = date('Y-m-d H:i:s');
|
||
$acc_number = "";
|
||
$target_file = 'sertg/accounts';
|
||
if (!is_dir($target_file)) {
|
||
mkdir($target_file, 0777, true);
|
||
}
|
||
if (isset($_POST["acc_number_issues_sub_" . $i])) {
|
||
$acc_number = implode(",", $_POST["acc_number_issues_sub_" . $i]);
|
||
}
|
||
|
||
$acc_other_number = "";
|
||
if (isset($_POST["acc_number_other_" . $i])) {
|
||
$acc_other_number = $_POST["acc_number_other_" . $i];
|
||
$acc_other_number = $conn->real_escape_string($acc_other_number);
|
||
}
|
||
|
||
$acc_aspect = "";
|
||
if (isset($_POST["acc_aspect_issues_sub_" . $i])) {
|
||
$acc_aspect = implode(",", $_POST["acc_aspect_issues_sub_" . $i]);
|
||
}
|
||
|
||
$acc_derogatory = "";
|
||
if (isset($_POST["acc_derogatory_issues_sub_" . $i])) {
|
||
$acc_derogatory = implode(",", $_POST["acc_derogatory_issues_sub_" . $i]);
|
||
}
|
||
|
||
$acc_other_derogatory = "";
|
||
if (isset($_POST["acc_derogatory_other_" . $i])) {
|
||
$acc_other_derogatory = $_POST["acc_derogatory_other_" . $i];
|
||
$acc_other_derogatory = $conn->real_escape_string($acc_other_derogatory);
|
||
}
|
||
|
||
$acc_other = "";
|
||
if (isset($_POST["acc_other_" . $i])) {
|
||
$acc_other = nl2br($_POST["acc_other_" . $i]);
|
||
$acc_other = $conn->real_escape_string($acc_other);
|
||
}
|
||
|
||
$image = "";
|
||
if (!empty($_FILES['image_' . $i]['name'])) {
|
||
$image = uniquename($_FILES['image_' . $i]);
|
||
$accImageList[$i] = $image;
|
||
}
|
||
|
||
$item_discount = 0;
|
||
if (!empty($_POST["item_discount_" . $i])) {
|
||
$item_discount = $_POST["item_discount_" . $i];
|
||
}
|
||
|
||
$item_ownership = 0;
|
||
if (!empty($_POST["item_ownership_" . $i])) {
|
||
$item_ownership = $_POST["item_ownership_" . $i];
|
||
}
|
||
|
||
$disable_indicator = 0;
|
||
if (isset($_POST['enhance_check_' . $i]) && !empty($_POST['enhance_check_' . $i])) {
|
||
$disable_indicator = $_POST['enhance_check_' . $i];
|
||
} else if (isset($_POST['inquery_check_' . $i]) && !empty($_POST['inquery_check_' . $i])) {
|
||
$disable_indicator = $_POST['inquery_check_' . $i];
|
||
}
|
||
|
||
$item_attack_num = 0;
|
||
if (!empty($_POST['item_attack_num_' . $i])) {
|
||
$item_attack_num = $_POST['item_attack_num_' . $i];
|
||
}
|
||
|
||
$isSTT = $_POST['isSTT_' . $i];
|
||
|
||
|
||
if (empty($_POST['temp_acc_img_' . $i]) && !empty($_FILES['image_' . $i]['name'])) {
|
||
|
||
$image = uniquename($_FILES['image_' . $i]);
|
||
$accImageList[$i] = $image;
|
||
$data = $_POST['acc_img_url_' . $i];
|
||
$data = str_replace('data:image/jpeg;base64,', '', $data);
|
||
$data = base64_decode($data);
|
||
$file = $target_file . "/" . $image;
|
||
file_put_contents($file, $data);
|
||
filePermissionSet($file);
|
||
} else if (!empty($_POST['temp_acc_img_' . $i]) && empty($_FILES['image_' . $i]['name'])) {
|
||
|
||
$image = $_POST['temp_acc_img_' . $i];
|
||
$accImageList[$i] = $image;
|
||
} else if (!empty($_POST['temp_acc_img_' . $i]) && !empty($_FILES['image_' . $i]['name'])) {
|
||
$image = uniquename($_FILES['image_' . $i]);
|
||
$accImageList[$i] = $image;
|
||
@unlink($target_file . "/" . $_POST['temp_acc_img_' . $i]);
|
||
$data = $_POST['acc_img_url_' . $i];
|
||
$data = str_replace('data:image/jpeg;base64,', '', $data);
|
||
$data = base64_decode($data);
|
||
$file = $target_file . "/" . $image;
|
||
file_put_contents($file, $data);
|
||
filePermissionSet($file);
|
||
}
|
||
|
||
if ($_POST['isAccImageExist_' . $i] == 1 && !empty($_POST['temp_acc_img_' . $i])) {
|
||
$image = "";
|
||
@unlink($target_file . "/" . $_POST['temp_acc_img_' . $i]);
|
||
}
|
||
$image_text = "";
|
||
if (isset($_POST["image_text_area_" . $i])) {
|
||
$image_text = nl2br($_POST["image_text_area_" . $i]);
|
||
$image_text = $conn->real_escape_string($image_text);
|
||
}
|
||
|
||
$rebuttal = 0;
|
||
|
||
if (!empty($_POST['rebuttal_' . $i])) {
|
||
$rebuttal = $_POST['rebuttal_' . $i];
|
||
}
|
||
$df_dropdown_value = 0;
|
||
if (!empty($_POST['df_deopdown_' . $i])) {
|
||
$df_dropdown_value = $_POST['df_deopdown_' . $i];
|
||
}
|
||
$df_textarea_value = "";
|
||
if (!empty($_POST['df_textarea_' . $i])) {
|
||
$df_textarea_value = $_POST['df_textarea_' . $i];
|
||
$df_textarea_value = $conn->real_escape_string($df_textarea_value);
|
||
}
|
||
|
||
$negative_items = array();
|
||
$negative_item_string = "";
|
||
|
||
if (isset($_POST['negative_item_' . $i]) && !empty($_POST['negative_item_' . $i])) {
|
||
$negative_items = $_POST['negative_item_' . $i];
|
||
foreach ($negative_items as $negative_item) {
|
||
if (!empty($negative_item_string)) {
|
||
$negative_item_string .= "," . $negative_item;
|
||
} else {
|
||
$negative_item_string = $negative_item;
|
||
}
|
||
}
|
||
}
|
||
|
||
$late_pays_items = array();
|
||
$late_pays_item_string = "";
|
||
if (isset($_POST['late_pays_item_bank_' . $i]) && !empty($_POST['late_pays_item_bank_' . $i])) {
|
||
$late_pays_items = $_POST['late_pays_item_bank_' . $i];
|
||
foreach ($late_pays_items as $negative_item) {
|
||
if (!empty($late_pays_item_string)) {
|
||
$late_pays_item_string .= "," . $negative_item;
|
||
} else {
|
||
$late_pays_item_string = $negative_item;
|
||
}
|
||
}
|
||
}
|
||
// echo $late_pays_item_string;exit;
|
||
// latepays 2 or less
|
||
|
||
$bank_items = array();
|
||
$bank_items_string = NULL;
|
||
if (isset($_POST['item_bank_' . $i]) && !empty($_POST['item_bank_' . $i])) {
|
||
$bank_items = $_POST['item_bank_' . $i];
|
||
foreach ($bank_items as $bank_item) {
|
||
if (!empty($bank_items_string)) {
|
||
$bank_items_string .= "," . $bank_item;
|
||
} else {
|
||
$bank_items_string = $bank_item;
|
||
}
|
||
}
|
||
}
|
||
|
||
$acc_item_category = 0;
|
||
if (isset($_POST['item_category_' . $i]) && $_POST['item_category_' . $i] > 0) {
|
||
$acc_item_category = $_POST['item_category_' . $i];
|
||
}
|
||
|
||
$inquriy_category = 0;
|
||
if (isset($_POST['item_inquirey_' . $i]) && $_POST['item_inquirey_' . $i] > 0) {
|
||
$inquriy_category = $_POST['item_inquirey_' . $i];
|
||
}
|
||
|
||
$public_category = 0;
|
||
if (isset($_POST['item_public_category_' . $i]) && $_POST['item_public_category_' . $i] > 0) {
|
||
$public_category = $_POST['item_public_category_' . $i];
|
||
}
|
||
|
||
$public_items = array();
|
||
$public_item_string = "";
|
||
if (isset($_POST['public_negative_item_' . $i]) && !empty($_POST['public_negative_item_' . $i])) {
|
||
$public_items = $_POST['public_negative_item_' . $i];
|
||
foreach ($public_items as $public_item) {
|
||
if (!empty($public_item_string)) {
|
||
$public_item_string .= "," . $public_item;
|
||
} else {
|
||
$public_item_string = $public_item;
|
||
}
|
||
}
|
||
}
|
||
|
||
$inqury_items = array();
|
||
$inqury_item_string = NULL;
|
||
if (isset($_POST['negative_inq_item_' . $i]) && !empty($_POST['negative_inq_item_' . $i])) {
|
||
$inqury_items = $_POST['negative_inq_item_' . $i];
|
||
foreach ($inqury_items as $inqury_item) {
|
||
if (!empty($inqury_item_string)) {
|
||
$inqury_item_string .= "," . $inqury_item;
|
||
} else {
|
||
$inqury_item_string = $inqury_item;
|
||
}
|
||
}
|
||
}
|
||
|
||
$is_auto_generated_image = 0;
|
||
if(isset($_POST['auto_generate_image_'.$i]) && $_POST['auto_generate_image_'.$i] == 1){
|
||
$is_auto_generated_image = 1;
|
||
}
|
||
|
||
$is_create_new_letter = 0;
|
||
if(isset($_POST['create_new_letter_'.$i]) && $_POST['create_new_letter_'.$i] == 1){
|
||
$is_create_new_letter = 1;
|
||
}
|
||
|
||
$current_date = date('Y-m-d h:i:s');
|
||
$acc_sql = "INSERT INTO sertg_account
|
||
(sertg_id,acc_number,acc_aspect,acc_derogatory,acc_other,
|
||
df_dropdown_value,df_textarea_value,acc_image,
|
||
acc_image_desc,acc_num_other,acc_derogatory_other,ownership_item_issue,
|
||
item_discontinuance,acc_disable_indicator,item_attack_num,
|
||
rebuttal_value,created_on,modified_on,acc_negative_items,latepays_banks,acc_public_records,acc_inquries,acc_inquries_categoy,acc_public_category,acc_selected_banks,acc_item_category,destination_checked_value,isSTT,is_auto_generated_image,is_create_new_letter)
|
||
VALUES ($sertg_id,'$acc_number','$acc_aspect','$acc_derogatory','$acc_other',$df_dropdown_value,'$df_textarea_value',"
|
||
. "'$image','$image_text','$acc_other_number','$acc_other_derogatory',$item_ownership,$item_discount,$disable_indicator,$item_attack_num,$rebuttal,"
|
||
. "'$current_date','$current_date','$negative_item_string','$late_pays_item_string','$public_item_string','$inqury_item_string',$inquriy_category,$public_category,'$bank_items_string',$acc_item_category,'',$isSTT,$is_auto_generated_image,$is_create_new_letter)";
|
||
//echo $acc_sql;exit;
|
||
$success = false;
|
||
if ($conn->query($acc_sql) === TRUE) {
|
||
$success = true;
|
||
$acc_id = mysqli_insert_id($conn);
|
||
|
||
if (!empty($_FILES['image_' . $i]["name"])) {
|
||
|
||
}
|
||
}
|
||
|
||
if ($success) {
|
||
if (!empty($dest_check)) {
|
||
foreach ($dest_check as $checkId) {
|
||
$acc_dest_sql = "INSERT INTO sertg_destination_acc (sertg_dest_id,sertg_acc_id)
|
||
VALUES ($checkId,$acc_id)";
|
||
if ($conn->query($acc_dest_sql) === TRUE) {
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return $accImageList;
|
||
}
|
||
|
||
function addAttachment($conn, $sertg_id) {
|
||
$attImageName = array();
|
||
for ($i = 1; $i <= 20; $i++) {
|
||
if (isset($_POST['att_check_' . $i])) {
|
||
$att_check = $_POST['att_check_' . $i];
|
||
$target_file = 'sertg/attachment';
|
||
$attachment = "";
|
||
if (!is_dir($target_file)) {
|
||
mkdir($target_file, 0777, true);
|
||
}
|
||
|
||
if (empty($_POST['temp_attachment_' . $i]) && !empty($_FILES['attachment_' . $i]['name'])) {
|
||
|
||
$attachment = uniquename($_FILES['attachment_' . $i]);
|
||
$attImageName[$i] = $attachment;
|
||
$data = $_POST['attachment_img_url_' . $i];
|
||
$data = str_replace('data:image/jpeg;base64,', '', $data);
|
||
$data = base64_decode($data);
|
||
$file = $target_file . "/" . $attachment;
|
||
file_put_contents($file, $data);
|
||
filePermissionSet($file);
|
||
} else if (!empty($_POST['temp_attachment_' . $i]) && empty($_FILES['attachment_' . $i]['name'])) {
|
||
|
||
$attachment = $_POST['temp_attachment_' . $i];
|
||
$attImageName[$i] = $attachment;
|
||
} else if (!empty($_POST['temp_attachment_' . $i]) && !empty($_FILES['attachment_' . $i]['name'])) {
|
||
$attachment = uniquename($_FILES['attachment_' . $i]);
|
||
$attImageName[$i] = $attachment;
|
||
@unlink($target_file . "/" . $_POST['temp_attachment_' . $i]);
|
||
$data = $_POST['attachment_img_url_' . $i];
|
||
$data = str_replace('data:image/jpeg;base64,', '', $data);
|
||
$data = base64_decode($data);
|
||
$file = $target_file . "/" . $attachment;
|
||
file_put_contents($file, $data);
|
||
filePermissionSet($file);
|
||
}
|
||
|
||
if ($_POST['isExistAttach_' . $i] == 1 && !empty($_POST['temp_attachment_' . $i])) {
|
||
$attachment = "";
|
||
//echo $target_file."/".$_POST['temp_attachment_' . $i];exit;
|
||
@unlink($target_file . "/" . $_POST['temp_attachment_' . $i]);
|
||
}
|
||
|
||
$current_date = date('Y-m-d H:i:s');
|
||
$attachmentSuccess = false;
|
||
$att_sql = "INSERT INTO sertg_attachment (sertg_id, attachment,created_on,modified_on)
|
||
VALUES ($sertg_id,'$attachment','$current_date','$current_date')";
|
||
|
||
if ($conn->query($att_sql) === TRUE) {
|
||
$att_id = mysqli_insert_id($conn);
|
||
|
||
$attachmentSuccess = true;
|
||
if (!empty($_FILES['attachment_' . $i]['name'])) {
|
||
|
||
|
||
//move_uploaded_file($_FILES['attachment_'.$i]["tmp_name"], $target_file."/".$attachment);
|
||
}
|
||
}
|
||
|
||
if ($attachmentSuccess) {
|
||
if (!empty($att_check)) {
|
||
foreach ($att_check as $checkId) {
|
||
$att_dest = "INSERT INTO sertg_destination_attachment (sertg_dest_id,sertg_attachment_id)
|
||
VALUES ($checkId,$att_id)";
|
||
|
||
if ($conn->query($att_dest) === TRUE) {
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $attImageName;
|
||
}
|
||
|
||
function uniquename($file) {
|
||
$fileString = 'jpg'; //end(explode(".", $file['name']));
|
||
$fileName = uniqid() . "_" . strtotime(date('Y-m-d H:i:s')) . "." . $fileString;
|
||
return $fileName;
|
||
}
|
||
|
||
function getDecoratoryNumber($subCatVal) {
|
||
|
||
$random_number = 0;
|
||
|
||
if ($subCatVal == 1) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 4) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 7) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 10) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 13) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 16) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 19) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 21) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 23) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 25) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 28) {
|
||
$random_number = rand(0, 3);
|
||
} else if ($subCatVal == 32) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 34) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 36) {
|
||
$random_number = rand(0, 1);
|
||
} else if ($subCatVal == 38) {
|
||
$random_number = rand(0, 2);
|
||
} else if ($subCatVal == 41) {
|
||
$random_number = rand(0, 2);
|
||
}
|
||
|
||
return ($subCatVal + $random_number);
|
||
}
|
||
|
||
function getOwnerShipNumber($subCatVal) {
|
||
$random_number = 0;
|
||
|
||
if ($subCatVal == 1) {
|
||
$random_number = rand(1, 2);
|
||
} else if ($subCatVal == 2) {
|
||
$random_number = rand(1, 4);
|
||
} else if ($subCatVal == 3) {
|
||
$random_number = rand(1, 6);
|
||
} else if ($subCatVal == 4) {
|
||
$random_number = rand(1, 4);
|
||
} else if ($subCatVal == 5) {
|
||
$random_number = rand(1, 6);
|
||
}
|
||
|
||
return $random_number;
|
||
}
|
||
|
||
function getRebuttal($item) {
|
||
$random_number = 0;
|
||
|
||
if ($item == 1) {
|
||
$random_number = rand(1, 2);
|
||
} elseif ($item == 2) {
|
||
$random_number = 3;
|
||
}
|
||
|
||
return $random_number;
|
||
}
|
||
|
||
function getAccAspectNum($subCatVal) {
|
||
$random_number = 0;
|
||
|
||
if ($subCatVal == 1) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 2) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 3) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 4) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 5) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 6) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 7) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 8) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 9) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 10) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 11) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 12) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 13) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 14) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 15) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 16) {
|
||
$random_number = rand(1, 2);
|
||
} else if ($subCatVal == 17) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 18) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 19) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 20) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 21) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 22) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 23) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 24) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 25) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 26) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 27) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 28) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 29) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 30) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 31) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 32) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 33) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 34) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 35) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 36) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 37) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 38) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 39) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 40) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 41) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 42) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 43) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 44) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 45) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 46) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 47) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 48) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 49) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 50) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 51) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 52) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 53) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 54) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 55) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 56) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 57) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 58) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 59) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 60) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 61) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 62) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 63) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 64) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 65) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 66) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 67) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 68) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 69) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 70) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 71) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 72) {
|
||
$random_number = rand(1, 3);
|
||
} else if ($subCatVal == 73) {
|
||
$random_number = rand(1, 3);
|
||
}
|
||
|
||
return $random_number;
|
||
}
|
||
|
||
function get_destination_name() {
|
||
$destination = ['', 'EXPERIAN DESTINATIONS', 'EQUIFAX DESTINATIONS', 'TRANS UNION DESTINATIONS',
|
||
'INNOVIS DESTINATIONS', 'LEXISNEXIS DESTINATIONS', 'SAGESTREAM LLC DESTINATIONS',
|
||
'CHEX SYSTEMS DESTINATIONS', 'MIB INC DESTINATIONS', 'FACTOR TRUST DESTINATIONS', 'OTHER', 'DATA FURNISHERS'];
|
||
|
||
return $destination;
|
||
}
|
||
|
||
function addAttachament($fileName, $fileDir) {
|
||
$target_dir = $fileDir . '/';
|
||
$target_file = $target_dir . basename($fileName);
|
||
rename($fileName, $target_file);
|
||
}
|
||
|
||
function getNegativeKeys(){
|
||
$negative_keys = '<p > <strong class="clr-red">? </strong> = <span class="bg-light-red">Data Point is QUESTIONABLE in its reporting</span>';
|
||
$negative_keys .='<br> <strong class="clr-red">I </strong> = <span class="bg-light-red">Data Point is INCONSISTENTLY reported across displayed bureaus, an infraction of the 5th point of Metro 2 Five points of compliance!</span>';
|
||
$negative_keys .='<br> <strong class="clr-red"> M </strong> = <span class="bg-light-red">Data Point is MISSING and or is DEFICIENTLY reported as compared to what is most likely information that SHOULD OF BEEN adequately reported!</span>';
|
||
$negative_keys .='<br> <strong class="clr-red"> U </strong> = <span class="bg-light-red">Data Point is else wise UNPROVEN , as reported! Undocumented claims can NOT be assumed valid nor compliantly reported!</span></p>';
|
||
return $negative_keys;
|
||
}
|
||
|
||
// Define variables for file names
|
||
$pdf_name = ".pdf";
|
||
$html_format_name = "SERTG_FORMAT.html";
|
||
$public_record_attack_format = file_get_contents("public_record_attack.html");
|
||
$stt_preset_letter_html_format = file_get_contents("sttLetter.html");
|
||
//collect required POST form's input
|
||
$personal_info = nl2br($_POST["personal_info"]);
|
||
$current_dob = $_POST["current_dob"];
|
||
$cra_report = $_POST["cr_data"];
|
||
$current_ssn = $_POST["ssn"];
|
||
|
||
|
||
if ($_POST['action'] == 'ajax') {
|
||
|
||
/*if(in_array(2,$download_category) && !isset($_SESSION['dropbox_access_token'])){
|
||
$is_db_operation = false;
|
||
$personal_info = null;
|
||
}*/
|
||
if ($_POST['update_id'] == 0) {
|
||
if($is_db_operation){
|
||
$saveData = saveToDB($conn);
|
||
}
|
||
$response = ['status' => 1, 'id' => $saveData['id']];
|
||
letterEmailSendToClient();
|
||
echo json_encode($response);
|
||
exit;
|
||
} else if ($_POST['update_id'] > 0) {
|
||
|
||
$update_id = $_POST['update_id'];
|
||
$sertgResult = false;
|
||
if($is_db_operation) {
|
||
$sertgResult = sertgUpdate($conn, $update_id);
|
||
}
|
||
if ($sertgResult) {
|
||
addDestination($conn, $update_id);
|
||
addAccount($conn, $update_id);
|
||
addAttachment($conn, $update_id);
|
||
$response = ['status' => 2, 'id' => $update_id];
|
||
letterEmailSendToClient();
|
||
echo json_encode($response);
|
||
exit;
|
||
}
|
||
}
|
||
} elseif ($_POST['action'] == 'create_new') {
|
||
$saveData = saveToDB($conn);
|
||
global $global_create_new_sertg_id;
|
||
$global_create_new_sertg_id = $saveData['id'];
|
||
$global_update_sertg_id = $_POST['update_id'];
|
||
$response = ['status' => 1, 'id' => $saveData['id']];
|
||
$imagefilename = $saveData['imagefilename'];
|
||
$imagefilename_attachement = $saveData['imgattach'];
|
||
}
|
||
|
||
if ($_POST['formAction'] == 'generate') {
|
||
|
||
/*if(in_array(2,$download_category) && !isset($_SESSION['dropbox_access_token'])){
|
||
$is_db_operation = true;
|
||
//$personal_info = null;
|
||
}*/
|
||
if ($_POST['update_id'] == 0) {
|
||
if($is_db_operation){
|
||
$savedInfo = saveToDB($conn);
|
||
$global_create_new_sertg_id = $savedInfo['id'];
|
||
$imagefilename = $savedInfo['imagefilename'];
|
||
$imagefilename_attachement = $savedInfo['imgattach'];
|
||
}
|
||
|
||
} else if ($_POST['update_id'] > 0) {
|
||
if($is_db_operation) {
|
||
$update_id = $_POST['update_id'];
|
||
$sertgResult = sertgUpdate($conn, $update_id);
|
||
global $global_update_sertg_id;
|
||
$global_update_sertg_id = $update_id;
|
||
if ($sertgResult) {
|
||
addDestination($conn, $update_id);
|
||
$imagefilename = addAccount($conn, $update_id);
|
||
$imagefilename_attachement = addAttachment($conn, $update_id);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// Collect Destination and Subdestination and create sub destination string value
|
||
if (isset($personal_info)) {
|
||
|
||
$destination = $_POST["destination"];
|
||
$loop_start = 1;
|
||
$loop_end = 0;
|
||
$zip_name_count = 0;
|
||
$item_sequence = 1;
|
||
$letter_stream_pr_variable = [];
|
||
$final_epic_counter = 0;
|
||
$first_epic_counter = 0;
|
||
$k = 0;
|
||
foreach($_POST as $key_name => $post){
|
||
|
||
if(strpos($key_name, 'epic_every_section_html_') !== false){
|
||
$key_index = str_replace('epic_every_section_html_', "", $key_name);
|
||
$final_epic_counter = $key_index;
|
||
if($k == 0){
|
||
$first_epic_counter = $key_index;
|
||
$k = 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
$_POST['epic_every_section_html_'.$first_epic_counter] = getNegativeKeys() . $_POST['epic_every_section_html_'.$first_epic_counter];
|
||
$_POST['epic_every_section_html_'.$final_epic_counter] = $_POST['epic_every_section_html_'.$final_epic_counter].getNegativeKeys();
|
||
|
||
if($is_db_operation) {
|
||
foreach ($slotArray as $slot) {
|
||
$singlefilename = 'SERTG_' . $global_member_id . "_" . $item_sequence . '_' . time();
|
||
$fileDir = 'pdf/' . $singlefilename;
|
||
|
||
if (!empty($new_file_name)) {
|
||
$singlefilename = $new_file_name . '_SERTG_' . $global_member_id . "_" . $item_sequence . '_' . time();
|
||
$fileDir = 'pdf/' . $singlefilename;
|
||
}
|
||
$item_sequence++;
|
||
if (!is_dir($fileDir)) {
|
||
mkdir($fileDir, 0777, true);
|
||
}
|
||
|
||
$loop_end = $loop_end + $slot;
|
||
$file_name_list = array();
|
||
|
||
if (!empty($destination)) {
|
||
$count_destination = 0;
|
||
|
||
$subdestArray = array();
|
||
|
||
foreach ($destination as $key => $value) {
|
||
$main_destination_id = $value;
|
||
// $isDF = true;
|
||
|
||
$get_destination_name = get_destination_name()[$value];
|
||
$count_destination++;
|
||
$subDestinationArray = getDestinationAddress($value);
|
||
$sub_destinations = $_POST["destination_sub_menu_" . $value];
|
||
$sub_destination = "";
|
||
$dfAssocAccount = array();
|
||
$create_new_letter = [];
|
||
$dstArray = array();
|
||
|
||
if (!empty($sub_destinations)) {
|
||
|
||
foreach ($sub_destinations as $index => $item) {
|
||
|
||
$subDestinationValue = $subDestinationArray[$item];
|
||
|
||
if ($item == -1) {
|
||
$selected_other = true;
|
||
} else {
|
||
$sub_destination = $sub_destination . "<br>" . $subDestinationValue;
|
||
}
|
||
}
|
||
|
||
if ($selected_other) {
|
||
$sub_destination = $sub_destination . "<br>" . nl2br($_POST['destination_sub_menu_other_' . $value]);
|
||
}
|
||
} else {
|
||
|
||
$allAddress = getDestinationAddress($value);
|
||
if (!empty($allAddress)) {
|
||
|
||
if (($key = array_search('OTHER', $allAddress)) !== false) {
|
||
unset($allAddress[$key]);
|
||
}
|
||
|
||
if (($key = array_search('', $allAddress)) !== false) {
|
||
unset($allAddress[$key]);
|
||
}
|
||
|
||
$sub_destination = implode("<br>", $allAddress);
|
||
$sub_destination = $sub_destination . "<br>";
|
||
} else {
|
||
if (!empty($_POST['other_address'])) {
|
||
$sub_destination = $sub_destination . nl2br($_POST['other_address']) . "<br>";
|
||
}
|
||
}
|
||
}
|
||
//code change
|
||
$unique_code = $global_member_id; //mt_rand(0, 1000) . time();
|
||
$unique_code_letterstream = mt_rand(0, 1000) . time();
|
||
$file_name = $get_destination_name . "_" . $unique_code . $pdf_name; //. '_' . $pdf_name;
|
||
if (!empty($new_file_name)) {
|
||
$file_name = $new_file_name . "_" . $file_name;
|
||
}
|
||
|
||
//get html content from pre defined format
|
||
$today = date("d M, Y");
|
||
$html = file_get_contents($html_format_name);
|
||
|
||
$tracking_number = getPersonalTrackingNumber();
|
||
|
||
|
||
$valueList = array(
|
||
$personal_info, $cra_report, $current_dob, $current_ssn, $tracking_number,
|
||
$today, $sub_destination
|
||
);
|
||
|
||
|
||
// $serialLineHTML = "";
|
||
$mici_cts = rand(1, 3);
|
||
|
||
for ($i = 1; $i <= 3; $i++) {
|
||
$start = "__START_MINI_CTS" . $i . "__";
|
||
$end = "__END_MINI_CTS" . $i . "__";
|
||
if ($mici_cts == $i) {
|
||
|
||
$html = str_replace(array($start, $end), array("", ""), $html);
|
||
} else {
|
||
$from = strpos($html, $start);
|
||
$to = strpos($html, $end);
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 16 + strlen($i)), "", $html);
|
||
}
|
||
}
|
||
|
||
|
||
if ($value != 11) {
|
||
$html = str_replace("__START_DF_DOB_SSN__", "", $html);
|
||
$html = str_replace("__END_DF_DOB_SSN__", "", $html);
|
||
|
||
$salb = rand(1, 26);
|
||
for ($i = 1; $i <= 26; $i++) {
|
||
if ($salb == $i) {
|
||
$start = "__START_SALB" . $i . "__";
|
||
$end = "__END_SALB" . $i . "__";
|
||
$html = str_replace(array($start, $end), array("", ""), $html);
|
||
} else {
|
||
$from = strpos($html, "__START_SALB" . $i . "__");
|
||
$to = strpos($html, "__END_SALB" . $i . "__");
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 12 + strlen($i)), "", $html);
|
||
}
|
||
}
|
||
} else {
|
||
|
||
$from = strpos($html, "__START_DF_DOB_SSN__");
|
||
$to = strpos($html, "__END_DF_DOB_SSN__");
|
||
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 18), "", $html);
|
||
|
||
for ($i = 1; $i <= 26; $i++) {
|
||
$from = strpos($html, "__START_SALB" . $i . "__");
|
||
$to = strpos($html, "__END_SALB" . $i . "__");
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 12 + strlen($i)), "", $html);
|
||
}
|
||
}
|
||
|
||
|
||
$bel = rand(1, 4);
|
||
|
||
for ($i = 1; $i <= 4; $i++) {
|
||
if ($bel == $i) {
|
||
$start = "__START_BEL" . $i . "__";
|
||
$end = "__END_BEL" . $i . "__";
|
||
$html = str_replace(array($start, $end), array("", ""), $html);
|
||
} else {
|
||
$from = strpos($html, "__START_BEL" . $i . "__");
|
||
$to = strpos($html, "__END_BEL" . $i . "__");
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 11 + strlen($i)), "", $html);
|
||
}
|
||
}
|
||
|
||
|
||
$csv = rand(1, 8);
|
||
|
||
for ($i = 1; $i <= 8; $i++) {
|
||
if ($csv == $i) {
|
||
$start = "__START_CSV" . $i . "__";
|
||
$end = "__END_CSV" . $i . "__";
|
||
$html = str_replace(array($start, $end), array("", ""), $html);
|
||
} else {
|
||
$from = strpos($html, "__START_CSV" . $i . "__");
|
||
$to = strpos($html, "__END_CSV" . $i . "__");
|
||
$html = str_replace(substr($html, $from, ($to - $from) + 11 + strlen($i)), "", $html);
|
||
}
|
||
}
|
||
|
||
|
||
$old_html = $html;
|
||
$separate_file_content = file_get_contents("SERTG_image.html");
|
||
|
||
|
||
$image_format_value = "";
|
||
$tmpDfArray = array();
|
||
if (empty($slot)) {
|
||
$loop_end = $loop_start;
|
||
}
|
||
$final_public_record_attack_html = "";
|
||
$final_stt_preset_letter_html = "";
|
||
$enquiry_count = 0;
|
||
$enquiry_bank_count = 0;
|
||
$html_account_assoc = [];
|
||
$html_account_assoc_stt = [];
|
||
$html_account_assoc_public = [];
|
||
$stt_letter_count = 0;
|
||
for ($i = $loop_start; $i <= $loop_end; $i++) {
|
||
$html = $old_html;
|
||
if (isset($_FILES["image_" . $i]["name"]) && !empty($_FILES["image_" . $i]["name"])) {
|
||
if ($key == 0) {
|
||
|
||
$deletionArray[] = $imagefilename[$i];
|
||
}
|
||
}
|
||
|
||
|
||
$dest_check_list = $_POST["dest_check_" . $i];
|
||
|
||
//echo '<pre>';print_r($dest_check_list);exit;
|
||
if (!isset($_POST['create_new_letter_' . $i]) && !empty($dest_check_list) && in_array($value, $dest_check_list)) {
|
||
// print Accounts
|
||
$sub_cat1 = $_POST["acc_number_issues_sub_" . $i];
|
||
$sub_cat2 = $_POST["acc_aspect_issues_sub_" . $i];
|
||
$sub_cat3 = $_POST["acc_derogatory_issues_sub_" . $i];
|
||
$sub_cat4 = $_POST["acc_other_" . $i];
|
||
$sub_cat_item_discont = $_POST["item_discount_" . $i];
|
||
$sub_cat_item_ownership = $_POST["item_ownership_" . $i];
|
||
$rebuttal = $_POST['rebuttal_' . $i];
|
||
|
||
|
||
$image = "";
|
||
$description = "";
|
||
$acc_sub_cat_value1 = "";
|
||
$acc_sub_cat_value2 = "";
|
||
$acc_sub_cat_value3 = "";
|
||
$acc_sub_cat_value4 = "";
|
||
$acc_sub_cat_value5 = "";
|
||
$acc_sub_cat_item_value5 = "";
|
||
$acc_sub_cat_item_ownership6 = "";
|
||
$acc_rebuttal = "";
|
||
|
||
$check_acc = true;
|
||
// print image
|
||
$url = 'sertg/accounts/';
|
||
$url = realpath($url) . "/";
|
||
$check_indicator = $_POST['check_indicator_' . $i];
|
||
if ($check_indicator == 0) {
|
||
if (isset($_FILES["image_" . $i]["name"]) && !empty($_FILES["image_" . $i]["name"])) {
|
||
|
||
$check_acc = false;
|
||
// Replace image Icon
|
||
/* if (isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 1) {
|
||
$image = "<img src='". $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
} else if(isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 2) {
|
||
$image = "<img src='" . $_POST['admin_inquiry_img']. "'><br/><br/>";
|
||
} else {
|
||
$image = "<img src='" . $url . $imagefilename[$i] . "'><br/><br/>";
|
||
} */
|
||
$arbitary_file_path = $url . $imagefilename[$i];
|
||
if (ENVIROMENT == 1 || ENVIROMENT == 2) {
|
||
if (file_exists($arbitary_file_path)) {
|
||
$arbitary_file_path = realpath($arbitary_file_path);
|
||
}
|
||
}
|
||
$image = "<img style='width:100%;' src='" . $arbitary_file_path . "'/><br/><br/>";
|
||
|
||
}
|
||
|
||
if ($check_acc && !empty($_POST["temp_acc_img_" . $i]) && $_POST['acc_img_clear_' . $i] == 0) {
|
||
|
||
/* if (isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 1) {
|
||
$image = "<img src='". $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
} else if(isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 2) {
|
||
$image = "<img src='" . $_POST['admin_inquiry_img']. "'><br/><br/>";
|
||
} else {
|
||
/*$image .= "<img src='" . $url . $_POST["temp_acc_img_" . $i] . "'><br/><br/>"; */
|
||
|
||
$image .= "<img style='width:100%;' src='" . $url . $_POST["temp_acc_img_" . $i] . "'><br/><br/>";
|
||
/* if($_POST["temp_acc_img_" . $i] == 1){
|
||
$image = "<img src='". $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
} elseif ($_POST["temp_acc_img_" . $i] == 2){
|
||
$image = "<img src='" . $_POST['admin_inquiry_img']. "'><br/><br/>";
|
||
}else{
|
||
$image .= "<img src='" . $url . $_POST["temp_acc_img_" . $i] . "'><br/><br/>";
|
||
} */
|
||
}
|
||
} elseif ($check_indicator == 1) {
|
||
if (ENVIROMENT) {
|
||
$_POST['admin_enhance_img'] = str_replace('/../', '../', $_POST['admin_enhance_img']);
|
||
if (ENVIROMENT == 1 || ENVIROMENT == 2) {
|
||
$_POST['admin_enhance_img'] = realpath($_POST['admin_enhance_img']);
|
||
}
|
||
} else {
|
||
$_POST['admin_enhance_img'] = str_replace(APP_HOST, '..', $_POST['admin_enhance_img']);
|
||
}
|
||
|
||
$image = "<img style='width:100%;' src='" . $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
|
||
} elseif ($check_indicator == 2) {
|
||
if (ENVIROMENT) {
|
||
$_POST['admin_inquiry_img'] = str_replace('/../', '../', $_POST['admin_inquiry_img']);
|
||
if (ENVIROMENT == 1 || ENVIROMENT == 2) {
|
||
$_POST['admin_inquiry_img'] = realpath($_POST['admin_inquiry_img']);
|
||
}
|
||
} else {
|
||
$_POST['admin_inquiry_img'] = str_replace(APP_HOST, '..', $_POST['admin_inquiry_img']);
|
||
}
|
||
|
||
$image = "<img style='width:100%;' src='" . $_POST['admin_inquiry_img'] . "'><br/><br/>";
|
||
}
|
||
|
||
/* elseif ($check_indicator == 1){
|
||
$image = "<img src='". $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
} elseif ($check_indicator == 2){
|
||
$image = "<img src='" . $_POST['admin_inquiry_img']. "'><br/><br/>";
|
||
} */
|
||
/* if (isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 1) {
|
||
|
||
$image = "<img src='". $_POST['admin_enhance_img'] . "'><br/><br/>";
|
||
} else if(isset($_POST['enhance_check_' . $i]) && $_POST['enhance_check_' . $i] == 2) {
|
||
$image = "<img src='" . $_POST['admin_inquiry_img']. "'><br/><br/>";
|
||
} */
|
||
|
||
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
|
||
$description = nl2br($_POST["image_text_area_" . $i]) . "<br/><br/>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$description = $_POST['epic_every_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
|
||
// generate $acc_sub_cat_value1
|
||
if (!empty($sub_cat1)) {
|
||
$sub_cat_string1 = "";
|
||
$other1 = false;
|
||
foreach ($sub_cat1 as $subcat1) {
|
||
if ($subcat1 == -1) {
|
||
$other1 = true;
|
||
continue;
|
||
}
|
||
$cat = 1;
|
||
$startTag = "__STARTAC_" . $cat . "-" . $subcat1 . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $subcat1 . "__";
|
||
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_value1 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$sub_cat_string1 .= $acc_sub_cat_value1 . "<br/><br/>";
|
||
}
|
||
if ($other1) {
|
||
$sub_cat_string1 = $sub_cat_string1 . nl2br($_POST['acc_number_other_' . $i]) . "<br><br>";
|
||
}
|
||
$acc_sub_cat_value1 = $sub_cat_string1;
|
||
}
|
||
|
||
|
||
// generate $acc_sub_cat_value2
|
||
if (!empty($sub_cat2)) {
|
||
$sub_cat_string2 = "";
|
||
foreach ($sub_cat2 as $subcat2) {
|
||
$randomValue = getAccAspectNum($subcat2);
|
||
$cat = 2;
|
||
$startTag = "__STARTAC_" . $cat . "-" . $subcat2 . "-" . $randomValue . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $subcat2 . "-" . $randomValue . "__";
|
||
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_value2 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$acc_sub_cat_value2 = str_replace('__DEROGATORY_CONDITION__', "", $acc_sub_cat_value2);
|
||
$sub_cat_string2 .= $acc_sub_cat_value2 . "<br/><br/>";
|
||
$acc_sub_cat_value2 = $sub_cat_string2;
|
||
}
|
||
|
||
//echo $acc_sub_cat_value2;exit;
|
||
|
||
}
|
||
|
||
|
||
// generate $acc_sub_cat_value3
|
||
if (!empty($sub_cat3)) {
|
||
$sub_cat_string3 = "";
|
||
$other3 = false;
|
||
foreach ($sub_cat3 as $subcat3) {
|
||
if ($subcat3 == -1) {
|
||
$other3 = true;
|
||
continue;
|
||
}
|
||
$cat = 3;
|
||
|
||
$subcat3 = getDecoratoryNumber($subcat3);
|
||
|
||
|
||
$startTag = "__STARTAC_" . $cat . "-" . $subcat3 . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $subcat3 . "__";
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_value3 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$sub_cat_string3 .= $acc_sub_cat_value3 . "<br/><br/>";
|
||
//$acc_sub_cat_value3 = $acc_sub_cat_value3."<br/><br/>";
|
||
}
|
||
|
||
if ($other3) {
|
||
$sub_cat_string3 = $sub_cat_string3 . "<span style='background-color:#e0a8ee'>" . nl2br($_POST['acc_derogatory_other_' . $i]) . "</span><br><br>";
|
||
}
|
||
|
||
$acc_sub_cat_value3 = $sub_cat_string3;
|
||
}
|
||
|
||
//echo $acc_sub_cat_value3;exit;
|
||
// generate $acc_sub_cat_value4
|
||
if (!empty($sub_cat4)) {
|
||
$acc_sub_cat_value4 = "<span style='background-color:#B0E0E6'>" . nl2br($sub_cat4) . "</span>" . "<br/><br/>";
|
||
}
|
||
|
||
$public_record_attack_html = "";
|
||
$stt_preset_letter_html = "";
|
||
if (isset($_POST['enhance_check_' . $i])) {
|
||
$enquiry_count++;
|
||
$enquiry_bank_count++;
|
||
if ($_POST['enhance_check_' . $i] == 1) {
|
||
$cat = 4;
|
||
$subcat5 = 1;
|
||
$startTag = "__STARTAC_" . $cat . "-" . $subcat5 . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $subcat5 . "__";
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_value5 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
|
||
$image_text_area = "";
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
$image_text_area = nl2br($_POST["image_text_area_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$image_text_area = $_POST['epic_personal_info_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
$acc_sub_cat_value5 = str_replace('__ACC_IMAGE_TEXTAREA__', $image_text_area, $acc_sub_cat_value5);
|
||
|
||
$acc_sub_cat_value5 = $acc_sub_cat_value5 . "<br><br>";
|
||
} elseif ($_POST['enhance_check_' . $i] == 2) {
|
||
|
||
$cat = 7;
|
||
$subcat5 = 1;
|
||
$startTag = "__STARTAC_" . $cat . "-" . $subcat5 . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $subcat5 . "__";
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_value5 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$image_text_area = "";
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
|
||
$image_text_area = nl2br($_POST["image_text_area_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$image_text_area = $_POST['epic_inquiry_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
$acc_sub_cat_value5 = str_replace('__ACC_IMAGE_TEXTAREA__', $image_text_area, $acc_sub_cat_value5);
|
||
$acc_sub_cat_value5 = $acc_sub_cat_value5 . "<br><br>";
|
||
} else if ($_POST['enhance_check_' . $i] == 3) {
|
||
|
||
$image_text_area = "";
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
$image_text_area = nl2br($_POST["image_text_area_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$image_text_area = $_POST['epic_every_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
$acc_sub_cat_value5 = '<span style="background-color: #FFFF00;">' . $image_text_area . "</span><br><br>";
|
||
} else if ($_POST['enhance_check_' . $i] == 5) {
|
||
|
||
$public_record_attack_html = str_replace("__PUBLIC_RECORDS_IMAGE__ATTACK__", $image, $public_record_attack_format);
|
||
$image = "";
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
$image_text_area = nl2br($_POST["image_text_area_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$image_text_area = $_POST['epic_public_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
$public_record_attack_html = str_replace("__PUBLIC_RECORDS_ATTACK__", $image_text_area, $public_record_attack_html);
|
||
global $client_name;
|
||
global $main_destination_id;
|
||
$attachament_part = attachmentSetup($imagefilename_attachement, $value);
|
||
|
||
$public_record_var_list = $valueList;
|
||
$public_record_var_list[0] = preg_replace('/\s+/', ' ', trim(strip_tags($public_record_var_list[0])));
|
||
$public_record_var_list[6] = getAddressByDestination($main_destination_id);
|
||
$public_record_attack_html = str_replace($varList, $public_record_var_list, $public_record_attack_html);
|
||
$public_record_attack_html = str_replace('__NAME__', $client_name, $public_record_attack_html);
|
||
$public_record_attack_html = str_replace('__ATTACHED_IMAGE__', $attachament_part, $public_record_attack_html);
|
||
|
||
$public_mpdf = new mPDF();
|
||
$unique = mt_rand(0, 1000) . time();
|
||
$public_file_name = $new_file_name . "_" . $get_destination_name . "_PUBLIC_ATTACK_" . $main_destination_id . $unique . $i . ".pdf";
|
||
global $main_destination_id;
|
||
$letter_stream_pr_variable[$unique_code_letterstream] = ['html' => $public_record_attack_html, 'destination_id' => $main_destination_id];
|
||
|
||
// $public_mpdf->defaultfooterline = 0;
|
||
// $public_mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
//
|
||
// $public_mpdf->WriteHTML($public_record_attack_html);
|
||
// $public_mpdf->Output($public_file_name);
|
||
writeSnappyPdf($public_record_attack_html, $fileDir . "/" . $public_file_name);
|
||
array_push($file_name_list, $public_file_name);
|
||
addAttachament($public_file_name, $fileDir);
|
||
$final_public_record_attack_html .= $public_record_attack_html;
|
||
} else if ($_POST['enhance_check_' . $i] == 4) {
|
||
|
||
$stt_letter_count++;
|
||
global $main_destination_id;
|
||
global $client_name;
|
||
|
||
$stt_personal_info = $personal_info;
|
||
$stt_personal_info = trim(str_replace($client_name, "", $stt_personal_info));
|
||
$valueList_stt = array(
|
||
$stt_personal_info, $cra_report, $current_dob, $current_ssn, $tracking_number,
|
||
$today, $sub_destination
|
||
);
|
||
|
||
$stt_preset_letter_html = str_replace("__BANK_IMAGE__", $image, $stt_preset_letter_html_format);
|
||
|
||
if (!empty($_POST["image_text_area_" . $i])) {
|
||
$image_text_area = nl2br($_POST["image_text_area_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
$image_text_area = $_POST['epic_every_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
$stt_preset_letter_html = str_replace("__BANK_NAMES__", $image_text_area, $stt_preset_letter_html);
|
||
$image = "";
|
||
$image_text_area_stt_inq = "";
|
||
if (!empty($_POST["sttInquery_" . $i]) && $_POST["sttInquery_" . $i] != 1) {
|
||
$image_text_area_stt_inq = nl2br($_POST["sttInquery_" . $i]) . "<br><br>";
|
||
}
|
||
|
||
$image_text_area_image_inq = "";
|
||
$attachment_part = attachmentSetup($imagefilename_attachement, $value);
|
||
$stt_preset_letter_var_list = $valueList_stt;
|
||
$stt_preset_letter_var_list[0] = preg_replace('/\s+/', ' ', trim(strip_tags($stt_preset_letter_var_list[0])));
|
||
$stt_preset_letter_html = str_replace("__BANK_INQURIES_IMAGE__", $image_text_area_image_inq, $stt_preset_letter_html);
|
||
$stt_preset_letter_html = str_replace("__BANK_INQURIES_", $image_text_area_stt_inq, $stt_preset_letter_html);
|
||
$stt_preset_letter_html = str_replace($varList, $stt_preset_letter_var_list, $stt_preset_letter_html);
|
||
$stt_preset_letter_html = str_replace('__NAME__', $client_name, $stt_preset_letter_html);
|
||
$stt_preset_letter_html = str_replace('__ATTACHED_IMAGE__', $attachment_part, $stt_preset_letter_html);
|
||
$unique = mt_rand(0, 1000) . time();
|
||
$stt_file_name = $new_file_name . "_" . $get_destination_name . "_STT_PRESET_" . $stt_letter_count . "_" . $main_destination_id . $unique . $i . ".pdf";
|
||
global $main_destination_id;
|
||
$global_html[$stt_file_name] = ['html' => $stt_preset_letter_html, 'destination_id' => $main_destination_id];
|
||
$stt_mpdf = new mPDF();
|
||
|
||
$stt_mpdf->defaultfooterline = 0;
|
||
$stt_mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
|
||
$stt_mpdf->WriteHTML($stt_preset_letter_html);
|
||
$stt_mpdf->Output($stt_file_name);
|
||
array_push($file_name_list, $stt_file_name);
|
||
addAttachament($stt_file_name, $fileDir);
|
||
$final_stt_preset_letter_html .= $stt_preset_letter_html;
|
||
} else {
|
||
|
||
}
|
||
} else {
|
||
if (isset($_POST['auto_generate_image_' . $i])) {
|
||
|
||
if (isset($_POST['epic_inquiry_section_html_' . $i]) && !empty($_POST['epic_inquiry_section_html_' . $i])) {
|
||
$acc_sub_cat_value5 = $_POST['epic_inquiry_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
|
||
if (isset($_POST['epic_public_section_html_' . $i]) && !empty($_POST['epic_public_section_html_' . $i])) {
|
||
$acc_sub_cat_value5 .= $_POST['epic_public_section_html_' . $i] . "<br/><br/>";
|
||
}
|
||
|
||
if (isset($_POST['epic_personal_info_' . $i]) && !empty($_POST['epic_personal_info_' . $i])) {
|
||
$acc_sub_cat_value5 .= $_POST['epic_personal_info_' . $i] . "<br/><br/>";
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
if (!empty($sub_cat_item_discont)) {
|
||
$cat = 5;
|
||
$startTag = "__STARTAC_" . $cat . "-" . $sub_cat_item_discont . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $sub_cat_item_discont . "__";
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_item_value5 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$acc_sub_cat_item_value5 = $acc_sub_cat_item_value5 . "<br><br>";
|
||
}
|
||
|
||
if (!empty($sub_cat_item_ownership)) {
|
||
$cat = 6;
|
||
$randomvalue = getOwnerShipNumber($sub_cat_item_ownership);
|
||
$startTag = "__STARTAC_" . $cat . "-" . $sub_cat_item_ownership . "-" . $randomvalue . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $sub_cat_item_ownership . "-" . $randomvalue . "__";
|
||
|
||
|
||
//Findout start and end position of $image_format_value and REPLACE
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_sub_cat_item_ownership6 = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$acc_sub_cat_item_ownership6 = $acc_sub_cat_item_ownership6 . "<br><br>";
|
||
}
|
||
|
||
$description = '<span style="background-color: #FFFF00;">' . $description . '</span>';
|
||
|
||
if (isset($_POST['enhance_check_' . $i])) {
|
||
$description = "";
|
||
}
|
||
|
||
$acc_rebuttal_string = "";
|
||
if (!empty($rebuttal)) {
|
||
$cat = 8;
|
||
$randRebutal = getRebuttal($rebuttal);
|
||
|
||
$startTag = "__STARTAC_" . $cat . "-" . $randRebutal . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $randRebutal . "__";
|
||
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$acc_rebuttal = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$acc_rebuttal_string = $acc_rebuttal . "<br/><br/>";
|
||
}
|
||
|
||
|
||
$image_temp = $image . $description . $acc_rebuttal_string . $acc_sub_cat_value5 . $acc_sub_cat_item_ownership6 . $acc_sub_cat_item_value5 . $acc_sub_cat_value1 . $acc_sub_cat_value2 . $acc_sub_cat_value3 . $acc_sub_cat_value4;
|
||
|
||
|
||
$image_format_value .= $image_temp;
|
||
|
||
if (!empty($image_temp)) {
|
||
$image_format_value .= "<span style='background:none;'><hr><br><br></span>";
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
$image_temp_new = $image . $description_new . $acc_rebuttal_string . $acc_sub_cat_value5 . $acc_sub_cat_item_ownership6 . $acc_sub_cat_item_value5 . $acc_sub_cat_value1 . $acc_sub_cat_value2 . $acc_sub_cat_value3 . $acc_sub_cat_value4;
|
||
|
||
|
||
if (isset($_POST['create_new_letter_' . $i]) && $_POST['create_new_letter_' . $i] == 1) {
|
||
$create_new_letter[$i] = [
|
||
'destinations' => $_POST['dest_check_' . $i],
|
||
'html' => create_new_letter_content($html, $i, $imagefilename, $separate_file_content, $varList, $valueList, $_POST),
|
||
];
|
||
} else {
|
||
if (!empty($stt_preset_letter_html)) {
|
||
$html_account_assoc_stt[$i] = $stt_preset_letter_html;
|
||
} else if (!empty ($public_record_attack_html)) {
|
||
$html_account_assoc_public[$i] = $public_record_attack_html;
|
||
} else {
|
||
if (!empty($_POST["sttInquery_" . $i])) {
|
||
$html_account_assoc[$value] = $html;
|
||
}
|
||
}
|
||
|
||
|
||
$tmpDfArray = $_POST['dest_check_' . $i];
|
||
if ($value == 11 && in_array($value, $tmpDfArray)) {
|
||
$image_temp = str_replace("#__NEGATIVE_KEYS__#", "", $image_temp);
|
||
$dfAssocAccount[$i] = $image_temp;
|
||
} else {
|
||
$dstArray[] = $value;
|
||
|
||
}
|
||
}
|
||
|
||
} // End Start-end loop
|
||
|
||
$html = "";
|
||
if (isset($html_account_assoc[$value]) && !empty($html_account_assoc[$value])) {
|
||
$html = $html_account_assoc[$value];
|
||
}
|
||
|
||
|
||
$html = str_replace("__LONG_IMAGE_CONTENT_SECTION__", $image_format_value, $html);
|
||
|
||
//Replace attached image
|
||
$attached_image_value = attachmentSetup($imagefilename_attachement, $value);
|
||
|
||
$html = str_replace("__ATTACHED_IMAGE__", $attached_image_value, $html);
|
||
$html = str_replace('__DF_DOB_SSN_START__', "", $html);
|
||
|
||
$html = str_replace('__DF_DOB_SSN_END__', "", $html);
|
||
$html = str_replace("__START_DF_SALB__", "", $html);
|
||
$html = str_replace("__START_DF_NAME_ADDRESS__", "", $html);
|
||
$html = str_replace('__CURRENT_DOB_FORMAT__', $current_dob, $html);
|
||
$html = str_replace($varList, $valueList, $html);
|
||
$html = str_replace("#__NEGATIVE_KEYS__#", "", $html);
|
||
//echo $html;exit;
|
||
$mpdf = new mPDF();
|
||
$mpdf->SetProtection(array("print"));
|
||
|
||
$mpdf->defaultfooterline = 0;
|
||
$mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
|
||
|
||
// if($_POST['member_id'] == 51){
|
||
// $mpdf->showImageErrors = true;
|
||
// }
|
||
|
||
// execute only for DF and gernates multiple files
|
||
if (!empty($dfAssocAccount)) {
|
||
//echo $html;exit;
|
||
$df_file_content = file_get_contents("DF_SERTG_FORMAT.html");
|
||
$valueList = array(
|
||
$personal_info, $cra_report, $current_dob, $current_ssn, $tracking_number,
|
||
$today, $sub_destination
|
||
);
|
||
// $serialLineHTML = "";
|
||
$mici_cts = rand(1, 3);
|
||
|
||
for ($i = 1; $i <= 3; $i++) {
|
||
$start = "__START_MINI_CTS" . $i . "__";
|
||
$end = "__END_MINI_CTS" . $i . "__";
|
||
if ($mici_cts == $i) {
|
||
|
||
$df_file_content = str_replace(array($start, $end), array("", ""), $df_file_content);
|
||
} else {
|
||
$from = strpos($df_file_content, $start);
|
||
$to = strpos($df_file_content, $end);
|
||
$df_file_content = str_replace(substr($df_file_content, $from, ($to - $from) + 16 + strlen($i)), "", $df_file_content);
|
||
//$html = substr($html, $from + strlen($start), ($to - $from - strlen($end) - 2));
|
||
}
|
||
}
|
||
$bel = rand(1, 4);
|
||
|
||
for ($i = 1; $i <= 4; $i++) {
|
||
if ($bel == $i) {
|
||
$start = "__START_BEL" . $i . "__";
|
||
$end = "__END_BEL" . $i . "__";
|
||
$df_file_content = str_replace(array($start, $end), array("", ""), $df_file_content);
|
||
} else {
|
||
$from = strpos($df_file_content, "__START_BEL" . $i . "__");
|
||
$to = strpos($df_file_content, "__END_BEL" . $i . "__");
|
||
$df_file_content = str_replace(substr($df_file_content, $from, ($to - $from) + 11 + strlen($i)), "", $df_file_content);
|
||
}
|
||
}
|
||
|
||
|
||
$csv = rand(1, 8);
|
||
|
||
for ($i = 1; $i <= 8; $i++) {
|
||
if ($csv == $i) {
|
||
$start = "__START_CSV" . $i . "__";
|
||
$end = "__END_CSV" . $i . "__";
|
||
$df_file_content = str_replace(array($start, $end), array("", ""), $df_file_content);
|
||
} else {
|
||
$from = strpos($df_file_content, "__START_CSV" . $i . "__");
|
||
$to = strpos($df_file_content, "__END_CSV" . $i . "__");
|
||
$df_file_content = str_replace(substr($df_file_content, $from, ($to - $from) + 11 + strlen($i)), "", $df_file_content);
|
||
}
|
||
}
|
||
// print_r(($dfAssocAccount));exit;
|
||
$df_file_content = str_replace($varList, $valueList, $df_file_content);
|
||
$df_global_html = [];
|
||
foreach ($dfAssocAccount as $key => $account) {
|
||
|
||
$from = strpos($account, "__DF_DOB_SSN_START__");
|
||
$to = strpos($account, "__DF_DOB_SSN_END__");
|
||
$str = substr($account, $from, ($to - $from));
|
||
$account = str_replace(substr($account, $from, ($to - $from)), "", $account);
|
||
$account = str_replace('__DF_DOB_SSN_END__', "", $account);
|
||
|
||
$df_content = str_replace("__LONG_IMAGE_CONTENT_SECTION__", $account, $df_file_content);
|
||
$df_content = str_replace('__CURRENT_DOB_FORMAT__', $current_dob, $df_content);
|
||
$df_dropdownItem = $_POST['df_deopdown_' . $key];
|
||
$df_textareaValue = $_POST['df_textarea_' . $key];
|
||
$df_DropDowncontent = "";
|
||
$df_textareaText = "";
|
||
if (!empty($df_dropdownItem)) {
|
||
$cat = 9;
|
||
|
||
$startTag = "__STARTAC_" . $cat . "-" . $df_dropdownItem . "__";
|
||
$endTag = "__ENDAC_" . $cat . "-" . $df_dropdownItem . "__";
|
||
|
||
$startPosition = strpos($separate_file_content, $startTag);
|
||
$endPosition = strpos($separate_file_content, $endTag);
|
||
$df_DropDowncontent = substr($separate_file_content, $startPosition + strlen($startTag), ($endPosition - $startPosition - strlen($endTag) - 2));
|
||
$df_DropDowncontent = $df_DropDowncontent . "<br/><br/>";
|
||
$df_content = str_replace("__START_DF_SALB__", $df_DropDowncontent, $df_content);
|
||
}
|
||
|
||
if (!empty($df_textareaValue)) {
|
||
$df_textareaText = $df_textareaValue . "<br><br>";
|
||
$df_content = str_replace("__START_DF_NAME_ADDRESS__", $df_textareaText, $df_content);
|
||
}
|
||
$fname = "DATA FURNISHERS" . "_" . mt_rand(0, 1000) . time() . '_' . $key . $pdf_name;
|
||
if (!empty($new_file_name)) {
|
||
$fname = $new_file_name . "_" . "DATA FURNISHERS" . "_" . mt_rand(0, 1000) . time() . '_' . $key . $pdf_name;
|
||
}
|
||
$mpdf1 = new mPDF();
|
||
$df_content = str_replace($varList, $valueList, $df_content);
|
||
$df_content = str_replace("__START_DF_SALB__", "", $df_content);
|
||
$df_content = str_replace("__START_DF_NAME_ADDRESS__", "", $df_content);
|
||
//$mpdf1->WriteHTML($df_content);
|
||
//$letter_stream_job_name = $unique_code;
|
||
global $main_destination_id;
|
||
//$global_html[$unique_code_letterstream] = ['html' => $df_content,'destination_id'=>$main_destination_id];
|
||
|
||
if (isset($_POST['df_textarea_' . $key]) && !empty($_POST['df_textarea_' . $key])) {
|
||
$df_post_address = $_POST['df_selected_address_value'];
|
||
$selected_bank_list = $_POST['letter_stream_bank_list_' . $key];
|
||
$full_address = $_POST['df_textarea_' . $key];
|
||
$splited_bank_name = "";
|
||
$remain_address = "";
|
||
if (!empty($full_address)) {
|
||
$exploded_array = explode(',', $full_address);
|
||
$splited_bank_name = $exploded_array[0];
|
||
//$remain_address = ltrim($splited_bank_name,$full_address);
|
||
if (!empty($exploded_array)) {
|
||
foreach ($exploded_array as $explode_key => $exploded_value) {
|
||
if ($explode_key == 0) {
|
||
continue;
|
||
}
|
||
if (!empty($remain_address)) {
|
||
$remain_address .= "," . $exploded_value;
|
||
} else {
|
||
$remain_address = $exploded_value;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$df_global_html[$key] = ['file_name' => $unique_code_letterstream . $key, 'html' => $df_content, 'destination_id' => $main_destination_id, 'address' => $remain_address, 'DF_BANK' => $splited_bank_name];
|
||
}
|
||
|
||
writeSnappyPdf($df_content, $fileDir . "/" . $fname);
|
||
//$mpdf1->Output($fname);
|
||
array_push($file_name_list, $fname);
|
||
addAttachament($fname, $fileDir);
|
||
}
|
||
} else if ($value != 11) {
|
||
|
||
// for each destination without DF and run once per destination
|
||
if (!empty($html)) {
|
||
|
||
$fileName = $file_name;
|
||
writeSnappyPdf($html, $fileDir . "/" . $fileName);
|
||
filePermissionSet($fileName);
|
||
global $main_destination_id;
|
||
$is_other = 0;
|
||
if ($value == 10) {
|
||
$is_other = 1;
|
||
}
|
||
|
||
|
||
//$letter_stream_job_name = str_replace(' DESTINATION', "",$get_destination_name)."_".date('m/d/y h:i:s');
|
||
$global_html[$unique_code_letterstream] = ['html' => $html, 'destination_id' => $main_destination_id, 'is_other' => $is_other];
|
||
array_push($file_name_list, $fileName);
|
||
addAttachament($fileName, $fileDir);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
$loop_start = $loop_end + 1;
|
||
$rootPath = $fileDir;
|
||
$zipname = $rootPath;
|
||
|
||
if (!empty($create_new_letter)) {
|
||
foreach ($create_new_letter as $new_letter_key => $new_dest) {
|
||
if (!empty($new_dest['destinations'])) {
|
||
foreach ($new_dest['destinations'] as $ndest) {
|
||
$dest_name = array_filter(getDestinationAddress($ndest));
|
||
$sub_dests = $_POST["destination_sub_menu_" . $ndest];
|
||
$sub_address_string = "";
|
||
if (!empty($sub_dests)) {
|
||
foreach ($sub_dests as $sub_id) {
|
||
if (!empty($sub_address_string)) {
|
||
$sub_address_string .= "<br/>" . $dest_name[$sub_id];
|
||
} else {
|
||
$sub_address_string = $dest_name[$sub_id];
|
||
}
|
||
|
||
}
|
||
} else {
|
||
|
||
if (!empty($dest_name)) {
|
||
|
||
if (($key = array_search('OTHER', $dest_name)) !== false) {
|
||
unset($dest_name[$key]);
|
||
}
|
||
|
||
if (($key = array_search('', $dest_name)) !== false) {
|
||
unset($dest_name[$key]);
|
||
}
|
||
|
||
$sub_address_string = implode("<br>", $dest_name);
|
||
$sub_address_string = $sub_address_string . "<br>";
|
||
}
|
||
}
|
||
|
||
$c_new_html = str_replace('__DESTINATIONS__', $sub_address_string, $new_dest['html']);
|
||
$c_new_html = str_replace($varList, $valueList, $c_new_html);
|
||
$f_new_letter_name = "NEW_CREATED_LETTER_" . get_destination_name()[$ndest] . "_" . $global_member_id . "_" . $new_letter_key . ".pdf";
|
||
|
||
if (!empty($new_file_name)) {
|
||
$f_new_letter_name = $new_file_name . "_" . $f_new_letter_name;
|
||
}
|
||
$c_new_html = str_replace("__ATTACHED_IMAGE__", $attached_image_value, $c_new_html);
|
||
writeSnappyPdf($c_new_html, $fileDir . "/" . $f_new_letter_name);
|
||
array_push($file_name_list, $f_new_letter_name);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if ($totalAccountSection == 1) {
|
||
|
||
$zip = new ZipArchive();
|
||
$zip->open($rootPath . "_" . $zip_name_count . '.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||
$zipname = $rootPath . "_" . $zip_name_count . '.zip';
|
||
|
||
|
||
$files = new RecursiveIteratorIterator(
|
||
new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY
|
||
);
|
||
|
||
foreach ($files as $name => $file) {
|
||
|
||
if (!$file->isDir()) {
|
||
$filePath = $file->getRealPath();
|
||
$relativePath = substr($filePath, strlen($rootPath) + 27);
|
||
$zip->addFile($filePath, $relativePath);
|
||
}
|
||
}
|
||
|
||
$zip->close();
|
||
$send_now = true;
|
||
if (isset($_POST['automation_type']) && $_POST['automation_type'] == 4) {
|
||
$send_now = false;
|
||
}
|
||
//this section execute to make single zip when slot_array is empty
|
||
if (isset($download_type) && $download_type == 1) {
|
||
|
||
if (empty($_POST['slot_array'])) {
|
||
|
||
$zip_download = $singlefilename . "_" . $zip_name_count . ".zip";
|
||
array_map('unlink', glob($fileDir . "/*.pdf"));
|
||
$path = __DIR__ . "/pdf/" . $zip_download;
|
||
//echo "Zip name ".$zip_download;exit;
|
||
|
||
zipDownload($zip_download, $path);
|
||
if ($fp = fopen($path, 'rb')) {
|
||
ob_end_clean();
|
||
while (!feof($fp) and (connection_status() == 0)) {
|
||
print(fread($fp, 8192));
|
||
flush();
|
||
}
|
||
|
||
@fclose($fp);
|
||
}
|
||
readfile($zip_download);
|
||
if (isset($_POST['set_automation']) && $_POST['set_automation'] == 1) {
|
||
copyzipToAnotherDir($zipname, "/../velocity/" . $global_member_id);
|
||
}
|
||
storePdfLetters($_POST['client_id'],$global_sertg_id,1,$zipname);
|
||
@unlink($zipname);
|
||
rmdir($fileDir);
|
||
|
||
//code change
|
||
|
||
}
|
||
|
||
|
||
} else if (isset($download_type) && $download_type > 1) {
|
||
$fileuri = realpath($zipname);
|
||
$pdfFileList = getDirContents($fileDir);
|
||
$error_no = "Your file will send with due time.";
|
||
if($download_type == 2) {
|
||
if ($send_now) {
|
||
$error_no = sendToClient($conn, $download_category, $fileuri, $zipname, $pdfFileList);
|
||
}
|
||
}else if($download_type == 3){
|
||
storePdfLetters($_POST['client_id'],$global_sertg_id,1,$zipname);
|
||
}
|
||
|
||
if (isset($_POST['set_automation']) && $_POST['set_automation'] == 1) {
|
||
copyzipToAnotherDir($zipname, "/../velocity/" . $global_member_id);
|
||
}
|
||
|
||
|
||
rrmdir($fileDir);
|
||
@unlink($zipname);
|
||
if ($send_now) {
|
||
letterEmailSendToClient();
|
||
}
|
||
echo json_encode($error_no);
|
||
exit;
|
||
//header('Location:' . $APP_HOST."/dashboard/form/".SERTG_VELOCITY_FORM_ID.$error_no);
|
||
}
|
||
$zip_name_count++;
|
||
}
|
||
}
|
||
|
||
//echo "<pre>";print_r($create_new_letter);exit;
|
||
//exit;
|
||
//this section execute to make AllZip when slot_array is not empty
|
||
if (!empty($_POST['slot_array'])) {
|
||
$new_all_zip_file_dir = "/Allzip_" . $global_member_id . "_" . $global_time;
|
||
if (!empty($new_file_name)) {
|
||
$new_all_zip_file_dir = "/" . $new_file_name . "_Allzip_" . $global_member_id . "_" . $global_time;
|
||
}
|
||
$allzipDir = __DIR__ . "/pdf" . $new_all_zip_file_dir;
|
||
if (!is_dir($allzipDir)) {
|
||
mkdir($allzipDir, 0777, true);
|
||
}
|
||
|
||
$zipname = str_replace("pdf/", "", $zipname);
|
||
|
||
rename(__DIR__ . "/pdf/" . $zipname, $allzipDir . "/" . $zipname);
|
||
}
|
||
}
|
||
}
|
||
//exit;
|
||
//this section execute to make AllZip when slot_array is not empty
|
||
if (!empty($_POST['slot_array'])) {
|
||
|
||
// Get real path for our folder
|
||
$rootPath = realpath($allzipDir);
|
||
// Files which need to be added into zip
|
||
// Initialize archive object
|
||
$zip1 = new ZipArchive();
|
||
$allzipDir = str_replace($new_all_zip_file_dir, "", $allzipDir);
|
||
$zip1->open($allzipDir . $new_all_zip_file_dir . '.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||
$Allzipname = $allzipDir . $new_all_zip_file_dir . '.zip';
|
||
|
||
// Create recursive directory iterator
|
||
/** @var SplFileInfo[] $files */
|
||
$files = new RecursiveIteratorIterator(
|
||
new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY
|
||
);
|
||
|
||
foreach ($files as $name => $file) {
|
||
// Skip directories (they would be added automatically)
|
||
if (!$file->isDir()) {
|
||
// Get real and relative path for current file
|
||
$filePath = $file->getRealPath();
|
||
$relativePath = substr($filePath, strlen($rootPath) + 1);
|
||
|
||
// Add current file to archive
|
||
$zip1->addFile($filePath, $relativePath);
|
||
}
|
||
}
|
||
|
||
// Zip archive will be created only after closing object
|
||
$zip1->close();
|
||
$send_now = true;
|
||
if(isset($_POST['automation_type']) && $_POST['automation_type'] == 4){
|
||
$send_now = false;
|
||
}
|
||
|
||
if (isset($download_type) && $download_type == 1) {
|
||
if(isset($_POST['set_automation']) && $_POST['set_automation'] == 1){
|
||
copyzipToAnotherDir($Allzipname, "/../velocity/".$global_member_id);
|
||
}
|
||
letterEmailSendToClient();
|
||
createZipAndDownload($Allzipname);
|
||
@unlink($Allzipname);
|
||
//code change
|
||
} else if (isset($download_type) && $download_type == 2) {
|
||
$fileuri = realpath($Allzipname);
|
||
$created_filepath = "pdf/" . $new_all_zip_file_dir;
|
||
$pdfFileList = getDirContents($created_filepath);
|
||
$error_no = "Your file will send with due time.";
|
||
|
||
if($send_now){
|
||
$error_no = sendToClient($conn, $download_category, $fileuri, $Allzipname, $pdfFileList);
|
||
}
|
||
//code change
|
||
if(isset($_POST['set_automation']) && $_POST['set_automation'] == 1){
|
||
copyzipToAnotherDir($Allzipname, "/../velocity/".$global_member_id);
|
||
}
|
||
rrmdir($created_filepath);
|
||
@unlink($Allzipname);
|
||
if($send_now){
|
||
letterEmailSendToClient();
|
||
}
|
||
echo json_encode($error_no);
|
||
exit;
|
||
//header('Location:' . $APP_HOST."/dashboard/form/".SERTG_VELOCITY_FORM_ID.$error_no);
|
||
}else if(isset($download_type) && $download_type == 3){
|
||
$created_filepath = "pdf/" . $new_all_zip_file_dir;
|
||
rrmdir($created_filepath);
|
||
storePdfLetters($_POST['client_id'],$global_sertg_id,1,$Allzipname);
|
||
}
|
||
}
|
||
|
||
} else {
|
||
$url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "SERTG.html";
|
||
header("Location:" . $url);
|
||
}
|
||
|
||
|
||
function copyzipToAnotherDir($file,$destination){
|
||
global $global_sertg_id;
|
||
$client_id = 0;
|
||
if(isset($_POST['client_id']) && $_POST['client_id'] > 0){
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
if(!empty($destination)){
|
||
$destination = __DIR__.$destination."/".$client_id."/";
|
||
}
|
||
if(!is_dir($destination)){
|
||
mkdir($destination,0777,true);
|
||
}
|
||
$file_path = "";
|
||
if(!empty($destination) && !empty($global_sertg_id)){
|
||
$file_path = $destination.$global_sertg_id.".zip";
|
||
}
|
||
|
||
if(file_exists($file_path)){
|
||
@unlink($file_path);
|
||
}
|
||
if(!empty($file_path)){
|
||
copy($file,$file_path);
|
||
}
|
||
}
|
||
|
||
function copyPdfToAnotherDir($file,$destination){
|
||
global $global_sertg_id;
|
||
$client_id = 0;
|
||
if(isset($_POST['client_id']) && $_POST['client_id'] > 0){
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
if(!empty($destination)){
|
||
$destination = __DIR__.$destination."/".$client_id."/";
|
||
}
|
||
|
||
$file_path = "";
|
||
if(!empty($destination) && !empty($global_sertg_id)){
|
||
$file_path = $destination.$global_sertg_id;
|
||
}
|
||
|
||
if(!is_dir($file_path)){
|
||
mkdir($file_path,0777,true);
|
||
}
|
||
|
||
$file_name = basename($file);
|
||
if(!empty($file_path) && !empty($file_name)){
|
||
copy($file,$file_path."/".$file_name);
|
||
}
|
||
}
|
||
|
||
function createZipAndDownload($zipFileName) {
|
||
|
||
global $global_member_id, $global_time, $new_file_name;
|
||
// set example variables
|
||
$filename = "Allzip_" . $global_member_id . "_" . $global_time . ".zip"; //"Allzip.zip";
|
||
if (!empty($new_file_name)) {
|
||
$filename = $new_file_name . "_" . $filename;
|
||
}
|
||
$filepath1 = __DIR__ . "/pdf/" . $filename;
|
||
|
||
copyzipToAnotherDir($filepath1, "/../velocity/".$global_member_id);
|
||
zipDownload($filename, $filepath1);
|
||
|
||
if ($fp = fopen($filepath1, 'rb')) {
|
||
ob_end_clean();
|
||
|
||
while (!feof($fp) and ( connection_status() == 0)) {
|
||
print(fread($fp, 8192));
|
||
flush();
|
||
}
|
||
|
||
@fclose($fp);
|
||
}
|
||
|
||
$zipPath = __DIR__ . "/pdf";
|
||
@unlink($filepath1);
|
||
rrmdir($zipPath);
|
||
}
|
||
|
||
function attachmentSetup($imagefilename_attachement,$value) {
|
||
$attached_image_value = "";
|
||
for ($i = 1; $i <= 20; $i++) {
|
||
|
||
|
||
if (isset($_FILES["attachment_" . $i]["name"]) && !empty($_FILES["attachment_" . $i]["name"])) {
|
||
|
||
if ($key == 0) {
|
||
// $imagefilename_attachement[$i] = mt_rand(0, 1000) . time() . '_' . $_FILES["attachment_" . $i]["name"];
|
||
//move_uploaded_file($_FILES["attachment_" . $i]["tmp_name"], $imagefilename_attachement[$i]);
|
||
$deletionArray[] = $imagefilename_attachement[$i];
|
||
}
|
||
}
|
||
|
||
$attDir = 'sertg/attachment/';
|
||
$attached_check_list = $_POST["att_check_" . $i];
|
||
$att_explode = "";
|
||
$att_image_real_path = "";
|
||
if (!empty($attached_check_list) && in_array($value, $attached_check_list)) {
|
||
$check_file = true;
|
||
if (isset($_FILES["attachment_" . $i]["name"]) && !empty($_FILES["attachment_" . $i]["name"])) {
|
||
if(file_exists($attDir . $imagefilename_attachement[$i])){
|
||
$att_image_real_path = realpath($attDir . $imagefilename_attachement[$i]);
|
||
}
|
||
|
||
$attached_image_value .= "<img style='width:100%;' src='" . $att_image_real_path . "'><br/><br/>";
|
||
$check_file = false;
|
||
}
|
||
|
||
if ($check_file && !empty($_POST["temp_attachment_" . $i]) && $_POST['att_img_clear_' . $i] == 0) {
|
||
$att_explode = explode('/', $_POST["temp_attachment_" . $i]);
|
||
if (!empty($att_explode) && ($att_explode[0] == 'contact_photo')) {
|
||
$attDir = "../";
|
||
}
|
||
|
||
if(file_exists($attDir . $_POST["temp_attachment_" . $i])){
|
||
$att_image_real_path = realpath($attDir . $_POST["temp_attachment_" . $i]);
|
||
}
|
||
|
||
$attached_image_value .= "<img style='width:100%;' src='" . $att_image_real_path . "'><br/><br/>";
|
||
}
|
||
}
|
||
}
|
||
//echo $attached_image_value;exit;
|
||
return $attached_image_value;
|
||
}
|
||
|
||
function zipDownload($filename, $filePath) {
|
||
header('Pragma: public');
|
||
header('Expires: -1');
|
||
header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
|
||
header('Content-Transfer-Encoding: binary');
|
||
header("Content-Disposition: attachment; filename=$filename");
|
||
header("Content-Type: application/zip");
|
||
header("Content-Length: " . filesize($filePath));
|
||
header("Content-Description: File Transfer");
|
||
}
|
||
|
||
function rrmdir($dir) {
|
||
if (is_dir($dir)) {
|
||
$objects = scandir($dir);
|
||
foreach ($objects as $object) {
|
||
if ($object != "." && $object != "..") {
|
||
if (is_dir($dir . "/" . $object))
|
||
rrmdir($dir . "/" . $object);
|
||
else
|
||
@unlink($dir . "/" . $object);
|
||
}
|
||
}
|
||
rmdir($dir);
|
||
}
|
||
}
|
||
|
||
function sendToClient($conn, $dropdown_category_id, $zip_file, $file_name = "", $pdfList = array()) {
|
||
|
||
$errors = ""; //"" = no error, 1 = dropbox error , 2 = dropbox success;
|
||
// 3 = zapier error , 4 = zapier success
|
||
// 5 = email error , 6 = email success
|
||
// 7 = google error , 8 = google success
|
||
$errorString = "";
|
||
$final_response['message'] = "";
|
||
$final_response['extras'] = [];
|
||
$dropdown_category_id = implode(",", $dropdown_category_id);
|
||
$category_id = 0;
|
||
$sql = "SELECT * FROM automations where id IN (" . $dropdown_category_id . ")";
|
||
|
||
$result = $conn->query($sql);
|
||
|
||
if ($result->num_rows > 0) {
|
||
$errorArray = [];
|
||
$errorMessages = setErrorMessage();
|
||
while ($row = $result->fetch_assoc()) {
|
||
|
||
$category_id = $row['export_id'];
|
||
$obj = json_decode($row['input_json']);
|
||
|
||
$data = [];
|
||
if (!empty($obj)) {
|
||
$data['access_key'] = !empty($obj->access_key) ? $obj->access_key : '';
|
||
$data['dropbox_token'] = !empty($obj->dropbox_token) ? $obj->dropbox_token : '';
|
||
$data['dropbox_client_id'] = !empty($obj->user_name) ? $obj->user_name : '';
|
||
$data['dropbox_client_secret'] = !empty($obj->password) ? $obj->password : '';
|
||
$data['dropbox_refresh_token'] = !empty($obj->dropbox_refresh_token) ? $obj->dropbox_refresh_token : '';
|
||
$data['email'] = !empty($obj->email) ? $obj->email : '';
|
||
$data['email_subject'] = !empty($obj->email_subject) ? $obj->email_subject : '';
|
||
$data['email_body'] = !empty($obj->email_body) ? $obj->email_body : '';
|
||
$data['google_token'] = !empty($obj->google_token) ? $obj->google_token : '';
|
||
$data['google_client_id'] = !empty($obj->google_client_id) ? $obj->google_client_id : '';
|
||
$data['google_client_secret'] = !empty($obj->google_client_secret) ? $obj->google_client_secret : '';
|
||
$data['google_refresh_token'] = !empty($obj->google_refresh_token) ? $obj->google_refresh_token : '';
|
||
$data['ring_client_id'] = !empty($obj->ring_client_id) ? $obj->ring_client_id : '';
|
||
$data['ring_client_secret'] = !empty($obj->ring_client_secret) ? $obj->ring_client_secret : '';
|
||
$data['ring_account'] = !empty($obj->ring_account) ? $obj->ring_account : '';
|
||
$data['ring_password'] = !empty($obj->ring_password) ? $obj->ring_password : '';
|
||
$data['ring_extension'] = !empty($obj->ring_extension) ? $obj->ring_extension : '';
|
||
$data['ring_isEmailReceived'] = isset($obj->ring_isEmailReceived) ? $obj->ring_isEmailReceived : 0;
|
||
$data['ring_server'] = !empty($obj->ring_server) ? $obj->ring_server : '';
|
||
$data['destination_2'] = !empty($obj->ring_fax_equifax_number) ? $obj->ring_fax_equifax_number : '';
|
||
$data['destination_3'] = !empty($obj->ring_fax_trans_number) ? $obj->ring_fax_trans_number : '';
|
||
$data['destination_1'] = !empty($obj->ring_fax_experian_number) ? $obj->ring_fax_experian_number : '';
|
||
$data['destination_0'] = !empty($obj->ring_fax_default_number) ? $obj->ring_fax_default_number : '';
|
||
$data['destination_4'] = !empty($obj->ring_fax_innovis_number) ? $obj->ring_fax_innovis_number : '';
|
||
$data['destination_5'] = !empty($obj->ring_fax_lexisnexis_number) ? $obj->ring_fax_lexisnexis_number : '';
|
||
$data['destination_6'] = !empty($obj->ring_fax_sagestream_number) ? $obj->ring_fax_sagestream_number : '';
|
||
$data['destination_7'] = !empty($obj->ring_fax_chex_systems_number) ? $obj->ring_fax_chex_systems_number : '';
|
||
$data['destination_8'] = !empty($obj->ring_fax_mib_inc_number) ? $obj->ring_fax_mib_inc_number : '';
|
||
$data['destination_9'] = !empty($obj->ring_factor_inc_number) ? $obj->ring_factor_inc_number : '';
|
||
$data['destination_10'] = !empty($obj->ring_data_furnishers_number) ? $obj->ring_data_furnishers_number : '';
|
||
$data['destination_11'] = !empty($obj->ring_other_number) ? $obj->ring_other_number : '';
|
||
$data['letter_stream_api_key'] = !empty($obj->letter_stream_api_key) ? $obj->letter_stream_api_key : "";
|
||
$data['letter_stream_api_id'] = !empty($obj->letter_stream_api_id) ? $obj->letter_stream_api_id : "";
|
||
$data['letter_stream_token'] = !empty($obj->letter_stream_token) ? $obj->letter_stream_token : "";
|
||
$data['letter_stream_name_1'] = !empty($obj->letter_stream_name_1) ? $obj->letter_stream_name_1 : "";
|
||
$data['letter_stream_name_2'] = !empty($obj->letter_stream_name_2) ? $obj->letter_stream_name_2 : "";
|
||
$data['letter_stream_address_1'] = !empty($obj->letter_stream_address_1) ? $obj->letter_stream_address_1 : "";
|
||
$data['letter_stream_address_2'] = !empty($obj->letter_stream_address_2) ? $obj->letter_stream_address_2 : "";
|
||
$data['letter_stream_city'] = !empty($obj->letter_stream_city) ? $obj->letter_stream_city : "";
|
||
$data['letter_stream_state'] = !empty($obj->letter_stream_state) ? $obj->letter_stream_state : "";
|
||
$data['letter_stream_zip'] = !empty($obj->letter_stream_zip) ? $obj->letter_stream_zip : "";
|
||
|
||
$data['one_drive_client_id'] = !empty($obj->one_drive_client_id) ? $obj->one_drive_client_id : "";
|
||
$data['one_drive_client_secret'] = !empty($obj->one_drive_client_secret) ? $obj->one_drive_client_secret : "";
|
||
$data['one_drive_code'] = !empty($obj->one_drive_code) ? $obj->one_drive_code : "";
|
||
}
|
||
|
||
|
||
if ($category_id == 1) {
|
||
$status = sendEmail($data, $zip_file);
|
||
if ($status) {
|
||
$errors = 6;
|
||
} else {
|
||
$errors = 5;
|
||
}
|
||
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . $row['name'] . " " . $errorMessages[$errors];
|
||
} else {
|
||
$errorString = $row['name'] . " " . $errorMessages[$errors];
|
||
}
|
||
} elseif ($category_id == 2) {
|
||
$status = sendDropbox($data, $file_name);
|
||
if ($status) {
|
||
$errors = 2;
|
||
} else {
|
||
$errors = 1;
|
||
}
|
||
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . $row['name'] . " " . $errorMessages[$errors];
|
||
} else {
|
||
$errorString = $row['name'] . " " . $errorMessages[$errors];
|
||
}
|
||
/*$dropbox_validation_response = getAuthorizeDropbox($data,$dropdown_category_id);
|
||
|
||
if($dropbox_validation_response['status']){
|
||
if($dropbox_validation_response['type'] == 1){
|
||
|
||
}else if($dropbox_validation_response['type'] == 2){
|
||
$final_response['extras'] = $dropbox_validation_response;
|
||
}
|
||
}*/
|
||
|
||
} elseif ($category_id == 3) {
|
||
$status = sendGoogleDrive($data, $zip_file);
|
||
if ($status) {
|
||
$errors = 8;
|
||
} else {
|
||
$errors = 7;
|
||
}
|
||
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . $row['name'] . " " . $errorMessages[$errors];
|
||
} else {
|
||
$errorString = $row['name'] . " " . $errorMessages[$errors];
|
||
}
|
||
} elseif ($category_id == 4) {
|
||
if (!empty($data['access_key'])) {
|
||
$status = sendZapier($data['access_key'], $zip_file);
|
||
if ($status) {
|
||
$errors = 4;
|
||
} else {
|
||
$errors = 3;
|
||
}
|
||
}
|
||
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . $row['name'] . " " . $errorMessages[$errors];
|
||
} else {
|
||
$errorString = $row['name'] . " " . $errorMessages[$errors];
|
||
}
|
||
} elseif ($category_id == 5) {
|
||
|
||
$equfax_number = $data['ring_fax_equifax_number'];
|
||
$trans_number = $data['ring_fax_trans_number'];
|
||
$experian_number = $data['ring_fax_experian_number'];
|
||
$fax_number_assoc_fax_content = [];
|
||
$fax_error_status_array = [];
|
||
$selectedDestination = $_POST['dest_check_1'];
|
||
global $totalAccountSection;
|
||
$allPdfAndNumbers = [];
|
||
for ($dest = 1; $dest <= $totalAccountSection; $dest++) {
|
||
if (isset($_POST['dest_check_' . $dest]) && !empty($_POST['dest_check_' . $dest])) {
|
||
$selectedDestination = $_POST['dest_check_' . $dest];
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (!empty($selectedDestination)) {
|
||
foreach ($selectedDestination as $dest) {
|
||
$tempArray = array();
|
||
|
||
$fax_number = $data['destination_0'];
|
||
|
||
$destName = get_destination_name()[$dest];
|
||
|
||
if (!empty($pdfList)) {
|
||
foreach ($pdfList as $pdf) {
|
||
if (is_file($pdf)) {
|
||
$current_pdf_name = basename($pdf);
|
||
if (strpos($current_pdf_name, $destName) !== false) {
|
||
$destination_no = checkDestinationNameExist($current_pdf_name);
|
||
if (!empty($data['destination_' . $destination_no])) {
|
||
$fax_number = $data['destination_' . $destination_no];
|
||
}
|
||
|
||
if ($destination_no == 1 || $destination_no == 2 || $destination_no == 3) {
|
||
$fax_numbers = explode(',', $fax_number);
|
||
if (!empty($fax_numbers) && is_array($fax_numbers)) {
|
||
foreach ($fax_numbers as $squence => $number) {
|
||
$number = str_replace([" ", "-", ")", "("], "", $number);
|
||
if (!empty($number) && !empty($pdf)) {
|
||
$tempArray[] = ['pdf' => $pdf, 'fax_number' => $number];
|
||
$allPdfAndNumbers[$destination_no][] = ['pdf' => $pdf, 'fax_number' => $number,'db_key'=>'destination_' . $destination_no,'sequence'=>$squence];
|
||
}
|
||
}
|
||
}
|
||
} else {
|
||
$fax_number = str_replace([" ", "-", ")", "("], "", $fax_number);
|
||
if (!empty($fax_number) && !empty($pdf)) {
|
||
$tempArray[] = ['pdf' => $pdf, 'fax_number' => $fax_number];
|
||
$allPdfAndNumbers[$destination_no][] = ['pdf' => $pdf, 'fax_number' => $fax_number,'db_key'=>'destination_' . $destination_no,'sequence'=>""];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!empty($tempArray)) {
|
||
$logsArray = $tempArray;
|
||
}
|
||
}
|
||
}
|
||
|
||
$finalArray = [];
|
||
if (!empty($allPdfAndNumbers)) {
|
||
foreach ($allPdfAndNumbers as $allpdf) {
|
||
if (!empty($allpdf)) {
|
||
foreach ($allpdf as $current_row) {
|
||
$finalArray[] = $current_row;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
$allPdfAndNumbers = $finalArray;
|
||
|
||
$response = sendFaxByringcentral($allPdfAndNumbers, $data);
|
||
if(isset($_POST['set_automation']) && $_POST['set_automation'] == 1){
|
||
if (!empty($response['faxinfo'])) {
|
||
global $global_member_id;
|
||
global $global_sertg_id;
|
||
$client_id = 0;
|
||
if (isset($_POST['client_id']) && $_POST['client_id'] > 0) {
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
$successResponseList = [];
|
||
$dir = "/../velocity/ringcentral/" . $global_member_id . '/'.$client_id."/". $global_sertg_id;
|
||
removeDirFilesFromDir($dir);
|
||
$unique_file_list = [];
|
||
foreach ($response['faxinfo'] as $sent_pdf_file) {
|
||
if($sent_pdf_file['status']){
|
||
$file_info_for_json['status'] = $sent_pdf_file['status'];
|
||
$file_info_for_json['pdf'] = $sent_pdf_file['pdf'];
|
||
$file_info_for_json['fax_number'] = $sent_pdf_file['fax_number'];
|
||
$file_info_for_json['db_key'] = $sent_pdf_file['db_key'];
|
||
$file_info_for_json['sequence'] = $sent_pdf_file['sequence'];
|
||
$successResponseList[] = $file_info_for_json;
|
||
if(!in_array($sent_pdf_file['file_full_path'], $unique_file_list)){
|
||
copyPdfToAnotherDir($sent_pdf_file['file_full_path'], "/../velocity/ringcentral/" . $global_member_id);
|
||
$unique_file_list[] = $sent_pdf_file['file_full_path'];
|
||
}
|
||
}
|
||
}
|
||
pdfInfoToJson($successResponseList, "/../velocity/ringcentral/");
|
||
}
|
||
}
|
||
$fax_number_assoc_fax_content = $response['faxinfo'];
|
||
$errors = 10;
|
||
if (!empty($fax_number_assoc_fax_content)) {
|
||
foreach ($fax_number_assoc_fax_content as $res) {
|
||
if (!$res['status']) {
|
||
$errors = 9;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// $file = fopen("sertg_export_error.txt","a");
|
||
// fwrite($file, json_encode($fax_number_assoc_fax_content));// replace will be by $fax_number_assoc_fax_content
|
||
// fclose($file);
|
||
//Send email to member if has checked for this member
|
||
if ($data['ring_isEmailReceived'] == 1 && !empty($fax_number_assoc_fax_content)) {
|
||
$member_email = $_POST['member_email'];
|
||
global $client_name;
|
||
sendEmailToMember($member_email, $fax_number_assoc_fax_content, $zip_file, $client_name);
|
||
}
|
||
}
|
||
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . $row['name'] . " " . $errorMessages[$errors];
|
||
} else {
|
||
$errorString = $row['name'] . " " . $errorMessages[$errors];
|
||
}
|
||
} elseif ($category_id == LETTER_STREAM_TYPE) {
|
||
$api_key = $data['letter_stream_api_key'];
|
||
$api_id = $data['letter_stream_api_id'];
|
||
$info['from'] = letterStreamRetunAddressGenerate($data);
|
||
$info['letter_stream_name_1'] = $data['letter_stream_name_1'];
|
||
$info['letter_stream_name_2'] = $data['letter_stream_name_2'];
|
||
$letterStreamResponse = sendToLetterStream($api_id, $api_key, $pdfList, $info);
|
||
extract($letterStreamResponse);
|
||
if ($status) {
|
||
$errors = 13;
|
||
} else {
|
||
$errors = 14;
|
||
}
|
||
|
||
if ($errors == 13) {
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . "The file has been sent to your letter stream.";
|
||
} else {
|
||
$errorString = "The file has been sent to your letter stream.";
|
||
}
|
||
} else if ($errors == 14) {
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . "Some files have not been sent to letterstream.";
|
||
} else {
|
||
$errorString = "Some files have not been sent to letterstream.";
|
||
}
|
||
|
||
if ($errorcode == -900) {
|
||
$errorString .= " Job name must be 8 to 20 characters (a-zA-Z0-9_-).";
|
||
} else if ($errorcode == -901) {
|
||
$errorString .= " Missing recipient address.";
|
||
} else if ($errorcode == -902) {
|
||
$errorString .= " Missing sender address";
|
||
} else if ($errorcode == -903) {
|
||
$errorString .= " Page count out of range";
|
||
} else if ($errorcode == -904) {
|
||
$errorString .= " Document page count does not match received page count";
|
||
} else if ($errorcode == -905) {
|
||
$errorString .= " Provided sheet color is invalid";
|
||
} else if ($errorcode == -906) {
|
||
$errorString .= " Provided MailType is invalid";
|
||
} else if ($errorcode == -907) {
|
||
$errorString .= " Provided PaperType is invalid";
|
||
} else if ($errorcode == -908) {
|
||
$errorString .= " 1 page documents must not be flagged as duplex";
|
||
} else if ($errorcode == -909) {
|
||
$errorString .= " ";
|
||
} else if ($errorcode == 910) {
|
||
$errorString .= " Missing Document File";
|
||
} else if ($errorcode == -911) {
|
||
$errorString .= " Insufficient funding. Items will not be processed until additional funding is added to your account";
|
||
} else if ($errorcode == -912) {
|
||
$errorString .= " Wrong file type";
|
||
} else if ($errorcode == -913) {
|
||
$errorString .= " No files found in submitted archive";
|
||
} else if ($errorcode == -914) {
|
||
$errorString .= " Could not copy file";
|
||
} else if ($errorcode == -915) {
|
||
$errorString .= " File error";
|
||
} else if ($errorcode == -916) {
|
||
$errorString .= " Could not open PDF for reading";
|
||
} else if ($errorcode == -917) {
|
||
$errorString .= " PDF file count does not match data file PDFs";
|
||
} else if ($errorcode == -918) {
|
||
$errorString .= " File Link Error";
|
||
} else if ($errorcode == -920) {
|
||
$errorString .= " Missing API Id";
|
||
} else if ($errorcode == -921) {
|
||
$errorString .= " Doc Id must be 6 to 30 alphanumeric";
|
||
} else if ($errorcode == -922) {
|
||
$errorString .= " Document Id error";
|
||
} else if ($errorcode == -924) {
|
||
$errorString .= " invalid doc id";
|
||
} else if ($errorcode == -925) {
|
||
$errorString .= " Batch Id is not unique";
|
||
} else if ($errorcode == -926) {
|
||
$errorString .= " invalid batch id";
|
||
} else if ($errorcode == -928) {
|
||
$errorString .= " invalid job id";
|
||
} else if ($errorcode == -929) {
|
||
$errorString .= " invalid tracking id";
|
||
} else if ($errorcode == -930) {
|
||
$errorString .= " Unable to parse data";
|
||
} else if ($errorcode == -935) {
|
||
$errorString .= " Unable to handle saved insert";
|
||
} else if ($errorcode == -940) {
|
||
$errorString .= " ";
|
||
} else if ($errorcode == -950) {
|
||
$errorString .= " ";
|
||
} else if ($errorcode == -951) {
|
||
$errorString .= " ";
|
||
} else if ($errorcode == -952) {
|
||
$errorString .= " Missing API_ID";
|
||
} else if ($errorcode == 953) {
|
||
$errorString .= " Missing Hash";
|
||
} else if ($errorcode == -954) {
|
||
$errorString .= " t arg does not meet requirements";
|
||
} else if ($errorcode == -955) {
|
||
$errorString .= " Missing unique_id (t arg)";
|
||
} else if ($errorcode == -956) {
|
||
$errorString .= " c arg does not meet requirements";
|
||
} else if ($errorcode == -957) {
|
||
$errorString .= " DUP";
|
||
} else if ($errorcode == -958) {
|
||
$errorString .= " IDOK";
|
||
} else if ($errorcode == -959) {
|
||
$errorString .= " BAD";
|
||
} else if ($errorcode == -970) {
|
||
$errorString .= " Certified tracking number invalid";
|
||
} else if ($errorcode == -998) {
|
||
$errorString .= " Improper submission format:";
|
||
} else if ($errorcode == -999) {
|
||
$errorString .= " ";
|
||
}
|
||
}
|
||
} elseif ($category_id == ONE_DRIVE_TYPE) {
|
||
|
||
$clientId = $data['one_drive_client_id'];
|
||
$clientSec = $data['one_drive_client_secret'];
|
||
$token = $data['one_drive_code'];
|
||
$attachment = $zip_file;
|
||
$response = sendToOneDrive($clientId, $clientSec, $token, $attachment);
|
||
if ($response['status']) {
|
||
$errors = 11;
|
||
} else {
|
||
$errors = 12;
|
||
}
|
||
if (!empty($errorString)) {
|
||
$errorString .= "\n" . "The file has been sent to your one drive.";
|
||
} else {
|
||
$errorString = "The file has been sent to your one drive.";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
$final_response['message'] = $errorString;
|
||
|
||
return $final_response;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
function sendToOneDrive($clientId, $clientSec, $token, $attachment) {
|
||
require 'vendor_onedrive/autoload.php';
|
||
global $global_member_id;
|
||
$result = false;
|
||
$values = [
|
||
'client_id' => $clientId,
|
||
'client_secret' => $clientSec,
|
||
'grant_type' => 'refresh_token',
|
||
'refresh_token' => $token,
|
||
];
|
||
$redirect_url = 'https://readytogoletters.com/one_drive_key_generator.php';
|
||
// $ch = curl_init();
|
||
// curl_setopt($ch, CURLOPT_URL, Client::TOKEN_URL);
|
||
// curl_setopt($ch, CURLOPT_POST, 1);
|
||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $values);
|
||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
// $server_output = curl_exec($ch);
|
||
// curl_close($ch);
|
||
|
||
$server_output = makeCurlRequest($values,Client::TOKEN_URL,[]);
|
||
$res = json_decode($server_output);
|
||
// if($global_member_id == 51){
|
||
// echo "<pre>";print_r($res);exit;
|
||
// }
|
||
|
||
|
||
$graph = new Graph();
|
||
$graph->setAccessToken($res->access_token);
|
||
|
||
$client = new Client(
|
||
$clientId, $graph, new GuzzleHttpClient(), [
|
||
'state' => (object) [
|
||
'redirect_uri' => $redirect_url,
|
||
'token' => (object) [
|
||
'obtained' => time(),
|
||
'data' => $res
|
||
]
|
||
]]
|
||
);
|
||
|
||
$state = $client->getState();
|
||
$generated_refresh_token = $state->token->data->refresh_token;
|
||
//$attachment
|
||
$myfile = file_get_contents($attachment);
|
||
|
||
// Past this point, you can start using file/folder functions from the SDK, eg:
|
||
$file_name = basename($attachment);
|
||
$file = $client->getRoot()->upload($file_name, $myfile);
|
||
//$children = $file
|
||
if ($token != $generated_refresh_token) {
|
||
$result = true;
|
||
}
|
||
|
||
return $result;
|
||
/// one drive api code here
|
||
}
|
||
|
||
function sendToLetterStream($api_id, $api_key, $pdfList, $info) {
|
||
|
||
$response = false;
|
||
$response = letterStreamProcess($api_id, $api_key, $info);
|
||
return $response;
|
||
}
|
||
|
||
function sendEmailToMember($memberEmail, $contents, $zip_file, $client_name) {
|
||
|
||
$current_date = date('F m,y');
|
||
$emailSubject = "Fax Sent at: " . $current_date;
|
||
if (!empty($client_name)) {
|
||
$emailSubject = "Fax Sent To: " . str_replace(" ", "_", $client_name) . "_" . $current_date;
|
||
}
|
||
$data['email'] = $memberEmail;
|
||
$data['email_subject'] = $emailSubject;
|
||
$contentString = "";
|
||
/* $file = fopen("fax_error.txt","w");
|
||
fwrite($file,json_encode($contents));
|
||
fclose($file); */
|
||
if (!empty($contents)) {
|
||
foreach ($contents as $key => $faxinfo) {
|
||
if ($faxinfo['status']) {
|
||
if (!empty($contentString)) {
|
||
$contentString .= "<p>" . $faxinfo['pdf'] . " has been <span style = 'color:green'>successfully</span> sent to " . $faxinfo['fax_number'] . "</p>";
|
||
} else {
|
||
$contentString = "<p>" . $faxinfo['pdf'] . " has been <span style = 'color:green'>successfully</span> sent to " . $faxinfo['fax_number'] . "</p>";
|
||
}
|
||
} else {
|
||
if (!empty($contentString)) {
|
||
$contentString .= "<p>" . $faxinfo['pdf'] . " has been <span style = 'color:red'>failed</span> to sent on " . $faxinfo['fax_number'] . "</p>";
|
||
} else {
|
||
$contentString = "<p>" . $faxinfo['pdf'] . " has been <span style = 'color:red'>failed</span> to sent on " . $faxinfo['fax_number'] . "</p>";
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!empty($client_name)) {
|
||
$contentString .= "<p>Client name : " . $client_name . "</p>";
|
||
}
|
||
|
||
$data['email_body'] = $contentString;
|
||
|
||
if (!empty($data['email'])) {
|
||
sendEmail($data, $zip_file);
|
||
}
|
||
}
|
||
|
||
|
||
function checkDestinationNameExist($pdf_name) {
|
||
$result = 0;
|
||
if (!empty(DESTINATIONS_NAME)) {
|
||
foreach (DESTINATIONS_NAME as $key => $dname) {
|
||
if (strpos($pdf_name, $dname) !== false) {
|
||
$result = $key;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
//function getPersonalize() {
|
||
// $member_ID = $_POST['member_id'];
|
||
// global $conn;
|
||
// $personalize = [];
|
||
// $sql = "select * from personalizes where member_id = " . $member_ID;
|
||
//
|
||
// $result = $conn->query($sql);
|
||
// if ($result->num_rows > 0) {
|
||
// while ($row = $result->fetch_assoc()) {
|
||
// $personalize = $row;
|
||
// }
|
||
// }
|
||
// return $personalize;
|
||
//}
|
||
|
||
|
||
|
||
|
||
|
||
|
||
function sendGoogleDrive($data, $zip_file) {
|
||
$result = true;
|
||
$clientId = $data['google_client_id']; //'1069879966426-fuv8et5l7abndhtttqhpofc636e3kkn3.apps.googleusercontent.com';
|
||
$clientSec = $data['google_client_secret']; //'nfcvOzisrBkN4xYXBAhQtlkg';
|
||
|
||
$accessToken = $data['google_token']; //'ya29.GlvvBtJrYayeGo9gsWSx622trc-kwj73uB9KVoZundmCbqrDtZ3nFkhmkcXFhluIkKsC6gc3I-z_q_NGBOcPBi_bjvlJoNhpETcvzxkOQNQwKTjH_lNfXs4fXGe1';
|
||
$refreshToken = $data['google_refresh_token']; //'1/pG_de-9RBo4L2HvyCPgjYhVljKPZwQ2TNBgyMGIQKLHykhtDjg_uMtFc1a1HY9pf';
|
||
//$clientId = "asdasdasd";
|
||
$redirectUrl = 'urn:ietf:wg:oauth:2.0:oob';
|
||
$tokenObj = '{"access_token":"' . $accessToken . '","expires_in":3600,"scope":"https:\/\/www.googleapis.com\/auth\/drive.file","token_type":"Bearer","created":1555475349,"refresh_token":"' . $refreshToken . '"}';
|
||
$tokenPath = 'token.json';
|
||
$file_path = realpath($zip_file);
|
||
$file_name = basename($file_path);
|
||
|
||
// Get the API client and construct the service object.
|
||
$client = getGoogleClient($clientId, $clientSec, $redirectUrl, $tokenObj, $tokenPath);
|
||
|
||
$service = new Google_Service_Drive($client);
|
||
|
||
if ($service) {
|
||
$mime_type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file_path);
|
||
|
||
$fileMetadata = new Google_Service_Drive_DriveFile(array(
|
||
'name' => $file_name, 'mimeType' => $mime_type));
|
||
|
||
$content = file_get_contents($file_path);
|
||
try {
|
||
$file = $service->files->create($fileMetadata, array(
|
||
'data' => $content,
|
||
'mimeType' => $mime_type,
|
||
'uploadType' => 'multipart',
|
||
'fields' => 'id'));
|
||
|
||
//printf("Upload Success. File ID: %s\n", $file->id);
|
||
} catch (\Exception $e) {
|
||
if (!empty($e->getMessage())) {
|
||
errorLog("Google drive error", $e->getMessage());
|
||
}
|
||
|
||
$result = false;
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
function sendRingCentral($data) {
|
||
|
||
}
|
||
|
||
function sendZapier($zapier_url, $fileuri) {
|
||
|
||
$result = true;
|
||
|
||
//Initialise the cURL var
|
||
// $ch = curl_init();
|
||
// converts the file into binary for sending
|
||
$fileuri = curl_file_create($fileuri, '', '');
|
||
|
||
|
||
// Get the response from cURL
|
||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
|
||
//Set the Url
|
||
// curl_setopt($ch, CURLOPT_URL, $zapier_url);
|
||
|
||
//Create a POST array with the file in it
|
||
$postData = array(
|
||
'file' => $fileuri,
|
||
);
|
||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
||
|
||
// Receive server response ...
|
||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||
// Execute the request
|
||
// $response = curl_exec($ch);
|
||
//$server_output = curl_exec($ch);
|
||
$server_output = makeCurlRequest($postData,$zapier_url,[]);
|
||
echo "<pre>";print_r($server_output);exit;
|
||
if ($server_output == false) {
|
||
$result = false;
|
||
}
|
||
|
||
|
||
// curl_close($ch);
|
||
return $result;
|
||
}
|
||
|
||
function getGoogleClient($clientId, $clientSec, $redirectUrl, $tokenObj = '', $tokenPath = '') {
|
||
|
||
$client = new Google_Client();
|
||
$client->setApplicationName('RTG Google Drive API Quickstart');
|
||
$client->setScopes(Google_Service_Drive::DRIVE_FILE);
|
||
$client->setClientId($clientId);
|
||
$client->setClientSecret($clientSec);
|
||
$client->setRedirectUri($redirectUrl);
|
||
$client->setAccessType('offline');
|
||
$client->setApprovalPrompt('auto');
|
||
|
||
// Load previously authorized token from a file, if it exists.
|
||
// The file token.json stores the user's access and refresh tokens, and is
|
||
// created automatically when the authorization flow completes for the first
|
||
// time.
|
||
|
||
if (file_exists($tokenPath) && is_file($tokenPath)) {
|
||
$accessTokenArray = json_decode(file_get_contents($tokenPath), true);
|
||
if ($accessTokenArray != null) {
|
||
$client->setAccessToken($accessTokenArray);
|
||
$accessToken = $accessTokenArray;
|
||
}
|
||
} else if (is_string($tokenObj) && $tokenObj != null && $tokenObj != '') {
|
||
$accessTokenArray = json_decode($tokenObj, true);
|
||
$client->setAccessToken($accessTokenArray);
|
||
// $accessToken = $accessTokenArray['access_token'];
|
||
}
|
||
|
||
// If there is no previous token or it's expired.
|
||
if ($client->isAccessTokenExpired()) {
|
||
// Refresh the token if possible, else fetch a new one.
|
||
if ($client->getRefreshToken()) {
|
||
$client->fetchAccessTokenWithRefreshToken($client->getRefreshToken());
|
||
} else {
|
||
|
||
// Request authorization from the user.
|
||
$authUrl = $client->createAuthUrl();
|
||
|
||
echo '
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||
<title>Document</title>
|
||
</head>
|
||
<body>
|
||
<a href=' . $authUrl . ' id="link" target="_blank">Click to Generate Token</a>
|
||
<script>
|
||
// document.getElementById("link").click();
|
||
</script>
|
||
</body>
|
||
</html>
|
||
';
|
||
print '<form action="index.php" method="GET">
|
||
<input type="text" name="verify" placeholder="Enter verification code:">
|
||
<input type="submit" name="Submit" value="Submit">
|
||
</form>';
|
||
|
||
if (isset($_GET['verify']) && $_GET['verify'] != '') {
|
||
$authCode = $_GET['verify'];
|
||
|
||
// header('location: '. $authUrl);
|
||
// Exchange authorization code for an access token.
|
||
if (isset($authCode)) {
|
||
// $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
|
||
$accessToken = $client->fetchAccessTokenWithAuthCode($authCode);
|
||
$client->setAccessToken($accessToken);
|
||
}
|
||
// Check to see if there was an error.
|
||
if (array_key_exists('error', $accessToken)) {
|
||
throw new Exception(join(', ', $accessToken));
|
||
}
|
||
}
|
||
}
|
||
// Save the token to a file.
|
||
// if (!file_exists(dirname($tokenPath))) {
|
||
// mkdir(dirname($tokenPath), 0700, true);
|
||
// }
|
||
// file_put_contents($tokenPath, json_encode($client->getAccessToken()));
|
||
}
|
||
return $client;
|
||
}
|
||
|
||
function getDirContents($dir, &$results = array()) {
|
||
$files = scandir($dir);
|
||
|
||
|
||
foreach ($files as $key => $value) {
|
||
$path = realpath($dir . DIRECTORY_SEPARATOR . $value);
|
||
if (!is_dir($path)) {
|
||
$results[] = $path;
|
||
} else if ($value != "." && $value != "..") {
|
||
getDirContents($path, $results);
|
||
$results[] = $path;
|
||
}
|
||
}
|
||
|
||
return $results;
|
||
}
|
||
|
||
function sendFaxByringcentral($fileAndNumber, $data) {
|
||
|
||
$result = ['status' => false, 'faxinfo' => []];
|
||
global $member_ID;
|
||
|
||
|
||
$resultArray = [];
|
||
$rcsdk = new SDK($data['ring_client_id'], $data['ring_client_secret'], $data['ring_server'], 'Fax|SMS|MMS', '1.0.0');
|
||
$platform = $rcsdk->platform();
|
||
|
||
// Authorize
|
||
|
||
try {
|
||
|
||
$isInserted = false;
|
||
$platform->login($data['ring_account'], $data['ring_extension'], $data['ring_password']);
|
||
if ($rcsdk->platform()->loggedIn()) {
|
||
$isInserted = insertFaxInfoToDB($data,$fileAndNumber);
|
||
}
|
||
//$request = $rcsdk->createMultipartBuilder();
|
||
// Send Fax
|
||
|
||
$faxStatusArray = [];
|
||
if ($isInserted && !empty($fileAndNumber)) {
|
||
foreach ($fileAndNumber as $faxInfo) {
|
||
// $request = $rcsdk->createMultipartBuilder()->setBody(array(
|
||
// 'to' => array(
|
||
// array('phoneNumber' => $faxInfo['fax_number']),
|
||
// ),
|
||
// 'faxResolution' => 'High',
|
||
// 'coverIndex' => 0
|
||
// ))->add(fopen($faxInfo['pdf'], 'r'), basename($faxInfo['pdf']))
|
||
// ->request('/account/~/extension/~/fax');
|
||
//
|
||
// $response = $platform->sendRequest($request);
|
||
// $status = $response->response()->getStatusCode();
|
||
$faxStatusArray[] = ['status' => true, 'pdf' => basename($faxInfo['pdf']), 'fax_number' => $faxInfo['fax_number'],'file_full_path'=>$faxInfo['pdf'],'db_key'=>$faxInfo['db_key'],'sequence'=>$faxInfo['sequence']];
|
||
}
|
||
}
|
||
|
||
|
||
|
||
$result = ['status' => true, 'faxinfo' => $faxStatusArray];
|
||
} catch (\Exception $e) {
|
||
if (!empty($e->getMessage())) {
|
||
global $global_member_id;
|
||
$error_string = "Member ID: ".$global_member_id." Error message : ".$e->getMessage();
|
||
errorLog("RingCentral Fax error", $error_string);
|
||
}
|
||
$result = ['status' => false, 'faxinfo' => $fileAndNumber];
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
function insertTable($table,$data){
|
||
global $conn;
|
||
$sql = "";
|
||
if(!empty($data)){
|
||
|
||
|
||
$value_string = "";
|
||
foreach($data as $value){
|
||
if(!empty($value_string)){
|
||
$value_string .= ",'".$value."'";
|
||
}else{
|
||
$value_string .= "'".$value."'";
|
||
}
|
||
}
|
||
if(!empty($value_string)){
|
||
$sql= "INSERT INTO $table (".implode(',', array_keys($data)).") VALUES ";
|
||
$sql .="(".$value_string.")";
|
||
}
|
||
|
||
}
|
||
|
||
$inserted_id = 0;
|
||
if ($conn->query($sql) === TRUE) {
|
||
$inserted_id = mysqli_insert_id($conn);
|
||
}
|
||
|
||
return $inserted_id;
|
||
}
|
||
|
||
function insertFaxInfoToDB($faxInfo,$fileAndNumber){
|
||
|
||
$result = false;
|
||
global $conn;
|
||
global $global_member_id;
|
||
|
||
$sql = "";
|
||
$pdf_file_list = [];
|
||
|
||
if(!empty($fileAndNumber)){
|
||
|
||
$deafult_fax_number = $faxInfo['destination_0'];
|
||
$current_date_time = date('Y-m-d H:i:s');
|
||
|
||
$faxNumbersData['member_id'] = $global_member_id;
|
||
$faxNumbersData['letter_type'] = 1;
|
||
|
||
$faxNumbersData['fax_client_id'] = trim($faxInfo['ring_client_id']);
|
||
$faxNumbersData['fax_client_secret'] = trim($faxInfo['ring_client_secret']);
|
||
$faxNumbersData['fax_password'] = $faxInfo['ring_password'];
|
||
$faxNumbersData['fax_extension'] = $faxInfo['ring_extension'];
|
||
$faxNumbersData['fax_account'] = $faxInfo['ring_account'];
|
||
$faxNumbersData['fax_server'] = $faxInfo['ring_server'];
|
||
$faxNumbersData['is_receive_email'] = $faxInfo['ring_isEmailReceived'];
|
||
|
||
$faxNumberFile['fax_number_id'] = $fax_number_id;
|
||
$faxNumberFile['is_send'] = 0;
|
||
$faxNumberFile['count_attempt'] = 0;
|
||
$faxNumberFile['created_on'] = $current_date_time;
|
||
$faxNumberFile['modified_on'] = $current_date_time;
|
||
$faxNumberFile['fax_file_path'] = "";
|
||
|
||
$sql= "INSERT INTO fax_number_files (".implode(',', array_keys($faxNumberFile)).") VALUES ";
|
||
|
||
$sql_muliple_values_string = "";
|
||
|
||
foreach($fileAndNumber as $file){
|
||
$pdf_file_path = $file['pdf'];
|
||
if(!file_exists($pdf_file_path)){
|
||
continue;
|
||
}
|
||
|
||
$batch_num = $global_member_id . "_" . time();
|
||
$faxNumbersData['batch_num'] = $batch_num;
|
||
$faxNumbersData['fax_number'] = !empty($file['fax_number']) ? $file['fax_number'] : $deafult_fax_number;
|
||
$faxNumbersData['fax_number'] = str_replace([" ", "-", ")", "("], "", $faxNumbersData['fax_number']);
|
||
|
||
$fax_number_id = insertTable('fax_numbers',$faxNumbersData); // fax_numbers insertion
|
||
|
||
$faxNumberFile['fax_number_id'] = $fax_number_id;
|
||
$faxNumberFile['fax_file_path'] = $global_member_id . "_" . time() . "_" . basename($pdf_file_path);
|
||
$pdf_file_list[] = [
|
||
'fax_number_id' => $fax_number_id,
|
||
'old_file_path' => $pdf_file_path,
|
||
'new_file_path' => $faxNumberFile['fax_file_path']
|
||
];
|
||
$value_string = "";
|
||
foreach($faxNumberFile as $value){
|
||
if(!empty($value_string)){
|
||
$value_string .= ",'".$value."'";
|
||
}else{
|
||
$value_string .= "'".$value."'";
|
||
}
|
||
}
|
||
if(!empty($value_string)){
|
||
$value_string = "(".$value_string.")";
|
||
if(!empty($sql_muliple_values_string)){
|
||
$sql_muliple_values_string .= ",".$value_string;
|
||
}else{
|
||
$sql_muliple_values_string = $value_string;
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!empty($sql_muliple_values_string)){
|
||
$sql .= $sql_muliple_values_string;
|
||
}
|
||
}
|
||
|
||
if (!empty($pdf_file_list) && !empty($sql) && $conn->query($sql) === TRUE) {
|
||
|
||
foreach ($pdf_file_list as $current_file){
|
||
$fax_number_id = $current_file['fax_number_id'];
|
||
$fax_pdf_file_dir = __DIR__."/../velocity/fax/pdf/".$fax_number_id;
|
||
if (!is_dir($fax_pdf_file_dir)) {
|
||
mkdir($fax_pdf_file_dir, 0777, true);
|
||
}
|
||
@copy($current_file['old_file_path'], $fax_pdf_file_dir . "/" . $current_file['new_file_path']);
|
||
}
|
||
|
||
$result = true;
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
function letterStreamProcess($api_id, $api_key, $info) {
|
||
|
||
$finalresponse = ['status' => false, 'errorcode' => ""];
|
||
$is_letterstream_duplex = "N";
|
||
if(isset($_POST['is_letterstream_duplex']) && $_POST['is_letterstream_duplex'] == 'Y'){
|
||
$is_letterstream_duplex = "Y";
|
||
}
|
||
|
||
$mailType = "firstclass";
|
||
if(isset($_POST['mailType']) && $_POST['mailType'] == 'certified'){
|
||
$mailType = "certified";
|
||
}
|
||
|
||
global $global_html;
|
||
global $other_address_html;
|
||
global $df_global_html;
|
||
global $letter_stream_pr_variable;
|
||
global $client_name;
|
||
$client_id = $_POST['client_id'];
|
||
global $conn;
|
||
global $fileTypeString;
|
||
$pi_di_str = $fileTypeString;
|
||
$isBureaus = true;
|
||
$path = "pdf/letterstream/";
|
||
if (!is_dir($path)) {
|
||
mkdir($path, 0777, true);
|
||
}
|
||
$other_address = $_POST['other_address'];
|
||
$other_formated_address = getFormatedDFAddress(RemoveBS($other_address));
|
||
|
||
$letter_stream_address_other = $_POST['letter_stream_address_other'];
|
||
|
||
$df_addresses = $_POST['letter_stream_address_11'];
|
||
$test['df_addresses'] = $df_addresses;
|
||
$test['df_global_html'] = $df_global_html;
|
||
|
||
$selected_df_address = [];
|
||
if (isset($_POST['selected_df_address']) && !empty($_POST['selected_df_address'])) {
|
||
$selected_df_address = $_POST['selected_df_address'];
|
||
}
|
||
|
||
|
||
$file_dir_array = [];
|
||
$destinationAssocPdf = [];
|
||
$member_ID = $_POST['member_id'];
|
||
$count = 0;
|
||
$db_client_count = 0;
|
||
$no_of_jobs = 0;
|
||
$testJobName = [];
|
||
$generated_pdf_file_list = [];
|
||
$successfully_sent_pdf = [];
|
||
|
||
// PR address for letterstream
|
||
if (!empty($letter_stream_pr_variable) && !empty($_POST['letter_stream_address_pr'])) {
|
||
$letter_stream_address_pr = $_POST['letter_stream_address_pr'];
|
||
$return_pr_address = $_POST['return_pr_address'];
|
||
$checkbox_pr_return_address = $_POST['checkbox_pr_return_address'];
|
||
$no_of_jobs = getTotalJobForPR($letter_stream_pr_variable);
|
||
if ($client_id > 0) {
|
||
$client_sql = "select clients.*,contacts.*"
|
||
. " from clients INNER JOIN contacts ON contacts.client_id = clients.id "
|
||
. "where contacts.is_primary_contact = 1 AND clients.id = $client_id";
|
||
|
||
$client_sql_result = $conn->query($client_sql);
|
||
$contact_info = [];
|
||
if ($client_sql_result->num_rows > 0) {
|
||
while ($row = $client_sql_result->fetch_assoc()) {
|
||
|
||
if($db_client_count == 0){
|
||
$db_client_count = $row['count_letterstream'];
|
||
}
|
||
|
||
if ($row['is_letterstream_return_address'] == 1) {
|
||
$contact_info['letter_stream_name_1'] = $row['first_name'];
|
||
$contact_info['letter_stream_name_2'] = $row['last_name'];
|
||
$contact_info['letter_stream_address_1'] = $row['address'];
|
||
$contact_info['letter_stream_address_2'] = "";
|
||
$contact_info['letter_stream_city'] = $row['city'];
|
||
$contact_info['letter_stream_state'] = $row['state'];
|
||
$contact_info['letter_stream_zip'] = $row['zip_code'];
|
||
$info['from'] = letterStreamRetunAddressGenerate($contact_info);
|
||
$info['letter_stream_name_1'] = $contact_info['letter_stream_name_1'];
|
||
$info['letter_stream_name_2'] = $contact_info['letter_stream_name_2'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// updateLetterStreamCount($conn,$db_client_count,$no_of_jobs,$client_id);
|
||
$loop_counter = 0;
|
||
foreach($letter_stream_pr_variable as $current_pr => $pr_value){
|
||
if(!empty($pr_value)){
|
||
$pdf = $pr_value['html'];
|
||
$new_file_name = $member_ID . "_" . $current_pr;
|
||
$pdf_path = $path . $new_file_name . ".pdf";
|
||
$destination_id = $pr_value['destination_id'];
|
||
// $mpdf = new mPDF();
|
||
//
|
||
// $mpdf->defaultfooterline = 0;
|
||
// $mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
//
|
||
// $mpdf->WriteHTML($pdf);
|
||
// $mpdf->Output($pdf_path);
|
||
// filePermissionSet($pdf_path);
|
||
writeSnappyPdf($pdf, $pdf_path);
|
||
$generated_pdf_file_list[] = $pdf_path;
|
||
if(!empty($letter_stream_address_pr[$destination_id])){
|
||
foreach($letter_stream_address_pr[$destination_id] as $my_current_pr_dest_id){
|
||
$count++;
|
||
$loop_counter++;
|
||
$from_address_value = $my_current_pr_dest_id;
|
||
$current_return_address_value = 0;
|
||
if(isset($checkbox_pr_return_address[$destination_id])){
|
||
$current_return_address_value = $return_pr_address[$destination_id];
|
||
}
|
||
$current_address = publicrecordsLetterStreamAddress($destination_id,$from_address_value,$current_return_address_value,$info);
|
||
|
||
|
||
//$unique_id = $count . "-" . time(); //this will only be accepted by our system one time
|
||
$unique_id = uniqueIdGenerateForLetterStream($client_id,$db_client_count); //this will only be accepted by our system one time
|
||
$string_to_hash = substr($unique_id, -6) . $api_key . substr($unique_id, 0, 6);
|
||
$hash = md5(base64_encode($string_to_hash));
|
||
$data = array('a' => $api_id, 'h' => $hash, 't' => $unique_id);
|
||
$job_name = "R" . $count . $member_ID . strtotime(date('m/d/y H:i:s'));
|
||
if ($client_id > 0) {
|
||
$db_client_count++;
|
||
$job_name = getJobName($client_name, $db_client_count, $no_of_jobs, $client_id, $pi_di_str);
|
||
|
||
|
||
// Update By 1 before sending to letter stream
|
||
updateLetterStreamCount($conn,$db_client_count,1,$client_id);
|
||
|
||
}
|
||
$data['job'] = $job_name;
|
||
$from_address = $current_address['from'];
|
||
$from_address = $info['letter_stream_name_1']." ".$info['letter_stream_name_2']. ":" . ":" . $from_address;
|
||
$new_return_address = $info['from'];
|
||
if(!empty($current_address['return'])){
|
||
$new_return_address = $current_address['return'];
|
||
}
|
||
|
||
|
||
|
||
|
||
$data['from'] = $from_address;
|
||
$data['responseformat'] = 'json';
|
||
$data['to[]'] = $unique_id . ':' . $new_return_address;
|
||
$data['debug'] = 3;
|
||
$data['coversheet'] = 'Y';
|
||
$data['mailtype'] = $mailType;
|
||
$data['duplex'] = $is_letterstream_duplex;
|
||
$data['single_file'] = curl_file_create(realpath($pdf_path));
|
||
$mpdf->enableImports = true;
|
||
$mpdf->SetImportUse();
|
||
$pages = $mpdf->SetSourceFile($pdf_path);
|
||
$data['pages'] = $pages;
|
||
$URL = LETTER_STREAM_API;
|
||
$response = makeCurlRequest($data,$URL,[]);
|
||
$response = json_decode($response);
|
||
$authOk = false;
|
||
$isUploaded = false;
|
||
$authSuccess = $response->message[0]->code; // Auth success code -199
|
||
$uploadSuccess = $response->message[1]->code; // Upload success code -105
|
||
$authSuccess = trim($authSuccess);
|
||
$uploadSuccess = trim($uploadSuccess);
|
||
|
||
|
||
|
||
if ($uploadSuccess == -925) {
|
||
updateLetterStreamCount($conn, $db_client_count, 10, $client_id);
|
||
}
|
||
|
||
if ($authSuccess == -199 && ($uploadSuccess == -105 || $uploadSuccess == -100 )) {
|
||
$finalresponse = ['status' => true, 'errorcode' => ""];
|
||
$successfully_sent_pdf[basename($pdf_path)][] = [
|
||
'file_path'=>$pdf_path,
|
||
'from_address'=>$data['from'],
|
||
'return_address'=>$new_return_address,
|
||
'duplex'=> $data['duplex'],
|
||
'mailType'=>$data['mailtype']
|
||
];
|
||
$successfully_sent_pdf_for_copy[] = $pdf_path;
|
||
} else {
|
||
$isBureaus = false;
|
||
$finalresponse = ['status' => false, 'errorcode' => $uploadSuccess];
|
||
$letter_stream_info_for_log = json_encode($data);
|
||
$letter_stream_info_for_log .= " #Client name : " . $client_name;
|
||
$errorString = "#AuthStatus:" . $authSuccess . "#UploadStatus:" . $uploadSuccess .
|
||
"#From Address:" . $info['from'] . "#To:" . $unique_id . ':' . $addressesByDestinationId[$address_id] . "#File Path:" . $pdf_path;
|
||
errorLog("LetterStream error public record", $errorString . $letter_stream_info_for_log);
|
||
break 2;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
// dbCountFinalUpdateForLetterStream($conn,$client_id,$loop_counter,$no_of_jobs); // update db count if count > no of jobs
|
||
}
|
||
|
||
// main address for letterstream
|
||
if (!empty($global_html)) {
|
||
$no_of_jobs = getTotalJob($global_html);
|
||
|
||
if ($client_id > 0 && $db_client_count == 0) {
|
||
$client_sql = "select clients.*,contacts.*"
|
||
. " from clients INNER JOIN contacts ON contacts.client_id = clients.id "
|
||
. "where contacts.is_primary_contact = 1 AND clients.id = $client_id";
|
||
|
||
$client_sql_result = $conn->query($client_sql);
|
||
$contact_info = [];
|
||
if ($client_sql_result->num_rows > 0) {
|
||
while ($row = $client_sql_result->fetch_assoc()) {
|
||
|
||
if($db_client_count == 0){
|
||
$db_client_count = $row['count_letterstream'];
|
||
}
|
||
|
||
if ($row['is_letterstream_return_address'] == 1) {
|
||
$contact_info['letter_stream_name_1'] = $row['first_name'];
|
||
$contact_info['letter_stream_name_2'] = $row['last_name'];
|
||
$contact_info['letter_stream_address_1'] = $row['address'];
|
||
$contact_info['letter_stream_address_2'] = "";
|
||
$contact_info['letter_stream_city'] = $row['city'];
|
||
$contact_info['letter_stream_state'] = $row['state'];
|
||
$contact_info['letter_stream_zip'] = $row['zip_code'];
|
||
$info['from'] = letterStreamRetunAddressGenerate($contact_info);
|
||
$info['letter_stream_name_1'] = $contact_info['letter_stream_name_1'];
|
||
$info['letter_stream_name_2'] = $contact_info['letter_stream_name_2'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//updateLetterStreamCount($conn,$db_client_count,$no_of_jobs,$client_id);
|
||
$loop_counter = 0;
|
||
foreach ($global_html as $file_name => $value) {
|
||
$pdf = $value['html'];
|
||
|
||
$destination_id = $value['destination_id'];
|
||
|
||
if (!empty($pdf)) {
|
||
$destName = get_destination_name()[$destination_id];
|
||
$new_file_name = $member_ID . "_" . $file_name;
|
||
$pdf_path = $path . $new_file_name . ".pdf";
|
||
$mpdf = new mPDF();
|
||
//
|
||
// $mpdf->defaultfooterline = 0;
|
||
// $mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
//
|
||
// $mpdf->WriteHTML($pdf);
|
||
// $mpdf->Output($pdf_path);
|
||
writeSnappyPdf($pdf, $pdf_path);
|
||
filePermissionSet($pdf_path);
|
||
$generated_pdf_file_list[] = $pdf_path;
|
||
|
||
$addressesByDestinationId = getDestinationAddressLetterStream($destination_id);
|
||
$form_addressesByDestinationId = getDestinationAddressLetterStreamForFormAddress($destination_id);
|
||
$addresses = $_POST['letter_stream_address_' . $destination_id];
|
||
$checkbox_return_address = $_POST['checkbox_return_address_' . $destination_id];
|
||
if($value['is_other'] == 1){
|
||
if(isset($_POST['letter_stream_address_other'][$destination_id])){
|
||
$addresses = $_POST['letter_stream_address_other'][$destination_id];
|
||
$addressesByDestinationId[1] = $other_formated_address;
|
||
|
||
}
|
||
}
|
||
|
||
|
||
// my code
|
||
if (!empty($addresses)) {
|
||
foreach ($addresses as $address_id) {
|
||
$count++;
|
||
$loop_counter++;
|
||
//$unique_id = $count . "-" . time(); //this will only be accepted by our system one time
|
||
$unique_id = uniqueIdGenerateForLetterStream($client_id,$db_client_count);
|
||
$string_to_hash = substr($unique_id, -6) . $api_key . substr($unique_id, 0, 6);
|
||
$hash = md5(base64_encode($string_to_hash));
|
||
$data = array('a' => $api_id, 'h' => $hash, 't' => $unique_id);
|
||
$job_name = "R" . $count . $member_ID . strtotime(date('m/d/y H:i:s'));
|
||
if ($client_id > 0) {
|
||
|
||
$db_client_count++;
|
||
$job_name = getJobName($client_name, $db_client_count, $no_of_jobs, $client_id, $pi_di_str);
|
||
|
||
// Update By 1 before sending to letter stream
|
||
updateLetterStreamCount($conn,$db_client_count,1,$client_id);
|
||
|
||
}
|
||
$data['job'] = $job_name;
|
||
$from_address = $info['from'];
|
||
$new_return_address = $addressesByDestinationId[$address_id];
|
||
if ($address_id == 1) {
|
||
if (isset($checkbox_return_address) && $checkbox_return_address == $destination_id && $destination_id != 11) {
|
||
$selected_address_id = $_POST['return_address_' . $destination_id];
|
||
$from_address = $addressesByDestinationId[$selected_address_id];
|
||
if(!empty($info['letter_stream_name_1']) && !empty($info['letter_stream_name_2'])){
|
||
$from_address = $info['letter_stream_name_1']." ".$info['letter_stream_name_2'] . ":" . ":" . $form_addressesByDestinationId[$selected_address_id];
|
||
}
|
||
}
|
||
}
|
||
|
||
if($value['is_other'] == 1){
|
||
$new_return_address = $info['letter_stream_name_1']." ".$info['letter_stream_name_2'] . ":" . ":" . $new_return_address;
|
||
}
|
||
|
||
/*echo "<pre>";print_r($new_return_address);
|
||
exit;*/
|
||
|
||
$data['from'] = $from_address;
|
||
$data['responseformat'] = 'json';
|
||
$data['to[]'] = $unique_id . ':' . $new_return_address;
|
||
$data['debug'] = 3;
|
||
$data['coversheet'] = 'Y';
|
||
$data['mailtype'] = $mailType;
|
||
$data['duplex'] = $is_letterstream_duplex;
|
||
$data['single_file'] = curl_file_create(realpath($pdf_path));
|
||
|
||
$mpdf->enableImports = true;
|
||
$mpdf->SetImportUse();
|
||
$pages = $mpdf->SetSourceFile($pdf_path);
|
||
$data['pages'] = $pages;
|
||
$testData[] = ['address_id' => $address_id, 'address' => $data['from'], 'file' => $pdf_path];
|
||
|
||
$URL = LETTER_STREAM_API;
|
||
$response = makeCurlRequest($data,$URL,[]);
|
||
//echo "<pre>";print_r($data);exit;
|
||
// $response = curl_exec($ch);
|
||
$response = json_decode($response);
|
||
$authOk = false;
|
||
$isUploaded = false;
|
||
$authSuccess = $response->message[0]->code; // Auth success code -199
|
||
$uploadSuccess = $response->message[1]->code; // Upload success code -105
|
||
$authSuccess = trim($authSuccess);
|
||
$uploadSuccess = trim($uploadSuccess);
|
||
|
||
|
||
if ($uploadSuccess == -925) {
|
||
updateLetterStreamCount($conn, $db_client_count, 10, $client_id);
|
||
}
|
||
if ($authSuccess == -199 && ($uploadSuccess == -105 || $uploadSuccess == -100 )) {
|
||
$finalresponse = ['status' => true, 'errorcode' => ""];
|
||
$successfully_sent_pdf[basename($pdf_path)][] = [
|
||
'file_path'=>$pdf_path,
|
||
'from_address'=>$data['from'],
|
||
'return_address'=>$new_return_address,
|
||
'duplex'=> $data['duplex'],
|
||
'mailType'=>$data['mailtype']
|
||
];
|
||
$successfully_sent_pdf_for_copy[] = $pdf_path;
|
||
//errorLog('dddd', json_encode($successfully_sent_pdf));
|
||
} else {
|
||
$isBureaus = false;
|
||
$finalresponse = ['status' => false, 'errorcode' => $uploadSuccess];
|
||
$letter_stream_info_for_log = json_encode($data);
|
||
$letter_stream_info_for_log .= " #Client name : " . $client_name;
|
||
$errorString = "#AuthStatus:" . $authSuccess . "#UploadStatus:" . $uploadSuccess .
|
||
"#From Address:" . $info['from'] . "#To:" . $unique_id . ':' . $addressesByDestinationId[$address_id] . "#File Path:" . $pdf_path;
|
||
errorLog("LetterStream error default address", $errorString . $letter_stream_info_for_log);
|
||
break 2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// dbCountFinalUpdateForLetterStream($conn,$client_id,$loop_counter,$no_of_jobs); // update db count if count > no of jobs
|
||
}
|
||
|
||
|
||
|
||
// DF address for letterstream
|
||
if (!empty($df_addresses) && $isBureaus) {
|
||
$no_of_jobs = getTotalJobForDF($df_global_html);
|
||
|
||
if ($client_id > 0 && $db_client_count == 0) {
|
||
$client_sql = "select clients.*,contacts.*"
|
||
. " from clients INNER JOIN contacts ON contacts.client_id = clients.id "
|
||
. "where contacts.is_primary_contact = 1 AND clients.id = $client_id";
|
||
|
||
$client_sql_result = $conn->query($client_sql);
|
||
$contact_info = [];
|
||
if ($client_sql_result->num_rows > 0) {
|
||
while ($row = $client_sql_result->fetch_assoc()) {
|
||
|
||
if($db_client_count == 0){
|
||
$db_client_count = $row['count_letterstream'];
|
||
}
|
||
|
||
|
||
|
||
if ($row['is_letterstream_return_address'] == 1) {
|
||
$contact_info['letter_stream_name_1'] = $row['first_name'];
|
||
$contact_info['letter_stream_name_2'] = $row['last_name'];
|
||
$contact_info['letter_stream_address_1'] = $row['address'];
|
||
$contact_info['letter_stream_address_2'] = "";
|
||
$contact_info['letter_stream_city'] = $row['city'];
|
||
$contact_info['letter_stream_state'] = $row['state'];
|
||
$contact_info['letter_stream_zip'] = $row['zip_code'];
|
||
$info['from'] = letterStreamRetunAddressGenerate($contact_info);
|
||
$info['letter_stream_name_1'] = $contact_info['letter_stream_name_1'];
|
||
$info['letter_stream_name_2'] = $contact_info['letter_stream_name_2'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
// updateLetterStreamCount($conn,$db_client_count,$no_of_jobs,$client_id);
|
||
$loop_counter = 0;
|
||
foreach ($df_addresses as $item_key => $df_current_address) {
|
||
$df_current_address = RemoveBS($df_current_address);//RemoveBS($df_current_address);
|
||
//pr($df_current_address);
|
||
$pdf = $df_global_html[$item_key]['html'];
|
||
$bank_name = "";
|
||
$destination_id = $df_global_html[$item_key]['destination_id'];
|
||
if (isset($df_global_html[$item_key]['DF_BANK'])) {
|
||
$bank_name = $df_global_html[$item_key]['DF_BANK'];
|
||
//echo $bank_name;exit;
|
||
}
|
||
|
||
if (!empty($pdf)) {
|
||
$destName = get_destination_name()[$destination_id];
|
||
$new_file_name = $member_ID . "_" . $df_global_html[$item_key]['file_name'];
|
||
$pdf_path = $path . $new_file_name . ".pdf";
|
||
$mpdf = new mPDF();
|
||
//
|
||
// $mpdf->defaultfooterline = 0;
|
||
// $mpdf->setFooter("Page {PAGENO} of {nb}");
|
||
//
|
||
// $mpdf->WriteHTML($pdf);
|
||
// $mpdf->Output($pdf_path);
|
||
writeSnappyPdf($pdf, $pdf_path);
|
||
filePermissionSet($pdf_path);
|
||
$generated_pdf_file_list_df[] = $pdf_path;
|
||
$from_address = $info['from'];
|
||
if (!empty($df_current_address)) {
|
||
$current_df_from_to_address = getFormatedDFAddress($df_current_address);
|
||
$from_address = $info['letter_stream_name_1']." ".$info['letter_stream_name_2']. ":" . ":" . $bank_name . "::" . $current_df_from_to_address;
|
||
$new_return_address = $info['letter_stream_name_1']." ".$info['letter_stream_name_2']. ":" . ":" .$current_df_from_to_address;
|
||
}
|
||
//pr($current_df_from_to_address);
|
||
$count++;
|
||
$loop_counter++;
|
||
//$unique_id = $count . "-" . time(); //this will only be accepted by our system one time
|
||
$unique_id = uniqueIdGenerateForLetterStream($client_id,$db_client_count);
|
||
$string_to_hash = substr($unique_id, -6) . $api_key . substr($unique_id, 0, 6);
|
||
$hash = md5(base64_encode($string_to_hash));
|
||
$data = array('a' => $api_id, 'h' => $hash, 't' => $unique_id);
|
||
$job_name = "R" . $count . $member_ID . strtotime(date('m/d/y H:i:s'));
|
||
if ($client_id > 0) {
|
||
|
||
$db_client_count++;
|
||
|
||
$job_name = getJobName($client_name, $db_client_count, $no_of_jobs, $client_id, $pi_di_str);
|
||
|
||
|
||
// Update By 1 before sending to letter stream
|
||
updateLetterStreamCount($conn,$db_client_count,1,$client_id);
|
||
|
||
|
||
}
|
||
$data['job'] = $job_name;
|
||
|
||
//$new_return_address = $addressesByDestinationId[$address_id];
|
||
|
||
$data['from'] = $from_address;
|
||
$data['responseformat'] = 'json';
|
||
$data['to[]'] = $unique_id . ':' . $new_return_address;
|
||
//echo "<pre>";print_r($data['to[]']);exit;
|
||
$data['debug'] = 3;
|
||
$data['coversheet'] = 'Y';
|
||
$data['mailtype'] = $mailType;
|
||
$data['duplex'] = $is_letterstream_duplex;
|
||
$data['single_file'] = curl_file_create(realpath($pdf_path));
|
||
$mpdf->enableImports = true;
|
||
$mpdf->SetImportUse();
|
||
$pages = $mpdf->SetSourceFile($pdf_path);
|
||
$data['pages'] = $pages;
|
||
|
||
//echo "<pre>";print_r($data);
|
||
// $ch = curl_init();
|
||
// curl_setopt($ch, CURLOPT_URL, LETTER_STREAM_API);
|
||
// curl_setopt($ch, CURLOPT_POST, 1);
|
||
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||
// $response = curl_exec($ch);
|
||
$URL = LETTER_STREAM_API;
|
||
$response = makeCurlRequest($data,$URL,[]);
|
||
$response = json_decode($response);
|
||
$authOk = false;
|
||
$isUploaded = false;
|
||
$authSuccess = $response->message[0]->code; // Auth success code -199
|
||
$uploadSuccess = $response->message[1]->code; // Upload success code -105
|
||
$authSuccess = trim($authSuccess);
|
||
$uploadSuccess = trim($uploadSuccess);
|
||
|
||
|
||
if($uploadSuccess == -925){
|
||
updateLetterStreamCount($conn,$db_client_count,10,$client_id);
|
||
}
|
||
if ($authSuccess == -199 && ($uploadSuccess == -105 || $uploadSuccess == -100 )) {
|
||
$finalresponse = ['status' => true, 'errorcode' => ""];
|
||
$successfully_sent_pdf[basename($pdf_path)][] = [
|
||
'file_path'=>$pdf_path,
|
||
'from_address'=>$data['from'],
|
||
'return_address'=>$new_return_address,
|
||
'duplex'=> $data['duplex'],
|
||
'mailType'=>$data['mailtype']
|
||
];
|
||
$successfully_sent_pdf_for_copy[] = $pdf_path;
|
||
} else {
|
||
$isBureaus = false;
|
||
$finalresponse = ['status' => false, 'errorcode' => $uploadSuccess];
|
||
$letter_stream_info_for_log = json_encode($data);
|
||
$letter_stream_info_for_log .= " #Client name : " . $client_name;
|
||
$errorString = "#AuthStatus:" . $authSuccess . "#UploadStatus:" . $uploadSuccess .
|
||
"#From Address:" . $info['from'] . "#To:" . $unique_id . ':' . $addressesByDestinationId[$address_id] . "#File Path:" . $pdf_path;
|
||
errorLog("LetterStream error DF Address", $errorString . $letter_stream_info_for_log);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
// dbCountFinalUpdateForLetterStream($conn,$client_id,$loop_counter,$no_of_jobs); // update db count if count > no of jobs
|
||
}
|
||
|
||
|
||
//exit;
|
||
if(isset($_POST['set_automation']) && $_POST['set_automation'] == 1){
|
||
if(!empty($successfully_sent_pdf_for_copy)){
|
||
global $global_member_id;
|
||
global $global_sertg_id;
|
||
$client_id = 0;
|
||
if(isset($_POST['client_id']) && $_POST['client_id'] > 0){
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
$dir = "/../velocity/letterstream/".$global_member_id.'/'.$client_id."/".$global_sertg_id;
|
||
removeDirFilesFromDir($dir);
|
||
foreach ($successfully_sent_pdf_for_copy as $sent_pdf_file) {
|
||
copyPdfToAnotherDir($sent_pdf_file,"/../velocity/letterstream/".$global_member_id);
|
||
}
|
||
|
||
if (!empty($successfully_sent_pdf)) {
|
||
pdfInfoToJson($successfully_sent_pdf,"/../velocity/letterstream/");
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
if (!empty($generated_pdf_file_list)) {
|
||
foreach ($generated_pdf_file_list as $pdf_file) {
|
||
@unlink($pdf_file);
|
||
}
|
||
}
|
||
|
||
if (!empty($generated_pdf_file_list_df)) {
|
||
foreach ($generated_pdf_file_list_df as $pdf_file_df) {
|
||
@unlink($pdf_file_df);
|
||
}
|
||
}
|
||
|
||
return $finalresponse;
|
||
}
|
||
|
||
|
||
|
||
function pr($data){
|
||
echo "<pre>";print_r($data);exit;
|
||
}
|
||
function removeDirFilesFromDir($dir){
|
||
$dir = __DIR__.$dir;
|
||
$files = glob($dir.'/*'); // get all file names
|
||
if(!empty($files)){
|
||
foreach ($files as $nfile) {
|
||
if (file_exists($nfile)){
|
||
@unlink($nfile);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
function pdfInfoToJson($info,$file_path){
|
||
$json = "";
|
||
global $global_member_id;
|
||
global $global_sertg_id;
|
||
$client_id = 0;
|
||
if(isset($_POST['client_id']) && $_POST['client_id'] > 0){
|
||
$client_id = $_POST['client_id'];
|
||
}
|
||
|
||
if(!empty($file_path)){
|
||
$file_path = __DIR__.$file_path."/".$global_member_id."/".$client_id."/".$global_sertg_id;
|
||
if(!is_dir($file_path)){
|
||
mkdir($file_path,0777,true);
|
||
}
|
||
|
||
$file_path = $file_path."/".$global_sertg_id.".json";
|
||
if(file_exists($file_path)){
|
||
@unlink($file_path);
|
||
}
|
||
if(!empty($info)){
|
||
$json = json_encode($info);
|
||
file_put_contents($file_path, $json);
|
||
filePermissionSet($file_path);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
function letterEmailSendToClient() {
|
||
global $client_name;
|
||
global $client_email;
|
||
global $selected_letter_type;
|
||
global $letter_email_signature;
|
||
global $next_sending_email_date;
|
||
global $letter_send_date_tmezone;
|
||
global $conn;
|
||
|
||
if (isset($_POST['set_schedule'])) {
|
||
if ($selected_letter_type > 0 && !empty($next_sending_email_date) && !empty($next_sending_email_date)) {
|
||
$sql = "INSERT INTO letter_email_schedules (client_email,client_name, datetime,letter_set, gmt,letter_email_signature) VALUES ('$client_email','$client_name', '$next_sending_email_date',$selected_letter_type, '$letter_send_date_tmezone','$letter_email_signature')";
|
||
$conn->query($sql);
|
||
}
|
||
} else {
|
||
if ($selected_letter_type > 0) {
|
||
//LETTER_TYPE_FOR_MAIL
|
||
$data['email'] = $client_email;
|
||
$data['email_subject'] = "Great News! We Have Started Your " . LETTER_TYPE_FOR_MAIL[$selected_letter_type] . " Set Of Letters";
|
||
$email_body = "Hello " . $client_name . ",<br/>We have just started your " . LETTER_TYPE_FOR_MAIL[$selected_letter_type] .
|
||
" Set of Letters. We are notifying you to let you know."
|
||
. "<br/>We will keep you updated on all updates and Wins as they come in. "
|
||
. "Thank you For choosing Us We look forward to helping you through this Journey.<br/></br><br/></br>";
|
||
$email_body .= nl2br($letter_email_signature);
|
||
|
||
$letter_info = getLetterSetEmailContent($conn,$_POST['member_id'],$selected_letter_type);
|
||
if(!empty($letter_info['email_subject'])){
|
||
$data['email_subject'] = $letter_info['email_subject'];
|
||
}
|
||
|
||
if(!empty($letter_info['email_body'])){
|
||
$email_body = nl2br($letter_info['email_body']);
|
||
$email_body = replaceClientInfo($email_body,$client_email);
|
||
$email_body = str_replace('[client_name]', $client_name, $email_body);
|
||
}
|
||
|
||
$data['email_body'] = $email_body;
|
||
sendEmail($data, "", "DO NOT REPLY");
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
function replaceClientInfo($html_body,$client_email){
|
||
global $conn;
|
||
$final_html = $html_body;
|
||
$ssn = "";
|
||
$birthDay = "";
|
||
$client_info['first_name'] = "";
|
||
if(!empty($client_email)){
|
||
$sql = 'SELECT * from creditreportsetups where client_id = (select client_id from contacts where email = "'.$client_email.'")';
|
||
$result = $conn->query($sql);
|
||
$client_info = $result->fetch_assoc();
|
||
|
||
}
|
||
|
||
$final_html = str_replace(AGREEMENT_PRIFIX, "", $final_html);
|
||
|
||
$final_html = str_replace(AGREEMENT_FIRSTNAME, $client_info['first_name'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_CUSTOMERNAME, $client_info['first_name'].' '.$client_info['last_name'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_LASTNAME, $client_info['last_name'], $final_html);
|
||
|
||
$final_html = str_replace(AGREEMENT_SUFFIX, "", $final_html);
|
||
|
||
$final_html = str_replace(AGREEMENT_SSN, $ssn, $final_html);
|
||
$final_html = str_replace(AGREEMENT_BIRTHDAY, $birthDay, $final_html);
|
||
|
||
$final_html = str_replace(AGREEMENT_ADDRESS, $client_info['address'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_CITY_STATE_POSTCODE, $client_info['city'].', '.$client_info['street_name'].', '.$client_info['zip_code'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_PRICE_FOR_SERVICE, "", $final_html);
|
||
$final_html = replaceCompanyInfo($final_html);
|
||
return $final_html;
|
||
}
|
||
|
||
function replaceCompanyInfo($html_body){
|
||
|
||
$company_info = getAuthUser();
|
||
|
||
$final_html=$html_body;
|
||
$final_html = str_replace(AGREEMENT_COMPANYNAME, $company_info['company_name'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_COMPANYADDRESS, $company_info['address_one'].$company_info['address_two'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_COMPANY_CITY_STATE_ZIP, $company_info['city'].', '.$company_info['state'].', '.$company_info['address_zip'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_COMPANYPHONE, $company_info['phone'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_COMPANYFAX, "", $final_html);
|
||
$final_html = str_replace(AGREEMENT_COMPANYWEBSITE, $company_info['website'], $final_html);
|
||
$final_html = str_replace(AGREEMENT_ADMINEMAIL, $company_info['email'], $final_html);
|
||
return $final_html;
|
||
}
|
||
|
||
function getTotalJobForPR($global_html) {
|
||
$no_of_job = 0;
|
||
if (!empty($global_html)) {
|
||
foreach ($global_html as $value) {
|
||
$destination_id = $value['destination_id'];
|
||
if (isset($_POST['letter_stream_address_pr'][$destination_id]) && !empty($_POST['letter_stream_address_pr'][$destination_id])) {
|
||
$no_of_job += count($_POST['letter_stream_address_pr'][$destination_id]);
|
||
}
|
||
}
|
||
}
|
||
|
||
return $no_of_job;
|
||
}
|
||
|
||
|
||
function getTotalJobForDF($global_html) {
|
||
$no_of_job = 0;
|
||
if (!empty($global_html)) {
|
||
foreach ($global_html as $value) {
|
||
$destination_id = $value['destination_id'];
|
||
if($destination_id == 11){
|
||
if (isset($_POST['letter_stream_address_' . $destination_id]) && !empty($_POST['letter_stream_address_' . $destination_id])) {
|
||
$current_content_count = count($_POST['letter_stream_address_' . $destination_id]);
|
||
$no_of_job += $current_content_count;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
return $no_of_job;
|
||
}
|
||
|
||
|
||
|
||
function getTotalJob($global_html) {
|
||
$no_of_job = 0;
|
||
if (!empty($global_html)) {
|
||
foreach ($global_html as $value) {
|
||
$destination_id = $value['destination_id'];
|
||
if (isset($_POST['letter_stream_address_' . $destination_id]) && !empty($_POST['letter_stream_address_' . $destination_id])) {
|
||
$current_content_count = count($_POST['letter_stream_address_' . $destination_id]);
|
||
$no_of_job += $current_content_count;
|
||
}
|
||
}
|
||
}
|
||
|
||
return $no_of_job;
|
||
}
|
||
|
||
function getTotalDfLetterSteramJob($global_html) {
|
||
$no_of_job = 0;
|
||
if (!empty($global_html)) {
|
||
foreach ($global_html as $value) {
|
||
$destination_id = $value['destination_id'];
|
||
if (isset($_POST['letter_stream_address_' . $destination_id]) && !empty($_POST['letter_stream_address_' . $destination_id])) {
|
||
$no_of_job += count($_POST['letter_stream_address_' . $destination_id]);
|
||
}
|
||
}
|
||
}
|
||
|
||
return $no_of_job;
|
||
}
|
||
|
||
function setDFLetterStreamAddressFormated($address) {
|
||
$finalAddress = "";
|
||
$number_part = "";
|
||
$text_part = "";
|
||
if (!empty($address)) {
|
||
$addressArray = explode(":", $address);
|
||
$name_1 = trim($addressArray[0]);
|
||
$second_part = $addressArray[1];
|
||
$second_partArray = explode(" ", $second_part);
|
||
$second_partArray_length = count($second_partArray);
|
||
$zip = trim($second_partArray[$second_partArray_length - 1]);
|
||
$city = trim($second_partArray[$second_partArray_length - 2]);
|
||
$state = $second_partArray[$second_partArray_length - 3];
|
||
$address_1 = "";
|
||
if (!empty($state)) {
|
||
$state = trim($state, ',');
|
||
$state = trim($state);
|
||
}
|
||
|
||
if (!empty($state) && is_numeric($state[0])) {
|
||
$state_len = strlen($state);
|
||
for ($s = 0; $s < $state_len; $s++) {
|
||
if (is_numeric($state[$s])) {
|
||
$number_part .= $state[$s];
|
||
} else {
|
||
$text_part .= $state[$s];
|
||
}
|
||
}
|
||
$state = $text_part;
|
||
}
|
||
|
||
for ($i = 0; $i < $second_partArray_length - 3; $i++) {
|
||
if (isset($second_partArray[$second_partArray_length - $i]) && !empty($second_partArray[$second_partArray_length - $i])) {
|
||
if (!empty($address_1)) {
|
||
$address_1 .= " " . trim($second_partArray[$i]);
|
||
} else {
|
||
$address_1 = trim($second_partArray[$i]);
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!empty($address_1) && !empty($number_part)) {
|
||
$address_1 .= " " . $number_part;
|
||
}
|
||
|
||
|
||
if (!empty($name_1)) {
|
||
$finalAddress = $name_1;
|
||
}
|
||
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":";
|
||
}
|
||
|
||
|
||
if (!empty($address_1)) {
|
||
$address_1 = trim($address_1, ',');
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":" . $address_1;
|
||
} else {
|
||
$finalAddress = $address_1;
|
||
}
|
||
}
|
||
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":";
|
||
}
|
||
|
||
if (!empty($state)) {
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":" . $state;
|
||
} else {
|
||
$finalAddress = $state;
|
||
}
|
||
}
|
||
|
||
if (!empty($city)) {
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":" . $city;
|
||
} else {
|
||
$finalAddress = $city;
|
||
}
|
||
}
|
||
|
||
if (!empty($zip)) {
|
||
if (!empty($finalAddress)) {
|
||
$finalAddress .= ":" . $zip;
|
||
} else {
|
||
$finalAddress = $zip;
|
||
}
|
||
}
|
||
}
|
||
|
||
return $finalAddress;
|
||
}
|
||
|
||
|
||
|
||
function getClientInfoById($conn, $id) {
|
||
$sertgForm = "SELECT * FROM contacts WHERE contacts.client_id = " . $id . " AND contacts.is_primary_contact = 1";
|
||
$result = $conn->query($sertgForm);
|
||
$data = [];
|
||
$data['name'] = "";
|
||
if ($result->num_rows > 0) {
|
||
while ($row = $result->fetch_assoc()) {
|
||
if (!empty($row['first_name'])) {
|
||
$data['name'] = $row['first_name'];
|
||
}
|
||
|
||
if (!empty($row['last_name'])) {
|
||
$data['name'] .= " " . $row['last_name'];
|
||
}
|
||
}
|
||
}
|
||
|
||
return $data;
|
||
}
|
||
|
||
|
||
|
||
function insertAutomationScheduleExport($conn, $automation_schedule_id, $data) {
|
||
$current_date_time = date('Y-m-d H:i:s');
|
||
$sql = "INSERT INTO automation_schedule_exports (automation_schedule_id,automation_id,created_on,modified_on) VALUES ";
|
||
$insert_string = "";
|
||
if (!empty($data['automation_id_list']) && $automation_schedule_id > 0) {
|
||
foreach ($data['automation_id_list'] as $automation_id) {
|
||
if (!empty($insert_string)) {
|
||
$insert_string .= ",(" . $automation_schedule_id . "," . $automation_id . ",'" . $current_date_time . "','" . $current_date_time . "')";
|
||
} else {
|
||
$insert_string = "(" . $automation_schedule_id . "," . $automation_id . ",'" . $current_date_time . "','" . $current_date_time . "')";
|
||
}
|
||
}
|
||
$sql .= $insert_string;
|
||
}
|
||
|
||
$result = $conn->query($sql);
|
||
}
|
||
|
||
function deleteAutomationScheduleExportByAutomationScheduleId($conn, $automation_schedule_id) {
|
||
$sql = "DELETE FROM `automation_schedule_exports` WHERE `automation_schedule_id` = " . $automation_schedule_id;
|
||
$result = $conn->query($sql);
|
||
}
|
||
|
||
function makezip($source, $destination) {
|
||
// Get real path for our folder
|
||
$rootPath = realpath($source);
|
||
|
||
// Initialize archive object
|
||
$zip = new ZipArchive();
|
||
$zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||
|
||
// Create recursive directory iterator
|
||
/** @var SplFileInfo[] $files */
|
||
$files = new RecursiveIteratorIterator(
|
||
new RecursiveDirectoryIterator($rootPath), RecursiveIteratorIterator::LEAVES_ONLY
|
||
);
|
||
|
||
|
||
|
||
foreach ($files as $name => $file) {
|
||
|
||
// Skip directories (they would be added automatically)
|
||
if (!$file->isDir()) {
|
||
// Get real and relative path for current file
|
||
$filePath = $file->getRealPath();
|
||
$relativePath = substr($filePath, strlen($rootPath) + 1);
|
||
|
||
// Add current file to archive
|
||
$zip->addFile($filePath, $relativePath);
|
||
}
|
||
}
|
||
|
||
// Zip archive will be created only after closing object
|
||
return $zip->close();
|
||
}
|
||
|
||
|
||
function getAddressByDestination($dest_id){
|
||
global $other_destination_id;
|
||
$address = "";
|
||
$public_record_var_list[1] ="<u><strong>Experian<strong/></u>, Attn Darryl Gibson, Esq. (or acting/current Group General Counsel),<br/>"
|
||
. "Experian Information Solutions, Inc., 475 Anton Blvd., Costa Mesa, CA 92626 <br/>"
|
||
. "<u><strong>(and mail to Experian POB 9701, ATTN Consumer Fraud Department, Allen, TX 75013)<strong/><u/>";
|
||
|
||
$public_record_var_list[2] = "<u><strong>EQUIFAX<strong/></u>, ATTN John J. Kelley, III, Esq. (or acting/current CHIEF LEGAL<br/>"
|
||
. "OFFICER), Equifax Information services LLC. 1550 Peachtree Street, N.W.<br/>"
|
||
. ", ATLANTA, GA 30309 <u><strong>(and also send to EQUIFAX , ATTN FRAUD<br/>"
|
||
. "DEPARTMENT,POB 740256, ATLANTA, GA 30374-0256)<strong/></u>";
|
||
|
||
$public_record_var_list[3] = "<u><strong>Trans Union,<strong/></u> Attn: john Blenke , Esq. (acting or current EVP and GENERAL<br/>"
|
||
. "COUNSEL), Transunion LLC, 555 W. Adams Street, CHICAGO, IL 60661 <u><strong>(and<br/>"
|
||
. "also send to Trans Union, Attn FRAUD DEPARTMENT, POB 2000, Chester , PA 19016-2000)<strong/><u/>";
|
||
|
||
|
||
|
||
if(isset($public_record_var_list[$dest_id])){
|
||
$address = $public_record_var_list[$dest_id];
|
||
}else{
|
||
$address_array = getDestinationAddress($dest_id);
|
||
$address_array = array_filter($address_array);
|
||
if(!empty($address_array) && is_array($address_array)){
|
||
$address = count($address_array) > 1 ? implode("<br/>",$address_array) : current($address_array);
|
||
}
|
||
}
|
||
|
||
/*
|
||
* for other address going here for velocity
|
||
*/
|
||
if($dest_id == $other_destination_id) {
|
||
$address = $_POST['other_address'];
|
||
}
|
||
|
||
return $address;
|
||
}
|
||
|
||
function publicrecordsLetterStreamAddress($destination_id,$from_address_value,$return_address_value = 0,$info){
|
||
//name_1:name_2:address_1:address_2:city:state:zip
|
||
$name_part = "";
|
||
if(!empty($info['letter_stream_name_1']) && !empty($info['letter_stream_name_2'])){
|
||
$name_part = $info['letter_stream_name_1'].":".$info['letter_stream_name_2'].":";
|
||
$pr_from[1][1] = "Experian Information Solutions Inc:475 Anton Blvd:Costa Mesa:CA:92626";
|
||
$pr_from[1][2] = "Experian POB 9701:ATTN Consumer Fraud Department:Allen:TX:75013";
|
||
|
||
$pr_from[2][1] = "Equifax Information services LLC:1550 Peachtree Street N.W:ATLANTA:GA:30309";
|
||
$pr_from[2][2] = "EQUIFAX ATTN FRAUD DEPARTMENT:POB 740256:ATLANTA:GA:30374-0256";
|
||
|
||
$pr_from[3][1] = "Transunion LLC:555 W. Adams Street:CHICAGO:IL:60661";
|
||
$pr_from[3][2] = "Trans Union Attn FRAUD DEPARTMENT:POB 2000:Chester:PA:19016-2000";
|
||
|
||
}else{
|
||
|
||
$pr_from[1][1] = "Experian::Information Solutions Inc:475 Anton Blvd:Costa Mesa:CA:92626";
|
||
$pr_from[1][2] = "Experian::POB 9701:ATTN Consumer Fraud Department:Allen:TX:75013";
|
||
|
||
$pr_from[2][1] = "Equifax:Information services LLC:1550 Peachtree Street N.W::ATLANTA:GA:30309";
|
||
$pr_from[2][2] = "EQUIFAX:ATTN FRAUD DEPARTMENT:POB 740256::ATLANTA:GA:30374-0256";
|
||
|
||
$pr_from[3][1] = "Transunion:LLC:555 W. Adams Street::CHICAGO:IL:60661";
|
||
$pr_from[3][2] = "Trans Union:Attn FRAUD DEPARTMENT:POB 2000::Chester:PA:19016-2000";
|
||
}
|
||
|
||
$pr_return[1][1]=$pr_from[1][1];
|
||
$pr_return[1][2]=$pr_from[1][2];
|
||
|
||
$pr_return[2][1]=$pr_from[2][1];
|
||
$pr_return[2][2]=$pr_from[2][2];
|
||
|
||
$pr_return[3][1]=$pr_from[3][1];
|
||
$pr_return[3][2]=$pr_from[3][2];
|
||
$result['from']=$pr_from[$destination_id][$from_address_value];
|
||
$result['return'] = "";
|
||
if($return_address_value > 0){
|
||
$result['return']=$pr_return[$destination_id][$return_address_value];
|
||
if(!empty($info['letter_stream_name_1']) && !empty($info['letter_stream_name_2'])){
|
||
$result['return']= $name_part.$pr_return[$destination_id][$return_address_value];
|
||
}
|
||
}
|
||
|
||
if($from_address_value == 1){
|
||
$result['return']=$pr_return[$destination_id][2];
|
||
if(!empty($info['letter_stream_name_1']) && !empty($info['letter_stream_name_2'])){
|
||
$result['return']=$name_part.$pr_return[$destination_id][2];
|
||
}
|
||
}
|
||
//echo "<pre>";print_r($result['return']);exit;
|
||
return $result;
|
||
}
|
||
|
||
function upgradeCmsuserStatus($member_id){
|
||
$result = false;
|
||
global $conn;
|
||
if($member_id > 0){
|
||
$sql = "update cmsuser_status set is_send_first_letter = 1, updated_at ='".date('Y-m-d H:i:s')."' where cmsuser_id = ".$member_id;
|
||
if ($conn->query($sql) === TRUE) {
|
||
$result = true;
|
||
}
|
||
}
|
||
|
||
return $result;
|
||
}
|
||
|
||
?>
|
||
|