get_res_json.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  39. $res = array();
  40. //查书
  41. if ($paragraph == -1) {
  42. //相关专辑
  43. $query = "select * from album where album.book='$book' ";
  44. $Fetch_ather = PDO_FetchAll($query);
  45. $iFetchAther = count($Fetch_ather);
  46. if ($iFetchAther > 0) {
  47. foreach ($Fetch_ather as $one_album) {
  48. array_push($res, array("book" => $book,
  49. "album_id" => $one_album["id"],
  50. "paragraph" => -1,
  51. "type" => $one_album["type"],
  52. "title" => $one_album["title"],
  53. "author" => $one_album["author"],
  54. ));
  55. if ($one_album["type"] == 1) {
  56. array_push($res, array("book" => $book,
  57. "album_id" => $one_album["id"],
  58. "paragraph" => -1,
  59. "type" => 6,
  60. "title" => $one_album["title"],
  61. "author" => $one_album["author"],
  62. ));
  63. }
  64. }
  65. }
  66. //相关专辑结束
  67. } else {
  68. //查书中的一个段
  69. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  70. $query = "select * from 'index' where book='{$book}' and paragraph='{$paragraph}' and type < '5' ";
  71. $Fetch = PDO_FetchAll($query);
  72. $iFetch = count($Fetch);
  73. if ($iFetch > 0) {
  74. //可用资源
  75. foreach ($Fetch as $one_album) {
  76. array_push($res, array("book" => $book,
  77. "album_id" => $one_album["album"],
  78. "paragraph" => $paragraph,
  79. "type" => $one_album["type"],
  80. "title" => $one_album["title"],
  81. "author" => $one_album["author"],
  82. "editor" => $one_album["editor"],
  83. "edition" => $one_album["edition"],
  84. "language" => $one_album["language"],
  85. "level" => $one_album["level"],
  86. ));
  87. if ($one_album["type"] == 1) {
  88. array_push($res, array("book" => $book,
  89. "album_id" => UUID(),
  90. "paragraph" => $paragraph,
  91. "type" => 6,
  92. "title" => $one_album["title"],
  93. "author" => $one_album["author"],
  94. "editor" => $one_album["editor"],
  95. "edition" => $one_album["edition"],
  96. "language" => $one_album["language"],
  97. "level" => $one_album["level"],
  98. ));
  99. }
  100. }
  101. }
  102. //查共享文档
  103. PDO_Connect(_FILE_DB_FILEINDEX_);
  104. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status>0 and share>0 order by create_time";
  105. $Fetch = PDO_FetchAll($query);
  106. $iFetch = count($Fetch);
  107. if ($iFetch > 0) {
  108. foreach ($Fetch as $one_file) {
  109. array_push($res, array("type" => "share",
  110. "id" => $one_file["id"],
  111. "title" => $one_file["title"],
  112. "author" => $one_file["user_id"],
  113. ));
  114. }
  115. }
  116. //查我的文档
  117. if ($UID != "") {
  118. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
  119. $Fetch = PDO_FetchAll($query);
  120. $iFetch = count($Fetch);
  121. if ($iFetch > 0) {
  122. foreach ($Fetch as $one_file) {
  123. array_push($res, array("type" => "mydoc",
  124. "id" => $one_file["id"],
  125. "title" => $one_file["title"],
  126. "file_name" => $one_file["file_name"],
  127. "author" => $one_file["user_id"],
  128. ));
  129. }
  130. }
  131. }
  132. }
  133. echo json_encode($res, JSON_UNESCAPED_UNICODE);