dict_find3.php 17 KB

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