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

class User_model extends CI_Model {
    
    public function __construct() {
        parent::__construct();
        $this->db = $this->load->database('default', TRUE);
        $CI =& get_instance();
        $CI->db =& $this->db;
    }

    public function get_user_details($user_name,$password){
    	return $this->db->select('*')
    					->from('user_settings')
    					->where(array('login_user_name'=>$user_name,'login_password'=>$password))
    					->get()
    					->row();
    }

    public function insert_data($table_name,$user_basic_data){
        $this->db->insert($table_name,$user_basic_data);
        return $this->db->insert_id();
    }

    public function get_user_data($id){
        return $this->db->select('*')
                        ->from('contact_user')
                        ->join('contact_user_billing','contact_user.id = contact_user_billing.id_contact_user','left')
                        ->join('contact_user_shipping','contact_user.id = contact_user_shipping.id_contact_user','left')
                        ->where('contact_user.id',$id)
                        ->get()
                        ->row();
    }

    public function update_data($tablename,$update_data,$where){
        $this->db->where($where);
        $this->db->update($tablename,$update_data);
    }

    public function user_list(){
        return $this->db->select('*')
                        ->from('contact_user')
                        ->get()
                        ->result();
    }

    public function user_list_where($where){
        return $this->db->select('*')
                        ->from('contact_user')
                        ->where($where)
                        ->get()
                        ->result();
    }

}