<?php 
$id=$this->uri->segment("3");
$doc_table="import_documents";
$get_doc_data=$this->ImportModel->get_item_data($id,$doc_table);
if($get_doc_data){
    foreach($get_doc_data as $doc_data){
        $doc_status=$doc_data['status'];

?>
<div class="container-fluid bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <ul class="breadcrumb">
                <li class="breadcrumb-item">
                    <a href="<?php echo base_url(); ?>">Home</a>
                </li>
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Import">Imported Student's Documents</a></li>
                <li class="breadcrumb-item">View Students</li>
            </ul>
            <div class="table-responsive">
                <table class="table table-bordered table-striped" id="mytable">
                    <thead>
                        <tr>
                            <th>Sl.No.</th>
                            <th>Admission No</th>
                            <th>Admission Date</th>
                            <th>Student Name</th>
                            <th>DOB</th>
                            <th>Gender</th>
                            <th>Father Name</th>
                            <th>Mother Name</th>
                            <th>Caste Category</th>
                            <th>Mobile No.</th>
                            <th>Class</th>
                            <th>Aadhar No</th>
                            <th>Status</th>
                            <th>Date Time</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $i=0;
                        $pending_validation_count=0;
                        $table="import_students";
                        $get_doc_stud_data=$this->ImportModel->get_doc_data($id,$table);
                        if($get_doc_stud_data){
                            foreach($get_doc_stud_data as $students_data){
                                $i=$i + 1;
                                $student_imp_status= $students_data['status'];
                                
                                if($students_data['validation'] == 0){
                                    $pending_validation_count=$pending_validation_count + 1;
                                }
                        ?>
                        <tr>
                            <td><?php echo $i; ?></td>
                            <td><?php echo $students_data['admission_no']; ?></td>
                            <td><?php echo $students_data['admission_date']; ?> </td>
                            <td><?php echo $students_data['student_name']; ?></td>
                            <td><?php echo $students_data['dob']; ?></td>
                            <td><?php echo $students_data['gender']; ?></td>
                            <td><?php echo $students_data['father_name']; ?></td>
                            <td><?php echo $students_data['mother_name']; ?></td>
                            <td><?php echo $students_data['caste_category']; ?></td>
                            <td><?php echo $students_data['mobile_no']; ?></td>
                            <td><?php echo $students_data['class']; ?></td>
                            <td><?php echo $students_data['aadhar_no']; ?></td>
                            <td>
                                <?php
                                    if($student_imp_status == "Valid"){
                                    ?>
                                    <button class="btn btn-sm btn-outline-primary"><?php echo $student_imp_status; ?></button>
                                    <?php
                                    }else if($student_imp_status == "Duplicate"){
                                    ?>
                                    <button class="btn btn-sm btn-outline-danger"><?php echo $student_imp_status; ?></button>
                                    <?php
                                    }else if($student_imp_status == "Invalid"){
                                    ?>
                                    <button class="btn btn-sm btn-outline-danger"><?php echo $student_imp_status; ?></button>
                                    <?php
                                    }else if($student_imp_status == "Imported"){
                                    ?>
                                    <button class="btn btn-sm btn-outline-success"><?php echo $student_imp_status; ?></button>
                                    <?php
                                    }else if($student_imp_status == "Pending"){
                                    ?>
                                    <button class="btn btn-sm btn-outline-warning"><?php echo $student_imp_status; ?></button>
                                    <?php
                                    } 
                                    ?>
                                    
                            </td>
                            <td><?php echo date("d-m-Y h:i:sa",strtotime($students_data['created_at'])); ?></td>
                        </tr>
                        <?php
                            }
                        }
                        ?>
                    </tbody>
                </table>
            </div>    
                <form method="post">
                    <?php // echo $pending_validation_count; ?>
                    <input type="hidden" name="doc_id" value="<?php echo $id; ?>">
                    <input type="hidden" name="academic_session" value="<?php echo $doc_data['academic_session']; ?>">
                    <?php 
                    if($doc_status == "Pending"){
                        if($pending_validation_count == 0){
                    ?>
                        <button type="submit" class="btn btn-sm btn-outline-success" name="confirm_import_students">Confirm Import Students</button>
                        <?php
                        }else{
                        ?>
                        <button type="submit" class="btn btn-outline-danger" name="validate_students">Validate Students</button>
                    <?php
                        }
                    }
                    ?>
                </form>
            
        </div>
    </div>
</div>
<?php 
    }
}
?>