sent_post.php 8.3 KB

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