sent_post.php 8.5 KB

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