<?php
$sid=$this->uri->segment('3');
$subject_id=$this->uri->segment('4');

$acedemic_session=$this->session->userdata('acedemic_session');
$student_course_info=$this->NewExamModel->student_course_info($sid,$acedemic_session);
$course_id='';
if($student_course_info){
    foreach($student_course_info as $course_info){
        $course_id=$course_info['course_id'];
    }
}

$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'];
    }
}
?>

<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"><a href="<?php echo base_url();?>Examination/dashboard">All Courses</a></li>
            <li class="breadcrumb-item"><a href="<?php echo base_url();?>Examination/course_students/<?php echo $course_id;?>"><?php echo $course; echo " "; echo $subject_stream;?></a></li>
            <li class="breadcrumb-item"><a href="<?php echo base_url();?>Examination/exam_log/<?php echo $sid;?>">Exam Log</a></li>
            <li class="breadcrumb-item">Add Exam Log</li>
        </ul>        
        </div>
    </div>
</div>
<?php $this->load->view('erp/exam/new/student-profile');?>


<div class="container pt-3 pb-3 bg-white">
    <div class="row">
        <div class="col-sm-12">
            <div class="table-responsive">
                <form method="post" action="#">
                    <?php 
                    $subject_table='exam_subjects_'.$acedemic_session.'';
                    $exam_type='';
                    $get_subject_info=$this->NewExamModel->get_item_data($subject_id,$subject_table);
                    if($get_subject_info){
                        foreach($get_subject_info as $subject_info){
                            $exam_type=$subject_info['exam_type'];
                    ?>
                    <div class="form-group">
                        <label>Subject</label>
                        <input type="hidden" name="course_id" value="<?php echo $course_id;?>">
                        <input type="hidden" name="acedemic_session" value="<?php echo $acedemic_session;?>">
                        <input type="hidden" value="<?php echo $sid;?>" name="sid" id="sid">
                        <input type="hidden" value="<?php echo $subject_id;?>" name="subject_id" id="subject_id" class="form-control">
                        <input type="text" name="subject_info" id="subject_info" value="<?php echo $subject_info['subject'];?>" class="form-control mb-2" readonly>
                        <input type="text" name="exam_type" id="exam_type" value="<?php echo $subject_info['exam_type'];?>" class="form-control" readonly>
                    </div>
                    <?php
                        }
                    }
                    ?>
                    
                    <?php
                    $exam_head_table='exam_heads_'.$acedemic_session.'';
                    $get_exam_heads=$this->NewExamModel->get_course_exam_heads($course_id,$exam_head_table);
                    if($get_exam_heads){
                        foreach($get_exam_heads as $exam_heads){
                            $ehid=$exam_heads['id'];
                            $log_value='';
                            $elog_table='exam_log_'.$acedemic_session.'';
                            $get_log_item_data=$this->NewExamModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                    ?>
                    <div class="form-group">
                        <label><?php echo $exam_heads['exam_head']; echo " ["; echo $exam_heads['mm']; echo "]";?></label>
                        <?php
                        if($exam_type == 'Marks'){
                            if($get_log_item_data){
                                foreach($get_log_item_data as $log_item_data){
                                    $log_value=$log_item_data['obtained_marks'];
                                }
                            }
                        ?>
                        
                        <input type="number" value="<?php echo $log_value;?>" class="form-control" name="exam_log_<?php echo $exam_heads['id']; ?>" placeholder="Enter <?php echo $exam_heads['exam_head'];?> Marks" id="exam_log">
                        <?php
                        }else if($exam_type == 'Grade'){
                            if($get_log_item_data){
                                foreach($get_log_item_data as $log_item_data){
                                    $log_value=$log_item_data['grade'];
                                }
                            }
                        ?>
                        <input type="text" class="form-control" value="<?php echo $log_value;?>" name="exam_log_<?php echo $exam_heads['id']; ?>" placeholder="Enter <?php echo $exam_heads['exam_head']; ?> Grade" id="exam_log">
                        <?php
                        }
                        
                        ?>
                    </div>                    
                    <?php
                        }
                    }
                    ?>

                    
                    <div class="form-group">
                        <button type="submit" name="add_exam_log" class="btn btn-sm btn-info">Update</button>
                    </div>
                    
                </form>
            </div>
        </div>
    </div>
</div>
<script>
$(document).ready(function(){    
    $("input").keyup(function(){
        // alert("Hello");
        // $("input").css("background-color", "pink");
    });
});
</script>