get_res_json.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /*
  3. 获取某书的资源列表
  4. 输入:book id
  5. album id
  6. paragraph
  7. 输出:资源列表的json数据
  8. */
  9. require_once "../studio/checklogin.inc";
  10. require_once "../config.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 > 0) {
  42. //查书中的一个段
  43. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  44. $query = "SELECT * from \""._TABLE_RES_INDEX_."\" where book='{$book}' and paragraph='{$paragraph}' and type < '5' ";
  45. $Fetch = PDO_FetchAll($query);
  46. $iFetch = count($Fetch);
  47. if ($iFetch > 0) {
  48. //可用资源
  49. foreach ($Fetch as $one_album) {
  50. array_push($res, array("book" => $book,
  51. "album_id" => $one_album["album"],
  52. "paragraph" => $paragraph,
  53. "type" => $one_album["type"],
  54. "title" => $one_album["title"],
  55. "author" => $one_album["author"],
  56. "editor" => $one_album["editor"],
  57. "edition" => $one_album["edition"],
  58. "language" => $one_album["language"],
  59. "level" => $one_album["level"],
  60. ));
  61. if ($one_album["type"] == 1) {
  62. array_push($res, array("book" => $book,
  63. "album_id" => UUID(),
  64. "paragraph" => $paragraph,
  65. "type" => 6,
  66. "title" => $one_album["title"],
  67. "author" => $one_album["author"],
  68. "editor" => $one_album["editor"],
  69. "edition" => $one_album["edition"],
  70. "language" => $one_album["language"],
  71. "level" => $one_album["level"],
  72. ));
  73. }
  74. }
  75. }
  76. //查共享文档
  77. PDO_Connect(_FILE_DB_FILEINDEX_);
  78. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status>0 and share>0 order by create_time";
  79. $Fetch = PDO_FetchAll($query);
  80. $iFetch = count($Fetch);
  81. if ($iFetch > 0) {
  82. foreach ($Fetch as $one_file) {
  83. array_push($res, array("type" => "share",
  84. "id" => $one_file["id"],
  85. "title" => $one_file["title"],
  86. "author" => $one_file["user_id"],
  87. ));
  88. }
  89. }
  90. //查我的文档
  91. if ($UID != "") {
  92. $query = "select * from fileindex where book='$book' and paragraph=$paragraph and status!=0 and user_id='{$UID}' order by create_time DESC";
  93. $Fetch = PDO_FetchAll($query);
  94. $iFetch = count($Fetch);
  95. if ($iFetch > 0) {
  96. foreach ($Fetch as $one_file) {
  97. array_push($res, array("type" => "mydoc",
  98. "id" => $one_file["id"],
  99. "title" => $one_file["title"],
  100. "file_name" => $one_file["file_name"],
  101. "author" => $one_file["user_id"],
  102. ));
  103. }
  104. }
  105. }
  106. }
  107. echo json_encode($res, JSON_UNESCAPED_UNICODE);