member_put.php 1.7 KB

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