news.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. !defined('BASEPATH') && exit('No direct script access allowed');
  3. class News extends MY_Admin_Controller
  4. {
  5. protected $check_access = false;
  6. public function __construct()
  7. {
  8. parent::__construct();
  9. $this->load->model('admin_model','admin');
  10. $this->load->model('news_model','news');
  11. }
  12. public function index()
  13. {
  14. if(!$this->checkAdminLogin())
  15. {
  16. $this->load->view('adminLoginView');
  17. } else {
  18. $type = $this->input->get('type');
  19. $items = $this->news->all($type);
  20. $exa = $this->config->item("NEWS");
  21. $data['exa'] = $exa;
  22. $data['items'] = $items;
  23. $data['type'] = $type;
  24. $this->load->view('newsView' , $data);
  25. }
  26. }
  27. public function add()
  28. {
  29. $action = $this->input->get('action');
  30. $type = $this->input->get('type');
  31. $exa = $this->config->item("NEWS");
  32. $data['exa'] = $exa;
  33. $data['type'] = $type;
  34. if($action == 'insert'){
  35. $_POST[] = $this->security->xss_clean($_POST);
  36. $parm['type'] = $type;
  37. $parm['title'] = trim($_POST['title']);
  38. $parm['author'] = trim($_POST['author']);
  39. $parm['from'] = trim($_POST['from']);
  40. $parm['pv'] = trim($_POST['pv']);
  41. $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
  42. $parm['addtime'] = time();
  43. $parm['img'] = trim($_POST['img']);
  44. $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
  45. $parm['content'] = trim($_POST['content']);
  46. if($this->news->insert($parm)){
  47. exit('<script language="javascript">alert("添加成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  48. }
  49. else
  50. exit('<script language="javascript">alert("添加失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  51. }
  52. $this->load->view('newsAddView' , $data);
  53. }
  54. public function edit()
  55. {
  56. $id = $this->input->get('id' , true);
  57. $action = $this->input->get('action');
  58. $type = $this->input->get('type');
  59. $exa = $this->config->item("NEWS");
  60. $data['exa'] = $exa;
  61. $data['type'] = $type;
  62. if($action == 'update'){
  63. $_POST[] = $this->security->xss_clean($_POST);
  64. $id = $_POST['id'];
  65. $parm['type'] = trim($_POST['type']);
  66. $parm['title'] = trim($_POST['title']);
  67. $parm['author'] = trim($_POST['author']);
  68. $parm['from'] = trim($_POST['from']);
  69. $parm['pv'] = trim($_POST['pv']);
  70. $parm['publishtime'] = strtotime(trim($_POST['publishtime']));
  71. $parm['addtime'] = time();
  72. $parm['img'] = trim($_POST['img']);
  73. $parm['desc'] = str_replace("\n", "<br>", trim($_POST['desc']));
  74. $parm['content'] = trim($_POST['content']);
  75. if($this->news->update($id , $parm)){
  76. exit('<script language="javascript">alert("更新成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  77. }
  78. else{
  79. exit('<script language="javascript">alert("更新失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  80. }
  81. }
  82. $item = $this->news->get($id);
  83. $data['item'] = $item;
  84. $this->load->view('newsEditView' , $data);
  85. }
  86. public function del()
  87. {
  88. $id = $this->input->get('id' , true);
  89. if($this->news->delete($id)){
  90. exit('<script language="javascript">alert("删除成功"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  91. }
  92. else
  93. exit('<script language="javascript">alert("删除失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  94. }
  95. // public function update_ord()
  96. // {
  97. // $type = $this->input->get('type');
  98. // $id = $this->input->get('id' , true);
  99. // $last_id = $this->input->get('last_id' , true);
  100. // $parm = $this->news->get($id);
  101. // $parm1 = $this->news->get($last_id);
  102. // $temp = $parm['ord'];
  103. // $parm['ord'] = $parm1['ord'];
  104. // $parm1['ord'] = $temp;
  105. // if($this->news->update($id , $parm) && $this->news->update($last_id , $parm1)){
  106. // exit('<script language="javascript"> document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  107. // }
  108. // else
  109. // exit('<script language="javascript">alert("失败"); document.location.href="'.ADMIN_PATH.'/news?type='.$type.'";</script>');
  110. // }
  111. }