nhance/app/Views/tpa_basic_info.php
2026-04-16 15:28:06 +05:30

618 lines
30 KiB
PHP
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<style>
.image-preview {
border: 1px solid #00999E;
border-radius: 12px;
width: 70px;
height: 70px;
display: flex;
align-items: center;
justify-content: center;
/* margin-right: 15px; */
}
.image-preview img {
width: 50px;
height: 50px;
object-fit: contain;
transition: transform 0.2s ease-in-out;
}
.image-preview:hover img {
transform: scale(1.2);
cursor: zoom-in;
}
.upload-btn {
background-color: #00999E;
color: #fff;
border: none;
border-radius: 25px;
padding: 6px 20px;
margin-right: 10px;
cursor: pointer;
font-size: 14px;
}
/* .delete-btn {
background-color: #e5f7f6;
color: #00999E;
border: none;
border-radius: 25px;
padding: 6px 20px;
cursor: pointer;
font-size: 14px;
} */
.helper-text {
font-size: 12px;
color: #666;
margin-top: 8px;
/* wrapping fixes */
word-wrap: break-word; /* old browsers */
overflow-wrap: break-word; /* modern browsers */
white-space: normal; /* allow wrapping */
max-width: 285px; /* adjust to your design width */
}
.hidden-input {
display: none;
}
</style>
<div class="tab-pane fade active show" id="general-q-tab">
<div class="row">
<div class="col-12">
<div class="card-body subcard">
<div class="custom-form">
<form role="form" class="parsley-examples" method="post" id="tpa_general_form" enctype="multipart/form-data" data-parsley-validate>
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
<input type="hidden" name="PrimaryKey" id="tpa_General_PrimaryKey" value="<?= isset($tpa['id']) ? $tpa['id'] : '' ?>" />
<input type="hidden" name="tpa_id" id="tpa_id" />
<div class="form-group">
<div class="form-row">
<div class="form-group col-md-4">
<label for="tpa_name">TPA Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="tpa_name" placeholder="Enter TPA Name" value="<?= isset($tpa['name']) ? $tpa['name'] : '' ?>" name="name" required data-parsley-minlength="2">
</div>
<div class="form-group col-md-4">
<label for="tpa_short_name">TPA Short Name<span class="text-danger">*</span></label>
<input type="text" class="form-control" id="short_name" placeholder="Enter Short Name" value="<?= isset($tpa['short_name']) ? $tpa['short_name'] : '' ?>" name="short_name" required data-parsley-minlength="3">
</div>
<div class="form-group col-md-4">
<label for="tpa_network_hospitals">Network Hospitals<span class="text-danger">*</span></label>
<input type="url" class="form-control" id="tpa_network_hospitals" name="network_hospitals" placeholder="Enter Network Hospitals" value="<?= isset($tpa['network_hospitals']) ? $tpa['network_hospitals'] : '' ?>" required data-parsley-type="url">
</div>
</div>
<br>
<div class="form-row">
<div class="form-group col-md-12">
<label for="tpa_ecard_template">E-Card Template<span class="text-danger"></span></label>
<textarea style="height: 380px;" class="form-control" id="ecard_content" placeholder="Enter E-card Content" name="ecard_content"><?= isset($template_data) ? $template_data : '' ?></textarea>
</div>
</div>
<div class="form-row" id="view_pre_btn" style="display :none">
<div class="form-group col-md-4">
<a href="<?= isset($tpa['id']) ? base_url('/util/preview-card/') . $tpa['id'] : '' ?>" class="btn btn-primary" id="preview" target="_blank">Preview</a>
</div>
</div>
<!-- <div class="form-row">
<div class="form-group col-md-4">
<label for="tpa_logo">TPA Logo<span class="text-danger"></span></label>
<input type="file" class="form-control" onchange="PreviewImage();" id="tpa_logo" name="tpa_logo" accept="image/jpeg, image/jpg, image/png">
</div>
<div class="form-group col-md-4">
<label for="tpa_front_card_image">Front card Image<span class="text-danger"></span></label>
<input type="file" class="form-control" onchange="PreviewImage2();" id="fc" name="fc" accept="image/jpeg, image/jpg, image/png">
</div>
<div class="form-group col-md-4">
<label for="tpa_back_card_image">Back card Image<span class="text-danger"></span></label>
<input type="file" class="form-control" onchange="PreviewImage3();" id="bc" name="bc" accept="image/jpeg, image/jpg, image/png">
</div>
</div> -->
<!-- <div class="form-row">
<div class="form-group col-md-4">
<label for="tpa_logo_preview">TPA Logo Preview<span class="text-danger"></span></label>
<img src="<?= isset($tpa['tpa_logo']) && !empty($tpa['tpa_logo']) ? base_url() . "public/uploads/logo/" . $tpa['tpa_logo'] : base_url() . "public/assets/images/avatar_2x.png" ?>" width="100" height="100" id="uploadPreview" class="avatar img-circle img-thumbnail" alt="avatar" />
</div>
<div class="form-group col-md-4">
<label for="tpa_front_card_preview">Front card Preview<span class="text-danger"></span></label>
<img src="<?= isset($tpa['front_card']) && !empty($tpa['front_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['front_card'] : base_url() . "public/assets/images/avatar_2x.png" ?>" width="100" height="100" id="uploadPreview2" class="avatar img-circle img-thumbnail" alt="avatar" />
</div>
<div class="form-group col-md-4">
<label for="tpa_back_card_preview">Back card Preview<span class="text-danger"></span></label>
<img src="<?= isset($tpa['back_card']) && !empty($tpa['back_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['back_card'] : base_url() . "public/assets/images/avatar_2x.png" ?>" width="100" height="100" id="uploadPreview3" class="avatar img-circle img-thumbnail" alt="avatar" />
</div>
</div> -->
<div class="form-row">
<!-- TPA Logo -->
<div class="form-group col-md-4">
<label for="tpa_logo">TPA Logo</label>
<div class="row align-items-center">
<!-- Left column: Image -->
<div class="col-auto">
<div class="image-preview">
<img src="<?= isset($tpa['tpa_logo']) && !empty($tpa['tpa_logo']) ? base_url() . "public/uploads/logo/" . $tpa['tpa_logo'] : base_url() . "public/assets/images/avatar_2x.png" ?>"
id="uploadPreview0"
class="avatar img-circle img-thumbnail"
alt="TPA Logo" />
</div>
</div>
<!-- Right column: Buttons + text -->
<div class="col">
<div class="d-flex">
<button type="button" class="upload-btn" onclick="document.getElementById('tpa_logo').click();">Upload</button>
<!-- <button type="button" class="delete-btn" onclick="removeImage0();">Delete</button> -->
</div>
<div class="helper-text" id="fileNameText0">
<?= isset($tpa['tpa_logo']) && !empty($tpa['tpa_logo']) ? $tpa['tpa_logo'] : '( Upload Your TPA Logo )' ?>
</div>
</div>
</div>
<div id="tpa_logo_error_container"></div>
<!-- Hidden File Input -->
<input type="file" class="hidden-input"
id="tpa_logo" name="tpa_logo"
accept="image/jpeg, image/jpg, image/png"
onchange="PreviewImage0(event);"
data-parsley-max-file-size="200"
data-parsley-file-extension="jpg,jpeg,png"
data-parsley-errors-container="#tpa_logo_error_container"
/>
</div>
<!-- TPA Logo Ends -->
<!-- Front Image -->
<div class="form-group col-md-4">
<label for="tpa_logo">Front card Image</label>
<div class="row align-items-center">
<!-- Left column: Image -->
<div class="col-auto">
<div class="image-preview">
<img src="<?= isset($tpa['front_card']) && !empty($tpa['front_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['front_card'] : base_url() . "public/assets/images/avatar_2x.png" ?>"
id="uploadPreview1"
class="avatar img-circle img-thumbnail"
alt="avatar" />
</div>
</div>
<!-- Right column: Buttons + text -->
<div class="col">
<div class="d-flex">
<button type="button" class="upload-btn" onclick="document.getElementById('fc').click();">Upload</button>
<!-- <button type="button" class="delete-btn" onclick="removeImage1();">Delete</button> -->
</div>
<div class="helper-text" id="fileNameText1">
<?= isset($tpa['front_card']) && !empty($tpa['front_card']) ? $tpa['front_card'] : '( Upload Your Front card Image )' ?>
</div>
</div>
</div>
<div id="fc_error_container"></div>
<!-- Hidden File Input -->
<input type="file" class="hidden-input"
id="fc" name="fc"
accept="image/jpeg, image/jpg, image/png"
onchange="PreviewImage1(event);"
data-parsley-max-file-size="500"
data-parsley-file-extension="jpg,jpeg,png"
data-parsley-errors-container="#fc_error_container"
/>
</div>
<!-- Front Image Ends -->
<!-- Back Image -->
<div class="form-group col-md-4">
<label for="tpa_logo">Back card Image</label>
<div class="row align-items-center">
<!-- Left column: Image -->
<div class="col-auto">
<div class="image-preview">
<img src="<?= isset($tpa['back_card']) && !empty($tpa['back_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['back_card'] : base_url() . "public/assets/images/avatar_2x.png" ?>"
id="uploadPreview4"
class="avatar img-circle img-thumbnail"
alt="avatar" />
</div>
</div>
<!-- Right column: Buttons + text -->
<div class="col">
<div class="d-flex">
<button type="button" class="upload-btn" onclick="document.getElementById('bc').click();">Upload</button>
<!-- <button type="button" class="delete-btn" onclick="removeImage4();">Delete</button> -->
</div>
<div class="helper-text" id="fileNameText4">
<?= isset($tpa['back_card']) && !empty($tpa['back_card']) ? $tpa['back_card'] : '( Upload Your Back card Image )' ?>
</div>
</div>
</div>
<div id="bc_error_container"></div>
<!-- Hidden File Input -->
<input type="file" class="hidden-input"
id="bc" name="bc"
accept="image/jpeg, image/jpg, image/png"
onchange="PreviewImage4(event);"
data-parsley-max-file-size="500"
data-parsley-file-extension="jpg,jpeg,png"
data-parsley-errors-container="#bc_error_container"
/>
</div>
<!-- Back Image Ends -->
</div>
</div>
<div class="form-group text-right m-b-0">
<button type="submit" class="btn app-btn-secondary waves-effect waves-light mr-1" id="btnSubmit">Submit</button>
<button type="button" class="btn btn-secondary waves-effect btnBack" id="btnBack">Cancel</button>
</div>
</form>
</div>
</div>
</div> <!-- end col-->
</div>
</div>
<!-- end -->
<div id="full-width-modal-emp-list" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="fullWidthModalLabel" aria-hidden="true">
<div class="modal-dialog modal-full-width">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="fullWidthModalLabel">Preview<span id="title_header_name"></span></h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="Preview_data">
</div>
<div class="modal-footer">
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- Image Preview Modal -->
<div class="modal fade" id="imagePreviewModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg">
<div class="modal-content" style="background: transparent; border: 0;">
<div class="modal-body text-center p-0">
<img src="" id="modalImage" class="img-fluid rounded" alt="Full-size preview" style="max-height: 90vh; cursor: zoom-out;">
</div>
</div>
</div>
</div>
<!-- /.modal -->
<script>
$(document).ready(function() {
// Handle image preview click to open modal
$('.image-preview').on('click', function() {
const imgSrc = $(this).find('img').attr('src');
// Don't open modal for the placeholder image
if (imgSrc && !imgSrc.includes('avatar_2x.png')) {
$('#modalImage').attr('src', imgSrc);
$('#imagePreviewModal').modal('show');
}
});
// Close modal on click (either on image or backdrop)
$('#imagePreviewModal').on('click', function() {
$(this).modal('hide');
});
// Custom Parsley validator for file size
window.Parsley.addValidator('maxFileSize', {
validateString: function(value, maxSize, parsleyInstance) {
if (!window.FileReader) {
alert('You browser does not support FileReader API, please upgrade.');
return true;
}
var files = parsleyInstance.$element[0].files;
if (files.length == 0) {
return true; // No file, so validation passes (unless required)
}
return files[0].size <= maxSize * 1024;
},
requirementType: 'integer',
messages: {
en: 'This file should not be larger than %s KB.'
}
});
// Custom Parsley validator for file extension
window.Parsley.addValidator('fileExtension', {
validateString: function(value, requirement, parsleyInstance) {
var file = parsleyInstance.$element[0].files[0];
if (!file) {
return true; // No file, so validation passes
}
var extensions = requirement.split(',').map(function(ext) { return ext.trim().toLowerCase(); });
var fileExtension = file.name.split('.').pop().toLowerCase();
return extensions.indexOf(fileExtension) !== -1;
},
requirementType: 'string',
messages: {
en: 'Allowed extensions are: %s.'
}
});
if($('#tpa_General_PrimaryKey').val() != ""){
$('#view_pre_btn').show()
}
$("#tpa_general_form").submit(function(events) {
events.preventDefault();
var isValid = $('#tpa_general_form').parsley().validate();
var PrimaryKey = $('#tpa_General_PrimaryKey').val();
var form_action = '';
console.log('tpa_General_PrimaryKey', PrimaryKey);
if (isValid) {
if (PrimaryKey === "") {
form_action = '<?= base_url("master/tpa/createpost"); ?>';
} else {
form_action = '<?= base_url("master/tpa/edit"); ?>';
}
console.log('tpa_General_form_action', form_action);
var formData = new FormData($('#tpa_general_form')[0]);
var OptionsHTML1 = '';
$('.loader').fadeIn();
$('.loader-mask').fadeIn();
$.ajax({
data: formData,
url: form_action,
type: "POST",
dataType: 'json',
processData: false,
contentType: false,
success: function(res) {
if($('#tpa_General_PrimaryKey').val() == ""){
window.location.href = '<?= base_url("master/tpa/list/"); ?>' + res.data.id;
}
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
}, 1000);
console.log(res);
$('#tpa_id').val(res.data.id);
$('#tpa_id_branch').val(res.data.id);
$('#tpa_branch_contacts_id').click();
$('#btnBranchAdd').show();
var message = "TPA General Info";
toastr.success(message, 'Success');
},
error: function(xhr, status, error) {
console.error(xhr.responseText);
console.error(status, error);
setTimeout(function() {
$('.loader').fadeOut();
$('.loader-mask').delay(350).fadeOut('slow');
console.log('Something Wrong!', 'Warning');
// Handle validation errors (CI4)
if (xhr.status === 400) {
let response = JSON.parse(xhr.responseText);
let errorMessages = "";
let seenMessages = []; // Array to store unique messages
if (response.errors) {
$.each(response.errors, function (field, message) {
if (!seenMessages.includes(message)) {
errorMessages += `• ${message}<br>`;
seenMessages.push(message); // Mark this message as "seen"
}
});
toastr.error(errorMessages, 'Validation Error', { "allowHtml": true });
} else {
toastr.warning(response.message || 'Validation failed', 'Warning');
}
}else if (xhr.status === 403) {
let response = JSON.parse(xhr.responseText);
toastr.error(response.message, 'Security Policy');
} else if (xhr.status === 500) {
toastr.error('Something went wrong . Please try again later.', 'Server Error');
} else {
toastr.error('An unexpected error occurred. Please try again later.', 'Error');
}
}, 1000);
}
});
}
});
function validateForm() {
var isValid = true;
// Perform validation for each field
$('#tpa_general_form input, #tpa_general_form select').each(function() {
// Check for empty text inputs and selects
if ($(this).is('input[type="text"]') || $(this).is('select')) {
if ($.trim($(this).val()) == '') {
alert('Please fill in all fields');
isValid = false;
return false; // Exit the loop early
}
}
// Check for file inputs (assuming image files)
if ($(this).is('input[type="file"]')) {
var fileInput = $(this)[0];
if (fileInput.files.length === 0) {
alert('Please select an image file');
isValid = false;
return false; // Exit the loop early
}
}
});
return isValid;
}
});
function PreviewImage() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("tpa_logo").files[0]);
oFReader.onload = function(oFREvent) {
document.getElementById("uploadPreview").src = oFREvent.target.result;
};
};
function PreviewImage2() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("fc").files[0]);
oFReader.onload = function(oFREvent) {
document.getElementById("uploadPreview2").src = oFREvent.target.result;
};
};
function PreviewImage3() {
var oFReader = new FileReader();
oFReader.readAsDataURL(document.getElementById("bc").files[0]);
oFReader.onload = function(oFREvent) {
document.getElementById("uploadPreview3").src = oFREvent.target.result;
};
};
function PreviewImage0(event) {
const input = event.target;
const file = input.files[0];
if (file) {
// Show preview
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('uploadPreview0').src = e.target.result;
};
reader.readAsDataURL(file);
// Show file name
document.getElementById('fileNameText0').innerText = file.name;
}
}
function removeImage0() {
// Reset preview to default
document.getElementById('uploadPreview0').src = "<?= base_url() . 'public/assets/images/avatar_2x.png' ?>";
document.getElementById('fileNameText0').innerText = '( Upload Your TPA Logo )';
document.getElementById('tpa_logo').value = ""; // clear file input
}
function PreviewImage1(event) {
const input = event.target;
const file = input.files[0];
if (file) {
// Show preview
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('uploadPreview1').src = e.target.result;
};
reader.readAsDataURL(file);
// Show file name
document.getElementById('fileNameText1').innerText = file.name;
}
}
function removeImage1() {
// Reset preview to default
document.getElementById('uploadPreview1').src = "<?= base_url() . 'public/assets/images/avatar_2x.png' ?>";
document.getElementById('fileNameText1').innerText = '( Upload Your Front card Image )';
document.getElementById('fc').value = ""; // clear file input
}
function PreviewImage4(event) {
const input = event.target;
const file = input.files[0];
if (file) {
// Show preview
const reader = new FileReader();
reader.onload = function(e) {
document.getElementById('uploadPreview4').src = e.target.result;
};
reader.readAsDataURL(file);
// Show file name
document.getElementById('fileNameText4').innerText = file.name;
}
}
function removeImage4() {
// Reset preview to default
document.getElementById('uploadPreview4').src = "<?= base_url() . 'public/assets/images/avatar_2x.png' ?>";
document.getElementById('fileNameText4').innerText = '( Upload Your Back card Image )';
document.getElementById('bc').value = ""; // clear file input
}
$('#preview').click(function() {
var ecardContent = $('#ecard_content').val();
$('#Preview_data').html(ecardContent);
});
// $(document).ready(function() {
// $('#preview').click(function() {
// // Get the value from the textarea
// var ecardContent = $('#ecard_content').val();
// var filename_front = $('#fc').val().split('\\').pop();
// var original_string_front = '{FRONT_CARD}';
// var replace_string_front = '<?= isset($tpa['front_card']) && !empty($tpa['front_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['front_card'] : "" ?>';
// ecardContent = ecardContent.replace(original_string_front, replace_string_front);
// console.log(ecardContent);
// var filename_back = $('#fc').val().split('\\').pop();
// var original_string_back = '{BACK_CARD}';
// var replace_string_back = '<?= isset($tpa['back_card']) && !empty($tpa['back_card']) ? base_url() . "public/uploads/template_bg/" . $tpa['back_card'] : "" ?>';
// ecardContent = ecardContent.replace(original_string_back, replace_string_back);
// // console.log(ecardContent)
// // Open a new window for printing
// var printWindow = window.open('', '_blank');
// // Insert the textarea value into the new window
// printWindow.document.write('<html><head><title>Preview Page</title></head><body>');
// printWindow.document.write(ecardContent); // Use <pre> tag to preserve formatting
// printWindow.document.write('</body></html>');
// // Trigger the print functionality
// printWindow.print();
// printWindow.close();
// });
// });
</script>