<?php 
$course_id=$this->uri->segment('3');
$courses_table='courses';
$course=''; 
$subject_stream='';
$get_course_info=$this->WelcomeModel->get_item_data($course_id,$courses_table);
if($get_course_info){
    foreach($get_course_info as $course_info){
        $course=$course_info['course'];
        $subject_stream=$course_info['subject_stream'];
    }
}
$new_course='';



if($course == "NURSERY"){
    $new_course='LKG';
}else if($course == "LKG"){
    $new_course='UKG';
}else if($course == "UKG"){
    $new_course = 1;
}else if($course == 1 || $course == 2 || $course == 3 || $course == 4 || $course== 5 || $course == 6 || $course == 7 || $course == 8 || $course == 9 || $course == 10 || $course == 11){
    $new_course=$course + 1;
}


$get_courses_data=$this->WelcomeModel->get_data($courses_table);
                    
$student_table='student';
$student_course_table='student_courses_data';
$acedemic_session=$this->session->userdata('acedemic_session');
?>

<div class="container-fluid mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            <ul class="breadcrumb mt-3">
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>School/courses">Courses</a></li>
                <li class="breadcrumb-item"><?php echo $course." ".$subject_stream; ?></li>
            </ul>
            <form method="post">
                <?php 
                if($success){
                ?>
                <div class="alert alert-success"><?php echo $success; ?></div>
                <?php
                }
                
                if($error){
                ?>
                <div class="alert alert-danger"><?php echo $error; ?></div>
                <?php
                }
                ?>
                <div class="table-responsive">
                    <table class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                <th>Count</th>
                                <th></th>
                                <th>Student Name</th>
                                <th>Father's Name</th>
                                <th>D.O.B.</th>
                                <th>Status</th>
                                <th>Profile</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                            
                            $count=0;
                            $get_all_course_students=$this->WelcomeModel->get_course_students_by_ac_session_by_course_id($acedemic_session,$course_id);
                            if($get_all_course_students){
                                foreach($get_all_course_students as $course_students){
                                    $count=$count + 1;
                                    $sid=$course_students['sid'];
                                    $get_student_info=$this->WelcomeModel->get_item_data($sid,$student_table);
                                    if($get_student_info){
                                        foreach($get_student_info as $student_info){
                                            // echo "<tr>";
                                            // echo "<td>".$count."</td>";
                                            // echo "<td>".$sid."</td>";
                                            // echo "<td>".$student_info['student_name']."</td>";
                                            // echo "<td>".$student_info['father_name']."</td>";
                                            // echo "<td>".$course_students['class']."</td>";
                            ?>
                            <tr>
                                <td><?php echo $count; ?></td>
                                <td><input type="checkbox" name="sid_list[]" value="<?php echo $sid; ?>" class="sid_list"></td>
                                <td><?php echo $student_info['student_name']; ?></td>
                                <td><?php echo $student_info['father_name']; ?></td>
                                <td><?php echo date('d-M-Y',strtotime($student_info['dob'])); ?></td>
                                <td>
                                <?php 
                                if($student_info['status'] == 1){
                                ?>
                                <button type="button" class="btn btn-sm btn-success">Active</button>
                                <?php
                                }
                                ?></td>
                                <td><a href="<?php echo base_url(); ?>Fee" class="btn btn-sm btn-info">View</a></td>
                            </tr>
                            <?php 
                                        }
                                    }
                                }
                            }
                            ?>
                            <tr>
                                <th></th>
                                <th><input type="checkbox" class="sel-all"></th>
                                <td colspan="5">Select All</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                
                <div class="form-group mt-3">
                    <select class="form-control" name="new_course">
                        <?php 
                        if($get_courses_data){
                            foreach($get_courses_data as $courses_data){
                                if($courses_data['course'] == $new_course){
                                    
                        ?>
                        <option value="<?php echo $courses_data['id']?>"><?php echo $courses_data['course']." ".$courses_data['subject_stream']; ?></option>
                        <?php
                                }
                            }
                        }
                        ?>
                        
                    </select>
                </div>
                <div class="form-group">
                    <label>Section</label>
                    <select class="form-control" name="section">
                        <option value="A">A</option>
                        <option value="B">B</option>
                        <option value="C">C</option>
                        <option value="D">D</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="submit" name="promote_students" class="btn btn-sm btn-success">Promote Students</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
    //   alert();
        $('.sel-all').change(function() {
            if ($(this).is(':checked')) {
                // console.log('Checked');
                // alert("checked");
                $(".sid_list").prop("checked", true);
            } else {
                // console.log('Unchecked');
                // alert("Unchecked");
                $(".sid_list").prop("checked", false);
            }
        });
    
    });
</script>