term.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <?php
  2. //查询term字典
  3. include "../public/config.php";
  4. include "../public/_pdo.php";
  5. include "./public.inc";
  6. if(isset($_GET["language"])){
  7. $currLanguage=$_GET["language"];
  8. $_COOKIE["language"]=$currLanguage;
  9. }
  10. else{
  11. if(isset($_COOKIE["language"])){
  12. $currLanguage=$_COOKIE["language"];
  13. }
  14. else{
  15. $currLanguage="en";
  16. $_COOKIE["language"]=$currLanguage;
  17. }
  18. }
  19. //load language file
  20. if(file_exists($dir_language.$currLanguage.".php")){
  21. require $dir_language.$currLanguage.".php";
  22. }
  23. else{
  24. include $dir_language."default.php";
  25. }
  26. $username = "";
  27. if(isset($_COOKIE["username"]) && !empty($_COOKIE["username"])){
  28. $username = $_COOKIE["username"];
  29. }
  30. $op=$_GET["op"];
  31. if(isset($_GET["word"])){
  32. if(empty($_GET["word"])){
  33. return;
  34. }
  35. $word=mb_strtolower($_GET["word"],'UTF-8');
  36. $org_word=$word;
  37. }
  38. if(isset($_GET["list"])){
  39. $list=$_GET["list"];
  40. }
  41. $count_return=0;
  42. $dict_list=array();
  43. global $PDO;
  44. PDO_Connect("sqlite:$_file_db_term");
  45. switch($op){
  46. case "pre"://预查询
  47. echo "<wordlist>";
  48. $query = "select word,count from dict where \"eword\" like ".$PDO->quote($word.'%')." OR \"word\" like ".$PDO->quote($word.'%')." limit 0,100";
  49. $Fetch = PDO_FetchAll($query);
  50. $iFetch=count($Fetch);
  51. if($iFetch>0){
  52. for($i=0;$i<$iFetch;$i++){
  53. $outXml = "<word>";
  54. $word=$Fetch[$i]["word"];
  55. $outXml = $outXml."<pali>$word</pali>";
  56. $outXml = $outXml."<count>".$Fetch[$i]["count"]."</count>";
  57. $outXml = $outXml."</word>";
  58. echo $outXml;
  59. }
  60. }
  61. echo "</wordlist>";
  62. break;
  63. case "my":
  64. $query = "select guid,word,meaning,other_meaning from term where owner= ".$PDO->quote($username);
  65. $Fetch = PDO_FetchAll($query);
  66. $iFetch=count($Fetch);
  67. if($iFetch>0){
  68. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  69. }
  70. break;
  71. case "allpali":
  72. $query = "select word from term where 1 group by word";
  73. $Fetch = PDO_FetchAll($query);
  74. $iFetch=count($Fetch);
  75. if($iFetch>0){
  76. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  77. }
  78. break;
  79. case "allmean":
  80. $query = "select meaning from term where \"word\" = ".$PDO->quote($word)." group by meaning";
  81. $Fetch = PDO_FetchAll($query);
  82. foreach($Fetch as $one){
  83. echo "<a>".$one["meaning"]."</a> ";
  84. }
  85. //echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  86. break;
  87. case "load_id":
  88. if(isset($_GET["id"])){
  89. $id=$_GET["id"];
  90. $query = "select * from term where \"guid\" = ".$PDO->quote($id);
  91. $Fetch = PDO_FetchAll($query);
  92. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  93. }
  94. else{
  95. echo "{}";
  96. }
  97. break;
  98. case "search":
  99. //查本人数据
  100. echo "<div>".$module_gui_str['editor']['1122']."</div>";//My Term
  101. $query = "select * from term where \"word\" = ".$PDO->quote($word)." AND \"owner\"= ".$PDO->quote($username)." limit 0,30";
  102. $Fetch = PDO_FetchAll($query);
  103. $iFetch=count($Fetch);
  104. $count_return+=$iFetch;
  105. if($iFetch>0){
  106. for($i=0;$i<$iFetch;$i++){
  107. $mean=$Fetch[$i]["meaning"];
  108. $guid=$Fetch[$i]["guid"];
  109. $dict_list[$guid]=$Fetch[$i]["owner"];
  110. echo "<div class='dict_word'>";
  111. echo "<a name='ref_dict_$guid'></a>";
  112. echo"<div class='dict'>$word</div>";
  113. echo "<div id='term_dict_my_$guid'>";
  114. echo "<div class='mean'>".$mean."</div>";
  115. echo "<div class='other_mean'>".$Fetch[$i]["other_meaning"]."</div>";
  116. echo "<div class='term_note' status=0>".$Fetch[$i]["note"]."</div>";
  117. echo "</div>";
  118. //编辑词条表单
  119. echo "<div id='term_dict_my_edit_$guid' style='display:none'>";
  120. echo "<input type='hidden' id='term_edit_word_$guid' value='$word' />";
  121. echo "<div class='mean'><input type='input' id='term_edit_mean_$guid' placeholder='".$module_gui_str['editor']['1010']."'value='$mean' /></div>";//'意思'
  122. echo "<div class='other_mean'><input type='input' id='term_edit_mean2_$guid' placeholder=".$module_gui_str['editor']['1120']." value='".$Fetch[$i]["other_meaning"]."' /></div>";//'备选意思(可选项)'
  123. echo "<div class='note'><textarea id='term_edit_note_$guid' placeholder='".$module_gui_str['editor']['1043']."'>".$Fetch[$i]["note"]."</textarea></div>";//'注解'
  124. echo "</div>";
  125. echo "<div id='term_edit_btn1_$guid'>";
  126. echo "<button onclick=\"term_apply('$guid')\">".$module_gui_str['editor_layout']['1003']."</button>";//Apply
  127. echo "<button onclick=\"term_edit('$guid')\">".$module_gui_str['editor']['1002']."</button>";//Edit
  128. echo "</div>";
  129. echo "<div id='term_edit_btn2_$guid' style='display:none'>";
  130. echo "<button onclick=\"term_data_esc_edit('$guid')\">".$module_gui_str['editor']['1028']."</button>";//Cancel
  131. echo "<button onclick=\"term_data_save('$guid')\">".$module_gui_str['editor']['1017']."</button>";//保存
  132. echo "</div>";
  133. echo "</div>";
  134. }
  135. }
  136. //新建词条
  137. echo "<div class='dict_word'>";
  138. echo "<div class='dict'>".$module_gui_str['editor']['1121']."</div>";//New Techinc Term
  139. echo "<div class='mean'>巴利拼写:<input type='input' placeholder=".$module_gui_str['editor']['1119']." id='term_new_word' value='{$word}' /></div>";//'拼写'
  140. echo "<div class='mean'>意思<input type='input' placeholder='".$module_gui_str["editor"]["1010"]."' id='term_new_mean'/></div>";//'意思'
  141. echo "<div class='other_mean'>第二意思:<input type='input' placeholder='".$module_gui_str['editor']['1120']."' id='term_new_mean2'/></div>";//'备选意思(可选项)'
  142. echo "<div class='tag'>分类:<input type='input' placeholder='".$module_gui_str['tools']['1005']."' id='term_new_tag'/></div>";//'标签'
  143. echo "<div class='note'>注解:<textarea width='100%' height='3em' placeholder='".$module_gui_str['editor']['1043']."' id='term_new_note'></textarea></div>";//'注解'
  144. echo "<button onclick=\"term_data_save('')\">".$module_gui_str['editor']['1017']."</button>";//保存
  145. echo "</div>";
  146. //查他人数据
  147. $query = "select * from term where \"word\" = ".$PDO->quote($word)."AND \"owner\" <> ".$PDO->quote($username)." limit 0,30";
  148. $Fetch = PDO_FetchAll($query);
  149. $iFetch=count($Fetch);
  150. $count_return+=$iFetch;
  151. if($iFetch>0){
  152. for($i=0;$i<$iFetch;$i++){
  153. $mean=$Fetch[$i]["meaning"];
  154. $guid=$Fetch[$i]["guid"];
  155. $dict_list[$guid]=$Fetch[$i]["owner"];
  156. echo "<div class='dict_word'>";
  157. echo "<a name='ref_dict_$guid'></a>";
  158. echo"<div class='dict'>".$Fetch[$i]["owner"]."</div>";
  159. echo "<div class='mean'>".$mean."</div>";
  160. echo "<div class='other_mean'>".$Fetch[$i]["other_meaning"]."</div>";
  161. echo "<div class='note'>".$Fetch[$i]["note"]."</div>";
  162. echo "<button onclick=\"term_data_copy_to_me($guid)\">".$module_gui_str['editor']['1123']."</button>";//复制
  163. echo "</div>";
  164. }
  165. }
  166. //查内容
  167. if($count_return<2){
  168. $word1=$org_word;
  169. $wordInMean="%$org_word%";
  170. echo $module_gui_str['editor']['1124'].":$org_word<br />";
  171. $query = "select * from term where \"meaning\" like ".$PDO->quote($word)." limit 0,30";
  172. $Fetch = PDO_FetchAll($query);
  173. $iFetch=count($Fetch);
  174. $count_return+=$iFetch;
  175. if($iFetch>0){
  176. for($i=0;$i<$iFetch;$i++){
  177. $mean=$Fetch[$i]["meaning"];
  178. $pos=mb_stripos($mean,$word,0,"UTF-8");
  179. if($pos){
  180. if($pos>20){
  181. $start=$pos-20;
  182. }
  183. else{
  184. $start=0;
  185. }
  186. $newmean=mb_substr($mean,$start,100,"UTF-8");
  187. }
  188. else{
  189. $newmean=$mean;
  190. }
  191. $pos=mb_stripos($newmean,$word1,0,"UTF-8");
  192. $head=mb_substr($newmean,0,$pos,"UTF-8");
  193. $mid=mb_substr($newmean,$pos,mb_strlen($word1,"UTF-8"),"UTF-8");
  194. $end=mb_substr($newmean,$pos+mb_strlen($word1,"UTF-8"),NULL,"UTF-8");
  195. $heigh_light_mean="$head<hl>$mid</hl>$end";
  196. $outXml = "<div class='dict_word'>";
  197. $outXml = $outXml."<div class='dict'>".$Fetch[$i]["owner"]."</div>";
  198. $outXml = $outXml."<div class='pali'>".$Fetch[$i]["word"]."</div>";
  199. $outXml = $outXml."<div class='mean'>".$heigh_light_mean."</div>";
  200. $outXml = $outXml."<div class='note'>{$Fetch[$i]["note"]}</div>";
  201. $outXml = $outXml."</div>";
  202. echo $outXml;
  203. }
  204. }
  205. }
  206. //查内容结束
  207. echo "<div id='dictlist'>";
  208. foreach($dict_list as $x=>$x_value) {
  209. echo "<a href='#ref_dict_$x'>$x_value</a><br/>";
  210. }
  211. echo "</div>";
  212. break;
  213. case "save":
  214. if($_GET["guid"]!=""){
  215. $mean=$_GET["mean"];
  216. $query="UPDATE term SET meaning='$mean' ,
  217. other_meaning='".$_GET["mean2"]."' ,
  218. note='".$_GET["note"]."'
  219. where guid='".$_GET["guid"]."'";
  220. }
  221. else{
  222. $newGuid=GUIDv4();
  223. $newGuid=str_replace("-","",$newGuid);
  224. $word=$_GET["word"];
  225. $worden=pali2english($word);
  226. $mean=$_GET["mean"];
  227. $mean2=$_GET["mean2"];
  228. $note=$_GET["note"];
  229. $tag=$_GET["tag"];
  230. $time=time();
  231. $query="INSERT INTO term VALUES (NULL,
  232. '$newGuid',
  233. '$word',
  234. '$worden',
  235. '$mean',
  236. '$mean2',
  237. '$note',
  238. '$tag',
  239. '$time',
  240. '$username',
  241. '1',
  242. 'zh',
  243. '0',
  244. '0',
  245. '0')";
  246. }
  247. $stmt = @PDO_Execute($query);
  248. $respond=array("status"=>0,"message"=>"");
  249. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  250. $error = PDO_ErrorInfo();
  251. $respond['status']=1;
  252. $respond['message']=$error[2];
  253. }
  254. else{
  255. $respond['status']=0;
  256. $respond['message']=$word;
  257. }
  258. echo json_encode($respond, JSON_UNESCAPED_UNICODE);
  259. break;
  260. case "copy"://拷贝到我的字典
  261. $query = "select * from term where \"guid\" = ".$PDO->quote($_GET["wordid"]);
  262. $Fetch = PDO_FetchAll($query);
  263. $iFetch=count($Fetch);
  264. if($iFetch>0){
  265. /* 开始一个事务,关闭自动提交 */
  266. $PDO->beginTransaction();
  267. $query="INSERT INTO term ('id','guid','word','word_en','meaning','other_meaning','note','tag','create_time','owner','hit') VALUES (null,?,?,?,?,?,?,?,".time().",'$username',1)";
  268. $stmt = $PDO->prepare($query);
  269. {
  270. $stmt->execute(array(GUIDv4(false),
  271. $Fetch[0]["word"],
  272. $Fetch[0]["word_en"],
  273. $Fetch[0]["meaning"],
  274. $Fetch[0]["other_meaning"],
  275. $Fetch[0]["note"],
  276. $Fetch[0]["tag"],
  277. ));
  278. }
  279. /* 提交更改 */
  280. $PDO->commit();
  281. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  282. $error = PDO_ErrorInfo();
  283. echo "error - $error[2] <br>";
  284. }
  285. else{
  286. echo "updata ok.";
  287. }
  288. }
  289. break;
  290. case "extract":
  291. $query = "select * from term where \"guid\" in ($list) limit 0,1000";
  292. $Fetch = PDO_FetchAll($query);
  293. $iFetch=count($Fetch);
  294. if($iFetch>0){
  295. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  296. }
  297. break;
  298. }
  299. ?>