search.php 6.9 KB

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