PHP File Manager
Editing File: Goods.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 Goods extends CI_Controller { function __construct() { parent::__construct(); $this->users->denyRestricted('products'); } public function index($mode = NULL, $sub_mode = NULL) { if($this->input->post('get_product') !== NULL) { $product_data = array('success' => false, 'product' => NULL, 'options' => NULL, 'extra_options' => NULL); if(($product_id = (int) $this->input->post('get_product')) && ($product_info = $this->products->getProducts($product_id, NULL, NULL, array('include_dummy' => false)))) { if(($customer_id = (int) $this->input->post('customer_id')) > 0 && ($agreed_price = $this->customers->getFixedPrices($customer_id, $product_id))) { $product_info->fixed_cost = $agreed_price->price; } $product_data['success'] = true; $product_data['product'] = $product_info; if(($product_options = $this->products->getProducts(NULL, NULL, $product_id, array('include_dummy' => false), false, -1))) { foreach($product_options as $option_info) { $product_data['options'][] = array ( 'option' => $option_info ); } } $product_data['extra_options'] = $this->products->getProductExtras($product_id); } exit_with_json($product_data); } if($this->input->post('get_options') !== NULL) { $product_options = array(); if(($parent_product_id = (int) $this->input->post('get_options')) > 0) { $product_options = $this->products->getProducts(NULL, NULL, $parent_product_id, array('include_dummy' => false), false, -1); } exit_with_json(array('success' => !empty($product_options), 'options' => $product_options)); } if($this->input->post('get_types_list') !== NULL) { $list_type = $this->input->post('get_types_list'); switch($list_type) { case 'country': $data_list = $this->products->getCountries(); break; case 'region': $data_list = $this->products->getRegions(); break; case 'style': $data_list = $this->products->getStyles(); break; case 'selection': $data_list = $this->products->getSelections(); break; } exit_with_json(array ( 'success' => isset($data_list), 'show_countries' => ($list_type == 'region'), 'data' => (isset($data_list)) ? $data_list : NULL )); } $head_data['page_title'] = 'Products'; $this->load->view('header', $head_data); $category_id = (($category_id = (int) $sub_mode) > 0) ? $category_id : NULL; $categories = $this->products->getCategories(NULL, $category_id); $data['categories'] = $categories; $data['unassigned_category_products'] = (!$categories) ? $this->products->getProducts(NULL, $category_id, NULL, array('include_dummy' => false)) : NULL; $data['search_query'] = ($this->input->get('search')) ? nullify(rawurldecode($this->input->get('search'))) : NULL; $data['viewing_category'] = $category_id; $data['parent_category'] = ($category_id && ($parent_category = $this->products->getCategories($category_id))) ? $parent_category->parent_category : -1; $data['segment_mode'] = ($sub_mode) ? $sub_mode : NULL; $data['page_segment'] = ($sub_mode) ? 3 : 2; $this->load->view('products/overview', $data); $this->load->view('footer'); } public function view($product_id = NULL) { $product_info = NULL; if(($product_id = (int) $product_id) > 0) { if(!($product_info = $this->products->getProducts($product_id, NULL, NULL, array('include_dummy' => false))) || isset($product_info->parent_id)) { redirect('/products'); exit; } } if($this->input->post('save_option_list')) { exit_with_json(array('success' => $this->products->saveOptionList($this->input->post('option_type'), $this->input->post()))); } if($this->input->post('save_product')) { if(!$this->products->saveProduct($this->input->post(), $product_id)) { $this->common->keepPostData(); } $this->common->keepResponseMessage(); redirect('/products/view/' . $product_id); exit; } $this->common->getPostData(); //predump($product_info); $head_data['page_title'] = ((isset($product_info->name)) ? 'Edit ' . input_value($product_info->name) . ' - ' : '') . 'Products'; $this->load->view('header', $head_data); $data['product_info'] = $product_info; $data['product_options'] = (isset($product_info->has_options) && $product_info->has_options) ? $this->products->getProducts(NULL, NULL, $product_id, array('include_dummy' => false)) : NULL; $data['categories'] = $this->products->getCategories(); $data['selected_categories'] = $this->products->getProductCategories($product_id); $data['extra_options'] = $this->products->getProductExtras($product_id); $this->load->view('products/edit', $data); $this->load->view('footer'); } public function edit($mode = NULL, $sub_mode = NULL, $tri_mode = NULL) { if($this->input->post('save_product')) { if(!($product_id = $this->products->saveProduct($this->input->post()))) { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect($this->agent->referrer()); exit; } else { $this->common->keepResponseMessage(); redirect('/products/view/' . $product_id); exit; } } if($this->input->post('save_option')) { if(!($option_id = $this->products->saveOption($this->input->post(), $this->input->post('option_id')))) { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect($this->agent->referrer()); exit; } else { $this->common->keepResponseMessage(); $main_product_id = $this->products->getProducts($option_id)->parent_id; redirect('/products/view/' . $main_product_id); exit; } } if($this->input->post('save_category')) { if(!($category_id = $this->products->saveCategory($this->input->post(), $this->input->post('category_id')))) { $this->common->keepResponseMessage(); $this->common->keepPostData(); redirect($this->agent->referrer()); exit; } else { $this->common->keepResponseMessage(); redirect('/products/edit/' . $category_id); exit; } } if($this->input->post('save_globals')) { if(!$this->products->saveProductExtras($this->input->post(), $this->input->post('product_id'))) { $this->common->keepPostData(); } $this->common->keepResponseMessage(); redirect($this->agent->referrer()); exit; } $this->common->getPostData(); //predump($product_info); if($mode == 'category') { $data = array(); if(($category_id = (int) $sub_mode) > 0) { if(!($category_info = $this->products->getCategories($category_id))) { redirect('/products'); exit; } $head_data['page_title'] = 'Edit ' . input_value($category_info->category) . ' - Products'; $data['category_info'] = $category_info; } else { $head_data['page_title'] = 'New category - Products'; } $template_name = 'edit-category'; } elseif($mode == 'option') { if($sub_mode == 'new') { if(!(($product_id = (int) $tri_mode) > 0 && ($product_info = $this->products->getProducts($tri_mode))) || isset($product_info->parent_id)) { redirect('/products'); exit; } $head_data['page_title'] = 'New product option - ' . input_value($product_info->name); $data['parent_id'] = $product_info->product_id; $data['product_option'] = true; } elseif($sub_mode == 'edit') { if(!(($option_id = (int) $tri_mode) > 0 && ($option_info = $this->products->getProducts($option_id))) || !isset($option_info->parent_id)) { redirect('/products'); exit; } $head_data['page_title'] = 'Edit product option - ' . input_value($option_info->option_name); $data['parent_id'] = $option_info->parent_id; $data['option_info'] = $option_info; } $template_name = 'edit-option'; } elseif($mode == 'global') { if(!(($product_id = (int) $tri_mode) > 0 && ($product_info = $this->products->getProducts($product_id)))) { redirect('/products'); exit; } $head_data['page_title'] = 'Edit global options - ' . input_value($product_info->name); $data['extra_options'] = (($extra_options = $this->products->getProductExtras($product_id))) ? $extra_options : array(-1); $data['product_id'] = $product_id; $template_name = 'edit-globals'; } else { $head_data['page_title'] = 'New product - Products'; $data['categories'] = $this->products->getCategories(); $data['with_category'] = ($mode == 'with-category' && ($selected_category_id = (int) $sub_mode)) ? $selected_category_id : NULL; $template_name = 'edit'; } $this->load->view('header', $head_data); $this->load->view('products/' . $template_name, $data); $this->load->view('footer'); } public function delete($mode = NULL, $sub_mode = NULL) { if($mode == 'category') { $this->products->deleteCategory($sub_mode); } elseif($mode == 'option') { $this->products->deleteOption($sub_mode); } elseif($mode == 'product') { $this->products->delete($sub_mode); } redirect($this->agent->referrer()); } }
Cancel