dict_find2.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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("sqlite:$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. }
  60. else{
  61. $query = "select * from dict where \"pali\"=".$PDO->quote($wordlist[$x]->word)." ORDER BY rowid DESC";
  62. }
  63. }
  64. else{
  65. if($wordlist[$x]->level==1){
  66. $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.' )";
  67. }
  68. else{
  69. $query = "select * from dict where \"pali\"=".$PDO->quote($wordlist[$x]->word)."";
  70. }
  71. }
  72. $Fetch = PDO_FetchAll($query);
  73. $iFetch=count($Fetch);
  74. if($iFetch>0){
  75. for($i=0;$i<$iFetch;$i++){
  76. $outXml = "<word>";
  77. $outXml .= "<id>".$Fetch[$i]["id"]."</id>";
  78. if(isset($Fetch[$i]["guid"])){$outXml .= "<guid>".$Fetch[$i]["guid"]."</guid>";}else{$outXml .= "<guid></guid>";}
  79. $outXml .= "<pali>".$Fetch[$i]["pali"]."</pali>";
  80. $outXml .= "<type>".$Fetch[$i]["type"]."</type>";
  81. $outXml .= "<gramma>".$Fetch[$i]["gramma"]."</gramma>";
  82. $outXml .= "<parent>".$Fetch[$i]["parent"]."</parent>";
  83. $outXml .= "<mean>".$Fetch[$i]["mean"]."</mean>";
  84. $outXml .= "<factors>".$Fetch[$i]["factors"]."</factors>";
  85. if(isset($Fetch[$i]["part_id"])){$outXml .= "<part_id>".$Fetch[$i]["part_id"]."</part_id>";}else{$outXml .= "<part_id></part_id>";}
  86. $outXml .= "<factormean>".$Fetch[$i]["factormean"]."</factormean>";
  87. if(isset($Fetch[$i]["note"])){
  88. $outXml .= "<note>".$Fetch[$i]["note"]."</note>";
  89. }
  90. else{
  91. $outXml .= "<note></note>";
  92. }
  93. if(isset($Fetch[$i]["status"])){
  94. $outXml .= "<status>".$Fetch[$i]["status"]."</status>";
  95. }
  96. else{
  97. $outXml .= "<status>256</status>";
  98. }
  99. if(isset($Fetch[$i]["enable"])){
  100. $outXml .= "<enable>".$Fetch[$i]["enable"]."</enable>";
  101. }
  102. else{
  103. $outXml .= "<enable>TURE</enable>";
  104. }
  105. if(isset($Fetch[$i]["dict_name"])){
  106. $outXml .= "<dict_name>".$Fetch[$i]["dict_name"]."</dict_name>";
  107. }
  108. else{
  109. $outXml .= "<dict_name>unkow</dict_name>";
  110. }
  111. if(isset($Fetch[$i]["language"])){
  112. $outXml .= "<language>".$Fetch[$i]["language"]."</language>";
  113. }
  114. else{
  115. $outXml .= "<language>en</language>";
  116. }
  117. if(isset($Fetch[$i]["time"])){
  118. $outXml .= "<time>".$Fetch[$i]["time"]."</time>";
  119. }
  120. else{
  121. $outXml .= "<time>0</time>";
  122. }
  123. $outXml .= "</word>";
  124. echo $outXml;
  125. }
  126. }
  127. /*直接查询结束*/
  128. }
  129. }
  130. $outXml = "</wordlist>";
  131. echo $outXml;
  132. //fwrite($fpTemp, $outXml);
  133. //fclose($fpTemp);
  134. //$fpTemp = fopen($tempFile, "r") or die("Unable to open file!");
  135. //$tempText = fread($fpTemp,filesize($tempFile));
  136. //fclose($fpTemp);
  137. //echo $tempText;
  138. ?>