|
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/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Companies extends Admin_Controller {
//this property is used for validating existing companies title on call back edit companies
private $companies_current_id = NULL;
function __construct() {
parent::__construct();
$this->load->model('companies_m');
if (!in_array('companies', $this->data['allowed_module'])) {
$this->data['allowed'] = false;
} else {
$this->data['allowed'] = true;
}
}
//this is to list all companies
public function index() {
/*----FILTER SEARCH PRODUCT--*/
if(isset($_POST['search_companies'])) {
//get product name from form
$this->data['keyword'] = $this->security->xss_clean($this->input->post('companies'));
//get all companies
$this->db->select('*');
$this->db->from('companies');
$this->db->like('name', $this->data['keyword']);
$this->db->order_by('join_date', 'DESC');
$this->data['companies'] = $this->db->get()->result();
} else {
//pagination in action. 100 results per page
$this->load->library('pagination');
$config = array();
$this->load->helper('pagination_helper');
$config = pagination_format();
$config['base_url'] = base_url() . 'admin/companies/index';
$config['total_rows'] = $this->companies_m->record_count();
$config['per_page'] = 200;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
//fetch all companies
$this->data['companies'] = $this->companies_m->get_all_companies($config["per_page"],
$this->uri->segment(4));
$this->data['use_pagination'] = 'yes';
}
//load view
$this->data['subview'] = 'admin/companies/index';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to add a new companies
public function add() {
if($this->data['allowed'] == false) { redirect('admin/dashboard'); }
$this->data['page_type'] = 'add';
$this->load->helper('rajaongkir');
$this->data['companies'] = $this->companies_m->get_new();
//get all province data from RajaOngkir.com API
//$this->data['provinces'] = get_rajaongkir_data('province'); //get from helper file
//get all provinces data from provinces table
$this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC');
$this->data['provinces'] = $this->db->get()->result();
//get all countries data from RajaOngkir.com API
//$this->data['countries'] = get_rajaongkir_data('v2/internationalDestination'); //get from helper file
//get all countries data from countries table
$this->db->select('*')->from('countries')->order_by('id_countries', 'ASC');
$this->data['countries'] = $this->db->get()->result();
//validation in action
//if country id 0 (indonesia) regular validation rule
if($this->input->post('country') == '0') {
$config = $this->companies_m->admin_rules_add;
} else {
//rules for international country
$config = $this->companies_m->admin_rules_international;
}
//$config['register_password']['rules'] .= '|required'; //for new user password is required
//$config['retype_register_password']['rules'] .= '|required|matches[register_password]'; //for new user password is required
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run($this) == TRUE) {
$data = array(
'name' => $this->security->xss_clean($this->input->post('name')),
'phone' => $this->security->xss_clean($this->input->post('phone')),
'email' => $this->security->xss_clean($this->input->post('email')),
'registration_number' => $this->security->xss_clean($this->input->post('registration_number')),
'bank_name' => $this->security->xss_clean($this->input->post('bank_name')),
'account_number' => $this->security->xss_clean($this->input->post('account_number')),
'account_name' => $this->security->xss_clean($this->input->post('account_name')),
'newsletter' => $this->input->post('newsletter'),
'status' => $this->input->post('status'),
'is_delete' => $this->input->post('is_delete'),
'address' => $this->security->xss_clean($this->input->post('address')),
'postcode' => $this->security->xss_clean($this->input->post('postcode')),
);
if($this->input->post('reseller_id')) {
$data['reseller_id'] = $this->input->post('reseller_id');
} else {
$data['reseller_id'] = NULL;
}
if($this->input->post('register_password') != '') {
//hash input password
$data['password'] = $this->companies_m->hash($this->input->post('register_password'));
}
if($this->input->post('country') == '0') {
if($this->input->post('province') != '' || $this->input->post('district') != '' || $this->input->post('subdistrict') != '') {
//this is indonesia
$data['id_province'] = (int) $this->input->post('province');
$data['id_district'] = (int) $this->input->post('district');
$data['id_subdistrict'] = (int) $this->input->post('subdistrict');
$data['id_country'] = 0;
$data['country'] = 'Indonesia';
//get province name
$this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', (int) $this->input->post('province'));
$data['province'] = $this->db->get()->row()->province;
//get district name
$this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', (int) $this->input->post('district'));
$data['district'] = $this->db->get()->row()->district;
//get subdistrict name
$this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', (int) $this->input->post('subdistrict'));
$data['subdistrict'] = $this->db->get()->row()->subdistrict;
}
} else {
//this is not indonesia
//get country name
$this->db->select('country')->from('countries')->where('id_countries', $this->input->post('country'));
$data['country'] = $this->db->get()->row()->country;
$data['id_country'] = (int) $this->input->post('country');
}
//add new point rewards to companies if rule exist
$this->db->select('first_customer')->from('point_rewards')->where('id_point_rewards', 1);
$point_rewards = (int) $this->db->get()->row()->first_customer;
if($point_rewards > 0) {
$data['current_pointreward'] = $point_rewards;
}
//save companies data
$this->db->insert('companies', $data);
$companies_id = $this->db->insert_id();
//email welcome message to companies..
//get companies data
$this->db->select('name, email')->from('companies')->where('id_companies', $companies_id);
$companies_data = $this->db->get()->row();
$data['companies_name'] = $companies_data->name;
$data['companies_email'] = $companies_data->email;
//get website data
$this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1);
$website_data = $this->db->get()->row();
$data['logo'] = $website_data->logo;
$data['website_name'] = $website_data->website_name;
$data['register_password'] = $this->input->post('register_password');
//get bonus pointrewards
if($point_rewards > 0) {
$data['pointrewards'] = $point_rewards;
}
$this->load->library('email');
//get email setting
$config['protocol'] = 'smtp';
$config['smtp_host'] = $website_data->email_smtp_host;
$config['smtp_port'] = $website_data->email_smtp_port;
$config['smtp_user'] = $website_data->email_smtp;
$config['smtp_pass'] = $website_data->email_smtp_password;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
$this->email->initialize($config);
$this->email->from($website_data->from_email, $website_data->website_name);
$this->email->to($data['companies_email']);
$this->email->subject('Welcome');
$email = $this->load->view('email/indonesian/account', $data, TRUE);
$this->email->message($email);
$this->email->send();
//----end send email
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Companies Add Successful</p>');
redirect('admin/companies');
}
$this->data['subview'] = 'admin/companies/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to edit companies in admin
public function edit($id = NULL) {
//check if id exist. If not exist, show 404.
$this->db->select('id_companies')->from('companies')->where('id_companies', $id);
$count_companies = $this->db->get()->num_rows();
if ($count_companies == 0) {
//companies not exist
show_404();
}
$this->data['shipping'] = $this->companies_m->get_shipping($id);
//get all provinces data from provinces table
$this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC');
$this->data['provinces'] = $this->db->get()->result();
//get all countries data from countries table
$this->db->select('*')->from('countries')->order_by('id_countries', 'ASC');
$this->data['countries'] = $this->db->get()->result();
//get current country
$current_country_id = $this->data['shipping']->id_country;
$this->data['current_country_id'] = $current_country_id;
//get current province
$current_province_id = $this->data['shipping']->id_province;
$this->data['current_province_id'] = $current_province_id;
//get district lists
$this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $current_province_id);
$this->data['district_lists'] = $this->db->get()->result();
$current_district_id = $this->data['shipping']->id_district;
$this->data['current_district_id'] = $current_district_id;
//get all initial subdistricts lists
$this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $current_district_id);
$this->data['subdistrict_lists'] = $this->db->get()->result();
$current_subdistrict_id = $this->data['shipping']->id_subdistrict;
$this->data['current_subdistrict_id'] = $current_subdistrict_id;
//get companies detail data
$this->db->select('*')->from('companies')->where('id_companies', $id);
$this->data['companies'] = $this->db->get()->row();
$this->companies_current_id = (int) $id;
//validation check in action
//if country id 0 (indonesia) regular validation rule
if($this->input->post('country') == '0') {
$config = $this->companies_m->admin_rules_edit;
} else {
//rules for international country
$config = $this->companies_m->admin_rules_international;
}
if($this->input->post('register_password')) {
$config['retype_register_password']['rules'] .= '|matches[register_password]'; //for new user password is required
}
$this->form_validation->set_rules($config);
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
if($this->form_validation->run($this) == TRUE) {
$data = array(
'name' => $this->security->xss_clean($this->input->post('name')),
'phone' => $this->security->xss_clean($this->input->post('phone')),
'email' => $this->security->xss_clean($this->input->post('email')),
'registration_number' => $this->security->xss_clean($this->input->post('registration_number')),
'bank_name' => $this->security->xss_clean($this->input->post('bank_name')),
'account_number' => $this->security->xss_clean($this->input->post('account_number')),
'account_name' => $this->security->xss_clean($this->input->post('account_name')),
'newsletter' => $this->input->post('newsletter'),
'status' => $this->input->post('status'),
'is_delete' => $this->input->post('is_delete'),
'address' => $this->security->xss_clean($this->input->post('address')),
'postcode' => $this->security->xss_clean($this->input->post('postcode')),
);
if($this->input->post('reseller_id')) {
$data['reseller_id'] = $this->input->post('reseller_id');
} else {
$data['reseller_id'] = NULL;
}
if($this->input->post('register_password') != '') {
//hash input password
$data['password'] = $this->companies_m->hash($this->input->post('register_password'));
}
if($this->input->post('country') == '0') {
if($this->input->post('province') != '' || $this->input->post('district') != '' || $this->input->post('subdistrict') != '') {
//this is indonesia
$data['id_province'] = (int) $this->input->post('province');
$data['id_district'] = (int) $this->input->post('district');
$data['id_subdistrict'] = (int) $this->input->post('subdistrict');
$data['id_country'] = 0;
$data['country'] = 'Indonesia';
//get province name
$this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', (int) $this->input->post('province'));
$data['province'] = $this->db->get()->row()->province;
//get district name
$this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', (int) $this->input->post('district'));
$data['district'] = $this->db->get()->row()->district;
//get subdistrict name
$this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', (int) $this->input->post('subdistrict'));
$data['subdistrict'] = $this->db->get()->row()->subdistrict;
}
} else {
//this is not indonesia
//get country name
$this->db->select('country')->from('countries')->where('id_countries', $this->input->post('country'));
$data['country'] = $this->db->get()->row()->country;
$data['id_country'] = (int) $this->input->post('country');
}
$this->db->where('id_companies', $id);
$this->db->update('companies', $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Companies Edit Successful</p>');
redirect('admin/companies/edit/' . $id);
}
//get companies wishlists
$this->db->select('product_id')->from('wishlist')->where('company_id', $id);
$this->data['wishlists'] = $this->db->get()->result();
$this->data['subview'] = 'admin/companies/edit';
$this->load->view('admin/templates/header', $this->data_header);
$this->load->view('admin/_layout_main', $this->data);
$this->load->view('admin/templates/footer');
}
//to soft delete a compant
public function is_delete($id) {
//check if id exist. If not exist, show 404.
$this->db->select('id_companies')->from('companies')->where('id_companies', $id);
$count = $this->db->get()->num_rows();
if ($count == 0) { show_404(); }
//delete soft company
$data = array(
'is_delete' => 'yes'
);
$this->db->where('id_companies', $id);
$this->db->update('companies', $data);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Company Deleted</p>');
redirect('admin/companies');
}
//to paermanently delete a companies
public function delete($id) {
if($this->data['allowed'] == false || $this->data['role'] == 'admin') { redirect('admin/dashboard'); }
//check if id exist. If not exist, show 404.
$this->db->select('id_companies')->from('companies')->where('id_companies', $id);
$count = $this->db->get()->num_rows();
if ($count == 0) { show_404(); }
//delete companies
$this->companies_m->delete($id);
$this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Companies Delete Successful</p>');
redirect('admin/companies');
}
//callback function validation register new email
public function cek_email($str) {
$num_rows = $this->companies_m->cek_existing_email($str, $this->companies_current_id);
if ($num_rows != 0 ) {
$this->form_validation->set_message('cek_email', 'Email already exist !');
return FALSE;
} else {
return TRUE;
}
}
}