<style>
.month-item{
    width:25%;float:left;font-weight:600;
}
</style>
<?php 
$sid=$this->uri->segment('3');
$active_acedemic_session='';
$aceemic_session_table='academic_session_details';
$get_active_acedemic_session=$this->TransportModel->get_data($aceemic_session_table);
if($get_active_acedemic_session){
    foreach($get_active_acedemic_session as $acedemic_sesion_data){
        if($acedemic_sesion_data['status'] ==1){
            $active_acedemic_session=$acedemic_sesion_data['id'];
        }        
    }
}


$vehicle_no='';
$fare='';
$route_no='';
$extra_fare='';

$apr_status=0;
$may_status=0;
$jun_status=0;
$jul_status=0;
$aug_status=0;
$sep_status=0;
$oct_status=0;
$nov_status=0;
$dec_status=0;
$jan_status=0;
$feb_status=0;
$mar_status=0;

$user_exist=0;

$get_student_route_info=$this->TransportModel->get_student_info_for_ac_sesssion($sid,$active_acedemic_session);
if($get_student_route_info){
    foreach($get_student_route_info as $student_route_info){
        
        $user_exist=$user_exist + 1;
        
        $vehicle_no=$student_route_info['vehicle_no'];
        $route_no=$student_route_info['route_no'];
        $fare=$student_route_info['fare'];
        $extra_fare=$student_route_info['extra_fare'];
        
        $apr_status=$student_route_info['april'];
        $may_status=$student_route_info['may'];
        $jun_status=$student_route_info['june'];
        $jul_status=$student_route_info['july'];
        $aug_status=$student_route_info['august'];
        $sep_status=$student_route_info['september'];
        $oct_status=$student_route_info['october'];
        $nov_status=$student_route_info['november'];
        $dec_status=$student_route_info['december'];
        $jan_status=$student_route_info['january'];
        $feb_status=$student_route_info['february'];
        $mar_status=$student_route_info['march'];
        
    }
}



