353 lines
13 KiB
PHP
353 lines
13 KiB
PHP
|
<style type="text/css">
|
||
|
label.error {
|
||
|
color : red;
|
||
|
text-align: left;
|
||
|
display: block;
|
||
|
}
|
||
|
#room_name_err {
|
||
|
color : red;
|
||
|
text-align: center;
|
||
|
}
|
||
|
|
||
|
</style>
|
||
|
<div class="row dash-main-row">
|
||
|
<div class="col-md-10 col-lg-10 p-0">
|
||
|
<ul class="nav nav-pills mb-3 rooms-sections row" id="pills-tab" role="tablist">
|
||
|
<li class="nav-item section-sec col-md-3 p-0">
|
||
|
<a class="nav-link sec-head " href="<?php echo base_url() ?>blocks" role="tab" aria-controls="pills-blocks" aria-selected="true">Blocks</a>
|
||
|
</li>
|
||
|
<li class="nav-item section-sec col-md-3 p-0">
|
||
|
<a class="nav-link sec-head active" href="<?php echo base_url() ?>floors" aria-selected="false">Floors</a>
|
||
|
</li>
|
||
|
<li class="nav-item section-sec col-md-3 p-0">
|
||
|
<a class="nav-link sec-head" href="<?php echo base_url() ?>rooms" aria-selected="false">Rooms</a>
|
||
|
</li>
|
||
|
<li class="nav-item section-sec col-md-3 p-0">
|
||
|
<a class="nav-link sec-head" href="<?php echo base_url() ?>beds" aria-selected="false">Beds</a>
|
||
|
</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div class="row dash-main-row">
|
||
|
<div class="col-md-12 col-lg-12 p-0">
|
||
|
|
||
|
<?php if ($this->session->flashdata('success')) { ?>
|
||
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||
|
<p><?php echo $this->session->flashdata('success') ?></p>
|
||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||
|
<span aria-hidden="true">×</span>
|
||
|
</button>
|
||
|
</div>
|
||
|
<?php } ?>
|
||
|
|
||
|
<?php if ($this->session->flashdata('failed')) { ?>
|
||
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||
|
<p><?php echo $this->session->flashdata('failed') ?></p>
|
||
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||
|
<span aria-hidden="true">×</span>
|
||
|
</button>
|
||
|
</div>
|
||
|
<?php } ?>
|
||
|
|
||
|
<table class="table example dash-table mt-3 text-center">
|
||
|
<thead>
|
||
|
<tr>
|
||
|
<th scope="col" class="dash-th">SI.No</th>
|
||
|
<th scope="col" class="dash-th">Floor Name</th>
|
||
|
<th scope="col" class="dash-th rooms-th">Block</th>
|
||
|
<th scope="col" class="dash-th rooms-th">Rooms</th>
|
||
|
<th scope="col" class="dash-th rooms-th">Total Beds</th>
|
||
|
<th scope="col" class="dash-th rooms-th">Total Students</th>
|
||
|
<th scope="col" class="dash-th-action">Actions</th>
|
||
|
</tr>
|
||
|
</thead>
|
||
|
<tfoot class="text-center">
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</tfoot>
|
||
|
<tbody>
|
||
|
<?php foreach ($floors_data as $key => $value) { ?>
|
||
|
<tr>
|
||
|
<td ><?php echo $key + 1 ?></td>
|
||
|
<td><?= $value['floor_name'] ?></td>
|
||
|
<td class="rooms-td"><?= $value['block_name'] ?></td>
|
||
|
<td class="rooms-td"><?= $value['room_count'] ?></td>
|
||
|
<td class="rooms-td"><?= $value['beds_count'] ?></td>
|
||
|
<td class="rooms-td"><?= $value['student_count']?></td>
|
||
|
<td class="preview-img">
|
||
|
<img class="action-img" onClick="set_floor_id(<?= $value['id'] ?>)" src="<?= base_url() ?>assets-hms/images/dashboard/edit-icon.svg" data-backdrop="static" data-keyboard="false" data-toggle="modal" data-target="#EditFloorsCenter" alt="">
|
||
|
|
||
|
<a data-toggle="DeleteRoomsCenter" onclick ="floordel(<?php echo $value['id'] ?>)" href="#deleteModal">
|
||
|
<img src="<?= base_url() ?>assets-hms/images/dashboard/delete-icon.svg" alt="" data-toggle="modal" data-target="#DeleteRoomsCenter" data-backdrop="static" data-keyboard="false">
|
||
|
</a>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<?php } ?>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<!-- Modal -->
|
||
|
<div class="modal fade" id="EditFloorsCenter" tabindex="-1" role="dialog" aria-labelledby=" EditFloorsCenterTitle" aria-hidden="true">
|
||
|
|
||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||
|
|
||
|
<div class="modal-content">
|
||
|
|
||
|
<div class="modal-header add-block-header">
|
||
|
<h5 class="modal-title" id="exampleModalLongTitle">Edit Floors</h5>
|
||
|
|
||
|
</div>
|
||
|
<form method="post" id="floor-edit-form">
|
||
|
|
||
|
<div class="modal-body add-block-body room-modal-body">
|
||
|
<p>Block Name</p>
|
||
|
<input type="text" id="block_name" placeholder="1st Block" class="form-control add-block-input" readonly>
|
||
|
<p>Floor Name</p>
|
||
|
<input type="text" id="floor_name" placeholder="1st Floor" class="form-control add-block-input" readonly>
|
||
|
|
||
|
<!-- <input type="hidden" name="floor_id" id="floor_id">
|
||
|
<input type="hidden" name="block_id" id="block_id"> -->
|
||
|
<div class="edit-floor-titles">
|
||
|
<div class="d-flex" style="width: 90%;">
|
||
|
<p>Add Room</p>
|
||
|
<i onclick="addInputField()" class="fas fa-plus add-icon"></i>
|
||
|
</div>
|
||
|
<p>A/C</p>
|
||
|
</div>
|
||
|
|
||
|
<div class="room-container">
|
||
|
<div class="edit-floor-main-div">
|
||
|
<div class="edit-floor-input">
|
||
|
<div class="edit-floor-left">
|
||
|
<input type="text" placeholder="A101" class="form-control add-input edit-floors-input room-names">
|
||
|
</div>
|
||
|
<div class="edit-floor-right">
|
||
|
<input type="checkbox" name="ac[]" class="form-check-input edit-floor-checkbox" id="exampleCheck1">
|
||
|
<img class="edit-delete-icon" onClick="deleteInput(this)" src="<?= base_url() ?>assets-hms/images/dashboard/delete-icon.svg" alt="">
|
||
|
</div>
|
||
|
</div>
|
||
|
<label id="room_names[0]-error" class="error" for="room_names[0]"></label>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="room_name_err"></div>
|
||
|
|
||
|
<div class="modal-footer add-block-footer">
|
||
|
<button type="submit" class="btn btn-primary add-block-blue">Update</button>
|
||
|
<button type="button" class="btn btn-secondary add-block-cancel" data-dismiss="modal">Cancel</button>
|
||
|
</div>
|
||
|
|
||
|
</form>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<!-- Delete Modal -->
|
||
|
<div class="modal fade" id="DeleteRoomsCenter" tabindex="-1" role="dialog" aria-labelledby="DeleteRoomsCenterTitle" aria-hidden="true">
|
||
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||
|
<div class="modal-content">
|
||
|
<div class="modal-header add-block-header">
|
||
|
<h5 class="modal-title" id="exampleModalLongTitle">Delete Floor</h5>
|
||
|
</div>
|
||
|
|
||
|
<div class="modal-body add-block-body">
|
||
|
<input type="hidden" id="floor_id" />
|
||
|
<h6>Are you sure you want to delete ?</h6>
|
||
|
</div>
|
||
|
|
||
|
<div class="modal-footer add-block-footer">
|
||
|
<button type="button" onclick="deletedata($('#floor_id').val());" class="btn btn-danger ">Yes</button>
|
||
|
<button type="button" class="btn btn-dark " data-dismiss="modal">No</button>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<script>
|
||
|
let floor_id;
|
||
|
let idCount = 0;
|
||
|
$(document).ready(function() {
|
||
|
|
||
|
$('.add-input').each(function(index,ele) {
|
||
|
$(ele).attr('name', 'room_names['+idCount+']');
|
||
|
idCount++;
|
||
|
});
|
||
|
|
||
|
$('.example').DataTable( {
|
||
|
initComplete: function () {
|
||
|
this.api().columns([1, 2, 3]).every( function () {
|
||
|
var column = this;
|
||
|
var select = $('<select><option value="">Filter</option></select>')
|
||
|
.appendTo( $(column.footer()).empty() )
|
||
|
.on( 'change', function () {
|
||
|
var val = $.fn.dataTable.util.escapeRegex(
|
||
|
$(this).val()
|
||
|
);
|
||
|
|
||
|
column
|
||
|
.search( val ? '^'+val+'$' : '', true, false )
|
||
|
.draw();
|
||
|
} );
|
||
|
|
||
|
column.data().unique().sort().each( function ( d, j ) {
|
||
|
select.append( '<option value="'+d+'">'+d+'</option>' )
|
||
|
} );
|
||
|
} );
|
||
|
}
|
||
|
} );
|
||
|
|
||
|
})
|
||
|
|
||
|
const set_floor_id = (id) => {
|
||
|
floor_id = id;
|
||
|
}
|
||
|
|
||
|
const addInputField = () => {
|
||
|
|
||
|
let checkForAdd = $('.room-names').length;
|
||
|
|
||
|
let inputContainer = '<div class="edit-floor-main-div"><div class="edit-floor-input mt-3"><div class="edit-floor-left"><input type="text" placeholder="Enter Room Name" name="room_names['+checkForAdd+']" class="form-control room-names add-input edit-floors-input"></div><div class="edit-floor-right"><input type="checkbox" class="form-check-input edit-floor-checkbox" name="ac[]" id="exampleCheck1"><img class="edit-delete-icon" onClick="deleteInput(this)" src="<?= base_url() ?>assets-hms/images/dashboard/delete-icon.svg" alt=""></div></div><label id="room_names['+checkForAdd+']-error" class="error" for="room_names['+checkForAdd+']"></label></div>';
|
||
|
|
||
|
|
||
|
$('.room-container').append(inputContainer);
|
||
|
idCount++;
|
||
|
}
|
||
|
|
||
|
|
||
|
function floordel(icn){
|
||
|
$('#floor_id').val(icn);
|
||
|
}
|
||
|
|
||
|
//
|
||
|
function deletedata(id){
|
||
|
window.location.href = "<?php echo base_url(); ?>HmsAdmin/delete_floors/" + id;
|
||
|
}
|
||
|
|
||
|
const deleteInput = (ele) => {
|
||
|
$(ele).parent().parent().parent().remove();
|
||
|
}
|
||
|
|
||
|
const deleteInputFromDb = (ele,room_id) => {
|
||
|
$(ele).parent().parent().parent().remove();
|
||
|
|
||
|
$.ajax({
|
||
|
url : '<?php echo base_url() ?>' + 'HmsAdmin/ajax_delete_rooms',
|
||
|
data : {
|
||
|
id : room_id
|
||
|
},
|
||
|
type : 'POST',
|
||
|
async : false,
|
||
|
success: function(data){
|
||
|
if(data){
|
||
|
$(ele).parent().remove();
|
||
|
} else {
|
||
|
$('#floor_name_err').text('Floor could not be deleted as it is linked with rooms');
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
// Before Modal Event
|
||
|
$("#EditFloorsCenter").on('show.bs.modal', function(){
|
||
|
$('.room-container').empty();
|
||
|
|
||
|
$.ajax({
|
||
|
url : '<?php echo base_url() ?>' + 'HmsAdmin/ajax_get_floor_rooms_info',
|
||
|
data : {
|
||
|
id : floor_id
|
||
|
},
|
||
|
type : 'POST',
|
||
|
async : false,
|
||
|
success: function(data){
|
||
|
|
||
|
if(!data) {
|
||
|
$('.room-container').empty();
|
||
|
$('.room-container').append('<p>Data could not be displayed due to some error. Please try again later</p>');
|
||
|
} else {
|
||
|
data = JSON.parse(data);
|
||
|
$('#block_name').val(data.block_name);
|
||
|
$('#floor_name').val(data.floor_name);
|
||
|
$('.room-container').append(data.rooms);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
|
//
|
||
|
jQuery.validator.addMethod("alphanumeric", function(value, element) {
|
||
|
return this.optional(element) || /^[a-z0-9\-\s]+$/i.test(value);
|
||
|
}, "Please enter alphanumeric Characters only");
|
||
|
|
||
|
// Edit Form Validation
|
||
|
$("#floor-edit-form").validate({
|
||
|
ignore: ':hidden',
|
||
|
rules: {
|
||
|
<?php for($i = 0; $i <= 20; $i++) {
|
||
|
echo "'room_names[$i]' : {
|
||
|
required : true,
|
||
|
alphanumeric : true
|
||
|
},";
|
||
|
}?>
|
||
|
|
||
|
},
|
||
|
submitHandler: function(form,e) {
|
||
|
|
||
|
e.preventDefault();
|
||
|
$(form).attr('action', "<?php echo base_url() ?>HmsAdmin/ae_rooms/"+floor_id);
|
||
|
let flag = false
|
||
|
let room_inputs = $('.room-names');
|
||
|
let room_names = [];
|
||
|
$(room_inputs).each(function(index,ele) {
|
||
|
let val = $(ele).val().toLowerCase();
|
||
|
room_names.push(val);
|
||
|
})
|
||
|
|
||
|
|
||
|
|
||
|
let findDuplicates = arr => arr.filter((item, index) => arr.indexOf(item) != index)
|
||
|
|
||
|
let dubArr = [...new Set(findDuplicates(room_names))] // Unique duplicates
|
||
|
|
||
|
if(dubArr.length > 0) {
|
||
|
$('#room_name_err').text(dubArr.toString() + ' have been repeated, please change');
|
||
|
} else {
|
||
|
flag = true;
|
||
|
}
|
||
|
|
||
|
$('.form-check-input').each(function(index,ele) {
|
||
|
if($(ele).prop('checked')){
|
||
|
$(this).val('A/C');
|
||
|
} else {
|
||
|
$(this).val('NON-A/C');
|
||
|
}
|
||
|
|
||
|
$(ele).prop('checked', true);
|
||
|
})
|
||
|
|
||
|
if(flag) {
|
||
|
form.submit();
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
</script>
|