<?php 
$acedemic_session=$this->session->userdata('acedemic_session');
$acedemic_session_table='academic_session_details';
$get_acedemic_session_data=$this->NewExamModel->get_item_data($acedemic_session,$acedemic_session_table);
$year_long='';
if($get_acedemic_session_data){
    foreach($get_acedemic_session_data as $acedemic_session_data){
        $year_long=$acedemic_session_data['year_long'];
    }
}
$courses_table='courses';

?>
<div class="container pt-3 pb-3 bg-white mt-3 mb-3">
    <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="#">Exam Heads</a></li>
                <li class="breadcrumb-item">Add New Exam Head</li>
            </ul>
            <!--<div class="table-responsive">-->
            <!--    <table class="table table-bordered table-striped">-->
            <!--        <thead>-->
            <!--            <tr>-->
            <!--                <th>#</th>-->
            <!--                <th></th>-->
            <!--                <th></th>-->
            <!--                <th></th>-->
            <!--                <th></th>-->
            <!--                <th></th>-->
            <!--            </tr>-->
            <!--        </thead>-->
            <!--    </table>-->
            <!--</div>-->
            
            <form method="post" action="#">
                
                <div class="form-group">
                    <label>Course</label>
                    <select class="form-control" id="course_id">
                        <?php 
                        $all_courses=$this->NewExamModel->get_data($courses_table);
                        if($all_courses){
                            foreach($all_courses as $courses){
                        ?>
                        <option value="<?php echo $courses['id'];?>"><?php echo $courses['course']; echo " "; echo  $courses['subject_stream'];?></option>
                        <?php
                            }
                        }
                        ?>
                        
                    </select>
                </div>
                
                <div class="form-group">
                    <label>Acedemic Session</label>
                    <input type="hidden" name="acedemic_session" id="acedemic_session" value="<?php echo $acedemic_session;?>">
                    <input type="text" name="acedemic_session_info" id="acedemic_session_info" class="form-control" value="<?php echo $year_long; ?>" readonly>
                </div>
                
                <div class="form-group" id="exam-head-sec">
                    <label>Exam Head</label>
                    <input type="text" id="exam_head" class="exam_head form-control mt-1 mb-1" value="" placeholder="Exam Head" required>
                </div>
                <button type="button" id="more_fields" onclick="add_fields();" class="btn btn-sm btn-info" >Add More Exam Head</button>
                <button type="button" id="add_exam_head" class="btn btn-sm btn-success">Add Exam Head</button>
            </form>
            
        </div>
    </div>
</div>


<script>

function add_fields() {    
    var input_element ='<input type="text" id="exam_head" class="exam_head form-control mt-1 mb-1" value="" placeholder="Exam Head" required>';
        $("#exam-head-sec").append(input_element);
     
    }
    
    
$(document).ready(function(){
    
    $("#add_exam_head").click(function(){
        // var taskObj = [];
        var acedemic_session = $('#acedemic_session').val();
        var course_id = $('#course_id').val();
        var acedemic_session_info = $('#acedemic_session_info').val();
        // alert()
        // if(task_date){
        
        $("input[id='exam_head']").each(function() {
            var exam_head = $(this).val();
            
            $.ajax({
                url: '<?php echo base_url(); ?>Examination/insert_exam_heads/',
                type: 'POST',
                data: {acedemic_session:acedemic_session,course_id:course_id,acedemic_session_info:acedemic_session_info,exam_head:exam_head},
                success: function(data){
                    alert(data);
                       /*$("#form")[0].reset();*/
                       
               }
            });
            
        });
        // location.reload();
        
        // }else{
        //         alert("Select Task Date");
        //     }
        
    });
});
</script>