Staffclass.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Staffclass extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_staffclass','staffclass');
  7. }
  8. //定义方法的调用规则 获取URI第二段值
  9. public function _remap($arg,$arg_array)
  10. {
  11. if($arg == 'add')//添加
  12. {
  13. $this->_add();
  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
  24. {
  25. $this->_index();
  26. }
  27. }
  28. //管理
  29. public function _index()
  30. {
  31. $post = $this->input->post(NULL, TRUE);
  32. if(isset($post['page']))
  33. {
  34. $page = $this->input->post('page',true);
  35. $perpage = $this->input->post('perpage',true);
  36. $name = $this->input->post('name',true);
  37. $where = "1=1 ";
  38. if($name)
  39. {
  40. $where .= " and name like '%$name%'";
  41. }
  42. //数据排序
  43. $order_str = "id asc";
  44. if(empty($page))
  45. {
  46. $start = 0;
  47. $perpage = 1;
  48. }
  49. else
  50. {
  51. $start = ($page - 1)*$perpage;
  52. }
  53. //取得信息列表
  54. $info_list = $this->staffclass->find_all($where,'id,name',$order_str,$start,$perpage);
  55. $total = $this->staffclass->find_count($where);
  56. $pagenum = ceil($total/$perpage);
  57. $over = $total-($start+$perpage);
  58. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  59. echo json_encode($rows);exit;
  60. }
  61. $this->_Template('staffclass',$this->data);
  62. }
  63. //添加
  64. public function _add()
  65. {
  66. $post = $this->input->post(NULL, TRUE);
  67. if(isset($post['name']))
  68. {
  69. $post['name'] = $this->input->post('name',true);
  70. if($this->staffclass->insert($post))
  71. {
  72. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  73. }
  74. else
  75. {
  76. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  77. }
  78. }
  79. $this->_Template('staffclass_add',$this->data);
  80. }
  81. //修改
  82. public function _edit($arg_array)
  83. {
  84. $post = $this->input->post(NULL, TRUE);
  85. if(isset($post['id']))
  86. {
  87. $id = $this->input->post('id',true);
  88. $post['name'] = $this->input->post('name',true);
  89. if($this->staffclass->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. $arg_array = $arg_array[0];
  99. $staffclass = $this->staffclass->read($arg_array);
  100. $this->data['staffclass'] = $staffclass;
  101. $this->_Template('staffclass_edit',$this->data);
  102. }
  103. //删除
  104. public function _del()
  105. {
  106. $post = $this->input->post(NULL, TRUE);
  107. if(isset($post['s']))
  108. {
  109. $id_arr = $this->input->post('s');
  110. $id_arr = explode(',',$id_arr);
  111. if(!$id_arr)
  112. {
  113. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  114. }
  115. //循环删除记录
  116. foreach ($id_arr as $v)
  117. {
  118. $this->staffclass->remove($v);
  119. }
  120. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  121. }
  122. }
  123. //删除
  124. public function _rows()
  125. {
  126. $a = 'xxaTyyWVbmBYp9Z9';
  127. $b = 'bg9ru7tqgrnceo2ecklmj2qlp4';
  128. $c = 'xKzbmDSkBwUToscJ';
  129. $d= $a.$b;
  130. echo sha1($d);
  131. }
  132. }