<?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">Add New Exam Schedule</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">
                    <label>Course</label>
                    <select class="form-control" id="course_id">
                        <?php
                        $courses_table='courses';
                        $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>Exam Head</label>
                    <select class="form-control" id="exam_head">
                        <?php
                        $exam_head_table='exam_heads_'.$acedemic_session.'';
                        $all_exam_heads=$this->NewExamModel->get_data($exam_head_table);
                        if($all_exam_heads){
                            foreach($all_exam_heads as $exam_heads){
                        ?>
                        <option value="<?php echo $exam_heads['id'];?>"><?php echo $exam_heads['exam_head'];?></option>
                        <?php
                            }
                        }
                        ?>
                        
                    </select>
                </div>
                
                <div class="form-group" id="exam-paper-sec">
                    <label>Exam Paper</label>
                    <input type="text" name="question_paper" id="exam_paper" class="exam_paper form-control mt-1 mb-1" value="" placeholder="Exam Paper">
                </div>
                
                <div class="form-group">
                    <button type="button" id="add_exam_paper" onclick="add_fields();" class="btn btn-sm btn-info" >Add More </button>
                    <button type="button" id="add_schedule" class="btn btn-sm btn-success">Submit</button>
                </div>
            </form>
            
        </div>
    </div>
</div>
<?php
    }
}
?>

<script>

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