dict_find2.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. require 'checklogin.inc';
  3. include "./config.php";
  4. include "./_pdo.php";
  5. $countInsert = 0;
  6. $wordlist = array();
  7. $tempFile = "temp.txt";
  8. //$input = file_get_contents("php://input"); //
  9. //$inputWordList=explode("$",$input);
  10. $arrlength = 0; /*size of word list*/
  11. //$dictType=$inputWordList[0];
  12. //$dictFileName=$inputWordList[1];
  13. //$parentLevel=$inputWordList[2];
  14. $dictType = $_POST["type"];
  15. $dictFileName = $_POST["filename"];
  16. $parentLevel = $_POST["level"];
  17. $wordlist = json_decode($_POST["data"], false);
  18. switch ($dictType) {
  19. case "user":
  20. $dictDir = $dir_user_base . $userid . $dir_dict_user . '/';
  21. break;
  22. case "sys":
  23. $dictDir = $dir_dict_system;
  24. break;
  25. case "third":
  26. $dictDir = $dir_dict_3rd;
  27. break;
  28. }
  29. if ($dictFileName == "wbw") {
  30. $dictFileName = $file_dict_wbw_default;
  31. }
  32. if ($dictFileName == "user_default") {
  33. $dictFileName = $file_dict_user_default;
  34. }
  35. /*
  36. for($i=3;$i<count($inputWordList);$i++){
  37. if(!empty($inputWordList[$i])){
  38. $words[$inputWordList[$i]]=1;
  39. }
  40. }
  41. foreach($words as $word=>$value){
  42. $wordlist[$arrlength]=$word;
  43. $arrlength++;
  44. }
  45. */
  46. $arrlength = count($wordlist);
  47. echo "<wordlist>";
  48. $db_path = $dictDir;
  49. $db_file = $db_path . $dictFileName;
  50. //open database
  51. PDO_Connect("$db_file");
  52. global $PDO;
  53. for ($x = 0; $x < $arrlength; $x++) {
  54. if (mb_strlen($wordlist[$x]->word) > 1) {
  55. //直接查
  56. if ($dictFileName == "wbw") {
  57. if ($wordlist[$x]->level == 1) {
  58. $query = "select * from dict where \"type\"<> \"pali\"=" . $PDO->quote($wordlist[$x]->word) . " AND ( type <> '.n.' AND type <> '.ti.' AND type <> '.adj.' AND type <> '.pron.' AND type <> '.v.' ) ORDER BY rowid DESC";
  59. } else {
  60. $query = "select * from dict where \"pali\"=" . $PDO->quote($wordlist[$x]->word) . " ORDER BY rowid DESC";
  61. }
  62. } else {
  63. if ($wordlist[$x]->level == 1) {
  64. $query = "select * from dict where \"pali\"=" . $PDO->quote($wordlist[$x]->word) . " AND ( type <> '.n.' AND type <> '.ti.' AND type <> '.adj.' AND type <> '.pron.' AND type <> '.v.' )";
  65. } else {
  66. $query = "select * from dict where \"pali\"=" . $PDO->quote($wordlist[$x]->word) . "";
  67. }
  68. }
  69. $Fetch = PDO_FetchAll($query);
  70. $iFetch = count($Fetch);
  71. if ($iFetch > 0) {
  72. for ($i = 0; $i < $iFetch; $i++) {
  73. $outXml = "<word>";
  74. $outXml .= "<id>" . $Fetch[$i]["id"] . "</id>";
  75. if (isset($Fetch[$i]["guid"])) {$outXml .= "<guid>" . $Fetch[$i]["guid"] . "</guid>";} else { $outXml .= "<guid></guid>";}
  76. $outXml .= "<pali>" . $Fetch[$i]["pali"] . "</pali>";
  77. $outXml .= "<type>" . $Fetch[$i]["type"] . "</type>";
  78. $outXml .= "<gramma>" . $Fetch[$i]["gramma"] . "</gramma>";
  79. $outXml .= "<parent>" . $Fetch[$i]["parent"] . "</parent>";
  80. $outXml .= "<mean>" . $Fetch[$i]["mean"] . "</mean>";
  81. $outXml .= "<factors>" . $Fetch[$i]["factors"] . "</factors>";
  82. if (isset($Fetch[$i]["part_id"])) {$outXml .= "<part_id>" . $Fetch[$i]["part_id"] . "</part_id>";} else { $outXml .= "<part_id></part_id>";}
  83. $outXml .= "<factormean>" . $Fetch[$i]["factormean"] . "</factormean>";
  84. if (isset($Fetch[$i]["note"])) {
  85. $outXml .= "<note>" . $Fetch[$i]["note"] . "</note>";
  86. } else {
  87. $outXml .= "<note></note>";
  88. }
  89. if (isset($Fetch[$i]["status"])) {
  90. $outXml .= "<status>" . $Fetch[$i]["status"] . "</status>";
  91. } else {
  92. $outXml .= "<status>256</status>";
  93. }
  94. if (isset($Fetch[$i]["enable"])) {
  95. $outXml .= "<enable>" . $Fetch[$i]["enable"] . "</enable>";
  96. } else {
  97. $outXml .= "<enable>TURE</enable>";
  98. }
  99. if (isset($Fetch[$i]["dict_name"])) {
  100. $outXml .= "<dict_name>" . $Fetch[$i]["dict_name"] . "</dict_name>";
  101. } else {
  102. $outXml .= "<dict_name>unkow</dict_name>";
  103. }
  104. if (isset($Fetch[$i]["language"])) {
  105. $outXml .= "<language>" . $Fetch[$i]["language"] . "</language>";
  106. } else {
  107. $outXml .= "<language>en</language>";
  108. }
  109. if (isset($Fetch[$i]["time"])) {
  110. $outXml .= "<time>" . $Fetch[$i]["time"] . "</time>";
  111. } else {
  112. $outXml .= "<time>0</time>";
  113. }
  114. $outXml .= "</word>";
  115. echo $outXml;
  116. }
  117. }
  118. /*直接查询结束*/
  119. }
  120. }
  121. $outXml = "</wordlist>";
  122. echo $outXml;
  123. //fwrite($fpTemp, $outXml);
  124. //fclose($fpTemp);
  125. //$fpTemp = fopen($tempFile, "r") or die("Unable to open file!");
  126. //$tempText = fread($fpTemp,filesize($tempFile));
  127. //fclose($fpTemp);
  128. //echo $tempText;