sent_post.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. $respond['book']=$_POST["book"];
  8. $respond['para']=$_POST["para"];
  9. $respond['begin']=$_POST["begin"];
  10. $respond['end']=$_POST["end"];
  11. $respond['channal']=$_POST["channal"];
  12. $respond['text']=$_POST["text"];
  13. #检查是否登陆
  14. if(!isset($_COOKIE["userid"])){
  15. $respond["status"] = 1;
  16. $respond["message"] = 'not login';
  17. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  18. exit;
  19. }
  20. #先查询对此channal是否有权限修改
  21. $cooperation = 0;
  22. if(isset($_POST["channal"])){
  23. PDO_Connect("sqlite:"._FILE_DB_CHANNAL_);
  24. $query = "SELECT owner FROM channal WHERE id=?";
  25. $fetch = PDO_FetchOne($query,array($_POST["channal"]));
  26. if($fetch && $fetch==$_COOKIE["userid"]){
  27. #自己的channal
  28. $cooperation = 1;
  29. }
  30. else{
  31. $query = "SELECT count(*) FROM cooperation WHERE channal_id= ? and user_id=? ";
  32. $fetch = PDO_FetchOne($query,array($_POST["channal"],$_COOKIE["userid"]));
  33. if($fetch>0){
  34. #有协作权限
  35. $cooperation = 1;
  36. }
  37. else{
  38. #无协作权限
  39. $cooperation = 0;
  40. }
  41. }
  42. }
  43. else{
  44. $respond["status"] = 1;
  45. $respond["message"] = 'error channal id';
  46. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  47. exit;
  48. }
  49. PDO_Connect("sqlite:"._FILE_DB_SENTENCE_);
  50. if(isset($_POST["id"])){
  51. if(empty($_POST["id"])){
  52. #没有id新建
  53. if($cooperation == 1){
  54. #有权限
  55. $query = "INSERT INTO sentence (id,
  56. parent,
  57. book,
  58. paragraph,
  59. begin,
  60. end,
  61. channal,
  62. tag,
  63. author,
  64. editor,
  65. text,
  66. language,
  67. ver,
  68. status,
  69. strlen,
  70. modify_time,
  71. receive_time,
  72. create_time
  73. )
  74. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  75. $stmt = $PDO->prepare($query);
  76. $stmt->execute(array(UUID::v4(),
  77. "",
  78. $_POST["book"],
  79. $_POST["para"],
  80. $_POST["begin"],
  81. $_POST["end"],
  82. $_POST["channal"],
  83. "",
  84. "[]",
  85. $_COOKIE["userid"],
  86. $_POST["text"],
  87. $_POST["lang"],
  88. 1,
  89. 7,
  90. mb_strlen($_POST["text"],"UTF-8"),
  91. mTime(),
  92. mTime(),
  93. mTime()
  94. ));
  95. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  96. /* 识别错误 */
  97. $error = PDO_ErrorInfo();
  98. $respond['message']=$error[2];
  99. $respond['status']=1;
  100. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  101. exit;
  102. }
  103. else{
  104. $respond['data']=array();
  105. }
  106. }
  107. else{
  108. #没权限
  109. $respond['message']="没有权限";
  110. $respond['status']=1;
  111. }
  112. }
  113. else{
  114. /* 修改现有数据 */
  115. #判断是否有修改权限
  116. if($cooperation == 1){
  117. #有权限
  118. $query="UPDATE sentence SET text= ? , strlen = ? , editor = ? , receive_time= ? , modify_time= ? where id= ? ";
  119. $stmt = PDO_Execute($query,
  120. array($_POST["text"],
  121. mb_strlen($_POST["text"],"UTF-8"),
  122. $_COOKIE["userid"] ,
  123. mTime(),
  124. mTime(),
  125. $_POST["id"]));
  126. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  127. /* 识别错误 */
  128. $error = PDO_ErrorInfo();
  129. $respond['message']=$error[2];
  130. $respond['status']=1;
  131. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  132. exit;
  133. }
  134. else{
  135. #没错误
  136. }
  137. }
  138. else{
  139. #没权限 建议
  140. $respond['message']="没有权限";
  141. $respond['status']=1;
  142. }
  143. }
  144. }
  145. else{
  146. # error
  147. }
  148. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  149. ?>