PHP File Manager
Editing File: Website.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 Website extends CI_Controller { private $is_dynamic_page = false; function __construct() { parent::__construct(); $this->users->setCustomerMode()->checkSession(); if($this->uri->segment(1) != 'logout' && !($this->uri->segment(1) == 'account' && $this->uri->segment(2) == 'password') && $this->users->logged_in && $this->users->request_password_change) { redirect('/account/password'); exit; } $this->load->model(array('pages', 'social')); if(method_exists($this, $this->router->fetch_method())) { //call_user_func(array($this, $this->router->fetch_method()), array_slice(explode('/', uri_string()), 1)); } else { if(!method_exists($this, $this->uri->segment(1))) { call_user_func(array($this, 'content'), uri_string()); $this->is_dynamic_page = true; } } } public function search() { $terms = $this->input->get('terms'); $entries = $this->news->get(null, array('search' => $terms)); $this->load->view('website/header', array('page_title' => 'Search results')); $this->load->view('website/search', array('results' => $entries, 'terms' => $terms)); $this->load->view('website/footer'); } public function content($mode = NULL, $sub_mode = NULL) { // $stuff = $this->pages->get(NULL, NULL, NULL, array('only_visible' => false), -1); // preprint($stuff); die(); if($this->pages->basePageExists() || $this->pages->is('/news', false)) { $is_homepage = $this->pages->is('/home', false); $data['is_home_page'] = $is_homepage; if(($is_homepage) && ($page_content = $this->pages->get(NULL, (string) $this->uri->segment(1)))) { $head_data['is_home_page'] = true; $latest_matches = $this->news->get(null, array( 'match_reports' => true, 'upcoming' => false, 'paginate' => true, 'per_page' => 2, )); $this->load->view('website/header', $head_data); $latest_news = $this->news->get(null, array( 'paginate' => true, 'per_page' => 5, )); $this->load->view('website/pages/content', array('page_info' => $page_content, 'hide_header' => true)); $this->load->view('website/news/latest', array('entries' => $latest_news)); $this->load->view('website/matches/latest', array('matches' => $latest_matches)); $this->load->view('website/footer'); } elseif(!$is_homepage && $this->pages->is('/news', false) && $news_info = $this->news->get(null, array('alias' => $this->uri->segment(2)))) { $head_data['page_title'] = $news_info->title; $this->load->view('website/header', $head_data); $this->load->view('website/news/view', array('entry' => $news_info)); $this->load->view('website/footer'); } elseif(!$is_homepage && ($page_content = $this->pages->get(NULL, (string) $this->uri->segment(1)))) { $head_data['page_title'] = $page_content->title; $this->load->view('website/header', $head_data); $data['page_info'] = $page_content; $this->load->view('website/pages/content', $data); if($this->pages->is('/contact', false)) { if($this->input->post('submit_enquiry')) { $this->load->model('contact'); exit_with_json(array ( 'success' => $this->contact->send($this->input->post()), 'msg' => $this->common->getResponseMessage() )); } $origin_locations = $this->common->getOriginLocations(); $origin_locations[0]->blank = NULL; $origin_locations[1]->blank = ' '; $data['origin_locations'] = $origin_locations; $this->load->view('website/contact', $data); } if ($news_items = $this->news->get(null, array('category' => $page_content->page_id, 'paginate' => true, 'per_page' => 30, 'page' => (int) $this->uri->segment(2)))) { $total_entries = $this->common->countPreviousQuery(); $this->load->view('website/news/index', array( 'total_entries' => $total_entries, 'entries' => $news_items, )); } $this->load->view('website/footer'); } else { // What to do...? } } else { show_404(); } } public function basket() { if(!$this->input->is_ajax_request()) { redirect('/'); exit; } $this->load->model('basket'); if($this->users->logged_in) { $this->basket->setCustomer($this->users->customer_id); } if($this->input->post('get')) { $basket_items = $this->basket->getBasket(NULL, true); $total = $this->basket->calculate('before-discounts'); $grand_total = $this->basket->calculate('grand-total'); $total_items = $this->basket->count(); $total_qty = $this->basket->count(true); exit_with_json(array ( 'success' => true, 'total_items' => $total_items, 'total_qty' => $total_qty, 'must_qualify' => ($this->config->item('minimum_items') > 0), 'qualify_delivery' => ($this->config->item('minimum_items') > 0) ? ($total_qty >= $this->config->item('minimum_items')) : true, 'qualify_delivery_remain' => ($this->config->item('minimum_items') > 0) ? ($this->config->item('minimum_items') - $total_qty) : 0, 'total' => $total, 'total_str' => display_money($total), 'charges' => $this->basket->getCharges(), 'grand' => $grand_total, 'grand_str' => display_money($grand_total), 'vat' => $this->basket->getVat(), 'items' => $basket_items )); } elseif($this->input->post('add')) { $add_to_basket = $this->basket->inStockOnly()->addToBasket($this->input->post('item'), $this->input->post('qty'), $this->input->post('extra_options'), $this->input->post('gift_wrapped'), $this->input->post('gift_wrap_cost'), $this->input->post('gift_wrapped')); exit_with_json(array ( 'success' => is_numeric($add_to_basket), 'quantity' => $add_to_basket )); } elseif($this->input->post('delete')) { exit_with_json(array('success' => $this->basket->removeFromBasket($this->input->post('delete')))); } elseif($this->input->post('delivery_rate')) { exit_with_json(array('success' => (bool) $this->orders->getUKDeliveryRate($this->input->post('postcode')))); } elseif($this->input->post('re_order')) { if($this->users->logged_in && $this->orders->get($this->input->post('re_order'), $this->users->customer_id)) { exit_with_json(array('success' => $this->orders->copyOrderItemsToBasket($this->input->post('re_order')))); } } exit_with_json(array('success' => false)); } public function checkout($mode = NULL, $sub_mode = NULL) { $this->load->model(array('basket', 'offers')); if($this->users->logged_in || in_array($this->uri->segment(2), array('new-customer', 'address', 'review', 'pay', 'success', 'cancelled'))) { $head_data['page_title'] = 'Order checkout'; $data['qualify_delivery'] = ($this->config->item('minimum_items') > 0) ? ($this->basket->count(true) >= $this->config->item('minimum_items')) : true; $order_free_delivery = $this->orders->eligibleFreeDelivery(); $data['customer_addresses'] = $this->customers->getCustomerAddresses($this->users->customer_id, true); $data['address_fields'] = array ( 'first_name' => array('First name *', 'col-md-7'), 'last_name' => array('Last name', 'col-md-7'), 'business' => array('Business', 'col-md-6'), 'address_1' => array('Address *', 'col-md-8'), 'address_2' => array(NULL, 'col-md-8 col-md-offset-4'), 'address_3' => array(NULL, 'col-md-8 col-md-offset-4'), 'town' => array('Town', 'col-md-5'), 'county' => array('County', 'col-md-5'), 'postcode' => array('Postcode *', 'col-md-3'), 'email' => array('Email *', 'col-md-7', 'email'), 'phone' => array('Phone', 'col-md-7', 'tel'), 'mobile' => array('Mobile', 'col-md-7', 'tel') ); $checkout_step = $this->uri->segment(2); switch($checkout_step) { default: case 'new-customer': if(!($basket_items = $this->basket->getBasket(NULL, true))) { redirect('/'); exit; } if($this->input->post('apply_voucher')) { if($this->offers->findByCode($this->input->post('voucher_code'), $this->users->customer_id)) { $this->basket->applyDiscountByCode($this->input->post('voucher_code')); } else { $this->session->set_flashdata('voucher_error', $this->offers->getReason()); } redirect($this->agent->referrer()); exit; } $data['basket_items'] = $basket_items; $data['basket_info'] = array ( 'total' => $this->basket->calculate('before-discounts'), 'grand' => $this->basket->calculate('grand-total'), 'vat' => $this->basket->getVat(), 'total' => $this->basket->calculate('before-discounts'), 'grand' => $this->basket->calculate('grand-total'), '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() ) ); $data['voucher_error'] = $this->session->flashdata('voucher_error'); $data['free_delivery'] = $this->orders->eligibleFreeDelivery(); $inner_template_name = 'order'; $delivery_step = 1; $head_data['page_title'] .= ' | Your Order'; break; case 'address': if($this->input->post('check_email')) { exit_with_json(array('used' => $this->customers->checkUsedEmail($this->input->post('email'), $this->users->customer_id))); } $data['registration_required'] = !$this->users->logged_in; $inner_template_name = 'address'; $delivery_step = 2; $head_data['page_title'] .= ' | Delivery & Billing'; break; case 'review': if(!$this->input->post('submit_details')) { redirect('/'); exit; } $post_data = $this->input->post(); $post_data['delivery_country'] = $post_data['invoice_country'] = 'GB'; $populated_addresses = $this->orders->populateAddressDetails($post_data); if(!$this->orders->validatePopulatedAddress($populated_addresses)) { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect('/checkout/address'); exit; } if(!$this->users->logged_in) { if(!(isset($post_data['customer_password'], $post_data['confirm_customer_password']) && ($account_password = remove_whitespace($post_data['customer_password'])) != '')) { $this->common->setResponseMessage('Please enter the password for your new account'); } } if(!$order_free_delivery) { $address_lookup = format_whitespace(format_display($populated_addresses['delivery']['address_1'], $populated_addresses['delivery']['town'], $populated_addresses['delivery']['postcode'], $populated_addresses['delivery']['country'])); if(!($geocoded_address = $this->common->geocodeAddress($address_lookup))) { $this->common->setResponseMessage('There was a problem trying to get your address details'); $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect('/checkout/address'); exit; } $order_free_delivery = $this->orders->eligibleFreeDelivery($geocoded_address->lat, $geocoded_address->lng); } if(($rate_info = $this->orders->getUKDeliveryRate($populated_addresses['delivery']['postcode']))) { $this->basket->setDeliveryType($rate_info->delivery_type); if($order_free_delivery) { $this->basket->setDeliveryCharges(0); } else { //if($this->basket->discount_code_type != OFFER_DISCOUNT_SHIPPING) if($this->basket->getDeliveryCharges() === NULL) { $this->basket->setDeliveryCharges($rate_info->costs); } } $estimated_delivery_date = $this->orders->estimateDeliveryDate($rate_info->delivery_days); $this->basket->setEstimatedDeliveryDate($estimated_delivery_date); $data['rate_info'] = $rate_info; $data['estimated_delivery'] = $estimated_delivery_date; } else { // Outside the UK... } $data['populated_addresses'] = $populated_addresses; $this->common->keepPostData(); $this->session->set_tempdata('checkout_data', $post_data, 600); $inner_template_name = 'review'; $delivery_step = 3; $head_data['page_title'] .= ' | Review'; break; case 'pay': if(!($checkout_data = $this->session->tempdata('checkout_data'))) { redirect('/'); exit; } $order_data = $checkout_data; $order_data['customer_id'] = $this->users->customer_id; $order_data['delivery_date'] = array(date('d-m-Y', $this->basket->getEstimatedDeliveryDate())); $order_data['delivery_type'] = $this->basket->getDeliveryType(); $order_data['delivery_charges'] = $this->basket->getDeliveryCharges(); $order_data['discount_code'] = $this->basket->getDiscountCode(); $order_data['referral'] = ($this->users->customer_id > 0) ? 2 : 3; // 2: Existing customer, 3: Existing site $order_data['no_confirmation_email'] = true; if(!$this->users->logged_in) { $order_data['_password'] = $order_data['customer_password']; $order_data['_confirm_password'] = $order_data['confirm_customer_password']; } $order_total = $this->basket->calculate('grand-total'); //preprint($order_data);exit; // Saves as a pending order if($this->orders->saveOrder($order_data, NULL, true)) { $this->load->model('payment/paypal'); $order_id = reset($this->orders->getCreatedOrderIds()); // Turn off in production! if(SYSTEM_IS_TEST) { $this->paypal->test('wayne-seller@rdit.co.uk'); } $this->paypal->amount($order_total) ->description($this->config->item('company_name') . ' order') ->setSecretString('order:' . $order_id); $paypal_link = $this->paypal->generatePayPalLink(); redirect($paypal_link); exit; } else { $this->common->keepResponseMessage(); redirect('/checkout'); } break; case 'success': if(!($this->input->get('tx') && $this->input->get('st') && $this->input->get('amt') && $this->input->get('cc') && $this->input->get('cm'))) { redirect('/'); exit; } $this->load->model('payment/paypal'); // REMOVE TEST IN PRODUCTION if(SYSTEM_IS_TEST) { $this->paypal->test('wayne-seller@rdit.co.uk'); } $response = $this->paypal->confirmPDTData($this->input->get('tx'), true); $related_order_id = $this->paypal->getRelatedOrderId(); if($response && ($order_info = $this->orders->get($related_order_id))) { $data['order_info'] = $order_info; $inner_template_name = 'payment'; $head_data['page_title'] .= ' | Payment completed'; $delivery_step = 4; } else { $inner_template_name = 'payment-failed'; $head_data['page_title'] .= ' | Payment failed'; $delivery_step = 3; } break; case 'cancelled': $inner_template_name = 'payment-cancelled'; $head_data['page_title'] .= ' | Payment cancelled'; $delivery_step = 3; break; } $data['inner_template_name'] = $inner_template_name; $data['delivery_step'] = $delivery_step; $this->common->getPostData(); $this->load->view('website/header', $head_data); $this->load->view('website/checkout', $data); } else { if($this->input->post('customer_login')) { if($this->users->login($this->input->post('customer_email'), $this->input->post('customer_password'), false)) { redirect('/checkout'); exit; } } $head_data['page_title'] = 'Customer login'; $this->load->view('website/header', $head_data); $this->load->view('website/login'); } $this->load->view('website/footer'); } public function place() { $this->load->model('basket'); if($this->input->post('submit_order')) { $order_data = $this->input->post(); if($this->users->customer_id) { $order_data = $order_data + array('customer_id' => $this->users->customer_id); } else { $order_data = $order_data + array('_password' => $this->input->post('customer_password'), '_confirm_password' => $this->input->post('confirm_customer_password')); } if($this->orders->saveOrder($order_data)) { $this->session->set_tempdata('successful_order_ids', $this->orders->getCreatedOrderIds(), 7200); redirect('/checkout/complete'); } else { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect($this->agent->referrer()); } } } public function account($mode = NULL, $sub_mode = NULL, $tri_mode = NULL) { if(!$this->users->logged_in || !$this->users->customer_id) { redirect('/login'); exit; } if($this->input->post('update_password')) { $this->customers->changeAccountPassword ( $this->users->customer_id, $this->input->post('old_password'), $this->input->post('password'), $this->input->post('confirm_password') ); $this->common->keepResponseMessage(); redirect('/account/password'); exit; } switch($mode) { default: case 'orders': if(in_array($sub_mode, array('view', 'invoice', 'pay', 'cancel'))) { if(!(($order_number = is_order_number($tri_mode)) && ($order_info = $this->orders->get(NULL, $this->users->customer_id, array('number' => $order_number))))) { redirect('/account/orders'); exit; } } if($sub_mode == 'view') { $data['order_info'] = $order_info; $data['order_items'] = $this->orders->getOrderItems($order_info->order_id); if(isset($order_info->discount_code)) { $this->load->model('offers'); $data['discount_info'] = $this->offers->get($order_info->discount_code); } $head_data['page_title'] = 'Order #' . $order_number; $template_name = 'view-order'; } elseif($sub_mode == 'invoice') { if($order_info->is_pending) { redirect('/account/orders'); exit; } $this->load->model('invoice'); $this->invoice->generateOrderInvoice($order_info->order_id); exit; } elseif($sub_mode == 'pay' || $sub_mode == 'success') { $this->load->model('payment/paypal'); // Turn off in production! if(SYSTEM_IS_TEST) { $this->paypal->test('wayne-seller@rdit.co.uk'); } if($sub_mode == 'pay') { if(!$order_info->is_pending) { redirect('/account/orders'); exit; } $this->paypal->amount($order_info->total_inc_vat) ->description($this->config->item('company_name') . ' order') ->setSecretString('order:' . $order_info->order_id) ->setSuccessUrl('/account/orders/success') ->setCancelUrl('/account/orders'); $paypal_link = $this->paypal->generatePayPalLink(); redirect($paypal_link); exit; } elseif($sub_mode == 'success') { $response = $this->paypal->confirmPDTData($this->input->get('tx'), true); $related_order_id = $this->paypal->getRelatedOrderId(); if($response && ($order_info = $this->orders->get($related_order_id))) { // Need to update the delivery date if there's been any delay $this->orders->changeOrderData($related_order_id, 'delivery_date', $this->orders->estimateDeliveryDate($order_info->delivery_days)); } redirect('/account/orders'); exit; } } elseif($sub_mode == 'cancel') { if(!$order_info->is_pending) { redirect('/account/orders'); exit; } $this->orders->deleteOrder($order_info->order_id); redirect('/account/orders'); exit; } else { $skip = ($mode == 'orders') ? -1 : 0; $limit = ($mode == 'orders') ? -1 : 4; $data['orders'] = $this->orders->get(NULL, $this->users->customer_id, array ( 'priority_order' => false, 'order_by' => array('pending' => 'desc', 'order-date' => 'desc') ), $skip, $limit); $head_data['page_title'] = 'Your orders'; $template_name = 'orders'; } break; case 'password': $head_data['page_title'] = 'Password settings'; $template_name = 'account-password'; break; } $this->load->view('website/header', $head_data); $data['template_name'] = $template_name; $this->load->view('website/account/main-body', $data); $this->load->view('website/footer'); } public function ipn() { if(stripos($this->agent->agent_string(), 'paypal ipn') !== false) { $this->load->model('payment/paypal'); // REMOVE TEST IN PRODUCTION! if(SYSTEM_IS_TEST) { $this->paypal->test('wayne-seller@rdit.co.uk'); } $this->paypal->confirmIPNData($this->input->post(), true); } } public function login() { if($this->users->logged_in) { redirect('/'); exit; } if($this->input->post('customer_login')) { if($this->users->login($this->input->post('customer_email'), $this->input->post('customer_password'), false)) { redirect('/'); exit; } } $head_data['page_title'] = 'Customer login'; $this->load->view('website/header', $head_data); $data['non_checkout'] = true; $this->load->view('website/login', $data); $this->load->view('website/footer'); } public function logout() { $this->users->logout(); redirect('/'); } public function sitemap() { header("Content-Type: application/xml", true); $xml = new DOMDocument('1.0', 'UTF-8'); $urlset = $xml->createElement('urlset'); $all_pages = $this->pages->get(NULL, NULL, NULL, NULL, -1); foreach($all_pages as $page_info) { $url = $xml->createElement('url'); $url->appendChild($xml->createElement('loc', SYSTEM_DEFAULT_HOST . $page_info->url)); $url->appendChild($xml->createElement('lastmod', date('c', ($page_info->last_updated) ? $page_info->last_updated : $page_info->date_created))); $url->appendChild($xml->createElement('changefreq', 'weekly')); $url->appendChild($xml->createElement('priority', ($page_info->parent_id) ? number_format((1.9 / $this->pages->getPageDepth($page_info->page_id)), 2, '.', '') : '1.0')); $urlset->appendChild($url); } $all_products = $this->products->getProducts(NULL, NULL, NULL, NULL, true, -1); foreach($all_products as $product_info) { $url = $xml->createElement('url'); $url->appendChild($xml->createElement('loc', SYSTEM_DEFAULT_HOST . 'wines/' . $product_info->product_id . '/' . $product_info->url_name)); $url->appendChild($xml->createElement('changefreq', 'monthly')); $url->appendChild($xml->createElement('priority', '0.6')); $urlset->appendChild($url); } $xml->appendChild($urlset); $xml_contents = $xml->saveXML(); exit($xml_contents); } public function error() { if(!$this->is_dynamic_page) { set_status_header(404); $this->load->view('errors/website/error_404'); } } }
Cancel