<?php 
include "../db.php";
if (isset($_POST['start'])) {
    $start= mysqli_real_escape_string($con,$_POST['start']);
    $AndWhere ='';
    if (!empty($_POST['FirstFilterValue'])) {
        $AndWhere = "AND wl_title = '$_POST[FirstFilterValue]'";
    } elseif (!empty($_POST['SecondFilterValue'])) {
        $AndWhere = "AND wl_vendor_id = '$_POST[SecondFilterValue]'";
    } elseif (!empty($_POST['FirstFilterValue']) && !empty($_POST['SecondFilterValue'])) {
        $AndWhere = "AND wl_title = '$_POST[FirstFilterValue]' AND wl_vendor_id = '$_POST[SecondFilterValue]'";
    }

    $sql = "SELECT * FROM work_list WHERE wl_recycle !='0' $AndWhere ORDER BY wl_id DESC LIMIT $start,10";
    $res = mysqli_query($con,$sql);

        if (mysqli_num_rows($res) === 0) {
            header('Content-Type: text/plain');
            echo '__NO_MORE_DATA__';
            exit;
        } else  {
        $c = $start + 1;

        while ($rows = mysqli_fetch_assoc($res)) {
            $vendor_id = $rows["wl_vendor_id"];
            $vendor_sql = mysqli_query($con, "SELECT * FROM work_place WHERE wp_id = '$vendor_id' ");
            if($vendor_row = mysqli_fetch_assoc($vendor_sql)){
                $vendor = $vendor_row["wp_name"];
            }

            $uniqueId = uniqid();
?>
<li class='clearfix' style='float: none;' id="employee<?php echo $rows["wl_id"]?>">
    <div class="single-dis-admin mb-2">
        <div class='row align-items-center'>
            <div class='col-md-8 col-xs-5'>
                <div class="d-flex justify-content-between align-items-center">
                    <div class="intro-admin">
                        <a style='color:orange;font-size:17px;' class='viewDetails' data-toggle='modal'
                            data-target='#adminDetailsModal' data-name='<?php echo !empty($vendor) ? $vendor : "-"; ?>'
                            data-title='<?php echo !empty($rows["wl_title"]) ? $rows["wl_title"] : "-"; ?>'
                            data-startdate='<?php echo !empty($rows["wl_date"]) ? $rows["wl_date"] : "-"; ?>'
                            data-enddate='<?php echo !empty($rows["wl_time"]) ? $rows["wl_time"] : "-"; ?>'
                            data-hotelamount='<?php echo !empty($rows["wl_amount_by_hotel"]) ? $rows["wl_amount_by_hotel"] : "-"; ?>'
                            data-studentamount='<?php echo !empty($rows["wl_amount_to_student"]) ? $rows["wl_amount_to_student"] : "-"; ?>'
                            data-date='<?php echo !empty($rows["wl_cDate"]) ? $rows["wl_cDate"] : "-"; ?>'>
                            <i class='fa fa-w' aria-hidden='true'></i>
                            <b><?php echo $rows["wl_title"];?></b>
                        </a>
                    </div>
                </div>
            </div>

            <div class='col-md-4 col-xs-4 d-flex justify-content-between'>
                <a href='work-student-attendance.php?vendor_id=<?= $vendor_id; ?>&work_id=<?php echo $rows["wl_id"];?>'
                    class='btn btn-primary btn-sm' title='Click to Edit'>Student Attendance
                </a>
                <a href='work-add-student.php?vendor_id=<?= $vendor_id; ?>&work_id=<?php echo $rows["wl_id"];?>'
                    class='btn btn-primary btn-sm' title='Click to Edit'>Add Student
                </a>
                <a href='view-work.php?vendor_id=<?= $vendor_id; ?>&edit_id=<?php echo $rows["wl_id"];?>'
                    class='btn btn-primary btn-sm' title='Click to Edit'><i class='fa fa-edit' aria-hidden='true'></i>
                </a>
                <br>
                <a href='view-work.php?vendor_id=<?= $vendor_id; ?>&del_id=<?php echo $rows["wl_id"];?>'
                    class='delete btn btn-warning btn-sm text-white' title='Click to recycle'><i class='fa fa-recycle'
                        aria-hidden='true'></i> </a>
            </div>
        </div>
    </div>
</li>
<?php
          $c++;
        }
        mysqli_close($con);
    }
}
?>

<script>
$(document).ready(function() {
    $('.viewDetails').on('click', function(e) {
        e.preventDefault();

        var name = $(this).data('name');
        $('#modalName').text(name);

        var title = $(this).data('title');
        $('#modalTitle').text(title);

        var startDate = $(this).data('startdate');
        $('#modalStartDate').text(startDate);

        var endDate = $(this).data('enddate');
        $('#modalEndDate').text(endDate);

        var hotelAmount = $(this).data('hotelamount');
        $('#modalHotelAmount').text(hotelAmount);

        var studentAmount = $(this).data('studentamount');
        $('#modalStudentAmount').text(studentAmount);

        var date = $(this).data('date');
        $('#modalDate').text(date);

        $('#adminDetailsModal').modal('show');
    });
});
</script>