member_put.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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["user_uid"]) && isset($_POST["groupid"])) {
  7. PDO_Connect("" . _FILE_DB_GROUP_);
  8. #TODO 先查是否有加人权限
  9. $query = "SELECT power from group_member where user_id=? and group_id=? ";
  10. $power = PDO_FetchRow($query, array($_COOKIE["user_uid"], $_POST["groupid"]));
  11. if ($power) {
  12. if ($power["power"] > 1) {
  13. $respond['status'] = 1;
  14. $respond['message'] = "no power to add memeber";
  15. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  16. exit;
  17. }
  18. }
  19. $query = "SELECT * from group_info where id=?";
  20. $fc = PDO_FetchRow($query, array($_POST["groupid"]));
  21. if ($fc) {
  22. if ($fc["parent"] == 0) {
  23. $level = 0;
  24. } else {
  25. $level = 1;
  26. #子小组要插入两条记录 第一条插入父层级
  27. $query = "SELECT * from group_info where id=?";
  28. $g_parent = PDO_FetchRow($query, array($fc["id"]));
  29. $query = "INSERT INTO group_member ( user_id , group_id , power , group_name , level , status ) VALUES ( ? , ? , ? , ? , ? ,? ) ";
  30. $sth = $PDO->prepare($query);
  31. $sth->execute(array($_POST["userid"], $fc["parent"], 2, $$g_parent["name"], 0, 1));
  32. $respond = array("status" => 0, "message" => "");
  33. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  34. $error = PDO_ErrorInfo();
  35. $respond['status'] = 1;
  36. $respond['message'] = $error[2];
  37. }
  38. }
  39. }
  40. #查询这个
  41. $query = "SELECT * from group_info where id=?";
  42. $g_curr = PDO_FetchRow($query, array($_POST["groupid"]));
  43. $query = "INSERT INTO group_member ( user_id , group_id , power , group_name , level , status )
  44. VALUES ( ? , ? , ? , ? , ? ,? ) ";
  45. $sth = $PDO->prepare($query);
  46. $sth->execute(array($_POST["userid"], $_POST["groupid"], 2, $g_curr["name"], $level, 1));
  47. $respond = array("status" => 0, "message" => "");
  48. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  49. $error = PDO_ErrorInfo();
  50. $respond['status'] = 1;
  51. $respond['message'] = $error[2];
  52. }
  53. }
  54. echo json_encode($respond, JSON_UNESCAPED_UNICODE);