<style>
    body{background:#EAEDED;}
    #student_status{width:30%;float:left;}
    .in-activate{float:left;}
    .student_status{box-shadow: 0 0 1px silver;padding:15px;margin:10px;}
    @media only screen and (max-width: 500px){
        .p-1{width:100%;float:left;}
        #student_status{width:70%;float:left;}    
    }
    a{color:black;}
    a:hover{text-decoration:none;}
    .form-control-1{
        padding:7px;
    }
    
    .bsd-div{
        box-shadow:4px 4px 8px silver;
        display:inline-block;
        width:100%;
        padding:15px;
        border-radius:15px;
    }
</style>
<div class="container-fluid user-dashboard mt-3 mb-3 bg-white">
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
    
            <ul class="breadcrumb">
                <!--<li class="breadcrumb-item"><?php echo $this->session->userdata('ac_year'); ?></li> -->
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>Welcome">Home</a></li> 
                <li class="breadcrumb-item"><a href="<?php echo base_url(); ?>School/students_academic_session_wise">all Student</a></li> 
                <li class="breadcrumb-item">Student Profile</li>
            </ul>    
        </div>
    </div>

    <div class="row">
        <div class="col-sm-12 mt-3 mb-3 pt-3 pb-3">
            <div class="bsd-div">
        <?php
        $table='student';
        $sid=$this->uri->segment('3');
        $data_student = $this->WelcomeModel->get_item_data($sid,$table);
        if($data_student){
            $count = 1;
            foreach($data_student as $records){
        ?>
        
                <div class="">
                    <label>Current Status 
                    <?php
                    if($records['status']==1){
                    ?>
                    <span class="badge badge-success badge-pill">Active</span>
                    <?php
                    }else if($records['status']==0){
                    ?>
                    <span class="badge badge-danger badge-pill"><?php echo $records['status_description']; ?></span>
                    <?php
                    }
                    ?>
                    </label>    
                </div>    
                <hr>
            

                <?php 
                if($records['status']==1){
                ?>
                <div class="form-group">
                    <select id="student_status" class="form-control-1">
                        <option value="">Select reason</option>    
                        <option value="Fee Defaulter">Fee Defaulter</option>
                        <option value="TC Awarded">TC Awarded</option>
                        <option value="Absconding">Absconding</option>
                        <option value="Suspended">Suspended</option>
                        <option value="Terminated">Terminated</option>
                    </select>
                    <button class="btn btn-sm btn-danger activate ml-3" active_attr="1" db_id="<?php echo $records['id'];?>">In Active</button>    
                </div>  
                <?php
                }else if($records['status']==0){
                ?>
                <div class="form-group">
                    <select id="student_status" class="form-control-1">
                        <option value="Active">Change Status to Active</option>    
                        <!--<option>Fee Defaulter</option>-->
                        <!--<option>TC Awarded</option>-->
                        <!--<option>Absconding</option>-->
                        <!--<option>Suspended</option>-->
                        <!--<option>Terminated</option>-->
                    </select>
                    <button class="btn btn-sm btn-success activate  ml-3" active_attr="0" db_id="<?php echo $records['id'];?>">Active </button>    
                </div>

        <?php
                }
            }
        }
        ?>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12 pt-3 pb-3">
            <?php
            $table="student";
            $data_student = $this->WelcomeModel->get_item_data($sid,$table);
            if($data_student){
                $count = 1;
                foreach($data_student as $records){
            ?>
            <div class="table-responsive">
                <table class="table table-bordered table-striped bg-white">
                    <!--<thead>-->
                        <!--<tr><th></th></tr>    -->
                    <!--</thead>    -->
                    <tbody>
                        <tr>
                            <td>Student Name : <b><?php echo $records['student_name'];?></b></td>
                            <td>Father's Name : <b><?php echo $records['father_name'];?></b></td>
                        </tr>
                        <tr>
                            <td>Scholar No. : <b><?php echo $records['sch_no'];?></b></td>
                        <?php
                        $acedemic_session=$this->session->userdata('acedemic_session');
                        $get_student_info=$this->WelcomeModel->get_student_in_acedemic_session($sid,$acedemic_session);
                        if($get_student_info){
                            foreach($get_student_info as $student_info){
                                $student_class =$student_info['class'];   
                            }
                        }
                        ?>
                            <td>Class : <b><?php echo $student_class."-".$records['section'];?></b></td>
                        </tr>
                        <tr>
                            <td>D.O.B. : <b><?php echo date('d-m-Y',strtotime($records['dob']));?></b></td>
                            <td>Contact No. : <b><?php echo $records['contact_no'];?></b></td>
                        </tr>
                        <tr>
                            <td>Alternate No. : <b><?php echo $records['alternate_no']; ?></b></td>
                            <td>Address : <b><?php echo $records['address'];?></b></td>
                        </tr>
                        <tr>
                            <td>Admission Date : <b><?php echo date('d-m-Y',strtotime($records['admission_date']));?></b></td>
                            <td></td>
                        </tr>
                    </tbody>
                </table>    
            </div>

        <?php
            }
        }
        ?>

        </div>
    </div>
</div>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script>
$(document).ready(function(){
    $(document).on("click",".activate",function(){
        var val = $(this).attr("active_attr");
        var id = $(this).attr("db_id");

        var reason=$("#student_status").val();
        if(reason==""){
            swal("Select Apropriate Reason");    
        }else{
            var table = 'student';   
            // alert(reason);    
            $.ajax({
                url: '<?php echo base_url(); ?>management/active_inactive_student',
                type: 'POST',
                data:{ val:val,id:id, table:table,reason:reason},
                success: function(data){
                    location.reload();
                }
            });
        }
    });    
});    
</script>