533 lines
26 KiB
PHP
Executable File
533 lines
26 KiB
PHP
Executable File
<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;
|
||
}
|
||
|
||
.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">
|
||
<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>
|
||
</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>
|
||
</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>
|
||
|
||
<!-- 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);" />
|
||
</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>
|
||
|
||
<!-- Hidden File Input -->
|
||
<input type="file" class="hidden-input"
|
||
id="fc" name="fc"
|
||
accept="image/jpeg, image/jpg, image/png"
|
||
onchange="PreviewImage1(event);" />
|
||
</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>
|
||
|
||
<!-- Hidden File Input -->
|
||
<input type="file" class="hidden-input"
|
||
id="bc" name="bc"
|
||
accept="image/jpeg, image/jpg, image/png"
|
||
onchange="PreviewImage4(event);" />
|
||
</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 -->
|
||
|
||
|
||
<script>
|
||
$(document).ready(function() {
|
||
|
||
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>
|