2
0

message.php 2.3 KB

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