sent_post.php 6.8 KB

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