358 lines
14 KiB
PHP
Executable File
358 lines
14 KiB
PHP
Executable File
<style>
|
|
|
|
.switch {
|
|
position: relative;
|
|
display: inline-block;
|
|
width: 54px;
|
|
height: 34px;
|
|
}
|
|
|
|
.switch input {
|
|
opacity: 0;
|
|
width: 0;
|
|
height: 0;
|
|
}
|
|
|
|
.slider {
|
|
position: absolute;
|
|
cursor: pointer;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background-color: #ccc;
|
|
-webkit-transition: .4s;
|
|
transition: .4s;
|
|
}
|
|
|
|
.slider:before {
|
|
position: absolute;
|
|
content: "";
|
|
height: 19px;
|
|
width: 19px;
|
|
left: 4px;
|
|
bottom: 4px;
|
|
background-color: white;
|
|
-webkit-transition: .4s;
|
|
transition: .4s;
|
|
}
|
|
|
|
input:checked + .slider {
|
|
background-color: #00999E;
|
|
}
|
|
|
|
input:focus + .slider {
|
|
box-shadow: 0 0 1px #00999E;
|
|
}
|
|
|
|
input:checked + .slider:before {
|
|
-webkit-transform: translateX(26px);
|
|
-ms-transform: translateX(26px);
|
|
transform: translateX(26px);
|
|
}
|
|
|
|
/* Rounded sliders */
|
|
.slider.round {
|
|
border-radius: 34px;
|
|
}
|
|
|
|
.slider.round:before {
|
|
border-radius: 50%;
|
|
}
|
|
</style>
|
|
|
|
|
|
<div class="tab-pane fade active show" id="general-q-tab">
|
|
|
|
<!---- new ----->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="card-body">
|
|
<div class="custom-form">
|
|
<form role="form" class="parsley-examples" method="post" id="insurer_general_form" enctype="multipart/form-data">
|
|
<input type="hidden" value="<?= csrf_hash() ?>" name="<?= csrf_token() ?>" />
|
|
<input type="hidden" name="PrimaryKey" id="insurer_General_PrimaryKey" value="<?= isset($insurer['id']) ? $insurer['id'] : '' ?>" />
|
|
<input type="hidden" name="insurer_id" id="insurer_id" />
|
|
|
|
<!-- Insurer Name -->
|
|
<div class="form-group row">
|
|
<label for="insurer_name" class="col-md-4 col-form-label">Insurer Name<span class="text-danger">*</span></label>
|
|
<div class="col-md-5">
|
|
<input type="text" class="form-control" id="insurer_name" placeholder="Enter Insurer Name"
|
|
value="<?= isset($insurer['name']) ? $insurer['name'] : '' ?>" name="name" required>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Short Name -->
|
|
<div class="form-group row">
|
|
<label for="short_name" class="col-md-4 col-form-label">Insurer Short Name<span class="text-danger">*</span></label>
|
|
<div class="col-md-5">
|
|
<input type="text" class="form-control" id="short_name" placeholder="Enter Short Name"
|
|
value="<?= isset($insurer['short_name']) ? $insurer['short_name'] : '' ?>" name="short_name" required minlength="3" maxlength="8">
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Insurer Type -->
|
|
<div class="form-group row">
|
|
<label class="col-md-4 col-form-label">Insurer Type</label>
|
|
<div class="col-md-6 d-flex align-items-center">
|
|
<input type="radio" id="type_pvt" name="type" value="pvt"
|
|
<?= isset($insurer['type']) && $insurer['type'] == 'pvt' ? 'checked' : '' ?>>
|
|
<label for="type_pvt" class="mr-3 ml-2 mt-1 ">PVT</label>
|
|
<input type="radio" id="type_psu" name="type" value="psu"
|
|
<?= isset($insurer['type']) && $insurer['type'] == 'psu' ? 'checked' : '' ?>>
|
|
<label for="type_psu" class="mr-3 ml-2 mt-1 ">PSU</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Insurer Category -->
|
|
<div class="form-group row">
|
|
<label class="col-md-4 col-form-label">Insurer Category</label>
|
|
<div class="col-md-6 d-flex align-items-center">
|
|
<input type="radio" id="cat_life" name="category" value="life"
|
|
<?= isset($insurer['category']) && $insurer['category'] == 'life' ? 'checked' : '' ?>>
|
|
<label for="cat_life" class="mr-3 ml-2 mt-1 ">Life</label>
|
|
<input type="radio" id="cat_general" name="category" value="general"
|
|
<?= isset($insurer['category']) && $insurer['category'] == 'general' ? 'checked' : '' ?>>
|
|
<label for="cat_general" class="mr-3 ml-2 mt-1 ">General (Non Life)</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add one day (Addition) -->
|
|
<div class="form-group row">
|
|
<label class="col-md-4 col-form-label">Add one day to date of coverage when Addition/Dependent addition</label>
|
|
<div class="col-md-6 d-flex align-items-center">
|
|
<label class="switch">
|
|
<input id="addition_add_day" type="checkbox" name="addition_add_day"
|
|
<?= (isset($insurer['addition_add_day']) && $insurer['addition_add_day'] == 1) ? 'checked' : '' ?>>
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Add one day (Deletion) -->
|
|
<div class="form-group row">
|
|
<label class="col-md-4 col-form-label">Add one day to date of Deletion</label>
|
|
<div class="col-md-6 d-flex align-items-center">
|
|
<label class="switch">
|
|
<input id="deletion_add_day" type="checkbox" name="deletion_add_day"
|
|
<?= (isset($insurer['deletion_add_day']) && $insurer['deletion_add_day'] == 1) ? 'checked' : '' ?>>
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<!-- Multievent Export -->
|
|
<div class="form-group row">
|
|
<label class="col-md-4 col-form-label">Multievent Export</label>
|
|
<div class="col-md-6 d-flex align-items-center">
|
|
<label class="switch mb-0">
|
|
<input id="is_multi_event" type="checkbox" name="is_multi_event"
|
|
<?= (isset($insurer['is_multi_event']) && $insurer['is_multi_event'] == 1) ? 'checked' : '' ?>>
|
|
<span class="slider round" style="height: 27px;"></span>
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Logo -->
|
|
<div class="form-group row">
|
|
<label for="insurer_logo" class="col-md-4 col-form-label">Insurer Logo</label>
|
|
<div class="col-md-5">
|
|
<div class="input-icon">
|
|
<input type="file" class="form-control" id="insurer_logo" name="insurer_logo"
|
|
accept="image/jpeg, image/jpg, image/png" onchange="PreviewImage();">
|
|
<i class="mdi mdi-upload additional-icon"></i>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-3">
|
|
<img src="<?= isset($insurer['insurer_logo']) && !empty($insurer['insurer_logo']) ? base_url() . "public/uploads/logo/" . $insurer['insurer_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>
|
|
|
|
<!-- Buttons -->
|
|
<div class="form-group row">
|
|
<div class="col-md-12 text-right">
|
|
<button type="submit" class="btn btn-primary 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>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div> <!-- end col-->
|
|
</div>
|
|
<!---- ends ------>
|
|
</div>
|
|
<!-- end -->
|
|
|
|
<script>
|
|
$(document).ready(function() {
|
|
|
|
$('#insurer_logo').on('change', function() {
|
|
PreviewImage();
|
|
});
|
|
|
|
$("#insurer_general_form").submit(function(events) {
|
|
|
|
events.preventDefault();
|
|
|
|
// var isValid = $('#insurer_General_PrimaryKey').parsley().validate();
|
|
var isValid = $('#insurer_general_form').parsley().validate();
|
|
var PrimaryKey = $('#insurer_General_PrimaryKey').val();
|
|
if (!isValid) {
|
|
console.log('Form is Empty', 'Warning');
|
|
return ;
|
|
}
|
|
|
|
var formElement = $('#insurer_general_form')[0];
|
|
var formData = new FormData(formElement);
|
|
|
|
// DEBUG: Log formData to see if it's empty
|
|
for (var pair of formData.entries()) {
|
|
console.log(pair[0]+ ', ' + pair[1]);
|
|
}
|
|
if (isValid) {
|
|
|
|
if (PrimaryKey === '') {
|
|
form_action = '<?= base_url("master/insurer/createpost"); ?>';
|
|
} else {
|
|
form_action = '<?= base_url("master/insurer/edit"); ?>';
|
|
}
|
|
|
|
var formData = new FormData($('#insurer_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) {
|
|
setTimeout(function() {
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
}, 1000);
|
|
console.log(res);
|
|
$('#insurer_id').val(res.data.id);
|
|
$('#insurer_General_PrimaryKey').val(res.data.id);
|
|
$('#insurer_id_branch').val(res.data.id);
|
|
// $('#insurer_branch_contacts_id').click();
|
|
|
|
$('#btnBranchAdd').show();
|
|
var message = "Insurer General Info";
|
|
toastr.success(message, 'Success');
|
|
|
|
if (PrimaryKey === '') {
|
|
setTimeout(function(){
|
|
window.location.href = '<?= base_url('master/insurer/list/')?>' + res.data.id
|
|
}, 100)
|
|
}else{
|
|
window.location.reload();
|
|
}
|
|
|
|
},
|
|
error: function(xhr, status, error) {
|
|
console.error(xhr.responseText);
|
|
console.error(status, error);
|
|
$('.loader').fadeOut();
|
|
$('.loader-mask').delay(350).fadeOut('slow');
|
|
console.log('Something Wrong!', 'warning');
|
|
if (xhr.status === 400) {
|
|
let response = JSON.parse(xhr.responseText);
|
|
if (response.errors) {
|
|
$.each(response.errors, function (field, message) {
|
|
toastr.warning(message, 'Validation Error');
|
|
});
|
|
} else {
|
|
toastr.warning(response.message || 'Validation failed', 'Warning');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
function validateForm() {
|
|
var isValid = true;
|
|
|
|
// Perform validation for each field
|
|
$('#insurer_general_form input, #insurer_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 fileInput = document.getElementById("insurer_logo");
|
|
var preview = document.getElementById("uploadPreview");
|
|
var defaultAvatar = '<?= base_url() . "public/assets/images/avatar_2x.png" ?>';
|
|
|
|
// If no file is selected (or cleared by validation), reset preview and stop
|
|
if (!fileInput.files || !fileInput.files[0]) {
|
|
preview.src = defaultAvatar;
|
|
return;
|
|
}
|
|
|
|
var file = fileInput.files[0];
|
|
var fileName = file.name.toLowerCase();
|
|
var parts = fileName.split('.');
|
|
|
|
// VALIDATION: Extensions and Double Extensions (e.g. .php.jpeg)
|
|
var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i;
|
|
|
|
if (!allowedExtensions.exec(fileName) || parts.length > 2) {
|
|
toastr.error("Security violation: Invalid format or double extension.", "Blocked");
|
|
fileInput.value = ""; // Clear the field
|
|
preview.src = defaultAvatar; // RESET PREVIEW
|
|
return;
|
|
}
|
|
|
|
// VALIDATION: Size (200KB)
|
|
if ((file.size / 1024) > 200) {
|
|
toastr.warning("File size exceeds 200 KB limit.", "Warning");
|
|
fileInput.value = ""; // Clear the field
|
|
preview.src = defaultAvatar; // RESET PREVIEW
|
|
return;
|
|
}
|
|
|
|
// SUCCESS: Read and Preview
|
|
var oFReader = new FileReader();
|
|
oFReader.readAsDataURL(file);
|
|
oFReader.onload = function(oFREvent) {
|
|
preview.src = oFREvent.target.result;
|
|
};
|
|
}
|
|
//-----------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
</script>
|