sent_post.php 8.5 KB

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