CatalogController.class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class CatalogController extends BaseController {
  5. //编辑页面
  6. public function edit(){
  7. $cat_id = I("cat_id");
  8. $Catalog = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
  9. if ($Catalog) {
  10. $this->assign("Catalog" , $Catalog);
  11. }
  12. $item_id = $Catalog['item_id'] ? $Catalog['item_id'] : I("item_id");
  13. $login_user = $this->checkLogin();
  14. if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
  15. $this->message("你无权限");
  16. return;
  17. }
  18. $this->assign("item_id" , $item_id);
  19. $this->display();
  20. }
  21. //保存目录
  22. public function save(){
  23. $cat_name = I("cat_name");
  24. $order = I("order") ? I("order") : 99 ;
  25. $cat_id = I("cat_id")? I("cat_id") : 0;
  26. $item_id = I("item_id");
  27. $login_user = $this->checkLogin();
  28. if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
  29. $this->message("你无权限");
  30. return;
  31. }
  32. $data['cat_name'] = $cat_name ;
  33. $data['order'] = $order ;
  34. $data['item_id'] = $item_id ;
  35. if ($cat_id > 0 ) {
  36. $ret = D("Catalog")->where(" cat_id = '$cat_id' ")->save($data);
  37. $return = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
  38. }else{
  39. $data['addtime'] = time();
  40. $cat_id = D("Catalog")->add($data);
  41. $return = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
  42. }
  43. if (!$return) {
  44. $return['error_code'] = 10103 ;
  45. $return['error_message'] = 'request fail' ;
  46. }
  47. $this->sendResult($return);
  48. }
  49. //获取目录列表
  50. public function catList(){
  51. $item_id = I("item_id");
  52. if ($item_id > 0 ) {
  53. $ret = D("Catalog")->where(" item_id = '$item_id' ")->order(" 'order', addtime asc ")->select();
  54. }
  55. if ($ret) {
  56. $this->sendResult($ret);
  57. }else{
  58. $return['error_code'] = 10103 ;
  59. $return['error_message'] = 'request fail' ;
  60. $this->sendResult($return);
  61. }
  62. }
  63. //删除目录
  64. public function delete(){
  65. $cat_id = I("cat_id")? I("cat_id") : 0;
  66. $cat = D("Catalog")->where(" cat_id = '$cat_id' ")->find();
  67. $item_id = $cat['item_id'];
  68. $login_user = $this->checkLogin();
  69. if (!$this->checkItemPermn($login_user['uid'] , $item_id)) {
  70. $return['error_code'] = -1 ;
  71. $return['error_message'] = '你无权限' ;
  72. $this->sendResult($return);
  73. return;
  74. }
  75. if (D("Page")->where(" cat_id = '$cat_id' ")->find()) {
  76. $return['error_code'] = -1 ;
  77. $return['error_message'] = '为了安全,不允许直接删除非空目录。请先删除或转移该目录下的所有页面' ;
  78. $this->sendResult($return);
  79. return;
  80. }
  81. if ($cat_id > 0 ) {
  82. $ret = D("Catalog")->where(" cat_id = '$cat_id' ")->limit(1)->delete();
  83. }
  84. if ($ret) {
  85. $this->sendResult($ret);
  86. }else{
  87. $return['error_code'] = -1 ;
  88. $return['error_message'] = 'request fail' ;
  89. $this->sendResult($return);
  90. }
  91. }
  92. }