dict_find3.php 16 KB

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