<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>


</head>

<body>
    <!-- <div class="page-header mt-5"> -->
    <div class="d-flex justify-content-between">
        <div>
            <h3 class=" tx-24 mg-b-5"><strong><?= $page; ?></strong></h4>
        </div>
        <div>
            <!-- <label>Pending</label>
            <input type="radio" name="filter" id="filter" class="filter" value="Pending">
                                <label>Completed</label>
            <input type="radio" name="filter" id="filter" class="filter" value="Completed"> -->
        </div>
    </div>
    <!-- </div>  -->
    <!-- Row -->

    <div class="row sidemenu-height">
        <div class="col-lg-12">
            <?php
            if ($this->session->flashdata('alert_success')) {
            ?>
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <?php echo $this->session->flashdata('alert_success'); ?>
                </div>
            <?php
            }
            if ($this->session->flashdata('alert_danger')) {
            ?>
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <?php echo $this->session->flashdata('alert_danger'); ?>
                </div>
            <?php
            }
            ?>
            <div class="card custom-card">
                <div class="card-header justify-content-start d-flex">
                    <?php if ($page != 'Shortlisted') { ?>
                        <div class="col-md-3">
                            <div class="btn btn-info" onclick="shortlist()">Add to Shortlisted</div>
                        </div>
                    <?php } ?>
                    <div class="form-group col-md-2">
                        <select name="courseId" id="courseId" class="form-control filtercourse select2">
                            <option value="">-- Filter Course --</option>
                            <?php foreach ($courses as $row) { ?>
                                <option value="<?php echo $row->short_name ?>"> <?php echo $row->short_name ?></option>
                            <?php } ?>
                        </select>
                    </div>
                    <div  class='col-md-4'>
                            <input type="checkbox" id="demandDraft" name="demandDraft" class="ml-2" ><label class="mt-2"> &nbsp; Demand Draft</label>
                            <input type="checkbox" id="scst" name="scst" class="ml-2" ><label class="mt-2"> &nbsp; SC/ST</label>
                    </div>
                    <div class='col-md-1'></div>
                    <div>
                     <button type="button" class="btn btn-primary waves-effect waves-light" onclick="exportReportToExcel(this)">Export to Excel</button>
                    </div>

                    
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="dmstable" class="table table-striped table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">
                            <thead>
                                <tr>
                                    <th class="wd-20p">S.No</th>
                                    <th class="wd-20p">Ref.No</th>
                                    <th class="wd-25p">Application No.</th>
                                    <th class="wd-15p">Course Name</th>
                                    <th class="wd-15p"> Name</th>
                                    <th class="wd-15p">Mobile No.</th>
                                    <th class="wd-15p">Gender</th>
                                    <th class="wd-15p">DOB</th>
                                    <th class="wd-15p">Address</th>
                                    <th class="wd-15p">City</th>
                                    <th class="wd-15p">Pincode</th>
                                    <th class="wd-15p">State</th>
                                    <th class="wd-15p">Country</th>
                                    <th class="wd-15p">Nationality</th>
                                    <th class="wd-15p">Email ID</th>
                                    <th class="wd-15p">Father Name</th>
                                    <th class="wd-15p">Father Occupation</th>
                                    <th class="wd-15p">Father Address</th>
                                    <th class="wd-15p">Father Mobile</th>
                                    <th class="wd-15p">Father Email</th>
                                    <th class="wd-15p">Mother Name</th>
                                    <th class="wd-15p">Mother Occupation</th>
                                    <th class="wd-15p">Annual Income in INR</th>
                                    <th class="wd-15p">Annual Income in Words</th>
                                    <th class="wd-15p">Application staus</th>
                                    <th class="wd-15p">Payment Mode</th>
                                    <th class="wd-15p">Payment Status</th>
                                    <th class="wd-15p">Submitted Date</th>
                                    <th class="wd-15p">Email</th>
                                    <th class="wd-15p">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($records as $i => $row) { ?>
                                    <tr>
                                        <td><input type="checkbox" class="checkbox mr-2 shortList" name="short_list[]" id="short_list<?= $i; ?>" value="<?= $row->appid; ?>"> <?= $i + 1 ?></td>
                                        <td><?= $row->reference_no ?></td>
                                        <td> <?= $row->application_no ?> </td>
                                        <td> <?php foreach ($courses as $course){  if($row->course_id == $course->id){ echo $course->short_name?>
                                       <?php } } ?></td>
                                       <td> <?= $row->first_name. ' ' .$row->middle_name.' ' .$row->last_name?></td>
                                        <td><?= $row->mobile ?></td>
                                        <td><?= $row->gender ?></td>
                                        <td><?= $row->dob ?></td>
                                        <td><?= $row->communication_address ?></td>
                                        <td><?= $row->city ?></td>
                                        <td><?= $row->pincode ?></td>
                                        <td><?= $row->state ?></td>
                                        <td><?= $row->cuntry ?></td>
                                        <td><?= $row->nationality ?></td>
                                        <td><?= $row->email ?></td>
                                        <td><?= $row->father_name ?></td>
                                        <td><?= $row->father_occupation ?></td>
                                        <td><?= $row->father_home_address ?></td>
                                        <td><?= $row->father_home_mobile ?></td>
                                        <td><?= $row->father_home_email ?></td>
                                        <td><?= $row->mother_name ?></td>
                                        <td><?= $row->mother_occupation ?></td>
                                        <td><?= $row->annual_income_rs ?></td>
                                        <td><?= $row->annual_income_words ?></td>
                                        <td><?= $row->status==1? 'Submitted': 'Drafted'; ?></td>
                                        <td><?= $row->payment_mode ==1? 'Online': 'Demand Draft'; ?></td>
                                        <td><?= $row->payment_status==2? 'Paid': 'Not Paid'; ?></td>
                                        <td><?=date('d-m-Y', strtotime($row->created_at)) ?></td>

                                        <!-- <td> <form action="<?= base_url('ApplicationController/mailSendOnCompletedList/') ?>" id="mailsed" method="post"><input type="hidden" value="<?= $row->email ?>" name="email" id="email"> <input type="hidden" name="refno" value="<?= $row->reference_no  ?>  ">  <input type="hidden"  name="course" value="<?= $row->course_name; ?>"   id="courseid"> <input type="hidden" value="<?= $row->first_name.' '.$row->middle_name.' '.$row->last_name ?>" name="uname" id="uname"><a class="" title="mail" onclick="mailSend()" ><i class="ti-email text-themecolor h5"></i></a></form></td> -->

                                        <td><a title="Send Mail" href="<?= base_url('ApplicationController/mailSendOnCompletedList/' . $row->appid) ?>"><i class="ti-email text-themecolor h5"></i></a>
</td>
                                        <td>
                                        <a title="Preview" target="_blank" href="<?= base_url('ApplicationController/viewApplication/' . $row->user_id) ?>" class="open-in-new-tab"><i class="ti-eye text-themecolor h5"></i></a>
                                        <a title="Edit" href="<?= base_url('ApplicationController/applicationedit/' . $row->appid) ?>" class=""><i class="ti-pencil-alt text-themecolor h5"></i></a>
                                        <!-- <a title="download" href="<?= base_url('ApplicationController/downloadApplication/' . $row->user_id) ?>" class="open-in-new-tab"><i class="ti-download text-themecolor h5"></i></a> -->
                                        </td>

                                        <!-- <td><?= ($row->payment_mode == '0') ? 'DD' : 'Online' ?></td> -->

                                         <!--<td style="padding-right: 10px;">

                                            <a title="Edit" href="<?= base_url('ApplicationController/completelist/' . $row->user_id) ?>" class="text-themecolor"><i class="ti-pencil-alt h5"></i></a>
                                        </td> -->
                                    </tr>
                                <?php  }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
    </div>

    <script src="<?php echo base_url('assets/js/table2excel.js')?>"></script>

    <script>

        function mailSend(){
            $('#mailsed').submit();
        }
        // jQuery
        $(document).ready(function() {
            // When a link with the class "open-in-new-tab" is clicked
            $(".open-in-new-tab").click(function(event) {
                // Prevent the default behavior (opening the link in the current tab)
                event.preventDefault();

                // Get the URL from the href attribute of the clicked link
                var url = $(this).attr("href");

                // Open the URL in a new tab/window
                window.open(url, "_blank");
            });
        });



        function shortlist() {
            var checkedValues = [];
            $('.shortList:checked').each(function() {
                checkedValues.push($(this).val());
            });
            // alert(checkedValues);
            if (checkedValues) {
                $.ajax({
                    type: "POST",
                    url: "<?php echo base_url('ApplicationController/shortList'); ?>", // Corrected URL
                    data: {
                        id: checkedValues
                    },
                    success: function(respose) {
                        // alert('fggh');
                        window.location.reload();
                        // loadCourses(); // Reload the course list
                    },
                    error: function(error) {
                        console.error(error);
                    }
                });
            }
        }
        $(document).ready(function() {
            $('#dmstable').DataTable();

            // Add checkbox click event
            $('#dmstable tbody').on('click', 'input.checkbox', function() {
                var tr = $(this).closest('tr');
                if ($(this).prop('checked')) {
                    tr.addClass('selected');
                } else {
                    tr.removeClass('selected');
                }
            });
            $(".filtercourse").on("change", function() {
                // alert($(this).val());
                var columnIndex = 3;
                var filterValue = $(this).val();
                $('#dmstable').DataTable().column(columnIndex).search(filterValue).draw();
            });
            $(".filter").on("change", function() {
                // alert($(this).val());
                var columnIndex = 7;
                var filterValue = $(this).val();
                //    console.log("Column Index:", $(this).data("column"));
                // table.column(columnIndex).search(filterValue).draw();
                $('#dmstable').DataTable().column(columnIndex).search(filterValue).draw();
                // table.columns(7).search($(this).val()).draw();
                // dataTable.column($(this).data("column")).search(this.value).draw();
            });
            // table.buttons().container().appendTo("#dmstable .col-md-6:eq(0)");
        });

           
//         function exportReportToExcel(elem) {
//     $("#dmstable").table2excel({
//         exclude: ".noExl",
//         filename: "CompletedReport",
//         fileext: ".xls",
//     });
// }

function exportReportToExcel(elem) {
    // Store the current pagination setting
    var oldPageLength = $('#dmstable').DataTable().page.len();
    // Set pagination to show all records
    $('#dmstable').DataTable().page.len(-1).draw();

    // Perform the export
    $("#dmstable").table2excel({
        exclude: ".noExl",
        filename: "CompletedReport",
        fileext: ".xls",
        onAfterExport: function() {
            // Revert to the original pagination setting
            $('#dmstable').DataTable().page.len(oldPageLength).draw();
        }
    });
}

    </script>