MMCT TEAM
Server IP : 103.191.208.50  /  Your IP : 216.73.216.53
Web Server : LiteSpeed
System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64
User : celkcksm ( 1031)
PHP Version : 7.4.33
Disable Function : show_source, system, shell_exec, passthru, popen, exec
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/celkcksm/ecampus.ncriptech.com/application/controllers/admin/Students.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');


/**
 * 
 */
class Students  extends BaseAdminController
{
    public $db_group='';
    protected $inst_id='';
    protected $inst_parent_id='';
    protected $branch_parent_inst_id='';
    protected $user_id='';
    protected $inst_code='';
    protected $inst_ph='';
    protected $inst_email='';
    protected $inst_type='';
    protected $user_type='';
    protected $admission_view_access='';
    protected $student_upload_limit='';
    protected $student_data_can_be_uploaded='no';
    protected $course_fees_edit_access='no';
    protected $course_booking_fees_edit_access='no';

    function __construct()
    {
        parent::__construct();
        $userdata=$this->data['userdata'];
		$this->db_group=$userdata->user_code;

        $institute_data=check_institute($userdata);

        $this->user_type=$userdata->user_type;

        $this->inst_id=$institute_data['institute_id'];
        $this->inst_parent_id=$institute_data['inst_parent_id'];
        $this->branch_parent_inst_id=$this->data['userdata']->branch_parent_inst_id;
        $this->inst_ph=$this->data['userdata']->inst_ph;
        $this->inst_email=$this->data['userdata']->inst_email;
        $this->user_id=$this->data['userdata']->user_id;
        $this->inst_code=$institute_data['inst_code'];
        $this->inst_type=$institute_data['inst_type'];
        $this->admission_view_access=$institute_data['admission_view_access'];
        $this->admission_add_access=$institute_data['admission_add_access'];
        $this->student_upload_limit=$institute_data['student_upload_limit'];
        $this->student_data_can_be_uploaded=$institute_data['student_data_can_be_uploaded'];
        $this->course_fees_edit_access=$institute_data['course_fees_edit'];
        $this->course_booking_fees_edit_access=$institute_data['course_booking_fees_edit'];
    }

    function index(){

        if($this->data['userdata']->user_type=='student'  ||   $this->data['userdata']->user_type=='agent' ){

            redirect($this->data['base_url']);
        }
       
        if(session_userdata('isAdminLoggedin')){
            $userdata=$this->data['userdata'];
            $db_group=$userdata->db_group;

            $this->data['page_title']='Students';

            $institute_data=check_institute($this->data['userdata']);

            $check_upload_limit=check_max_upload_limit($this->data['userdata'],$db_group);

            $check_account=check_account_renewal_status($this->data['userdata']);

            $sessions=$this->sessm->get_session(array('session_inst_id'=>$institute_data['institute_id']),FALSE);
            $courses=$this->cm->get_course(array('course_inst_id'=>$institute_data['institute_id']),FALSE);

            $session_courses=$this->sessm->get_session_courses(array('session_inst_id'=>$institute_data['institute_id']),FALSE);

            
            $this->data['student_upload_limit']=$check_upload_limit['student_upload_limit'];
            $this->data['student_data_can_be_uploaded']=$check_upload_limit['student_data_can_be_uploaded'];

            $this->data['expiry_message']=$check_account['expiry_message'];
            $this->data['expired_message']=$check_account['expired_message'];

            $this->data['sessions']=$sessions;
            $this->data['courses']=$courses;
            $this->data['session_courses']=$session_courses;
            $this->data['excel_type']='only_student_data';

            $this->data['hostels']=$this->hm->get_hostel(array('hostel_inst_id'=>$institute_data['institute_id']),FALSE);

            $this->theme->title($this->data['page_title'])->add_partial('partial_upload_excel_modal',$this->data)->add_partial('partial_temp_exceldata_load_modal',$this->data)->load('users/vw_students', $this->data);
        }else{

            redirect($this->data['base_url']);
        }
    }


    function indexBranch(){
       
        if(session_userdata('isAdminLoggedin')){
            if($this->data['userdata']->user_type==='institute_branch'){
                redirect($this->data['base_url'].'/students');
            }else{
                $this->data['page_title']='Branch Students';

                $institute_data=check_institute($this->data['userdata']);

                $check_upload_limit=check_max_upload_limit($this->data['userdata']);

                $check_account=check_account_renewal_status($this->data['userdata']);


                $this->data['student_upload_limit']=$check_upload_limit['student_upload_limit'];
                $this->data['student_data_can_be_uploaded']=$check_upload_limit['student_data_can_be_uploaded'];

                $this->data['branches']=$this->um->get_institute_branch(array('branch_parent_inst_id'=>$institute_data['institute_id']),FALSE);
                $this->theme->title($this->data['page_title'])->load('users/vw_students_branch', $this->data);
            }                
        }else{

            redirect($this->data['base_url']);
        }
    }

