Merge branch 'dev' of bitbucket.org:jubilian/nhance into dev
This commit is contained in:
commit
cc0d3aa76c
@ -62,7 +62,7 @@ class BDSReportController extends AdminController
|
||||
left join pt_co_share_details pt_co on ins.id = pt_co.insurer_id and pt_co.is_active = 1
|
||||
left join co_share_stmt_details stmt on pt_co.id = stmt.co_share_id and stmt.is_active = 1
|
||||
left join policy_transaction pt on pt_co.pt_id = pt.id and pt.is_active = 1 and pt.policy_issue_date >= '$fromDate' and pt.policy_issue_date <= '$toDate'
|
||||
left join policy_type ptp on pt.policy_type_id = ptp.id and ptp.policy_category = $insurerCategory
|
||||
left join policy_type ptp on pt.policy_type_id = ptp.id and ptp.policy_category = $insurerCategory and ptp.is_active = 1
|
||||
where ins.is_active = 1 and (ptp.policy_category = $insurerCategory or ptp.policy_category is null)
|
||||
group by ins.id
|
||||
";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
@ -6,17 +7,11 @@ use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
class ExcelSanitizeHelper
|
||||
{
|
||||
/**
|
||||
* Array of non-printable characters to be removed from strings.
|
||||
*
|
||||
* You can modify this array to include any characters you want to remove.
|
||||
* Regex pattern for non-printable characters to be removed from strings.
|
||||
*
|
||||
* This pattern includes control characters, zero-width characters, and Excel-specific codes
|
||||
*/
|
||||
private static $nonPrintableChars = [
|
||||
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09",
|
||||
"\x0A", "\x0B", "\x0C", "\x0D", "\x0E", "\x0F", "\x10", "\x11", "\x12", "\x13",
|
||||
"\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D",
|
||||
"\x1E", "\x1F", "\x7F", "_x000D_", "_x000A_", "_x0009_", "_x0008_", "_x0007_",
|
||||
"_x0006_", "_x0005_", "_x0004_", "_x0003_", "_x0002_", "_x0001_","\u200C"
|
||||
];
|
||||
private static $nonPrintablePattern = '/[\x00-\x1F\x7F\x{200B}\x{200C}]|_x[0-9A-F]{4}_/u';
|
||||
|
||||
/**
|
||||
* Sanitizes array data by removing non-printable characters and trimming whitespace from strings.
|
||||
@ -24,22 +19,21 @@ class ExcelSanitizeHelper
|
||||
* @param array $data Input array containing data to sanitize
|
||||
* @return array Sanitized array with non-printable characters removed and leading/trailing whitespace trimmed
|
||||
*/
|
||||
public static function sanitizeArrayData(array $data): array
|
||||
public static function sanitizeArrayData(array $data): array
|
||||
{
|
||||
try {
|
||||
$cleanData = [];
|
||||
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$cleanData[$key] = self::sanitizeArrayData($value); // Recursive call for nested arrays
|
||||
} elseif (is_string($value)) {
|
||||
// Remove non-printable characters and trim whitespace from strings
|
||||
$cleanData[$key] = trim(str_replace(self::$nonPrintableChars, '', $value));
|
||||
$cleanData[$key] = trim(preg_replace(self::$nonPrintablePattern, '', $value));
|
||||
} else {
|
||||
$cleanData[$key] = $value; // Keep non-string/non-array data as is
|
||||
}
|
||||
}
|
||||
|
||||
return $cleanData;
|
||||
} catch (\Exception $e) {
|
||||
// Log the error and the problematic data for debugging
|
||||
|
||||
@ -1226,6 +1226,20 @@ class sendMailNotification
|
||||
$notification = $params['notification_data'];
|
||||
$client_data = $params['client_data'];
|
||||
$mail = $params['test_mail'];
|
||||
$mailAttachmentModel = new MailAttachmentModel();
|
||||
$attachment_data = $mailAttachmentModel
|
||||
->select('file_path, file_name')
|
||||
->where('notification_id', $notification['id'])
|
||||
->where('is_active', 1)
|
||||
->findAll();
|
||||
|
||||
$attachments = [];
|
||||
foreach ($attachment_data as $data) {
|
||||
$attachments[] = [
|
||||
"filePath" => WRITEPATH . $data['file_path'],
|
||||
"fileName" => $data['file_name']
|
||||
];
|
||||
}
|
||||
|
||||
$mail_content = $notification['mail_content'];
|
||||
$subject = $notification['subject'];
|
||||
@ -1252,7 +1266,7 @@ class sendMailNotification
|
||||
$mail_content = str_replace("[[ecard_download_link]]", "<a href='$link/1'>Download Insurance Card</a>", $mail_content);
|
||||
$mail_content = str_replace("[[client_name]]", $client_data['client_name'], $mail_content);
|
||||
|
||||
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'], 'reply_to' => $client_data['reply_to']];
|
||||
$wholeData = ['mail' => $mail, 'subject' => $subject,'message'=> $mail_content,'bcc'=> $client_data['common_mails'],'attachments' => $attachments, 'reply_to' => $client_data['reply_to']];
|
||||
|
||||
return $wholeData;
|
||||
|
||||
|
||||
@ -175,7 +175,7 @@
|
||||
<span class="slider round" style="height: 27px;"></span>
|
||||
</label>
|
||||
|
||||
<a href="" data-toggle="modal" id="account_maneger_summary_mail" onclick="getMailTemplateData(this)" data-target="#account_maneger_summary_mail_modal">Edit</a>
|
||||
<a href="" data-toggle="modal" id="account_maneger_summary_mail" onclick="getMailTemplateData2(this)" data-target="#account_maneger_summary_mail_modal">Edit</a>
|
||||
</div>
|
||||
<div class="form-group col-md-5">
|
||||
<textarea style="display:none;" name="" id="" class="form-control "></textarea>
|
||||
@ -446,6 +446,16 @@
|
||||
|
||||
|
||||
<input type="file" id="Question_title_fileInput" style="display: none;">
|
||||
<table id="attachment_table_ecard" class="table table-sm mb-0" style="margin-top: 30px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attachments</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="attachment_tbody_ecard">
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
@ -664,7 +674,24 @@
|
||||
<div class="form-group col-md-2 testmail" style="display: none;">
|
||||
<a class="btn btn-primary waves-effect waves-light mr-1 setid" onclick="testMailSend(this)">Test Mail</a>
|
||||
</div>
|
||||
</div><hr>
|
||||
</div>
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-12">
|
||||
<select id="account_maneger_summary_mail_modal_customButton" class="form-control" style="border:none;right: 6px;width: auto;position: absolute;z-index: 1;top: 17px;height: 32px;float: right;" onchange="copyToClipboard(this)">
|
||||
<option value="">PlaceHolders</option>
|
||||
<?php foreach ($placeHolders as $value): ?>
|
||||
<?php if($value == 'member_name' || $value == 'nhance_logo' || $value == 'client_logo' || $value == 'app_link' || $value == 'client_name' || $value == 'member_summary'){ ?>
|
||||
<?php $valueChange = str_replace('_', ' ', $value); $valueChange = ucwords($valueChange); ?>
|
||||
<option value="{{<?php echo $value; ?>}}"><?php echo $valueChange; ?></option>
|
||||
<?php } ?>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<span id="copy-feedback" style="display: none; position: absolute; top: 50px; right: 10px; color: green; font-size: 12px;">
|
||||
Copied to clipboard!
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<!-- Unlayer editor -->
|
||||
<div class="form-row" id="rac_rate_dropdown">
|
||||
<div class="form-group col-md-12">
|
||||
@ -897,7 +924,7 @@
|
||||
}
|
||||
else if (target.matches('#account_maneger_summary_mail_modal_customButton'))
|
||||
{
|
||||
editor4.selection.insertHTML($(target).val());
|
||||
// editor4.selection.insertHTML($(target).val());
|
||||
$(target).val('');
|
||||
}
|
||||
else if (target.matches('#client_hr_summary_mail_modal_customButton'))
|
||||
@ -913,7 +940,7 @@
|
||||
editor.setEditorValue('');
|
||||
editor2.setEditorValue('');
|
||||
editor3.setEditorValue('');
|
||||
editor4.setEditorValue('');
|
||||
// editor4.setEditorValue('');
|
||||
editor5.setEditorValue('');
|
||||
editor6.setEditorValue('');
|
||||
|
||||
@ -1275,10 +1302,10 @@
|
||||
return word.charAt(0).toUpperCase() + word.slice(1);
|
||||
}).join(' ');
|
||||
}
|
||||
|
||||
template_name = '';
|
||||
function getMailTemplateData(element)
|
||||
{
|
||||
var template_name = $(element).attr('id');
|
||||
template_name = $(element).attr('id');
|
||||
|
||||
if (template_name == "member_welcome_mail" || template_name == "member_reminder_mail" || template_name == "member_ecard_mail" || template_name == "member_review_and_summary_mail" || template_name == "client_hr_summary_mail")
|
||||
{
|
||||
@ -1311,16 +1338,19 @@
|
||||
if(res.id){
|
||||
$('.testmail').show();
|
||||
$('#attachment_table').show();
|
||||
$('#attachment_table_ecard')
|
||||
$('.setid').attr('data-id', res.id);
|
||||
}else{
|
||||
$('.testmail').hide();
|
||||
$('#attachment_table').hide();
|
||||
$('#attachment_table_ecard').hide();
|
||||
$('.setid').attr('data-id', '');
|
||||
}
|
||||
|
||||
}else{
|
||||
$('.testmail').hide();
|
||||
$('#attachment_table').hide();
|
||||
$('#attachment_table_ecard').hide();
|
||||
$('.setid').attr('data-id', '');
|
||||
|
||||
}
|
||||
@ -1448,8 +1478,13 @@
|
||||
function addHTMLInput(data = null) {
|
||||
|
||||
console.log('addHTMLInput function called');
|
||||
|
||||
const container = document.getElementById('attachment_tbody');
|
||||
console.log(template_name);
|
||||
var container = '';
|
||||
if (template_name == 'member_welcome_mail'){
|
||||
container = document.getElementById('attachment_tbody');
|
||||
}else{
|
||||
container = document.getElementById('attachment_tbody_ecard');
|
||||
}
|
||||
|
||||
if (data) {
|
||||
|
||||
@ -1512,7 +1547,11 @@
|
||||
}
|
||||
|
||||
function removeHTMLInput(element) {
|
||||
const container = document.getElementById('attachment_tbody');
|
||||
if (template_name == 'member_welcome_mail'){
|
||||
const container = document.getElementById('attachment_tbody');
|
||||
}else{
|
||||
const container = document.getElementById('attachment_tbody_ecard');
|
||||
}
|
||||
const rows = container.querySelectorAll('.dynamic-form-row');
|
||||
|
||||
if (rows.length > 1) {
|
||||
@ -1525,13 +1564,14 @@
|
||||
|
||||
event.preventDefault(); // Prevent the default form submission
|
||||
|
||||
var template_name = $('#member_welcome_mail_template_name').val();
|
||||
// var template_name = template_name;
|
||||
var client_id = $('#general_PrimaryKey').val();
|
||||
// console.log(client_id);
|
||||
|
||||
const formData = new FormData(form);
|
||||
formData.append('template_name', template_name);
|
||||
formData.append('client_id', client_id);
|
||||
|
||||
console.log(formData.template_name);
|
||||
const fileInput = form.querySelector('input[type="file"]');
|
||||
|
||||
// Check if a file is selected
|
||||
@ -1597,7 +1637,7 @@
|
||||
|
||||
function removeAttachment(id){
|
||||
|
||||
var template_name = $('#member_welcome_mail_template_name').val();
|
||||
// var template_name = template_name
|
||||
var client_id = $('#general_PrimaryKey').val();
|
||||
|
||||
$('.loader').fadeIn();
|
||||
@ -1751,10 +1791,10 @@ function initializeEditor(callback) {
|
||||
}
|
||||
|
||||
// Modified template data function with better error handling
|
||||
function getMailTemplateData(element) {
|
||||
function getMailTemplateData2(element) {
|
||||
const template_name = element.id;
|
||||
const validTemplates = [
|
||||
"account_maneger_summary_mail",
|
||||
"account_maneger_summary_mail","member_reminder_mail","member_ecard_mail"
|
||||
];
|
||||
|
||||
if (!validTemplates.includes(template_name)) {
|
||||
@ -1824,6 +1864,7 @@ function getMailTemplateData(element) {
|
||||
// Update UI elements
|
||||
$('.testmail').toggle(!!res.id);
|
||||
$('#attachment_table').toggle(!!res.id);
|
||||
$('#attachment_table_ecard').toggle(!!res.id);
|
||||
$('.setid').attr('data-id', res.id || '');
|
||||
}else{
|
||||
console.log("Inside else");
|
||||
@ -1949,5 +1990,76 @@ function hideBranding(){
|
||||
console.log('Overlay added to hide branding.');
|
||||
});
|
||||
}
|
||||
function copyToClipboard(selectElement) {
|
||||
const value = selectElement.value; // Get the selected value
|
||||
if (value) {
|
||||
// Use the Clipboard API to copy the value
|
||||
navigator.clipboard.writeText(value)
|
||||
.then(() => {
|
||||
const feedback = document.getElementById('copy-feedback');
|
||||
feedback.style.display = 'inline'; // Show the feedback message
|
||||
setTimeout(() => {
|
||||
feedback.style.display = 'none'; // Hide the feedback message after 2 seconds
|
||||
}, 2000);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Failed to copy text: ', err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
<!-- <script src="https://editor.unlayer.com/embed.js"></script> -->
|
||||
|
||||
<!-- <script>
|
||||
// Initialize Unlayer editor
|
||||
unlayer.init({
|
||||
id: 'editor-container', // Make sure to target your correct editor container ID
|
||||
projectId: 1234, // Replace with your actual Unlayer project ID
|
||||
tools: {
|
||||
text: {
|
||||
label: 'Text',
|
||||
icon: 'fa fa-font'
|
||||
}
|
||||
},
|
||||
paste: { // Enable the paste tool
|
||||
label: 'Paste',
|
||||
icon: 'fa fa-clipboard', // You can customize the icon here
|
||||
action: function() {
|
||||
// You can handle any custom behavior for paste here
|
||||
console.log('Paste icon clicked!');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Function to handle pasting clipboard content into a text block
|
||||
async function pasteFromClipboard() {
|
||||
try {
|
||||
// Use the Clipboard API to get the clipboard text
|
||||
const text = await navigator.clipboard.readText();
|
||||
if (text) {
|
||||
// Get the current selected block or create one if none exists
|
||||
const editor = unlayer.getEditor();
|
||||
const currentBlock = editor.getSelectedElement();
|
||||
|
||||
if (currentBlock && currentBlock.type === 'text') {
|
||||
// If the selected block is a text block, insert the text there
|
||||
editor.insertText(text);
|
||||
} else {
|
||||
// If there's no text block, create one and insert the text
|
||||
editor.addTextBlock({
|
||||
"type": "text",
|
||||
"text": text
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to read clipboard contents: ', err);
|
||||
}
|
||||
}
|
||||
|
||||
// Listen for the click event inside the editor container
|
||||
document.getElementById('editor-container').addEventListener('click', function() {
|
||||
pasteFromClipboard(); // Paste clipboard content when clicked inside editor
|
||||
});
|
||||
</script> -->
|
||||
|
||||
67
tests/unit/ExcelSanitizeHelperTest.php
Normal file
67
tests/unit/ExcelSanitizeHelperTest.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Helpers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Helpers\ExcelSanitizeHelper;
|
||||
|
||||
class ExcelSanitizeHelperTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test sanitizeArrayData with various input scenarios.
|
||||
*/
|
||||
public function testSanitizeArrayData()
|
||||
{
|
||||
// Test with a flat array
|
||||
$input = [
|
||||
"validString" => "HelloWorld",
|
||||
"withNonPrintable" => "71030034240400000016",
|
||||
"withWhitespace" => " Trim me ",
|
||||
"nonStringValue" => 'Hello
|
||||
World',
|
||||
];
|
||||
$expected = [
|
||||
"validString" => "HelloWorld",
|
||||
"withNonPrintable" => "71030034240400000016",
|
||||
"withWhitespace" => "Trim me",
|
||||
"nonStringValue" => 'HelloWorld',
|
||||
];
|
||||
$result = ExcelSanitizeHelper::sanitizeArrayData($input);
|
||||
// var_dump($input);
|
||||
// var_dump($result);
|
||||
$this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));
|
||||
|
||||
// Test with nested arrays
|
||||
$input = [
|
||||
"nested" => [
|
||||
"validString" => "71030034240400000016",
|
||||
"withNonPrintable" => "Nested\x01\x02String_x000A_",
|
||||
],
|
||||
"withWhitespace" => " Outer whitespace ",
|
||||
];var_dump($input);
|
||||
$expected = [
|
||||
"nested" => [
|
||||
"validString" => "71030034240400000016",
|
||||
"withNonPrintable" => "NestedString",
|
||||
],
|
||||
"withWhitespace" => "Outer whitespace",
|
||||
];
|
||||
$this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));
|
||||
|
||||
// Test with empty array
|
||||
$this->assertSame([], ExcelSanitizeHelper::sanitizeArrayData([]));
|
||||
|
||||
// Test with an array containing only non-string values
|
||||
$input = [
|
||||
"integer" => 42,
|
||||
"float" => 3.14,
|
||||
"boolean" => true,
|
||||
"null" => null,
|
||||
];
|
||||
$this->assertSame($input, ExcelSanitizeHelper::sanitizeArrayData($input));
|
||||
|
||||
// Test with invalid input to ensure graceful handling (edge case)
|
||||
$input = ["invalid" => "\x00\x01\x7F_x000D_", "normal" => "Text"];
|
||||
$expected = ["invalid" => "", "normal" => "Text"];
|
||||
$this->assertSame($expected, ExcelSanitizeHelper::sanitizeArrayData($input));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user