get_res_json.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. 获取某书的资源列表
  4. 输入:book id
  5. album id
  6. paragraph
  7. 输出:资源列表的json数据
  8. */
  9. require_once "../studio/checklogin.inc";
  10. require_once "../path.php";
  11. require_once "../public/_pdo.php";
  12. require_once "../studio/public.inc";
  13. if (isset($_GET["book"])) {
  14. $book = $_GET["book"];
  15. } else {
  16. echo "no book id";
  17. exit;
  18. }
  19. if (substr($book, 0, 1) == 'p') {
  20. $book = substr($book, 1);
  21. }
  22. if (isset($_GET["paragraph"])) {
  23. $paragraph = $_GET["paragraph"];
  24. } else {
  25. $paragraph = -1;
  26. }
  27. function format_file_size($size)
  28. {
  29. if ($size < 102) {
  30. $str_size = $size . "B";
  31. } else if ($size < (1024 * 102)) {
  32. $str_size = sprintf("%.1f KB", $size / 1024);
  33. } else {
  34. $str_size = sprintf("%.1f MB", $size / (1024 * 1024));
  35. }
  36. return ($str_size);
  37. }
  38. $db_file = _FILE_DB_RESRES_INDEX_;
  39. PDO_Connect("$db_file");
  40. $res = array();
  41. //查书
  42. if ($paragraph == -1) {
  43. //相关专辑
  44. $query = "select * from album where album.book='$book' ";
  45. $Fetch_ather = PDO_FetchAll($query);
  46. $iFetchAther = count($Fetch_ather);
  47. if ($iFetchAther > 0) {
  48. foreach ($Fetch_ather as $one_album) {
  49. array_push($res, array("book" => $book,
  50. "album_id" => $one_album["id"],
  51. "paragraph" => -1,
  52. "type" => $one_album["type"],
  53. "title" => $one_album["title"],
  54. "author" => $one_album["author"],
  55. ));
  56. if ($one_album["type"] == 1) {
  57. array_push($res, array("book" => $book,
  58. "album_id" => $one_album["id"],
  59. "paragraph" => -1,
  60. "type" => 6,
  61. "title" => $one_album["title"],
  62. "author" => $one_album["author"],
  63. ));
  64. }
  65. }
  66. }
  67. //相关专辑结束
  68. } else {
  69. //查书中的一个段
  70. $db_file = _FILE_DB_RESRES_INDEX_;
  71. PDO_Connect("$db_file");
  72. $query = "select * from 'index' where book='{$book}' and paragraph='{$paragraph}' and type < '5' ";
  73. $Fetch = PDO_FetchAll($query);
  74. $iFetch = count($Fetch);
  75. if ($iFetch > 0) {
  76. //可用资源
  77. foreach ($Fetch as $one_album) {
  78. array_push($res, array("book" => $book,
  79. "album_id" => $one_album["album"],
  80. "paragraph" => $paragraph,
  81. "type" => $one_album["type"],
  82. "title" => $one_album["title"],
  83. "author" => $one_album["author"],
  84. "editor" => $one_album["editor"],
  85. "edition" => $one_album["edition"],
  86. "language" => $one_album["language"],
  87. "level" => $one_album["level"],
  88. ));
  89. if ($one_album["type"] == 1) {
  90. array_push($res, array("book" => $book,
  91. "album_id" => UUID(),
  92. "paragraph" => $paragraph,
  93. "type" => 6,
  94. "title" => $one_album["title"],
  95. "author" => $one_album["author"],
  96. "editor" => $one_album["editor"],
  97. "edition" => $one_album["edition"],
  98. "language" => $one_album["language"],
  99. "level" => $one_album["level"],
  100. ));
  101. }
  102. }
  103. }
  104. //查共享文档
  105. $db_file = _FILE_DB_FILEINDEX_;
  106. PDO_Connect("$db_file");
  107. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status>0 and share>0 order by create_time";
  108. $Fetch = PDO_FetchAll($query);
  109. $iFetch = count($Fetch);
  110. if ($iFetch > 0) {
  111. foreach ($Fetch as $one_file) {
  112. array_push($res, array("type" => "share",
  113. "id" => $one_file["id"],
  114. "title" => $one_file["title"],
  115. "author" => $one_file["user_id"],
  116. ));
  117. }
  118. }
  119. //查我的文档
  120. if ($UID != "") {
  121. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
  122. $Fetch = PDO_FetchAll($query);
  123. $iFetch = count($Fetch);
  124. if ($iFetch > 0) {
  125. foreach ($Fetch as $one_file) {
  126. array_push($res, array("type" => "mydoc",
  127. "id" => $one_file["id"],
  128. "title" => $one_file["title"],
  129. "file_name" => $one_file["file_name"],
  130. "author" => $one_file["user_id"],
  131. ));
  132. }
  133. }
  134. }
  135. }
  136. echo json_encode($res, JSON_UNESCAPED_UNICODE);