group_del.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once "../path.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. $respond = array("status" => 0, "message" => "");
  6. if (isset($_COOKIE["userid"]) && isset($_POST["groupid"])) {
  7. PDO_Connect("" . _FILE_DB_GROUP_);
  8. #TODO 先查是否有删除权限
  9. $query = "SELECT parent from group_info where id=? and owner=? ";
  10. $gInfo = PDO_FetchRow($query, array($_POST["groupid"], $_COOKIE["userid"]));
  11. if ($gInfo) {
  12. #删除group info
  13. $query = "DELETE from group_info where id=? and owner=? ";
  14. PDO_Execute($query, array($_POST["groupid"], $_COOKIE["userid"]));
  15. #删除 组员
  16. $query = "DELETE from group_member where group_id=? ";
  17. PDO_Execute($query, array($_POST["groupid"]));
  18. #删除到此组的分享
  19. #查询是否有子项目
  20. $query = "SELECT id from group_info where parent=? ";
  21. $project = PDO_FetchAll($query, array($_POST["groupid"]));
  22. if (count($project)) {
  23. $arrProject = array();
  24. foreach ($project as $key => $value) {
  25. # code...
  26. $arrProject[] = $value["id"];
  27. }
  28. $place_holders = implode(',', array_fill(0, count($arrProject), '?'));
  29. #删除 parent info
  30. $query = "DELETE from group_info where id IN ($place_holders) ";
  31. PDO_Execute($query, $arrProject);
  32. #删除 parent 组员
  33. $query = "DELETE from group_member where group_id IN ($place_holders) ";
  34. PDO_Execute($query, $arrProject);
  35. #删除到此组的分享
  36. }
  37. } else {
  38. $respond['status'] = 1;
  39. $respond['message'] = "no power to delete ";
  40. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  41. exit;
  42. }
  43. }
  44. echo json_encode($respond, JSON_UNESCAPED_UNICODE);