sent_post.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. #更新一个句子
  3. include("../log/pref_log.php");
  4. require_once "../config.php";
  5. require_once "../public/_pdo.php";
  6. require_once "../public/function.php";
  7. require_once "../usent/function.php";
  8. require_once "../ucenter/active.php";
  9. require_once "../share/function.php";
  10. #检查是否登陆
  11. if (!isset($_COOKIE["userid"])) {
  12. $respond["status"] = 1;
  13. $respond["message"] = 'not login';
  14. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  15. exit;
  16. }
  17. if (isset($_POST["landmark"])) {
  18. $_landmark = $_POST["landmark"];
  19. } else {
  20. $_landmark = "";
  21. }
  22. //回传数据
  23. $respond = array("status" => 0, "message" => "");
  24. $respond['id'] = $_POST["id"];
  25. $respond['book'] = $_POST["book"];
  26. $respond['para'] = $_POST["para"];
  27. $respond['begin'] = $_POST["begin"];
  28. $respond['end'] = $_POST["end"];
  29. $respond['channal'] = $_POST["channal"];
  30. $respond['text'] = $_POST["text"];
  31. $respond['editor'] = $_COOKIE["userid"];
  32. $respond['commit_type'] = 0; #0 未提交 1 插入 2 修改 3pr
  33. add_edit_event(_SENT_EDIT_, "{$_POST["book"]}-{$_POST["para"]}-{$_POST["begin"]}-{$_POST["end"]}@{$_POST["channal"]}");
  34. #先查询对此channal是否有权限修改
  35. $cooperation = 0;
  36. $text_lang = "en";
  37. $channel_status = 0;
  38. if (isset($_POST["channal"])) {
  39. PDO_Connect( _FILE_DB_CHANNAL_,_DB_USERNAME_,_DB_PASSWORD_);
  40. $query = "SELECT owner_uid, lang , status FROM "._TABLE_CHANNEL_." WHERE uid=?";
  41. $fetch = PDO_FetchRow($query, array($_POST["channal"]));
  42. if ($fetch) {
  43. $text_lang = $fetch["lang"];
  44. $channel_status = $fetch["status"];
  45. }
  46. $respond['lang'] = $text_lang;
  47. if ($fetch && $fetch["owner_uid"] == $_COOKIE["user_uid"]) {
  48. #自己的channal
  49. $cooperation = 30;
  50. } else {
  51. $sharePower = share_get_res_power($_COOKIE["user_uid"],$_POST["channal"]);
  52. $cooperation = $sharePower;
  53. if($channel_status>=30 && $cooperation<10){
  54. #全网公开的 可以提交pr
  55. $cooperation = 10;
  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. if($cooperation==0){
  65. $respond['message'] = "no power";
  66. $respond['status'] = 1;
  67. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  68. exit;
  69. }
  70. PDO_Connect(_FILE_DB_SENTENCE_,_DB_USERNAME_,_DB_PASSWORD_);
  71. $_id = false;
  72. if ((isset($_POST["id"]) && empty($_POST["id"])) || !isset($_POST["id"])) {
  73. # 判断是否已经有了
  74. $query = "SELECT uid FROM "._TABLE_SENTENCE_." WHERE book_id = ? AND paragraph = ? AND word_start = ? AND word_end = ? AND channel_uid = ? ";
  75. $_id = PDO_FetchOne($query, array($_POST["book"], $_POST["para"], $_POST["begin"], $_POST["end"], $_POST["channal"]));
  76. } else {
  77. $_id = $_POST["id"];
  78. }
  79. if ($_id == false) {
  80. # 没有id新建
  81. if ($cooperation >=20) {
  82. #有写入权限
  83. $query = "INSERT INTO "._TABLE_SENTENCE_." (uid,
  84. parent_uid,
  85. book_id,
  86. paragraph,
  87. word_start,
  88. word_end,
  89. channel_uid,
  90. author,
  91. editor_uid,
  92. content,
  93. language,
  94. status,
  95. strlen,
  96. modify_time,
  97. create_time
  98. )
  99. VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  100. $stmt = $PDO->prepare($query);
  101. $newId = UUID::v4();
  102. $stmt->execute(array($newId,
  103. "",
  104. $_POST["book"],
  105. $_POST["para"],
  106. $_POST["begin"],
  107. $_POST["end"],
  108. $_POST["channal"],
  109. "",
  110. $_COOKIE["userid"],
  111. $_POST["text"],
  112. $text_lang,
  113. $channel_status,
  114. mb_strlen($_POST["text"], "UTF-8"),
  115. mTime(),
  116. mTime(),
  117. ));
  118. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  119. /* 识别错误 */
  120. $error = PDO_ErrorInfo();
  121. $respond['message'] = $error[2];
  122. $respond['status'] = 1;
  123. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  124. exit;
  125. } else {
  126. # 没错误
  127. # 更新historay
  128. #没错误 更新历史记录
  129. $respond['commit_type'] = 1;
  130. $respond['message'] = update_historay($newId, $_COOKIE["userid"], $_POST["text"], $_landmark);
  131. if ($respond['message'] !== "") {
  132. $respond['status'] = 1;
  133. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  134. exit;
  135. }
  136. }
  137. } else {
  138. #没写入权限 插入pr数据
  139. $query = "INSERT INTO "._TABLE_SENTENCE_PR_." (
  140. book_id,
  141. paragraph,
  142. word_start,
  143. word_end,
  144. channel_uid,
  145. author,
  146. editor_uid,
  147. content,
  148. language,
  149. status,
  150. strlen,
  151. modify_time,
  152. create_time
  153. )
  154. VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  155. $stmt = $PDO->prepare($query);
  156. # 初始状态 1 未处理
  157. $stmt->execute(array(
  158. $_POST["book"],
  159. $_POST["para"],
  160. $_POST["begin"],
  161. $_POST["end"],
  162. $_POST["channal"],
  163. "",
  164. $_COOKIE["userid"],
  165. $_POST["text"],
  166. $text_lang,
  167. 1,
  168. mb_strlen($_POST["text"], "UTF-8"),
  169. mTime(),
  170. mTime()
  171. ));
  172. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  173. /* 识别错误 */
  174. $error = PDO_ErrorInfo();
  175. $respond['message'] = $error[2];
  176. $respond['status'] = 1;
  177. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  178. exit;
  179. } else {
  180. # 没错误
  181. $respond['message'] = "已经提交修改建议";
  182. $respond['status'] = 0;
  183. $respond['commit_type'] = 3;
  184. }
  185. }
  186. } else {
  187. /* 修改现有数据 */
  188. #判断是否有修改权限
  189. if ($cooperation >=20) {
  190. #有写入权限
  191. $query = "UPDATE "._TABLE_SENTENCE_." SET content= ? , strlen = ? , editor_uid = ? , modify_time= ? where uid= ? ";
  192. $stmt = PDO_Execute($query,
  193. array($_POST["text"],
  194. mb_strlen($_POST["text"], "UTF-8"),
  195. $_COOKIE["userid"],
  196. mTime(),
  197. $_id));
  198. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  199. /* 识别错误 */
  200. $error = PDO_ErrorInfo();
  201. $respond['message'] = $error[2];
  202. $respond['status'] = 1;
  203. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  204. exit;
  205. } else {
  206. #没错误 更新历史记录
  207. $respond['commit_type'] = 2;
  208. $respond['message'] = update_historay($_id, $_COOKIE["userid"], $_POST["text"], $_landmark);
  209. if ($respond['message'] !== "") {
  210. $respond['status'] = 1;
  211. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  212. exit;
  213. }
  214. }
  215. } else {
  216. #TO DO没权限 插入pr数据
  217. #没写入权限 插入pr数据
  218. $query = "INSERT INTO "._TABLE_SENTENCE_PR_." (
  219. book_id,
  220. paragraph,
  221. word_start,
  222. word_end,
  223. channel_uid,
  224. author,
  225. editor_uid,
  226. content,
  227. language,
  228. status,
  229. strlen,
  230. modify_time,
  231. create_time
  232. )
  233. VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
  234. $stmt = $PDO->prepare($query);
  235. # 初始状态 1 未处理
  236. $stmt->execute(array(
  237. $_POST["book"],
  238. $_POST["para"],
  239. $_POST["begin"],
  240. $_POST["end"],
  241. $_POST["channal"],
  242. "",
  243. $_COOKIE["userid"],
  244. $_POST["text"],
  245. $text_lang,
  246. 1,
  247. mb_strlen($_POST["text"], "UTF-8"),
  248. mTime(),
  249. mTime()
  250. ));
  251. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  252. /* 识别错误 */
  253. $error = PDO_ErrorInfo();
  254. $respond['message'] = $error[2];
  255. $respond['status'] = 1;
  256. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  257. exit;
  258. } else {
  259. # 没错误
  260. $respond['commit_type'] = 3;
  261. $respond['message'] = "已经提交修改建议";
  262. $respond['status'] = 0;
  263. }
  264. }
  265. }
  266. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  267. PrefLog();