PHP File Manager
Editing File: People.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 People extends CI_Controller { function __construct() { parent::__construct(); $this->users->denyRestricted('customers'); } public function index($mode = NULL, $sub_mode = NULL) { $head_data['page_title'] = 'Customers'; $customers_filters = array(); $uri_suffix = ''; if($this->input->get('search')) { $customers_filters['customer_details'] = $this->input->get('search'); $uri_suffix = '?search=' . $this->input->get('search'); } if($mode == 'retail') { $customers_filters['archived'] = false; $customers_filters['retail'] = true; $head_data['page_title'] = 'Retail customers'; } elseif($mode == 'archived') { $customers_filters['archived'] = true; $head_data['page_title'] = 'Archived customers'; } else { $customers_filters['archived'] = $customers_filters['retail'] = false; } $this->load->view('header', $head_data); $data['customers'] = $this->customers->get(NULL, $customers_filters, $mode, $this->common->default_per_page); $data['current_suffix'] = $uri_suffix; $data['current_mode'] = $mode; $this->load->view('customers/overview', $data); $this->load->view('footer'); } public function view($customer_id = 0, $mode = NULL, $sub_mode = NULL) { if(($customer_id = (int) $customer_id) <= 0 || !($customer_info = $this->customers->get($customer_id))) { redirect('/customers'); exit; } if($this->input->post('update_customer')) { if($this->customers->saveCustomer($this->input->post(), $customer_id)) { $this->common->keepResponseMessage(); redirect('/customers/view/' . $customer_id); exit; } } if($this->input->post('check_email') !== NULL) { if(filter_var($this->input->post('check_email'), FILTER_VALIDATE_EMAIL)) { exit_with_json(array('valid_email' => true, 'email_used' => $this->customers->checkUsedEmail($this->input->post('check_email'), $customer_id))); } else { exit_with_json(array('valid_email' => false)); } } if($mode == 'request') { $this->customers->tradeRequestDecision($customer_id, ($sub_mode == 'approve'), ($this->uri->segment(6) != 'no-confirmation')); $this->common->keepResponseMessage(); redirect('/customers/view/' . $customer_id); exit; } $head_data['page_title'] = 'Customer - ' . (($customer_info->business) ? $customer_info->business : format_display($customer_info->first_name, $customer_info->last_name)); $this->load->view('header', $head_data); $orders_page_number = ($mode == 'orders' && ($orders_page_number = (int) $sub_mode) > 0) ? $orders_page_number : 1; $customer_orders = $this->orders->get(NULL, $customer_id, array('order_by' => array('delivery-date' => 'desc')), $orders_page_number, 6); $total_orders = $this->common->countPreviousQuery(); $data['customer_info'] = $customer_info; $data['customer_orders'] = $customer_orders; $data['customer_total_orders'] = $total_orders; $data['customer_notes'] = $this->customers->getCustomerNotes($customer_id, 0, 4); $data['fixed_products'] = $this->customers->getFixedPrices($customer_id); $data['referral_types'] = $this->common->getReferrals(); $this->load->view('customers/view', $data); $this->load->view('footer'); } public function notes($customer_id = 0, $page = NULL) { if($this->uri->segment(2) == 'notes' && $this->uri->segment(3) == 'delete') { if(($note_id = (int) $this->uri->segment(4)) > 0) { $this->customers->deleteCustomerNote($note_id); redirect($this->agent->referrer()); exit; } } if(($customer_id = (int) $customer_id) <= 0 || !($customer_info = $this->customers->get($customer_id))) { redirect('/customers'); exit; } if($this->input->post('save_note')) { $post_data = $this->input->post() + array('customer_id' => $customer_id); if(!$this->customers->saveCustomerNote($post_data)) { $this->common->keepPostData(); } $this->common->keepResponseMessage(); redirect($this->agent->referrer()); exit; } $head_data['page_title'] = 'Customer notes - ' . (($customer_info->business) ? $customer_info->business : format_name($customer_info->first_name, $customer_info->last_name)); $this->load->view('header', $head_data); $data['customer_info'] = $customer_info; $data['customer_notes'] = $this->customers->getCustomerNotes($customer_id, $page, $this->common->default_per_page); $this->load->view('customers/notes', $data); $this->load->view('footer'); } public function payments($customer_id = 0, $sub_mode = NULL, $tri_mode = NULL, $quad_mode = NULL) { if(($customer_id = (int) $customer_id) <= 0 || !($customer_info = $this->customers->get($customer_id))) { redirect('/customers'); exit; } if($this->input->post('add_payment')) { $this->customers->addPayment($customer_id, $this->input->post('payment_type'), $this->input->post('paid_amount')); redirect('/customers/view/' . $customer_id . '/payments'); exit; } if($sub_mode == 'confirm') { $this->orders->markAsPaid($tri_mode, $quad_mode); redirect('/customers/view/' . $customer_id . '/payments'); exit; } if($sub_mode == 'delete-order-payment' || $sub_mode == 'delete-payment') { if($sub_mode == 'delete-order-payment') { $this->orders->removePayment($tri_mode); } else { $this->customers->removePayment($tri_mode); } redirect('/customers/view/' . $customer_id . '/payments'); exit; } $head_data['page_title'] = (($customer_info->business) ? $customer_info->business : format_display($customer_info->first_name, $customer_info->last_name)) . ' - Payments'; $this->load->view('header', $head_data); $data['all_payments'] = $this->customers->getAllPayments($customer_id, $sub_mode, $this->common->default_per_page); $data['customer_info'] = $customer_info; $this->load->view('customers/payments', $data); $this->load->view('footer'); } public function edit() { if($this->input->post('save_customer') || $this->input->post('save_customer_do_order')) { if(($customer_id = $this->customers->saveCustomer($this->input->post(), NULL, true))) { $this->common->keepResponseMessage(); redirect((($this->input->post('save_customer_do_order')) ? '/orders/edit/customer' : '/customers/view') . '/' . $customer_id); exit; } } if($this->input->post('check_email') !== NULL) { if(filter_var($this->input->post('check_email'), FILTER_VALIDATE_EMAIL)) { exit_with_json(array('valid_email' => true, 'email_used' => $this->customers->checkUsedEmail($this->input->post('check_email')))); } else { exit_with_json(array('valid_email' => false)); } } $head_data['page_title'] = 'New customer'; $this->load->view('header', $head_data); $this->load->view('customers/view'); $this->load->view('footer'); } public function archives($customer_id = NULL, $restore_customer = NULL) { $this->customers->archive($customer_id, ($restore_customer == 'unarchive')); redirect($this->agent->referrer()); exit; } public function delete($customer_id = NULL) { $this->customers->delete($customer_id); redirect('/customers'); exit; } public function agreements($customer_id = 0, $mode = NULL, $agreement_id = NULL) { if(($customer_id = (int) $customer_id) <= 0 || !($customer_info = $this->customers->get($customer_id))) { redirect('/customers'); exit; } switch($mode) { default: case 'edit': if($this->input->post('save_agreements')) { $this->customers->saveAgreements($customer_id, $this->input->post()); redirect('/customers/view/' . $customer_id); exit; } $head_data['page_title'] = 'Agreed product prices - Customers'; $this->load->view('header', $head_data); $data['fixed_prices'] = $this->customers->getFixedPrices($customer_id); $this->load->view('customers/agreements', $data); $this->load->view('footer'); break; case 'delete': $this->customers->deleteAgreement($agreement_id); redirect('/customers/view/' . $customer_id); exit; break; } } public function map() { $head_data['page_title'] = 'Map - Customers'; $this->load->view('header', $head_data); $customers = $this->customers->get(NULL, NULL, -1); $customers_data = array(); $data['customers'] = $customers; foreach($customers as $customer_info) { $customers_data[] = array ( 'customer_id' => $customer_info->customer_id, 'name' => ($customer_info->business) ? format_name($customer_info->business) : format_name($customer_info->first_name, $customer_info->last_name), 'address' => format_address($customer_info->address_1, $customer_info->address_2, $customer_info->address_3, $customer_info->town, $customer_info->county, $customer_info->postcode), 'outstanding' => display_money($customer_info->total_outstanding), 'orders' => number_format($customer_info->total_orders), 'latitude' => $customer_info->latitude, 'longitude' => $customer_info->longitude ); } $data['customers_data'] = $customers_data; $this->load->view('customers/map', $data); $this->load->view('footer'); } public function search() { $query_data = rawurldecode($this->input->get('q')); //decode_post_data($query_data); $components = http_build_query(array('search' => $query_data)); redirect('/customers/' . (($components) ? '?' . $components : '')); exit; } }
Cancel