sent_post.php 4.6 KB

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