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

$get_exam_heads=$this->NewExamModel->get_exam_heads_data($course_id,$acedemic_session,$exam_heads_table);

$courses_table='courses';
$get_course_info=$this->NewExamModel->get_item_data($course_id,$courses_table);
?>

<div class="container-fluid mt-3 mb-3 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();?>Welcome">Home</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Examination/dashboard">Exam</a></li>
                <li class="breadcrumb-item">Exam Heads</li>
                <li class="breadcrumb-item">
                    <?php 
                    if($get_course_info){
                        foreach($get_course_info as $course_info){
                            echo $course_info['course']; echo " "; echo $course_info['subject_stream'];
                        }
                    }
                    ?>
                </li>
            </ul>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Exam Head</th>
                            <th>MM</th>
                            <th>Head Order</th>
                            <th>Exam Mode</th>
                            <th>Status</th>
                            <th>Update</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if($get_exam_heads){
                            foreach($get_exam_heads as $exam_heads){
                        ?>
                        <tr>
                            <td><?php echo $exam_heads['exam_head'];?></td>
                            <td><?php echo $exam_heads['mm'];?></td>
                            <td><?php echo $exam_heads['head_order'];?></td>
                            <td><?php echo $exam_heads['exam_mode'];?></td>
                            <td>
                                <?php
                                if($exam_heads['status'] == 0){
                                ?>
                                    <button class="btn btn-sm btn-danger" id="status_btn" db_id="<?php echo $exam_heads['id'];?>" db_status="1">Inactive</button>
                                <?php
                                }else if($exam_heads['status'] == 1){
                                ?>
                                    <button class="btn btn-sm btn-success" id="status_btn" db_id="<?php echo $exam_heads['id'];?>" db_status="0">Active</button>
                                <?php
                                }
                                ?>
                            </td>
                            <td><a href="<?php echo base_url();?>Examination/update_exam_heads/<?php echo $exam_heads['id'];?>" target="_blank">Update</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_heads_<?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>
