sent_post.php 8.7 KB

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