RoleTrashAction.class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class RoleTrashAction extends CommonAction{
  10. public function trash()
  11. {
  12. if(intval($_REQUEST['action_id'])!='')
  13. {
  14. $action_id= intval($_REQUEST['action_id']);
  15. }
  16. $this->assign('action_id',$action_id);
  17. $condition['is_delete'] = 1;
  18. $this->assign("default_map",$condition);
  19. $map = $this->_search ();
  20. //追加默认参数
  21. if($this->get("default_map"))
  22. $map = array_merge($map,$this->get("default_map"));
  23. if (method_exists ( $this, '_filter' )) {
  24. $this->_filter ( $map );
  25. }
  26. $name="Role";
  27. $model = D ($name);
  28. if (! empty ( $model )) {
  29. $this->_list ( $model, $map );
  30. }
  31. $this->display ();
  32. return;
  33. }
  34. //相关操作
  35. public function set_effect()
  36. {
  37. $id = intval($_REQUEST['id']);
  38. $ajax = intval($_REQUEST['ajax']);
  39. $info = M("Role")->where("id=".$id)->getField("name");
  40. $c_is_effect = M("Role")->where("id=".$id)->getField("is_effect"); //当前状态
  41. $n_is_effect = $c_is_effect == 0 ? 1 : 0; //需设置的状态
  42. M("Role")->where("id=".$id)->setField("is_effect",$n_is_effect);
  43. save_log($info.l("SET_EFFECT_".$n_is_effect),1);
  44. $this->ajaxReturn($n_is_effect,l("SET_EFFECT_".$n_is_effect),1) ;
  45. }
  46. public function delete() {
  47. //删除指定记录
  48. $ajax = intval($_REQUEST['ajax']);
  49. $id = $_REQUEST ['id'];
  50. if (isset ( $id )) {
  51. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  52. $rel_data = M("Role")->where($condition)->findAll();
  53. foreach($rel_data as $data)
  54. {
  55. $info[] = $data['name'];
  56. //开始验证分组下是否存在管理员
  57. if(M("Admin")->where("is_effect = 1 and is_delete = 0 and role_id=".$data['id'])->count()>0)
  58. {
  59. $this->error ($data['name'].l("EXIST_ADMIN"),$ajax);
  60. }
  61. }
  62. if($info) $info = implode(",",$info);
  63. $list = M("Role")->where ( $condition )->setField ( 'is_delete', 1 );
  64. if ($list!==false) {
  65. save_log($info.l("DELETE_SUCCESS"),1);
  66. $this->success (l("DELETE_SUCCESS"),$ajax);
  67. } else {
  68. save_log($info.l("DELETE_FAILED"),0);
  69. $this->error (l("DELETE_FAILED"),$ajax);
  70. }
  71. } else {
  72. $this->error (l("INVALID_OPERATION"),$ajax);
  73. }
  74. }
  75. public function restore() {
  76. //删除指定记录
  77. $ajax = intval($_REQUEST['ajax']);
  78. $id = $_REQUEST ['id'];
  79. if (isset ( $id )) {
  80. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  81. $rel_data = M("Role")->where($condition)->findAll();
  82. foreach($rel_data as $data)
  83. {
  84. $info[] = $data['name'];
  85. }
  86. if($info) $info = implode(",",$info);
  87. $list = M("Role")->where ( $condition )->setField ( 'is_delete', 0 );
  88. if ($list!==false) {
  89. save_log($info.l("RESTORE_SUCCESS"),1);
  90. $this->success (l("RESTORE_SUCCESS"),$ajax);
  91. } else {
  92. save_log($info.l("RESTORE_FAILED"),0);
  93. $this->error (l("RESTORE_FAILED"),$ajax);
  94. }
  95. } else {
  96. $this->error (l("INVALID_OPERATION"),$ajax);
  97. }
  98. }
  99. public function foreverdelete() {
  100. //彻底删除指定记录
  101. $ajax = intval($_REQUEST['ajax']);
  102. $id = $_REQUEST ['id'];
  103. if (isset ( $id )) {
  104. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  105. $role_access_condition = array ('role_id' => array ('in', explode ( ',', $id ) ) );
  106. $rel_data = M("Role")->where($condition)->findAll();
  107. foreach($rel_data as $data)
  108. {
  109. $info[] = $data['name'];
  110. //开始验证分组下是否存在管理员
  111. if(M("Admin")->where("is_effect = 1 and is_delete = 0 and role_id=".$data['id'])->count()>0)
  112. {
  113. $this->error ($data['name'].l("EXIST_ADMIN"),$ajax);
  114. }
  115. }
  116. if($info) $info = implode(",",$info);
  117. $list = M("Role")->where ( $condition )->delete();
  118. M("RoleAccess")->where($role_access_condition)->delete();
  119. M("Admin")->where($role_access_condition)->delete();
  120. if ($list!==false) {
  121. save_log($info.l("FOREVER_DELETE_SUCCESS"),1);
  122. $this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  123. } else {
  124. save_log($info.l("FOREVER_DELETE_FAILED"),0);
  125. $this->error (l("FOREVER_DELETE_FAILED"),$ajax);
  126. }
  127. } else {
  128. $this->error (l("INVALID_OPERATION"),$ajax);
  129. }
  130. }
  131. }
  132. ?>