<?php
$course_id=$this->uri->segment('3');
$acedemic_session=$this->session->userdata('acedemic_session');
$subjects_table='exam_subjects_'.$acedemic_session.'';


$course_table='courses';
$course='';
$subject_stream='';
$get_course_data=$this->NewExamModel->get_item_data($course_id,$course_table);
if($get_course_data){
    foreach($get_course_data as $course_data){
        $course=$course_data['course'];
        $subject_stream=$course_data['subject_stream'];
    }
}

$get_subjects=$this->NewExamModel->get_subjects_data($course_id,$acedemic_session,$subjects_table);

?>
<div class="container-fluid mt-3 mb-3 pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            <ul class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Examination/dashboard">Exam</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Examination/dashboard">All Courses</a></li>
                <li class="breadcrumb-item"><?php echo $course; echo " "; echo $subject_stream; ?></li>
            </ul>
            
            <div class="table-responsive">
                
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Subject</th>
                            <th>Order</th>
                            <th>MM</th>
                            <th>Exam Type</th>
                            <th>Subject Type</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if($get_subjects){
                            foreach($get_subjects as $subjects){
                        ?>
                        <tr>
                            <td><?php echo $subjects['subject'];?></td>
                            <td><?php echo $subjects['subject_order'];?></td>
                            <td><?php echo $subjects['MM'];?></td>
                            <td><?php echo $subjects['exam_type'];?></td>
                            <td><?php echo $subjects['subject_type'];?></td>
                            <td>
                                <?php
                                if($subjects['status'] == 0){
                                ?>
                                <button class="btn btn-sm btn-danger" id="status_btn" db_id="<?php echo $subjects['id'];?>" db_status='1'>Inactive</button>
                                <?php
                                }else if($subjects['status']==1){
                                ?>
                                    <button class="btn btn-sm btn-success" id="status_btn" db_id="<?php echo $subjects['id'];?>" db_status='0'>Active</button>
                                <?php
                                }
                                ?>
                            </td>
                            <td><a href="<?php echo base_url();?>Examination/update_subject_info/<?php echo $subjects['id']; ?>" class="btn btn-sm btn-info" target="_blank">Udate</a></td>
                        </tr>
                        <?php
                            }
                        }
                        
                        ?>
                        
                        
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function (){
        $(document).on("click","#status_btn",function(){
            var id = $(this).attr("db_id");    
            var val = $(this).attr("db_status");    
            var table = 'exam_subjects_<?php echo $acedemic_session;?>';
            $.ajax({
                url: '<?php echo base_url(); ?>Examination/active_inactive',
                type: 'POST',
                data: {id:id,val:val,table:table},
                success: function(data){
                    location.reload(); 
                }
            });


        });
    });
</script>