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/rabbithabit.com/public_html/application/controllers/admin/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Customers extends Admin_Controller { //this property is used for validating existing customer title on call back edit customer private $customer_current_id = NULL; function __construct() { parent::__construct(); $this->load->model('customer_m'); } //this is to list all customers public function index() { /*----FILTER SEARCH PRODUCT--*/ $this->data['search_by'] = 'by_name'; if(isset($_POST['search_customer'])) { //get product name from form $this->data['keyword'] = $this->security->xss_clean($this->input->post('customer')); $this->data['search_by'] = $this->security->xss_clean($this->input->post('search_by')); $flash_search_by = ''; //get all customers $this->db->select('*'); $this->db->from('customers'); if ($this->data['search_by'] == 'by_name') { $this->db->like('name', $this->data['keyword']); $flash_search_by = 'Pencarian dengan Nama : '.$this->data['keyword']; }else{ $this->db->like('email', $this->data['keyword']); $flash_search_by = 'Pencarian dengan Email : '.$this->data['keyword']; } $this->db->order_by('join_date', 'DESC'); $this->data['customers'] = $this->db->get()->result(); $this->session->set_flashdata('flash_search_by', '<br><p style="background:green; color:white; padding:3px; font-weight:bold;">'.$flash_search_by.'</p>'); } else { $this->load->helper('pagination_helper'); add_pagination(base_url() . 'admin/customers/index', $this->customer_m->record_count(), 100, 4); //fetch all customers $this->data['customers'] = $this->customer_m->get_all_customers(100, $this->uri->segment(4)); $this->data['use_pagination'] = 'yes'; } //load view $this->data['subview'] = 'admin/customers/index'; $this->load->view('admin/templates/header', $this->data_header); $this->load->view('admin/_layout_main', $this->data); $this->load->view('admin/templates/footer'); } function migrasi_data_customers(){ $customers = $this->db->select('*')->from('ps_customer')->get()->result(); foreach ($customers as $customer) { //get city $city = $this->db->select('*')->from('ps_address')->where('id_customer',$customer->id_customer)->get()->row(); $gender = $this->db->select('type')->from('ps_gender')->where('id_gender',$customer->id_gender)->get()->row(); if (count($city)>0) { $district_data = $this->db->select('rajaongkir_id_district,district')->from('indonesia_districts')->where('district',$city->city)->get()->row(); if (count($district_data) > 0) { $id_district_id = $district_data->rajaongkir_id_district; $name_district = $district_data->district; }else{ $id_district_id = NULL; $name_district = NULL; } }else{ $id_district_id = NULL; $name_district = NULL; } //get id_district $data = array( 'name' => $customer->firstname.''.$customer->lastname, 'shipping_name' => $customer->firstname.''.$customer->lastname, 'recipient_name' => $customer->firstname.''.$customer->lastname, 'email' => $customer->email, 'birthday' => $customer->birthday, 'join_date' => $customer->date_add, 'district' => $name_district, 'id_district' => $id_district_id, 'shipping_id_district' => $id_district_id, 'shipping_district' => $name_district, 'status' => 1, 'type' => 'regular', 'id_country' => 0, 'shipping_id_country' => 0, 'country' => 'Indonesia', 'shipping_country' => 'Indonesia', ); if ($gender->type == 0) { $data['sex_type'] = 'male'; }else{ $data['sex_type'] = 'female'; } if (count($city)>0) { $data['postcode'] = $city->postcode; $data['shipping_postcode'] = $city->postcode; $data['phone'] = $city->phone_mobile; $data['shipping_phone'] = $city->phone_mobile; } $this->db->insert('customers', $data); } } function migrasi_data_customers_english(){ $customers = $this->db->select('*')->from('ps_customer')->get()->result(); foreach ($customers as $customer) { //get city $city = $this->db->select('*')->from('ps_address')->where('id_customer',$customer->id_customer)->get()->row(); $gender = $this->db->select('type')->from('ps_gender')->where('id_gender',$customer->id_gender)->get()->row(); if (count($city)>0) { $district_data = $this->db->select('rajaongkir_id_district,district')->from('indonesia_districts')->where('district',$city->city)->get()->row(); if (count($district_data) > 0) { $id_district_id = $district_data->rajaongkir_id_district; $name_district = $district_data->district; }else{ $id_district_id = NULL; $name_district = NULL; } }else{ $id_district_id = NULL; $name_district = NULL; } $cek = $this->db->select('email')->from('customers')->where('email',$customer->email)->get()->num_rows(); if ($cek == 0){ $data = array( 'name' => $customer->firstname.''.$customer->lastname, 'shipping_name' => $customer->firstname.''.$customer->lastname, 'recipient_name' => $customer->firstname.''.$customer->lastname, 'email' => $customer->email, 'birthday' => $customer->birthday, 'join_date' => $customer->date_add, 'district' => $name_district, 'id_district' => $id_district_id, 'shipping_id_district' => $id_district_id, 'shipping_district' => $name_district, 'status' => 1, 'type' => 'regular', 'id_country' => 0, 'shipping_id_country' => 0, 'country' => 'Indonesia', 'shipping_country' => 'Indonesia', ); if ($gender->type == 0) { $data['sex_type'] = 'male'; }else{ $data['sex_type'] = 'female'; } if (count($city)>0) { $data['postcode'] = $city->postcode; $data['shipping_postcode'] = $city->postcode; $data['phone'] = $city->phone_mobile; $data['shipping_phone'] = $city->phone_mobile; } $this->db->insert('customers', $data); } } } //to add a new customer public function add() { $this->data['page_type'] = 'add'; $this->load->helper('rajaongkir'); $this->data['customers'] = $this->customer_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->customer_m->admin_rules_add; } else { //rules for international country $config = $this->customer_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')), 'birthday' =>$this->security->xss_clean($this->input->post('birthday')), 'sex_type' =>$this->input->post('sex_type'), 'shipping_name' => $this->security->xss_clean($this->input->post('name')), 'recipient_name' => $this->security->xss_clean($this->input->post('name')), 'sex_type' => $this->input->post('sex_type'), 'phone' => $this->security->xss_clean($this->input->post('phone')), 'birthday' => $this->security->xss_clean($this->input->post('birthday')), 'email' => $this->security->xss_clean($this->input->post('email')), 'status' => $this->input->post('status'), 'type' => $this->input->post('customer_type'), 'address' => $this->security->xss_clean($this->input->post('address')), 'shipping_address' => $this->security->xss_clean($this->input->post('address')), 'postcode' => $this->security->xss_clean($this->input->post('postcode')), 'shipping_postcode' => $this->security->xss_clean($this->input->post('postcode')), 'shipping_phone' => $this->security->xss_clean($this->input->post('phone')), ); 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->customer_m->hash($this->input->post('register_password')); } if($this->input->post('country') == '0') { if(!empty($this->input->post('province')) && !empty($this->input->post('district')) && !empty($this->input->post('subdistrict'))) { //this is indonesia $data['id_province'] = (int) $this->input->post('province'); $data['shipping_id_province'] = (int) $this->input->post('province'); $data['id_district'] = (int) $this->input->post('district'); $data['shipping_id_district'] = (int) $this->input->post('district'); $data['id_subdistrict'] = (int) $this->input->post('subdistrict'); $data['shipping_id_subdistrict'] = (int) $this->input->post('subdistrict'); $data['id_country'] = 0; $data['shipping_id_country'] = 0; $data['country'] = 'Indonesia'; $data['shipping_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; $data['shipping_province'] = $data['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; $data['shipping_district'] = $data['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; $data['shipping_subdistrict'] = $data['subdistrict']; } //if one of region is empty, then fill default value of Jakarta Barat if(empty($this->input->post('province')) || empty($this->input->post('district')) || empty($this->input->post('subdistrict'))) { //this is indonesia $data['id_province'] = 6; $data['shipping_id_province'] = 6; $data['id_district'] = 151; $data['shipping_id_district'] = 151; $data['id_subdistrict'] = 2088; $data['shipping_id_subdistrict'] = 2088; $data['id_country'] = 0; $data['shipping_id_country'] = 0; $data['country'] = 'Indonesia'; $data['shipping_country'] = 'Indonesia'; //get province name $this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', 6); $data['province'] = $this->db->get()->row()->province; $data['shipping_province'] = $data['province']; //get district name $this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', 151); $data['district'] = $this->db->get()->row()->district; $data['shipping_district'] = $data['district']; //get subdistrict name $this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', 2088); $data['subdistrict'] = $this->db->get()->row()->subdistrict; $data['shipping_subdistrict'] = $data['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['shipping_country'] = $data['country']; $data['id_country'] = (int) $this->input->post('country'); $data['shipping_id_country'] = (int) $this->input->post('country'); } //add new point rewards to customer 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 customer data $this->db->insert('customers', $data); $customer_id = $this->db->insert_id(); if($this->input->post('customer_type') == 'regular') { //email welcome message to customer.. //get customer data $this->db->select('name, email')->from('customers')->where('id_customers', $customer_id); $customer_data = $this->db->get()->row(); $data['customer_name'] = $customer_data->name; $data['customer_email'] = $customer_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['customer_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;">Customer Add Successful</p>'); if ($this->session->userdata('location_add_customer') == 'orders') { $this->session->unset_userdata('location_add_customer'); redirect("admin/orders/add_order"); } else{ redirect('admin/customers'); } } $this->data['subview'] = 'admin/customers/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 customer in admin public function edit($id = NULL) { //check if id exist. If not exist, show 404. $this->db->select('id_customers')->from('customers')->where('id_customers', $id); $count_customer = $this->db->get()->num_rows(); if ($count_customer == 0) { //customer not exist show_404(); } $this->data['shipping'] = $this->customer_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']->shipping_id_country; $this->data['current_country_id'] = $current_country_id; //get current province $current_province_id = $this->data['shipping']->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']->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']->shipping_id_subdistrict; $this->data['current_subdistrict_id'] = $current_subdistrict_id; //get customer detail data $this->db->select('*')->from('customers')->where('id_customers', $id); $this->data['customers'] = $this->db->get()->row(); $this->customer_current_id = (int) $id; //validation check in action //if country id 0 (indonesia) regular validation rule if($this->input->post('country') == '0') { $config = $this->customer_m->admin_rules_edit; } else { //rules for international country $config = $this->customer_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')), 'shipping_name' => $this->security->xss_clean($this->input->post('name')), 'recipient_name' => $this->security->xss_clean($this->input->post('name')), 'sex_type' => $this->input->post('sex_type'), 'phone' => $this->security->xss_clean($this->input->post('phone')), 'birthday' => $this->security->xss_clean($this->input->post('birthday')), 'email' => $this->security->xss_clean($this->input->post('email')), 'newsletter' => $this->input->post('newsletter'), 'status' => $this->input->post('status'), 'is_delete' => $this->input->post('is_delete'), 'type' => $this->input->post('customer_type'), 'address' => $this->security->xss_clean($this->input->post('address')), 'shipping_address' => $this->security->xss_clean($this->input->post('address')), 'postcode' => $this->security->xss_clean($this->input->post('postcode')), 'shipping_postcode' => $this->security->xss_clean($this->input->post('postcode')), 'shipping_phone' => $this->security->xss_clean($this->input->post('phone')), ); 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->customer_m->hash($this->input->post('register_password')); } if($this->input->post('country') == '0') { if(!empty($this->input->post('province')) && !empty($this->input->post('district')) && !empty($this->input->post('subdistrict'))) { //this is indonesia $data['id_province'] = (int) $this->input->post('province'); $data['shipping_id_province'] = (int) $this->input->post('province'); $data['id_district'] = (int) $this->input->post('district'); $data['shipping_id_district'] = (int) $this->input->post('district'); $data['id_subdistrict'] = (int) $this->input->post('subdistrict'); $data['shipping_id_subdistrict'] = (int) $this->input->post('subdistrict'); $data['id_country'] = 0; $data['shipping_id_country'] = 0; $data['country'] = 'Indonesia'; $data['shipping_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; $data['shipping_province'] = $data['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; $data['shipping_district'] = $data['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; $data['shipping_subdistrict'] = $data['subdistrict']; } //if one of region is empty, then fill default value of Jakarta Barat if(empty($this->input->post('province')) || empty($this->input->post('district')) || empty($this->input->post('subdistrict'))) { //this is indonesia $data['id_province'] = 6; $data['shipping_id_province'] = 6; $data['id_district'] = 151; $data['shipping_id_district'] = 151; $data['id_subdistrict'] = 2088; $data['shipping_id_subdistrict'] = 2088; $data['id_country'] = 0; $data['shipping_id_country'] = 0; $data['country'] = 'Indonesia'; $data['shipping_country'] = 'Indonesia'; //get province name $this->db->select('province')->from('indonesia_provinces')->where('rajaongkir_province_id', 6); $data['province'] = $this->db->get()->row()->province; $data['shipping_province'] = $data['province']; //get district name $this->db->select('district')->from('indonesia_districts')->where('rajaongkir_id_district', 151); $data['district'] = $this->db->get()->row()->district; $data['shipping_district'] = $data['district']; //get subdistrict name $this->db->select('subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', 2088); $data['subdistrict'] = $this->db->get()->row()->subdistrict; $data['shipping_subdistrict'] = $data['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['shipping_country'] = $data['country']; $data['id_country'] = (int) $this->input->post('country'); $data['shipping_id_country'] = (int) $this->input->post('country'); } $this->db->where('id_customers', $id); $this->db->update('customers', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Customer Edit Successful</p>'); redirect('admin/customers/edit/' . $id); } //get customer wishlists $this->db->select('product_id')->from('wishlist')->where('customer_id', $id); $this->data['wishlists'] = $this->db->get()->result(); $this->data['subview'] = 'admin/customers/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 customer public function is_delete($id) { //check if id exist. If not exist, show 404. $this->db->select('id_customers')->from('customers')->where('id_customers', $id); $count = $this->db->get()->num_rows(); if ($count == 0) { show_404(); } //delete soft customer $data = array( 'is_delete' => 'yes' ); $this->db->where('id_customers', $id); $this->db->update('customers', $data); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Customer Deleted</p>'); redirect('admin/customers'); } //to permanent delete a customer public function delete($id) { //check if id exist. If not exist, show 404. $this->db->select('id_customers')->from('customers')->where('id_customers', $id); $count = $this->db->get()->num_rows(); if ($count == 0) { show_404(); } //delete customer $this->customer_m->delete($id); $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Customer Delete Successful</p>'); redirect('admin/customers'); } //callback function validation register new email public function cek_email($str) { $num_rows = $this->customer_m->cek_existing_email($str, $this->customer_current_id); if ($num_rows != 0 ) { $this->form_validation->set_message('cek_email', 'Email already exist !'); return FALSE; } else { return TRUE; } } public function upload_customers() { //upload products data if(!isset($_POST['upload_csv'])) { show_404(); } //check if the uploaded file is csv format $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv'); if(in_array($_FILES['userfile']['type'],$mimes)){ ini_set('auto_detect_line_endings', TRUE); //to detect line ending //continue import operation //open the csv file and put into variable $file = fopen($_FILES['userfile']['tmp_name'],'r') or die('cannot open file'); //initialize array $csv_data = array(); //if not reach end of file... while (!feof($file)) { //put the csv into array.. $csv_data[] = fgetcsv($file, 10000, ','); //file, length, separator.. } fclose($file); //close the file /* echo '<pre>'; print_r($csv_data); echo '</pre>'; exit(); */ $row_number = 0; foreach ($csv_data as $item) { $row_number = $row_number + 1; //skip the 1st row... if($row_number != 1) { if(empty($item)) {continue;} //if array is empty, then continue to next iteration and bypass below script.. //check if product code already exist, if already exist, update the row, else, insert new $this->db->select('id_customers')->from('customers')->where('email', $item[8]); $count_customer = $this->db->get()->num_rows(); if($count_customer > 0) { /*----update current customer------*/ } else { //insert new //add to customers table $data = array( 'name' => $item[2], 'email' => $item[8], 'password' => 'farmakunewmigration08', 'recipient_name' => $item[2], 'address' => $item[9], 'id_country' => 0, 'country' => 'Indonesia', 'shipping_country' => 'Indonesia', 'postcode' => $item[11], 'phone' => $item[7], 'shipping_name' => $item[2], 'shipping_address' => $item[9], 'shipping_id_country' => 0, 'shipping_postcode' => $item[11], 'shipping_phone' => $item[7], 'status' => 1, 'province' => $item[12], 'shipping_province' => $item[12] ); //BIRTHDAY if(!empty($item[4])) { $birthday = trim(str_replace('0:00','',$item[4])); //format 11/23/1994 0:00 $birthday = str_replace('/','-', $birthday); //neer to change format to 22-3-2018 $birthday_array = explode('-', $birthday); $data['birthday'] = $birthday_array[1] . '-' . $birthday_array[0] . '-' . $birthday_array[2]; } //ID PROVINCE //get id_province from province name $this->db->select('rajaongkir_province_id')->from('indonesia_provinces')->where('province', $item[12]); $id_province = $this->db->get()->row(); if(count($id_province) > 0) { //province exist $data['id_province'] = $id_province->rajaongkir_province_id; $data['shipping_id_province'] = $id_province->rajaongkir_province_id; } //ID DISTRICT & SUBDISTRICT if(!empty($item[10])) { $district_subdistrict = $item[10]; if(strpos($district_subdistrict, 'Kota') !== false) { $district_subdistrict = str_replace('Kota','', $district_subdistrict); } elseif(strpos($district_subdistrict, 'Kabupaten') !== false) { $district_subdistrict = str_replace('Kabupaten','', $district_subdistrict); } $district_subdistrict_array = explode('-', $district_subdistrict); if(isset($district_subdistrict_array[0])) { $data['district'] = trim($district_subdistrict_array[0]); $data['shipping_district'] = trim($district_subdistrict_array[0]); } if(isset($district_subdistrict_array[1])) { $data['subdistrict'] = trim($district_subdistrict_array[1]); $data['shipping_subdistrict'] = trim($district_subdistrict_array[1]); } if(isset($data['district'])) { //ID DISTRICT & shipping id district $this->db->select('rajaongkir_id_district')->from('indonesia_districts')->where('district', $data['district']); $district_id = $this->db->get()->row(); if(count($district_id) >0) { $data['id_district'] = $district_id->rajaongkir_id_district; $data['shipping_id_district'] = $district_id->rajaongkir_id_district; } } //ID SUB DISTRICT & shipping id sub distirct if(isset($data['subdistrict'])) { $this->db->select('rajaongkir_id_subdistrict')->from('indonesia_subdistricts')->where('subdistrict', $data['subdistrict']); $subdistrict_id = $this->db->get()->row(); if(count($subdistrict_id) >0) { $data['id_subdistrict'] = $subdistrict_id->rajaongkir_id_subdistrict; $data['shipping_id_subdistrict'] = $subdistrict_id->rajaongkir_id_subdistrict; } } } //JOIN DATE $join_date_array = explode(' ', trim($item[0])); //format 4/26/2018 13:37 $join_date = $join_date_array[0]; $join_time = $join_date_array[1]; $join_date = str_replace('/', '-', $join_date); $join_date_array = explode('-', $join_date); $data['join_date'] = $join_date_array[2] . '-' . $join_date_array[0] . '-' . $join_date_array[1] . ' ' . $join_time; $this->db->insert('customers', $data); } } /*---end if($row_number != 1) --*/ } /*---end foreach ($csv_data as $item) ---*/ $this->session->set_flashdata('success', '<br><p style="background:green; color:white; padding:5px; font-weight:bold;">Products CSV Imported.</p>'); redirect('admin/customers'); } else { //not a csv file. Not allowed. die('Sorry, file type not allowed. Please upload only CSV file.'); } } }