2
0

search.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. require_once "../public/config.php";
  3. require_once "../public/_pdo.php";
  4. require_once "../public/function.php";
  5. if (isset($_GET["op"])) {
  6. $op = $_GET["op"];
  7. } else {
  8. echo "no op";
  9. exit;
  10. }
  11. if (isset($_GET["word"])) {
  12. $word = $_GET["word"];
  13. } else {
  14. echo "no word";
  15. exit;
  16. }
  17. _load_book_index();
  18. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  19. switch ($op) {
  20. case "pre":
  21. //查作者
  22. $query = "select count(*) from 'author' where name like '%$word%'";
  23. $count = PDO_FetchOne($query);
  24. if ($count > 0) {
  25. $query = "select * from 'author' where name like '%$word%' limit 0,5";
  26. $Fetch = PDO_FetchAll($query);
  27. $iFetch = count($Fetch);
  28. if ($iFetch > 0) {
  29. echo "<div class='search_list_div'><div class='search_type'>作者($count)</div></div>";
  30. for ($i = 0; $i < $iFetch; $i++) {
  31. echo "<div class='search_list_div' onclick=\"pre_search('author','" . $Fetch[$i]["name"] . "')\"><div class='search_item'>" . $Fetch[$i]["name"] . "</div></div>";
  32. }
  33. }
  34. }
  35. //查标题
  36. $query = "select count(*) from \""._TABLE_RES_INDEX_."\" where title_en like '%$word%' or title like '%$word%'";
  37. $count = PDO_FetchOne($query);
  38. $query = "select * from \""._TABLE_RES_INDEX_."\" where title_en like '%$word%' or title like '%$word%' limit 0,20";
  39. $Fetch = PDO_FetchAll($query);
  40. $iFetch = count($Fetch);
  41. if ($iFetch > 0) {
  42. PDO_Connect(_FILE_DB_PALITEXT_);
  43. $arrBookType = json_decode(file_get_contents("../public/book_name/booktype.json"));
  44. echo "<div class='search_list_div'><div class='search_type'>标题({$count})</div></div>";
  45. for ($i = 0; $i < $iFetch; $i++) {
  46. $book = $Fetch[$i]["book"];
  47. if (substr($book, 0, 1) == 'p') {
  48. $book = substr($book, 1);
  49. }
  50. $book--;
  51. $open_link = "onclick='index_render_res_list(" . $Fetch[$i]["book"] . "," . $Fetch[$i]["album"] . "," . $Fetch[$i]["paragraph"] . ")'";
  52. $bookid = $Fetch[$i]["book"];
  53. $t1 = $arrBookType[$bookid - 1]->c1;
  54. $t2 = $arrBookType[$bookid - 1]->c2;
  55. $t3 = $arrBookType[$bookid - 1]->c3;
  56. $bookInfo = _get_book_info($bookid);
  57. $bookname = $bookInfo->title;
  58. echo "<div class='search_list_div'>";
  59. echo "<div class='search_item' $open_link><b>{$Fetch[$i]["title"]}</b>";
  60. echo "<br><span class='media_type'>{$t1}</span>";
  61. //echo "<span class='media_type'>{$t2}</span> <span class='media_type'>{$t3}</span>";
  62. $path = "";
  63. $parent = $Fetch[$i]["paragraph"];
  64. $deep = 0;
  65. $sFirstParentTitle = "";
  66. //循环查找父标题 得到整条路径
  67. while ($parent > -1) {
  68. $query = "SELECT * FROM "._TABLE_PALI_TEXT_." where book = ? and paragraph = ? limit 1";
  69. $FetParent = PDO_FetchAll($query,array($bookid,$parent));
  70. if ($deep > 0) {
  71. $path = "{$FetParent[0]["toc"]}>{$path}";
  72. }
  73. if ($sFirstParentTitle == "") {
  74. $sFirstParentTitle = $FetParent[0]["toc"];
  75. }
  76. $parent = $FetParent[0]["parent"];
  77. $deep++;
  78. if ($deep > 5) {
  79. break;
  80. }
  81. }
  82. if (strlen($path) > 0) {
  83. $path = substr($path, 0, -1);
  84. }
  85. echo "<i>{$bookname}</i> > {$path}";
  86. echo "</div>";
  87. echo "</div>";
  88. }
  89. }
  90. PDO_Connect(_FILE_DB_RESRES_INDEX_);
  91. //查标签
  92. $query = "SELECT count(*) from \""._TABLE_RES_INDEX_."\" where tag like '%$word%'";
  93. $count = PDO_FetchOne($query);
  94. $query = "SELECT * from \""._TABLE_RES_INDEX_."\" where tag like '%$word%' limit 10";
  95. $Fetch = PDO_FetchAll($query);
  96. $iFetch = count($Fetch);
  97. if ($iFetch > 0) {
  98. echo "<ul class='search_list'>";
  99. echo "<li class='title'><div>标签($count)</div><div class='ui-icon ui-icon-carat-r'></div></li>";
  100. for ($i = 0; $i < $iFetch; $i++) {
  101. $open_link = "onclick='index_render_res_list(" . $Fetch[$i]["book"] . "," . $Fetch[$i]["album"] . "," . $Fetch[$i]["paragraph"] . ")'";
  102. echo "<li $open_link><div>" . $Fetch[$i]["title"] . "-{$Fetch[$i]["book"]}</div><div class='ui-icon ui-icon-carat-r'></div></li>";
  103. }
  104. echo "</ul>";
  105. }
  106. break;
  107. case "author":
  108. echo "<div id='search_author'>";
  109. echo "<div id='author_name'>$word</div>";
  110. echo "<div id='search_body'>";
  111. //author id
  112. $query = "SELECT id from 'author' where name = '$word'";
  113. $arr_author = PDO_FetchAll($query);
  114. if (count($arr_author) > 0) {
  115. $author_id = $arr_author[0]["id"];
  116. }
  117. //查album
  118. $query = "SELECT count(*) from 'album' where author = '$author_id'";
  119. $count = PDO_FetchOne($query);
  120. if ($count > 0) {
  121. $query = "SELECT * from 'album' where author = '$author_id' limit 0,10";
  122. $Fetch = PDO_FetchAll($query);
  123. $iFetch = count($Fetch);
  124. if ($iFetch > 0) {
  125. echo "<div class='search_list_div'><div class='search_type'>专辑($count)</div></div>";
  126. for ($i = 0; $i < $iFetch; $i++) {
  127. $open_link = "onclick='index_render_res_list(" . $Fetch[$i]["book"] . "," . $Fetch[$i]["id"] . ",-1)'";
  128. echo "<div class='search_list_div'><div class='search_item' $open_link>" . $Fetch[$i]["title"] . "</div></div>";
  129. }
  130. }
  131. }
  132. //查资源
  133. $query = "SELECT count(*) from \""._TABLE_RES_INDEX_."\" where author = '$author_id'";
  134. $count = PDO_FetchOne($query);
  135. if ($count > 0) {
  136. $query = "SELECT * from \""._TABLE_RES_INDEX_."\" where author = '$author_id' limit 0,10";
  137. $Fetch = PDO_FetchAll($query);
  138. $iFetch = count($Fetch);
  139. if ($iFetch > 0) {
  140. echo "<div class='search_list_div'><div class='search_type'>标题($count)</div></div>";
  141. for ($i = 0; $i < $iFetch; $i++) {
  142. $open_link = "onclick='index_render_res_list(" . $Fetch[$i]["book"] . "," . $Fetch[$i]["album"] . "," . $Fetch[$i]["paragraph"] . ")'";
  143. echo "<div class='search_list_div' $open_link><div class='search_item'>" . $Fetch[$i]["title"] . "</div></div>";
  144. }
  145. }
  146. }
  147. echo "</div>";
  148. echo "</div>";
  149. break;
  150. case "album":
  151. break;
  152. }