sent_post.php 8.6 KB

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