Viewing file: editTermConfig.php (10.84 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<div id="modalDel" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header flex-column">
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
<div class="icon-box">
<i class="bi-x-circle" style="color:red; font-size:70px;"></i>
</div><br />
<h4 class="modal-title text-center">Are you sure?</h4>
</div>
<div class="modal-body text-center">
<p>ต้องการลบข้อมูลนี้ใช่หรือไม่</p>
<form method="post" name="delForm" id="delForm">
<input type="hidden" name="tmcAcY" id="tmcAcY" />
<input type="hidden" name="tmcTmId" id="tmcTmId" />
<input type="hidden" class="form-control" name="action" value="deleteTmc" />
</form>
</div>
<div class="modal-footer justify-content-center">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="button" id="btnConfirmDel" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</div>
<div class="modal" id="editTmc" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">แก้ไขข้อมูล</h5>
<button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="container">
<form method="post" name="editTmcForm" id="editTmcForm" action="javascript:updateTmc();" class="row g-3 needs-validation" novalidate>
<input type="hidden" class="form-control" name="action" value="updateTmc" />
<input type="hidden" class="form-control" name="tmcTmId" id="tmcTmId" />
<div class="col-md-6">
<div class="input-group">
<label for="inputGroup01" class="input-group-text">ปีการศึกษา</label>
<input type="number" class="form-control" name="tmcAcY" id="tmcAcY" readonly />
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<label for="inputGroupSelect02" class="input-group-text">ภาคการศึกษา</label>
<select class="form-select" name="tmcTmIdSelect" id="tmcTmIdSelect" disabled>
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Term";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->tmId . "'>" . $data->tmName . "</option>";
}
?>
</select>
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<label for="inputGroup01" class="input-group-text">วันที่เริ่มต้น</label>
<input type="date" class="form-control" name="tmcFrDate" id="tmcFrDate" required />
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-6">
<div class="input-group">
<label for="inputGroup02" class="input-group-text">วันที่สิ้นสุด</label>
<input type="date" class="form-control" name="tmcToDate" id="tmcToDate" required />
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-12" style="text-align: center;">
<button type="submit" id="btnUpdateSubmit" class="btn btn-primary">Update</button>
<!--<button type="submit" class="btn btn-primary">Save</button>-->
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<!--<button type="submit" id="btnUpdateSubmit" class="btn btn-primary">Save</button>-->
</div>
</div>
</div>
</div>
<div class="container">
<p class="fs-3">แก้ไขข้อมูลปีการศึกษา</p>
<table id="tmcList" class="table table-striped display" style="width:100%">
<thead>
<tr>
<th>ปีการศึกษา</th>
<th>ภาคการศึกษา</th>
<th>วันที่เริ่มต้น</th>
<th>วันที่สิ้นสุด</th>
<th>ดำเนินการ</th>
</tr>
</thead>
<tfoot>
<tr>
<th>ปีการศึกษา</th>
<th>ภาคการศึกษา</th>
<th>วันที่เริ่มต้น</th>
<th>วันที่สิ้นสุด</th>
<th>ดำเนินการ</th>
</tr>
</tfoot>
</table>
</div>
<!-- Bootstrap JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.12.1/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script>
$(document).ready(function() {
getDataAll();
get();
delTmc();
$(document).delegate("[data-target='#modalDel']", "click", function() {
$("#delForm [name=\"tmcAcY\"]").val($(this).attr('data-id'));
$("#delForm [name=\"tmcTmId\"]").val($(this).attr('data-id2'));
})
});
function getDataAll() {
$('#tmcList').DataTable({
processing: true,
"ordering": false,
ajax: {
url: "api/termConfig.php",
data: {
action: "getTmcAll"
},
dataSrc: 'data'
},
columnDefs: [{
targets: [0, 1, 2, 3, 4],
className: 'text-center'
},
{
"width": "15%",
"targets": 4
}
],
columns: [{
data: "tmcAcY"
},
{
data: "tmName"
},
{
data: "tmcFrDate"
},
{
data: "tmcToDate"
},
{
data: "opt"
},
],
});
}
function get() {
$(document).delegate("[data-target='#editTmc']", "click", function() {
var tmcAcY = $(this).attr('data-id');
var tmcTmId = $(this).attr('data-id2');
// Ajax config
$.ajax({
type: "GET", //we are using GET method to get data from server side
url: './api/termConfig.php', // get the route value
data: {
tmcAcY: tmcAcY,
tmcTmId: tmcTmId,
action: "getTmcById"
}, //set data
beforeSend: function() { //We add this before send to disable the button once we submit it so that we prevent the multiple click
},
success: function(response) { //once the request successfully process to the server side it will return result here
response = JSON.parse(response);
$("#editTmcForm [name=\"tmcAcY\"]").val(response.tmcAcY);
$("#editTmcForm [name=\"tmcTmId\"]").val(response.tmcTmId);
$("#editTmcForm [name=\"tmcTmIdSelect\"]").val(response.tmcTmId);
$("#editTmcForm [name=\"tmcFrDate\"]").val(response.tmcFrDate);
$("#editTmcForm [name=\"tmcToDate\"]").val(response.tmcToDate);
}
});
});
}
function updateTmc() {
var $this = $("#btnUpdateSubmit"); //submit button selector using ID
var $caption = $this.html(); // We store the html content of the submit button
var form = "#editTmcForm"; //defined the #form ID
var formData = $(form).serializeArray(); //serialize the form into array
//var route = $(form).attr('action'); //get the route using attribute action
var route = "./api/termConfig.php";
// Ajax config
$.ajax({
type: "POST", //we are using POST method to submit the data to the server side
url: route, // get the route value
data: formData, // our serialized array data for server side
beforeSend: function() { //We add this before send to disable the button once we submit it so that we prevent the multiple click
$this.attr('disabled', true).html("Processing...");
},
success: function(response) { //once the request successfully process to the server side it will return result here
$this.attr('disabled', false).html($caption);
// Reload lists of employees
//getDataAll();
//window.location.href='./?page=editCurriculum';
//$('#courseList').DataTable().ajax.reload();
$('#tmcList').DataTable().destroy();
getDataAll();
// We will display the result using alert
alert(response);
// Reset form
//resetForm(form);
// Close modal
$(".modal-backdrop").remove();
$('#editTmc').modal().toggle();
},
});
}
function delTmc() {
$("#btnConfirmDel").on("click", function() {
var $this = $(this); //submit button selector using ID
var $caption = $this.html(); // We store the html content of the submit button
var form = "#delForm"; //defined the #form ID
var formData = $(form).serializeArray(); //serialize the form into array
//var route = $(form).attr('action'); //get the route using attribute action
var route = "./api/delTmcData.php";
// Ajax config
$.ajax({
type: "POST", //we are using POST method to submit the data to the server side
url: route, // get the route value
data: formData, // our serialized array data for server side
beforeSend: function() { //We add this before send to disable the button once we submit it so that we prevent the multiple click
$this.attr('disabled', true).html("Processing...");
},
success: function(response) { //once the request successfully process to the server side it will return result here
$this.attr('disabled', false).html($caption);
// Reload lists of employees
$('#tmcList').DataTable().destroy();
getDataAll();
// We will display the result using alert
alert(response);
// Reset form
//resetForm(form);
// Close modal
$(".modal-backdrop").remove();
$('#modalDel').modal().toggle();
},
});
});
}
(() => {
'use strict'
// Fetch all the forms we want to apply custom Bootstrap validation styles to
const forms = document.querySelectorAll('.needs-validation')
// Loop over them and prevent submission
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
form.classList.add('was-validated')
}, false)
})
})()
</script>
|