<?php
class LoginModel extends CI_Model {

    public function check_permission($username,$password){
        $info=array();
        $this->db->select('*');
        $this->db->from('school_staff');
        $this->db->where('mobile_number',$username);
        // $this->db->where('password',$password);
        $info=$this->db->get()->result_array();
        return $info;  
    }    

    public function chnage_password($username,$opassword,$newpassword){
        $info =array();	
        $this->db->where("mobile_number",$username);
        $this->db->where("password",$opassword);
        $data_array_update=array("password"=>$newpassword);
        $info= $this->db->update('school_staff',$data_array_update);
        return $info;    
    }

    public function all_teachers(){
        $info=array();
        $this->db->select('*');
        $this->db->from('school_staff');
        $info=$this->db->get()->result_array();
        return $info;      
    }
    
    public function update_staff_credentials($userid,$usertype,$data_array_update,$table){
        $info =array();	
        $this->db->where("user_id",$userid);
        $this->db->where("usertype",$usertype);
        $info= $this->db->update($table,$data_array_update);
        return $info;    
    }

public function all_students(){
$info=array();
$this->db->select('*');
$this->db->from('student');
$info=$this->db->get()->result_array();
return $info;          
}

public function add_login_user($data_array){
$table='login_credentials';
$this->db->insert($table,$data_array);
return $this->db->insert_id();      
}
    
    
public function check_user_type($username,$password1){
$info=array();
$this->db->select('*');
$this->db->from('login_credentials');
$this->db->where('mob_number',$username);
$this->db->where('password',$password1);
$info=$this->db->get()->result_array();
return $info;      
}
public function change_login_credentials($username,$opassword,$newpassword){
$table='login_credentials';
$info =array();	
$this->db->where("username",$username);
$this->db->where("password",$opassword);
$data_array_update=array("password"=>$newpassword);
$info= $this->db->update('login_credentials',$data_array_update);
return $info;    
}
    public function get_staff_data($username){
        $info=array();
        $this->db->select('*');
        $this->db->from('school_staff');
        $this->db->where('mobile_number',$username);
        $info=$this->db->get()->result_array();
        return $info;  
    }

    public function add_log($data_array){
        $table='login_history';    
        $this->db->insert($table,$data_array);
        return $this->db->insert_id();        
    }


    public function get_item_data($tid){
        $info=array();
        $this->db->select('*');
        $this->db->from('school_staff');
        $this->db->where('id',$tid);
        $info=$this->db->get()->result_array();
        return $info;  
    }
    public function check_login($username,$password){
        $info=array();
        $this->db->select('*');
        $this->db->from('student');
        $this->db->where('contact_no',$username);
        // $this->db->where('password',$password);
        $info=$this->db->get()->result_array();
        return $info;  
    }
    
    public function get_staff_data_with_mobile_no($username){
        $info=array();
        $this->db->select('*');
        $this->db->from('school_staff');
        $this->db->where('mobile_number',$username);
        $info=$this->db->get()->result_array();
        return $info;  
    }
    
    public function update_item_data($id,$data_array_update,$table){
        $this->db->where("id",$id);
        $this->db->update($table,$data_array_update);
        return $this->db->affected_rows();
    }

}