<?php

class CommonModel extends CI_Model {

	function __construct()
    {
        parent::__construct();		
    }


    public function getWhere($a, $b, $c) {
        $data = array();
        $query = $this->db->get_where($a, array($b => $c));  //echo $data1 = $this->db->last_query();
        foreach ($query->result_array() as $row) {
            $data[] = $row;
        }
        return $data;
    }

    /** load 
    * 
    * @param1       
    * @return       getAllData
    * @access       public
    * @author       Q.P
    * @copyright    N/A
    * @link         CommonModel
    * @since       21.12.2017
    * @deprecated   N/A
    */

    public function getAllData($a) {
        $data = array();
        $query = $this->db->get($a);
        foreach ($query->result_array() as $row) {
            $data[] = $row;
        }return $data;
    } 


    /**
    * load Home page
    * 
    * @param1       
    * @return       FormInsert
    * @access       public
    * @author       Q.P
    * @copyright    N/A
    * @link         CommonModel
    * @since        21.12.2017
    * @deprecated   N/A
    **/

    function insert($table,$data) {

        $this->db->insert($table,$data);
    }

    function edit_data($table,$field,$val,$update_val) {

       $this->db->where($field,$val)->update($table,$update_val);
    }
   
    function record_count($where,$table,$field)
    {
        $data=[];

         $sql = "SELECT COUNT(*) AS TotalrecordCount FROM  $table   WHERE 1   $where";

        $recordSet = $this->db->query($sql);
            if ($recordSet)
            {
                $row = $recordSet->row();
                $total_rows = $row->TotalrecordCount;
            } 

        return $total_rows;
    }

    public function all_data_list($limit,$start,$where,$table,$field)
    {
        $data=[];

           $sql="SELECT * FROM $table  WHERE 1 $where  ORDER BY $field DESC LIMIT ".$start.",".$limit ;

                $recordSet = $this->db->query($sql);
                $data['result'] = $recordSet->result_array();
                return $data;

    }

    public function fetch_a_row($field_name,$field_value,$table_name)
    {
        $this->db->where($field_name, $field_value);
        $query = $this->db->get($table_name);
        
        $result=$query->result();
        return $result[0];
    }

    public function del($field_name,$field_value,$table_name)
    {
        $this->db->where($field_name, $field_value);
        $this->db->delete($table_name);
        
    }

    public function appling_student_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='0' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_appling_student_list($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='0' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function submited_student_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='1' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_submited_student_list($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='1' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function send_student_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['hod_status']) && $param['hod_status'] != '') {
            $where .= " AND  hod_status ='".$param['hod_status'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='2' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_send_student_list($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['hod_status']) && $param['hod_status'] != '') {
            $where .= " AND  hod_status ='".$param['hod_status'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='2' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function SendBackStudent_student_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='3' ";

        $where .= " AND  hod_status ='2' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_SendBackStudent_student_list($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        $admin_details=$this->db->where('admin_id',$this->session->userdata('admin_id'))->get('tbl_hod')->result_array();


        $where .= " AND  applied_department_id ='".$admin_details[0]['department_id'].
            "' ";
        $where .= " AND  application_status ='3' ";

        $where .= " AND  hod_status ='2' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function Approved_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='2' ";

        $where .= " AND  hod_status ='1' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_Approved_List($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='2' ";

        $where .= " AND  hod_status ='1' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function Rejected_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='2' ";

        $where .= " AND  hod_status ='2' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_Rejected_List($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='2' ";

        $where .= " AND  hod_status ='2' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

    public function Final_count($param)
    {

        $data = [];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }
        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }

        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='4' ";

        $where .= " AND  deleted_status ='1' ";


        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC ";
        $data = $this->db->query($sql)->result_array();

        $total_rows=sizeof($data);

        /*$recordSet = $this->db->query($sql);
        if ($recordSet) {
            $row = $recordSet->row();
            $total_rows = $row->TotalrecordCount;
        }*/

        return $total_rows;

    }

    public function all_Final_List($limit,$start,$param)
    {

        $data=[];
        $where = '';
        if (isset($param['fullname']) && $param['fullname'] != '') {
            $where .= " AND  fullname like '%".$param['fullname'].
            "%' ";
        }
        if (isset($param['roll_no']) && $param['roll_no'] != '') {
            $where .= " AND  roll_no ='".$param['roll_no'].
            "' ";
        }
        if (isset($param['registration_no']) && $param['registration_no'] != '') {
            $where .= " AND  registration_no ='".$param['registration_no'].
            "' ";
        }

        if (isset($param['course_id']) && $param['course_id'] != '') {
            $where .= " AND  course_id ='".$param['course_id'].
            "' ";
        }

        if (isset($param['semester']) && $param['semester'] != '') {
            $where .= " AND  semester ='".$param['semester'].
            "' ";
        }
        
        if (isset($param['department_id']) && $param['department_id'] != '') {
            $where .= " AND  department_id ='".$param['department_id'].
            "' ";
        }

        $where .= " AND  application_status ='4' ";

        $where .= " AND  deleted_status ='1' ";
        

        $sql="SELECT * FROM tbl_student_lists INNER JOIN tbl_student_application ON tbl_student_lists.student_id=tbl_student_application.student_id WHERE 1  $where  ORDER BY appling_date DESC  LIMIT ".$start.",".$limit ;
        $data = $this->db->query($sql)->result_array();
        // echo "<pre>";print_r($data);exit();
        return $data;
    }

}
?>