Classid.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Classid extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_classid','classid');
  7. }
  8. //定义方法的调用规则 获取URI第二段值
  9. public function _remap($arg,$arg_array)
  10. {
  11. if($arg == 'add')//添加
  12. {
  13. $this->_add($arg_array);
  14. }
  15. else if($arg == 'edit')
  16. {
  17. $this->_edit($arg_array);
  18. }
  19. else if($arg == 'del')
  20. {
  21. $this->_del();
  22. }
  23. else if($arg == 'px')
  24. {
  25. $this->_px();
  26. }
  27. else
  28. {
  29. $this->_index();
  30. }
  31. }
  32. //管理
  33. public function _index()
  34. {
  35. $post = $this->input->post(NULL, TRUE);
  36. if(isset($post['rows']))
  37. {
  38. $page = $this->input->post('page',true);
  39. $perpage = $this->input->post('perpage',true);
  40. $title = $this->input->post('title',true);
  41. $pp = $this->input->post('pp',true);
  42. $order_str = "px asc";
  43. $where = "1='1'";
  44. if($title)
  45. {
  46. $where .= " and title like '%$title%'";
  47. }
  48. if($pp)
  49. {
  50. $where .= " and pp = '$pp'";
  51. }
  52. if(empty($page))
  53. {
  54. $start = 0;
  55. $perpage = 1;
  56. }
  57. //取得信息列表
  58. $info_list = $this->classid->find_all($where,'*',$order_str);
  59. echo json_encode(array('data'=>$info_list,'power'=>array(),'success'=>true));exit;
  60. }
  61. $this->_Template('classid',$this->data);
  62. }
  63. //添加
  64. public function _add($arg_array)
  65. {
  66. $post = $this->input->post(NULL, TRUE);
  67. if(isset($post['title']))
  68. {
  69. $dn = $this->classid->find_count("1=1","*","px asc");
  70. $post['px'] = $dn+1;
  71. if($this->classid->insert($post))
  72. {
  73. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  74. }
  75. else
  76. {
  77. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  78. }
  79. }
  80. $this->_Template('classid_add',$this->data);
  81. }
  82. //修改
  83. public function _edit($arg_array)
  84. {
  85. $post = $this->input->post(NULL, TRUE);
  86. if(isset($post['id']))
  87. {
  88. $id = $this->input->post('id',true);
  89. if($this->classid->save($post,$id))
  90. {
  91. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  92. }
  93. else
  94. {
  95. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  96. }
  97. }
  98. $classid = $this->classid->read($arg_array[0]);
  99. $this->data['classid'] = $classid;
  100. $this->_Template('classid_edit',$this->data);
  101. }
  102. //删除
  103. public function _del()
  104. {
  105. $post = $this->input->post(NULL, TRUE);
  106. if(isset($post['s']))
  107. {
  108. $id_arr = $this->input->post('s');
  109. $id_arr = explode(',',$id_arr);
  110. if(!$id_arr)
  111. {
  112. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  113. }
  114. //循环删除记录
  115. foreach ($id_arr as $v)
  116. {
  117. $this->classid->remove($v);
  118. }
  119. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  120. }
  121. }
  122. public function _px()
  123. {
  124. $post = $this->input->post(NULL, TRUE);
  125. if(isset($post['data']))
  126. {
  127. //echo json_encode(array('msg'=>'防止误排序,请联系开启!','success'=>false));exit;
  128. $data = $this->input->post('data',true);
  129. $data = explode('|',trim($data,'|'));
  130. $this->db->trans_begin();
  131. foreach ($data as $k=>$v)
  132. {
  133. $this->classid->save(array('px'=>$k),$v);
  134. }
  135. if ($this->db->trans_status() === TRUE)
  136. {
  137. $this->db->trans_commit();
  138. }
  139. else
  140. {
  141. $this->db->trans_rollback();
  142. }
  143. }
  144. }
  145. }