2
0

message.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. require_once "../path.php";
  3. include "../public/_pdo.php";
  4. if (isset($_POST["op"])) {
  5. $op = $_POST["op"];
  6. } else {
  7. echo "no op type";
  8. exit;
  9. }
  10. if (isset($_POST["lastid"])) {
  11. $lastid = $_POST["lastid"];
  12. } else {
  13. echo "no lastid ";
  14. exit;
  15. }
  16. if (isset($_POST["doclist"])) {
  17. $doclist = $_POST["doclist"];
  18. } else {
  19. echo "no doclist id";
  20. exit;
  21. }
  22. if (isset($_POST["data"])) {
  23. $data = $_POST["data"];
  24. } else {
  25. echo "no data";
  26. exit;
  27. }
  28. if (isset($_POST["book"])) {
  29. $book = $_POST["book"];
  30. } else {
  31. $book = 0;
  32. }
  33. if (isset($_POST["paragraph"])) {
  34. $para = $_POST["paragraph"];
  35. } else {
  36. $para = 0;
  37. }
  38. if (isset($_COOKIE["username"]) && !empty($_COOKIE["username"])) {
  39. $uid = $_COOKIE["uid"];
  40. $username = $_COOKIE["username"];
  41. } else {
  42. echo "not login";
  43. exit;
  44. }
  45. //消息轉入user文件夾,方便升級
  46. PDO_Connect(_FILE_DB_MESSAGE_);
  47. if ($op == "send") {
  48. // 开始一个事务,关闭自动提交
  49. $PDO->beginTransaction();
  50. $query = "INSERT INTO message ('id',
  51. 'sender',
  52. 'type',
  53. 'book',
  54. 'paragraph',
  55. 'data',
  56. 'doc_id',
  57. 'time')
  58. VALUES (NULL,'{$username}',?,?,?,?,?,?)";
  59. $stmt = $PDO->prepare($query);
  60. $arrMsgData = json_decode($data);
  61. foreach ($arrMsgData as $oneMsg) {
  62. $newData = array($oneMsg->type, $oneMsg->book, $oneMsg->para, $oneMsg->data, $oneMsg->docid, time());
  63. $stmt->execute($newData);
  64. }
  65. // 提交更改
  66. $PDO->commit();
  67. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  68. $error = PDO_ErrorInfo();
  69. echo "error - $error[2] <br>";
  70. } else {
  71. }
  72. }
  73. $query = "select id from message where 1 order by id DESC limit 0,1";
  74. $maxId = PDO_FetchOne($query);
  75. //查询相关文档的消息
  76. echo "<message>";
  77. echo "<msg><type>maxid</type><data>$maxId</data></msg>";
  78. $query = "select * from message where \"doc_id\" = '$doclist' AND \"id\" > {$lastid} limit 0,10000";
  79. $Fetch = PDO_FetchAll($query);
  80. $iFetch = count($Fetch);
  81. if ($iFetch > 0) {
  82. for ($i = 0; $i < $iFetch; $i++) {
  83. echo "<msg>";
  84. echo "<id>" . $Fetch[$i]["id"] . "</id>";
  85. echo "<sender>" . $Fetch[$i]["sender"] . "</sender>";
  86. echo "<type>" . $Fetch[$i]["type"] . "</type>";
  87. echo "<data>" . $Fetch[$i]["data"] . "</data>";
  88. echo "<docid>" . $Fetch[$i]["doc_id"] . "</docid>";
  89. echo "<time>" . $Fetch[$i]["time"] . "</time>";
  90. echo "<read>0</read>";
  91. echo "</msg>";
  92. }
  93. }
  94. echo "</message>";