<?php
$exam_table='all_exams';
$exam_id=$this->uri->segment('3');
$get_exam_info=$this->NewExamModel->get_item_data($exam_id,$exam_table);
if($get_exam_info){
    foreach($get_exam_info as $exam_info){
        $acedemic_session=$exam_info['acedemic_session'];

?>

<div class="container 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">Exam</a></li>
                <li class="breadcrumb-item"> Exam Schedule</li>
                <li class="breadcrumb-item">Add New Exam Date</li>
            </ul>
            <form method="post" action="#">
                <input type="hidden" id="acedemic_session" value="<?php echo $acedemic_session;?>">
                <input type="hidden" id="exam_id" value="<?php echo $exam_id;?>">
                <?php
                $acedemic_sesion_table='academic_session_details';
                $get_session_info=$this->NewExamModel->get_item_data($acedemic_session,$acedemic_sesion_table);
                if($get_session_info){
                    foreach($get_session_info as $session_info){
                ?>
                <input type="text" id="acedemic_session_info" value="<?php echo $session_info['year_long'];?>" class="form-control" readonly>
                <?php
                    }
                }
                ?>
                
                <div class="form-group">
                    <label>Exam</label>
                    <input type="text" id="exam_title" value="<?php echo $exam_info['exam_title'];?>" class="form-control" readonly>
                </div>
                <div class="form-group">
                    <label>Exam Type</label>
                    <input type="text" id="exam_type" class="form-control" value="<?php echo $exam_info['exam_type'];?>" readonly>
                </div>
                <div class="form-group" id="exam-date-sec">
                    <label>Exam Date</label>
                    <input type="date"  id="exam_date" class="exam_paper form-control mt-1 mb-1" value="" placeholder="Exam Date">
                </div>
                
                <div class="form-group">
                    <button type="button" id="" onclick="add_fields();" class="btn btn-sm btn-info" >Add More </button>
                    <button type="button" id="add_exam_date" class="btn btn-sm btn-success">Submit</button>
                </div>
            </form>
            
        </div>
    </div>
</div>
<?php
    }
}
?>

<script>

function add_fields() {    
    var input_element ='<input type="date" id="exam_date" class="exam_date form-control mt-1 mb-1" placeholder="Exam Date" value="" required>';
        $("#exam-date-sec").append(input_element);
    }
    
    
$(document).ready(function(){
    
    $("#add_exam_date").click(function(){
        
        var exam_id = $("#exam_id").val();
        var acedemic_session = $('#acedemic_session').val();
        var acedemic_session_info = $('#acedemic_session_info').val();
        
        
        $("input[id='exam_date']").each(function() {
            var exam_date = $(this).val();
            alert(exam_date);            
            $.ajax({
                url: '<?php echo base_url(); ?>Examination/insert_exam_date/',
                type: 'POST',
                data: {exam_id:exam_id,acedemic_session:acedemic_session,acedemic_session_info:acedemic_session_info,exam_date:exam_date},
                success: function(data){
                    
                }
            });
        });
        swal("Added Successfully");
    });
});
</script>