<?php 
$sid=$this->uri->segment('3');
$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-fluid mt-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">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">Log Sheet</li>
            </ul>
        </div>
    </div>
</div>
<?php
$this->load->view('erp/exam/new/student-profile');
?>
<div class="container-fluid bg-white pt-3 pb-3">
    <div class="row">
        <div class="col-sm-12">
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>S.No.</th>
                            <th>Subject</th>
                            <?php 
                            $eh_count=0;
                            $exam_head_table='exam_heads_'.$acedemic_session.'';
                            $all_exam_heads=$this->NewExamModel->get_course_exam_heads($course_id,$exam_head_table);
                            if($all_exam_heads){
                                foreach($all_exam_heads as $exam_heads){
                                    $eh_count=$eh_count + 1;
                            ?>
                            <th><?php echo $exam_heads['exam_head']; echo "[".$exam_heads['mm']."]";?></th>
                            <?php
                                }
                            }
                            ?>
                            <th>
                                <a href="<?php echo base_url();?>Examination/new_exam_log/<?php echo $sid;?>" class="btn btn-sm btn-warning">
                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
                                        <path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
                                        <path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
                                    </svg>
                                </a>
                                <a href="<?php echo base_url();?>Examination/exam_attendance_log/<?php echo $sid;?>" class="btn btn-sm btn-warning ml-3">Attendance Log
                                    
                                </a>
                            </th>
                            
                            
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $sub_count=0;
                            $subject_table='exam_subjects_'.$acedemic_session.'';
                            $all_active_subjects=$this->NewExamModel->get_course_active_subjects($course_id,$subject_table);
                            if($all_active_subjects){
                                foreach($all_active_subjects as $subjects){
                                    $sub_count=$sub_count + 1;
                                    $subject_id=$subjects['id'];
                            ?>
                        <tr>
                            <th><?php echo $sub_count;?></th>
                            <th><?php echo $subjects['subject'];?></th>
                            <?php 
                            $exam_head_table='exam_heads_'.$acedemic_session.'';
                            $all_exam_heads=$this->NewExamModel->get_course_exam_heads($course_id,$exam_head_table);
                            if($all_exam_heads){
                                foreach($all_exam_heads as $exam_heads){
                                    $ehid=$exam_heads['id'];
                                    $elog_table='exam_log_'.$acedemic_session.'';
                                    $get_log_item_data=$this->NewExamModel->get_log_item_data($sid,$ehid,$subject_id,$elog_table);
                                    if($get_log_item_data){
                                        foreach($get_log_item_data as $elog_data){
                            ?>
                            <td>
                                <?php 
                                if($subjects['exam_type'] == 'Marks'){
                                    echo $elog_data['obtained_marks'];
                                }else if($subjects['exam_type'] == 'Grade'){
                                echo $elog_data['grade'];
                                }
                                ?>
                                
                            </td>
                            <?php
                                        }
                                    }else{
                            ?>
                            <td>---</td>                            
                            <?php
                                    }
                            ?>
                                                        
                            
                            <?php
                                }
                            }
                            ?>
                            <td>
                                --
                            </td>
                        </tr>    
                            <?php
                                }
                            }
                            ?>
                    </tbody>
                </table>
            </div>
                  
        </div>
    </div>
</div>


<script>
    $(document).ready(function(){
        $(".remark" ).change(function() {
            var remark = $(this).val();
        
            $(".remark-input").val(remark);
            // alert(remark);
            // $.ajax({
            //     url: '<?php echo base_url() ?>Welcome/change_ac_session',
            //     type: 'POST', 
            //     data: {ac_session_id:ac_session_id},
            //     success: function(data){
            //         // swal("Changed Successfully");
            //         location.reload(); 
            //     }
            // });
        });
        $(".add-remark").click(function(){
            var remark=$(".remark").val();
            var total_working_days=$(".total_working_days").val();
            var attendance=$(".attendance").val();
            var sid=$(".student_id").val();
            var exam_id=$(".exam_id").val();
            var course_id=$(".course_id").val();
            var course=$(".course").val();
            var roll_number=$(".roll_number").val();
            
            $.ajax({
                url: '<?php echo base_url(); ?>Examination/student_exam_data',
                type: 'POST', 
                data: {sid:sid,remark:remark,total_working_days:total_working_days,attendance:attendance,exam_id:exam_id,course_id:course_id,course:course,roll_number:roll_number},
                success: function(data){
                    swal(data);
                    // alert("Updated Successfully");
                    location.reload(); 
                }
            });
        });
    });
</script>