123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- ! defined('BASEPATH') && exit('No direct script access allowed');
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- class Product extends MY_Admin_Controller
- {
- protected $check_access = FALSE;
- public function __construct()
- {
- parent::__construct();
- $this->load->model('admin_model', 'admin');
- $this->load->model('product_model', 'product');
- $this->load->model('type_model', 'type');
- }
- public function index()
- {
- if ( ! $this->checkAdminLogin()) {
- $this->load->view('adminLoginView');
- } else {
- $items = $this->product->all();
- $type = $this->type->all_index_id();
- $data['type'] = $type;
- $data['items'] = $items;
- $this->load->view('productView', $data);
- }
- }
- public function add()
- {
- $type = $this->type->all();
- $data['type'] = $type;
- $action = $this->input->get('action');
- if ($action == 'insert') {
- $_POST[] = $this->security->xss_clean($_POST);
- $type_str = implode(',', $_POST['type']);
- $parm['type'] = $type_str;
- $parm['title'] = trim($_POST['title']);
- $parm['pid'] = trim($_POST['pid']);
- $parm['level'] = 1;
- $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
- $parm['addtime'] = time();
- foreach ($_POST['img'] as $key => $value) {
- $t['img'] = $value;
- $json[] = $t;
- }
- $parm['img'] = json_encode($json);
- $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
- $parm['sence'] = trim($_POST['sence']);
- if ($this->product->insert($parm)) {
- exit('<script language="javascript">alert("添加成功"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- } else {
- exit('<script language="javascript">alert("添加失败"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- }
- }
- $this->load->view('productAddView', $data);
- }
- public function edit()
- {
- $id = $this->input->get('id', TRUE);
- $action = $this->input->get('action');
- $type = $this->type->all();
- $data['type'] = $type;
- if ($action == 'update') {
- $_POST[] = $this->security->xss_clean($_POST);
- $id = $_POST['id'];
- $type_str = implode(',', $_POST['type']);
- $parm['type'] = $type_str;
- $parm['title'] = trim($_POST['title']);
- $parm['pid'] = trim($_POST['pid']);
- $parm['level'] = 1;
- $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
- $parm['addtime'] = time();
- foreach ($_POST['img'] as $key => $value) {
- $t['img'] = $value;
- $json[] = $t;
- }
- $parm['img'] = json_encode($json);
- $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
- $parm['sence'] = trim($_POST['sence']);
- if ($this->product->update($id, $parm)) {
- exit('<script language="javascript">alert("更新成功"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- } else {
- exit('<script language="javascript">alert("更新失败"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- }
- }
- $item = $this->product->get($id);
- $item['img'] = json_decode($item['img'], true);
- $data['item'] = $item;
- $this->load->view('productEditView', $data);
- }
- public function del()
- {
- $id = $this->input->get('id', TRUE);
- if ($this->product->delete($id)) {
- exit('<script language="javascript">alert("删除成功"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- } else {
- exit('<script language="javascript">alert("删除失败"); document.location.href="' . ADMIN_PATH . '/product";</script>');
- }
- }
- }
|