sent.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. //查询term字典
  3. require_once "../../public/_pdo.php";
  4. require_once "../../public/function.php";
  5. require_once '../../vendor/autoloader.php';
  6. require_once '../../path.php';
  7. $username = "";
  8. $op = $_POST["op"];
  9. if (isset($_POST["uid"])) {
  10. $UID = $_POST["uid"];
  11. } else {
  12. if (isset($_COOKIE["username"]) && !empty($_COOKIE["username"])) {
  13. $UID = $_COOKIE["uid"];
  14. }
  15. }
  16. if (isset($_POST["book"])) {
  17. $_book = $_POST["book"];
  18. }
  19. if (isset($_POST["para"])) {
  20. $_para = $_POST["para"];
  21. }
  22. if (isset($_POST["begin"])) {
  23. $_begin = $_POST["begin"];
  24. }
  25. if (isset($_POST["end"])) {
  26. $_end = $_POST["end"];
  27. }
  28. if (isset($_POST["tag"])) {
  29. $_tag = $_POST["tag"];
  30. }
  31. if (isset($_POST["text"])) {
  32. $_text = $_POST["text"];
  33. }
  34. if (isset($_POST["author"])) {
  35. $_author = $_POST["author"];
  36. }
  37. if (isset($_POST["lang"])) {
  38. $_lang = $_POST["lang"];
  39. }
  40. if (isset($_POST["status"])) {
  41. $_status = $_POST["status"];
  42. }
  43. if (isset($_POST["id"])) {
  44. $_id = $_POST["id"];
  45. }
  46. if (isset($_POST["block_id"])) {
  47. $_block_id = $_POST["block_id"];
  48. }
  49. global $PDO;
  50. PDO_Connect(_FILE_DB_SENTENCE_);
  51. switch ($op) {
  52. case "save":
  53. /*
  54. $client = new \GuzzleHttp\Client();
  55. $parm = ['form_params'=>['op'=>$op,
  56. 'id'=>$_id,
  57. 'block_id'=>$_block_id,
  58. 'parent_id'=>$_parent_id,
  59. 'uid'=>$UID,
  60. 'book'=>$_book,
  61. 'paragraph'=>$_para,
  62. 'begin'=>$_begin,
  63. 'end'=>$_end,
  64. 'style'=>$_style,
  65. 'text'=>$_text,
  66. 'stage'=>$_stage,
  67. 'author'=>$_author,
  68. 'lang'=>$_lang
  69. ]];
  70. $response = $client->request('POST', 'http://10.10.1.100/wikipalipro/app/studio/sent/sent.php',$parm);
  71. $status = $response->getStatusCode();
  72. $head_type = $response->getHeaderLine('content-type');
  73. //echo $response->getBody();
  74. */
  75. if ($_id == 0) {
  76. $query = "select * from sentence where
  77. book='{$_book}' and
  78. paragraph='{$_para}' and
  79. begin='{$_begin}' and
  80. end='{$_end}' and
  81. tag='{$_style}' and
  82. author='{$_author}' and
  83. editor='{$UID}' and
  84. language='{$_lang}'
  85. ";
  86. $Fetch = PDO_FetchAll($query);
  87. $iFetch = count($Fetch);
  88. if ($iFetch > 0) {
  89. $_id = $Fetch[0]["id"];
  90. $_block_id = $Fetch[0]["block_id"];
  91. }
  92. }
  93. $recodeId = $_id;
  94. $time = mTime();
  95. if ($_id != 0) { //修改旧记录
  96. $query = "UPDATE sentence SET text='$_text' ,
  97. receive_time='{$time}'
  98. where id=" . $PDO->quote($_id);
  99. } else { //新建记录
  100. $uuid = UUID::v4();
  101. $query = "INSERT INTO sentence VALUES ('{$uuid}',
  102. '$_block_id',
  103. '$_book',
  104. '$_para',
  105. '$_begin',
  106. '$_end',
  107. '$_tag',
  108. '$_author',
  109. '$UID',
  110. '$_text',
  111. '$_lang',
  112. '1',
  113. '1',
  114. '$time',
  115. '$time')";
  116. }
  117. $stmt = @PDO_Execute($query);
  118. $respond = array("status" => 0, "message" => "");
  119. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  120. $error = PDO_ErrorInfo();
  121. $respond['status'] = 1;
  122. $respond['error'] = $error[2];
  123. } else {
  124. $respond['status'] = 0;
  125. $respond['error'] = "";
  126. if ($recodeId == 0) {
  127. $respond['id'] = $uuid;
  128. } else {
  129. $respond['id'] = $recodeId;
  130. }
  131. $respond['block_id'] = $_block_id;
  132. $respond['begin'] = $_begin;
  133. $respond['end'] = $_end;
  134. }
  135. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  136. break;
  137. }