dict_find3.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. //查询参考字典
  3. require '../public/casesuf.inc';
  4. require '../public/union.inc';
  5. include "../public/config.php";
  6. include "../public/_pdo.php";
  7. if(isset($_GET["language"])){
  8. $currLanguage=$_GET["language"];
  9. }
  10. else{
  11. if(isset($_COOKIE["language"])){
  12. $currLanguage=$_COOKIE["language"];
  13. }
  14. else{
  15. $currLanguage="en";
  16. }
  17. }
  18. if(file_exists($dir_language.$currLanguage.".php")){
  19. require $dir_language.$currLanguage.".php";
  20. echo("<script language=\"javascript\" src=\"language/$currLanguage.js\"></script>");
  21. }
  22. else{
  23. include $dir_language."default.php";
  24. }
  25. $op=$_GET["op"];
  26. $word=mb_strtolower($_GET["word"],'UTF-8');
  27. $org_word=$word;
  28. $count_return=0;
  29. $dict_list=array();
  30. global $PDO;
  31. switch($op){
  32. case "pre"://预查询
  33. $dictFileName=_FILE_DB_WORD_INDEX_;
  34. PDO_Connect("sqlite:$dictFileName");
  35. echo "<div>";
  36. $query = "select word,count from wordindex where \"word_en\" like ".$PDO->quote($word.'%')." OR \"word\" like ".$PDO->quote($word.'%')." limit 0,50";
  37. echo $query;
  38. $Fetch = PDO_FetchAll($query);
  39. $iFetch=count($Fetch);
  40. if($iFetch>0){
  41. for($i=0;$i<$iFetch;$i++){
  42. $word=$Fetch[$i]["word"];
  43. $count=$Fetch[$i]["count"];
  44. echo "<div class='dict_word_list'>";
  45. echo "<a onclick='dict_pre_word_click(\"$word\")'>$word-$count</a>";
  46. echo "</div>";
  47. }
  48. }
  49. echo "</div>";
  50. break;
  51. case "search":
  52. $strDictTab="<li id=\"dt_dict\" class=\"act\" onclick=\"tab_click('dict_ref','dt_dict')\">字典</li>";
  53. //获取书名
  54. $arrBookName=json_decode(file_get_contents("../public/book_name/sc.json"));
  55. echo "<div id=\"dict_bold\">";
  56. //加语尾
  57. $arrNewWord=array();
  58. for ($row = 0; $row < count($case); $row++) {
  59. $len=mb_strlen($case[$row][0],"UTF-8");
  60. $end=mb_substr($word, 0-$len,NULL,"UTF-8");
  61. if($end==$case[$row][0]){
  62. $newWord=mb_substr($word, 0,mb_strlen($word,"UTF-8")-$len,"UTF-8").$case[$row][1];
  63. $arrNewWord[$newWord]=1;
  64. }
  65. }
  66. //加连读词尾
  67. $arrUnWord=array();
  68. for ($row = 0; $row < count($union); $row++) {
  69. $len=mb_strlen($union[$row][0],"UTF-8");
  70. foreach($arrNewWord as $x=>$x_value){
  71. $end=mb_substr($x, 0-$len,NULL,"UTF-8");
  72. if($end==$union[$row][0]){
  73. $newWord=mb_substr($x, 0,mb_strlen($x,"UTF-8")-$len,"UTF-8").$union[$row][1];
  74. $arrUnWord[$newWord]=1;
  75. }
  76. }
  77. }
  78. //将连读词和$arrNewWord混合
  79. foreach($arrUnWord as $x=>$x_value){
  80. $arrNewWord[$x]=1;
  81. }
  82. if(count($arrNewWord)>0){
  83. $strQueryWord="(";
  84. foreach($arrNewWord as $x=>$x_value) {
  85. $strQueryWord.="'{$x}',";
  86. }
  87. $strQueryWord=mb_substr($strQueryWord, 0,mb_strlen($strQueryWord,"UTF-8")-1,"UTF-8");
  88. $strQueryWord.=")";
  89. }
  90. else{
  91. $strQueryWord="('{$word}')";
  92. }
  93. //主显示区开始
  94. echo "<div style='display:flex;'>";
  95. //主显示区左侧开始
  96. echo "<div style='flex:3;max-width: 17em;min-width: 10em;'>";
  97. echo "<button onclick=\"dict_update_bold(0)\">".$module_gui_str['search']['1001']."</button>";
  98. /*查找实际出现的拼写
  99. */
  100. $dictFileName=_FILE_DB_WORD_INDEX_;
  101. PDO_Connect("sqlite:$dictFileName");
  102. $query = "select id,word,count from wordindex where \"word\" in $strQueryWord";
  103. $arrRealWordList = PDO_FetchAll($query);
  104. $countWord=count($arrRealWordList);
  105. echo "$word<br />共{$countWord}单词符合<br />";
  106. $strQueryWordId="(";//实际出现的单词id查询字串
  107. $aQueryWordList=array();//id 为键 拼写为值的数组
  108. $aShowWordList=array();//拼写为键 个数为值的数组
  109. $aShowWordIdList=array();//拼写为键 值Id的数组
  110. for($i=0;$i<$countWord;$i++){
  111. $value= $arrRealWordList[$i];
  112. $strQueryWordId.="'{$value["id"]}',";
  113. $aQueryWordList["{$value["id"]}"]=$value["word"];
  114. $aShowWordList[$value["word"]]=$value["count"];
  115. $aShowWordIdList[$value["word"]]=$value["id"];
  116. }
  117. $strQueryWordId=mb_substr($strQueryWordId, 0,mb_strlen($strQueryWordId,"UTF-8")-1,"UTF-8");
  118. $strQueryWordId.=")";
  119. //显示单词列表
  120. echo "<div>";
  121. echo "<input id='bold_all_word' type='checkbox' checked='true' value='' onclick=\"dict_bold_word_all_select()\"/>全选<br />";
  122. arsort($aShowWordList);
  123. $i=0;
  124. foreach($aShowWordList as $x=>$x_value) {
  125. $wordid=$aShowWordIdList[$x];
  126. echo "<input id='bold_word_{$i}' type='checkbox' checked value='{$wordid}' />";
  127. echo "<a onclick=\"dict_bold_word_select({$i})\">";
  128. echo $x.":".$x_value."<br />";
  129. echo "</a>";
  130. $i++;
  131. }
  132. echo "<input id='bold_word_count' type='hidden' value='{$countWord}' />";
  133. echo "</div>";
  134. //查找这些词出现在哪些书中
  135. $dictFileName=_FILE_DB_BOOK_WORD_;
  136. PDO_Connect("sqlite:$dictFileName");
  137. $query = "SELECT book,sum(count) as co FROM bookword WHERE \"wordindex\" IN $strQueryWordId GROUP BY book LIMIT 0,217";
  138. $Fetch = PDO_FetchAll($query);
  139. $iFetch=count($Fetch);
  140. if($iFetch>0){
  141. $aWordInBook=array();
  142. foreach($Fetch as $xBook){
  143. $aWordInBook["{$xBook["book"]}"]=$xBook["co"];
  144. }
  145. arsort($aWordInBook);
  146. echo "<div id='bold_book_list'>";
  147. echo "出现在{$iFetch}本书中:<br />";
  148. echo "<input type='checkbox' checked='true' value='' />全选<br />";
  149. $i=0;
  150. foreach($aWordInBook as $x=>$x_value) {
  151. $book=$x;
  152. $bookname=$arrBookName[$book-1]->title;
  153. echo "<input id='bold_book_{$i}' type='checkbox' checked value='{$book}'/>";
  154. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  155. echo "《{$bookname}》:{$x_value}次<br />";
  156. echo "</a>";
  157. $i++;
  158. }
  159. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  160. echo "</div>";
  161. }
  162. //查找这些词出现在哪些书中结束
  163. echo "</div>";
  164. //黑体字主显示区左侧结束
  165. //黑体字主显示区右侧开始
  166. echo "<div id=\"dict_bold_right\" style='flex:7;'>";
  167. //前20条记录
  168. $dictFileName=_FILE_DB_WORD_INDEX_;
  169. PDO_Connect("sqlite:$dictFileName");
  170. $query = "SELECT book,paragraph, wordindex FROM word WHERE \"wordindex\" in $strQueryWordId LIMIT 0,20";
  171. $Fetch = PDO_FetchAll($query);
  172. $iFetch=count($Fetch);
  173. if($iFetch>0){
  174. $dictFileName=_FILE_DB_PALITEXT_;
  175. PDO_Connect("sqlite:$dictFileName");
  176. for($i=0;$i<$iFetch;$i++){
  177. $paliwordid=$Fetch[$i]["wordindex"];
  178. $paliword=$aQueryWordList["{$paliwordid}"];
  179. $book=$Fetch[$i]["book"];
  180. $paragraph=$Fetch[$i]["paragraph"];
  181. $bookname=$arrBookName[$book-1]->title;
  182. $c1=$arrBookName[$book-1]->c1;
  183. echo "<div class='dict_word'>";
  184. echo "<div class='dict'>《{$bookname}》 $c1</div>";
  185. echo "<div class='mean'>$paliword</div>";
  186. {
  187. $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,1";
  188. $FetchPaliText = PDO_FetchAll($query);
  189. $countPaliText=count($FetchPaliText);
  190. if($countPaliText>0){
  191. for($iPali=0;$iPali<$countPaliText;$iPali++){
  192. if(substr($paliword,-1)=="n"){
  193. $paliword=substr($paliword,0,-1);
  194. }
  195. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["vri_text"]);
  196. echo "<div class='wizard_par_div'>{$light_text}</div>";
  197. }
  198. }
  199. }
  200. echo "</div>";
  201. }
  202. }
  203. echo "</div>";
  204. //黑体字主显示区右侧结束
  205. echo "</div>";
  206. //黑体字主显示区结束
  207. echo "</div>";
  208. //查黑体字结束
  209. echo "<div id='real_dict_tab'>$strDictTab</div>";
  210. break;
  211. case "update":
  212. $target=$_GET["target"];
  213. switch($target){
  214. case "bold";
  215. $arrBookName=json_decode(file_get_contents("../public/book_name/sc.json"));
  216. $arrBookType=json_decode(file_get_contents("../public/book_name/booktype.json"));
  217. $dictFileName=_FILE_DB_BOOK_WORD_;
  218. PDO_Connect("sqlite:$dictFileName");
  219. $wordlist=$_GET["wordlist"];
  220. $booklist=$_GET["booklist"];
  221. $aBookList=ltrim($booklist,"(");
  222. $aBookList=rtrim($aBookList,")");
  223. $aBookList=str_replace("'","",$aBookList);
  224. $aBookList=str_getcsv($aBookList);
  225. foreach($aBookList as $oneBook){
  226. $aInputBook["{$oneBook}"]=1;
  227. }
  228. //查找这些词出现在哪些书中
  229. $query = "select book,sum(count) as co from bookword where \"wordindex\" in $wordlist group by book order by co DESC";
  230. $Fetch = PDO_FetchAll($query);
  231. $iFetch=count($Fetch);
  232. if($iFetch>0){
  233. $booktypesum["vinaya"]=array(0,0);
  234. $booktypesum["sutta"]=array(0,0);
  235. $booktypesum["abhidhamma"]=array(0,0);
  236. $booktypesum["anna"]=array(0,0);
  237. $booktypesum["mula"]=array(0,0);
  238. $booktypesum["atthakattha"]=array(0,0);
  239. $booktypesum["tika"]=array(0,0);
  240. $booktypesum["anna2"]=array(0,0);
  241. for($i=0;$i<$iFetch;$i++){
  242. $book=$Fetch[$i]["book"];
  243. $sum=$Fetch[$i]["co"];
  244. $t1=$arrBookType[$book-1]->c1;
  245. $t2=$arrBookType[$book-1]->c2;
  246. if(isset($booktypesum[$t1])){
  247. $booktypesum[$t1][0]++;
  248. $booktypesum[$t1][1]+=$sum;
  249. }
  250. else{
  251. $booktypesum[$t1][0]=1;
  252. $booktypesum[$t1][1]=$sum;
  253. }
  254. if(isset($booktypesum[$t2])){
  255. $booktypesum[$t2][0]++;
  256. $booktypesum[$t2][1]+=$sum;
  257. }
  258. else{
  259. $booktypesum[$t2][0]=1;
  260. $booktypesum[$t2][1]=$sum;
  261. }
  262. }
  263. echo "<div id='bold_book_list_new'>";
  264. echo "出现在{$iFetch}本书中:<br />";
  265. echo "<input id='bold_all_book' type='checkbox' checked onclick=\"dict_bold_book_all_select()\" />全选<br />";
  266. echo "<input id='id_book_filter_vinaya' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_vinaya','vinaya')\" />律藏-{$booktypesum["vinaya"][0]}-{$booktypesum["vinaya"][1]}<br />";
  267. echo "<input id='id_book_filter_sutta' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_sutta','sutta')\" />经藏-{$booktypesum["sutta"][0]}-{$booktypesum["sutta"][1]}<br />";
  268. echo "<input id='id_book_filter_abhidhamma' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_abhidhamma','abhidhamma')\" />阿毗达摩藏-{$booktypesum["abhidhamma"][0]}-{$booktypesum["abhidhamma"][1]}<br />";
  269. echo "<input id='id_book_filter_anna' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna','anna')\" />其他-{$booktypesum["anna"][0]}-{$booktypesum["anna"][1]}<br /><br />";
  270. echo "<input id='id_book_filter_mula' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_mula','mula')\" />根本-{$booktypesum["mula"][0]}-{$booktypesum["mula"][1]}<br />";
  271. echo "<input id='id_book_filter_atthakattha' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_atthakattha','atthakattha')\" />义注-{$booktypesum["atthakattha"][0]}-{$booktypesum["atthakattha"][1]}<br />";
  272. echo "<input id='id_book_filter_tika' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_tika','tika')\" />复注-{$booktypesum["tika"][0]}-{$booktypesum["tika"][1]}<br />";
  273. echo "<input id='id_book_filter_anna2' type='checkbox' checked onclick=\"search_book_filter('id_book_filter_anna2','anna2')\" />其他-{$booktypesum["anna2"][0]}-{$booktypesum["anna2"][1]}<br /><br />";
  274. for($i=0;$i<$iFetch;$i++){
  275. $book=$Fetch[$i]["book"];
  276. $bookname=$arrBookName[$book-1]->title;
  277. if(isset($aInputBook["{$book}"])){
  278. $bookcheck="checked";
  279. }
  280. else{
  281. $bookcheck="";
  282. }
  283. $t1=$arrBookType[$book-1]->c1;
  284. $t2=$arrBookType[$book-1]->c2;
  285. echo "<div class='{$t1}'>";
  286. echo "<div class='{$t2}'>";
  287. echo "<input id='bold_book_{$i}' type='checkbox' $bookcheck value='{$book}'/>";
  288. echo "<a onclick=\"dict_bold_book_select({$i})\">";
  289. echo "《{$bookname}》:{$Fetch[$i]["co"]}次<br />";
  290. echo "</a>";
  291. echo "</div></div>";
  292. }
  293. echo "<input id='bold_book_count' type='hidden' value='{$iFetch}' />";
  294. echo "</div>";
  295. }
  296. //查找这些词出现在哪些书中结束
  297. //前20条记录
  298. $dictFileName=_FILE_DB_WORD_INDEX_;
  299. PDO_Connect("sqlite:$dictFileName");
  300. $query = "select * from word where \"wordindex\" in $wordlist and \"book\" in $booklist group by book,paragraph limit 0,20";
  301. $Fetch = PDO_FetchAll($query);
  302. $iFetch=count($Fetch);
  303. if($iFetch>0){
  304. $dictFileName=_FILE_DB_PALITEXT_;
  305. PDO_Connect("sqlite:$dictFileName");
  306. for($i=0;$i<$iFetch;$i++){
  307. $paliword=$Fetch[$i]["wordindex"];
  308. $book=$Fetch[$i]["book"];
  309. $bookname=$arrBookName[$book-1]->title;
  310. $c1=$arrBookName[$book-1]->c1;
  311. $c2=$arrBookName[$book-1]->c2;
  312. $paragraph=$Fetch[$i]["paragraph"];
  313. echo "<div class='dict_word'>";
  314. echo "<div class='dict'>《{$bookname}》 $c1 $c2 </div>";
  315. echo "<div class='mean'>$paliword</div>";
  316. $query = "select * from vri_text where \"book\" = '{$book}' and \"paragraph\" = '{$paragraph}' limit 0,20";
  317. $FetchPaliText = PDO_FetchAll($query);
  318. $countPaliText=count($FetchPaliText);
  319. if($countPaliText>0){
  320. for($iPali=0;$iPali<$countPaliText;$iPali++){
  321. if(substr($paliword,-1)=="n"){
  322. $paliword=substr($paliword,0,-1);
  323. }
  324. $light_text=str_replace($paliword,"<hl>{$paliword}</hl>",$FetchPaliText[$iPali]["vri_text"]);
  325. echo "<div class='wizard_par_div'>{$light_text}</div>";
  326. }
  327. }
  328. echo "</div>";
  329. }
  330. }
  331. break;
  332. }
  333. break;
  334. }
  335. ?>