get_res_json.php 3.8 KB

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