<?php
$sid=$this->uri->segment('3');
$courses_table='courses';
?>
<div class="container bg-white mt-3 mb-3 pt-3 pb-3">
    <div class="row">
        <div class="col-sm-12">
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Count</th>
                            <th>Class</th>
                            <th>Date of Admission</th>
                            <th>Date of Promotion</th>
                            <th>Date of Removal</th>
                            <th>Cause of Removal</th>
                            <th>Acedemic Session</th>
                            <th>Conduct & Work</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $count=0;
                        
                        $get_student_courses_data=$this->SchoolModel->get_student_courses_data($sid);
                        if($get_student_courses_data){
                            foreach($get_student_courses_data as $courses_data){
                               $count = $count + 1;
                               $course_id=$courses_data['course_id'];
                               $course=$courses_data['class'];
                               $ac_session_table='academic_session_details';
                               $ac_session_id=$courses_data['acedemic_session'];
                               $ac_session__data=$this->WelcomeModel->get_item_data($ac_session_id,$ac_session_table);
                               ?>
                        <tr>
                            <td><?php echo $count;?></td>
                            <td>
                                <?php
                                $get_course_info=$this->WelcomeModel->get_item_data($course_id,$courses_table);
                                if($get_course_info){
                                    foreach($get_course_info as $course_info){
                                        echo $course_info['course']; echo " "; echo $course_info['subject_stream'];
                                    }
                                }
                                ?>
                            </td>
                            <td><?php if($courses_data['date_of_admission'] !='0000-00-00'){echo date('d-M-Y',strtotime($courses_data['date_of_admission']));} ?></td>
                            <td><?php if($courses_data['date_of_promotion'] !='0000-00-00'){echo date('d-M-Y',strtotime($courses_data['date_of_promotion']));} ?></td>
                            <td><?php if($courses_data['date_of_removal'] !='0000-00-00'){echo date('d-M-Y',strtotime($courses_data['date_of_removal']));} ?></td>
                            <td><?php if($courses_data['cause_of_removal']){echo date('d-M-Y',strtotime($courses_data['cause_of_removal']));} ?></td>
                            <td>
                                <?php
                                if($ac_session__data){
                                   foreach($ac_session__data as $session__data){
                                        $acedemic_session_full_year=$session__data['year_long'];        
                                        echo $acedemic_session_full_year;
                                   }
                                }
                                ?>
                            </td>
                            <td></td>
                            <td><a href="<?php echo base_url();?>School/update_scholor_register/<?php echo $courses_data['id']; ?>">Update</a></td>
                        </tr>                                
                                <?php
                            }
                        }
                        ?>

                    </tbody>
                </table>   
                
            </div>
            <div class="mt-3 mb-3 pt-3 pb-3">
                <form method="post" action="#">
                    <h3 class="text-center">Add New Log<hr></h3>
                    <?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
                    }
                    ?>
                    <input type="hidden" name="sid" value="<?php echo $sid;?>">
                    <div class="form-group">
                        <label>Acedemic Year</label>
                        <select class="form-control" name="acedemic_session">
                            <?php 
                            $acedemic_session_table='academic_session_details';
                            $get_data=$this->SchoolModel->get_data($acedemic_session_table);
                            if($get_data){
                                foreach($get_data as $data){
                            ?>
                            <option value="<?php echo $data['id'];?>"><?php echo $data['year_long'];?></option>
                            <?php
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Class</label>
                        <select class="form-control" name="course_id">
                            <?php
                            
                            $get_all_courses=$this->SchoolModel->get_data($courses_table);
                            if($get_all_courses){
                                foreach($get_all_courses as $course_info){
                            ?>
                            <option value="<?php echo $course_info['id'];?>"><?php echo $course_info['course']; echo " "; echo $course_info['subject_stream'];?></option>
                            <?php
                                }
                            }
                            ?>
                        </select>
                    </div>
                    <div class="form-group">
                        <button class="btn btn-sm btn-success" name="add_new_course">Add New Course</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>