123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- !defined('BASEPATH') && exit('No direct script access allowed');
- class News extends MY_Admin_Controller
- {
- protected $check_access = false;
- public function __construct()
- {
- parent::__construct();
- $this->load->model('admin_model','admin');
- $this->load->model('news_model','news');
- }
- public function index()
- {
- if(!$this->checkAdminLogin())
- {
- $this->load->view('adminLoginView');
- } else {
- $type = $this->input->get('type');
- $items = $this->news->all($type);
- $exa = $this->config->item("NEWS");
- $data['exa'] = $exa;
- $data['items'] = $items;
- $data['type'] = $type;
- $this->load->view('newsView' , $data);
- }
- }
- public function add()
- {
-
- $action = $this->input->get('action');
- $type = $this->input->get('type');
- $exa = $this->config->item("NEWS");
- $data['exa'] = $exa;
- $data['type'] = $type;
- if($action == 'insert'){
- $_POST[] = $this->security->xss_clean($_POST);
- $parm['type'] = $type;
- $parm['title'] = trim($_POST['title']);
- $parm['author'] = trim($_POST['author']);
- $parm['from'] = trim($_POST['from']);
- $parm['pv'] = trim($_POST['pv']);
- $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
- $parm['addtime'] = time();
- $parm['img'] = trim($_POST['img']);
- $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
- $parm['content'] = trim($_POST['content']);
- if($this->news->insert($parm)){
- exit('<script language="javascript">alert("添加成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- else
- exit('<script language="javascript">alert("添加失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- $this->load->view('newsAddView' , $data);
- }
- public function edit()
- {
- $id = $this->input->get('id' , true);
- $action = $this->input->get('action');
- $type = $this->input->get('type');
- $exa = $this->config->item("NEWS");
- $data['exa'] = $exa;
- $data['type'] = $type;
- if($action == 'update'){
- $_POST[] = $this->security->xss_clean($_POST);
- $id = $_POST['id'];
- $parm['type'] = trim($_POST['type']);
- $parm['title'] = trim($_POST['title']);
- $parm['author'] = trim($_POST['author']);
- $parm['from'] = trim($_POST['from']);
- $parm['pv'] = trim($_POST['pv']);
- $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
- $parm['addtime'] = time();
- $parm['img'] = trim($_POST['img']);
- $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
- $parm['content'] = trim($_POST['content']);
- if($this->news->update($id , $parm)){
- exit('<script language="javascript">alert("更新成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- else{
- exit('<script language="javascript">alert("更新失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- }
- $item = $this->news->get($id);
- $data['item'] = $item;
- $this->load->view('newsEditView' , $data);
- }
- public function del()
- {
- $id = $this->input->get('id' , true);
- if($this->news->delete($id)){
- exit('<script language="javascript">alert("删除成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- else
- exit('<script language="javascript">alert("删除失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- }
- // public function update_ord()
- // {
- // $type = $this->input->get('type');
- // $id = $this->input->get('id' , true);
- // $last_id = $this->input->get('last_id' , true);
- // $parm = $this->news->get($id);
- // $parm1 = $this->news->get($last_id);
- // $temp = $parm['ord'];
- // $parm['ord'] = $parm1['ord'];
- // $parm1['ord'] = $temp;
- // if($this->news->update($id , $parm) && $this->news->update($last_id , $parm1)){
- // exit('<script language="javascript"> document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- // }
- // else
- // exit('<script language="javascript">alert("失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
- // }
- }
|