<?php
class Userm extends CI_Model {
function __construct(){
parent::__construct();
}
function _auth($username, $pass){
$q = $this->db->get_where('users', array('username' => $username), 1);
if($q->num_rows() > 0){
$rs = $q->row();
$array = array('username' => $username, 'password' => $pass, 'is_active' => "Approved");
$q = $this->db->get_where('users', $array, 1);
if($q->num_rows() > 0){
$rs = $q->row();
$data = array(
'user_id' => $rs->user_id,
'username' => $rs->username,
'display_name' => $rs->first_name,
'is_active' => $rs->is_active,
'lastlogin' => $rs->last_login,
'success' => 'TRUE'
);
return $data;
}
else{
$data = array('success' => 'FALSE');
return $data;
}
}
else{
$data = array('success' => 'FALSE');
return $data;
}
}
function _check_password($user_id,$password){
$q = $this->db->get_where('users', array("password" => $password,"user_id" => $user_id), 1);
if($q->num_rows() > 0){
return true;
}
return false;
}
function _is_exists($value,$column="username"){
$q = $this->db->get_where('users', array($column => $value), 1);
if($q->num_rows() > 0){
return true;
}
return false;
}
function _update($uid, $lastlogin){
$array = array('last_login' => time());
$this->db->where('user_id', $uid);
$this->db->limit(1);
$this->db->update('users', $array);
}
function _getall($uid, $un = NULL){
if($un === NULL)
$this->db->where('user_id', $uid);
else
$this->db->where('username', $un);
$this->db->limit(1);
$q = $this->db->get('users');
if($q->num_rows() > 0){
$rs = $q->row();
$data = array(
'user_id' => $rs->user_id,
'company_name' => $rs->company_name,
'last_login' => $rs->last_login,
'username' => $rs->username,
'first_name' => $rs->first_name,
'middle_name' => $rs->middle_name,
'last_name' => $rs->last_name,
'email' => $rs->email,
'address' => $rs->address,
'address1' => $rs->address1,
'phone' => $rs->phone,
'mobile' => $rs->mobile,
'city' => $rs->city,
'state' => $rs->state,
'country' => $rs->country,
'zipcode' => $rs->zipcode,
'shipping_first_name' => $rs->shipping_first_name,
'shipping_middle_name' => $rs->shipping_middle_name,
'shipping_last_name' => $rs->shipping_last_name,
'shipping_address' => $rs->shipping_address,
'shipping_address1' => $rs->shipping_address1,
'shipping_phone' => $rs->shipping_phone,
'shipping_mobile' => $rs->shipping_mobile,
'shipping_city' => $rs->shipping_city,
'shipping_state' => $rs->shipping_state,
'shipping_country' => $rs->shipping_country,
'shipping_zipcode' => $rs->shipping_zipcode,
'is_active' => $rs->is_active
);
return $data;
}
return FALSE;
}
function _insert($data){
$this->db->insert('users', $data);
return $this->db->insert_id();
}
function get_valid_order($customer_id,$order_id){
$strsql = "SELECT order_id from orders where order_id = $order_id and user_id = $customer_id";
return $this->db->query($strsql)->result();
}
function get_customer_orders($customer_id){
$strsql = "SELECT o.*, ps.payment_status_detail AS payment_status_detail,
pg.gateway_detail AS gateway_detail, u.username AS username, os.status_detail AS status_detail
FROM orders o
LEFT JOIN payment_status as ps ON ps.payment_status_code = o.payment_status
LEFT JOIN payment_gateways as pg ON pg.gateway_code = o.payment_method
LEFT JOIN users as u ON u.user_id = o.user_id
LEFT JOIN order_status as os ON os.status_code = o.order_status
where o.user_id = $customer_id";
return $this->db->query($strsql)->result();
}
function _up_profile($uid, $data, $un = NULL){
if($un === NULL)
$this->db->where('user_id', $uid);
else
$this->db->where('username', $un);
return $this->db->update('users', $data);
}
}
@KyuuKazami