my_group_put.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. #新增群组或项目
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once '../public/function.php';
  6. $respond = array("status" => 0, "message" => "");
  7. if (isset($_COOKIE["userid"])) {
  8. PDO_Connect(_FILE_DB_GROUP_);
  9. #先查询是否有重复的组名
  10. $query = "SELECT id FROM group_info WHERE name = ? ";
  11. $Fetch = PDO_FetchRow($query, array($_POST["name"]));
  12. if ($Fetch) {
  13. $respond['status'] = 1;
  14. $respond['message'] = "错误:有相同的组名称,请选择另一个名称。";
  15. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  16. exit;
  17. }
  18. $query = "INSERT INTO group_info ( id, parent , name , description , status , owner ,create_time )
  19. VALUES ( ?, ? , ? , ? , ? , ? ,? ) ";
  20. $sth = $PDO->prepare($query);
  21. $newid = UUID::v4();
  22. $sth->execute(array($newid, $_POST["parent"], $_POST["name"], "", 1, $_COOKIE["userid"], mTime()));
  23. $respond = array("status" => 0, "message" => "");
  24. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  25. $error = PDO_ErrorInfo();
  26. $respond['status'] = 1;
  27. $respond['message'] = $error[2];
  28. }
  29. #将创建者添加到成员中
  30. $query = "INSERT INTO group_member ( user_id , group_id , power , group_name , level , status )
  31. VALUES ( ? , ? , ? , ? , ? ,? ) ";
  32. $sth = $PDO->prepare($query);
  33. $sth->execute(array($_COOKIE["userid"], $newid, 0, $_POST["name"], 0, 1));
  34. $respond = array("status" => 0, "message" => "");
  35. if (!$sth || ($sth && $sth->errorCode() != 0)) {
  36. $error = PDO_ErrorInfo();
  37. $respond['status'] = 1;
  38. $respond['message'] = $error[2];
  39. }
  40. }
  41. echo json_encode($respond, JSON_UNESCAPED_UNICODE);