<?php
class Users_model extends CI_Model{

    function create ($form_array){

        $this->db->insert('sk_users', $form_array);
    }

    function all(){
        
        $this->db->order_by("id", "desc");
        $query = $this->db->get('sk_users');
        return $query->result_array();

        #return $users = $this->db->get('sk_users')->result_array();
    }

    function getUser($id){

        $this->db->where('id', $id);
        return $user = $this->db->get('sk_users')->row_array();

    }

    function updateUser($id, $user){
        $this->db->where('id', $id);
        $this->db->update('sk_users', $user);

    }
    
    function deleteUser($id){
        $this->db->where('id', $id);
        $this->db->delete('sk_users');
    }
    
    function canLogin($username, $password){
        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $query = $this->db->get('login');
        
        if($query->num_rows() > 0){
            return true;
        }else{
            return false;
        }
    }
    
    function getPortal(){
        return $user = $this->db->get('portal')->row_array();
    }
    
    function updatePortal($user){
        $this->db->update('portal', $user);

    }

}
?>