sent_post.php 8.5 KB

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