<style>
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
}
form{
    display:inline-block;
    width:100%;
}
.form-group{

    padding:15px;
}

.w-50{
    width:50%;
    float:left;    
}
</style>

<?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 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-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>
            
            
            <?php 
            $student_table='student';
            $get_student_data=$this->NewExamModel->get_item_data($sid,$student_table);
            if($get_student_data){
                foreach($get_student_data as $student_data){
            ?>

            
            
            <form method="post" action="#" style="box-shadow:0 0 5px silver;padding:20px;">
                <div class="form-group">
                    <label>Student Name</label>
                    <input type="text" value="<?php echo $student_data['student_name'];?>" class="form-control" readonly>
                </div>
                <div class="form-group">
                    <label>Father's Name</label>
                    <input type="text" value="<?php echo $student_data['father_name'];?>" class="form-control" readonly>
                </div>
                <div class="form-group">
                    <label>Course</label>
                    <input type="text" name="course_info" id="course_info" value="<?php echo $course; echo " "; echo $subject_stream;?>" class="form-control" readonly>
                </div>
                    
            </form>
            
      
            <?php
                }
            }
            ?>


<?php
// $this->load->view('erp/exam/new/student-profile');
?>



    <!--<div class="row">-->
    <!--    <div class="col-sm-12">-->
            <form method="post" action="#">
                <?php 
                if($success){
                ?>
                <div class="alert alert-success"><?php echo $success; ?></div>
                <?php
                }
                ?>
                
            
            
                <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>Edit</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'){
                                    if($exam_heads['freeze'] == 1){
                                    ?>
                                    <input type="hidden" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="<?php echo $elog_data['obtained_marks']; ?>" class="form-control" >
                                    <?php echo $elog_data['obtained_marks']; ?>
                                    <?php
                                    }else{
                                    ?>
                                    <input type="number" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="<?php echo $elog_data['obtained_marks']; ?>" class="form-control" max="<?php echo $exam_heads['mm']; ?>">
                                    <?php
                                    }
                                ?>
                                
                                <?php 
                                    
                                }else if($subjects['exam_type'] == 'Grade'){
                                    if($exam_heads['freeze'] == 1){
                                    ?>
                                    <input type="hidden" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="<?php echo $elog_data['grade']; ?>" class="form-control">    
                                    <?php echo $elog_data['grade']; ?>
                                    <?php
                                    }else{
                                    ?>
                                    <input type="text" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="<?php echo $elog_data['grade']; ?>" class="form-control">    
                                    <?php
                                    }
                                ?>
                                
                                <?php
                                        // echo $elog_data['grade'];
                                }
                                ?>
                                
                            </td>
                            <?php
                                        }
                                    }else{
                            ?>
                            <td>
                                <?php
                                if($subjects['exam_type'] == 'Marks'){
                                ?>
                                <input type="number" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="" class="form-control" max="<?php echo $exam_heads['mm']; ?>">
                                <?php
                                }else if($subjects['exam_type'] == 'Grade'){
                                ?>
                                <input type="text" name="<?php echo  "s_".$subject_id."_h_".$ehid; ?>" value="" class="form-control">
                                <?php
                                }
                                ?>
                                </td>                            
                            <?php
                                    }
                            ?>
                                                        
                            
                            <?php
                                }
                            }
                            ?>
                            <!--<td>-->
                            <!--    <a href="<?php echo base_url();?>Examination/add_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>-->
                            <!--</td>-->
                        </tr>    
                            <?php
                                }
                            }
                            ?>
                    </tbody>
                </table>
                </div>
                <input type="hidden" name="sid" value="<?php echo $sid;?>" >
                <input type="hidden" name="course_id" value="<?php echo $course_id;?>" >
                <div class="form-group">
                    <button type="submit" name="add_exam_log" class="btn btn-sm  btn-success mt-3">Submit</button>
                </div>
            </form>  
        </div>
    </div>

    <?php 
    $exam_id='3';
    $course_exam_data_table='exam_course_data';
    $get_exam_course_data=$this->NewExamModel->check_course_exam_data($exam_id,$course_id,$course_exam_data_table);
    $total_working_days=0;
    if($get_exam_course_data){
        foreach($get_exam_course_data as $exam_data){
            $total_working_days=$exam_data['working_days'];
        }
    }


    $attendance_days=0;
    $remark='';
    $roll_no="";
    $result_table='exam_result';
    $check_student_exam_data=$this->NewExamModel->get_student_exam_data($sid,$exam_id,$course_id,$result_table);
    if($check_student_exam_data){
        foreach($check_student_exam_data as $exam_data){
            $attendance_days=$exam_data['attendance_days'];
            $remark=$exam_data['remark'];
            $roll_no=$exam_data['roll_no'];
        }
    }
    ?>
    <!--<div class="container bg-white">-->
    <div class="row">
        <div class="col-sm-12 pb-3">
            <form style="box-shadow:0 0 5px silver;padding:25px;">
                <h1 class="text-center" style="font-size:22px;font-weight:700;">Update First Term Exam Data</h1><hr>
                <div class="form-group w-50">
                    <label>First Term Working Days</label>
                    <input type="number" value="<?php echo $total_working_days; ?>" name="total_working_days" class="form-control total_working_days" readonly>
                    <input type="hidden" class="student_id" value="<?php echo $sid;?>">
                    <input type="hidden" class="exam_id" value="<?php echo $exam_id;?>">
                    <input type="hidden" class="course_id" value="<?php echo $course_id; ?>">
                    <input type="hidden" class="course" value="<?php echo $course." ".$subject_stream; ?>">
                    
                </div>
                <div class="form-group w-50">
                    <label>First Term Attendance</label>
                    <input type="number" name="attendance" class="form-control attendance" placeholder="Enter Present Days" value="<?php echo $attendance_days; ?>">
                </div>
                
                <div class="form-group">
                    <label>First Term Remark</label>
                    <select class="form-control remark">
                        <option value="">-- Select Remark --</option>
                        <?php 
                        $remark_table='exam_quote_list';
                        $all_remarks=$this->NewExamModel->get_data($remark_table);
                        if($all_remarks){
                            foreach($all_remarks as $remark_data){
                        ?>
                        <option value="<?php echo $remark_data['quote']; ?>" <?php if($remark == $remark_data['quote']){ echo "selected"; } ?> ><?php echo $remark_data['quote']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group">
                    <input type="text" name="remark" class="form-control remark-input" value="<?php if($remark !=''){ echo $remark; } ?>" placeholder="Enter Remark">
                </div>
                
                <div class="form-group">
                    <label>Roll Number :</label>
                    <input type="text" name="roll_number" class="form-control roll_number" placeholder="Roll Number" value="<?php echo $roll_no; ?>">
                </div>
                
                
                
                <div class="form-group">
                    <button class="btn btn-sm btn-success add-remark" type="button">Submit</button>
                </div>
            </form>
        </div>
    </div>
<!--</div>-->

<?php
$second_term_exam_id=1;
$second_term_remark="";
$second_term_attendance_days=0;

$result_table='exam_result';
$check_student_exam_data=$this->NewExamModel->get_student_exam_data($sid,$second_term_exam_id,$course_id,$result_table);
if($check_student_exam_data){
    foreach($check_student_exam_data as $exam_data){
        $second_term_attendance_days=$exam_data['attendance_days'];
        $second_term_remark=$exam_data['remark'];
        $roll_no=$exam_data['roll_no'];
    }
}


$course_exam_data_table='exam_course_data';
$get_exam_course_data=$this->NewExamModel->check_course_exam_data($second_term_exam_id,$course_id,$course_exam_data_table);
$second_term_total_working_days=0;
if($get_exam_course_data){
    foreach($get_exam_course_data as $exam_data){
        $second_term_total_working_days=$exam_data['working_days'];
    }
}
?>
<!--<div class="container bg-white mt-3">-->
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <form style="box-shadow:0 0 5px silver;padding:25px;">
                <h1 class="text-center" style="font-size:22px;font-weight:700;">Update Second Term Exam Data</h1><hr>
                <div class="form-group w-50">
                    <label>Second Term Working Days</label>
                    <input type="number" value="<?php echo $second_term_total_working_days; ?>" name="total_working_days" class="form-control second_term_total_working_days" readonly>
                    <input type="hidden" class="student_id" value="<?php echo $sid;?>">
                    <input type="hidden" class="second_term_exam_id" value="<?php echo $second_term_exam_id; ?>">
                    <input type="hidden" class="course_id" value="<?php echo $course_id; ?>">
                    <input type="hidden" class="course" value="<?php echo $course." ".$subject_stream; ?>">
                    
                </div>
                <div class="form-group w-50">
                    <label>Second Term Attendance</label>
                    <input type="number" name="attendance" class="form-control second_term_attendance" placeholder="Enter Present Days" value="<?php echo $second_term_attendance_days; ?>">
                </div>
                
                <div class="form-group">
                    <label>Second Term Remark</label>
                    <select class="form-control second-term-remark">
                        <option value="">-- Select Remark --</option>
                        <?php 
                        $remark_table='exam_quote_list';
                        $all_remarks=$this->NewExamModel->get_data($remark_table);
                        if($all_remarks){
                            foreach($all_remarks as $remark_data){
                        ?>
                        <option value="<?php echo $remark_data['quote']; ?>" <?php if($second_term_remark == $remark_data['quote']){ echo "selected"; } ?> ><?php echo $remark_data['quote']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group">
                    <input type="text" name="remark" class="form-control second-term-remark-input" value="<?php if($second_term_remark !=''){ echo $second_term_remark; } ?>" placeholder="Enter Remark">
                </div>
                
                <div class="form-group">
                    <label>Roll Number :</label>
                    <input type="text" name="roll_number" class="form-control second_term_roll_number" placeholder="Roll Number" value="<?php echo $roll_no; ?>">
                </div>
                
                
                
                <div class="form-group">
                    <button class="btn btn-sm btn-success add-second-term-remark" type="button">Submit</button>
                </div>
            </form>
        </div>
    </div>
    
<?php
$annual_exam_id=4;
$annual_remark="";
$annual_attendance_days=0;

$result_table='exam_result';
$check_student_exam_data=$this->NewExamModel->get_student_exam_data($sid,$annual_exam_id,$course_id,$result_table);
if($check_student_exam_data){
    foreach($check_student_exam_data as $exam_data){
        $annual_attendance_days=$exam_data['attendance_days'];
        $annual_remark=$exam_data['remark'];
        $roll_no=$exam_data['roll_no'];
    }
}


$course_exam_data_table='exam_course_data';
$get_exam_course_data=$this->NewExamModel->check_course_exam_data($annual_exam_id,$course_id,$course_exam_data_table);
$annual_total_working_days=0;
if($get_exam_course_data){
    foreach($get_exam_course_data as $exam_data){
        $annual_total_working_days=$exam_data['working_days'];
    }
}
?>
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <form style="box-shadow:0 0 5px silver;padding:25px;">
                <h1 class="text-center" style="font-size:22px;font-weight:700;">Update Annual Exam Data</h1><hr>
                <div class="form-group w-50">
                    <label>Annual Working Days</label>
                    <input type="number" value="<?php echo $annual_total_working_days; ?>" name="total_working_days" class="form-control annual_total_working_days" readonly>
                    <input type="hidden" class="student_id" value="<?php echo $sid;?>">
                    <input type="hidden" class="annual_exam_id" value="<?php echo $annual_exam_id; ?>">
                    <input type="hidden" class="course_id" value="<?php echo $course_id; ?>">
                    <input type="hidden" class="course" value="<?php echo $course." ".$subject_stream; ?>">
                    
                </div>
                <div class="form-group w-50">
                    <label>Annual Attendance</label>
                    <input type="number" name="attendance" class="form-control annual_attendance" placeholder="Enter Present Days" value="<?php echo $annual_attendance_days; ?>">
                </div>
                
                <div class="form-group">
                    <label>Annual Remark</label>
                    <select class="form-control annual-remark">
                        <option value="">-- Select Remark --</option>
                        <?php 
                        $remark_table='exam_quote_list';
                        $all_remarks=$this->NewExamModel->get_data($remark_table);
                        if($all_remarks){
                            foreach($all_remarks as $remark_data){
                        ?>
                        <option value="<?php echo $remark_data['quote']; ?>" <?php if($annual_remark == $remark_data['quote']){ echo "selected"; } ?> ><?php echo $remark_data['quote']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group">
                    <input type="text" name="remark" class="form-control annual-remark-input" value="<?php if($annual_remark !=''){ echo $annual_remark; } ?>" placeholder="Enter Remark">
                </div>
                
                <div class="form-group">
                    <label>Roll Number :</label>
                    <input type="text" name="roll_number" class="form-control annual_roll_number" placeholder="Roll Number" value="<?php echo $roll_no; ?>">
                </div>
                
                
                
                <div class="form-group">
                    <button class="btn btn-sm btn-success add-annual-remark" type="button">Submit</button>
                </div>
            </form>
        </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-input").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(); 
                }
            });
        });
        
        
        $(".second-term-remark" ).change(function() {
            var remark = $(this).val();
            $(".second-term-remark-input").val(remark);
        });
        

        $(".add-second-term-remark").click(function(){
            var remark=$(".second-term-remark-input").val();
            var total_working_days=$(".second_term_total_working_days").val();
            var attendance=$(".second_term_attendance").val();
            var sid=$(".student_id").val();
            var exam_id=$(".second_term_exam_id").val();
            var course_id=$(".course_id").val();
            var course=$(".course").val();
            var roll_number=$(".second_term_roll_number").val();
            // alert(exam_id);
            $.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(); 
                }
            });
        });
        
        $(".annual-remark").change(function(){
            var remark = $(this).val();
            $(".annual-remark-input").val(remark);
        });
        
        $(".add-annual-remark").click(function(){
            var remark=$(".annual-remark-input").val();
            var total_working_days=$(".annual_total_working_days").val();
            var attendance=$(".annual_attendance").val();
            var sid=$(".student_id").val();
            var exam_id=$(".annual_exam_id").val();
            var course_id=$(".course_id").val();
            var course=$(".course").val();
            var roll_number=$(".annual_roll_number").val();
            // alert(exam_id);
            $.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>