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", "
", trim($_POST['desc'])); $parm['sence'] = trim($_POST['sence']); if ($this->product->insert($parm)) { exit(''); } else { exit(''); } } $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", "
", trim($_POST['desc'])); $parm['sence'] = trim($_POST['sence']); if ($this->product->update($id, $parm)) { exit(''); } else { exit(''); } } $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(''); } else { exit(''); } } }