Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /proc/self/root/var/www/laciasmara.com/public_html/shop/application/models/ |
Upload File : |
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Customer_m extends MY_Model { protected $_table_name = 'customers'; protected $_primary_key = 'id_customers'; protected $_order_by = 'id_customers'; public $rules = array( 'email' => array( 'field' => 'login_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email' ), 'password' => array( 'field' => 'login_password', 'label' => 'Password', 'rules' => 'trim|required' ) ); public $rules_sms = array( 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required|callback__cek_phone' ), 'sms_code' => array( 'field' => 'sms_code', 'label' => 'SMS Code', 'rules' => 'trim|required|callback__cek_smscode' ) ); public $lostpassword_rules = array( 'email' => array( 'field' => 'emaillost', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_checkregisteredemail' ) ); public $registration_rules = array( 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone', 'label' => 'phone', 'rules' => 'trim|required|callback__cek_phone' ), 'register_email' => array( 'field' => 'register_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback__cek_email' ), 'register_password' => array( 'field' => 'register_password', 'label' => 'Password', 'rules' => 'trim|required' ), 'toc' => array( 'field' => 'toc', 'label' => 'toc', 'rules' => 'trim|required' ), ); public $guestcheckout_rules = array( 'name' => array( 'field' => 'name_guest', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone_guest', 'label' => 'Phone', 'rules' => 'trim|required' ), 'register_email' => array( 'field' => 'register_email_guest', 'label' => 'Email', 'rules' => 'trim|required|valid_email' ), 'country' => array( 'field' => 'country', 'label' => 'Country', 'rules' => 'trim|required' ), 'province' => array( 'field' => 'province', 'label' => 'Province', 'rules' => 'trim|required' ), 'district' => array( 'field' => 'district', 'label' => 'District', 'rules' => 'trim|required' ), 'subdistrict' => array( 'field' => 'subdistrict', 'label' => 'Subdistrict', 'rules' => 'trim|required' ), 'address' => array( 'field' => 'address', 'label' => 'Address', 'rules' => 'trim|required' ), 'postcode' => array( 'field' => 'postcode', 'label' => 'Postcode', 'rules' => 'trim' ), ); public $guestcheckout_rules_international = array( 'name' => array( 'field' => 'name_guest', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone_guest', 'label' => 'Phone', 'rules' => 'trim|required' ), 'register_email' => array( 'field' => 'register_email_guest', 'label' => 'Email', 'rules' => 'trim|required|valid_email' ), 'country' => array( 'field' => 'country', 'label' => 'Country', 'rules' => 'trim|required' ), 'address' => array( 'field' => 'address', 'label' => 'Address', 'rules' => 'trim|required' ), 'postcode' => array( 'field' => 'postcode', 'label' => 'Postcode', 'rules' => 'trim' ), ); public $registration_rules_international = array( 'title' => array( 'field' => 'title', 'label' => 'Title', 'rules' => 'trim|required' ), 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required' ), 'register_email' => array( 'field' => 'register_email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_cek_email' ), 'birthday' => array( 'field' => 'birthday', 'label' => 'Birthday', 'rules' => 'trim' ), 'register_password' => array( 'field' => 'register_password', 'label' => 'Password', 'rules' => 'trim|required' ), 'country' => array( 'field' => 'country', 'label' => 'Country', 'rules' => 'trim|required' ), 'address' => array( 'field' => 'address', 'label' => 'Address', 'rules' => 'trim|required' ), 'postcode' => array( 'field' => 'postcode', 'label' => 'Postcode', 'rules' => 'trim' ) ); public $admin_rules_add = array( 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required' ), 'email' => array( 'field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_cek_email' ), 'register_password' => array( 'field' => 'register_password', 'label' => 'Password', 'rules' => 'trim|required' ), 'retype_register_password' => array( 'field' => 'retype_register_password', 'label' => 'Retype Password', 'rules' => 'trim|required|matches[register_password]' ), ); public $admin_rules_edit = array( 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required' ), 'email' => array( 'field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_cek_email' ), 'register_password' => array( 'field' => 'register_password', 'label' => 'Password', 'rules' => 'trim' ), 'retype_register_password' => array( 'field' => 'retype_register_password', 'label' => 'Retype Password', 'rules' => 'trim|matches[register_password]' ), ); public $admin_rules_international = array( 'title' => array( 'field' => 'title', 'label' => 'Title', 'rules' => 'trim|required' ), 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required' ), 'email' => array( 'field' => 'email', 'label' => 'Email', 'rules' => 'trim|required|valid_email|callback_cek_email' ), 'birthday' => array( 'field' => 'birthday', 'label' => 'Birthday', 'rules' => 'trim' ), 'register_password' => array( 'field' => 'register_password', 'label' => 'Password', 'rules' => 'trim' ), 'retype_register_password' => array( 'field' => 'retype_register_password', 'label' => 'Retype Password', 'rules' => 'trim' ), 'country' => array( 'field' => 'country', 'label' => 'Country', 'rules' => 'trim|required' ), 'address' => array( 'field' => 'address', 'label' => 'Address', 'rules' => 'trim|required' ), 'postcode' => array( 'field' => 'postcode', 'label' => 'Postcode', 'rules' => 'trim' ) ); public $profile_rules = array( 'name' => array( 'field' => 'name', 'label' => 'Name', 'rules' => 'trim|required' ), 'password' => array( 'field' => 'password', 'label' => 'Password', 'rules' => 'trim' ), ); public $shipping_rules = array( 'shipping_address' => array( 'field' => 'shipping_address', 'label' => 'Shipping ddress', 'rules' => 'trim|required' ), 'shipping_country' => array( 'field' => 'shipping_country', 'label' => 'Country', 'rules' => 'trim|required' ), 'shipping_province' => array( 'field' => 'shipping_province', 'label' => 'Shipping Province', 'rules' => 'trim|required' ), 'shipping_district' => array( 'field' => 'shipping_district', 'label' => 'Shipping District', 'rules' => 'trim|required' ), 'shipping_subdistrict' => array( 'field' => 'shipping_subdistrict', 'label' => 'Shipping Sub District', 'rules' => 'trim|required' ), 'shipping_postcode' => array( 'field' => 'shipping_postcode', 'label' => 'Postcode', 'rules' => 'trim' ) ); public $shipping_rules_international = array( 'recipient_name' => array( 'field' => 'recipient_name', 'label' => 'Recipient Name', 'rules' => 'trim|required' ), 'address' => array( 'field' => 'address', 'label' => 'Address', 'rules' => 'trim|required' ), 'country' => array( 'field' => 'country', 'label' => 'Country', 'rules' => 'trim|required' ), 'postcode' => array( 'field' => 'postcode', 'label' => 'Postcode', 'rules' => 'trim' ), 'phone' => array( 'field' => 'phone', 'label' => 'Phone', 'rules' => 'trim|required' ), 'shipping_name' => array( 'field' => 'shipping_name', 'label' => 'Shipping Name', 'rules' => 'trim' ), 'shipping_address' => array( 'field' => 'shipping_address', 'label' => 'AShipping ddress', 'rules' => 'trim' ), 'shipping_country' => array( 'field' => 'shipping_country', 'label' => 'Country', 'rules' => 'trim' ), 'shipping_postcode' => array( 'field' => 'shipping_postcode', 'label' => 'Postcode', 'rules' => 'trim' ), 'shipping_phone' => array( 'field' => 'shipping_phone', 'label' => 'Phone', 'rules' => 'trim|required' ) ); function __construct() { parent::__construct(); } //function for login public function login($email) { // Check if the provided email exists in either the email or email_alt fields $customer = $this->get_by( "(email = '$email' OR email_alt = '$email') AND password = '" . $this->hash($this->input->post('password')) . "' AND status = 1", TRUE ); if (count($customer)) { // If a customer is found, log them in $customer_data = array( 'customer_name' => $customer->name, 'reseller_id' => $customer->reseller_id, 'customer_email' => $customer->email, 'customer_id' => $customer->id_customers, 'customer_loggedin' => TRUE, 'customer_type' => 'regular', 'customer_district' => $customer->district, 'customer_province' => $customer->province, 'customer_country' => $customer->country, ); $this->session->set_userdata(array('customer' => $customer_data)); return true; } return false; } public function login_by_email($email) { $customer = $this->_getCustomerByEmailAndPassword($email); if (empty($customer)) { return false; } $this->_setCustomerSession($customer); return true; } private function _getCustomerByEmailAndPassword($email) { $hashed_password = $this->hash($this->input->post('login_password')); return $this->get_by( "(email = '$email' OR email_alt = '$email') AND password = '$hashed_password' AND status = 1", TRUE ); } public function get_customer_addresses($customer_id) { $this->db->select('customer_addresses.*, customers.is_first'); $this->db->from('customer_addresses'); $this->db->join('customers', 'customers.id_customers = customer_addresses.customer_id', 'left'); $this->db->where('customer_addresses.customer_id', $customer_id); $this->db->order_by('customer_addresses.is_default', 'DESC'); $this->db->order_by('customer_addresses.created_at', 'ASC'); $query = $this->db->get(); return $query->result(); } public function get_customer_address_by_id($customer_id, $address_id) { $this->db->select('customer_addresses.*, customers.is_first'); $this->db->from('customer_addresses'); $this->db->join('customers', 'customers.id_customers = customer_addresses.customer_id', 'left'); $this->db->where('customer_addresses.customer_id', $customer_id); $this->db->where('customer_addresses.id', $address_id); return $this->db->get()->row(); } public function is_first_address_by_district($customer_id, $district_id) { $this->db->where('customer_id', $customer_id); $this->db->where('rajaongkir_district_id', $district_id); $this->db->where('is_first', 1); $address = $this->db->get('customer_addresses')->row(); return $address ? true : false; } public function set_default($id, $customer_id) { $this->db->where('id', $id); $this->db->where('customer_id', $customer_id); return $this->db->update('customer_addresses', ['is_default' => 1]); } public function unset_default($customer_id) { $this->db->where('customer_id', $customer_id); return $this->db->update('customer_addresses', ['is_default' => 0]); } public function get_address_by_id($id) { return $this->db->get_where('customer_addresses', ['id' => $id])->row(); } public function delete_address($id) { return $this->db->delete('customer_addresses', ['id' => $id]); } public function get_other_address($customer_id, $exclude_id) { $this->db->where('customer_id', $customer_id); $this->db->where('id !=', $exclude_id); $this->db->order_by('created_at', 'ASC'); return $this->db->get('customer_addresses')->row(); } private function _setCustomerSession($customer) { $customer_data = [ 'customer_name' => $customer->name, 'reseller_id' => $customer->reseller_id, 'customer_email' => $customer->email, 'customer_id' => $customer->id_customers, 'customer_loggedin' => TRUE, 'customer_type' => 'regular', 'customer_district' => $customer->district, 'customer_province' => $customer->province, 'customer_country' => $customer->country, ]; $this->session->set_userdata(['customer' => $customer_data]); } public function email_exists($email) { return $this->db->where('email', $email) ->count_all_results('customers') > 0; } public function login_sms() { $customer = $this->get_by(array( 'phone' => $this->security->xss_clean($this->input->post('phone')) ), TRUE); if (count($customer)) { //if customer is exist in database, then log them in.. $customer_data = array( 'customer_name' => $customer->name, 'customer_email' => $customer->email, 'customer_id' => $customer->id_customers, 'customer_loggedin' => TRUE, 'customer_type' => 'regular' ); $this->session->set_userdata(array('customer' => $customer_data)); } } //function for 1st login after registration public function first_login_guest() { $customer = $this->get_by(array( 'email' => $this->security->xss_clean($this->input->post('register_email')), /* 'password' => NULL */ ), TRUE); if (count($customer)) { //if customer is exist in database, then log them in.. $customer_data = array( 'customer_name' => $customer->name, 'customer_email' => $customer->email, 'customer_id' => $customer->id_customers, 'customer_loggedin' => TRUE, 'customer_type' => 'regular' ); $this->session->set_userdata(array('customer' => $customer_data)); } } //function for logout public function logout() { $this->session->unset_userdata('customer'); } //IS USED: function to check if logged in, true if loggedin public function loggedin() { return (bool) $this->session->userdata('customer')['customer_loggedin']; } //function for hashing SHA512 public function hash($string) { return hash('sha512', $string . config_item('encryption_key')); //password is salted with encryption key, and then use sha512 } //count existing email function cek_existing_email($email, $customer_id) { $this->db->select('id_customers'); $this->db->from('customers'); $this->db->where('email', $email); if ($customer_id != NULL) { $this->db->where('id_customers !=', $customer_id); } $query = $this->db->get(); return $query->num_rows(); } //count existing phone function cek_existing_phone($phone, $customer_id) { $this->db->select('id_customers'); $this->db->from('customers'); $this->db->where('phone', $phone); if ($customer_id != NULL) { $this->db->where('id_customers !=', $customer_id); } $query = $this->db->get(); return $query->num_rows(); } //count smscode function cek_smscode($code) { $this->db->select('id_sms_code'); $this->db->from('sms_code'); $this->db->where('phone', $this->security->xss_clean($this->input->post('phone'))); $this->db->where('sms_code', $code); $query = $this->db->get(); return $query->num_rows(); } //get customer by id customer function get_customer($id_customer) { $this->db->select('*'); $this->db->from('customers'); $this->db->where('id_customers', $id_customer); $query = $this->db->get(); return $query->row(); } //update customer profile function update_profile($id, $data) { $this->db->where('id_customers', $id); $this->db->update('customers', $data); } //get shipping function get_shipping($id_customer) { $this->db->select('*'); $this->db->from('customers'); $this->db->where('id_customers', $id_customer); $query = $this->db->get(); return $query->row(); } //update shipping function update_shipping($id, $data) { $this->db->where('id_customers', $id); $this->db->update('customers', $data); } //function to return a new user public function get_new() { $user = new stdClass(); $user->name = ''; $user->sex_type = ''; $user->newsletter = ''; $user->is_delete = ''; $user->title = ''; $user->email = ''; $user->phone = ''; $user->password = ''; $user->address = ''; $user->postcode = ''; $user->status = ''; $user->reseller_id = ''; $user->current_pointreward = ''; $user->dropship = ''; $user->shipping_address = ''; $user->shipping_postcode = ''; $user->type = ''; $user->is_first = ''; return $user; } //function count all record for customers public function record_count() { $this->db->select('*')->from('customers')->where('is_delete', 'no'); $count = $this->db->get()->num_rows(); return $count; } //get all customer with pagination included function get_all_customers($limit, $start) { $this->db->select('*,TIMESTAMPDIFF(YEAR, birthday, CURDATE()) AS age'); $this->db->from('customers'); $this->db->order_by('join_date', 'ASC'); $this->db->limit($limit, $start); $query = $this->db->get(); return $query->result(); } function get_all_ranking() { $this->db->select('orders.customer_id, customers.email, customers.phone , customers.name as name, COUNT(*) as jumlah'); $this->db->from('orders'); $this->db->join('customers', 'customers.id_customers = orders.customer_id'); $this->db->where('payment_status', 5); $this->db->where('reseller_id', NULL); $this->db->where_not_in('orders.customer_id', array(21, 815, 2615, 1427, 2190, 2496, 1964, 2768, 2611, 2283, 2796)); $this->db->group_by('orders.customer_id'); $this->db->order_by('jumlah', 'DESC'); $query = $this->db->get(); return $query->result(); } function get_all_ranking_nominal() { $this->db->select('orders.customer_id, customers.email, customers.phone, customers.name as name, COUNT(*) as jumlah, SUM(orders.grand_total_amount) as grand_total_amount'); $this->db->from('orders'); $this->db->join('customers', 'customers.id_customers = orders.customer_id'); $this->db->where('payment_status', 5); $this->db->where('reseller_id', NULL); $this->db->where_not_in('orders.customer_id', array(21, 815, 2615, 1427, 2190, 2496, 1964, 2768, 2611, 2283, 2796)); $this->db->group_by('orders.customer_id'); $this->db->order_by('grand_total_amount', 'DESC'); $query = $this->db->get(); return $query->result(); } function get_all_ranking_filtered($startDate, $endDate) { $this->db->select('orders.customer_id, customers.email, customers.phone , customers.name as name, COUNT(*) as jumlah'); $this->db->from('orders'); $this->db->join('customers', 'customers.id_customers = orders.customer_id'); $this->db->where('payment_status', 5); $this->db->where('order_date >=', $startDate); $this->db->where('order_date <=', $endDate); $this->db->where('reseller_id', NULL); $this->db->where_not_in('orders.customer_id', array(21, 815, 2615, 1427, 2190, 2496, 1964, 2768, 2611, 2283, 2796)); $this->db->group_by('orders.customer_id'); $this->db->order_by('jumlah', 'DESC'); $query = $this->db->get(); return $query->result(); } function get_all_ranking_nominal_filtered($startDate, $endDate) { $this->db->select('orders.customer_id, customers.email, customers.phone, customers.name as name, COUNT(*) as jumlah, SUM(orders.grand_total_amount) as grand_total_amount'); $this->db->from('orders'); $this->db->join('customers', 'customers.id_customers = orders.customer_id'); $this->db->join('orders_detail', 'orders.id_orders = orders_detail.orders_id'); // Assuming there's a join condition between orders and orders_detail $this->db->where('orders.payment_status', 5); $this->db->where('orders.order_date >=', $startDate); $this->db->where('orders.order_date <=', $endDate); $this->db->where('customers.reseller_id', NULL); $this->db->where_not_in('orders.customer_id', array(21, 815, 2615, 1427, 2190, 2496, 1964, 2768, 2611, 2283, 2796)); $this->db->group_by('orders.customer_id'); $this->db->order_by('grand_total_amount', 'DESC'); $query = $this->db->get(); return $query->result(); } //excel export customer data function excel_export() { $this->db->select('name, email, phone, birthday, address, province, district, subdistrict, type'); $this->db->from('customers'); $this->db->order_by('join_date', 'DESC'); $query = $this->db->get(); return $query->result(); } public function checkUser($user_data) { // Memeriksa apakah user sudah ada $this->db->select('id_customers'); $this->db->from('customers'); $this->db->where('oauth_uid', $user_data['oauth_uid']); $query = $this->db->get(); if ($query->num_rows() > 0) { // User sudah ada, update datanya $this->db->where('oauth_uid', $user_data['oauth_uid']); $this->db->update('customers', $user_data); return $query->row()->id_customers; // Kembalikan ID user yang ada } else { // User belum ada, insert data baru $this->db->insert('customers', $user_data); return $this->db->insert_id(); // Kembalikan ID user yang baru ditambahkan } } public function get_user_by_email($email) { return $this->db->get_where('customers', ['email' => $email])->row(); } public function get_user_by_id($id) { return $this->db->get_where('customers', ['id_customers' => $id])->row(); } public function fetch_all_customers() { $this->db->select('*'); $this->db->from('customers'); $this->db->where('type', 'regular'); $query = $this->db->get(); return $query->result(); } public function fetch_all_retailers() { $this->db->select('*'); $this->db->from('customers'); $this->db->where('type', 'regular'); $this->db->where('reseller_id IS NOT NULL'); $this->db->where('reseller_id !=', ''); $query = $this->db->get(); return $query->result(); } public function fetch_customer_by_id($customer_id) { return $this->db->get_where('customers', ['id_customers' => $customer_id])->row(); } }