2
0

term_post.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. 修改术语
  4. */
  5. require_once "../path.php";
  6. require_once "../public/_pdo.php";
  7. require_once '../public/function.php';
  8. require_once "../redis/function.php";
  9. $redis = redis_connect();
  10. #未登录不能修改
  11. if (isset($_COOKIE["userid"]) == false) {
  12. $respond['status'] = 1;
  13. $respond['message'] = "not yet log in";
  14. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  15. exit;
  16. }
  17. $respond = array("status" => 0, "message" => "");
  18. PDO_Connect("" . _FILE_DB_TERM_);
  19. if ($_POST["id"] != "") {
  20. #更新
  21. #先查询是否有权限
  22. $query = "SELECT id from term where guid= ? and owner = ? ";
  23. $stmt = $PDO->prepare($query);
  24. $stmt->execute(array($_POST["id"],$_COOKIE["userid"]));
  25. if ($stmt) {
  26. $Fetch = $stmt->fetch(PDO::FETCH_ASSOC);
  27. if(!$Fetch){
  28. $respond['status'] = 1;
  29. $respond['message'] = "no power";
  30. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  31. exit;
  32. }
  33. }
  34. $query = "UPDATE term SET meaning= ? ,other_meaning = ? , tag= ? ,channal = ? , language = ? , note = ? , receive_time= ?, modify_time= ? where guid= ? and owner = ? ";
  35. $stmt = @PDO_Execute($query,
  36. array($_POST["mean"],
  37. $_POST["mean2"],
  38. $_POST["tag"],
  39. $_POST["channal"],
  40. $_POST["language"],
  41. $_POST["note"],
  42. mTime(),
  43. mTime(),
  44. $_POST["id"],
  45. $_COOKIE["userid"],
  46. ));
  47. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  48. $error = PDO_ErrorInfo();
  49. $respond['status'] = 1;
  50. $respond['message'] = $error[2] . $query;
  51. } else {
  52. $respond['status'] = 0;
  53. $respond['message'] = $_POST["word"];
  54. }
  55. } else {
  56. #新建
  57. if(trim($_POST["word"])==""){
  58. $respond['status'] = 1;
  59. $respond['message'] = "pali word cannot be empty";
  60. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  61. exit;
  62. }
  63. if(trim($_POST["mean"])==""){
  64. $respond['status'] = 1;
  65. $respond['message'] = "meaning cannot be empty";
  66. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  67. exit;
  68. }
  69. if(trim($_POST["language"])==""){
  70. $respond['status'] = 1;
  71. $respond['message'] = "language cannot be empty";
  72. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  73. exit;
  74. }
  75. $parm[] = UUID::v4();
  76. $parm[] = $_POST["word"];
  77. $parm[] = pali2english($_POST["word"]);
  78. $parm[] = $_POST["mean"];
  79. $parm[] = $_POST["mean2"];
  80. $parm[] = $_POST["tag"];
  81. $parm[] = $_POST["channal"];
  82. $parm[] = $_POST["language"];
  83. $parm[] = $_POST["note"];
  84. $parm[] = $_COOKIE["userid"];
  85. $parm[] = 0;
  86. $parm[] = mTime();
  87. $parm[] = mTime();
  88. $parm[] = mTime();
  89. $query = "INSERT INTO term (id, guid, word, word_en, meaning, other_meaning, tag, channal, language,note,owner,hit,create_time,modify_time,receive_time )
  90. VALUES (NULL, ? , ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
  91. $stmt = @PDO_Execute($query, $parm);
  92. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  93. $error = PDO_ErrorInfo();
  94. $respond['status'] = 1;
  95. $respond['message'] = $error[2] . $query;
  96. } else {
  97. $respond['status'] = 0;
  98. $respond['message'] = $_POST["word"];
  99. }
  100. }
  101. #更新 redis
  102. if ($redis != false) {
  103. {
  104. # code...
  105. $query = "SELECT id,word,meaning,other_meaning,note,owner,language from term where word = ? ";
  106. $stmt = $PDO->prepare($query);
  107. $stmt->execute(array($_POST["word"]));
  108. if ($stmt) {
  109. $Fetch = $stmt->fetchAll(PDO::FETCH_ASSOC);
  110. $redisWord=array();
  111. foreach ($Fetch as $one) {
  112. # code...
  113. $redisWord[] = array($one["id"],
  114. $one["word"],
  115. "",
  116. "",
  117. "",
  118. $one["meaning"]."$".$one["other_meaning"],
  119. $one["note"],
  120. "",
  121. "",
  122. 1,
  123. 100,
  124. $one["owner"],
  125. "term",
  126. $one["language"]
  127. );
  128. }
  129. $redis->hSet("dict://term",$_POST["word"],json_encode($redisWord,JSON_UNESCAPED_UNICODE));
  130. }
  131. }
  132. }
  133. #更新redis结束
  134. echo json_encode($respond, JSON_UNESCAPED_UNICODE);