<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Students extends Admin_Core_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('user_model', 'user');
    }

    function all_enquiry()
    {
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_students'] = $this->user->get_all_enquiry_student_for_atp(user_id());
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/all_enquiry');
        $this->load->view('admin/include/footer');
    }

    function add_new_enquiry()
    {
        $atp_id = user_id();
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        // if(check_atp_programm() == true)
        // {
        $data['all_course'] = $this->course->get_all_course_for_admission_by_atp_id(user_id());
        // }
        // else
        // {
        //     $data['all_course'] = $this->course->get_all_course_for_admission_for_premium_prg();
        // }
        $data['all_employee'] = $this->user->get_all_employee_by_id($atp_id);
        $data['all_lead'] = $this->setting_model->get_all_lead_source();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/add_new_enquiry');
        $this->load->view('admin/include/footer');
    }

    function add_enquiry()
    {
        if ($this->user->add_enquiry()) {
            $this->session->set_userdata('success', "Enquiry Successfully Added");
            redirect(base_url().'admin/students/all_enquiry');
        } else {
            $this->session->set_userdata('error', "Enquiry Added Faild");
            redirect($this->agent->referrer());
        }
    }

    function edit_enquiry($id)
    {
        $this->load->model('course_model', 'course');
        $atp_id = user()->user_id;
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_course'] = $this->course->get_all_course_for_admission_by_atp_id(user_id());
        $data['all_employee'] = $this->user->get_all_employee_by_id($atp_id);
        $data['all_lead'] = $this->setting_model->get_all_lead_source();
        $data['enquiry'] = $this->user->get_student_enquiry_by_id($id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/edit_enquiry');
        $this->load->view('admin/include/footer');
    }

    function update_enquiry($id)
    {
        if ($this->user->update_enquiry($id)) {
            $this->session->set_userdata('success', "Enquiry Successfully Updated");
            redirect(base_url().'admin/students/all_enquiry');
        } else {
            $this->session->set_userdata('error', "Enquiry Updated Faild");
            redirect($this->agent->referrer());
        }
    }

    function change_enquiry_status()
    {
        if ($this->user->change_enquiry_status()) {
            $this->session->set_userdata('success', "Status Successfully Changed");
            redirect(base_url().'admin/students/all_enquiry');
        } else {
            $this->session->set_userdata('error', "Status Changed Faild");
            redirect($this->agent->referrer());
        }
    }

    function all_followup($id)
    {
        $atp_id = user_id();

        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_followup'] = $this->user->get_all_followup_student_for_atp($id, $atp_id);
        $data['all_mode'] = $this->setting_model->get_all_followup_mode();
        $data['student_id'] = $id;
        $data['studnt_details'] = $this->user->get_student_enquiry_by_id($id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/all_followup');
        $this->load->view('admin/include/footer');
    }

    function add_new_follow_up_details($student_id, $atp_id)
    {
        if ($this->user->add_new_follow_up_details(user()->user_id, $student_id, $atp_id)) {
            $this->session->set_userdata('success', "Follow Up Details Successfully Added");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Follow Up Details Added Faild");
            redirect($this->agent->referrer());
        }
    }

    function admitted_student()
    {
        $atp_id = user()->user_id;
        $this->load->model('course_model', 'course');
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_students'] = $this->user->get_all_admintted_student($atp_id);
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/admitted_student');
        $this->load->view('admin/include/footer');
    }

    function pay_student_admission_fee($student_id)
    {
        $atp_id = user()->user_id;
        if ($this->user->pay_student_admission_fee($atp_id, $student_id)) {
            $this->session->set_userdata('success', "Student Successfully Admitted");
            redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Student Admitted Faild, You Dont Have Sufficent Wallet Balance");
            redirect($this->agent->referrer());
        }
    }

    function take_admission($id)
    {
        $this->load->model('course_model', 'course');
        $atp_id = user_id();
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['student'] = $this->user->get_student_by_id_and_atp_id($id, $atp_id);
        
        // if(check_atp_programm() == true)
        // {
            $data['all_course'] = $this->course->get_all_course_for_admission_by_atp_id(user_id());
            $this->load->view('admin/include/header', $data);
            $this->load->view('admin/student/edit_admitted_student');
            $this->load->view('admin/include/footer');
        // }
        // else
        // {
        //     $data['all_course'] = $this->course->get_all_course_for_admission_for_premium_prg();
        //     $this->load->view('admin/include/header', $data);
        //     $this->load->view('admin/student/edit_admitted_student_for_premium');
        //     $this->load->view('admin/include/footer');
        // }
        
    }

    function update_adminssion_student($id)
    {
        $atp_id = user()->user_id;

        if ($this->user->update_adminssion_student($id, $atp_id)) {
            $this->session->set_userdata('success', "Student Successfully Updated");
            redirect(base_url().'admin/students/admitted_student');
        } else {
            $this->session->set_userdata('error', "Student Updated Faild");
            redirect($this->agent->referrer());
        }
    }

    function assign_batch()
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_batch'] = $this->setting_model->get_all_batch();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/assign_student');
        $this->load->view('admin/include/footer');
    }

    function get_batch_details_by_batch_id($id)
    {
        $this->db->where('batch_id', $id);
        $batch_data = $this->db->get('student_batch')->row();

        $this->db->select('a.*, b.user_name, b.user_reg_id, b.user_mobile');
        $this->db->from('student_course a');
        $this->db->join('users b', 'b.user_id = a.st_course_student_id');
        $this->db->where('a.st_course_status >', 1);
        $this->db->where('a.st_course_course_id', $batch_data->batch_course);
        $all_data = $this->db->get()->result();

        $result = '';
        foreach ($all_data as $data) 
        {
            $result .= '
                <tr>
                    <td>'.$data->user_name.'</td>
                    <td>'.$data->user_reg_id.'</td>
                    <td>'.$data->user_mobile.'</td>
                    <td><input '.(($id==$data->st_course_batch)?'checked="checked"':"").' type="checkbox" name="batch[]" class="form-control check-box" style="height:15px!important;" value="'.$data->st_course_id.'">
                    <input type="hidden" name="u_id[]" value='.$data->st_course_id.'>
                    </td>
                </tr>
            ';
        }

        // echo '<pre>';
        // print_r($result);
        echo json_encode($result);
    }

    function add_new_batch()
    {

        if ($this->user->add_new_batch()) {
            $this->session->set_userdata('success', "Batch Successfully Added");
             redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Batch Added Faild");
             redirect($this->agent->referrer());
        }
    }

    function get_course_by_student_id_for_add_installment($id)
    {
        $this->db->select('a.*, b.id, b.title, b.discounted_price, b.price');
        $this->db->from('student_course a');
        $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
        $this->db->where('a.st_course_student_id', $id);
        $this->db->where('a.st_course_status >', 1);
        $this->db->where('a.st_course_batch > ', 0);
        $this->db->where('a.st_is_course_payment_complete', 0);
        $all_data = $this->db->get()->result();

        $data_all = [];
        $option = '<option value="">Select Course From List</option>';
        $price = 0;
        foreach ($all_data as $data) 
        {
            if($data->discount_flag == 1)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->price;
            }
            
            $option .= '<option value="'.$data->id.'">'.$data->title.'</option>';
            $price_data .= $price;
        }

        $data_all = [
            'option' => $option,
        ];

        echo json_encode($data_all);
    }

    function get_course_by_student_id($id)
    {
        $this->db->select('a.*, b.id, b.title, b.discounted_price, b.course_price');
        $this->db->from('student_course a');
        $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
        $this->db->where('a.st_course_student_id', $id);
        $this->db->where('a.st_course_status !=', 0);
        $all_data = $this->db->get()->result();

        $data_all = [];
        $option = '<option value="">Select Course From List</option>';
        $price = 0;
        foreach ($all_data as $data) 
        {
            if($data->discounted_price)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->course_price;
            }
            
            $option .= '<option value="'.$data->id.'">'.$data->title.'</option>';
            $price_data .= $price;
        }

        $data_all = [
            'option' => $option,
        ];

        echo json_encode($data_all);
    }

    function get_course_by_student_id_for_refund($id)
    {
        $this->db->select('a.*, b.id, b.title, b.discounted_price, b.price');
        $this->db->from('student_course a');
        $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
        $this->db->where('a.st_course_student_id', $id);
        $this->db->where('a.st_course_status !=', 0);
        $this->db->where('a.st_course_status !=', 6);
        $this->db->where('a.fee_student_course_price !=', 0);
        $all_data = $this->db->get()->result();

        $data_all = [];
        $option = '<option value="">Select Course From List</option>';
        $price = 0;
        foreach ($all_data as $data) 
        {
            if($data->discounted_price)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->price;
            }
            
            $option .= '<option value="'.$data->id.'">'.$data->title.'</option>';
            $price_data .= $price;
        }

        $data_all = [
            'option' => $option,
        ];

        echo json_encode($data_all);
    }

    function get_course_by_student_id_for_admission_form_print($id)
    {
        $this->db->select('a.*, b.id, b.title, b.discounted_price, b.price');
        $this->db->from('student_course a');
        $this->db->join('course b', 'b.id = a.st_course_course_id', 'left');
        $this->db->where('a.st_course_student_id', $id);
        $this->db->where('a.st_course_status > ', 0);
        $all_data = $this->db->get()->result();

        $data_all = [];
        $option = '<option value="">Select Course From List</option>';
        foreach ($all_data as $data) 
        {
            $option .= '<option value="'.$data->id.'">'.$data->title.'</option>';
        }

        $data_all = [
            'option' => $option,
        ];

        echo json_encode($data_all);
    }

    function get_course_price_by_course_id_for_refund($c_id, $st_id)
    {
        $atp_id = user_id();

        // if(check_atp_programm() == true)
        // {
            // $this->db->where('atp_c_p_atp_id', $atp_id);
            // $this->db->where('atp_c_p_course_id', $c_id);
            // $data = $this->db->get('atp_course_price')->row();

            // $price = $data->atp_c_p_course_price;
        // }
        // else
        // {
            $this->db->select('price, discounted_price');
            $this->db->where('id', $c_id);
            $data = $this->db->get('course')->row();
            if($data->discounted_price)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->price;
            }
        // }
        


        // $tax = ($course_price * user()->user_gst) / 100; 
        // $price = $course_price + $tax;
        
        $this->db->where('st_course_course_id', $c_id);
        $this->db->where('st_course_student_id', $st_id);
        $this->db->where('st_course_student_atp_id', $atp_id);
        $ins_details = $this->db->get('student_course')->row();

        if($ins_details->fee_student_course_main_price > 0)
        {
            $main_price = $ins_details->fee_student_course_main_price;
        }   
        else
        {
            $main_price = $price;
        }
        $details = array(
            'price' => $price, 
            'course_price' => $ins_details->fee_student_course_price,
            'course_discount' => $ins_details->fee_student_course_discount,
            'main_price' => $main_price,
            'down_payment' => $ins_details->fee_student_course_down_pay,
            'due_ammount' => $main_price - $ins_details->fee_student_course_due,
            'no_instalment' => $ins_details->fee_student_course_instalment,
            'no_days' => $ins_details->fee_student_course_days,
            'start_date' => $ins_details->fee_student_course_start_day,
            'exam_approve' => $ins_details->fee_student_exam_approve,
        );

        echo json_encode($details);
    }

    function get_course_price_by_course_id($c_id, $st_id)
    {
        $atp_id = user_id();
        
        // if(check_atp_programm() == true)
        // {
            // $this->db->where('atp_c_p_atp_id', $atp_id);
            // $this->db->where('atp_c_p_course_id', $c_id);
            // $data = $this->db->get('atp_course_price')->row();

            // $price = $data->atp_c_p_course_price;
        // }
        // else
        // {
            $this->db->select('price, discounted_price');
            $this->db->where('id', $c_id);
            $data = $this->db->get('course')->row();
            if($data->discounted_price)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->price;
            }
        // }

        
        // $tax = ($course_price * user()->user_gst) / 100; 
        // $price = $course_price + $tax;
        
        $this->db->where('st_course_course_id', $c_id);
        $this->db->where('st_course_student_id', $st_id);
        $this->db->where('st_course_student_atp_id', $atp_id);
        $ins_details = $this->db->get('student_course')->row();

        if($ins_details->fee_student_course_main_price > 0)
        {
            $main_price = $ins_details->fee_student_course_main_price;
        }   
        else
        {
            $main_price = $price;
        }
        $details = array(
            'price' => $price, 
            'course_price' => $ins_details->fee_student_course_price,
            'course_discount' => $ins_details->fee_student_course_discount,
            'main_price' => $main_price,
            'down_payment' => $ins_details->fee_student_course_down_pay,
            'due_ammount' => $ins_details->fee_student_course_due,
            'no_instalment' => $ins_details->fee_student_course_instalment,
            'no_days' => $ins_details->fee_student_course_days,
            'start_date' => $ins_details->fee_student_course_start_day,
            'exam_approve' => $ins_details->fee_student_exam_approve,
        );

        echo json_encode($details);
    }

    function get_course_price_by_course_id_for_fee_recive($c_id, $st_id)
    {
        $atp_id = user_id();
        
        // if(check_atp_programm() == true)
        // {
            // $this->db->where('atp_c_p_atp_id', $atp_id);
            // $this->db->where('atp_c_p_course_id', $c_id);
            // $data = $this->db->get('atp_course_price')->row();

            // $price = $data->atp_c_p_course_price;
        // }
        // else
        // {
            $this->db->select('price, discounted_price');
            $this->db->where('id', $c_id);
            $data = $this->db->get('course')->row();
            if($data->discounted_price)
            {
                $price = $data->discounted_price;
            }
            else
            {
                $price = $data->price;
            }
        // }
        // $tax = ($course_price * user()->user_gst) / 100; 
        // $price = $course_price + $tax;

        $this->db->where('st_course_course_id', $c_id);
        $this->db->where('st_course_student_id', $st_id);
        $this->db->where('st_course_student_atp_id', $atp_id);
        $ins_details = $this->db->get('student_course')->row();

        $this->db->where('instalment_student_id', $st_id);
        $this->db->where('instalment_course_id', $c_id);
        $this->db->where('instalment_status', 0);
        $instal_amt = $this->db->get('student_payment_instalment')->result();

        $option = '<option value="">Select From List</option>';
        $a = 1;
        foreach ($instal_amt as $key => $instalment) 
        {
            $option .= '<option value="'.$instalment->instalment_id.'">Instalment '.$a.' [Rs.'.$instalment->instalment_amount.']</option>';
        $a++; }

        if($ins_details->fee_student_course_main_price > 0)
        {
            $main_price = $ins_details->fee_student_course_main_price;
        }   
        else
        {
            $main_price = $price;
        }


        $details = array(
            'price' => $price, 
            'course_price' => $ins_details->fee_student_course_price,
            'course_discount' => $ins_details->fee_student_course_discount,
            'main_price' => $main_price,
            'down_payment' => $ins_details->fee_student_course_down_pay,
            'due_ammount' => $ins_details->fee_student_course_due,
            'option' => $option,
            'course_table_id' => $ins_details->st_course_id
        );

        echo json_encode($details);
    }

    public function get_instalment_amt($ins_id)
    {
        $this->db->where('instalment_id', $ins_id);
        $data = $this->db->get('student_payment_instalment')->row();

        echo $data->instalment_amount;
    }

    function assign_exam_generate_table()
    {
        $course = $this->input->post('course');
        // $course = 13;
        $atp_id = user_id();
        $this->db->select('a.st_course_id, a.st_course_student_id, a.st_course_course_id, b.user_name, b.user_photo, b.user_reg_id');
        $this->db->from('student_course a');
        $this->db->join('users b', 'b.user_id = a.st_course_student_id', 'left');
        $this->db->where('a.st_course_is_exam_approve', 0);
        $this->db->where('a.st_course_course_id', $course);
        $this->db->where('a.st_course_status', 3);
        $this->db->where('a.st_course_student_atp_id', $atp_id);
        $all_data = $this->db->get()->result();

        $table = '';
        foreach ($all_data as $key => $data)
        {
            $this->db->select('instalment_status');
            $this->db->where('instalment_course_id', $course);
            $this->db->where('instalment_student_id', $data->st_course_student_id);
            $all_inst_details = $this->db->get('student_payment_instalment')->result();

            $inst_status = [];
            foreach ($all_inst_details as $key => $inst_details) 
            {
                $inst_status[] = $inst_details->instalment_status;
            }

            if (!in_array(0, $inst_status)) {

                $table .= '<tr>
                        <td>'.$data->user_reg_id.'</td>
                        <td>'.$data->user_name.'</td>
                        <td><img src="'.base_url().$data->user_photo.'" width="50px"></td>
                        <td><input type="checkbox" name="st_course_id[]" class="form-control check-box" style="height:15px!important;" value="'.$data->st_course_id.'">
                        <input type="hidden" name="st_course_student_id[]" value='.$data->st_course_student_id.'>
                    </tr>';
            }
        }

        echo json_encode($table);
        
    }

    public function get_student_admission_form_data($course_id, $student_id)
    {
        $this->db->select('a.*, b.title, b.duration, c.user_name, c.user_photo, c.user_reg_id, c.user_mobile, c.user_email, c.user_created_at, c.user_dob');
        $this->db->from('student_course a');
        $this->db->join('course b', 'b.id = a.st_course_course_id');
        $this->db->join('users c', 'c.user_id = a.st_course_student_id');
        $this->db->where('a.st_course_course_id', $course_id);
        $this->db->where('a.st_course_student_id', $student_id);
        $data = $this->db->get()->row();

        $arrayName = array(
            'sname' => $data->user_name, 
            'photo' => $data->user_photo, 
            'regno' => $data->user_reg_id, 
            'mobile' => $data->user_mobile, 
            'email' => $data->user_email, 
            'adate' => date('d-m-Y', strtotime($data->st_course_date)), 
            'dob' => date('d-m-Y', strtotime($data->user_dob)), 
            'crse' => $data->title, 
            'duration' => $data->duration, 
        );
        echo json_encode($arrayName);
    }

    public function update_admission_date()
    {
        echo $this->user->update_admission_date();
    }

    public function update_admission_batch()
    {
         echo $this->user->update_admission_batch();
    }

    public function student_course_payment()
    {
        $atp_id = user()->user_id;
        echo $this->user->student_course_payment($atp_id);
    }

    public function add_new_course_for_student()
    {
        echo $this->user->add_new_course_for_student($id);
    }

    function re_admission($student_id)
    {
        $this->load->model('course_model', 'course');
        $atp_id = user_id();
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['student'] = $this->user->get_student_by_id_and_atp_id($student_id, $atp_id);
        $data['all_course'] = $this->course->get_all_course_for_admission_by_atp_id(user_id());
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/re_admission');
        $this->load->view('admin/include/footer');
    }

    function extend_assign_exam_generate_table()
    {
        $course = $this->input->post('course');
        $atp_id = user()->user_id;
        $this->db->select('a.*, b.user_name, b.user_photo, b.user_reg_id');
        $this->db->from('student_course a');
        $this->db->join('users b', 'b.user_id = a.st_course_student_id', 'left');
        $this->db->where('a.st_course_is_exam_approve', 1);
        $this->db->where('a.st_course_course_id', $course);
        $this->db->where('a.st_course_status', 4);
        $this->db->where('a.st_course_student_atp_id', $atp_id);
        // $this->db->where('a.st_student_exam_date <=', date('Y-m-d'));
        $all_data = $this->db->get()->result();

        $table = '';
        foreach ($all_data as $key => $data)
        {

            $table .= '<tr>
                    <td>'.$data->user_reg_id.'</td>
                    <td>'.$data->user_name.'</td>
                    <td><img src="'.base_url().$data->user_photo.'" width="50px"></td>
                    <td><input type="checkbox" name="st_course_id[]" class="form-control check-box" style="height:15px!important;" value="'.$data->st_course_id.'">
                    <input type="hidden" name="st_course_student_id[]" value='.$data->st_course_student_id.'>
                </tr>';
        }

        echo json_encode($table);
    }

    public function re_exam_generate_table()
    {
        
        $course = $this->input->post('course');
        $atp_id = user()->user_id;
        $this->db->select('a.*, b.user_name, b.user_photo, b.user_reg_id');
        $this->db->from('student_course a');
        $this->db->join('users b', 'b.user_id = a.st_course_student_id', 'left');
        $this->db->where('a.st_course_is_exam_approve', 2);
        $this->db->where('a.st_course_course_id', $course);
        $this->db->where('a.st_course_status', 5);
        $this->db->where('a.st_course_student_atp_id', $atp_id);
        // $this->db->where('a.st_student_exam_date <=', date('Y-m-d'));
        $all_data = $this->db->get()->result();

        $table = '';
        foreach ($all_data as $key => $data)
        {

            $table .= '<tr>
                    <td>'.$data->user_reg_id.'</td>
                    <td>'.$data->user_name.'</td>
                    <td><img src="'.base_url().$data->user_photo.'" width="50px"></td>
                    <td><input type="checkbox" name="st_course_id[]" class="form-control check-box" style="height:15px!important;" value="'.$data->st_course_id.'">
                    <input type="hidden" name="st_course_student_id[]" value='.$data->st_course_student_id.'>
                </tr>';
        }

        echo json_encode($table);
    }

    function get_student_data_by_batch_id()
    {
        $batch_id = $this->input->post('batch');
        $date = $this->input->post('date');

        $this->db->select('a.st_course_student_id, b.user_name');
        $this->db->from('student_course a');
        $this->db->join('users b', 'b.user_id = a.st_course_student_id');
        $this->db->where('a.st_course_batch', $batch_id);
        $all_student = $this->db->get()->result();

        $i = 0;
        $option = '<table class="table table-bordered table-striped">
                      <tr>
                        <th>Student Name</th>
                        <th width="20%">Date</th>
                        <th width="5%">Absent</th>
                        <th width="5%">Present</th>
                      </tr>';
        foreach ($all_student as $student) 
        {
            $this->db->where('st_att_student_id', $student->st_course_student_id);
            $this->db->where('st_att_date', $date);
            $this->db->where('st_att_batch', $batch_id);
            $att_data = $this->db->get('student_attendance')->row();
            $option .= '<tr>
                            <td>'.$student->user_name.'<input type="hidden" name="student_id[]" value="'.$student->st_course_student_id.'"></td>
                            <td>'.$date.' <input type="hidden" name="date[]" value="'.$date.'"><input type="hidden" name="batch[]" value="'.$batch_id.'"></td>
                            <td><input type="radio" id="presunt_status_'.$i.'" '.(($att_data->st_att_present_status=='1')?'checked':"").' name="present_status_'.$i.'" value="1"></td>
                            <td><input type="radio" id="presunt_status_'.$i.'" '.(($att_data->st_att_present_status=='0')?'checked':"").' name="present_status_'.$i.'" value="0"></td>
                          </tr> ';
        $i++;}

        $option .= '</table>';

        echo $option;
    }

    function update_student_attandence()
    {
        if ($this->user->update_student_attandence()) {
            $this->session->set_userdata('success', "Attandence Successfully Updated");
             redirect($this->agent->referrer());
        } else {
            $this->session->set_userdata('error', "Attandence Updated Faild");
             redirect($this->agent->referrer());
        }
    }

    public function view_all_student()
    {
        $data['app_setting'] = $this->setting_model->get_all_app_setting();
        $data['all_students'] = $this->user->get_all_admintted_student_for_admin();
        $this->load->view('admin/include/header', $data);
        $this->load->view('admin/student/all_student_for_admin');
        $this->load->view('admin/include/footer');
    }
}
