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


<html>
    <head>
        
        <link rel="stylesheet" href="css/alerts.css">

        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
         <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">
        <title>Leave Application</title>
        <style>
            .header_table{
                border-color: white;  
                text-align: left;
                width: 100%;               
            }

            .table {
                border-collapse: collapse;               
                width: 100%;
            }

            .td, .th {
                border: 1.2px solid black;
                text-align: left;
                padding: 8px;
            }

            body {
                font-family: Arial, Helvetica, sans-serif;
            }

            /* Add padding to containers */
            .container {
                padding: 16px;
                background-color: white;
            }

            /* Full-width input fields */
            input[type=text], select {
                width: 100%;
                padding: 20px;
                /*margin: 5px 0 22px 0;*/
                display: inline-block;
                border: none;
                /*background: #f1f1f1;*/
            }
            label {
                width: 10%;
                padding: 20px;
                /*margin: 5px 0 22px 0;*/
                display: inline-block;
                border: none;
                /*background: #f1f1f1;*/
            }

            input[type=date]{
                width: 30%;
                padding: 10px;
                display: inline-block;
                border: none;
            }

            input[type=text]:focus, select:focus, input[type=date]:focus, label:focus{
                background-color: #ddd;
                outline: none;
            }

            /* Overwrite default styles of hr */
            hr {
                border: 1px solid black;
                margin-bottom: 25px;
            }

            /* Set a style for the submit button */
            .submit_btn {
                background-color: #190a5c;
                color: white;
                padding: 16px 20px;
                margin: 8px 0;
                border: none;
                border-radius: 30px;
                cursor: pointer;
                width: 100%;
                opacity: 0.9;
            }

            .submit_btn:hover {
                opacity: 1;
            }
            /* Set a style for the submit button */
            .reset_btn {
                background-color: red;
                color: white;
                padding: 16px 20px;
                margin: 8px 0;
                border: none;
                border-radius: 30px;
                cursor: pointer;
                width: 47%;
                opacity: 0.9;
            }

            .reset_btn:hover {
                opacity: 1;
            }

            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>
        <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">Leave Application Submitted 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>
            <%}%>
            <%
                if ("statusUpdated".equals(msg)) {
            %> 
            <div class="alert"> 
                <button class="closebtn"><i class="fa fa-close"></i></button>
                <h3 class="alert">Leave Application status is updated</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>
        <!--<h2><a class="back" href="#"><i class='fas fa-arrow-circle-left'> Back</i></a></h2>-->
        <h3 style="text-align: center">Leave Applications</h3>
        <table>
            <thead>
                <tr>
                    <th>Leave#</th>
                    <th>From Date</th>
                    <th>To Date</th>                    
                    <th>LM Approved</th>
                    <th>HR Approved</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");
                        while (rs.next()) {
                %>

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

                </form>  
                <%
                    }

                %>
            </div>
            <%    } catch (Exception e) {
                    System.out.println(e);
                }
            %>         
        </tbody>
    </table>
    <br>
        <%
            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 users where email='" + email + "'");
                while (rs.next()) {
        %>
 
                         <form action="leaveAppAction.jsp" method="post">   

 
                <table class="header_table">
                    <tr>
                        <th><img src="images/Clinica HD Logo.png" alt="CLINICA" width="150px" height="150px"></th>
                        <th style="font-size: 30px">Leave Application</th>
                    </tr>
                </table>

                <hr>

                <table class="table">
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Name of Employee:</th>
                        <td class="td"><input type="text" value="<%=rs.getString(2)%> <%=rs.getString(4)%>" name="name" disabled></td>
                        <th class="th" style="background-color: #dddddd;">Employee#</th>
                        <td class="td"><input type="text" value="<%=rs.getString(19)%>" name="emp_code" disabled></td>
                        <input type="hidden" name="emp_code" value="<%=rs.getString(19)%>">
                        <input type="hidden" name="LMemail" value="<%=rs.getString(25)%>">
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Department:</th>
                        <td class="td"><input type="text" value="<%=rs.getString(23)%>" name="department" disabled></td>
                        <th class="th" style="background-color: #dddddd;">Designation: </th>
                        <td class="td"><input type="text" value="<%=rs.getString(22)%>" name="designation"  disabled></td>
                    </tr>
                </table>
                <br>



           
        <table class="table">  
                    <tr>
                        <th class="th"  style="background-color: #dddddd;">Nature of Leave Applied</th>
                        <td class="td"><select name="nature_of_leave" id="nature_of_leave" required>
                                <option value="Select" disabled selected>Select nature of leave</option>
                                <option value="CL">Casual leave(CL)</option>
                                <option value="SL">Sick leave(SL)</option>
                                <option value="PL">Paid leave(PL)</option>
                                <option value="LWP">leave without pay (LWP)</option>
                            </select></td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Number of leave days applied</th>
                        <td class="td"><input type="text" placeholder="Enter number of leave days applied" name="days_applied" id="days" required></td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Date</th>
                        <td class="td"><label for="date"><b>From</b></label>
                            <input type="date" placeholder="From" name="date_from" id="" required>
                            <label for="date"><b>To</b></label>
                            <input type="date" placeholder="To " name="date_to" id="" required>
                        </td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">If half day</th>
                        <td class="td"><select name="half_day" id="half_day" required>
                                <option value="Select if half day" disabled>Select</option>
                                <option value="First Half">First Half</option>
                                <option value="Second Half">Second Half</option>
                                <option value="NA">NA</option>
                            </select></td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Reason for requesting leave</th>
                        <td class="td"><input type="text" placeholder="Enter your reason" name="reason" required></td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Contact number during leave</th>
                        <td class="td"><input type="text" placeholder="Enter your phone number" name="contact_number" required></td>
                    </tr>
                    <tr>
                        <th class="th" style="background-color: #dddddd;">Contact address during leave</th>
                        <td class="td"><input type="text" placeholder="Enter your address" name="contact_address" required>
                        </td>
                    </tr>

                    <tr>
                        <th class="th" style="background-color: #dddddd;">Name of person taking charge during leave</th>
                        <td class="td"><input type="text" placeholder="Enter name" name="allocated_person" required>
                        </td>
                    </tr>
                </table>

                   <button type="submit" class="submit_btn">SUBMIT</button>
        </form>
       <%
           }
            } catch (Exception e) {
                out.println(e);
            }
        %>
        <br>
        <br>
        <br>
    </body>
</html>
                
                