$student_table='student';
$course_id='';
$get_student_info=$this->TransportModel->get_item_data($sid,$student_table);
if($get_student_info){
    foreach($get_student_info as $student_info){
        $get_student_course_info=$this->TransportModel->student_session_info($sid,$active_acedemic_session);
        if($get_student_course_info){
            foreach($get_student_course_info as $student_course_info){
                $course_id=$student_course_info['course_id'];
            }
        }
        
        $subject_stream='';
        $course='';
        $courses_table='courses';
        $get_course_info=$this->TransportModel->get_item_data($course_id,$courses_table);
        foreach($get_course_info as $course_info){
            $course=$course_info['course'];
            $subject_stream=$course_info['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();?>Transport">Transport</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Transport/list_student">All Students</a></li>
                <li class="breadcrumb-item"><a href="<?php echo base_url();?>Transport/students">Students</a></li>
                <li class="breadcrumb-item"><a href="#">Add Student</a></li>
            </ul>
        </div>
        
        <div class="col-sm-12">
            
            <ul class="nav nav-tabs tab-item-1">
                <li class="nav-item">
                    <a class="nav-link" href="<?php echo base_url();?>Transport/students">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-list-ol" viewBox="0 0 16 16">
                            <path fill-rule="evenodd" d="M5 11.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5zm0-4a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5z"/>
                            <path d="M1.713 11.865v-.474H2c.217 0 .363-.137.363-.317 0-.185-.158-.31-.361-.31-.223 0-.367.152-.373.31h-.59c.016-.467.373-.787.986-.787.588-.002.954.291.957.703a.595.595 0 0 1-.492.594v.033a.615.615 0 0 1 .569.631c.003.533-.502.8-1.051.8-.656 0-1-.37-1.008-.794h.582c.008.178.186.306.422.309.254 0 .424-.145.422-.35-.002-.195-.155-.348-.414-.348h-.3zm-.004-4.699h-.604v-.035c0-.408.295-.844.958-.844.583 0 .96.326.96.756 0 .389-.257.617-.476.848l-.537.572v.03h1.054V9H1.143v-.395l.957-.99c.138-.142.293-.304.293-.508 0-.18-.147-.32-.342-.32a.33.33 0 0 0-.342.338v.041zM2.564 5h-.635V2.924h-.031l-.598.42v-.567l.629-.443h.635V5z"/>
                        </svg> All Students</a>
                </li>
                
                <li class="nav-item">
                    <a class="nav-link" href="<?php echo base_url();?>Transport/list_student">
                        <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
                            <path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3v-3z"/>
                        </svg>  Add New Student
                    </a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">Update Route And Fare</a>
                </li>
                
            </ul>   
            <form method="post" action="#" class="form-outer">
                <div>
                <?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
                }
                ?>
                <div class="form-group w-50">
                    <label>Student Name</label>
                    <input type="hidden" name="sid" value="<?php echo $sid;?>">
                    <input type="text" name="student_name" class="form-control" value="<?php echo $student_info['student_name'];?>" readonly>
                </div>    
                
                <div class="form-group w-50">
                    <label>Father's Name</label>
                    <input type="text" name="father_name" class="form-control" value="<?php echo $student_info['father_name'];?>" readonly>
                </div>
                
                <div class="form-group w-50">
                    <label>Residence Address</label>
                    <input type="text" class="form-control" name="student_address" value="<?php echo htmlspecialchars_decode($student_info['address']);?>">
                </div>
                
                <div class="form-group w-50">
                    <label>Course</label>
                    <input type="text" name="course_info" value="<?php echo $course; echo " "; echo $subject_stream;?>" class="form-control" readonly>
                </div>
                
                <div class="form-group w-50">
                    <label>Add Route</label>
                    <select class="form-control" name="route_id" id="route_id">
                        <option>-- Select Transport Route --</option>
                        <?php
                        $routes_table='transport_routes';
                        $all_routes=$this->TransportModel->get_data($routes_table);
                        if($all_routes){
                            foreach($all_routes as $routes){
                        ?>
                        <option value="<?php echo $routes['id'];?>" <?php if($routes['id'] == $route_no){echo "selected";} ?>><?php echo $routes['route_title']; echo " (Route Fare: "; echo $routes['route_fare']; echo ")";?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group w-50">
                    <label>Route Fare</label>
                    <input type="number" name="route_fare" id="route_fare" value="<?php if($user_exist == 1){ echo $fare;} ?>" class="form-control" placeholder="Route Fare" readonly>
                </div>
                
                <div class="form-group w-50">
                    <label>Extra Route Fare</label>
                    <input type="number" name="extra_route_fare" id="extra_route_fare" value="<?php if($user_exist == 1){ echo $extra_fare;} ?>" class="form-control" placeholder="Extra Route Fare" >
                </div>
                
                <div class="form-group w-50">
                    <label>Vehicle</label>
                    <select class="form-control" name="vehicle_id">
                        <option value="">-- Select Vehicle --</option>
                        <?php
                        $tranport_vehicles='transport_vehicle';
                        $all_vehicles=$this->TransportModel->get_data($tranport_vehicles);
                        if($all_vehicles){
                            foreach($all_vehicles as $vehicles){
                        ?>
                        <option value="<?php echo $vehicles['id'];?>" <?php if($vehicles['id'] == $vehicle_no){echo "selected";}?>><?php echo $vehicles['vehicle_number'];?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
                
                <div class="form-group w-100">
                    <div class="month-item"><input type="checkbox" name="apr_status" value="1" <?php if($apr_status == 1){echo "checked";} ?>  class="checkbox"> Apr </div>
                    <div class="month-item"><input type="checkbox" name="may_status" value="1" <?php if($may_status == 1){echo "checked";} ?>  class="checkbox"> May </div>
                    <div class="month-item"><input type="checkbox" name="jun_status" value="1" <?php if($jun_status == 1){echo "checked";} ?>  class="checkbox"> Jun </div>
                    <div class="month-item"><input type="checkbox" name="jul_status" value="1" <?php if($jul_status == 1){echo "checked";} ?>  class="checkbox"> Jul </div>
                    <div class="month-item"><input type="checkbox" name="aug_status" value="1" <?php if($aug_status == 1){echo "checked";} ?>  class="checkbox"> Aug </div>
                    <div class="month-item"><input type="checkbox" name="sep_status" value="1" <?php if($sep_status == 1){echo "checked";} ?>  class="checkbox"> Sep </div>
                    <div class="month-item"><input type="checkbox" name="oct_status" value="1" <?php if($oct_status == 1){echo "checked";} ?>  class="checkbox"> Oct </div>
                    <div class="month-item"><input type="checkbox" name="nov_status" value="1" <?php if($nov_status == 1){echo "checked";} ?>  class="checkbox"> Nov </div>
                    <div class="month-item"><input type="checkbox" name="dec_status" value="1" <?php if($dec_status == 1){echo "checked";} ?>  class="checkbox"> Dec </div>
                    <div class="month-item"><input type="checkbox" name="jan_status" value="1" <?php if($jan_status == 1){echo "checked";} ?>  class="checkbox"> Jan </div>
                    <div class="month-item"><input type="checkbox" name="feb_status" value="1" <?php if($feb_status == 1){echo "checked";} ?>  class="checkbox"> Feb </div>
                    <div class="month-item"><input type="checkbox" name="mar_status" value="1" <?php if($mar_status == 1){echo "checked";} ?>  class="checkbox"> Mar </div>
                    
                </div>
                <div class="w-100">
                    
                    <input type="checkbox" name="check_all" id="select_all">
                    <label>Check All</label>
                </div>
                <div class="form-group w-100">
                    <button class="btn btn-sm btn-success mt-3" type="submit" name="add_new_student">Submit</button>
                </div>
                </div>
            </form>
        </div>
        <div class="col-sm-12 pt-3 pb-3">
            <?php $this->load->view('erp/transport/quick-links');?>
        </div>
    </div>
</div>

<script>
    // function myFunction(){
    //     // alert("Hi");
    //     var route_id=
        
        
    // }
    $(document).ready(function(){
        $('#route_id').on('change',function(){   
            var route_id=this.value;
            $.ajax({
                url: '<?php echo base_url() ?>Transport/get_route_fee',
                type: 'POST', 
                data: {route_id:route_id},
                success: function(data){
                    $("#route_fare").val(data);
                    alert(data);
                }
            });
        });
    });
</script>
<?php
    }
}
?>

<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>