    function indexRegister($student_id=null){
       
        if(session_userdata('isAdminLoggedin')){

            $userdata=$this->data['userdata'];
            $db_group=$userdata->user_code;

            $this->data['page_title']='Students Register';

            $institute_data=check_institute($this->data['userdata']);
            $check_upload_limit=check_max_upload_limit($this->data['userdata'],$db_group);

            $check_account=check_account_renewal_status($this->data['userdata']);

            $sessions=$this->sessm->get_session(array('session_inst_id'=>$institute_data['institute_id']),FALSE);
            $courses=$this->cm->get_course(array('course_inst_id'=>$institute_data['institute_id']),FALSE);

            $session_courses=$this->sessm->get_session_courses(array('session_inst_id'=>$institute_data['institute_id']),FALSE);

            $this->data['system_sessions']=$sessions;
            $this->data['courses']=$courses;
            $this->data['session_courses']=$session_courses;

            $_sessions=array();

            if(!empty($student_id)){
                $this->data['student_id']=$student_id;
                $student_id=decode_data($student_id);

                $student_data=$this->um->get_user(array('stu_id'=>$student_id),'student');

                $this->data['userdata']=$student_data;

                $_religions=array();
                $_caste_category=array();
                $_countries=array();
                $_blood_groups=array();
                $_occupations=array();

                $countries=$this->sm->_get_countries(null,FALSE);
                $states=$this->sm->_get_states(null,FALSE);
                $blood_groups=$this->sm->_get_blood_groups(null,FALSE);
                $occupations=$this->sm->_get_occupations(null,FALSE);
                $religions=$this->cst->get_religion(null,FALSE);

                if(!empty($states)){
                    foreach ($states as $key => $value) {
                        $_states[]=array(
                            'state_id'=>$value->state_id,
                            'state_name'=>$value->state_name,
                            'cur_selected'=>($student_data->stu_cur_state==$value->state_id)?'selected':'',
                            'perma_selected'=>($student_data->stu_perma_state==$value->state_id)?'selected':''
                        );
                    }
                }

                $_current_districts=[];
                $_perm_districts=[];

                if(!empty($student_data)){
                    $current_districts=$this->sm->_get_districts(array('state_id'=>$student_data->stu_cur_state),FALSE);
                    $perm_districts=$this->sm->_get_districts(array('state_id'=>$student_data->stu_perma_state),FALSE);
                }

                if(!empty($current_districts)){

                    foreach ($current_districts as $key => $value) {
                        $_current_districts[]=array(
                            'district_id'=>$value->district_id,
                            'district_name'=>$value->district_name,
                            'selected'=>($student_data->stu_cur_district==$value->district_id)?'selected':'',
                        );
                    }
                }

                if(!empty($perm_districts)){

                    foreach ($perm_districts as $key => $value) {
                        $_perm_districts[]=array(
                            'district_id'=>$value->district_id,
                            'district_name'=>$value->district_name,
                            'selected'=>($student_data->stu_perma_district==$value->district_id)?'selected':''
                        );
                    }
                }

                $this->data['states']=$_states;

                if(!empty($occupations)){
                    foreach ($occupations as $key => $value) {
                        $_occupations[]=array(
                            'occupation_id'=>$value->occupation_id,
                            'occupation_name'=>$value->occupation_name,
                            'father_occupation'=>($student_data->stu_father_occupation==$value->occupation_id)?'selected':'',
                            'mother_occupation'=>($student_data->stu_mother_occupation==$value->occupation_id)?'selected':'',
                            'guardian_occupation'=>($student_data->stu_guardian_occupation==$value->occupation_id)?'selected':''
                        );
                    }
                }

                $this->data['occupations']=$_occupations;


                if(!empty($countries)){
                    foreach ($countries as $key => $value) {
                        $_countries[]=array(
                            'country_id'=>$value->country_id,
                            'country_nationality'=>$value->country_nationality,
                            'selected'=>($student_data->stu_nationality==$value->country_id)?'selected':''
                        );
                    }
                }

                $this->data['countries']=$_countries;


                if(!empty($blood_groups)){
                    foreach ($blood_groups as $key => $value) {
                        $_blood_groups[]=array(
                            'blood_group_id'=>$value->blood_group_id,
                            'blood_group_name'=>$value->blood_group_name,
                            'selected'=>($student_data->stu_blood_group==$value->blood_group_id)?'selected':''
                        );
                    }
                }

                $this->data['blood_groups']=$_blood_groups;

                $caste_category=$this->cst->get_caste_category(null,FALSE);                

                if(!empty($caste_category)){
                    foreach ($caste_category as $key => $value) {
                        $_caste_category[]=array(
                            'caste_id'=>$value->caste_id,
                            'caste_name'=>$value->caste_name,
                            'selected'=>($student_data->stu_caste==$value->caste_id)?'selected':''
                        );
                    }
                }

                $this->data['caste_category']=$_caste_category;

                if(!empty($religions)){
                    foreach ($religions as $key => $value) {
                        $_religions[]=array(
                            'reiligion_id'=>$value->reiligion_id,
                            'religion_name'=>$value->religion_name,
                            'selected'=>($student_data->stu_religion==$value->reiligion_id)?'selected':''
                        );
                    }
                }

                $this->data['religions']=$_religions;

                $this->data['genders']=array(
                    'Male'=>($student_data->stu_gender=='male')?'selected':'',
                    'Female'=>($student_data->stu_gender=='female')?'selected':'',
                    'Other'=>($student_data->stu_gender=='other')?'selected':'',
                );

                $this->data['academic_details']=$this->um->get_students_academics(array('acad_stu_id'=>$student_id));

                
                $aadhar_file=$this->sm->get_file(array('storage_type'=>'aadhar_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $madhyamik_admit_card_file=$this->sm->get_file(array('storage_type'=>'madhyamik_admit_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $madhyamik_result_card_file=$this->sm->get_file(array('storage_type'=>'madhyamik_result_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $madhyamik_rank_card_file=$this->sm->get_file(array('storage_type'=>'madhyamik_rank_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $twelfth_result_card_file=$this->sm->get_file(array('storage_type'=>'12th_result_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $grad_result_card_file=$this->sm->get_file(array('storage_type'=>'grad_result_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $post_grad_result_card_file=$this->sm->get_file(array('storage_type'=>'post_grad_result_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $other_certificate_card_file=$this->sm->get_file(array('storage_type'=>'other_certificate_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));
                $student_profile_photo_file=$this->sm->get_file(array('storage_type'=>'student_profile_photo','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));

                $student_signature_photo_file=$this->sm->get_file(array('storage_type'=>'student_signature_photo','storage_type_id'=>$student_data->user_id));
                $madhyamik_registration_card_file=$this->sm->get_file(array('storage_type'=>'madhyamik_registration_card','storage_type_of'=>'student','storage_type_id'=>$student_data->user_id));


                if(!empty($aadhar_file)){
                    if(file_exists(FCPATH.$aadhar_file->media_disk_path)){
                        $aadhar_card=($aadhar_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($aadhar_file->media_disk_path_relative);
                    }else{
                        $aadhar_card=$this->data['no_image'];
                    }                     
                }else{
                   $aadhar_card=$this->data['no_image'];
                }


                if(!empty($madhyamik_result_card_file)){
                    if(file_exists(FCPATH.$madhyamik_result_card_file->media_disk_path)){
                        $madhyamik_result_card=($madhyamik_result_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($madhyamik_result_card_file->media_disk_path_relative);
                    }else{
                        $madhyamik_result_card=$this->data['no_image'];
                    }                     
                }else{
                   $madhyamik_result_card=$this->data['no_image'];
                }

                if(!empty($other_certificate_card_file)){
                    if(file_exists(FCPATH.$other_certificate_card_file->media_disk_path)){
                        $other_certificate_card=($other_certificate_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($other_certificate_card_file->media_disk_path_relative);
                    }else{
                        $other_certificate_card=$this->data['no_image'];
                    }                     
                }else{
                   $other_certificate_card=$this->data['no_image'];
                }

                if(!empty($twelfth_result_card_file)){
                    if(file_exists(FCPATH.$twelfth_result_card_file->media_disk_path)){
                        $twelft_result=($twelfth_result_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($twelfth_result_card_file->media_disk_path_relative);
                    }else{
                        $twelft_result=$this->data['no_image'];
                    }                     
                }else{
                   $twelft_result=$this->data['no_image'];
                }

                if(!empty($grad_result_card_file)){
                    if(file_exists(FCPATH.$grad_result_card_file->media_disk_path)){
                        $grad_result=($grad_result_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($grad_result_card_file->media_disk_path_relative);
                    }else{
                        $grad_result=$this->data['no_image'];
                    }                     
                }else{
                   $grad_result=$this->data['no_image'];
                }

        

                if(!empty($post_grad_result_card_file)){
                    if(file_exists(FCPATH.$post_grad_result_card_file->media_disk_path)){
                        $post_grad_result=($post_grad_result_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($post_grad_result_card_file->media_disk_path_relative);
                    }else{
                        $post_grad_result=$this->data['no_image'];
                    }                     
                }else{
                   $post_grad_result=$this->data['no_image'];
                }


                if(!empty($madhyamik_registration_card_file)){
                    if(file_exists(FCPATH.$madhyamik_registration_card_file->media_disk_path)){
                        $reg_card_10th=($madhyamik_registration_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($madhyamik_registration_card_file->media_disk_path_relative);
                    }else{
                        $reg_card_10th=$this->data['no_image'];
                    }                    
                }else{
                    $reg_card_10th=$this->data['no_image'];
                }
                

                if(!empty($student_profile_photo_file)){
                    if(file_exists(FCPATH.$student_profile_photo_file->media_disk_path)){
                        $profile_photo=($student_profile_photo_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($student_profile_photo_file->media_disk_path_relative);
                    }else{
                        $profile_photo=$this->data['no_image'];
                    }                    
                }else{
                    $profile_photo=$this->data['no_image'];
                }

                if(!empty($student_signature_photo_file)){
                    if(file_exists(FCPATH.$student_signature_photo_file->media_disk_path)){
                        $signature_photo=($student_signature_photo_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($student_signature_photo_file->media_disk_path_relative);
                    }else{
                        $signature_photo=$this->data['no_image'];
                    }                    
                }else{
                    $signature_photo=$this->data['no_image'];
                }


                if(!empty($madhyamik_admit_card_file)){
                    if(file_exists(FCPATH.$madhyamik_admit_card_file->media_disk_path)){
                        $admit_card_10th=($madhyamik_admit_card_file->media_mime=='application/pdf')?base_url('uploads/app/pdf.png'):base_url($madhyamik_admit_card_file->media_disk_path_relative);
                    }else{
                        $admit_card_10th=$this->data['no_image'];
                    }                     
                }else{
                   $admit_card_10th=$this->data['no_image'];
                }

                $admission_data=$this->adm->get_admission_data(array('admission_stu_id'=>$student_data->user_id));
                $this->data['course_subjects']=$this->cm->get_subject(array('subject_course_id'=>$admission_data->admission_course_id),FALSE);
                $this->data['admission_data']=$admission_data;

                //print_obj($this->data['admission_data']);die;

                $this->data['aadhar_card']=$aadhar_card;
                $this->data['profile_photo']=$profile_photo;
                $this->data['signature_photo']=$signature_photo;
                $this->data['admit_card_10th']=$admit_card_10th;
                $this->data['reg_card_10th']=$reg_card_10th;
                $this->data['madhyamik_result_card']=$madhyamik_result_card;
                $this->data['madhyamik_rank_card']=$madhyamik_rank_card;
                $this->data['twelft_result']=$twelft_result;
                $this->data['grad_result']=$grad_result;
                $this->data['post_grad_result']=$post_grad_result;
                $this->data['other_certificate_card']=$other_certificate_card;

                $this->data['current_districts']=$_current_districts;
                $this->data['perm_districts']=$_perm_districts;

                $this->data['tenth_boards']= $this->config->item('tenth_boards');
                $this->data['twelfth_boards']= $this->config->item('twelfth_boards');

                $view_file='users/vw_students_register_edit';

            }else{
                $view_file='users/vw_students_register';
            }

            if(!empty($sessions)){
                foreach ($sessions as $key => $value) {
                    $_sessions[]=array(
                        'session_id'=>$value->session_id,
                        'session_start_year'=>$value->session_start_year,
                        'session_end_year'=>$value->session_end_year
                    );
                }                    
            }


            $this->data['sessions']=$_sessions;

            $this->data['student_upload_limit']=$check_upload_limit['student_upload_limit'];
            $this->data['student_data_can_be_uploaded']=$check_upload_limit['student_data_can_be_uploaded'];

            $this->data['expiry_message']=$check_account['expiry_message'];
            $this->data['expired_message']=$check_account['expired_message'];


            $this->theme->title($this->data['page_title'])->load($view_file, $this->data);
        }else{

            redirect($this->data['base_url']);
        }
    }


    public function onSearchStudentsList(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $institute_data=check_institute($this->data['userdata']);
                $db_group=$this->data['userdata']->user_code;

                $param['column_order'] = array(
                    null,
                    'stu_first_name'
                );                

                $param['column_search'] = array('stu_first_name','stu_mid_name','stu_last_name');
                $param['is_removed']='no';
                $param['order'] = array('stu_id' => 'ASC');
                $posts=$this->input->post();

                if($posts['data_of']==='own'){
                    $param['inst_id']=$this->data['userdata']->user_id;
                }else if($posts['data_of']==='branch'){
                    $param['inst_parent_id']=$this->data['userdata']->user_id;
                }


                if(isset($posts['data_of_id']) && !empty($posts['data_of_id'])){
                    $param['inst_id']=$posts['data_of_id'];
                }

                if(isset($posts['stu_status']) && !empty($posts['stu_status'])){
                    $param['stu_status']=$posts['stu_status'];
                }


                //$param['created_by']=session_userdata('admin_id');


                $list = $this->um->_get_students($posts,$param,FALSE,FALSE,$db_group);

                //print_obj($list);die;
                
                
                $data = array();
                $no = isset($posts['start'])?$posts['start']:0;

                $action='';

                foreach ($list as $stu){
                    $no++;

                    $row = array();

                    $agent_name[$stu->stu_user_id]='';

                    if($stu->admission_agent_id!=null){
                        $agent_data=$this->um->get_agents(array('agent_id'=>$stu->admission_agent_id),TRUE,$this->data['userdata']->user_code);

                        if(!empty($agent_data)){
                            $agent_name[$stu->stu_user_id].='<br><b>Consultant:'.$agent_data->agent_name.'</b>';                             
                        }
                    }

                    $row[]  =  '<input type="checkbox" class="student_list_check_boxes" value="'.$stu->stu_user_id.'">';

                    $row[]  =   $no;
                    

                    $active_session=$this->adm->get_admission_data(array('admission_stu_id'=>$stu->stu_user_id,'admission_data_active'=>'yes'));

                    //print_obj($active_session);die;

                    if($posts['data_of']==='branch'){
                        $param['inst_parent_id']=$this->data['userdata']->user_id;

                        $branch_data=$this->um->get_institute_branch(array('branch_user_id'=>$stu->stu_inst_id));

                        //print_obj($branch_data);die;

                        $row[]  =   $branch_data->branch_name;
                    }
                    

                    if($stu->stu_mid_name!=''){
                        $stu_name=$stu->stu_first_name.' '.$stu->stu_mid_name.' '.$stu->stu_last_name;
                    }else{
                        $stu_name=$stu->stu_first_name.' '.$stu->stu_last_name;
                    }

                    $stu_image=$this->sm->get_file(array('storage_type'=>'student_profile_photo','storage_type_id'=>$stu->stu_user_id,'storage_parent_id'=>$stu->stu_inst_id));


                    if(!empty($stu_image) && !empty($stu_image->media_disk_path)){
                        if(file_exists_any_separator(FCPATH.$stu_image->media_disk_path)){
                            $image=base_url($stu_image->media_disk_path_relative);
                        }else{
                            $image=$this->data['no_image'];
                        }
                    }else{
                        $image=$this->data['no_image'];
                    }

                    $row[]  =   '<img class="img-thumbnail" src="'.$image.'" height="30px;" width="30px;">';
                    $row[]  =   $stu_name.'<br>'.$stu->stu_user_code.'<br>Admission Code:'.$stu->admission_code.$agent_name[$stu->stu_user_id];
                    $row[]  =   $stu->stu_email;
                    $row[]  =   $stu->stu_ph_no;

                    if($stu->user_status==='active'){
                        $status='<span class="badge badge-success">Active</span>';
                    }else if($stu->user_status==='inactive'){
                        $status='<span class="badge badge-danger">Inactive</span>';
                    }

                    $row[]  =   $status;

                    $action='<div class="btn-group" role="group" aria-label="Basic example">';
                    if($posts['data_of']==='own'){
                        if(!empty($active_session)){
                            if($stu->stu_avail_hostel=='yes'){
                                $session_data=$this->sessm->get_session(array('session_id'=>$active_session->admission_sess_id));
                                $action.='<button type="button" class="btn btn-xs btn-info btn_add_hostel_fees" data-student_id="'.encode_data($stu->stu_user_id).'" data-hostel_id="'.encode_data($stu->stu_avail_hostel_id).'" data-course_id="'.encode_data($active_session->admission_course_id).'" data-session_id="'.encode_data($active_session->admission_sess_id).'" data-session_start="'.$session_data->session_start_year.'" data-session_end="'.$session_data->session_end_year.'">Hostel Fees</button>
                                <a class="btn btn-xs btn-dark" href="'.$this->data['base_url'].'/students/add/'.encode_data($stu->stu_id).'"><i class="fa fa-edit"></i></a>';
                            }else{
                                $action.='<a class="btn btn-xs btn-dark" href="'.$this->data['base_url'].'/students/register/'.encode_data($stu->stu_id).'"><i class="fa fa-edit"></i></a> <button class="btn btn-xs btn-danger btn_del_student" data-stu_id="'.encode_data($stu->stu_id).'"><i class="fa fa-trash"></i></button>';
                            }                       
                        }else{
                            $action.='<a class="btn btn-xs btn-dark" href="'.$this->data['base_url'].'/students/register/'.encode_data($stu->stu_id).'"><i class="fa fa-edit"></i></a> <button class="btn btn-xs btn-danger btn_del_student" data-stu_id="'.encode_data($stu->stu_id).'"><i class="fa fa-trash"></i></button>';
                        }
                    }

                    $action.='</div>';
                        

                                     
                    $row[]  = $action;  

                    $data[] = $row; 
                }

                $output = array(
                    "draw" => isset($posts['draw'])?$posts['draw']:'',
                    "recordsTotal" => $this->um->_get_students($posts,$param,TRUE,FALSE,$db_group),
                    "recordsFiltered" => $this->um->_get_students($posts,$param,TRUE,FALSE,$db_group),
                    "data" => $data,
                );
                
                echo json_encode($output);
                session_write_close();

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    public function onGetStudents(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $institute_data=check_institute($this->data['userdata']);
                $inst_id=$institute_data['institute_id'];

                $session_id=post_data('session_id');
                $course_id=post_data('course_id');

                if($course_id>0){
                    $students=$this->adm->get_admission_data(array('admission_inst_id'=>$inst_id,'admission_sess_id'=>$session_id,'admission_course_id'=>$course_id),FALSE);
                }else{
                    $students=$this->adm->get_admission_data(array('admission_inst_id'=>$inst_id,'admission_sess_id'=>$session_id),FALSE,$this->db_group);
                }

                session_write_close();

                return json_headers($students);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    public function onRegisterStudents(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $institute_data=check_institute($this->data['userdata']);
                $inst_id=$institute_data['institute_id'];
                $inst_parent_id=$institute_data['inst_parent_id'];
                $inst_type=$institute_data['inst_type'];
                $inst_code=$institute_data['inst_code'];
                $inst_name=$institute_data['inst_name'];
                $inst_logo_url=$institute_data['inst_logo_url'];
                $student_upload_limit=$institute_data['student_upload_limit'];

                $session_id=post_data('stu_session');
                $course_id=post_data('stu_course');
                $subject_id=post_data('stu_subject');
                $stu_password=post_data('stu_password');
                $stu_email=post_data('stu_email');
                $stu_phone=post_data('stu_phone');

                $stu_first_name=post_data('stu_first_name');
                $stu_middle_name=post_data('stu_middle_name');
                $stu_last_name=post_data('stu_last_name');

                $max_student_uploaded=$this->um->get_count_students(array('stu_inst_id'=>$inst_id));

                //print_obj($max_student_uploaded);die;

                if($max_student_uploaded==$student_upload_limit){
                    $student_data_can_be_uploaded='no';
                }else if($max_student_uploaded<$student_upload_limit){
                    $student_data_can_be_uploaded='yes';
                }

                //echo $student_data_can_be_uploaded;die;


                if($student_data_can_be_uploaded=='yes'){
                    $data_found=$this->um->get_duplicate_student(array('stu_email'=>$stu_email));

                    if($data_found[0]->counted==0){

                        $session_course_data=$this->sessm->get_session_courses(array('session_id'=>$session_id,'session_course_id'=>$course_id,'session_inst_id'=>$inst_id));


                        //print_obj($session_course_data);die;

                        $student_found=$this->um->get_duplicate_student(array('stu_ph_no'=>$stu_phone));

                        if($student_found[0]->counted==0){

                            $total_students=$this->um->get_count_students(array('stu_inst_id'=>$inst_id));
                            $student_id_val=$total_students+1;

                            if(!empty($stu_password)){
                                $stu_password=$stu_password;
                            }else{
                                $stu_password='Password@123';
                            }

                            $password=password_hash($stu_password, PASSWORD_BCRYPT, array('cost'=>12));

                            $course_data=$this->cm->get_course(array('course_id'=>$course_id,'course_inst_id'=>$inst_id));
                            $session_data=$this->sessm->get_session(array('session_id'=>$session_id,'session_inst_id'=>$inst_id));
                            $subject_data=$this->cm->get_subject(array('subject_id'=>$subject_id));
                        
                            $stu_user_data=array(
                                'user_name'=>$stu_email,
                                'user_password'=>$password,
                                'user_password_visible'=>encode_data($stu_password),
                                'user_type'=>'student',
                                'user_permissions'=>NULL,
                                'user_status'=>'active',
                                'created_by_type'=>'ntadmin',
                                'created_by'=>$inst_id,
                                'created_at'=>date('Y-m-d')
                            );

                            $user_id=$this->um->store_users($stu_user_data);

                            if($user_id){

                                if(!empty($this->data['student_code_settings'])){
                                    if ($this->data['student_code_settings']=='college_code/course_code/session/student_number') {
                                        $stu_user_code=strtoupper($this->data['user_code']).'/'.$course_data->course_code.'/'.$session_data->session_start_year.'-'.$session_data->session_end_year.'/'.$student_id_val;
                                    }
                                }else{
                                    $stu_user_code=strtoupper($user_code).'/'.$course_data->course_code.'/'.$session_data->session_start_year.'-'.$session_data->session_end_year.'/'.$student_id_val;
                                }

                                $student_data=array(
                                    'stu_inst_type'=>$this->data['userdata']->user_type,
                                    'stu_user_code'=>$stu_user_code,
                                    'stu_user_id'=>$user_id,
                                    'stu_inst_id'=>$inst_id,
                                    'stu_inst_parent_id'=>$inst_parent_id,
                                    'stu_first_name'=>$stu_first_name,
                                    'stu_mid_name'=>$stu_middle_name,
                                    'stu_last_name'=>$stu_last_name,
                                    'stu_email'=>$stu_email,
                                    'stu_ph_no'=>$stu_phone,
                                    'created_by'=>$inst_id,
                                    'created_at'=>date('Y-m-d')
                                );

                                $student_id=$this->um->store_students($student_data);

                                if($student_id){

                                   /* $mail_data['inst_id']=$inst_id;
                                    $mail_data['mail_from']='webmaster';
                                    $mail_data['to_email']=$stu_email;
                                    $mail_data['mail_from_name']=$inst_name;
                                    $mail_data['mail_subject']=$inst_name.' CMS Portal Registration for Session '.$session_data->session_start_year.'-'.$session_data->session_end_year;
                                    $mail_data['mail_type']='html';
                                    $mail_data['mail_custom_type']='html';
                                    $mail_data['mail_data']=array(
                                        'stu_user_code'=>$stu_user_code,
                                        'stu_name'=>$stu_name,
                                        'stu_email'=>$stu_email,
                                        'stu_ph_no'=>$stu_phone,
                                        'user_name'=>$stu_email,
                                        'user_password'=>$stu_password,
                                        'booking_code'=>$booking_code,
                                        'booking_amount'=>($booking_amount>0)?number_format($booking_amount,2):'0',
                                        'booking_payment_link'=>$payment_link,
                                        'portal_url'=>$this->data['base_url'],
                                        'portal_logo'=>$inst_logo_url,
                                        'portal_inst_name'=>$inst_name,
                                        'access_url'=>$this->data['base_url'],
                                        'college_email'=>$inst_email,
                                        'college_phone'=>$this->data['userdata']->user_contact_no,
                                        'college_address'=>$this->data['userdata']->user_address_1,
                                        'application_session'=>$session_year_data,
                                        'application_course'=>$course_data->course_name,
                                        'application_course_fees'=>(!empty($course_fees))?number_format($course_fees,2):'',
                                        'application_subject'=>(!empty($subject_data))?$subject_data->subject_name:'N/A',
                                        'default_logo_small'=>$inst_logo_url,
                                        'created_at'=>date('Y-m-d')
                                    );
                                    
                                    $mail_data['mail_view']='_pages/mails/vw_registration_mail';

                                    $html=$this->theme->view('_pages/mails/vw_registration_mail',$mail_data['data'],true);

                                    //echo $html;die;

                                    $_email_settings=$this->sm->get_system_settings(array('settings_inst_id'=>$param['inst_id'],'settings_type'=>'email_settings'));

                                    $email_settings=unserialize($_email_settings->settings_value);

                                    //$mail_msg=$this->onSendMail($mail_data);

                                    $config = Array(
                                        'protocol' => 'smtp',//$email_settings['MAIL_PROTOCOL'],
                                        'smtp_host' => 'smtp.hostinger.com ',//$email_settings['MAIL_SERVER'],
                                        'smtp_port' => '465',//$email_settings['MAIL_PORT'],
                                        'smtp_user' => 'cloudcampus@cloudcampus.org.in',//$email_settings['WEBMASTER_EMAIL'],
                                        'smtp_pass' => 'h514[5ulhK&^',//$email_settings['MAIL_PASSWORD'],
                                        'mailtype'  => 'html',
                                        'wordwrap'=> TRUE, 
                                        'charset'   => 'utf-8'
                                    );
                                    $this->load->library('email', $config);
                                    // $this->email->set_newline("\r\n");

                                    $this->email->set_crlf( "\r\n" );
                                    
                                    $this->email->from('cloudcampus@cloudcampus.org.in', $inst_name);
                                    $this->email->to($stu_email); 
                                    $this->email->subject($mail_data['mail_subject']);
                                    $this->email->message(htmlspecialchars_decode($html));

                                    if($this->email->send())
                                    {
                                        $return['success']='Student registered successfully.'.$mail_msg;
                                    }
                                    else
                                    {
                                        $return['error']='Student registered successfully.'.$this->email->print_debugger();
                                    }*/

                                    $return['success']='Student registered successfully';

                                    
                                }else{
                                    $return['error']='Student data not registered.';
                                }

                            }else{
                                $return['error']='Student not registered';
                            }

                        }else{
                            $return['error']='Student already registered';
                        }

                    }else{
                        $return['error']='Student already registered';
                    }
                }else if($student_data_can_be_uploaded=='no'){
                    $return['info']='you have reached to student upload limit of '.$student_upload_limit.' students.You need to upgrade your limit';
                }

                    

                json_headers($return);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    public function onDeleteStudents(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $student_id=post_data('student_id');
                $userdata=$this->data['userdata'];

                if(!empty($student_id)){
                    $student_id=decode_data($student_id);

                    $student_data=$this->um->get_user(array('stu_id'=>$student_id),'student');

                    if(!empty($student_data)){

                        $adm_data=$this->adm->get_admission_data(array('admission_stu_id'=>$student_data->stu_user_id));                        

                        $deleted=$this->um->delete_students(array('stu_user_id'=>$student_data->stu_user_id));
    
                        if($deleted){                            
                          
                            $logs_data=array(
                                'log_user_type'=>$userdata->user_type,
                                'log_user_id'=>$userdata->user_id,
                                'log_stu_id'=>$adm_data->admission_stu_id,
                                'log_user_code'=>$userdata->user_code,
                                'admission_data'=>$adm_data
                            );

                            create_admission_data_delete_log($logs_data);
                            
                            $return['success']='Student Data Deleted';
                        }else{
                            $return['error']='Student Data not deleted';
                        }

                    }else{
                        $return['error']='Student data not found in the system';
                    }

                }else{
                    $return['error']='No student data found';
                }

                json_headers($return);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    public function onCheckEmailExists(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            $stu_email=post_data('stu_email');
            $student_data=$this->um->get_user(array('stu_email'=>$stu_email),'student');

            if(!empty($student_data)){
                echo 'false';
            }else{
                echo 'true';
            }
        }
    }

    public function onCheckPhoneNoExists(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            $stu_phone=post_data('stu_phone');
            $student_data=$this->um->get_user(array('stu_ph_no'=>$stu_phone),'student');

            if(!empty($student_data)){
                echo 'false';
            }else{
                echo 'true';
            }
        }
    }


    public function onUploadStudentDocs(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $institute_data=check_institute($this->data['userdata']);
                $inst_id=$this->inst_id;
                $inst_type=$this->inst_type;
                $inst_code=$this->inst_code;
                $student_id=post_data('student_id');
                $user_id=$this->user_id;

                if(!empty($student_id)){

                    $stu_id=decode_data($student_id);
                    $student_data=$this->um->get_students(array('stu_id'=>$stu_id));
                    $storage_dir='institutes/'.$inst_code.'/students';

                    // 'aadhar_card','madhyamik_admit_card','madhyamik_result_card','12th_result_card','grad_result_card','post_grad_result_card','other_certificate_card','pan_card','profile_photo','college_logo','college_branch_logo','college_printing_logo','college_report_card_logo','college_report_card_logo','college_authorize_signature_logo','college_seal_logo','student_profile_photo','student_signature_photo','madhyamik_registration_card','madhyamik_rank_card','cheque_scan_backcopy_file','cheque_scan_frontcopy_file','asset_image','employee_docs'

                   

                    if(isset($_FILES['stu_addhar_card_file']) && $_FILES['stu_addhar_card_file']['name']!=''){

                        $aadhar_card_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_addhar_card_file',
                            'file_types'=>'png,jpg,jpeg,webp',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'aadhar_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $aadhar_card_file_id=$this->onUploadFiles($aadhar_card_file);

                        if(!is_numeric($aadhar_card_file_id)){
                            $file_error[]='AADHAR Card '.$aadhar_card_file_id;
                        }
                    }

                    if(isset($_FILES['stu_madhyamik_admit_card_file']) && $_FILES['stu_madhyamik_admit_card_file']['name']!=''){

                        $profile_picture_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_madhyamik_admit_card_file',
                            'file_types'=>'png,jpg,jpeg,webp',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'madhyamik_admit_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $profile_file_id=$this->onUploadFiles($profile_picture_file);

                        if(!is_numeric($profile_file_id)){
                            $file_error[]='10th Admit Card '.$profile_file_id;
                        }
                    }

                    if(isset($_FILES['stu_madhyamik_reg_card_file']) && $_FILES['stu_madhyamik_reg_card_file']['name']!=''){

                        $madhyamik_registration_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_madhyamik_reg_card_file',
                            'file_types'=>'png,jpg,jpeg,webp',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'madhyamik_registration_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $madhyamik_registration_file_id=$this->onUploadFiles($madhyamik_registration_file);

                        if(!is_numeric($madhyamik_registration_file_id)){
                            $file_error[]='10th Admit Card '.$madhyamik_registration_file_id;
                        }
                    }

                    if(isset($_FILES['stu_madhyamik_result_file']) && $_FILES['stu_madhyamik_result_file']['name']!=''){

                        $madhyamik_result_card_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_madhyamik_result_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'madhyamik_result_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $madhyamik_result_card_file_id=$this->onUploadFiles($madhyamik_result_card_file);

                        if(!is_numeric($madhyamik_result_card_file_id)){
                            $file_error[]='10th Result Card '.$madhyamik_result_card_file_id;
                        }
                    }

                    if(isset($_FILES['stu_12th_result_file']) && $_FILES['stu_12th_result_file']['name']!=''){

                        $twelfth_result_card_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_12th_result_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'12th_result_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $twelfth_result_card_file_id=$this->onUploadFiles($twelfth_result_card_file);

                        if(!is_numeric($twelfth_result_card_file_id)){
                            $file_error[]='12th Result Card '.$twelfth_result_card_file_id;
                        }
                    }

                    if(isset($_FILES['stu_grad_result_file']) && $_FILES['stu_grad_result_file']['name']!=''){

                        $grad_result_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_grad_result_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'grad_result_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $grad_result_file_id=$this->onUploadFiles($grad_result_file);

                        if(!is_numeric($grad_result_file_id)){
                            $file_error[]='Graduation Result '.$grad_result_file_id;
                        }
                    }

                    if(isset($_FILES['stu_post_grad_result_file']) && $_FILES['stu_post_grad_result_file']['name']!=''){

                        $post_grad_result_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_post_grad_result_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'post_grad_result_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $post_grad_result_card_id=$this->onUploadFiles($post_grad_result_file);

                        if(!is_numeric($post_grad_result_card_id)){
                            $file_error[]='Post Graduation Result '.$post_grad_result_card_id;
                        }
                    }

                    if(isset($_FILES['stu_other_certificate_file']) && $_FILES['stu_other_certificate_file']['name']!=''){

                        $stu_other_certificate_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_other_certificate_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'other_certificate_card',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $stu_other_certificate_file_id=$this->onUploadFiles($stu_other_certificate_file);

                        if(!is_numeric($stu_other_certificate_file_id)){
                            $file_error[]='Other Certificate File '.$stu_other_certificate_file_id;
                        }
                    }

                    if(isset($_FILES['stu_profile_photo_file']) && $_FILES['stu_profile_photo_file']['name']!=''){

                        $profile_picture_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_profile_photo_file',
                            'file_types'=>'png,jpg,jpeg,webp',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'student_profile_photo',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $profile_file_id=$this->onUploadFiles($profile_picture_file);

                        if(!is_numeric($profile_file_id)){
                            $file_error[]='Profile Picture '.$profile_file_id;
                        }
                    }

                    if(isset($_FILES['stu_post_signature_file']) && $_FILES['stu_post_signature_file']['name']!=''){

                        $signature_file=array(
                            'file_size'=>'0.05',
                            'file_name'=>'stu_post_signature_file',
                            'file_types'=>'png,jpg,jpeg,pdf',
                            'file_type_of'=>'student',
                            'file_storage_type'=>'student_signature_photo',
                            'file_storage_dir'=>$storage_dir,
                            'file_storage_type_id'=>$student_data->stu_user_id,
                            'file_parent_id'=>$inst_id,
                            'file_compress'=>false,
                            'file_operation_type'=>'update',
                            'file_uploaded_by'=>$user_id
                        );

                        $signature_file_id=$this->onUploadFiles($signature_file);

                        if(!is_numeric($signature_file_id)){
                            $file_error[]='Signature  '.$signature_file_id;
                        }
                    }

                    if(isset($file_error) && !empty($file_error)){
                        $return['error']=$file_error;
                    }else{
                        $return['success']='Documents has been updated';
                    }

                }else{
                    $return['error']='Data mnipulation not allowed.';
                }

                json_headers($return);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    function indexOnlineApplicationForm(){
        if(session_userdata('isAdminLoggedin')){

             echo 'Online Application Form';

            // $this->data['page_title']='Students';

            // $this->data['hostels']=$this->hm->get_hostel(array('hostel_inst_id'=>$this->data['userdata']->user_id),FALSE);

            // $this->theme->title($this->data['page_title'])->load('users/vw_students', $this->data);
        }else{

            redirect($this->data['base_url']);
        }
    }


    public function onUploadExcelFileData(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){
                error_reporting(0);

                $user_id=decode_data(session_userdata('admin_id'));
                $data_imported=FALSE;

                $today=date('Y-m-d');

                $tempdata=array();

                $inst_id=$this->data['userdata']->user_id;

                if($this->data['userdata']->user_type=='institute'){
                    $parent_inst_id=$this->data['userdata']->user_id;
                }else if($this->data['userdata']->user_type=='institute_branch'){
                    $parent_inst_id=$this->data['userdata']->branch_parent_inst_id;
                }

                $excel_type=post_data('excel_type');
              
                $table_rows='';

                $_exceldata=array();

                // $inipath = php_ini_loaded_file();

                // if ($inipath) {
                //     echo 'Loaded php.ini: ' . $inipath;
                // } else {
                //    echo 'A php.ini file is not loaded';
                // }

                //print_obj($_FILES['excel_data_file']);die;               

                if(isset($_FILES['excel_data_file']) && $_FILES['excel_data_file']['name']!=''){
                    // $get_excel_tempstatus_students=$this->um->get_excel_tempstatus_students(array('phone_no'=>$session,'course_id'=>$course,'inst_id'=>$inst_id,'excel_file_name'=>$_FILES['excel_file']['name']));                         

                    // if(empty($get_excel_tempstatus_students)){
                        
                    // }else{
                    //     $this->data['excel_temp_data']=$this->um->get_excel_temp_students(array('temp_status_id'=>$get_excel_tempstatus_students->excel_status_id),FALSE);
                    //     $this->data['session_id']=$get_excel_tempstatus_students->session_id;
                    //     $this->data['course_id']=$get_excel_tempstatus_students->course_id;
                    //     $this->data['subject_id']=$get_excel_tempstatus_students->subject_id;
                    //     $return['html']=$this->theme->view('_pages/admission/vw_admission_seatbook_excel_temp_data',$this->data,true);
                    //     $return['error']='Excel file already uploaded with same file name.Please check again.';
                    // }

                    $excel_data=array(
                        'file_size'=>'10',
                        'file_name'=>'excel_data_file',
                        'file_types'=>'xls,xlsx',
                    );

                    $file_path=$this->onUploadExcelFiles($excel_data);

                    // print_obj($file_path);
                    // print_obj(is_dir($file_path));die;

                    // is_file(filename)

                    if(is_file($file_path)){
                        $validated=$this->onValidateExcel($file_path);

                        //print_obj($validated);die;

                        if($validated['validated']==200){
                            $exceldata=$validated['exceldata'];

                            //print_obj($exceldata);die;

                            if(!empty($exceldata)){
                               foreach ($exceldata as $_key => $_value) {
                                    $_exceldata[]=array_filter($_value[0]);
                                } 
                            }

                                

                            //print_obj($_exceldata);die;

                            if(!empty($_exceldata)){

                                $temp_status_data_to_add=array(
                                    'inst_id'=>$inst_id,
                                    'excel_upload_type'=>$excel_type,
                                    'excel_file_name'=>$_FILES['excel_data_file']['name'],
                                    'excel_upload_status'=>'uploaded_not_imported',
                                    'excel_uploaded_by'=>$user_id
                                );

                                $status_added=$this->um->store_excel_tempstatus_students($temp_status_data_to_add);

                                if($status_added){
                                    foreach ($_exceldata as $key => $value){
                                        $row=$key+1;

                                        //print_obj($value[$key][$key]);die;

                                        $f_name             =   isset($value[0])?strip_javascript(xss_clean(trim($value[0]))):'';
                                        $m_name             =   isset($value[1])?strip_javascript(xss_clean(trim($value[1]))):'';
                                        $l_name             =   isset($value[2])?strip_javascript(xss_clean(trim($value[2]))):'';
                                        $email              =   isset($value[3])?strip_javascript(xss_clean(trim($value[3]))):'';
                                        $phno               =   isset($value[4])?strip_javascript(xss_clean(trim($value[4]))):'';
                                        $whatsapp_no        =   isset($value[5])?strip_javascript(xss_clean(trim($value[5]))):'';
                                        $dob                =   isset($value[6])?strip_javascript(xss_clean(trim($value[6]))):'';
                                        $aadhar             =   isset($value[7])?strip_javascript(xss_clean(trim($value[7]))):'';
                                        $gender             =   isset($value[8])?strip_javascript(xss_clean(trim($value[8]))):'';


                                        $father_first_name      =   isset($value[9])?strip_javascript(xss_clean(trim($value[9]))):'';
                                        $father_middle_name     =   isset($value[10])?strip_javascript(xss_clean(trim($value[10]))):'';
                                        $father_last_name       =   isset($value[11])?strip_javascript(xss_clean(trim($value[11]))):'';
                                        $father_phone_no        =   isset($value[12])?strip_javascript(xss_clean(trim($value[12]))):'';

                                        $mother_first_name   =   isset($value[13])?strip_javascript(xss_clean(trim($value[13]))):'';
                                        $mother_middle_name  =   isset($value[14])?strip_javascript(xss_clean(trim($value[14]))):'';
                                        $mother_last_name    =   isset($value[15])?strip_javascript(xss_clean(trim($value[15]))):'';


                                        $tenth_passing_year     =   isset($value[16])?strip_javascript(xss_clean(trim($value[16]))):'';
                                        $tenth_marks            =   isset($value[17])?strip_javascript(xss_clean(trim($value[17]))):'';
                                        $tenth_percentage       =   isset($value[18])?strip_javascript(xss_clean(trim($value[18]))):'';


                                        $twelfth_passing_year   =   isset($value[19])?strip_javascript(xss_clean(trim($value[19]))):'';
                                        $twelfth_marks          =   isset($value[20])?strip_javascript(xss_clean(trim($value[20]))):'';
                                        $twelfth_percentage     =   isset($value[21])?strip_javascript(xss_clean(trim($value[21]))):'';

                                        //echo $f_name;


                                        if(in_array($gender, array('m','M','male','Male','MALE'))){
                                            $gender='male';
                                        }else if(in_array($gender, array('f','F','female','Female','FEMALE'))){
                                            $gender='female';
                                        }else{
                                            $gender='others';
                                        }


                                        $tempdata[]=array(
                                            'temp_status_id'=>$status_added,
                                            'first_name'=>$f_name,
                                            'middle_name'=>$m_name,
                                            'last_name'=>$l_name,
                                            'email'=>$email,
                                            'phone_no'=>$phno,
                                            'whatsapp_no'=>$whatsapp_no,
                                            'dob'=>$dob,
                                            'aadhar'=>$aadhar,
                                            'gender'=>$gender,
                                            'father_first_name'=>$father_first_name,
                                            'father_middle_name'=>$father_middle_name,
                                            'father_last_name'=>$father_last_name,
                                            'father_phone_no'=>$father_phone_no,
                                            'mother_first_name'=>$mother_first_name,
                                            'mother_middle_name'=>$mother_middle_name,
                                            'father_last_name'=>$mother_last_name,
                                            'mother_last_name'=>$father_phone_no,
                                            'tenth_passing_year'=>$tenth_passing_year,
                                            'tenth_passing_marks'=>$tenth_marks,
                                            'tenth_percentage'=>$tenth_percentage,
                                            'twelfth_passing_year'=>$twelfth_passing_year,
                                            'twelfth_passing_marks'=>$twelfth_marks,
                                            'twelfth_passing_percentage'=>$twelfth_percentage,
                                            'created_by'=>$user_id
                                        );
                                    }

                                    //die;

                                    //print_obj($tempdata);die;

                                    if(!empty($tempdata)){
                                        $added=$this->um->store_excel_temp_students($tempdata,TRUE);

                                        if($added){

                                            $tempdata_status=$this->um->get_excel_tempstatus_students(array('excel_status_id'=>$status_added,'excel_upload_type'=>$excel_type));
                                            $this->data['excel_temp_data']=$this->um->get_excel_temp_students(array('temp_status_id'=>$tempdata_status->excel_status_id,'created_by'=>$user_id,'DATE(created_at)'=>$today),FALSE);

                                            $this->data['temp_data_type']=$excel_type;
                                            $this->data['session_id']=$session;
                                            $this->data['course_id']=$course;
                                            $this->data['subject_id']=$subject;
                                            $return['html']=$this->theme->view('_pages/admission/vw_admission_seatbook_excel_temp_data',$this->data,true);
                                            $return['success']='Excel data uploaded.You need to verify the data in next popup for final data import';
                                        }else{
                                            $return['error']='Error occurred.Try after some time.';
                                        }
                                    }else{
                                        $return['error']='No data found to import';
                                    }
                                }else{
                                    $return['error']='Excel can not be uploadede now.Try after sometime.';
                                }      
                            }else{
                                $return['error']='Data can not be imported now.Try after sometime.';
                            }
                        }else{
                            $return['error']=$validated['error'];
                        }
                    }else{
                        $return['error']='File upload error';
                    }                        

                }else{
                    $return['error']='Excel file is missing';
                }
                   

                header('Content-Type: application/json');

                echo json_encode($return);

            }else{
                redirect($this->data['admin_base_url']);
            }
        }else{
            redirect($this->data['admin_base_url']);
        }
    }


    public function onValidateExcel($uploaded_file){
        if($uploaded_file!=''){
            $row_arrays=array(
                'first_name',
                'middle_name',
                'last_name',
                'email',
                'phone_no',
                'whatsapp_no',
                'dob',
                'aadhar',
                'gender',
                'father_fisrt_name',
                'father_middle_name',
                'father_last_name',
                'father_phone_no',
                'mother_first_name',
                'mother_middle_name',
                'mother_last_name',
                '10th_passing_year',
                '10th_marks',
                '10th_percentage',
                '12th_passing_year',
                '12th_marks',
                '12th_percentage'
            );

            $heading=$this->excel->getRangedColumnData($uploaded_file,'A','V',true,false);

            $diff = array_diff($heading[0][0], $row_arrays);

            if(empty($diff) && (count($heading[0][0])===22)){
                $count=1;

                $exceldata=$this->excel->getRangedColumnData($uploaded_file,'A','V',true,false);

                //print_obj($exceldata);die;

                $table_rows='';
                if($exceldata!='' || !empty($exceldata)){
                    // foreach ($exceldata as $key => $value){
                    //  $count++;
                    //  $row=$key+2;

                    //  $name   =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][1]))):'';
                    //  $email  =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][2]))):'';
                    //  $phno   =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][3]))):'';
                    //  $estd   =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][4]))):'';
                    //  $country    =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][5]))):'';
                    //  $state  =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][6]))):'';
                    //  $district   =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][7]))):'';
                    //  $city   =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][8]))):'';
                    //  $address    =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][9]))):'';
                    //  $pincode    =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][10]))):'';
                    //  $university =   isset($value[0][1])?strip_javascript(xss_clean(trim($value[0][11]))):'';

                        
                    // }

                    unset($exceldata[0]);

                    return ['validated'=>200,'exceldata'=>$exceldata];
                }else{
                    //return 'Excel data format is wrong.Please download the sample excel for your reference 1';
                    $table_rows='';
                    return ['validated'=>400,'table_rows'=>$table_rows,'error'=>'Excel data format headings are wrong.Please download the sample excel for your reference'];
                }
            }else{
                $table_rows='';
                //return 'Excel data format is wrong.Please download the sample excel for your reference 2';
                return ['validated'=>400,'table_rows'=>$table_rows,'error'=>'Excel data format headings are wrong.Please download the sample excel for your reference'];
            }
        }else{
            return ['error'=>'Excel file not selected'];
        }
    }


    public function onImportSeatbookingData(){
         if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $user_id=decode_data(session_userdata('admin_id'));
                $data_imported=FALSE;

                $inst_id=$this->data['userdata']->user_id;

                if($this->data['userdata']->user_type=='institute'){
                    $parent_inst_id=$this->data['userdata']->user_id;
                }else if($this->data['userdata']->user_type=='institute_branch'){
                    $parent_inst_id=$this->data['userdata']->branch_parent_inst_id;
                }

                //$excel_data=$this->input->post('excel_data');

                $session=post_data('session_id');
                $course=post_data('course_id');
                $subject=post_data('subject_id');

                $first_name=post_data('first_name');
                $middle_name=post_data('middle_name');
                $last_name=post_data('last_name');
                $email=post_data('email');
                $phone_no=post_data('phone_no');
                $whatsapp_no=post_data('whatsapp_no');
                $dob=post_data('dob');
                $aadhar=post_data('aadhar');
                $gender=post_data('gender');

                $father_first_name=post_data('father_first_name');
                $father_middle_name=post_data('father_middle_name');
                $father_last_name=post_data('father_last_name');

                $father_phone_no=post_data('father_phone_no');

                $mother_first_name=post_data('mother_first_name');
                $mother_middle_name=post_data('mother_middle_name');
                $mother_last_name=post_data('mother_last_name');
                $twelfth_passing_year=post_data('twelfth_passing_year');
                $twelfth_passing_marks=post_data('twelfth_passing_marks');
                $twelfth_passing_percentage=post_data('twelfth_passing_percentage');

                $temp_data_id=post_data('temp_data_id');

                $data_row=post_data('data_row');

                if(!empty($email) && !empty($phone_no)){
                    $student_data_with_phone=$this->um->get_user(array('stu_inst_id'=>$inst_id,'stu_ph_no'=>$phone_no),'student');
                    $student_data_with_mail=$this->um->get_user(array('stu_inst_id'=>$inst_id,'stu_email'=>$email),'student');

                    if(empty($student_data_with_phone) && empty($student_data_with_mail)){

                        if($dob!='0000-00-00'){
                            $user_age=calculate_age($dob);

                            if(valid_email($email) && isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)==12)){

                                if($user_age>=18){
                                    $data_to_add=array(  
                                        'stu_inst_type'=>$this->data['userdata']->user_type,                      
                                        'stu_inst_id'=>$inst_id,
                                        'stu_inst_parent_id'=>$parent_inst_id,
                                        'stu_first_name'=>$first_name,
                                        'stu_mid_name'=>(!empty($middle_name))?$middle_name:null,
                                        'stu_last_name'=>$last_name,
                                        'stu_email'=>$email,
                                        'stu_ph_no'=>$phone_no,
                                        'stu_whatsapp_no'=>$whatsapp_no,
                                        'stu_dob'=>date('Y-m-d',strtotime($dob)),
                                        'stu_gender'=>$gender,
                                        'stu_nationality'=>'1',
                                        'stu_father_first_name'=>$father_first_name,
                                        'stu_father_mid_name'=>$father_middle_name,
                                        'stu_father_last_name'=>$father_last_name,
                                        'stu_father_ph_no'=>$father_phone_no,
                                        'stu_mother_first_name'=>$mother_first_name,
                                        'stu_mother_mid_name'=>$mother_middle_name,
                                        'stu_mother_last_name'=>$mother_last_name,
                                        'created_by'=>$this->data['userdata']->user_id,
                                        'created_at'=>date('Y-m-d')
                                    );

                                    $student_profile_id=$this->um->store_students($data_to_add);


                                    if($student_profile_id){
                                        $password=generate_password('Password@123');

                                        $student_userdata=array(
                                            'user_name'=>$email,
                                            'user_password'=>$password,
                                            'user_password_visible'=>encode_data('Password@123'),
                                            'user_type'=>'student',
                                            'user_permissions'=>null,
                                            'user_status'=>'active',
                                            'created_by_type'=>'ntadmin',
                                            'created_by'=>$this->data['userdata']->user_id,
                                            'created_at'=>date('Y-m-d')
                                        );

                                        $student_user_id=$this->um->store_users($student_userdata);


                                        $this->um->delete_excel_temp_students(array('phone_no'=>$phone_no));
                                        $temp_data_count=$this->um->get_count_excel_temp_students(array('temp_status_id'=>$temp_data_id));
                                        $return['temp_data_count']=$temp_data_count;
                                        $data_row_color='#00c22f';
                                        $return['success']='Students for seat bookings added at row no:'.$data_row;

                                    }else{
                                        $data_row_color='#f12409';
                                        $return['error']='Undefined error occurred at row no:'.$data_row;
                                    }
                                }else{
                                    $data_row_color='#f12409';
                                    $return['error']='Student is underage at row:'.$data_row;
                                }

                            }else if(valid_email($email) && !isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)==12)){
                                $data_row_color='#f12409';
                                $return['error']='DOB format is not valid at row:'.$data_row;
                            }else if(!valid_email($email) && isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)==12)){
                                $data_row_color='#f12409';
                                $return['error']='Email address is not valid at row:'.$data_row;
                            }else if(valid_email($email) && isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)!=12)){
                                $data_row_color='#f12409';
                                $return['error']='Aadhar no is not valid at row:'.$data_row;
                            }else if(!valid_email($email) && isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)!=12)){
                                $data_row_color='#f12409';
                                $return['error']='Email address & Aadhar no is not valid at row:'.$data_row;
                            }else if(valid_email($email) && !isDateValid($dob) && (is_numeric($aadhar) && strlen($aadhar)!=12)){
                                $data_row_color='#f12409';
                                $return['error']='DOB & Aadhar no is not valid at row:'.$data_row;
                            }
                            else{
                                $data_row_color='#f12409';
                                $return['error']='Email address , DOB, Aadhar is not valid at row:'.$data_row;
                            }
                        }else{
                            $data_row_color='#f12409';
                            $return['error']='Dob format is incorrect at row '.$data_row.'.Format should be dd-mm-yyyy';
                        }




                    }else if(empty($student_data_with_phone) && !empty($student_data_with_mail)){
                        $data_row_color='#f12409';
                        $return['error']='Student alreday exists with same email address at row:'.$data_row;
                    }else if(!empty($student_data_with_phone) && empty($student_data_with_mail)){
                        $data_row_color='#f12409';
                        $return['error']='Student alreday exists with same phone no at row:'.$data_row;
                    }
                    else{
                        $data_row_color='#f12409';
                        $return['error']='Student alreday exists with same phone no or email address at row:'.$data_row;
                    }

                }else{
                    $data_row_color='#f12409';
                    $return['error']='Data not added at row no:'.$data_row;
                }

                    
                $return['data_row']=$data_row;
                $return['data_row_color']=$data_row_color;

                json_headers($return);

            }else{
                redirect($this->data['admin_base_url']);
            }
        }else{
            redirect($this->data['admin_base_url']);
        }
    }


    /**Excel Export**/
    public function onExportToExcel(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $stu_ids=$this->input->post('stu_ids');

                if(!empty($stu_ids)){

                    $students=$this->um->_get_users($stu_ids,'stu_id,stu_user_id,stu_first_name,stu_mid_name,stu_last_name,religion_name,stu_first_name,stu_user_code,stu_dob,stu_gender,stu_ph_no,stu_emergency_ph_no,stu_whatsapp_no,stu_aadhar,stu_dob,stu_father_first_name,stu_father_mid_name,stu_father_last_name,stu_father_ph_no,stu_father_email,stu_father_income,stu_father_occupation,stu_mother_first_name,stu_mother_mid_name,stu_mother_last_name,stu_mother_ph_no,stu_mother_email,stu_mother_occupation,stu_father_is_guardian,stu_guardian_first_name,stu_guardian_mid_name,stu_guardian_last_name,stu_guardian_ph_no,stu_guardian_email,stu_guardian_income,stu_cur_addr_co,stu_cur_addr_country,stu_cur_city,stu_cur_district,stu_cur_pincode,stu_cur_ps,stu_cur_po,stu_cur_address_line,stu_cur_address_landmark,stu_perma_address_as_cur_address,stu_perma_addr_co,stu_perma_addr_country,stu_perma_state,stu_perma_city,stu_perma_district,stu_perma_pincode,stu_perma_ps,stu_perma_po,stu_perma_address_line,stu_perma_address_landmark,stu_same_address,stu_last_qualification_board,stu_last_qualification,stu_passing_year,stu_passing_percentage,stu_cur_state,,religion_name,caste_name');

                    //print_obj($students);die;


                    if(!empty($students)){
                        foreach ($students as $key => $value) {

                            if($value->stu_first_name){
                                $stu_full_name=strtoupper($value->stu_first_name.' '.$value->stu_mid_name.' '.$value->stu_last_name);
                            }else{
                                $stu_full_name=strtoupper($value->stu_first_name.' '.$value->stu_last_name);
                            }

                            if(!empty($value->stu_cur_address_landmark)){
                                $stu_address='C/O:'.$value->stu_perma_addr_co.','.$value->stu_perma_address_line.','.$value->stu_perma_address_landmark.','.$value->stu_perma_pincode;
                            }else{
                                $stu_address='C/O:'.$value->stu_perma_addr_co.','.$value->stu_perma_address_line.','.$value->stu_perma_pincode;
                            }

                            $admission_data=$this->adm->__get_admission_data(array('admission_stu_id'=>$value->stu_user_id),'admission_stu_id,admission_sess_id,admission_date,admission_code,course_id,course_name,course_code,session_start_year,session_end_year');

                            //print_obj($admission_data);die;

                            $seatbooking_data=$this->adm->__get_seat_bookings_data(array('booking_stu_profile_id'=>$value->stu_id),'booking_stu_profile_id,booking_code,booking_sess_id,course_id,course_name,course_code,session_start_year,session_end_year,created_at');


                            $data_to_export=array(
                                'stu_user_id'=>$value->stu_user_id,
                                'stu_name'=>$stu_full_name,
                                'stu_code'=>$value->stu_user_code,
                                'stu_dob'=>date('d-m-Y',strtotime($value->stu_dob)),
                                'stu_gender'=>ucwords($value->stu_gender),
                                'stu_religion'=>$value->religion_name,
                                'stu_caste'=>$value->caste_name,
                                'stu_ph_no'=>$value->stu_ph_no,
                                'stu_emergency_ph_no'=>$value->stu_emergency_ph_no,
                                'stu_whatsapp_no'=>$value->stu_whatsapp_no,
                                'stu_aadhar'=>$value->stu_aadhar,
                                'stu_dob'=>$value->stu_dob,
                                'stu_email'=>$value->stu_email,
                                'stu_blood_group'=>$value->stu_blood_group,
                                'stu_father_first_name'=>$value->stu_father_first_name,
                                'stu_father_mid_name'=>$value->stu_father_mid_name,
                                'stu_father_last_name'=>$value->stu_father_last_name,
                                'stu_father_ph_no'=>$value->stu_father_ph_no,
                                'stu_father_email'=>$value->stu_father_email,
                                'stu_father_income'=>$value->stu_father_income,
                                'stu_father_occupation'=>$value->stu_father_occupation,
                                'stu_mother_first_name'=>$value->stu_mother_first_name,
                                'stu_mother_mid_name'=>$value->stu_mother_mid_name,
                                'stu_mother_last_name'=>$value->stu_mother_last_name,
                                'stu_mother_ph_no'=>$value->stu_mother_ph_no,
                                'stu_mother_email'=>$value->stu_mother_email,
                                'stu_mother_occupation'=>$value->stu_mother_occupation,
                                'stu_father_is_guardian'=>$value->stu_father_is_guardian,
                                'stu_guardian_first_name'=>$value->stu_guardian_first_name,
                                'stu_guardian_mid_name'=>$value->stu_guardian_mid_name,
                                'stu_guardian_last_name'=>$value->stu_guardian_last_name,
                                'stu_guardian_ph_no'=>$value->stu_guardian_ph_no,
                                'stu_guardian_email'=>$value->stu_guardian_email,
                                'stu_guardian_income'=>$value->stu_guardian_income,
                                'stu_cur_addr_co'=>$value->stu_cur_addr_co,
                                'stu_cur_addr_country'=>$value->stu_cur_addr_country,
                                'stu_cur_city'=>$value->stu_cur_city,
                                'stu_cur_district'=>$value->stu_cur_district,
                                'stu_cur_pincode'=>$value->stu_cur_pincode,
                                'stu_cur_ps'=>$value->stu_cur_ps,
                                'stu_cur_po'=>$value->stu_cur_po,
                                'stu_cur_address_line'=>$value->stu_cur_address_line,
                                'stu_cur_address_landmark'=>$value->stu_cur_address_landmark,
                                'stu_perma_address_as_cur_address'=>$value->stu_perma_address_as_cur_address,
                                'stu_perma_addr_co'=>$value->stu_perma_addr_co,
                                'stu_perma_addr_country'=>$value->stu_perma_addr_country,
                                'stu_perma_state'=>$value->stu_perma_state,
                                'stu_perma_city'=>$value->stu_perma_city,
                                'stu_perma_district'=>$value->stu_perma_district,
                                'stu_perma_pincode'=>$value->stu_perma_pincode,
                                'stu_perma_ps'=>$value->stu_perma_ps,
                                'stu_perma_po'=>$value->stu_perma_po,
                                'stu_perma_address_line'=>$value->stu_perma_address_line,
                                'stu_perma_address_landmark'=>$value->stu_perma_address_landmark,
                                'stu_address'=>$value->stu_address,
                                'stu_last_qualification_board'=>$value->stu_last_qualification_board,
                                'stu_last_qualification'=>$value->stu_last_qualification,
                                'stu_passing_year'=>$value->stu_passing_year,
                                'stu_passing_percentage'=>$value->stu_passing_percentage                                
                            );


                            if(!empty($admission_data)){
                                $get_session_course_student_wise=$this->sessm->get_session_course_student_wise(array('session_stu_id'=>$value->stu_user_id,'session_course_id'=>$admission_data->course_id));

                                //print_obj($get_session_course_student_wise);die;

                                if(empty($get_session_course_student_wise)){
                                    $session_course=$this->sessm->get_session_course(array('session_id'=>$admission_data->admission_sess_id,'session_course_id'=>$admission_data->course_id));
                                    $course_cost=$session_course->session_course_fees;
                                }else{
                                    $cousrse_cost=$get_session_course_student_wise->session_course_fees;
                                }


                                //$cousrse_cost=$get_session_course_student_wise->session_course_fees;

                                $data_to_export['stu_admission_code']=$admission_data->admission_code;
                                $data_to_export['stu_course']=$admission_data->course_name;
                                $data_to_export['stu_course_cost']=$cousrse_cost;
                                $data_to_export['stu_session']=$admission_data->session_start_year.'-'.$admission_data->session_end_year;
                                $data_to_export['stu_admission_date']=date('d-m-Y',strtotime($admission_data->admission_date));
                                $data_to_export['stu_admission_status']='Admission Completed';  
                            }else{
                                $get_session_course_student_wise=$this->sessm->get_session_course_student_wise(array('session_stu_id'=>$value->stu_user_id,'session_course_id'=>$seatbooking_data->course_id));

                                if(empty($get_session_course_student_wise)){
                                    $session_course=$this->sessm->get_session_course(array('session_id'=>$seatbooking_data->booking_sess_id,'session_course_id'=>$seatbooking_data->course_id));
                                    $course_cost=$session_course->session_course_fees;
                                }else{
                                    $cousrse_cost=$get_session_course_student_wise->session_course_fees;
                                }

                                //$cousrse_cost=$get_session_course_student_wise->session_course_fees;

                                $data_to_export['stu_admission_code']=$seatbooking_data->booking_code;
                                $data_to_export['stu_course']=$seatbooking_data->course_name;
                                $data_to_export['stu_course_cost']=$cousrse_cost;
                                $data_to_export['stu_session']=$seatbooking_data->session_start_year.'-'.$seatbooking_data->session_end_year;
                                $data_to_export['stu_admission_date']=date('d-m-Y',strtotime($seatbooking_data->created_at));
                                $data_to_export['stu_admission_status']='Seat Booked';                                
                            }             


                            $data['students_list'][]=$data_to_export;
                        }
                        

                        $htmlString=$this->theme->view('_pages/reports_format/vw_students_list_reports',$data,true);
                        $file_name='student_list_'.date('Y_m_d');

                        $file_path=write_html_excel($htmlString,$file_name);

                        $return['download_file']=$file_path;
                        $return['success']='Data exported';

                    }else{
                        $return['error']='No data found';
                    }


                }else{
                    $return['error']='Please select at leat one student';
                }

                json_headers($return);

            }else{
                redirect($this->data['admin_base_url']);
            }
        }else{
            redirect($this->data['admin_base_url']);
        }
    }



    public function indexStudentGuardians(){
        if(session_userdata('isAdminLoggedin')){

            $this->data['page_title']='Guardians';

            $institute_data=check_institute($this->data['userdata']);

            $inst_id=$institute_data['institute_id'];


            $this->theme->title($this->data['page_title'])->add_partial('partial_upload_excel_modal',$this->data)->add_partial('partial_temp_exceldata_load_modal',$this->data)->load('users/vw_students_guardians', $this->data);
        }else{

            redirect($this->data['base_url']);
        }
    }


    public function onSearchStudentsGuardiansList(){
        if(session_userdata('isAdminLoggedin')==TRUE && session_userdata('admin_id')){
            if($this->input->is_ajax_request() && $this->input->server('REQUEST_METHOD')=='POST'){

                $institute_data=check_institute($this->data['userdata']);
                $inst_id=$intitute_data['institute_id'];


                $param['column_order'] = array(
                    null,
                    'stu_first_name'
                );
                

                $param['column_search'] = array('stu_first_name','stu_mid_name','stu_last_name','stu_father_first_name','stu_father_mid_name','stu_father_last_name','stu_mother_first_name','stu_mother_mid_name','stu_mother_last_name');
                $param['is_removed']='no';
                $param['order'] = array('stu_id' => 'ASC');
                $posts=$this->input->post();


                if($posts['data_of']==='own'){
                    $param['inst_id']=$this->data['userdata']->user_id;
                }else if($posts['data_of']==='branch'){
                    $param['inst_parent_id']=$this->data['userdata']->user_id;
                }


                if(isset($posts['data_of_id']) && !empty($posts['data_of_id'])){
                    $param['inst_id']=$posts['data_of_id'];
                }

                if(isset($posts['stu_status']) && !empty($posts['stu_status'])){
                    $param['stu_status']=$posts['stu_status'];
                }

                $param['father_is_guardian']='yes';
                $param['mother_is_guardian']='yes';


                //$param['created_by']=session_userdata('admin_id');


                $list = $this->um->_get_students($posts,$param,FALSE,FALSE);

                //print_obj($list);die;
                
                
                $data = array();
                $no = isset($posts['start'])?$posts['start']:0;

                $action='';

                foreach ($list as $stu){
                    $no++;

                    $row = array();

                    $row[]  =   $no;

                    $active_session=$this->adm->get_admission_data(array('admission_stu_id'=>$stu->stu_user_id,'admission_data_active'=>'yes'));

                    //print_obj($active_session);die;

                    if($posts['data_of']==='branch'){
                        $param['inst_parent_id']=$this->data['userdata']->user_id;

                        $branch_data=$this->um->get_institute_branch(array('branch_user_id'=>$stu->stu_inst_id));

                        $row[]  =   $branch_data->branch_name;
                    }

                    if($stu->stu_mid_name!=''){
                        $stu_name=$stu->stu_first_name.' '.$stu->stu_mid_name.' '.$stu->stu_last_name;
                    }else{
                        $stu_name=$stu->stu_first_name.' '.$stu->stu_last_name;
                    }

                    $stu_image=$this->sm->get_file(array('storage_type'=>'student_profile_photo','storage_type_id'=>$stu->stu_user_id,'storage_parent_id'=>$stu->stu_inst_id));

                    if(!empty($stu_image) && is_file(FCPATH.$stu_image->media_disk_path)){
                        $image=base_url($stu_image->media_disk_path);
                    }else{
                        $image=$this->data['no_image'];
                    }

                    if($stu->stu_father_is_guardian=='yes' && $stu->stu_mother_is_guardian=='yes'){
                        if($stu->stu_father_first_name!='' && $stu->stu_mother_first_name!=''){
                            if($stu->stu_father_mid_name!=''){
                                $guardian='Father:'.$stu->stu_father_first_name.' '.$stu->stu_father_mid_name.' '.$stu->stu_father_last_name;                               
                            }else if($stu->stu_father_mid_name==''){
                                $guardian='Father:'.$stu->stu_father_first_name.' '.$stu->stu_father_last_name;
                            }
                            if($stu->stu_mother_mid_name!=''){
                                $guardian.='<br>Mother:'.$stu->stu_mother_first_name.' '.$stu->stu_mother_mid_name.' '.$stu->stu_father_last_name;
                            }else if($stu->stu_father_mid_name==''){
                                $guardian.='<br>Mother:'.$stu->stu_mother_first_name.' '.$stu->stu_mother_last_name;
                            }
                            $guardian_email='Father:'.$stu->stu_father_email;
                            $guardian_email.='<br>Mother:'.$stu->stu_mother_email;

                            $guardian_phone_no='Father:'.$stu->stu_father_ph_no;
                            $guardian_phone_no.='<br>Mother:'.$stu->stu_mother_ph_no;
                        }else{
                           $guardian='Not Given';
                           $guardian_email='Not Given';
                           $guardian_phone_no='Not Given';
                        } 
                        
                    }else if($stu->stu_father_is_guardian=='yes' && $stu->stu_mother_is_guardian=='no'){
                        if($stu->stu_father_first_name!=''){
                            if($stu->stu_father_mid_name!=''){
                                $guardian='Father:'.$stu->stu_father_first_name.' '.$stu->stu_father_mid_name.' '.$stu->stu_father_last_name;
                            }else if($stu->stu_father_mid_name==''){
                                $guardian='Father:'.$stu->stu_father_first_name.' '.$stu->stu_father_last_name;
                            }
                            $guardian_email='Father:'.$stu->stu_father_email;
                            $guardian_phone_no='Father:'.$stu->stu_father_ph_no;
                        }else{
                           $guardian='Not Given';
                           $guardian_email='Not Given';
                           $guardian_phone_no='Not Given';
                        }
                            
                    }else if($stu->stu_father_is_guardian=='no' && $stu->stu_mother_is_guardian=='yes'){
                        if($stu->stu_mother_first_name!=''){
                            if($stu->stu_father_mid_name!=''){
                                $guardian='Mother:'.$stu->stu_mother_first_name.' '.$stu->stu_mother_mid_name.' '.$stu->stu_father_last_name;
                            }else if($stu->stu_father_mid_name==''){
                                $guardian='Mother:'.$stu->stu_mother_first_name.' '.$stu->stu_mother_last_name;
                            }
                            $guardian_email='Mother:'.$stu->stu_mother_email;
                            $guardian_phone_no.='Mother:'.$stu->stu_mother_ph_no;
                        }else{
                           $guardian='Not Given';
                           $guardian_email='Not Given';
                           $guardian_phone_no='Not Given';
                        }
                            
                    }else{
                        $guardian='Not Given';
                        $guardian_email='Not Given';
                        $guardian_phone_no='Not Given';
                    }

                    $action='<button type="button" class="btn btn-xs btn-dark btn_update_guardian"><i class="fa fa-pencil"></i></button>';

                    $row[]  =   '<img class="img-thumbnail" src="'.$image.'" height="30px;" width="30px;"><br><strong>'.$stu_name.'<br>'.$stu->stu_user_code.'</strong>';
                    $row[]  =   '<strong>'.$guardian.'</strong>';
                    $row[]  =   '<strong>'.$guardian_email.'</strong>';
                    $row[]  =   '<strong>'.$guardian_phone_no.'</strong>';
                                     
                    $row[]  = $action;  

                    $data[] = $row; 
                }

                $output = array(
                    "draw" => isset($posts['draw'])?$posts['draw']:'',
                    "recordsTotal" => $this->um->_get_students($posts,$param,TRUE),
                    "recordsFiltered" => $this->um->_get_students($posts,$param,TRUE),
                    "data" => $data,
                );
                
                echo json_encode($output);

            }else{
                redirect($this->data['base_url']);
            }
        }else{
            redirect($this->data['base_url']);
        }
    }


    
}

MMCT - 2023