|
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 : /var/www/angkasapuraretail.com/public_html/application/models/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class companies_m extends MY_Model {
protected $_table_name = 'companies';
protected $_primary_key = 'id_companies';
protected $_order_by = 'id_companies';
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'),
'registration_number' => array(
'field'=>'registration_number',
'label'=>'Registration Number',
'rules'=>'trim|required'),
'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'),
'registration_number' => array(
'field'=>'registration_number',
'label'=>'Registration Number',
'rules'=>'trim|required'),
'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() {
$companies = $this->get_by(array(
'email' => $this->security->xss_clean($this->input->post('email')),
'password' => $this->hash($this->input->post('password')),
'status' => 1
), TRUE);
if(count($companies)) {
//if companies is exist in database, then log them in..
$companies_data = array(
'companies_name' => $companies->name,
'companies_email' => $companies->email,
'companies_id' => $companies->id_companies,
'companies_loggedin' => TRUE
);
$this->session->set_userdata(array('companies' => $companies_data));
}
}
public function login_sms() {
$companies = $this->get_by(array(
'phone' => $this->security->xss_clean($this->input->post('phone'))
), TRUE);
if(count($companies)) {
//if companies is exist in database, then log them in..
$companies_data = array(
'companies_name' => $companies->name,
'companies_email' => $companies->email,
'companies_id' => $companies->id_companies,
'companies_loggedin' => TRUE
);
$this->session->set_userdata(array('companies' => $companies_data));
}
}
//function for 1st login after registration
public function first_login_guest() {
$companies = $this->get_by(array(
'email' => $this->security->xss_clean($this->input->post('register_email')),
/* 'password' => NULL */
), TRUE);
if(count($companies)) {
//if companies is exist in database, then log them in..
$companies_data = array(
'companies_name' => $companies->name,
'companies_email' => $companies->email,
'companies_id' => $companies->id_companies,
'companies_loggedin' => TRUE
);
$this->session->set_userdata(array('companies' => $companies_data));
}
}
//function for logout
public function logout() {
$this->session->unset_userdata('companies');
}
//IS USED: function to check if logged in, true if loggedin
public function loggedin() {
return (bool) $this->session->userdata('companies')['companies_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, $companies_id) {
$this->db->select('id_companies');
$this->db->from('companies');
$this->db->where('email', $email);
if ($companies_id != NULL) {
$this->db->where('id_companies !=', $companies_id);
}
$query = $this->db->get();
return $query->num_rows();
}
//count existing phone
function cek_existing_phone($phone, $companies_id) {
$this->db->select('id_companies');
$this->db->from('companies');
$this->db->where('phone', $phone);
if ($companies_id != NULL) {
$this->db->where('id_companies !=', $companies_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 companies by id companies
function get_companies($id_companies) {
$this->db->select('*');
$this->db->from('companies');
$this->db->where('id_companies', $id_companies);
$query = $this->db->get();
return $query->row();
}
//update companies profile
function update_profile($id, $data) {
$this->db->where('id_companies', $id);
$this->db->update('companies', $data);
}
//get shipping
function get_shipping($id_companies) {
$this->db->select('*');
$this->db->from('companies');
$this->db->where('id_companies', $id_companies);
$query = $this->db->get();
return $query->row();
}
//update shipping
function update_shipping($id, $data) {
$this->db->where('id_companies', $id);
$this->db->update('companies', $data);
}
//function to return a new user
public function get_new() {
$user = new stdClass();
$user->name = '';
$user->newsletter = '';
$user->registration_number = '';
$user->bank_name = '';
$user->account_number = '';
$user->account_name = '';
$user->is_delete = '';
$user->email = '';
$user->phone = '';
$user->password = '';
$user->address = '';
$user->postcode = '';
$user->status = '';
$user->reseller_id = '';
return $user;
}
//function count all record for companies
public function record_count() {
$this->db->select('*')->from('companies')->where('is_delete', 'no');
$count = $this->db->get()->num_rows();
return $count;
}
//get all companies with pagination included
function get_all_companies($limit, $start) {
$this->db->select('*');
$this->db->from('companies');
$this->db->where('is_delete', 'no');
$this->db->order_by('join_date', 'DESC');
$this->db->limit($limit, $start);
$query = $this->db->get();
return $query->result();
}
//excel export companies data
function excel_export() {
$this->db->select('name, title, email, phone, address, district, province, country, postcode, birthday, socialmedia, join_date');
$this->db->from('companies');
$this->db->order_by('join_date', 'DESC');
$query = $this->db->get();
return $query->result();
}
}