search.php 5.4 KB

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