sent.php 3.2 KB

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