<?php
$sid=$this->uri->segment('3');
$acedemic_session=$this->session->userdata('acedemic_session');
$acedemic_session_table='academic_session_details';
$acedemic_session_data=$this->ExamManagementModel->get_item_data($acedemic_session,$acedemic_session_table);
$course_id='';
$course='';
$subject_stream='';


$table="student";
$get_student_data=$this->ExamManagementModel->get_student_combined_data($sid,$acedemic_session,$table);
if($get_student_data){
    foreach($get_student_data as $student){
        $course=$student['course'];
        $subject_stream=$student['subject_stream'];
        $course_id=$student['course_id'];
        $class=$student['scd_class'];
        $section=$student['scd_section'];


        $exam_subjects_table='exam_subject_master_'.$acedemic_session;
        $get_course_subjects=$this->ExamManagementModel->get_class_active_subjects($course,$exam_subjects_table);

        $student_subjects_table="student_subjects_".$acedemic_session;
?>

<style>
    .w_25_1{
        width:25%;
        float:left;
        /*padding:10px;*/
    }
    @media only screen and (max-width: 767px) {
        .w_25_1{
            width:100%;
        }
    }
</style>
<div class="container-fluid bg-white mt-3 mb-3">
    <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();?>ExamManagement">Exam</a></li>
                <li class="breadcrumb-item">Subject</li>
                <li class="breadcrumb-item">Allocate</li>
                
            </ul>
            
            <div class="profile-div text-center pb-3">
                <?php
                if($profile_pic !=''){
                ?>
                <img src="<?php echo base_url();?>student-data/profile-img/<?php echo $profile_pic;?>" style="border-radius:50%;width:200px;">
                <?php
                }else{
                ?>
                <img src="<?php echo base_url();?>assets/student-profile-pic.jpg" style="border-radius:50%;">
                <?php
                }
                ?>
            </div>
            
            <div class="table-responsive">
                <table class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <?php
                            if($acedemic_session_data){
                                foreach($acedemic_session_data as $session_data){
                            ?>
                            <th colspan="2" class="text-center">Personal Information (<?php echo $session_data['year_long']; ?>)</th>
                            <?php
                                }
                            }
                            ?>
                            
                        </tr>
                        <tr>
                            <th>Name</th>
                            <td><?php echo $student['student_name'];?></td>
                        </tr>
                        <tr>
                            <th>Father's Name</th>
                            <td><?php echo $student['father_name'];?></td>
                        </tr>
                        <tr>
                            <th>D.O.B.</th>
                            <td><?php if($student['dob']){echo date('d-M-Y',strtotime($student['dob']));}else{ echo "----";}?></td>
                        </tr>
                        <tr>
                            <th>Contact No.:</th>
                            <td><?php echo $student['contact_no']; if($alternate_no !=""){ echo " , "; } echo $student['alternate_no'];?></td>
                        </tr>
                        <tr>
                            <th>Address : </th>
                            <td><?php echo $student['address'];?></td>
                        </tr>
                        <tr>
                            <th>Class : </th>
                            <td><?php if($student['subject_stream'] !=""){ echo $student["course"].'-'.$student['subject_stream']; }else{ echo $student["course"]; } echo "-".$section; ?></td>
                        </tr>
                    </thead>
                </table>
            </div>
            
            
                <form method="post" action="#" class="mt-3">
                    <?php 
                    if($success){
                    ?>
                    <div class="alert alert-success"><?php echo $success; ?></div>
                    <?php
                    }
                    
                    if($error){
                    ?>
                    <div class="alert alert-danger"><?php echo $error; ?></div>
                    <?php
                    }
                    ?>
                
                    <table class="table table-bordered">
                        <tr>
                            
                            <th class="text-center">Update Student Subjects<?php // echo $course; echo " ";  echo $subject_stream;?></th>
                        </tr>
                        <tr>
                            
                            <td style="width:100%;">
                                <input type="hidden" name="sid" value="<?php echo $sid; ?>">
                                <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" name="class" value="<?php echo $student["course"]; ?>">
                                <input type="hidden" name="section" value="<?php echo $student['scd_section']; ?>">
                        <?php
                        if($get_course_subjects){
                            foreach($get_course_subjects as $subjects){
                                $subject_id=$subjects['id'];
                                $student_sub_count=0;
                                $get_subject_info=$this->ExamManagementModel->student_subject_info($sid,$acedemic_session,$subject_id,$student_subjects_table);
                                if($get_subject_info){
                                    $student_sub_count=$student_sub_count + 1;
                                }
                                
                            ?>
                        
                                
                                <div class="form-group w_25_1">
                                    <input type="checkbox" value="<?php echo $subjects['id'];?>" name="subject_item[]" id="subject_item" <?php if($student_sub_count == 1){ echo "checked";} ?> class="checkbox">&nbsp;&nbsp;<?php echo $subjects['subject']; ?>
                                </div>    
                                
                        <?php
                            }
                        }
                        ?>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="">
                                    <label><input type="checkbox" id="select_all" class="check_all_subjects"> Select All</label>
                                </div>    
                                
                                
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <div class="" style="display:inline-block;width:100% !important;">
                                    <button class="btn btn-sm btn-success" name="allot_subjects" type="submit">Allot Subjects        </button>
                                </div>
                            </td>
                        </tr>
                    </table>
                
                    
                </form>
            
        </div>
    </div>    
</div>    
<?php

    }
}else{
    echo "Error";
}
?>
<script>
    $(document).ready(function(){
        // alert();        
        $('#select_all').on('click',function(){
            if(this.checked){
                $('.checkbox').each(function(){
                    this.checked = true;
                });
            }else{
                $('.checkbox').each(function(){
                    this.checked = false;
                });
            }
        });
    });
</script>