Vlist.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. defined('BASEPATH') or exit( 'No direct script access allowed' );
  3. class Vlist extends CI_Controller
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->database();
  9. $this->load->model("User");
  10. $this->User->Login();
  11. }
  12. public function index()
  13. {
  14. $page = intval($this->input->get_post("page", true));
  15. $page = ($page < 1 ? 1 : $page);
  16. $per_page = 16;
  17. $where = array( );
  18. $key = $this->input->get_post("key", true);
  19. $where_str = "";
  20. if( !empty($key) )
  21. {
  22. $where_str = " where name like '%" . $key . "%'";
  23. }
  24. $sel_sql = "select * from " . CS_SqlPrefix . "class " . $where_str . " order by id desc";
  25. $tol_sql = "select count(*) as count from " . CS_SqlPrefix . "class " . $where_str;
  26. $total_res = $this->db->query($tol_sql)->row();
  27. $total = $total_res->count;
  28. $totalPages = (ceil($total / $per_page) ? ceil($total / $per_page) : 1);
  29. $page = ($totalPages < $page ? $totalPages : $page);
  30. $data["nums"] = $total;
  31. if( $total < $per_page )
  32. {
  33. $per_page = $total;
  34. }
  35. $sel_sql .= " limit " . $per_page * ($page - 1) . "," . $per_page;
  36. $data["vlist"] = $this->db->query($sel_sql)->result();
  37. $base_url = site_url("vlist") . "?key=" . $key . "&page=";
  38. $data["page_data"] = page_data($total, $page, $totalPages);
  39. $data["page_list"] = admin_page($base_url, $page, $totalPages);
  40. $data["page"] = $page;
  41. $data["key"] = $key;
  42. $this->load->view("vlist.html", $data);
  43. }
  44. public function edit($id = 0)
  45. {
  46. $id = intval($id);
  47. if( 0 < $id )
  48. {
  49. $vod = $this->db->query("select * from " . CS_SqlPrefix . "class where id=" . $id)->row();
  50. $data["name"] = $vod->name;
  51. $data["xid"] = $vod->xid;
  52. $data["id"] = $vod->id;
  53. }
  54. else
  55. {
  56. $data["name"] = "";
  57. $data["xid"] = 10;
  58. $data["id"] = 0;
  59. }
  60. $this->load->view("vlist_edit.html", $data);
  61. }
  62. public function save($id = 0)
  63. {
  64. $id = intval($id);
  65. $data["name"] = $this->input->post("name", true);
  66. $data["xid"] = (int) $this->input->post("xid", true);
  67. if( empty($data["name"]) )
  68. {
  69. getjson("分类名字不能为空");
  70. }
  71. if( $id == 0 )
  72. {
  73. $this->db->insert("class", $data);
  74. }
  75. else
  76. {
  77. $this->db->update("class", $data, array( "id" => $id ));
  78. }
  79. getjson($info, 0);
  80. }
  81. public function del()
  82. {
  83. $ids = $this->input->get_post("id");
  84. if( is_array($ids) )
  85. {
  86. array_unique($ids);
  87. $ids = array_merge($ids);
  88. if( sizeof($ids) < 1 )
  89. {
  90. getjson("请选择要删除的文件");
  91. }
  92. foreach( $ids as $key => $value )
  93. {
  94. $id = intval($value);
  95. if( $id < 1 )
  96. {
  97. continue;
  98. }
  99. $this->db->delete("class", array( "id" => $id ));
  100. }
  101. }
  102. else
  103. {
  104. $id = intval($ids);
  105. $this->db->delete("class", array( "id" => $id ));
  106. }
  107. $info["url"] = site_url("class") . "?v=" . rand(0, 999);
  108. getjson($info, 0);
  109. return NULL;
  110. }
  111. }