📁 File Manager
Editing:
/home/wedigitalindia/public_html/demo.wedigitalindia.com/dcl-erp/leave.php
<?php include_once("include/head.php"); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); ?> <div class="main-panel"> <div class="content-wrapper"> <div class="card"> <div class="card-body"> <div class="row"> <div class="col-md-3"> <h4 class="card-title">MANAGE LEAVE</h4> </div> <div class="col-md-9"> <button type="button" class="btn btn-primary btn-sm float-right mb-2" data-toggle="modal" data-target="#exampleModal-3">Add Leave <i class="ti-arrow-circle-right ml-1"></i></button> <!-- Add Leave Modal --> <div class="modal fade" id="exampleModal-3" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel-3" aria-hidden="true"> <div class="modal-dialog modal-md" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel-3">Add Leave Type</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form id="addLeaveForm" method="POST" action="process_leave.php?action=add"> <div class="form-row"> <div class="col-md-12 mb-3"> <label for="employee_id">Employee</label> <select id="employee_id" class="form-control" name="employee_id" required> <option value="">Choose Employee</option> <?php $sql = "SELECT employee_id, first_name, last_name FROM employees"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_assoc($result)) { echo '<option value="' . $row['employee_id'] . '">' . $row['first_name'] . ' ' . $row['last_name'] . '</option>'; } ?> </select> </div> <div class="col-md-12 mb-3"> <label for="ltyp">Leave Type</label> <select id="ltyp" class="form-control" name="ltyp" required> <option value="" disabled selected>Select an Leave Type</option> <option value="1">Casual Leaves (4)</option> <option value="2">Medical Leaves (2)</option> </select> </div> <div class="col-md-6 mb-3"> <label for="startdate">Start Date</label> <input type="date" name="startdate" class="form-control" id="startdate"> </div> <div class="col-md-6 mb-3"> <label for="enddate">End Date</label> <input type="date" name="enddate" class="form-control" id="enddate"> </div> <div class="col-md-12 mb-3"> <label for="reason">Reason</label> <textarea id="reason" class="form-control" name="reason"></textarea> </div> <div class="col-md-12 mb-3"> <label for="remarks">Remarks</label> <textarea id="remarks" class="form-control" name="remarks"></textarea> </div> </div> <div class="modal-footer"> <button type="submit" name="save" value="save" class="btn btn-primary">Save changes</button> <button type="button" class="btn btn-light" data-dismiss="modal">Close</button> </div> </form> </div> </div> </div> </div> <!-- End Add Leave Modal --> </div> </div> <div class="row"> <div class="col-12"> <div class="table-responsive"> <table id="order-listing" class="table"> <thead> <tr> <th> Id</th> <th>Employee Name</th> <th>Leave Type</th> <th>Apply Date</th> <th>Start Date</th> <th>End Date</th> <th>Total Days</th> <th>Leave Status</th> <th>Actions</th> </tr> </thead> <tbody> <?php $sql = "SELECT leaves.*, employees.first_name , employees.last_name FROM leaves INNER JOIN employees ON leaves.employee_id = employees.employee_id ORDER BY leaves.id DESC"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { if($row['leave_type'] ==1){ $leave_type = 'Casual'; }else{ $leave_type = 'Medical'; } echo '<tr> <td>' . $row['id'] . '</td> <td class="text-capitalize">' . $row['first_name'] . ' ' . $row['last_name'] . '</td> <td>' . $leave_type . '</td> <td>' . $row['created_at'] . '</td> <td>' . $row['start_date'] . '</td> <td>' . $row['end_date'] . '</td> <td>' . $row['duration'] . '</td> <td>' . $row['leave_status'] . '</td> <td> <button class="btn btn-primary btn-sm mb-2 ml-2 edit-btn" data-id="' . $row['id'] . '" data-toggle="modal" data-target="#editLeaveModal">Edit</button> <button class="btn btn-success btn-sm mb-2 ml-2 update-status" data-id="' . $row['id'] . '" data-toggle="modal" data-target="#updateLeaveModal">Update Status</button> <button class="btn btn-danger btn-sm mb-2 ml-2 delete-btn" data-id="' . $row['id'] . '" data-toggle="modal" data-target="#deleteLeaveModal">Delete</button> </td> </tr>'; } } else { echo '<tr><td colspan="9">No leaves found</td></tr>'; } ?> </tbody> </table> </div> </div> </div> </div> </div> </div> </div> <!-- Edit Leave Modal --> <div class="modal fade" id="editLeaveModal" tabindex="-1" role="dialog" aria-labelledby="editLeaveModalLabel" aria-hidden="true"> <div class="modal-dialog modal-md" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="editLeaveModalLabel">Edit Leave Type</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form id="editLeaveForm" method="POST" action="process_leave.php?action=edit"> <input type="hidden" name="leave_id" id="edit_leave_id"> <div class="form-row"> <div class="col-md-12 mb-3"> <label for="edit_employee_id">Employee</label> <select id="edit_employee_id" class="form-control" name="employee_id" required> <option value="">Choose Employee</option> <?php $sql = "SELECT employee_id, first_name, last_name FROM employees"; $result = mysqli_query($conn, $sql); while ($row = mysqli_fetch_assoc($result)) { echo '<option value="' . $row['employee_id'] . '">' . $row['first_name'] . ' ' . $row['last_name'] . '</option>'; } ?> </select> </div> <div class="col-md-12 mb-3"> <label for="edit_ltyp">Leave Type</label> <select id="edit_ltyp" class="form-control" name="ltyp" required> <option value="1">Casual Leaves (4)</option> <option value="2">Medical Leaves (2)</option> </select> </div> <div class="col-md-6 mb-3"> <label for="edit_startdate">Start Date</label> <input type="date" name="startdate" class="form-control" id="edit_startdate"> </div> <div class="col-md-6 mb-3"> <label for="edit_enddate">End Date</label> <input type="date" name="enddate" class="form-control" id="edit_enddate"> </div> <div class="col-md-12 mb-3"> <label for="edit_reason">Reason</label> <textarea id="edit_reason" class="form-control" name="reason"></textarea> </div> <div class="col-md-12 mb-3"> <label for="edit_remarks">Remarks</label> <textarea id="edit_remarks" class="form-control" name="remarks"></textarea> </div> </div> <div class="modal-footer"> <button type="submit" name="save_edit" class="btn btn-primary">Save changes</button> <button type="button" class="btn btn-light" data-dismiss="modal">Close</button> </div> </form> </div> </div> </div> </div> <!-- End Edit Leave Modal --> <!-- Delete Leave Modal --> <div class="modal fade" id="deleteLeaveModal" tabindex="-1" role="dialog" aria-labelledby="deleteLeaveModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="deleteLeaveModalLabel">Delete Leave Type</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <p>Are you sure you want to delete this leave type?</p> </div> <div class="modal-footer"> <form id="deleteLeaveForm" method="POST" action="process_leave.php?action=delete"> <input type="hidden" name="leave_id" id="delete_leave_id"> <button type="submit" class="btn btn-danger">Delete</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> </form> </div> </div> </div> </div> <!-- End Delete Leave Modal --> <!-- Update Leave Status Modal --> <div class="modal fade" id="updateLeaveModal" tabindex="-1" role="dialog" aria-labelledby="updateLeaveModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="updateLeaveModalLabel">Update Leave Status</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> <form id="updateStatusForm" method="POST" action="process_leave.php?action=update_status"> <input type="hidden" name="leave_id" id="update_leave_id"> <div class="form-group"> <label for="update_status">Select Status:</label> <select class="form-control" id="update_status" name="status" required> <option value="Pending">Pending</option> <option value="Approved">Approved</option> <option value="Rejected">Rejected</option> </select> </div> <div class="modal-footer"> <button type="submit" class="btn btn-primary">Update Status</button> <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button> </div> </form> </div> </div> </div> </div> <script> document.addEventListener('DOMContentLoaded', function () { const editButtons = document.querySelectorAll('.edit-btn'); editButtons.forEach(button => { button.addEventListener('click', function () { const id = this.getAttribute('data-id'); document.getElementById('edit_leave_id').value = id; // Fetch data and populate the form fetch('fetch_leave_data.php', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ 'id': id }) }) .then(response => response.json()) .then(data => { if (data.error) { alert(data.error); } else { document.getElementById('edit_employee_id').value = data.employee_id; document.getElementById('edit_ltyp').value = data.leave_type; document.getElementById('edit_startdate').value = data.start_date; document.getElementById('edit_enddate').value = data.end_date; document.getElementById('edit_reason').value = data.reason; document.getElementById('edit_remarks').value = data.remarks; } }) .catch(error => console.error('Error:', error)); }); }); const deleteButtons = document.querySelectorAll('.delete-btn'); deleteButtons.forEach(button => { button.addEventListener('click', function () { const id = this.getAttribute('data-id'); document.getElementById('delete_leave_id').value = id; }); }); }); </script> <script> document.addEventListener('DOMContentLoaded', function () { const updateButtons = document.querySelectorAll('.update-status'); const updateModal = document.getElementById('updateLeaveModal'); const updateLeaveIdField = document.getElementById('update_leave_id'); const updateStatusSelect = document.getElementById('update_status'); updateButtons.forEach(button => { button.addEventListener('click', function () { const id = this.getAttribute('data-id'); updateLeaveIdField.value = id; }); }); // Clear form when modal closes $('#updateLeaveModal').on('hidden.bs.modal', function () { updateStatusSelect.value = 'Pending'; // Set default status as Pending }); }); </script> <?php include_once("include/footer.php"); ?>
Save
Cancel