Viewing file: curMapping.php (14.45 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!-- Modal Delete -->
<div id="modalDelCm" class="modal">
<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="delCmForm" id="delCmForm">
<input type="hidden" name="pcrCsCurId" id="pcrCsCurId" />
<input type="hidden" name="pcrCsCdId1" id="pcrCsCdId1" />
<input type="hidden" name="pcrCsCdId2" id="pcrCsCdId2" />
<input type="hidden" name="pcrCrsId" id="pcrCrsId" />
<input type="hidden" name="action" value="deleteCm" />
</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>
<!-- Modal Success -->
<div id="modalSuccess" class="modal">
<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 bi-check-circle-fill" style="color:green; font-size:70px;"></i>
</div><br />
<h4 class="modal-title text-center">Success</h4>
</div>
<div class="modal-body text-center">
<p>ดำเนินการสำเร็จ</p>
</div>
<div class="modal-footer justify-content-center">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal" id="modalAddCm" 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">เพิ่ม Mapping รายวิชา-หลักสูตร</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="addCmForm" id="addCmForm" action="javascript:insertCm();" class="row g-3 needs-validation" novalidate>
<input type="hidden" name="action" value="insertCm" />
<input type="hidden" class="form-control" name="pcrCsCurId" id="pcrCsCurId" />
<input type="hidden" class="form-control" name="pcrCsCdId1" id="pcrCsCdId1" />
<input type="hidden" class="form-control" name="pcrCsCdId2" id="pcrCsCdId2" />
<div class="col-md-12">
<div class="input-group">
<label for="inputGroupSelect01" class="input-group-text">หลักสูตร</label>
<select class="form-select" name="curId" id="curId" disabled>
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Curriculum WHERE curStatus = 'Y'";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->curId . "'>" . $data->curName . "</option>";
}
?>
</select>
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-group">
<label for="inputGroupSelect01" class="input-group-text">หมวดวิชาหลัก</label>
<select class="form-select" name="cdId1" id="cdId1" disabled>
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Condition";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->cdId . "'>" . $data->cdName . "</option>";
}
?>
</select>
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-12">
<div class="input-group">
<label for="inputGroupSelect02" class="input-group-text">หมวดวิชาย่อย</label>
<select class="form-select" name="cdId2" id="cdId2" disabled>
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Condition";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->cdId . "'>" . $data->cdName . "</option>";
}
?>
</select>
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-10">
<div class="input-group">
<label for="inputGroupSelect02" class="input-group-text">รายวิชา</label>
<select class="form-select" name="pcrCrsIdSelect" id="pcrCrsIdSelect" required>
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Course";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->crsId . "'>" . $data->crsCode . " " . $data->crsName . "</option>";
}
?>
</select>
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-2">
<div class="input-group">
<label for="inputGroup01" class="input-group-text">เกรดขั้นต่ำ</label>
<input type="text" class="form-control" name="pcrMinGrade" id="pcrMinGrade" required />
<div class="invalid-feedback">
กรุณากรอกข้อมูลให้ถูกต้อง
</div>
</div>
</div>
<div class="col-md-12" style="text-align: center;">
<button type="submit" id="btnAddCmSubmit" class="btn btn-primary">Save</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>
</div>
</div>
</div>
</div>
<div class="container">
<p class="fs-3">Mapping รายวิชาหลักสูตร</p>
<fieldset class="border p-2">
<legend class="float-none w-auto p-2">เลือกหลักสูตร</legend>
<div class="col-md-12">
<div class="input-group">
<label for="inputGroupSelect01" class="input-group-text">หลักสูตร</label>
<select class="form-select" name="curSelect" id="curSelect">
<option selected disabled value="">-- เลือก --</option>
<?php
$sql = "SELECT * FROM rg_Curriculum WHERE curStatus = 'Y'";
$link->query($sql);
while ($data = $link->getnext()) {
echo "<option value='" . $data->curId . "'>" . $data->curName . "</option>";
}
?>
</select>
</div>
</div><br />
</fieldset><br />
<table id="cmList" class="table table-striped display" style="width:100%">
<thead>
<tr>
<th class="text-center">ลำดับที่</th>
<th class="text-center">หมวดวิชาหลัก</th>
<th class="text-center">หมวดวิชาย่อย</th>
<th class="text-center">หน่วยกิต</th>
<th class="text-center">จัดการ</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="text-center">ลำดับที่</th>
<th class="text-center">หมวดวิชาหลัก</th>
<th class="text-center">หมวดวิชาย่อย</th>
<th class="text-center">หน่วยกิต</th>
<th class="text-center">จัดการ</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() {
$('#pcrCrsIdSelect').select2({
dropdownParent: $('#modalAddCm'),
theme: "bootstrap-5",
width: $(this).data('width') ? $(this).data('width') : $(this).hasClass('w-100') ? '100%' : 'style',
placeholder: $(this).data('placeholder'),
});
if (!$("#curSelect").val()) {
$('#cmList').hide();
}
$("#curSelect").change(function() {
$('#cmList').show();
$('#cmList').DataTable().destroy();
getCmByCur();
})
$(document).delegate("[data-target='#modalDelCm']", "click", function() {
$("#delCmForm [name=\"pcrCsCurId\"]").val($(this).attr('data-id'));
$("#delCmForm [name=\"pcrCsCdId1\"]").val($(this).attr('data-id2'));
$("#delCmForm [name=\"pcrCsCdId2\"]").val($(this).attr('data-id3'));
$("#delCmForm [name=\"pcrCrsId\"]").val($(this).attr('data-id4'));
})
getAddDataCm();
delCm();
});
function resetForm(selector) {
$(selector)[0].reset();
}
function getCmByCur() {
var curId = $("#curSelect").val();
$('#cmList').DataTable({
processing: true,
"ordering": false,
ajax: {
type: "GET",
url: "api/curriculumMapping.php",
data: {
curId: curId,
action: "getCmByCurId"
},
dataSrc: 'data'
},
columnDefs: [{
targets: [0, 3, 4],
className: 'text-center'
},
{
"width": "45%",
"targets": 2
},
{
"width": "20%",
"targets": 1
}
],
columns: [{
data: "csSeq"
},
{
data: "cdName1"
},
{
data: "cdName2"
},
{
data: "csCreditTotal"
},
{
data: "opt"
},
],
});
}
function getAddDataCm() {
$(document).delegate("[data-target='#modalAddCm']", "click", function() {
var pcrCsCurId = $(this).attr('data-id');
var pcrCsCdId1 = $(this).attr('data-id2');
var pcrCsCdId2 = $(this).attr('data-id3');
$("#addCmForm [name=\"pcrCsCurId\"]").val(pcrCsCurId);
$("#addCmForm [name=\"pcrCsCdId1\"]").val(pcrCsCdId1);
$("#addCmForm [name=\"pcrCsCdId2\"]").val(pcrCsCdId2);
$("#addCmForm [name=\"curId\"]").val(pcrCsCurId);
$("#addCmForm [name=\"cdId1\"]").val(pcrCsCdId1);
$("#addCmForm [name=\"cdId2\"]").val(pcrCsCdId2);
});
}
function delCm() {
$("#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 = "#delCmForm"; //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/curriculumMapping.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
$('#cmList').DataTable().destroy();
getCmByCur();
// We will display the result using alert
alert(response);
// Reset form
//resetForm(form);
// Close modal
$(".modal-backdrop").remove();
$('#modalDelCm').modal().toggle();
},
});
});
}
function insertCm() {
var $this = $("#btnAddCmSubmit"); //submit button selector using ID
var $caption = $this.html(); // We store the html content of the submit button
var form = "#addCmForm"; //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/curriculumMapping.php";
//alert("call insert function");
// 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';
//$('#curStrucList').DataTable().ajax.reload();
$('#cmList').DataTable().destroy();
getCmByCur();
// We will display the result using alert
alert(response);
// Reset form
//resetForm(form);
// Close modal
//$('#addCurStruc').modal().hide();
$(".modal-backdrop").remove();
$('#modalAddCm').modal().toggle();
//$(".modal-backdrop").remove();
},
});
}
(() => {
'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>
|