PHP File Manager
Editing File: Ajax.php
<?php /* * Copyright (C) Wayne Purton-Smith - All Rights Reserved * Unauthorized copying of this file or removing this paragraph, via any medium is strictly prohibited * Proprietary and confidential * Written by Wayne Purton-Smith <waynepurtonsmith@hotmail.co.uk> February 2014 */ class Ajax extends CI_Controller { public function request() { if($this->input->post('get_customer_addresses')) { $this->users->denyRestricted('customers'); if(($customer_id = (int) $this->input->post('get_customer_addresses')) && ($customer_info = $this->customers->get($customer_id))) { exit_with_json(array ( 'success' => true, 'addresses' => $this->customers->getCustomerAddresses($customer_id, true), 'records' => $this->customers->getCustomerAddresses($customer_id), 'discount' => array ( 'type' => $customer_info->default_discount_type, 'amount' => $customer_info->default_discount ), 'charges' => !$customer_info->no_charges, 'delivery' => $customer_info->preferred_delivery_time )); } exit_with_json(array('success' => false)); } elseif($this->input->post('get_customer_orders')) { $this->users->denyRestricted('customers', 'orders'); if(($customer_id = (int) $this->input->post('get_customer_orders')) > 0) { exit_with_json(array ( 'success' => true, 'orders' => $this->orders->get(NULL, $customer_id, array ( 'order_date_from' => strtotime('-14 days 00:00:00'), 'order_date_to' => strtotime('today 23:59:59'), 'order_by' => array('order-date' => 'desc') )) )); } exit_with_json(array('success' => false)); } elseif($this->input->post('get_level') && ($item_id = (int) $this->input->post('get_level')) > 0) { $this->users->denyRestricted('stock'); $stock_level = $this->stocks->getStock($item_id); exit_with_json(array('success' => (isset($stock_level->stock_level)), 'details' => $stock_level)); } elseif($this->input->get_post('get_available_products')) { $this->users->denyRestricted('products'); $products_list = $this->products->getProductsList(); exit_with_json(array('success' => !empty($products_list), 'products' => $products_list)); } elseif($this->input->post('search_products') !== NULL) { $this->users->denyRestricted('products'); $search_products = array(); if(strlen(($search_query = trim($this->input->post('search_products'))))) { $results = $this->products->getProducts(NULL, NULL, NULL, array('query' => $search_query, 'include_dummy' => false), false, 0, 6); foreach($results as $product_info) { $search_products[$product_info->product_id . (($product_info->parent_id) ? ':' . $product_info->parent_id : '')] = $product_info->name . ' ⋅ <strong>' . display_money($product_info->cost) . '</strong>'; } } exit_with_json(array('success' => !empty($search_products), 'results' => $search_products)); } elseif($this->input->post('search_customers') !== NULL) { $this->users->denyRestricted('customers'); $search_customers = array(); if(strlen(($search_query = trim($this->input->post('search_customers'))))) { $results = $this->customers->get(NULL, array('query' => $search_query), 0, 6); foreach($results as $customer_info) { $search_customers[$customer_info->customer_id] = '<strong>' . (($customer_info->business) ? $customer_info->business : format_display($customer_info->first_name, $customer_info->last_name)) . '</strong> ⋅ ' . format_address($customer_info->address_1, $customer_info->address_2, $customer_info->address_3, $customer_info->town, $customer_info->county, $customer_info->postcode, $customer_info->country); } } exit_with_json(array('success' => !empty($search_customers), 'results' => $search_customers)); } elseif($this->input->post('get_category') !== NULL) { $this->users->denyRestricted('products'); exit_with_json(array ( 'categories' => $this->products->getCategories(NULL, $this->input->post('get_category')), 'products' => $this->products->getProductsInCategory($this->input->post('get_category')) )); } elseif($this->input->post('lookup_discount') !== NULL) { $this->users->denyRestricted('orders', 'offers'); $discount_info = array('valid_code' => false, 'info' => NULL, 'details' => NULL, 'reason' => NULL); if(($discount_code = $this->input->post('lookup_discount'))) { $this->load->model('offers'); $lookup_info = $this->offers->findByCode($discount_code, $this->input->post('customer_id')); $discount_info['valid_code'] = ($lookup_info !== false); $discount_info['info'] = $lookup_info; $discount_info['details'] = $this->offers->explainOffer($lookup_info); $discount_info['reason'] = $this->offers->getReason(); } exit_with_json($discount_info); } else { exit_with_json(array('success' => false)); } } public function basket() { $this->users->denyRestricted('orders'); $this->load->model('basket'); $this->users->setCustomerMode()->checkSession(); if($this->users->logged_in && $this->users->customer_id > 0) { $this->basket->setCustomer($this->users->customer_id); } if($this->input->post('update')) { $response = $this->basket->addToBasket($this->input->post('id'), $this->input->post('qty'), $this->input->post('extra_options'), $this->input->post('gift_wrapped'), $this->input->post('gift_wrap_cost'), $this->input->post('gift_message')); exit_with_json(array ( 'success' => (is_numeric($response)), 'total' => $this->basket->calculate('before-discounts'), 'grand' => $this->basket->calculate('grand-total'), 'vat' => $this->basket->getVat(), 'discount' => $this->basket->getDiscount(), 'count' => $response )); } elseif($this->input->post('get')) { exit_with_json(array ( 'success' => true, 'customer' => $this->basket->getCustomer(), 'total' => $this->basket->calculate('before-discounts'), 'chargeable' => $this->basket->isChargeable(), 'charges' => $this->basket->getCharges(), 'grand' => $this->basket->calculate('grand-total'), 'gift_charges' => $this->basket->getGiftCharges(), 'vat' => $this->basket->getVat(), 'discount' => $this->basket->getDiscount(), 'discount_type' => $this->basket->getDiscountType(), 'discount_code' => $this->basket->getDiscountCode(), 'total_discount' => $this->basket->calculateDiscount(), 'delivery' => array ( 'info' => $this->basket->getDeliveryInfo(), 'total' => $this->basket->calculateDeliveryCharges(), 'manual_charge' => $this->basket->getDeliveryCharges() ), 'items' => $this->basket->getBasket() )); } elseif($this->input->post('get_options') !== NULL) { $options_data = array(); if(($parent_id = (int) $this->input->post('get_options')) > 0) { $product_options = $this->products->getProducts(NULL, NULL, $parent_id, array('include_dummy' => false), true, -1); foreach($product_options as $option_info) { $options_data[$option_info->product_id] = $option_info->option_name . ' (+ ' . display_money($option_info->option_cost) . ')'; } } exit_with_json(array('success' => !empty($options_data), 'options' => $options_data)); } elseif($this->input->post('set_customer') !== NULL) { $this->basket->setCustomer($this->input->post('set_customer')); exit_with_json(array('success' => true)); } elseif($this->input->post('set_discount') !== NULL) { $this->basket->setDiscountType($this->input->post('set_discount')); exit_with_json(array('success' => true)); } elseif($this->input->post('set_discount_amount') !== NULL) { $this->basket->setDiscount($this->input->post('set_discount_amount')); exit_with_json(array('success' => true)); } elseif($this->input->post('set_charge_mode') !== NULL) { $this->basket->setChargeableMode($this->input->post('set_charge_mode')); exit_with_json(array('success' => true)); } elseif($this->input->post('set_delivery') !== NULL) { $this->basket->setDeliveryType($this->input->post('set_delivery')); exit_with_json(array('success' => true)); } elseif($this->input->post('set_delivery_charges') !== NULL) { $this->basket->setDeliveryCharges($this->input->post('set_delivery_charges')); exit_with_json(array('success' => true)); } elseif($this->input->post('get_total')) { exit_with_json(array ( 'success' => true, 'total' => $this->basket->calculate('before-discounts'), 'grand' => $this->basket->calculate('grand-total'), 'vat' => $this->basket->getVat(), 'discount' => $this->basket->getDiscount(), )); } elseif($this->input->post('use_order')) { if(($order_id = (int) $this->input->post('use_order')) > 0) { exit_with_json(array('success' => $this->orders->copyOrderItemsToBasket($order_id))); } } elseif($this->input->post('empty')) { exit_with_json(array('success' => $this->basket->clearBasket())); } elseif($this->input->post('delete_item')) { exit_with_json(array('success' => $this->basket->removeFromBasket($this->input->post('delete_item')))); } exit_with_json(array('success' => false)); } public function upload($mode = NULL) { $this->users->denyRestricted('content'); header("Content-Type: text/html", true); $this->load->library('upload'); $base_path = 'assets/uploads/content/'; $this->upload->initialize(array ( 'upload_path' => $base_path, 'allowed_types' => 'jpeg|jpg', 'file_ext_tolower' => true, 'remove_spaces' => true )); if($this->upload->do_upload('upload')) { $upload_data = $this->upload->data(); $full_image_path = $upload_data['full_path']; $this->load->library('image_lib', array ( 'source_image' => $full_image_path, 'create_thumb' => true, 'new_image' => $full_image_path, 'width' => 250, 'height' => 250, 'maintain_ratio' => true, 'quality' => 75 )); $this->image_lib->resize(); $javascript_response = 'window.parent.CKEDITOR.tools.callFunction(1, \'/' . $base_path . $upload_data['file_name'] . '\', \'\');'; } else { $javascript_response = 'window.parent.alert(\'File failed to upload\');'; } exit('<script type="text/javascript">' . $javascript_response . '</script>'); } }
Cancel