<%@page import="project.ConnectionProvider"%>
<%@page import="java.sql.*"%>
<%@include file="adminHeader.jsp" %>

<html>
    <head>
        <link rel="stylesheet" href="css/alerts.css"> 
         <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Home</title>
        <style>

            table {
                font-family: arial, sans-serif;
                border-collapse: collapse;
                width: 100%;
            }

            td, th {
                border: 1px solid #dddddd;
                text-align: left;
                padding: 8px;
            }

            th {
                background-color: #dddddd;
            }

            .edit{
                /*border: 1px solid #dddddd;*/
                border: none;
                text-align: center;
                padding: 0px;
                background-color: #dddddd;
                margin: 0px;
            }

            .edit:hover{
                border: none;
                text-align: center;
                background-color: gray;
                color: white;
            }
        </style>
    </head>
    <body style="background-color: #f2f2f2">
        <div class="modal-content animate">
            <%
                String msg = request.getParameter("msg");
                if ("done".equals(msg)) {
            %>
            <div class="alert"> 
                <button class="closebtn"><i class="fa fa-close"></i></button>
                <h3 class="alert">Status Updated Successfully!</h3>
            </div>
            <%}%>
            <%
                if ("wrong".equals(msg)) {
            %> 
            <div class="alert"> 
                <button class="closebtn"><i class="fa fa-close"></i></button>
                <h3 class="alert">Some thing went wrong! Try again!</h3>
            </div>
            <%}%>
        </div>
        <script>
            var close = document.getElementsByClassName("closebtn");
            var i;

            for (i = 0; i < close.length; i++) {
                close[i].onclick = function () {
                    var div = this.parentElement;
                    div.style.opacity = "0";
                    setTimeout(function () {
                        div.style.display = "none";
                    }, 600);
                }
            }
        </script>
<h3 style="text-align: center">Leave Applications</h3>
        <table>
            <thead>
                <tr>
                    <th>Employee ID</th>
                    <th>From Date</th>
                    <th>To Date</th>
                    <th>Mobile Number</th>
                    <th>Leave Type</th>
                    <th>View More</th>
                </tr>
            </thead>
            <div class="row">
                <%
                    try {
                        Class.forName("com.mysql.jdbc.Driver");
                        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/CLINIHR", "root", "Clinica123");
                        Statement st = con.createStatement();
                        ResultSet rs = st.executeQuery("select * from leave_App where LM_approved='Approved'");
                        while (rs.next()) {
                %>

                <form action="viewLeaveDetails.jsp?req_id=<%=rs.getString(1)%>" method="post"> 
                    </tbody>
                    <tr style="background-color: white">
                        <td><%=rs.getString(2)%></td>
                        <td><%=rs.getString(6)%></td>
                        <td><%=rs.getString(7)%></td>
                        <td><%=rs.getString(10)%></td>
                        <td><%=rs.getString(4)%></td>

                        <td class="edit"><button class="edit" style="width: 100%; padding: 8px;" type="submit"> View More </button></td>
                    </tr> 

                </form>  
                <%
                    }

                %>
            </div>
            <%    } catch (Exception e) {
                    System.out.println(e);
                }
            %>         
        </tbody>
    </table>
    <br>
    <br>
    <br>

</body>
</html>