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/kanvakanva.com/public_html/application/controllers/ |
Upload File : |
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Ajax extends Public_Controller { public function __construct() { parent::__construct(); } public function remove_cart() { $rowid = $this->input->post('rowid'); if ($rowid=="all"){ $this->cart->destroy(); } else { $data = array( 'rowid' => $rowid, 'qty' => 0 ); $this->cart->update($data); } $product_grand_total = 0; foreach ($this->cart->contents() as $item): $this->db->select('image1'); $this->db->from('products'); $this->db->where('id_products', $item['id']); $image_thumb = $this->db->get()->row('image1'); $product_grand_total = $product_grand_total + $item['subtotal']; endforeach; $result = array( 'total_cart' => $this->cart->total_items(), 'total_product' => number_format($product_grand_total,0,",",".") ); echo json_encode($result); } //ajax product page select size public function ajax_select_size() { //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $quantity = (int) $this->input->post('quantity'); $id_product = (int) $this->input->post('id_product'); //get product base price $this->db->select('price')->from('products')->where('id_products', $id_product); $base_price = $this->db->get()->row()->price; //check if the id_product has quantity discount $this->db->select('id_quantity_discount')->from('quantity_discount')->where('product_id', $id_product); $count_quantity_discount = $this->db->get()->num_rows(); if ($count_quantity_discount > 0) { //get discount for chosen quantity, choosing the closest quantity $query = $this->db->query("SELECT discount_percentage FROM quantity_discount WHERE min_quantity <= '$quantity' ORDER BY ABS(min_quantity - '$quantity') LIMIT 1"); $row = $query->row(); if (count($row) > 0) { $data['quantity_discounted_price'] = $base_price - ($base_price * $row->discount_percentage / 100); $data['quantity_discount_percentage'] = $row->discount_percentage; } else { //quantity is less than minimum discount rule //check if have base normal discount $this->db->select('discount_price')->from('products')->where('id_products', $id_product); $discount_price = $this->db->get()->row()->discount_price; if ($discount_price != 0) { $data['discounted_price'] = $base_price - ($base_price * $discount_price / 100); $data['discount_percentage'] = $discount_price; } } } else { //no quantity discount //check if have base normal discount $this->db->select('discount_price')->from('products')->where('id_products', $id_product); $discount_price = $this->db->get()->row()->discount_price; if ($discount_price != 0) { $data['discounted_price'] = $base_price - ($base_price * $discount_price / 100); $data['discount_percentage'] = $discount_price; } } $data['price'] = $base_price; $data['id_product'] = $id_product; $this->load->view('ajax_select_size', $data); } //ajax product page add product review public function ajax_addproductreview() { //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } //CPATCHA VALIDATION // First, delete old captchas $expiration = time() - 7200; // Two hour limit $this->db->where('captcha_time < ', $expiration) ->delete('captcha'); // Then see if a captcha exists and match $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?'; $binds = array($_POST['captcha'], $this->input->ip_address(), $expiration); $query = $this->db->query($sql, $binds); $row = $query->row(); if ($row->count == 0) { echo '<p style="background-color:red; color:white; padding:5px;">Mohon masukan kode yang benar.</p>'; exit(); } $product_id = (int) $this->input->post('product_id'); $rating = $this->input->post('rating'); $review = $this->security->xss_clean($this->input->post('review')); if($this->input->post('customer_id')) { //if customer act as a registered during product review $customer_id = (int) $this->input->post('customer_id'); //get customer name and email $this->db->select('name, email')->from('customers')->where('id_customers', $customer_id); $customer_data = $this->db->get()->row(); $data = array( 'product_id' => $product_id, 'review_date' => date('j M Y'), 'is_registered' => 'yes', 'customer_id' => $customer_id, 'name' => $customer_data->name, 'email' => $customer_data->email, 'rating' => $rating, 'review' => $review ); } else { //customer act as a guest during product review //get value from serialize form data ajax $name = $this->security->xss_clean($this->input->post('name')); $email = $this->security->xss_clean($this->input->post('email')); $data = array( 'product_id' => $product_id, 'review_date' => date('j M Y'), 'is_registered' => 'no', 'name' => $name, 'email' => $email, 'rating' => $rating, 'review' => $review ); } $this->db->insert('product_review', $data); //get all product reviews $this->db->select('*')->from('product_review')->where('product_id', $product_id)->order_by('review_date', 'DESC'); $data['product_reviews'] = $this->db->get()->result(); $data['product_id'] = $product_id; $this->load->view('ajax_addproductreview', $data); } //ajax get price public function ajax_get_price() { //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $id_product_details = (int) $this->input->post('id_product_details'); $product_id = (int) $this->input->post('product_id'); //get pricing details $this->db->select('price, discounted_price')->from('stocks')->where('size_id', $id_product_details)->where('product_id', $product_id); $prices = $this->db->get()->row(); $data['price'] = $prices->price; $data['discounted_price'] = $prices->discounted_price; $this->load->view('ajax_get_price', $data); } //ajax product page add to cart public function ajax_add_to_cart() { //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $this->load->library('form_validation'); $this->load->library('cart'); //validation check in action $config = array( array( 'field' => 'product_size', 'label' => 'product Size', 'rules' => 'trim|required|callback_cek_stock' ) ); $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $id_product_details = (int) $this->input->post('product_size'); //get product details $this->db->select('*')->from('product_details')->where('id_product_details', $id_product_details); $product_details = $this->db->get()->row(); $data['id'] = (int) $this->input->post('product_id'); $data['name'] = '<strong>' . $this->input->post('product_name') . '</strong>' . '<br>Option: ' . $product_details->attributes . '<br>Product Code: ' . $product_details->sku; $data['qty'] = (int) $this->input->post('qty'); $data['price'] = (int) $this->input->post('price'); $data['options']['size'] = $product_details->attributes; $data['options']['sku'] = $product_details->sku; $this->cart->product_name_rules = '[:print:]'; //this is to eliminate cart product name restriction on special characters $this->cart->insert($data); echo count($this->cart->contents()); } else { echo 0; //means not enough stock } } //callback function validation cek stock available when add to cart public function cek_stock() { $id_product_details = (int) $this->input->post('product_size'); $chosen_quantity = (int) $this->input->post('qty'); ; //get current stock froms product_details table $this->db->select('stock'); $this->db->from('product_details'); $this->db->where('id_product_details', $id_product_details); $query = $this->db->get(); $current_stock = (int) $query->row()->stock; //check if quantity is less or equal to current stock if ($chosen_quantity > $current_stock) { return FALSE; } else { return TRUE; } } public function ajax_get_district() { //if(!$_POST) { show_404(); } //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $province_id = (int) $this->input->post('id_province'); //check districts table if province_id already available $this->db->select('id_indonesia_districts')->from('indonesia_districts')->where('indonesia_id_province', $province_id); $count_districts = $this->db->get()->num_rows(); if($count_districts > 0) { //districts already available, get the districts $this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $province_id); $data['districts'] = $this->db->get()->result(); } else { //districts not available yet..then get rajaongkir data and store into districts table $this->load->helper('rajaongkir'); //get list of districts from RajaOngkir.com API $districts = get_rajaongkir_data('city?province=' . $province_id); //get from helper file foreach($districts['rajaongkir']['results'] as $district) { //check first if rajaongkir district_id already exist.. $this->db->select('rajaongkir_id_district')->from('indonesia_districts')->where('rajaongkir_id_district', $district['city_id']); $count_districts = $this->db->get()->num_rows(); if($count_districts == 0) { //can input new data, because still empty //insert into districts database $data = array( 'rajaongkir_id_district' => $district['city_id'], 'district' => $district['city_name'], 'indonesia_id_province' => $province_id ); $this->db->insert('indonesia_districts', $data); } } //districts should be available now, get the districts $this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $province_id); $data['districts'] = $this->db->get()->result(); } $this->load->view('ajax_get_district', $data); } public function ajax_get_shipping_district() { //if(!$_POST) { show_404(); } //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $shipping_province_id = (int) $this->input->post('id_shipping_province'); //check districts table if province_id already available $this->db->select('id_indonesia_districts')->from('indonesia_districts')->where('indonesia_id_province', $shipping_province_id); $count_districts = $this->db->get()->num_rows(); if($count_districts > 0) { //districts already available, get the districts $this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $shipping_province_id); $data['shipping_districts'] = $this->db->get()->result(); } else { //districts not available yet..then get rajaongkir data and store into districts table $this->load->helper('rajaongkir'); //get list of districts from RajaOngkir.com API $districts = get_rajaongkir_data('city?province=' . $shipping_province_id); //get from helper file foreach($districts['rajaongkir']['results'] as $district) { //check first if rajaongkir district_id already exist.. $this->db->select('rajaongkir_id_district')->from('indonesia_districts')->where('rajaongkir_id_district', $district['city_id']); $count_districts = $this->db->get()->num_rows(); if($count_districts == 0) { //can input new data, because still empty //insert into districts database $data = array( 'rajaongkir_id_district' => $district['city_id'], 'district' => $district['city_name'], 'indonesia_id_province' => $shipping_province_id ); $this->db->insert('indonesia_districts', $data); } } //districts should be available now, get the districts $this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $shipping_province_id); $data['shipping_districts'] = $this->db->get()->result(); } $this->load->view('ajax_get_shipping_district', $data); } public function ajax_get_subdistrict() { //if(!$_POST) { show_404(); } //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $district_id = (int) $this->input->post('id_district'); //check subdistricts table if district_id already available $this->db->select('id_indonesia_subdistricts')->from('indonesia_subdistricts')->where('indonesia_id_district', $district_id); $count_subdistricts = $this->db->get()->num_rows(); if($count_subdistricts > 0) { //subdistricts already available, get the subdistricts $this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $district_id); $data['subdistricts'] = $this->db->get()->result(); } else { //subdistricts not available yet..then get rajaongkir data and store into subdistricts table $this->load->helper('rajaongkir'); //get list of subdistricts from RajaOngkir.com API $subdistricts = get_rajaongkir_data('subdistrict?city=' . $district_id); //get from helper file foreach($subdistricts['rajaongkir']['results'] as $subdistrict) { //check first if rajaongkir subdistrict_id already exist.. $this->db->select('rajaongkir_id_subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $subdistrict['subdistrict_id']); $count_subdistricts = $this->db->get()->num_rows(); if($count_subdistricts == 0) { //can input new data, because still empty //insert into subdistricts database $data = array( 'rajaongkir_id_subdistrict' => $subdistrict['subdistrict_id'], 'subdistrict' => $subdistrict['subdistrict_name'], 'indonesia_id_district' => $district_id ); $this->db->insert('indonesia_subdistricts', $data); } } //subdistricts should be available now, get the subdistricts $this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $district_id); $data['subdistricts'] = $this->db->get()->result(); } $this->load->view('ajax_get_subdistrict', $data); } public function ajax_get_shipping_subdistrict() { //if(!$_POST) { show_404(); } //test if ajax call to prevent direct access if (!$this->input->is_ajax_request()) { exit('No direct script access allowed'); } $shipping_district_id = (int) $this->input->post('id_shipping_district'); //check subdistricts table if district_id already available $this->db->select('id_indonesia_subdistricts')->from('indonesia_subdistricts')->where('indonesia_id_district', $shipping_district_id); $count_subdistricts = $this->db->get()->num_rows(); if($count_subdistricts > 0) { //subdistricts already available, get the subdistricts $this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $shipping_district_id); $data['shipping_subdistricts'] = $this->db->get()->result(); } else { //subdistricts not available yet..then get rajaongkir data and store into subdistricts table $this->load->helper('rajaongkir'); //get list of subdistricts from RajaOngkir.com API $subdistricts = get_rajaongkir_data('subdistrict?city=' . $shipping_district_id); //get from helper file foreach($subdistricts['rajaongkir']['results'] as $subdistrict) { //check first if rajaongkir subdistrict_id already exist.. $this->db->select('rajaongkir_id_subdistrict')->from('indonesia_subdistricts')->where('rajaongkir_id_subdistrict', $subdistrict['subdistrict_id']); $count_subdistricts = $this->db->get()->num_rows(); if($count_subdistricts == 0) { //can input new data, because still empty //insert into subdistricts database $data = array( 'rajaongkir_id_subdistrict' => $subdistrict['subdistrict_id'], 'subdistrict' => $subdistrict['subdistrict_name'], 'indonesia_id_district' => $shipping_district_id ); $this->db->insert('indonesia_subdistricts', $data); } } //subdistricts should be available now, get the subdistricts $this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $shipping_district_id); $data['shipping_subdistricts'] = $this->db->get()->result(); } $this->load->view('ajax_get_shipping_subdistrict', $data); } }