557 lines
29 KiB
PHP
557 lines
29 KiB
PHP
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
@include('layouts.shared/title-meta', ['title' => 'Form'])
|
|
@include('layouts.shared/head-css', ['mode' => $mode ?? '', 'demo' => $demo ?? ''])
|
|
<link href="{{ asset('assets/libs/sweetalert2/sweetalert2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
<link href="{{ asset('assets/libs/select2/select2.min.css') }}" rel="stylesheet" type="text/css" />
|
|
</head>
|
|
<div id="pageloader">
|
|
<img src="http://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif" alt="processing..." />
|
|
</div>
|
|
|
|
<body class="loading">
|
|
<div class="account-pages">
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8 col-lg-6 col-xl-5 p-0">
|
|
<div class="card bg-pattern">
|
|
<div class="card-body p-3 row">
|
|
|
|
@if (Session::has('error'))
|
|
<div class="alert alert-danger">{{ Session::get('error') }}</div>
|
|
<br>
|
|
@endif
|
|
@if (session('success'))
|
|
<div class=" alert alert-success">{{ session('success') }}
|
|
</div>
|
|
<br>
|
|
@endif
|
|
<div class="col-8">
|
|
<h4 class="page-title">{{ $form->title }}</h4>
|
|
</div>
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="col-4">
|
|
@if ($form->link_type == 'form')
|
|
<a href="/form/history" class="float-end pt-1">View History</a>
|
|
@else
|
|
<a href="{{ url()->previous() }}" class="float-end pt-1">Back</a>
|
|
@endif
|
|
</div>
|
|
@endif
|
|
@if (isset($form->user_info))
|
|
<div class="col-12">
|
|
<h6>Submitted By: {{ $form->user_info->name }}</h6>
|
|
</div>
|
|
@endif
|
|
|
|
@php
|
|
$submissions = Formhelper::getMultiformData($form->partition, $form_id, $form->user_id);
|
|
$submissions = $submissions->data->submissions;
|
|
|
|
@endphp
|
|
|
|
<h1 id="submitted-msg" class="text-center" style="display:none;">
|
|
You have already submitted Doctors
|
|
</h1>
|
|
|
|
@if (count($submissions) <= 0)
|
|
|
|
|
|
<form method="POST" action="/form/submit" id="report-form"
|
|
enctype="multipart/form-data">
|
|
<input type="hidden" name="form_id" value="{{ $form_id }}">
|
|
<input type="hidden" name="user_id" value="{{$form->user_id}}">
|
|
@csrf
|
|
@if ($id)
|
|
<input type="hidden" name="id" value="{{ $id }}">
|
|
@endif
|
|
|
|
@foreach ($questions as $question)
|
|
@if (!in_array($question->code, ['select_month', 'record_date', 'select_emanzen_thursday_week']))
|
|
@continue;
|
|
@endif
|
|
<div class="col-md-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!}
|
|
</label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="1" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('textarea')
|
|
<textarea id="field-{{ $question->code }}" name="{{ $question->code }}" class="form-control"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>{{ isset($question->value) ? $question->value : '' }}</textarea>
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control" id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
|
|
<div class="col-md-12" id="doctor-wrapper-group">
|
|
<div class="doctor-wrapper row mt-3">
|
|
@foreach ($questions as $question)
|
|
@if (in_array($question->code, ['select_month', 'record_date', 'select_emanzen_thursday_week']))
|
|
@continue;
|
|
@endif
|
|
<div class="col-12 mb-2">
|
|
<label for="field-{{ $question->code }}"
|
|
class="form-label">{{ $question->question }}
|
|
{!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!} </label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" name="{{ $question->code }}[]"
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input type="{{ $question->type }}" name="{{ $question->code }}[]"
|
|
class="form-control {{ $question->type }}_{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input type="{{ $question->type }}" min="0" max="9999999999"
|
|
step="any" name="{{ $question->code }}[]"
|
|
class="form-control number_{{ $question->code }}"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}
|
|
value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control select_{{ $question->code }}"
|
|
{!!($question->code
|
|
== 'contact_id')?'data-toggle="select2"':'' !!}
|
|
id="field-{{ $question->code }}"
|
|
name="{{ $question->code }}[]"
|
|
{{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@if ($question->code == 'contact_id')
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
msl_code="{{ isset($option->contact->msl_code) ? $option->contact->msl_code : '' }}"
|
|
speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
@else
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}"
|
|
{{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>
|
|
{{ $option->display }}
|
|
</option>
|
|
@endforeach
|
|
@endif
|
|
</select>
|
|
@break
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>
|
|
</div>
|
|
|
|
@if (!isset($form->is_approval) || (isset($form->is_approval) && $form->is_approval != 'yes'))
|
|
<div class="text-center button-list row mt-3">
|
|
<div class="col-6 d-grid"><button class="btn btn-primary" type="submit"
|
|
id="submit-btn"> Submit </button></div>
|
|
<div class="col-6 d-grid"><button class="btn btn-warning" type="button"
|
|
id="adddoctor-btn"> Add Doctor </button></div>
|
|
</div>
|
|
@endif
|
|
</form>
|
|
@else
|
|
<h4 class="text-center">You have already submitted Doctors</h4>
|
|
|
|
@endif
|
|
</div> <!-- end card-body -->
|
|
</div>
|
|
<!-- end card -->
|
|
|
|
<!-- end row -->
|
|
|
|
</div> <!-- end col -->
|
|
</div>
|
|
<!-- end row -->
|
|
</div>
|
|
<!-- end container -->
|
|
</div>
|
|
<!-- end page -->
|
|
<style type="text/css">
|
|
#pageloader {
|
|
background: rgba(255, 255, 255, 0.8);
|
|
display: none;
|
|
height: 100%;
|
|
position: fixed;
|
|
width: 100%;
|
|
z-index: 9999;
|
|
}
|
|
|
|
#pageloader img {
|
|
left: 50%;
|
|
margin-left: -32px;
|
|
margin-top: -32px;
|
|
position: absolute;
|
|
top: 50%;
|
|
}
|
|
|
|
.doctor-wrapper {
|
|
border: 1px solid #ccc;
|
|
border-radius: 15px;
|
|
padding: 15px;
|
|
position: relative;
|
|
}
|
|
</style>
|
|
@include('layouts.shared/footer-script')
|
|
<script src="{{ asset('assets/libs/sweetalert2/sweetalert2.min.js') }}"></script>
|
|
<script src="{{ asset('assets/libs/select2/select2.min.js') }}"></script>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function($) {
|
|
let doctors = [];
|
|
@php
|
|
$hierarchies = [];
|
|
if(isset($form->users) && is_array($form->users)){
|
|
foreach($form->users as $user){
|
|
if(isset($user->hierarchy_id)){
|
|
$hierarchies[] = $user->hierarchy_id;
|
|
}
|
|
}
|
|
}
|
|
@endphp
|
|
|
|
// Get all hierarchies from PHP array
|
|
let allHierarchies = @json($hierarchies);
|
|
console.log(allHierarchies);
|
|
// Use Promise.all to load all doctors for each hierarchy
|
|
(async function() {
|
|
const responses = await Promise.all(
|
|
allHierarchies.map(function(hierarchy) {
|
|
return $.ajax({
|
|
type: "GET",
|
|
url: '/form/getdoctorlist?partition={{ $form->partition }}&hierarchy=' + hierarchy,
|
|
processData: false,
|
|
contentType: false
|
|
});
|
|
})
|
|
);
|
|
|
|
// Each response is an array of doctors
|
|
responses.forEach(function(data) {
|
|
if (data && Array.isArray(data)) {
|
|
doctors = doctors.concat(data);
|
|
}
|
|
});
|
|
|
|
// Now populate the #field-contact_id select with merged doctors
|
|
let $contactSelect = $('#field-contact_id');
|
|
if($contactSelect.length) {
|
|
$contactSelect.empty();
|
|
$contactSelect.append(
|
|
$('<option></option>').val('').text(' -- Select -- ')
|
|
);
|
|
doctors.forEach(function(itm) {
|
|
$contactSelect.append(
|
|
$("<option></option>")
|
|
.attr("speciality", itm.contact.speciality)
|
|
.attr("msl_code", itm.contact.msl_code)
|
|
.attr("value", itm.value)
|
|
.text(itm.display)
|
|
);
|
|
});
|
|
}
|
|
$('.select_contact_id').on('change', function() {
|
|
console.log('changed');
|
|
$(this).parent().parent().find('.text_speciality').val($("option:selected",
|
|
this).attr("speciality"))
|
|
$(this).parent().parent().find('.text_msl_code').val($("option:selected", this)
|
|
.attr("msl_code"))
|
|
})
|
|
|
|
})();
|
|
|
|
console.log(doctors);
|
|
|
|
|
|
$('[data-toggle="select2"]').select2();
|
|
|
|
var doctorformhtml = `<div class="doctor-wrapper row mt-3">
|
|
<div class="col-12">
|
|
<button type="button" class="btn btn-danger btn-remove float-end" style="position:absolute; right:0px; top:0px;"><i class="mdi mdi-close"></i></button>
|
|
</div>
|
|
@foreach ($questions as $question)
|
|
@if (in_array($question->code, ['select_month', 'record_date', 'select_emanzen_thursday_week']))
|
|
@continue;
|
|
@endif
|
|
<div class="col-12 mb-2">
|
|
<label for="field-{{ $question->code }}" class="form-label">{{ $question->question }} {!! $question->required == 'yes' ? '<span class="text-danger">*</span>' : '' !!} </label>
|
|
@switch($question->type)
|
|
@case('hidden')
|
|
<input type="{{ $question->type }}" name="{{ $question->code }}[]" value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('text')
|
|
@case('email')
|
|
|
|
@case('tel')
|
|
@case('date')
|
|
<input class="form-control text_{{ $question->code }}" type="{{ $question->type }}" name="{{ $question->code }}[]" class="form-control {{ $question->type }}_{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }} value="{{ isset($question->value) ? $question->value : '' }}">
|
|
@break
|
|
|
|
@case('number')
|
|
<input class="form-control number_{{ $question->code }}" type="{{ $question->type }}" min="0" max="9999999999" step="any" name="{{ $question->code }}[]" class="form-control number_{{ $question->code }}" {{ $question->required == 'yes' ? 'required' : '' }} value="{{ isset($question->value) ? $question->value : 0 }}">
|
|
@break
|
|
|
|
@case('dropdown')
|
|
<select class="form-control select_{{ $question->code }}" {!! $question->code == 'contact_id' ? 'data-toggle="select2"' : '' !!} name="{{ $question->code }}[]" {{ $question->required == 'yes' ? 'required' : '' }}>
|
|
<option value=""> -- Select -- </option>
|
|
@foreach ($question->options as $option)
|
|
<option value="{{ $option->value }}" speciality="{{ isset($option->contact->speciality) ? $option->contact->speciality : '' }}" msl_code="{{ isset($option->contact->msl_code) ? $option->contact->msl_code : '' }}" {{ isset($question->value) && $question->value == $option->value ? 'selected' : '' }}>{{ $option->display }}</option>
|
|
@endforeach
|
|
</select>
|
|
@break
|
|
|
|
@endswitch
|
|
</div>
|
|
@endforeach
|
|
</div>`
|
|
|
|
$(document).on('click', '#adddoctor-btn', function() {
|
|
// console.log(doctorformhtml)
|
|
$('#doctor-wrapper-group').append(doctorformhtml)
|
|
$('.btn-remove').unbind()
|
|
$('.btn-remove').click(function() {
|
|
$(this).parent().parent().remove()
|
|
})
|
|
|
|
for (let itm of doctors) {
|
|
$('#doctor-wrapper-group').children().last().find('.select_contact_id').append($(
|
|
"<option></option>").attr("speciality", itm.contact.speciality).attr(
|
|
"msl_code", itm.contact.msl_code).attr("value", itm.value).text(itm
|
|
.display));
|
|
}
|
|
|
|
//$('.select_contact_id').unbind()
|
|
$('.select_contact_id').on('change', function() {
|
|
console.log('changed');
|
|
$(this).parent().parent().find('.text_speciality').val($("option:selected",
|
|
this).attr("speciality"))
|
|
$(this).parent().parent().find('.text_msl_code').val($("option:selected", this)
|
|
.attr("msl_code"))
|
|
})
|
|
|
|
$('.text_speciality,.text_msl_code').prop('readonly', 'true');
|
|
$('[data-toggle="select2"]').select2();
|
|
})
|
|
|
|
$('#report-form').on('submit', function(event) {
|
|
event.preventDefault();
|
|
let numberOfSubmission = $('#doctor-wrapper-group').children().length;
|
|
if (numberOfSubmission < 30) {
|
|
event.preventDefault();
|
|
alert(
|
|
`Minimum 30 submissions required to submit the form. Currently you have only selected ${numberOfSubmission} doctors`);
|
|
return false;
|
|
}
|
|
if (numberOfSubmission > 50) {
|
|
event.preventDefault();
|
|
alert(
|
|
`You can at most select 50 doctors at a time ! Currently You have selected ${numberOfSubmission} doctors`);
|
|
return false;
|
|
}
|
|
$('.doctor-wrapper').each(function(index) {
|
|
for (let ques of ["record_date", "select_rehab_tuesday_week"]) {
|
|
$('#report-form').append('<input type="hidden" name="' + ques +
|
|
'[]" value="' + $('#field-' + ques).val() + '">')
|
|
}
|
|
});
|
|
|
|
$("#pageloader").fadeIn();
|
|
$.ajax({
|
|
type: "POST",
|
|
url: '/form/ajaxsubmitmultiple',
|
|
data: new FormData($('#report-form')[0]),
|
|
processData: false,
|
|
contentType: false,
|
|
success: function(data) {
|
|
$("#pageloader").fadeOut();
|
|
if (data.status == 'success') {
|
|
Swal.fire({
|
|
title: 'Great!',
|
|
text: 'Your data is successfully submitted!',
|
|
icon: 'success'
|
|
}).then((result) => {
|
|
if (result.isConfirmed) {
|
|
// ✅ div hide
|
|
$('#report-form').hide();
|
|
|
|
// ✅ h1 show
|
|
$('#submitted-msg').show();
|
|
|
|
// optional: form reset
|
|
$('#report-form').trigger("reset");
|
|
}
|
|
});
|
|
$('#report-form').trigger("reset");
|
|
} else {
|
|
Swal.fire({
|
|
icon: 'error',
|
|
title: 'Data not submitted',
|
|
text: 'Something went wrong, please try again after some time!'
|
|
})
|
|
}
|
|
},
|
|
});
|
|
});
|
|
|
|
var today = new Date();
|
|
var dd = String(today.getDate()).padStart(2, '0');
|
|
var mm = String(today.getMonth() + 1).padStart(2, '0');
|
|
var yyyy = today.getFullYear();
|
|
today = yyyy + '-' + mm + '-' + dd;
|
|
|
|
var plandateField = document.getElementById('field-record_date');
|
|
|
|
plandateField.setAttribute('max', today);
|
|
});
|
|
</script>
|
|
|
|
<script>
|
|
/**
|
|
* Sync contact dropdown options to newly added doctor wrappers
|
|
* WITHOUT changing existing code
|
|
*/
|
|
$(document).on('click', '#adddoctor-btn', function () {
|
|
|
|
// Wait till wrapper is appended by existing code
|
|
setTimeout(function () {
|
|
|
|
let $source = $('#field-contact_id');
|
|
let $newWrapper = $('#doctor-wrapper-group').children().last();
|
|
let $target = $newWrapper.find('.select_contact_id');
|
|
|
|
if ($source.length && $target.length) {
|
|
|
|
// Clear existing options
|
|
$target.empty();
|
|
|
|
// Clone all options from main contact dropdown
|
|
$source.find('option').each(function () {
|
|
$target.append($(this).clone());
|
|
});
|
|
}
|
|
|
|
}, 0);
|
|
|
|
});
|
|
</script>
|
|
<script>
|
|
/**
|
|
* Prevent selecting same doctor in multiple wrappers
|
|
*/
|
|
function syncDoctorSelections() {
|
|
|
|
let selectedDoctors = [];
|
|
|
|
// Collect all selected doctor IDs
|
|
$('.select_contact_id').each(function () {
|
|
let val = $(this).val();
|
|
if (val) {
|
|
selectedDoctors.push(val);
|
|
}
|
|
});
|
|
|
|
// Disable selected doctors in other dropdowns
|
|
$('.select_contact_id').each(function () {
|
|
let currentVal = $(this).val();
|
|
|
|
$(this).find('option').each(function () {
|
|
let optionVal = $(this).val();
|
|
|
|
if (!optionVal) return; // skip placeholder
|
|
|
|
if (selectedDoctors.includes(optionVal) && optionVal !== currentVal) {
|
|
$(this).prop('disabled', true);
|
|
} else {
|
|
$(this).prop('disabled', false);
|
|
}
|
|
});
|
|
|
|
// Refresh Select2 if applied
|
|
if ($(this).hasClass("select2-hidden-accessible")) {
|
|
$(this).trigger('change.select2');
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Bind change event (works for dynamically added wrappers)
|
|
*/
|
|
$(document).on('change', '.select_contact_id', function () {
|
|
syncDoctorSelections();
|
|
});
|
|
|
|
/**
|
|
* Run after adding a new doctor wrapper
|
|
*/
|
|
$(document).on('click', '#adddoctor-btn', function () {
|
|
setTimeout(function () {
|
|
syncDoctorSelections();
|
|
}, 0);
|
|
});
|
|
|
|
/**
|
|
* Run after removing a wrapper
|
|
*/
|
|
$(document).on('click', '.btn-remove', function () {
|
|
setTimeout(function () {
|
|
syncDoctorSelections();
|
|
}, 0);
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|