Studyclass.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Studyclass extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_studyclass','studyclass');
  6. $this->load->_model('Model_typeclass','typeclass');
  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($arg_array);
  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. $title = $this->input->post('title',true);
  37. $type = $this->input->post('type',true);
  38. $where = "1=1 ";
  39. //数据排序
  40. $order_str = "id asc";
  41. if(empty($page))
  42. {
  43. $start = 0;
  44. $perpage = 1;
  45. }
  46. else
  47. {
  48. $start = ($page - 1)*$perpage;
  49. }
  50. if($title)
  51. {
  52. $where .= " and title like '%$title%'";
  53. }
  54. if($type)
  55. {
  56. $where .= " and type = '$type'";
  57. }
  58. //取得信息列表
  59. $info_list = $this->studyclass->find_all($where,'id,title,addtime',$order_str,$start,$perpage);
  60. //格式化数据
  61. foreach ($info_list as $key=>$value)
  62. {
  63. $info_list[$key]['addtime'] = date("Y-m-d H:i:s",$value['addtime']);
  64. }
  65. $total = $this->studyclass->find_count($where);
  66. $pagenum = ceil($total/$perpage);
  67. $over = $total-($start+$perpage);
  68. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
  69. echo json_encode($rows);exit;
  70. }
  71. $this->_Template('studyclass',$this->data);
  72. }
  73. //添加
  74. public function _add()
  75. {
  76. $post = $this->input->post(NULL, TRUE);
  77. if(isset($post['title']))
  78. {
  79. $post['title'] = $this->input->post('title',true);
  80. $post['addtime'] = time();
  81. if($this->studyclass->insert($post))
  82. {
  83. echo json_encode(array('msg'=>'添加成功','success'=>true));exit;
  84. }
  85. else
  86. {
  87. echo json_encode(array('msg'=>'添加失败,请重试','success'=>false));exit;
  88. }
  89. }
  90. $this->_Template('studyclass_add',$this->data);
  91. }
  92. //修改
  93. public function _edit($arg_array)
  94. {
  95. $post = $this->input->post(NULL, TRUE);
  96. if(isset($post['id']))
  97. {
  98. $id = $this->input->post('id',true);
  99. $post['title'] = $this->input->post('title',true);
  100. $post['edittime'] = time();
  101. if($this->studyclass->save($post,$id))
  102. {
  103. echo json_encode(array('msg'=>'修改成功','success'=>true));exit;
  104. }
  105. else
  106. {
  107. echo json_encode(array('msg'=>'修改失败,请重试','success'=>false));exit;
  108. }
  109. }
  110. $arg_array = $arg_array[0];
  111. $studyclass = $this->studyclass->read($arg_array);
  112. $this->data['studyclass'] = $studyclass;
  113. $this->_Template('studyclass_edit',$this->data);
  114. }
  115. //删除
  116. public function _del()
  117. {
  118. $post = $this->input->post(NULL, TRUE);
  119. if(isset($post['s']))
  120. {
  121. $id_arr = $this->input->post('s');
  122. $id_arr = explode(',',$id_arr);
  123. if(!$id_arr)
  124. {
  125. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  126. }
  127. //循环删除记录
  128. foreach ($id_arr as $v)
  129. {
  130. $this->studyclass->remove($v);
  131. }
  132. echo json_encode(array('del'=>$id_arr,'msg'=>'删除记录成功!','success'=>true));
  133. }
  134. }
  135. }